diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f5f5822a..498ea3bf9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -155,6 +155,7 @@ All notable changes to Bambuddy will be documented in this file. - **The frontend build no longer warns about `path` and `crypto` being externalized for the STEP previewer (#2976)** — `occt-import-js`, the Emscripten build behind STEP previews, requires both modules, but only inside its `ENVIRONMENT_IS_NODE` branches; in the browser it loads its `.wasm` from the URL the preview worker passes and draws randomness from `crypto.getRandomValues`. Vite still externalized both and printed two warnings on every build. `vite.config.ts` now drops exactly those two warnings for that one package through `build.rolldownOptions.onLog`, so an externalization anywhere else, or of any other module, still shows. ### Fixed +- **A printing queue job showed the slot AMS Filament Backup had switched away from as empty** — When a spool ran out mid-print and the printer carried on from the backup spool, the job's card in the queue still named the original slot, now marked **Empty**, as if the print had a problem. The card now shows the backup spool the printer is using. It follows the printer's own record of the trays the print has drawn from, including a backup that ran out in turn. A switch between two slots the job uses is a normal colour change and is not taken for a backup. Queued jobs still warn about an empty slot as before. - **Slice dialog hid renamed printer profiles while "Only printers that are online" was on (#3172, reported by @gregspatrick)** — The filter read the printer model from the profile's name, so a copy saved as `Bambu Lab P1S 0.4 nozzle - Copy` read as an unknown model and was hidden even with a P1S online, until **Show all** was picked. It now reads the model from the profile the copy was saved from, as the loaded-spools filter already did. - **Printer cards never showed the last print, nor the Good / Reject prompt for it** — Each card asked for its printer's archives with the arguments in the wrong order, so it requested none and always got an empty list. The **Last:** line on an idle card and the outcome prompt from #1898 never appeared there. - **One request for every card:** the cards now share a single request that returns the archive each printer printed last (a reprint of an older archive counts), instead of one per card. On a farm with 59 printers that was 59 requests on every page load and after every finished print, each scanning the whole archive table for duplicates. diff --git a/backend/app/api/routes/printers.py b/backend/app/api/routes/printers.py index 1766acc3c..59b3c78da 100644 --- a/backend/app/api/routes/printers.py +++ b/backend/app/api/routes/printers.py @@ -831,6 +831,7 @@ async def get_printer_status( for ext_id, slot in state.extruder_slots.items() }, tray_now=tray_now, + tray_change_log=[[tray, layer] for tray, layer in state.tray_change_log], # Runout guidance (#2587): resolve the firmware's target/previous slot to a # global tray ID, but only while PAUSED — the moment the operator needs it. expected_tray=( diff --git a/backend/app/schemas/printer.py b/backend/app/schemas/printer.py index 9dfaa92b7..ba85f9ef3 100644 --- a/backend/app/schemas/printer.py +++ b/backend/app/schemas/printer.py @@ -417,6 +417,11 @@ class PrinterStatus(BaseModel): extruder_slots: dict[str, ExtruderSlotResponse] = {} # Currently loaded tray (global ID): 254 = external spool, 255 = no filament tray_now: int = 255 + # The trays this print has drawn from, in order: [[global tray ID, layer the + # switch happened at], ...]. A tray outside the job's AMS mapping is a backup + # spool the printer switched to (AMS Filament Backup); the queue card shows it + # in place of the slot that ran out. Reset at the start of each print. + tray_change_log: list[list[int]] = [] # Runout / filament-replacement guidance (#2587). Populated only while the # print is PAUSED. Both are globalised tray IDs (ams_id*4+slot, or 128-135 for # AMS-HT, or 254 for external) so the frontend can highlight them with the same diff --git a/backend/app/services/printer_manager.py b/backend/app/services/printer_manager.py index 59f8504ce..dfc5793ed 100644 --- a/backend/app/services/printer_manager.py +++ b/backend/app/services/printer_manager.py @@ -1577,6 +1577,8 @@ def printer_state_to_dict( "ams_status_main": state.ams_status_main, "ams_status_sub": state.ams_status_sub, "tray_now": state.tray_now, + # Grows only when tray_now changes, which already triggers a push. + "tray_change_log": [[tray, layer] for tray, layer in getattr(state, "tray_change_log", None) or []], # Runout / filament-replacement guidance (#2587). Only meaningful while # PAUSED — resolve the firmware's target/previous slot to a global tray ID # so the AMS graphic can highlight the slot the print now expects and name diff --git a/backend/tests/integration/test_printers_api.py b/backend/tests/integration/test_printers_api.py index 119a08250..8dfdb62b5 100644 --- a/backend/tests/integration/test_printers_api.py +++ b/backend/tests/integration/test_printers_api.py @@ -723,6 +723,29 @@ class TestPrintersAPI: "1": {"ams_id": None, "slot_id": None, "has_filament": False}, } + @pytest.mark.asyncio + @pytest.mark.integration + async def test_status_reports_the_trays_the_print_drew_from(self, async_client: AsyncClient, printer_factory): + """Restored after a restart as lists, recorded live as tuples: both serialise alike.""" + from unittest.mock import MagicMock, patch + + from backend.app.services.bambu_mqtt import PrinterState + + printer = await printer_factory() + + state = PrinterState() + state.connected = True + state.state = "RUNNING" + state.tray_change_log = [[2, 0], (1, 350)] + + with patch("backend.app.api.routes.printers.printer_manager") as mock_pm: + mock_pm.get_status = MagicMock(return_value=state) + mock_pm.is_awaiting_plate_clear = MagicMock(return_value=False) + + response = await async_client.get(f"/api/v1/printers/{printer.id}/status") + + assert response.json()["tray_change_log"] == [[2, 0], [1, 350]] + @pytest.mark.asyncio @pytest.mark.integration async def test_cover_uses_dispatched_plate_when_gcode_file_lacks_path( diff --git a/backend/tests/unit/services/test_printer_manager.py b/backend/tests/unit/services/test_printer_manager.py index 8758ed848..bfb8f6ab5 100644 --- a/backend/tests/unit/services/test_printer_manager.py +++ b/backend/tests/unit/services/test_printer_manager.py @@ -989,6 +989,12 @@ class TestPrinterStateToDict: "1": {"ams_id": None, "slot_id": None, "has_filament": False}, } + def test_the_tray_change_log_rides_the_websocket(self, mock_state): + """The queue card reads the backup spool a print switched to from it.""" + mock_state.tray_change_log = [(2, 0), (1, 350)] + + assert printer_state_to_dict(mock_state)["tray_change_log"] == [[2, 0], [1, 350]] + def test_extruder_slots_are_empty_when_unreported(self, mock_state): """Printers outside the H2/X2 series never send the block.""" assert printer_state_to_dict(mock_state)["extruder_slots"] == {} diff --git a/frontend/src/__tests__/pages/QueuePage.test.tsx b/frontend/src/__tests__/pages/QueuePage.test.tsx index 2a0fe39c7..6a509b171 100644 --- a/frontend/src/__tests__/pages/QueuePage.test.tsx +++ b/frontend/src/__tests__/pages/QueuePage.test.tsx @@ -719,7 +719,7 @@ describe('QueuePage', () => { }); describe('stored mapping on the live printer (#3132)', () => { - const mappedItem = (amsMapping: number[]) => ({ + const mappedItem = (amsMapping: number[], extra: Record = {}) => ({ ...mockQueueItems[0], id: 88, printer_id: 1, @@ -739,11 +739,16 @@ describe('QueuePage', () => { force_color_match: false, }, ], + ...extra, }); - const useMappedPrinter = (amsMapping: number[], status: Record) => { + const useMappedPrinter = ( + amsMapping: number[], + status: Record, + item: Record = {}, + ) => { server.use( - http.get('/api/v1/queue/', () => HttpResponse.json([mappedItem(amsMapping)])), + http.get('/api/v1/queue/', () => HttpResponse.json([mappedItem(amsMapping, item)])), http.get('/api/v1/library/files/19/plates', () => HttpResponse.json({ file_id: 19, @@ -827,6 +832,74 @@ describe('QueuePage', () => { expect(within(row).getByTestId('filament-swatch')).toHaveAttribute('title', '#8E351B'); }); + describe('AMS Filament Backup during the print', () => { + const printing = { status: 'printing', started_at: '2024-01-01T10:00:00Z' }; + + it('shows the backup spool the printer switched to', async () => { + // A3 ran out at layer 350 and the printer carried on from A2. + useMappedPrinter( + [2], + { connected: true, state: 'RUNNING', ams: amsWithEmptyA3, vt_tray: [], tray_change_log: [[2, 0], [1, 350]] }, + printing, + ); + const row = await mappedRow(); + + await waitFor(() => { + expect(within(row).getByText(/^A2 · PLA · /)).toBeInTheDocument(); + }); + expect(within(row).queryByText(/Empty/)).not.toBeInTheDocument(); + }); + + it('follows a backup that ran out in turn', async () => { + useMappedPrinter( + [2], + { + connected: true, + state: 'RUNNING', + ams: amsWithEmptyA3, + vt_tray: [], + tray_change_log: [[2, 0], [1, 120], [0, 400]], + }, + printing, + ); + const row = await mappedRow(); + + await waitFor(() => { + expect(within(row).getByText(/^A1 · PLA · /)).toBeInTheDocument(); + }); + expect(within(row).queryByText(/^A2 · /)).not.toBeInTheDocument(); + }); + + it('does not take a change to another mapped slot for a backup', async () => { + // Slot 2 of the job feeds from A2: switching there is a colour change. + useMappedPrinter( + [2, 1], + { connected: true, state: 'RUNNING', ams: amsWithEmptyA3, vt_tray: [], tray_change_log: [[2, 0], [1, 30]] }, + printing, + ); + const row = await mappedRow(); + + await waitFor(() => { + expect(within(row).getByText('A3 · Empty · Caramel')).toBeInTheDocument(); + }); + }); + + it('leaves a queued job pointed at its mapped slot', async () => { + // The log belongs to whatever the printer prints now, not this job. + useMappedPrinter([2], { + connected: true, + ams: amsWithEmptyA3, + vt_tray: [], + tray_change_log: [[2, 0], [1, 350]], + }); + const row = await mappedRow(); + + await waitFor(() => { + expect(within(row).getByText('A3 · Empty · Caramel')).toBeInTheDocument(); + }); + }); + }); + it('never calls the external spool empty, having no presence signal', async () => { // Shape the status route really sends: an external tray carries no // state / exists, so an unconfigured spool and no spool look the same. diff --git a/frontend/src/api/client.ts b/frontend/src/api/client.ts index 4495412d1..da723b907 100644 --- a/frontend/src/api/client.ts +++ b/frontend/src/api/client.ts @@ -699,6 +699,10 @@ export interface PrinterStatus { extruder_slots: Record; // Currently loaded tray (global tray ID, 255 = no filament loaded, 254 = external spool) tray_now: number; + // The trays this print has drawn from, in order: [global tray ID, layer of the + // switch]. A tray outside the job's AMS mapping is a backup spool the printer + // switched to (AMS Filament Backup). Reset at the start of each print. + tray_change_log?: [number, number][]; // Runout / filament-replacement guidance (#2587). Populated only while PAUSED. // Global tray IDs (ams_id*4+slot, 128-135 = AMS-HT, 254 = external), matching // the same numbering as tray_now so the AMS graphic can highlight them. diff --git a/frontend/src/pages/QueuePage.tsx b/frontend/src/pages/QueuePage.tsx index 69c6c0bf0..d3f095f46 100644 --- a/frontend/src/pages/QueuePage.tsx +++ b/frontend/src/pages/QueuePage.tsx @@ -122,6 +122,35 @@ function emptyMappedSlotLabel(status: PrinterStatus | undefined, trayId: number) return formatSlotLabel(amsId, slot, isHt, false); } +/** + * The backup tray each mapped tray handed over to during the running print. + * + * With AMS Filament Backup on, a spool that runs out is replaced by an identical + * one in another slot, and the job's stored mapping still names the empty slot. + * The printer's tray log shows the switch: a tray the mapping doesn't name, right + * after the tray it took over from. A backup that runs out in turn hands over + * again, so the chain resolves to the slot the mapping named. + */ +function backupTrays(mapping: number[] | null | undefined, log: [number, number][] | undefined): Map { + const backups = new Map(); + if (!mapping?.length || !log?.length) return backups; + const mapped = new Set(mapping.filter((tray) => tray >= 0)); + // Backup tray -> the mapped tray it stands in for. + const standsInFor = new Map(); + let previous: number | undefined; + for (const [tray] of log) { + if (previous !== undefined && !mapped.has(tray) && !standsInFor.has(tray)) { + const original = mapped.has(previous) ? previous : standsInFor.get(previous); + if (original !== undefined) { + standsInFor.set(tray, original); + backups.set(original, tray); + } + } + previous = tray; + } + return backups; +} + function queueFilamentLabel(filament: QueueFilamentDisplay): string { return filament.slotLabel ? [ @@ -151,10 +180,15 @@ function resolveQueueFilaments( // slot. Once its live tray data is available, that is more specific than // either the queue override or the original slice. When the printer reports // that tray as empty, keep the intended colour but say the slot is empty. + // While the job prints, a slot whose spool ran out shows the backup spool the + // printer switched to instead. + const backups = + item.status === 'printing' ? backupTrays(item.ams_mapping, status?.tray_change_log) : new Map(); const resolveSlot = (planned: QueueFilamentDisplay): QueueFilamentDisplay => { const slotId = planned.slotId; - const mappedTrayId = slotId > 0 ? item.ams_mapping?.[slotId - 1] : undefined; - if (mappedTrayId == null || mappedTrayId < 0) return planned; + const storedTrayId = slotId > 0 ? item.ams_mapping?.[slotId - 1] : undefined; + if (storedTrayId == null || storedTrayId < 0) return planned; + const mappedTrayId = backups.get(storedTrayId) ?? storedTrayId; const loaded = loadedFilaments.find((filament) => filament.globalTrayId === mappedTrayId); if (loaded) { return { diff --git a/static/assets/AdditionalSection-BgleEt_Y.js b/static/assets/AdditionalSection-9uxxm13d.js similarity index 99% rename from static/assets/AdditionalSection-BgleEt_Y.js rename to static/assets/AdditionalSection-9uxxm13d.js index fcd90fef5..b81aa07f5 100644 --- a/static/assets/AdditionalSection-BgleEt_Y.js +++ b/static/assets/AdditionalSection-9uxxm13d.js @@ -1 +1 @@ -import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,w as r}from"./client-DnySrlFv.js";import{a as i,i as a}from"./info-ROUoQhJR.js";import{n as o}from"./ToastContext-BRX0SW3C.js";import{t as s}from"./cloud-off-DfYbNG2N.js";import{t as c}from"./loader-circle-BEmFtawu.js";import{t as l}from"./scale-CD6XdXUk.js";import{t as u}from"./search-0n0CBc74.js";import{t as d}from"./sparkles-DRqKNlhr.js";import{t as f}from"./x-DR-Trv6U.js";import{y as p}from"./date-G9KUauqz.js";import{n as m,t as h}from"./filamentSwatchHelpers-D3oXQSGk.js";import{Dn as g,N as _,On as v,lt as y,w as b}from"./index-0t--Yqoi.js";import{_ as x,h as S,u as C,y as w}from"./utils-DVekehs6.js";var T={material:``,subtype:``,brand:``,color_name:``,rgba:`808080FF`,extra_colors:``,effect_type:``,label_weight:1e3,core_weight:250,core_weight_catalog_id:null,weight_used:0,slicer_filament:``,note:``,cost_per_kg:null,category:``,low_stock_threshold_pct:null,material_number:``,location_id:null,last_dried_at:``,spoolman_filament_id:null},E=new Set([`material`,`subtype`,`brand`,`rgba`,`color_name`,`label_weight`]);function D(e,t=!1,n=!1,r=`create`){let i={};return t||n||r!==`create`?(!e.material&&!e.spoolman_filament_id&&(i.material=`Material is required`),{isValid:Object.keys(i).length===0,errors:i}):(e.slicer_filament||(i.slicer_filament=`Slicer preset is required`),e.material||(i.material=`Material is required`),e.brand||(i.brand=`Brand is required`),e.subtype||(i.subtype=`Subtype is required`),{isValid:Object.keys(i).length===0,errors:i})}var O=e(n(),1),k=t(),A={local:`bg-green-100 dark:bg-green-500/20 text-green-700 dark:text-green-400`,orca_cloud:`bg-purple-100 dark:bg-purple-500/20 text-purple-700 dark:text-purple-400`,cloud:`bg-bambu-blue/20 text-bambu-blue`,builtin:`bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400`};function j({source:e}){let{t}=r(),n={local:t(`profiles.localProfiles.badge`),orca_cloud:t(`configureAmsSlot.orcaCloud`),cloud:t(`configureAmsSlot.bambuCloud`),builtin:t(`configureAmsSlot.builtin`)}[e];return(0,k.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded whitespace-nowrap ${A[e]}`,children:n})}function M({value:e,options:t,inheritLabel:n,onChange:a,disabled:o=!1,ariaLabel:s}){let{t:c}=r(),[l,d]=(0,O.useState)(!1),[p,m]=(0,O.useState)(``),h=(0,O.useRef)(null),g=t.find(t=>t.code===e);(0,O.useEffect)(()=>{if(!l)return;let e=e=>{h.current&&!h.current.contains(e.target)&&d(!1)},t=e=>{e.key===`Escape`&&(e.stopPropagation(),d(!1))};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t,!0),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t,!0)}},[l]);let _=p.trim().toLowerCase(),v=_?t.filter(e=>e.displayName.toLowerCase().includes(_)):t,y=e=>{a(e),d(!1),m(``)};return(0,k.jsxs)(`div`,{className:`relative`,ref:h,children:[(0,k.jsxs)(`button`,{type:`button`,"aria-label":s,"aria-haspopup":`listbox`,"aria-expanded":l,disabled:o,onClick:()=>d(e=>!e),className:`w-full flex items-center gap-2 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-sm text-left focus:outline-none focus:border-bambu-green disabled:opacity-50`,children:[(0,k.jsx)(`span`,{className:`flex-1 min-w-0 truncate ${g?`text-white`:`text-bambu-gray italic`}`,children:g?g.displayName:n}),g&&(0,k.jsx)(j,{source:g.source}),(0,k.jsx)(i,{className:`w-3.5 h-3.5 text-bambu-gray shrink-0`})]}),l&&(0,k.jsxs)(`div`,{className:`absolute z-50 mt-1 w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl`,children:[(0,k.jsx)(`div`,{className:`p-2 border-b border-bambu-dark-tertiary`,children:(0,k.jsxs)(`div`,{className:`relative`,children:[(0,k.jsx)(u,{className:`w-3.5 h-3.5 text-bambu-gray absolute left-2 top-1/2 -translate-y-1/2`}),(0,k.jsx)(`input`,{autoFocus:!0,type:`text`,value:p,onChange:e=>m(e.target.value),placeholder:c(`inventory.searchPresets`),className:`w-full pl-7 pr-7 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded-md text-sm text-white placeholder:text-bambu-gray/60 focus:outline-none focus:border-bambu-green`}),p&&(0,k.jsx)(`button`,{type:`button`,"aria-label":c(`common.clear`),onClick:()=>m(``),className:`absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white`,children:(0,k.jsx)(f,{className:`w-3.5 h-3.5`})})]})}),(0,k.jsxs)(`div`,{className:`max-h-56 overflow-y-auto p-1`,role:`listbox`,"aria-label":s,children:[(0,k.jsx)(`button`,{type:`button`,role:`option`,"aria-selected":!g,onClick:()=>y(null),className:`w-full text-left px-2 py-1.5 rounded-md text-sm italic ${g?`text-bambu-gray hover:bg-bambu-dark`:`bg-bambu-green/15 text-bambu-green`}`,children:n}),v.length===0?(0,k.jsx)(`p`,{className:`px-2 py-2 text-sm text-bambu-gray`,children:c(`inventory.noResults`)}):v.map(t=>(0,k.jsxs)(`button`,{type:`button`,role:`option`,"aria-selected":t.code===e,onClick:()=>y(t),className:`w-full flex items-center gap-2 text-left px-2 py-1.5 rounded-md text-sm ${t.code===e?`bg-bambu-green/15 text-bambu-green`:`text-white hover:bg-bambu-dark`}`,children:[(0,k.jsx)(`span`,{className:`flex-1 min-w-0 truncate`,title:t.displayName,children:t.displayName}),(0,k.jsx)(j,{source:t.source})]},t.code))]})]})]})}function N(e,t){if(t.length===0)return{top:[],rest:e};let n=new Set(t.map(e=>e.toLowerCase()));return{top:e.filter(e=>n.has(e.toLowerCase())),rest:e.filter(e=>!n.has(e.toLowerCase()))}}function P({label:e}){return(0,k.jsx)(`div`,{className:`px-3 py-1 text-[11px] font-semibold uppercase tracking-wide text-bambu-gray/70 bg-bambu-dark-tertiary/40`,children:e})}function F({formData:e,updateField:t,cloudAuthenticated:n,loadingCloudPresets:a,presetInputValue:o,setPresetInputValue:l,selectedPresetOption:d,filamentOptions:f,availableBrands:p,availableMaterials:m,suggestedBrands:h,suggestedMaterials:v,quickAdd:y,detailsRequired:b,quantity:S,onQuantityChange:w,errors:T}){let{t:E}=r(),[D,A]=(0,O.useState)(!1),[M,F]=(0,O.useState)(!1),[I,L]=(0,O.useState)(!1),[R,z]=(0,O.useState)(!1),[B,V]=(0,O.useState)(``),[H,U]=(0,O.useState)(``),[W,G]=(0,O.useState)(``),[ee,K]=(0,O.useState)(String(e.label_weight)),[te,ne]=(0,O.useState)(!1),[re,ie]=(0,O.useState)(new Set),q=(0,O.useRef)(null),J=(0,O.useRef)(null),ae=(0,O.useRef)(null),oe=(0,O.useRef)(null);(0,O.useEffect)(()=>{let e=e=>{q.current&&!q.current.contains(e.target)&&A(!1),oe.current&&!oe.current.contains(e.target)&&z(!1),J.current&&!J.current.contains(e.target)&&F(!1),ae.current&&!ae.current.contains(e.target)&&L(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[]);let se=(0,O.useMemo)(()=>{if(!o)return f;let e=o.toLowerCase();return f.filter(t=>t.displayName.toLowerCase().includes(e)||t.code.toLowerCase().includes(e))},[f,o]),Y=(0,O.useMemo)(()=>{if(!B)return p;let e=B.toLowerCase();return p.filter(t=>t.toLowerCase().includes(e)).sort((t,n)=>{let r=t.toLowerCase()===e,i=n.toLowerCase()===e;return r&&!i?-1:!r&&i?1:t.localeCompare(n)})},[p,B]),ce=(0,O.useMemo)(()=>{if(!H)return x;let e=H.toLowerCase();return x.filter(t=>t.toLowerCase().includes(e))},[H]),X=(0,O.useMemo)(()=>{if(!W)return m;let e=W.toLowerCase();return m.filter(t=>t.toLowerCase().includes(e)).sort((t,n)=>{let r=t.toLowerCase()===e,i=n.toLowerCase()===e;return r&&!i?-1:!r&&i?1:t.localeCompare(n)})},[W,m]),Z=(0,O.useMemo)(()=>N(Y,h),[Y,h]),Q=(0,O.useMemo)(()=>N(X,v),[X,v]);(0,O.useEffect)(()=>{te||K(String(e.label_weight))},[e.label_weight,te]);let le=n=>{t(`slicer_filament`,n.code),l(n.displayName),A(!1);let r=C(n.name),i=new Set,a=[[`material`,r.material],[`brand`,r.brand],[`subtype`,r.variant]];for(let[n,r]of a)r&&(e[n]&&!re.has(n)||(t(n,r),i.add(n)));ie(i)},$=(e,n)=>{re.has(e)&&ie(t=>{let n=new Set(t);return n.delete(e),n}),t(e,n)},ue=t=>(0,k.jsx)(`button`,{type:`button`,className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${e.brand===t?`bg-bambu-green/10 text-bambu-green`:`text-white`}`,onClick:()=>{$(`brand`,t),F(!1),V(``)},children:t},t),de=t=>(0,k.jsx)(`button`,{type:`button`,className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${e.material===t?`bg-bambu-green/10 text-bambu-green`:`text-white`}`,onClick:()=>{$(`material`,t),z(!1),G(``)},children:t},t);return(0,k.jsxs)(`div`,{className:`space-y-4`,children:[!y&&(0,k.jsx)(`div`,{className:`flex items-center gap-2 text-xs text-bambu-gray`,children:a?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(c,{className:`w-3 h-3 animate-spin`}),` `,E(`inventory.loadingPresets`)]}):n?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(g,{className:`w-3 h-3 text-bambu-green`}),` `,E(`inventory.cloudConnected`)]}):(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(s,{className:`w-3 h-3`}),` `,E(`inventory.cloudNotConnected`)]})}),!y&&(0,k.jsxs)(`div`,{children:[(0,k.jsxs)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:[E(`inventory.slicerPreset`),b&&` *`]}),(0,k.jsxs)(`div`,{className:`relative`,ref:q,children:[(0,k.jsx)(u,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50 pointer-events-none`}),(0,k.jsx)(`input`,{type:`text`,className:`w-full pl-9 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`,placeholder:E(`inventory.searchPresets`),value:o,onChange:e=>{l(e.target.value),A(!0)},onFocus:()=>{A(!0),l(``)}}),D&&(0,k.jsx)(`div`,{className:`absolute z-50 w-full mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-64 overflow-y-auto`,children:se.length===0?(0,k.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:E(`inventory.noPresetsFound`)}):se.map(e=>(0,k.jsxs)(`button`,{type:`button`,className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary flex items-center gap-2 ${d?.code===e.code?`bg-bambu-green/10 text-bambu-green`:`text-white`}`,onClick:()=>le(e),children:[(0,k.jsx)(`span`,{className:`flex-1 min-w-0 truncate`,title:e.displayName,children:e.displayName}),(0,k.jsx)(j,{source:e.source})]},`${e.code}::${e.name}`))})]}),d&&(0,k.jsxs)(`div`,{className:`mt-1 text-xs text-bambu-gray`,children:[E(`inventory.selectedPreset`),`: `,(0,k.jsx)(`span`,{className:`font-mono text-bambu-green`,children:d.code})]}),T?.slicer_filament&&(0,k.jsx)(`p`,{className:`mt-1 text-xs text-red-700 dark:text-red-400`,children:T.slicer_filament})]}),(0,k.jsxs)(`div`,{children:[(0,k.jsxs)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:[E(`inventory.material`),` *`]}),(0,k.jsxs)(`div`,{className:`relative`,ref:oe,children:[(0,k.jsx)(`input`,{type:`text`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`,placeholder:E(`inventory.selectMaterial`),value:R?W:e.material,onChange:e=>{G(e.target.value),z(!0)},onFocus:()=>{z(!0),G(``)}}),(0,k.jsx)(i,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50 pointer-events-none`}),R&&(0,k.jsxs)(`div`,{className:`absolute z-50 w-full mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-48 overflow-y-auto`,children:[X.length===0?(0,k.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:E(`inventory.noResults`)}):(0,k.jsxs)(k.Fragment,{children:[Q.top.length>0&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(P,{label:E(`inventory.suggestedOptions`)}),Q.top.map(de)]}),Q.rest.length>0&&(0,k.jsxs)(k.Fragment,{children:[Q.top.length>0&&(0,k.jsx)(P,{label:E(`inventory.allOptions`)}),Q.rest.map(de)]})]}),W&&!X.includes(W)&&(0,k.jsx)(`button`,{type:`button`,className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary text-bambu-green border-t border-bambu-dark-tertiary`,onClick:()=>{$(`material`,W),z(!1),G(``)},children:E(`inventory.useCustomMaterial`,{material:W})})]})]}),T?.material&&(0,k.jsx)(`p`,{className:`mt-1 text-xs text-red-700 dark:text-red-400`,children:T.material})]}),(0,k.jsxs)(`div`,{children:[(0,k.jsxs)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:[E(`inventory.brand`),b&&` *`]}),(0,k.jsxs)(`div`,{className:`relative`,ref:J,children:[(0,k.jsx)(`input`,{type:`text`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`,placeholder:E(`inventory.searchBrand`),value:M?B:e.brand,onChange:e=>{V(e.target.value),F(!0)},onFocus:()=>{F(!0),V(``)}}),(0,k.jsx)(i,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50 pointer-events-none`}),M&&(0,k.jsxs)(`div`,{className:`absolute z-50 w-full mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-48 overflow-y-auto`,children:[Y.length===0?(0,k.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:E(`inventory.noResults`)}):(0,k.jsxs)(k.Fragment,{children:[Z.top.length>0&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(P,{label:E(`inventory.suggestedOptions`)}),Z.top.map(ue)]}),Z.rest.length>0&&(0,k.jsxs)(k.Fragment,{children:[Z.top.length>0&&(0,k.jsx)(P,{label:E(`inventory.allOptions`)}),Z.rest.map(ue)]})]}),B&&!Y.includes(B)&&(0,k.jsx)(`button`,{type:`button`,className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary text-bambu-green border-t border-bambu-dark-tertiary`,onClick:()=>{$(`brand`,B),F(!1),V(``)},children:E(`inventory.useCustomBrand`,{brand:B})})]})]}),T?.brand&&(0,k.jsx)(`p`,{className:`mt-1 text-xs text-red-700 dark:text-red-400`,children:T.brand})]}),(0,k.jsxs)(`div`,{children:[(0,k.jsxs)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:[E(`inventory.subtype`),b&&` *`]}),(0,k.jsxs)(`div`,{className:`relative`,ref:ae,children:[(0,k.jsx)(`input`,{type:`text`,value:I?H:e.subtype,onChange:e=>{U(e.target.value),L(!0)},onFocus:()=>{L(!0),U(``)},placeholder:`Basic, Matte, Silk...`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`}),(0,k.jsx)(i,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50 pointer-events-none`}),I&&(0,k.jsxs)(`div`,{className:`absolute z-50 w-full mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-48 overflow-y-auto`,children:[ce.length===0?(0,k.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:E(`inventory.noResults`)}):ce.map(t=>(0,k.jsx)(`button`,{type:`button`,className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${e.subtype===t?`bg-bambu-green/10 text-bambu-green`:`text-white`}`,onClick:()=>{$(`subtype`,t),L(!1),U(``)},children:t},t)),H&&!x.some(e=>e.toLowerCase()===H.toLowerCase().trim())&&(0,k.jsx)(`button`,{type:`button`,className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary text-bambu-green border-t border-bambu-dark-tertiary`,onClick:()=>{$(`subtype`,H),L(!1),U(``)},children:E(`inventory.useCustomBrand`,{brand:H})})]})]}),T?.subtype&&(0,k.jsx)(`p`,{className:`mt-1 text-xs text-red-700 dark:text-red-400`,children:T.subtype})]}),(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:E(`inventory.labelWeight`)}),(0,k.jsxs)(`div`,{className:`relative`,children:[(0,k.jsx)(`input`,{type:`number`,className:`w-full px-3 py-2 pr-7 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`,value:ee,min:0,onFocus:()=>ne(!0),onChange:e=>K(e.target.value),onBlur:()=>{ne(!1);let n=ee.trim(),r=Number(n);if(!n||!Number.isFinite(r)||r<0){K(String(e.label_weight));return}let i=Math.round(r);t(`label_weight`,i),K(String(i))}}),(0,k.jsx)(`span`,{className:`absolute right-2 top-1/2 -translate-y-1/2 text-xs text-bambu-gray`,children:`g`})]})]}),y&&(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:E(`inventory.quantity`)}),(0,k.jsx)(_,{className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`,value:S,min:1,max:100,onChange:w,fallback:1})]})]})}function I(e){let t=e.split(/[\s,]+/).map(e=>e.trim().replace(/^#/,``)).filter(Boolean),n=[],r=[];for(let e of t)(e.length===6||e.length===8)&&/^[0-9a-fA-F]+$/.test(e)?n.push(e.toLowerCase()):r.push(e);return{value:n.join(`,`),invalid:r}}function L({formData:e,updateField:t,recentColors:n,onColorUsed:o,catalogColors:s}){let{t:c}=r(),[l,f]=(0,O.useState)(!1),[p,g]=(0,O.useState)(``),_=(e.rgba.replace(`#`,``)+`FF`).substring(0,8).toUpperCase(),x=_.substring(0,6),C=_.substring(6,8)===`00`,[T,E]=(0,O.useState)(C?_:x);(0,O.useEffect)(()=>{E(C?_:x)},[x,_,C]);let D=e=>_===(e.replace(`#`,``)+`FF`).substring(0,8).toUpperCase(),A=e=>y(e),j=(e,n,r,i)=>{let a=e.replace(`#`,``).toUpperCase();if(t(`rgba`,a.length===8?a:a+`FF`),t(`color_name`,n),r!==void 0){let e=r??``;R(e),B([]),V.current=e,t(`extra_colors`,e)}i!==void 0&&t(`effect_type`,i??``),o({name:n,hex:e})},M=(0,O.useMemo)(()=>{if(s.length===0)return[];let t=e.brand?.trim(),n=e.material?.toLowerCase().trim(),r=e.subtype?.toLowerCase().trim();if(!t&&!n)return[];let i=t?t.toLowerCase().split(/[\s\-_]+/).filter(e=>e.length>=2):[],a=e=>{if(i.length===0)return!0;let t=e.toLowerCase();return i.some(e=>t.includes(e))};if(t&&!n){let e=s.filter(e=>a(e.manufacturer));if(e.length>0)return e.map(e=>({name:e.color_name,hex:e.hex_color.replace(`#`,``).substring(0,6),manufacturer:e.manufacturer,material:typeof e.material==`string`?e.material:void 0,extra_colors:e.extra_colors??null,effect_type:e.effect_type??null}))}let o=n&&r?`${n} ${r}`:``;if(o){let e=s.filter(e=>a(e.manufacturer)&&e.material?.toLowerCase()===o);if(e.length>0)return e.map(e=>({name:e.color_name,hex:e.hex_color.replace(`#`,``).substring(0,6),manufacturer:e.manufacturer,material:typeof e.material==`string`?e.material:void 0,extra_colors:e.extra_colors??null,effect_type:e.effect_type??null}));let t=o.replace(/\+$/,``);if(t!==o){let e=s.filter(e=>a(e.manufacturer)&&e.material?.toLowerCase()===t);if(e.length>0)return e.map(e=>({name:e.color_name,hex:e.hex_color.replace(`#`,``).substring(0,6),manufacturer:e.manufacturer,material:typeof e.material==`string`?e.material:void 0}))}}if(n){let e=s.filter(e=>a(e.manufacturer)&&(!e.material||e.material.toLowerCase().startsWith(n)));if(e.length>0)return e.map(e=>({name:e.color_name,hex:e.hex_color.replace(`#`,``).substring(0,6),manufacturer:e.manufacturer,material:typeof e.material==`string`?e.material:void 0,extra_colors:e.extra_colors??null,effect_type:e.effect_type??null}))}return[]},[s,e.brand,e.material,e.subtype]),N=(0,O.useMemo)(()=>{if(!p)return M;if(M.length===0)return[];let e=p.toLowerCase();return M.filter(t=>t.name.toLowerCase().includes(e)||(t.manufacturer?.toLowerCase().includes(e)??!1)||(t.material?.toLowerCase().includes(e)??!1))},[p,M]),P=M.length>0,F=(0,O.useMemo)(()=>p?S.filter(e=>e.name.toLowerCase().includes(p.toLowerCase())):l?S:w,[p,l]),[L,R]=(0,O.useState)(e.extra_colors),[z,B]=(0,O.useState)([]),V=(0,O.useRef)(e.extra_colors);(0,O.useEffect)(()=>{e.extra_colors!==V.current&&(R(e.extra_colors),B([]),V.current=e.extra_colors)},[e.extra_colors]);let H=(0,O.useMemo)(()=>m({rgba:e.rgba,extraColors:e.extra_colors,effectType:e.effect_type,subtype:e.subtype,effectSize:`bar`}),[e.rgba,e.extra_colors,e.effect_type,e.subtype]),U=e=>{if(R(e),!e.trim()){B([]),V.current=``,t(`extra_colors`,``);return}let{value:n,invalid:r}=I(e);B(r),V.current=n,t(`extra_colors`,n)};return(0,k.jsxs)(`div`,{className:`space-y-3`,children:[(0,k.jsx)(`div`,{className:`h-10 rounded-lg border border-bambu-dark-tertiary`,style:H,"data-testid":`color-preview-banner`}),n.length>0&&(0,k.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,k.jsxs)(`div`,{className:`flex items-center gap-1.5 text-xs text-bambu-gray shrink-0`,children:[(0,k.jsx)(v,{className:`w-3 h-3`}),(0,k.jsx)(`span`,{children:c(`inventory.recentColors`)})]}),(0,k.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:n.map(e=>(0,k.jsx)(`button`,{type:`button`,onClick:()=>j(e.hex,e.name),className:`w-6 h-6 rounded border-2 transition-all hover:scale-110 ${D(e.hex)?`border-bambu-green ring-1 ring-bambu-green/30 scale-110`:`border-bambu-dark-tertiary`}`,style:A(e.hex),title:e.name},e.hex))})]}),(0,k.jsxs)(`div`,{className:`relative`,children:[(0,k.jsx)(u,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50 pointer-events-none`}),(0,k.jsx)(`input`,{type:`text`,className:`w-full pl-9 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`,placeholder:c(`inventory.searchColors`),value:p,onChange:e=>g(e.target.value)})]}),P?(0,k.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,k.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:p?c(`inventory.searchResults`):`${e.brand}${e.material?` ${e.material}`:``}`}),(0,k.jsxs)(`div`,{className:`flex flex-wrap gap-1.5`,children:[N.map(e=>(0,k.jsx)(`button`,{type:`button`,onClick:()=>j(e.hex,e.name,e.extra_colors,e.effect_type),className:`w-6 h-6 rounded border-2 transition-all hover:scale-110 hover:z-20 relative group ${D(e.hex)?`border-bambu-green ring-1 ring-bambu-green/30 scale-110`:`border-bambu-dark-tertiary`}`,style:A(e.hex),title:e.manufacturer&&e.material?`${e.name} (${e.manufacturer} — ${e.material})`:e.manufacturer?`${e.name} (${e.manufacturer})`:e.name,children:(0,k.jsx)(`span`,{className:`absolute -bottom-7 left-1/2 -translate-x-1/2 px-2 py-0.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-xs whitespace-nowrap opacity-0 group-hover:opacity-100 transition-opacity pointer-events-none z-20 shadow-lg text-white`,children:e.manufacturer&&e.material?`${e.name} (${e.manufacturer} — ${e.material})`:e.manufacturer?`${e.name} (${e.manufacturer})`:e.name})},`${e.hex}-${e.name}-${e.manufacturer??``}`)),N.length===0&&(0,k.jsx)(`p`,{className:`text-sm text-bambu-gray py-1`,children:c(`inventory.noColorsFound`)})]})]}):(0,k.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,k.jsxs)(`div`,{className:`flex items-center justify-between text-xs text-bambu-gray`,children:[(0,k.jsx)(`span`,{children:c(p?`inventory.searchResults`:l?`inventory.allColors`:`inventory.commonColors`)}),!p&&(0,k.jsx)(`button`,{type:`button`,onClick:()=>f(!l),className:`flex items-center gap-1 hover:text-white transition-colors`,children:l?(0,k.jsxs)(k.Fragment,{children:[c(`inventory.showLess`),` `,(0,k.jsx)(a,{className:`w-3 h-3`})]}):(0,k.jsxs)(k.Fragment,{children:[c(`inventory.showAll`),` `,(0,k.jsx)(i,{className:`w-3 h-3`})]})})]}),(0,k.jsxs)(`div`,{className:`flex flex-wrap gap-1.5`,children:[F.map(e=>(0,k.jsx)(`button`,{type:`button`,onClick:()=>j(e.hex,e.name),className:`w-6 h-6 rounded border-2 transition-all hover:scale-110 hover:z-20 relative group ${D(e.hex)?`border-bambu-green ring-1 ring-bambu-green/30 scale-110`:`border-bambu-dark-tertiary`}`,style:A(e.hex),title:e.name,children:(0,k.jsx)(`span`,{className:`absolute -bottom-7 left-1/2 -translate-x-1/2 px-2 py-0.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-xs whitespace-nowrap opacity-0 group-hover:opacity-100 transition-opacity pointer-events-none z-20 shadow-lg text-white`,children:e.name})},e.hex)),F.length===0&&(0,k.jsx)(`p`,{className:`text-sm text-bambu-gray py-1`,children:c(`inventory.noColorsFound`)})]})]}),(0,k.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:c(`inventory.colorName`)}),(0,k.jsx)(`input`,{type:`text`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`,placeholder:c(`inventory.colorNamePlaceholder`),value:e.color_name,onChange:e=>t(`color_name`,e.target.value)})]}),(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:c(`inventory.hexColor`)}),(0,k.jsxs)(`div`,{className:`flex gap-2`,children:[(0,k.jsxs)(`div`,{className:`relative flex-1`,children:[(0,k.jsx)(`span`,{className:`absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray`,children:`#`}),(0,k.jsx)(`input`,{type:`text`,className:`w-full pl-7 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm font-mono uppercase focus:outline-none focus:border-bambu-green`,placeholder:`RRGGBB`,value:T.toUpperCase(),onChange:e=>{let n=e.target.value.replace(`#`,``).replace(/[^0-9A-Fa-f]/g,``).toUpperCase(),r=n.length>8?n.substring(0,8):n;E(r),r.length===6?t(`rgba`,r+`FF`):r.length===8&&t(`rgba`,r)},onBlur:()=>{if(T.length===7){let e=T+`0`;E(e),t(`rgba`,e)}else if(T.length>0&&T.length<6){let e=T.padEnd(6,`0`);E(e),t(`rgba`,e+`FF`)}}})]}),(0,k.jsx)(`input`,{type:`color`,className:`w-11 h-[38px] rounded-lg cursor-pointer border border-bambu-dark-tertiary shrink-0 bg-transparent`,value:`#${x}`,onChange:e=>{t(`rgba`,e.target.value.replace(`#`,``).toUpperCase()+`FF`)},title:c(`inventory.pickColor`)})]})]})]}),(0,k.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3 pt-2 border-t border-bambu-dark-tertiary/50`,children:[(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:c(`inventory.extraColorsLabel`)}),(0,k.jsx)(`input`,{type:`text`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm font-mono placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`,placeholder:c(`inventory.extraColorsPlaceholder`),value:L,onChange:e=>U(e.target.value),"data-testid":`extra-colors-input`}),z.length>0&&(0,k.jsx)(`p`,{className:`text-xs text-red-700 dark:text-red-400 mt-1`,children:c(`inventory.extraColorsInvalid`,{tokens:z.join(`, `)})}),!z.length&&(0,k.jsx)(`p`,{className:`text-xs text-bambu-gray/70 mt-1`,children:c(`inventory.extraColorsHint`)})]}),(0,k.jsxs)(`div`,{children:[(0,k.jsxs)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1 flex items-center gap-1.5`,children:[(0,k.jsx)(d,{className:`w-3.5 h-3.5`}),c(`inventory.colorEffectLabel`)]}),(0,k.jsxs)(`div`,{className:`flex gap-2 items-stretch`,children:[(0,k.jsx)(`select`,{className:`flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`,value:e.effect_type,onChange:e=>t(`effect_type`,e.target.value),"data-testid":`effect-type-select`,children:h.map(e=>(0,k.jsx)(`option`,{value:e.value,children:c(e.labelKey)},e.value||`none`))}),(0,k.jsx)(b,{rgba:e.rgba,extraColors:e.extra_colors,effectType:e.effect_type,subtype:e.subtype,effectSize:`preview`,className:`w-10 h-10`,shape:`square`})]})]})]})]})}function R({catalog:e,value:t,onChange:n,catalogId:i,onCatalogIdChange:a}){let{t:o}=r(),[s,c]=(0,O.useState)(!1),[u,d]=(0,O.useState)(``),f=(0,O.useRef)(null),p=(0,O.useRef)(null);(0,O.useEffect)(()=>{let e=e=>{f.current&&!f.current.contains(e.target)&&c(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[]),(0,O.useEffect)(()=>{if(e.length===0)return;let n=e.filter(e=>e.weight===t);if(i){let n=e.find(e=>e.id===i);if(n&&n.weight===t)return}n.length===1?a(n[0].id):n.length===0&&i!==null&&a(null)},[t,e,i,a]);let m=(0,O.useMemo)(()=>{if(!u)return e;let t=u.toLowerCase();return e.filter(e=>e.name.toLowerCase().includes(t)||e.weight.toString().includes(t))},[e,u]),h=(0,O.useMemo)(()=>e.filter(e=>e.weight===t),[e,t]),g=(0,O.useMemo)(()=>{if(s)return u;if(i){let t=e.find(e=>e.id===i);if(t)return t.name}return h.length>0?h[0].name:``},[s,u,i,e,h]);return(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:(0,k.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,k.jsx)(l,{className:`w-3.5 h-3.5 text-bambu-gray`}),o(`inventory.coreWeight`)]})}),(0,k.jsxs)(`div`,{className:`flex gap-2 items-center`,children:[(0,k.jsxs)(`div`,{className:`flex-1 min-w-0 relative`,ref:f,children:[(0,k.jsx)(`input`,{ref:p,type:`text`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`,placeholder:o(`inventory.searchSpoolWeight`),value:g,onFocus:()=>{c(!0),d(``)},onChange:e=>{d(e.target.value),c(!0)}}),s&&(0,k.jsx)(`div`,{className:`absolute z-50 w-full mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-64 overflow-y-auto`,children:m.length===0?(0,k.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:o(`inventory.noResults`)}):m.map(e=>(0,k.jsxs)(`button`,{type:`button`,className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary flex justify-between items-center ${(i?e.id===i:e.weight===t)?`bg-bambu-green/10 text-bambu-green`:`text-white`}`,onClick:()=>{a(e.id),n(e.weight),c(!1),d(``)},children:[(0,k.jsx)(`span`,{className:`truncate`,children:e.name}),(0,k.jsxs)(`span`,{className:`font-mono text-xs text-bambu-gray ml-2 shrink-0`,children:[e.weight,`g`]})]},e.id))})]}),(0,k.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[(0,k.jsx)(`input`,{type:`number`,className:`w-16 px-2 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm text-center font-mono focus:outline-none focus:border-bambu-green`,value:t,min:0,max:2e3,onChange:e=>{let t=parseInt(e.target.value);!isNaN(t)&&t>=0&&n(t)}}),(0,k.jsx)(`span`,{className:`text-bambu-gray text-sm`,children:`g`})]})]})]})}function z({formData:e,updateField:t,spoolCatalog:n,currencySymbol:i,availableCategories:a,availableMaterialNumbers:s,availableLocations:c=[],onCreateLocation:l,globalLowStockThreshold:u,spoolmanMode:d=!1,showLastDried:f=!1}){let{t:m}=r(),{showToast:h}=o(),[g,_]=(0,O.useState)(``),[v,y]=(0,O.useState)(!1),[b,x]=(0,O.useState)(``),[S,C]=(0,O.useState)(!1),[w,T]=(0,O.useState)(``),[E,D]=(0,O.useState)(!1),A=Math.max(0,e.label_weight-e.weight_used),j=e.core_weight+A;return(0,O.useEffect)(()=>{v||_(String(j))},[v,j]),(0,O.useEffect)(()=>{S||x(String(A))},[S,A]),(0,k.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-x-4 gap-y-4`,children:[(0,k.jsx)(`div`,{className:`sm:col-span-2`,children:(0,k.jsx)(R,{catalog:n,value:e.core_weight,onChange:e=>t(`core_weight`,e),catalogId:e.core_weight_catalog_id,onCatalogIdChange:e=>t(`core_weight_catalog_id`,e)})}),(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:m(`inventory.currentWeight`)}),(0,k.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,k.jsxs)(`div`,{className:`relative flex-1`,children:[(0,k.jsx)(`input`,{type:`number`,value:b,min:0,max:e.label_weight,onFocus:()=>C(!0),onChange:e=>{x(e.target.value)},onBlur:()=>{C(!1);let n=b.trim(),r=Number(n);if(!n||!Number.isFinite(r)||r<0||r>e.label_weight){x(String(A));return}let i=Math.round(r);t(`weight_used`,Math.max(0,e.label_weight-i)),x(String(i))},className:`w-full px-3 py-2 pr-7 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`}),(0,k.jsx)(`span`,{className:`absolute right-2 top-1/2 -translate-y-1/2 text-xs text-bambu-gray`,children:`g`})]}),(0,k.jsxs)(`span`,{className:`text-xs text-bambu-gray shrink-0`,children:[`/ `,e.label_weight,`g`]})]})]}),(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:m(`inventory.measuredWeight`)}),(0,k.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,k.jsxs)(`div`,{className:`relative flex-1`,children:[(0,k.jsx)(`input`,{type:`number`,value:g,min:0,onFocus:()=>y(!0),onChange:e=>{_(e.target.value)},onBlur:()=>{y(!1);let n=g.trim(),r=Number(n),i=e.core_weight,a=e.core_weight+e.label_weight;if(!n||!Number.isFinite(r)||ra){h(m(`inventory.measuredWeightError`,{min:i,max:a}),`error`),_(String(j));return}let o=Math.round(r),s=Math.max(0,Math.min(e.label_weight,o-e.core_weight));t(`weight_used`,Math.max(0,e.label_weight-s)),_(String(o))},className:`w-full px-3 py-2 pr-7 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`}),(0,k.jsx)(`span`,{className:`absolute right-2 top-1/2 -translate-y-1/2 text-xs text-bambu-gray`,children:`g`})]}),(0,k.jsxs)(`span`,{className:`text-xs text-bambu-gray shrink-0`,children:[`/ `,e.core_weight+e.label_weight,`g`]})]})]}),(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:m(`inventory.costPerKg`,`Cost per kg`)}),(0,k.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,k.jsxs)(`div`,{className:`relative flex-1`,children:[(0,k.jsx)(`span`,{className:`absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray text-sm pointer-events-none`,children:i}),(0,k.jsx)(`input`,{type:`number`,value:e.cost_per_kg??``,min:0,step:.01,placeholder:`0.00`,onChange:e=>{t(`cost_per_kg`,e.target.value===``?null:parseFloat(e.target.value))},style:{paddingLeft:`${Math.max(2,i.length*.6+1)}rem`},className:`w-full py-2 pr-3 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`})]})})]}),!d&&(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,htmlFor:`spool-material-number`,children:m(`inventory.materialNumber`)}),(0,k.jsx)(`input`,{id:`spool-material-number`,type:`text`,list:`spool-material-number-options`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`,placeholder:m(`inventory.materialNumberPlaceholder`),value:e.material_number,maxLength:64,onChange:e=>t(`material_number`,e.target.value)}),s.length>0&&(0,k.jsx)(`datalist`,{id:`spool-material-number-options`,children:s.map(e=>(0,k.jsx)(`option`,{value:e},e))}),(0,k.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:m(`inventory.materialNumberHelp`)})]}),(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,htmlFor:`spool-category`,children:m(`inventory.category`)}),(0,k.jsx)(`input`,{id:`spool-category`,type:`text`,list:`spool-category-options`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`,placeholder:m(`inventory.categoryPlaceholder`),value:e.category,maxLength:50,onChange:e=>t(`category`,e.target.value)}),a.length>0&&(0,k.jsx)(`datalist`,{id:`spool-category-options`,children:a.map(e=>(0,k.jsx)(`option`,{value:e},e))})]}),(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,htmlFor:`spool-low-stock-threshold`,children:m(`inventory.lowStockThresholdOverride`)}),(0,k.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,k.jsxs)(`div`,{className:`relative flex-1`,children:[(0,k.jsx)(`input`,{id:`spool-low-stock-threshold`,type:`number`,className:`w-full px-3 py-2 pr-8 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`,placeholder:String(u),value:e.low_stock_threshold_pct??``,min:1,max:99,step:1,onChange:e=>{let n=e.target.value;if(n===``){t(`low_stock_threshold_pct`,null);return}let r=Number(n);Number.isFinite(r)&&t(`low_stock_threshold_pct`,Math.min(99,Math.max(1,Math.round(r))))}}),(0,k.jsx)(`span`,{className:`absolute right-3 top-1/2 -translate-y-1/2 text-xs text-bambu-gray pointer-events-none`,children:`%`})]})}),(0,k.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:m(`inventory.lowStockThresholdOverrideHelp`,{global:u})})]}),(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,htmlFor:`spool-storage-location`,children:m(`inventory.storageLocation`)}),(0,k.jsxs)(`select`,{id:`spool-storage-location`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`,value:e.location_id??``,onChange:e=>{let n=e.target.value;if(!n){t(`location_id`,null);return}t(`location_id`,Number(n))},children:[(0,k.jsx)(`option`,{value:``,children:m(`inventory.storageLocationNone`)}),c.map(e=>(0,k.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),l&&(0,k.jsxs)(`div`,{className:`mt-2 flex gap-2`,children:[(0,k.jsx)(`input`,{type:`text`,maxLength:255,className:`flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`,placeholder:m(`locations.createPlaceholder`),value:w,onChange:e=>T(e.target.value)}),(0,k.jsx)(`button`,{type:`button`,className:`px-3 py-2 text-sm rounded-lg bg-bambu-dark-tertiary text-white hover:bg-bambu-gray-dark disabled:opacity-50`,disabled:!w.trim()||E,onClick:async()=>{let e=w.trim();if(!(!e||!l)){D(!0);try{let n=await l(e);n&&(t(`location_id`,n.id),T(``))}finally{D(!1)}}},children:m(`locations.addShort`)})]})]}),f&&(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,htmlFor:`spool-last-dried`,children:m(`inventory.lastDried`)}),(0,k.jsxs)(`div`,{className:`flex gap-2`,children:[(0,k.jsx)(`input`,{id:`spool-last-dried`,type:`datetime-local`,className:`flex-1 min-w-0 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`,value:e.last_dried_at,onChange:e=>t(`last_dried_at`,e.target.value)}),(0,k.jsx)(`button`,{type:`button`,className:`px-3 py-2 text-sm rounded-lg bg-bambu-dark-tertiary text-white hover:bg-bambu-gray-dark`,onClick:()=>t(`last_dried_at`,p(new Date)),children:m(`inventory.lastDriedNow`)})]}),(0,k.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:m(`inventory.lastDriedHelp`)})]}),(0,k.jsxs)(`div`,{className:`sm:col-span-2`,children:[(0,k.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:m(`inventory.note`)}),(0,k.jsx)(`textarea`,{className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green resize-none min-h-[80px]`,placeholder:m(`inventory.notePlaceholder`),value:e.note,onChange:e=>t(`note`,e.target.value)})]})]})}export{E as a,M as i,L as n,T as o,F as r,D as s,z as t}; \ No newline at end of file +import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,w as r}from"./client-DnySrlFv.js";import{a as i,i as a}from"./info-ROUoQhJR.js";import{n as o}from"./ToastContext-BRX0SW3C.js";import{t as s}from"./cloud-off-DfYbNG2N.js";import{t as c}from"./loader-circle-BEmFtawu.js";import{t as l}from"./scale-CD6XdXUk.js";import{t as u}from"./search-0n0CBc74.js";import{t as d}from"./sparkles-DRqKNlhr.js";import{t as f}from"./x-DR-Trv6U.js";import{y as p}from"./date-G9KUauqz.js";import{n as m,t as h}from"./filamentSwatchHelpers-D3oXQSGk.js";import{Dn as g,N as _,On as v,lt as y,w as b}from"./index-Cxa-KVmA.js";import{_ as x,h as S,u as C,y as w}from"./utils-subfXwl6.js";var T={material:``,subtype:``,brand:``,color_name:``,rgba:`808080FF`,extra_colors:``,effect_type:``,label_weight:1e3,core_weight:250,core_weight_catalog_id:null,weight_used:0,slicer_filament:``,note:``,cost_per_kg:null,category:``,low_stock_threshold_pct:null,material_number:``,location_id:null,last_dried_at:``,spoolman_filament_id:null},E=new Set([`material`,`subtype`,`brand`,`rgba`,`color_name`,`label_weight`]);function D(e,t=!1,n=!1,r=`create`){let i={};return t||n||r!==`create`?(!e.material&&!e.spoolman_filament_id&&(i.material=`Material is required`),{isValid:Object.keys(i).length===0,errors:i}):(e.slicer_filament||(i.slicer_filament=`Slicer preset is required`),e.material||(i.material=`Material is required`),e.brand||(i.brand=`Brand is required`),e.subtype||(i.subtype=`Subtype is required`),{isValid:Object.keys(i).length===0,errors:i})}var O=e(n(),1),k=t(),A={local:`bg-green-100 dark:bg-green-500/20 text-green-700 dark:text-green-400`,orca_cloud:`bg-purple-100 dark:bg-purple-500/20 text-purple-700 dark:text-purple-400`,cloud:`bg-bambu-blue/20 text-bambu-blue`,builtin:`bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400`};function j({source:e}){let{t}=r(),n={local:t(`profiles.localProfiles.badge`),orca_cloud:t(`configureAmsSlot.orcaCloud`),cloud:t(`configureAmsSlot.bambuCloud`),builtin:t(`configureAmsSlot.builtin`)}[e];return(0,k.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded whitespace-nowrap ${A[e]}`,children:n})}function M({value:e,options:t,inheritLabel:n,onChange:a,disabled:o=!1,ariaLabel:s}){let{t:c}=r(),[l,d]=(0,O.useState)(!1),[p,m]=(0,O.useState)(``),h=(0,O.useRef)(null),g=t.find(t=>t.code===e);(0,O.useEffect)(()=>{if(!l)return;let e=e=>{h.current&&!h.current.contains(e.target)&&d(!1)},t=e=>{e.key===`Escape`&&(e.stopPropagation(),d(!1))};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t,!0),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t,!0)}},[l]);let _=p.trim().toLowerCase(),v=_?t.filter(e=>e.displayName.toLowerCase().includes(_)):t,y=e=>{a(e),d(!1),m(``)};return(0,k.jsxs)(`div`,{className:`relative`,ref:h,children:[(0,k.jsxs)(`button`,{type:`button`,"aria-label":s,"aria-haspopup":`listbox`,"aria-expanded":l,disabled:o,onClick:()=>d(e=>!e),className:`w-full flex items-center gap-2 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-sm text-left focus:outline-none focus:border-bambu-green disabled:opacity-50`,children:[(0,k.jsx)(`span`,{className:`flex-1 min-w-0 truncate ${g?`text-white`:`text-bambu-gray italic`}`,children:g?g.displayName:n}),g&&(0,k.jsx)(j,{source:g.source}),(0,k.jsx)(i,{className:`w-3.5 h-3.5 text-bambu-gray shrink-0`})]}),l&&(0,k.jsxs)(`div`,{className:`absolute z-50 mt-1 w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl`,children:[(0,k.jsx)(`div`,{className:`p-2 border-b border-bambu-dark-tertiary`,children:(0,k.jsxs)(`div`,{className:`relative`,children:[(0,k.jsx)(u,{className:`w-3.5 h-3.5 text-bambu-gray absolute left-2 top-1/2 -translate-y-1/2`}),(0,k.jsx)(`input`,{autoFocus:!0,type:`text`,value:p,onChange:e=>m(e.target.value),placeholder:c(`inventory.searchPresets`),className:`w-full pl-7 pr-7 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded-md text-sm text-white placeholder:text-bambu-gray/60 focus:outline-none focus:border-bambu-green`}),p&&(0,k.jsx)(`button`,{type:`button`,"aria-label":c(`common.clear`),onClick:()=>m(``),className:`absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white`,children:(0,k.jsx)(f,{className:`w-3.5 h-3.5`})})]})}),(0,k.jsxs)(`div`,{className:`max-h-56 overflow-y-auto p-1`,role:`listbox`,"aria-label":s,children:[(0,k.jsx)(`button`,{type:`button`,role:`option`,"aria-selected":!g,onClick:()=>y(null),className:`w-full text-left px-2 py-1.5 rounded-md text-sm italic ${g?`text-bambu-gray hover:bg-bambu-dark`:`bg-bambu-green/15 text-bambu-green`}`,children:n}),v.length===0?(0,k.jsx)(`p`,{className:`px-2 py-2 text-sm text-bambu-gray`,children:c(`inventory.noResults`)}):v.map(t=>(0,k.jsxs)(`button`,{type:`button`,role:`option`,"aria-selected":t.code===e,onClick:()=>y(t),className:`w-full flex items-center gap-2 text-left px-2 py-1.5 rounded-md text-sm ${t.code===e?`bg-bambu-green/15 text-bambu-green`:`text-white hover:bg-bambu-dark`}`,children:[(0,k.jsx)(`span`,{className:`flex-1 min-w-0 truncate`,title:t.displayName,children:t.displayName}),(0,k.jsx)(j,{source:t.source})]},t.code))]})]})]})}function N(e,t){if(t.length===0)return{top:[],rest:e};let n=new Set(t.map(e=>e.toLowerCase()));return{top:e.filter(e=>n.has(e.toLowerCase())),rest:e.filter(e=>!n.has(e.toLowerCase()))}}function P({label:e}){return(0,k.jsx)(`div`,{className:`px-3 py-1 text-[11px] font-semibold uppercase tracking-wide text-bambu-gray/70 bg-bambu-dark-tertiary/40`,children:e})}function F({formData:e,updateField:t,cloudAuthenticated:n,loadingCloudPresets:a,presetInputValue:o,setPresetInputValue:l,selectedPresetOption:d,filamentOptions:f,availableBrands:p,availableMaterials:m,suggestedBrands:h,suggestedMaterials:v,quickAdd:y,detailsRequired:b,quantity:S,onQuantityChange:w,errors:T}){let{t:E}=r(),[D,A]=(0,O.useState)(!1),[M,F]=(0,O.useState)(!1),[I,L]=(0,O.useState)(!1),[R,z]=(0,O.useState)(!1),[B,V]=(0,O.useState)(``),[H,U]=(0,O.useState)(``),[W,G]=(0,O.useState)(``),[ee,K]=(0,O.useState)(String(e.label_weight)),[te,ne]=(0,O.useState)(!1),[re,ie]=(0,O.useState)(new Set),q=(0,O.useRef)(null),J=(0,O.useRef)(null),ae=(0,O.useRef)(null),oe=(0,O.useRef)(null);(0,O.useEffect)(()=>{let e=e=>{q.current&&!q.current.contains(e.target)&&A(!1),oe.current&&!oe.current.contains(e.target)&&z(!1),J.current&&!J.current.contains(e.target)&&F(!1),ae.current&&!ae.current.contains(e.target)&&L(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[]);let se=(0,O.useMemo)(()=>{if(!o)return f;let e=o.toLowerCase();return f.filter(t=>t.displayName.toLowerCase().includes(e)||t.code.toLowerCase().includes(e))},[f,o]),Y=(0,O.useMemo)(()=>{if(!B)return p;let e=B.toLowerCase();return p.filter(t=>t.toLowerCase().includes(e)).sort((t,n)=>{let r=t.toLowerCase()===e,i=n.toLowerCase()===e;return r&&!i?-1:!r&&i?1:t.localeCompare(n)})},[p,B]),ce=(0,O.useMemo)(()=>{if(!H)return x;let e=H.toLowerCase();return x.filter(t=>t.toLowerCase().includes(e))},[H]),X=(0,O.useMemo)(()=>{if(!W)return m;let e=W.toLowerCase();return m.filter(t=>t.toLowerCase().includes(e)).sort((t,n)=>{let r=t.toLowerCase()===e,i=n.toLowerCase()===e;return r&&!i?-1:!r&&i?1:t.localeCompare(n)})},[W,m]),Z=(0,O.useMemo)(()=>N(Y,h),[Y,h]),Q=(0,O.useMemo)(()=>N(X,v),[X,v]);(0,O.useEffect)(()=>{te||K(String(e.label_weight))},[e.label_weight,te]);let le=n=>{t(`slicer_filament`,n.code),l(n.displayName),A(!1);let r=C(n.name),i=new Set,a=[[`material`,r.material],[`brand`,r.brand],[`subtype`,r.variant]];for(let[n,r]of a)r&&(e[n]&&!re.has(n)||(t(n,r),i.add(n)));ie(i)},$=(e,n)=>{re.has(e)&&ie(t=>{let n=new Set(t);return n.delete(e),n}),t(e,n)},ue=t=>(0,k.jsx)(`button`,{type:`button`,className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${e.brand===t?`bg-bambu-green/10 text-bambu-green`:`text-white`}`,onClick:()=>{$(`brand`,t),F(!1),V(``)},children:t},t),de=t=>(0,k.jsx)(`button`,{type:`button`,className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${e.material===t?`bg-bambu-green/10 text-bambu-green`:`text-white`}`,onClick:()=>{$(`material`,t),z(!1),G(``)},children:t},t);return(0,k.jsxs)(`div`,{className:`space-y-4`,children:[!y&&(0,k.jsx)(`div`,{className:`flex items-center gap-2 text-xs text-bambu-gray`,children:a?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(c,{className:`w-3 h-3 animate-spin`}),` `,E(`inventory.loadingPresets`)]}):n?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(g,{className:`w-3 h-3 text-bambu-green`}),` `,E(`inventory.cloudConnected`)]}):(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(s,{className:`w-3 h-3`}),` `,E(`inventory.cloudNotConnected`)]})}),!y&&(0,k.jsxs)(`div`,{children:[(0,k.jsxs)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:[E(`inventory.slicerPreset`),b&&` *`]}),(0,k.jsxs)(`div`,{className:`relative`,ref:q,children:[(0,k.jsx)(u,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50 pointer-events-none`}),(0,k.jsx)(`input`,{type:`text`,className:`w-full pl-9 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`,placeholder:E(`inventory.searchPresets`),value:o,onChange:e=>{l(e.target.value),A(!0)},onFocus:()=>{A(!0),l(``)}}),D&&(0,k.jsx)(`div`,{className:`absolute z-50 w-full mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-64 overflow-y-auto`,children:se.length===0?(0,k.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:E(`inventory.noPresetsFound`)}):se.map(e=>(0,k.jsxs)(`button`,{type:`button`,className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary flex items-center gap-2 ${d?.code===e.code?`bg-bambu-green/10 text-bambu-green`:`text-white`}`,onClick:()=>le(e),children:[(0,k.jsx)(`span`,{className:`flex-1 min-w-0 truncate`,title:e.displayName,children:e.displayName}),(0,k.jsx)(j,{source:e.source})]},`${e.code}::${e.name}`))})]}),d&&(0,k.jsxs)(`div`,{className:`mt-1 text-xs text-bambu-gray`,children:[E(`inventory.selectedPreset`),`: `,(0,k.jsx)(`span`,{className:`font-mono text-bambu-green`,children:d.code})]}),T?.slicer_filament&&(0,k.jsx)(`p`,{className:`mt-1 text-xs text-red-700 dark:text-red-400`,children:T.slicer_filament})]}),(0,k.jsxs)(`div`,{children:[(0,k.jsxs)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:[E(`inventory.material`),` *`]}),(0,k.jsxs)(`div`,{className:`relative`,ref:oe,children:[(0,k.jsx)(`input`,{type:`text`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`,placeholder:E(`inventory.selectMaterial`),value:R?W:e.material,onChange:e=>{G(e.target.value),z(!0)},onFocus:()=>{z(!0),G(``)}}),(0,k.jsx)(i,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50 pointer-events-none`}),R&&(0,k.jsxs)(`div`,{className:`absolute z-50 w-full mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-48 overflow-y-auto`,children:[X.length===0?(0,k.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:E(`inventory.noResults`)}):(0,k.jsxs)(k.Fragment,{children:[Q.top.length>0&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(P,{label:E(`inventory.suggestedOptions`)}),Q.top.map(de)]}),Q.rest.length>0&&(0,k.jsxs)(k.Fragment,{children:[Q.top.length>0&&(0,k.jsx)(P,{label:E(`inventory.allOptions`)}),Q.rest.map(de)]})]}),W&&!X.includes(W)&&(0,k.jsx)(`button`,{type:`button`,className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary text-bambu-green border-t border-bambu-dark-tertiary`,onClick:()=>{$(`material`,W),z(!1),G(``)},children:E(`inventory.useCustomMaterial`,{material:W})})]})]}),T?.material&&(0,k.jsx)(`p`,{className:`mt-1 text-xs text-red-700 dark:text-red-400`,children:T.material})]}),(0,k.jsxs)(`div`,{children:[(0,k.jsxs)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:[E(`inventory.brand`),b&&` *`]}),(0,k.jsxs)(`div`,{className:`relative`,ref:J,children:[(0,k.jsx)(`input`,{type:`text`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`,placeholder:E(`inventory.searchBrand`),value:M?B:e.brand,onChange:e=>{V(e.target.value),F(!0)},onFocus:()=>{F(!0),V(``)}}),(0,k.jsx)(i,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50 pointer-events-none`}),M&&(0,k.jsxs)(`div`,{className:`absolute z-50 w-full mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-48 overflow-y-auto`,children:[Y.length===0?(0,k.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:E(`inventory.noResults`)}):(0,k.jsxs)(k.Fragment,{children:[Z.top.length>0&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(P,{label:E(`inventory.suggestedOptions`)}),Z.top.map(ue)]}),Z.rest.length>0&&(0,k.jsxs)(k.Fragment,{children:[Z.top.length>0&&(0,k.jsx)(P,{label:E(`inventory.allOptions`)}),Z.rest.map(ue)]})]}),B&&!Y.includes(B)&&(0,k.jsx)(`button`,{type:`button`,className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary text-bambu-green border-t border-bambu-dark-tertiary`,onClick:()=>{$(`brand`,B),F(!1),V(``)},children:E(`inventory.useCustomBrand`,{brand:B})})]})]}),T?.brand&&(0,k.jsx)(`p`,{className:`mt-1 text-xs text-red-700 dark:text-red-400`,children:T.brand})]}),(0,k.jsxs)(`div`,{children:[(0,k.jsxs)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:[E(`inventory.subtype`),b&&` *`]}),(0,k.jsxs)(`div`,{className:`relative`,ref:ae,children:[(0,k.jsx)(`input`,{type:`text`,value:I?H:e.subtype,onChange:e=>{U(e.target.value),L(!0)},onFocus:()=>{L(!0),U(``)},placeholder:`Basic, Matte, Silk...`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`}),(0,k.jsx)(i,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50 pointer-events-none`}),I&&(0,k.jsxs)(`div`,{className:`absolute z-50 w-full mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-48 overflow-y-auto`,children:[ce.length===0?(0,k.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:E(`inventory.noResults`)}):ce.map(t=>(0,k.jsx)(`button`,{type:`button`,className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${e.subtype===t?`bg-bambu-green/10 text-bambu-green`:`text-white`}`,onClick:()=>{$(`subtype`,t),L(!1),U(``)},children:t},t)),H&&!x.some(e=>e.toLowerCase()===H.toLowerCase().trim())&&(0,k.jsx)(`button`,{type:`button`,className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary text-bambu-green border-t border-bambu-dark-tertiary`,onClick:()=>{$(`subtype`,H),L(!1),U(``)},children:E(`inventory.useCustomBrand`,{brand:H})})]})]}),T?.subtype&&(0,k.jsx)(`p`,{className:`mt-1 text-xs text-red-700 dark:text-red-400`,children:T.subtype})]}),(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:E(`inventory.labelWeight`)}),(0,k.jsxs)(`div`,{className:`relative`,children:[(0,k.jsx)(`input`,{type:`number`,className:`w-full px-3 py-2 pr-7 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`,value:ee,min:0,onFocus:()=>ne(!0),onChange:e=>K(e.target.value),onBlur:()=>{ne(!1);let n=ee.trim(),r=Number(n);if(!n||!Number.isFinite(r)||r<0){K(String(e.label_weight));return}let i=Math.round(r);t(`label_weight`,i),K(String(i))}}),(0,k.jsx)(`span`,{className:`absolute right-2 top-1/2 -translate-y-1/2 text-xs text-bambu-gray`,children:`g`})]})]}),y&&(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:E(`inventory.quantity`)}),(0,k.jsx)(_,{className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`,value:S,min:1,max:100,onChange:w,fallback:1})]})]})}function I(e){let t=e.split(/[\s,]+/).map(e=>e.trim().replace(/^#/,``)).filter(Boolean),n=[],r=[];for(let e of t)(e.length===6||e.length===8)&&/^[0-9a-fA-F]+$/.test(e)?n.push(e.toLowerCase()):r.push(e);return{value:n.join(`,`),invalid:r}}function L({formData:e,updateField:t,recentColors:n,onColorUsed:o,catalogColors:s}){let{t:c}=r(),[l,f]=(0,O.useState)(!1),[p,g]=(0,O.useState)(``),_=(e.rgba.replace(`#`,``)+`FF`).substring(0,8).toUpperCase(),x=_.substring(0,6),C=_.substring(6,8)===`00`,[T,E]=(0,O.useState)(C?_:x);(0,O.useEffect)(()=>{E(C?_:x)},[x,_,C]);let D=e=>_===(e.replace(`#`,``)+`FF`).substring(0,8).toUpperCase(),A=e=>y(e),j=(e,n,r,i)=>{let a=e.replace(`#`,``).toUpperCase();if(t(`rgba`,a.length===8?a:a+`FF`),t(`color_name`,n),r!==void 0){let e=r??``;R(e),B([]),V.current=e,t(`extra_colors`,e)}i!==void 0&&t(`effect_type`,i??``),o({name:n,hex:e})},M=(0,O.useMemo)(()=>{if(s.length===0)return[];let t=e.brand?.trim(),n=e.material?.toLowerCase().trim(),r=e.subtype?.toLowerCase().trim();if(!t&&!n)return[];let i=t?t.toLowerCase().split(/[\s\-_]+/).filter(e=>e.length>=2):[],a=e=>{if(i.length===0)return!0;let t=e.toLowerCase();return i.some(e=>t.includes(e))};if(t&&!n){let e=s.filter(e=>a(e.manufacturer));if(e.length>0)return e.map(e=>({name:e.color_name,hex:e.hex_color.replace(`#`,``).substring(0,6),manufacturer:e.manufacturer,material:typeof e.material==`string`?e.material:void 0,extra_colors:e.extra_colors??null,effect_type:e.effect_type??null}))}let o=n&&r?`${n} ${r}`:``;if(o){let e=s.filter(e=>a(e.manufacturer)&&e.material?.toLowerCase()===o);if(e.length>0)return e.map(e=>({name:e.color_name,hex:e.hex_color.replace(`#`,``).substring(0,6),manufacturer:e.manufacturer,material:typeof e.material==`string`?e.material:void 0,extra_colors:e.extra_colors??null,effect_type:e.effect_type??null}));let t=o.replace(/\+$/,``);if(t!==o){let e=s.filter(e=>a(e.manufacturer)&&e.material?.toLowerCase()===t);if(e.length>0)return e.map(e=>({name:e.color_name,hex:e.hex_color.replace(`#`,``).substring(0,6),manufacturer:e.manufacturer,material:typeof e.material==`string`?e.material:void 0}))}}if(n){let e=s.filter(e=>a(e.manufacturer)&&(!e.material||e.material.toLowerCase().startsWith(n)));if(e.length>0)return e.map(e=>({name:e.color_name,hex:e.hex_color.replace(`#`,``).substring(0,6),manufacturer:e.manufacturer,material:typeof e.material==`string`?e.material:void 0,extra_colors:e.extra_colors??null,effect_type:e.effect_type??null}))}return[]},[s,e.brand,e.material,e.subtype]),N=(0,O.useMemo)(()=>{if(!p)return M;if(M.length===0)return[];let e=p.toLowerCase();return M.filter(t=>t.name.toLowerCase().includes(e)||(t.manufacturer?.toLowerCase().includes(e)??!1)||(t.material?.toLowerCase().includes(e)??!1))},[p,M]),P=M.length>0,F=(0,O.useMemo)(()=>p?S.filter(e=>e.name.toLowerCase().includes(p.toLowerCase())):l?S:w,[p,l]),[L,R]=(0,O.useState)(e.extra_colors),[z,B]=(0,O.useState)([]),V=(0,O.useRef)(e.extra_colors);(0,O.useEffect)(()=>{e.extra_colors!==V.current&&(R(e.extra_colors),B([]),V.current=e.extra_colors)},[e.extra_colors]);let H=(0,O.useMemo)(()=>m({rgba:e.rgba,extraColors:e.extra_colors,effectType:e.effect_type,subtype:e.subtype,effectSize:`bar`}),[e.rgba,e.extra_colors,e.effect_type,e.subtype]),U=e=>{if(R(e),!e.trim()){B([]),V.current=``,t(`extra_colors`,``);return}let{value:n,invalid:r}=I(e);B(r),V.current=n,t(`extra_colors`,n)};return(0,k.jsxs)(`div`,{className:`space-y-3`,children:[(0,k.jsx)(`div`,{className:`h-10 rounded-lg border border-bambu-dark-tertiary`,style:H,"data-testid":`color-preview-banner`}),n.length>0&&(0,k.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,k.jsxs)(`div`,{className:`flex items-center gap-1.5 text-xs text-bambu-gray shrink-0`,children:[(0,k.jsx)(v,{className:`w-3 h-3`}),(0,k.jsx)(`span`,{children:c(`inventory.recentColors`)})]}),(0,k.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:n.map(e=>(0,k.jsx)(`button`,{type:`button`,onClick:()=>j(e.hex,e.name),className:`w-6 h-6 rounded border-2 transition-all hover:scale-110 ${D(e.hex)?`border-bambu-green ring-1 ring-bambu-green/30 scale-110`:`border-bambu-dark-tertiary`}`,style:A(e.hex),title:e.name},e.hex))})]}),(0,k.jsxs)(`div`,{className:`relative`,children:[(0,k.jsx)(u,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50 pointer-events-none`}),(0,k.jsx)(`input`,{type:`text`,className:`w-full pl-9 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`,placeholder:c(`inventory.searchColors`),value:p,onChange:e=>g(e.target.value)})]}),P?(0,k.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,k.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:p?c(`inventory.searchResults`):`${e.brand}${e.material?` ${e.material}`:``}`}),(0,k.jsxs)(`div`,{className:`flex flex-wrap gap-1.5`,children:[N.map(e=>(0,k.jsx)(`button`,{type:`button`,onClick:()=>j(e.hex,e.name,e.extra_colors,e.effect_type),className:`w-6 h-6 rounded border-2 transition-all hover:scale-110 hover:z-20 relative group ${D(e.hex)?`border-bambu-green ring-1 ring-bambu-green/30 scale-110`:`border-bambu-dark-tertiary`}`,style:A(e.hex),title:e.manufacturer&&e.material?`${e.name} (${e.manufacturer} — ${e.material})`:e.manufacturer?`${e.name} (${e.manufacturer})`:e.name,children:(0,k.jsx)(`span`,{className:`absolute -bottom-7 left-1/2 -translate-x-1/2 px-2 py-0.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-xs whitespace-nowrap opacity-0 group-hover:opacity-100 transition-opacity pointer-events-none z-20 shadow-lg text-white`,children:e.manufacturer&&e.material?`${e.name} (${e.manufacturer} — ${e.material})`:e.manufacturer?`${e.name} (${e.manufacturer})`:e.name})},`${e.hex}-${e.name}-${e.manufacturer??``}`)),N.length===0&&(0,k.jsx)(`p`,{className:`text-sm text-bambu-gray py-1`,children:c(`inventory.noColorsFound`)})]})]}):(0,k.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,k.jsxs)(`div`,{className:`flex items-center justify-between text-xs text-bambu-gray`,children:[(0,k.jsx)(`span`,{children:c(p?`inventory.searchResults`:l?`inventory.allColors`:`inventory.commonColors`)}),!p&&(0,k.jsx)(`button`,{type:`button`,onClick:()=>f(!l),className:`flex items-center gap-1 hover:text-white transition-colors`,children:l?(0,k.jsxs)(k.Fragment,{children:[c(`inventory.showLess`),` `,(0,k.jsx)(a,{className:`w-3 h-3`})]}):(0,k.jsxs)(k.Fragment,{children:[c(`inventory.showAll`),` `,(0,k.jsx)(i,{className:`w-3 h-3`})]})})]}),(0,k.jsxs)(`div`,{className:`flex flex-wrap gap-1.5`,children:[F.map(e=>(0,k.jsx)(`button`,{type:`button`,onClick:()=>j(e.hex,e.name),className:`w-6 h-6 rounded border-2 transition-all hover:scale-110 hover:z-20 relative group ${D(e.hex)?`border-bambu-green ring-1 ring-bambu-green/30 scale-110`:`border-bambu-dark-tertiary`}`,style:A(e.hex),title:e.name,children:(0,k.jsx)(`span`,{className:`absolute -bottom-7 left-1/2 -translate-x-1/2 px-2 py-0.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-xs whitespace-nowrap opacity-0 group-hover:opacity-100 transition-opacity pointer-events-none z-20 shadow-lg text-white`,children:e.name})},e.hex)),F.length===0&&(0,k.jsx)(`p`,{className:`text-sm text-bambu-gray py-1`,children:c(`inventory.noColorsFound`)})]})]}),(0,k.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:c(`inventory.colorName`)}),(0,k.jsx)(`input`,{type:`text`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`,placeholder:c(`inventory.colorNamePlaceholder`),value:e.color_name,onChange:e=>t(`color_name`,e.target.value)})]}),(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:c(`inventory.hexColor`)}),(0,k.jsxs)(`div`,{className:`flex gap-2`,children:[(0,k.jsxs)(`div`,{className:`relative flex-1`,children:[(0,k.jsx)(`span`,{className:`absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray`,children:`#`}),(0,k.jsx)(`input`,{type:`text`,className:`w-full pl-7 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm font-mono uppercase focus:outline-none focus:border-bambu-green`,placeholder:`RRGGBB`,value:T.toUpperCase(),onChange:e=>{let n=e.target.value.replace(`#`,``).replace(/[^0-9A-Fa-f]/g,``).toUpperCase(),r=n.length>8?n.substring(0,8):n;E(r),r.length===6?t(`rgba`,r+`FF`):r.length===8&&t(`rgba`,r)},onBlur:()=>{if(T.length===7){let e=T+`0`;E(e),t(`rgba`,e)}else if(T.length>0&&T.length<6){let e=T.padEnd(6,`0`);E(e),t(`rgba`,e+`FF`)}}})]}),(0,k.jsx)(`input`,{type:`color`,className:`w-11 h-[38px] rounded-lg cursor-pointer border border-bambu-dark-tertiary shrink-0 bg-transparent`,value:`#${x}`,onChange:e=>{t(`rgba`,e.target.value.replace(`#`,``).toUpperCase()+`FF`)},title:c(`inventory.pickColor`)})]})]})]}),(0,k.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3 pt-2 border-t border-bambu-dark-tertiary/50`,children:[(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:c(`inventory.extraColorsLabel`)}),(0,k.jsx)(`input`,{type:`text`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm font-mono placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`,placeholder:c(`inventory.extraColorsPlaceholder`),value:L,onChange:e=>U(e.target.value),"data-testid":`extra-colors-input`}),z.length>0&&(0,k.jsx)(`p`,{className:`text-xs text-red-700 dark:text-red-400 mt-1`,children:c(`inventory.extraColorsInvalid`,{tokens:z.join(`, `)})}),!z.length&&(0,k.jsx)(`p`,{className:`text-xs text-bambu-gray/70 mt-1`,children:c(`inventory.extraColorsHint`)})]}),(0,k.jsxs)(`div`,{children:[(0,k.jsxs)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1 flex items-center gap-1.5`,children:[(0,k.jsx)(d,{className:`w-3.5 h-3.5`}),c(`inventory.colorEffectLabel`)]}),(0,k.jsxs)(`div`,{className:`flex gap-2 items-stretch`,children:[(0,k.jsx)(`select`,{className:`flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`,value:e.effect_type,onChange:e=>t(`effect_type`,e.target.value),"data-testid":`effect-type-select`,children:h.map(e=>(0,k.jsx)(`option`,{value:e.value,children:c(e.labelKey)},e.value||`none`))}),(0,k.jsx)(b,{rgba:e.rgba,extraColors:e.extra_colors,effectType:e.effect_type,subtype:e.subtype,effectSize:`preview`,className:`w-10 h-10`,shape:`square`})]})]})]})]})}function R({catalog:e,value:t,onChange:n,catalogId:i,onCatalogIdChange:a}){let{t:o}=r(),[s,c]=(0,O.useState)(!1),[u,d]=(0,O.useState)(``),f=(0,O.useRef)(null),p=(0,O.useRef)(null);(0,O.useEffect)(()=>{let e=e=>{f.current&&!f.current.contains(e.target)&&c(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[]),(0,O.useEffect)(()=>{if(e.length===0)return;let n=e.filter(e=>e.weight===t);if(i){let n=e.find(e=>e.id===i);if(n&&n.weight===t)return}n.length===1?a(n[0].id):n.length===0&&i!==null&&a(null)},[t,e,i,a]);let m=(0,O.useMemo)(()=>{if(!u)return e;let t=u.toLowerCase();return e.filter(e=>e.name.toLowerCase().includes(t)||e.weight.toString().includes(t))},[e,u]),h=(0,O.useMemo)(()=>e.filter(e=>e.weight===t),[e,t]),g=(0,O.useMemo)(()=>{if(s)return u;if(i){let t=e.find(e=>e.id===i);if(t)return t.name}return h.length>0?h[0].name:``},[s,u,i,e,h]);return(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:(0,k.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,k.jsx)(l,{className:`w-3.5 h-3.5 text-bambu-gray`}),o(`inventory.coreWeight`)]})}),(0,k.jsxs)(`div`,{className:`flex gap-2 items-center`,children:[(0,k.jsxs)(`div`,{className:`flex-1 min-w-0 relative`,ref:f,children:[(0,k.jsx)(`input`,{ref:p,type:`text`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`,placeholder:o(`inventory.searchSpoolWeight`),value:g,onFocus:()=>{c(!0),d(``)},onChange:e=>{d(e.target.value),c(!0)}}),s&&(0,k.jsx)(`div`,{className:`absolute z-50 w-full mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-64 overflow-y-auto`,children:m.length===0?(0,k.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:o(`inventory.noResults`)}):m.map(e=>(0,k.jsxs)(`button`,{type:`button`,className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary flex justify-between items-center ${(i?e.id===i:e.weight===t)?`bg-bambu-green/10 text-bambu-green`:`text-white`}`,onClick:()=>{a(e.id),n(e.weight),c(!1),d(``)},children:[(0,k.jsx)(`span`,{className:`truncate`,children:e.name}),(0,k.jsxs)(`span`,{className:`font-mono text-xs text-bambu-gray ml-2 shrink-0`,children:[e.weight,`g`]})]},e.id))})]}),(0,k.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[(0,k.jsx)(`input`,{type:`number`,className:`w-16 px-2 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm text-center font-mono focus:outline-none focus:border-bambu-green`,value:t,min:0,max:2e3,onChange:e=>{let t=parseInt(e.target.value);!isNaN(t)&&t>=0&&n(t)}}),(0,k.jsx)(`span`,{className:`text-bambu-gray text-sm`,children:`g`})]})]})]})}function z({formData:e,updateField:t,spoolCatalog:n,currencySymbol:i,availableCategories:a,availableMaterialNumbers:s,availableLocations:c=[],onCreateLocation:l,globalLowStockThreshold:u,spoolmanMode:d=!1,showLastDried:f=!1}){let{t:m}=r(),{showToast:h}=o(),[g,_]=(0,O.useState)(``),[v,y]=(0,O.useState)(!1),[b,x]=(0,O.useState)(``),[S,C]=(0,O.useState)(!1),[w,T]=(0,O.useState)(``),[E,D]=(0,O.useState)(!1),A=Math.max(0,e.label_weight-e.weight_used),j=e.core_weight+A;return(0,O.useEffect)(()=>{v||_(String(j))},[v,j]),(0,O.useEffect)(()=>{S||x(String(A))},[S,A]),(0,k.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-x-4 gap-y-4`,children:[(0,k.jsx)(`div`,{className:`sm:col-span-2`,children:(0,k.jsx)(R,{catalog:n,value:e.core_weight,onChange:e=>t(`core_weight`,e),catalogId:e.core_weight_catalog_id,onCatalogIdChange:e=>t(`core_weight_catalog_id`,e)})}),(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:m(`inventory.currentWeight`)}),(0,k.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,k.jsxs)(`div`,{className:`relative flex-1`,children:[(0,k.jsx)(`input`,{type:`number`,value:b,min:0,max:e.label_weight,onFocus:()=>C(!0),onChange:e=>{x(e.target.value)},onBlur:()=>{C(!1);let n=b.trim(),r=Number(n);if(!n||!Number.isFinite(r)||r<0||r>e.label_weight){x(String(A));return}let i=Math.round(r);t(`weight_used`,Math.max(0,e.label_weight-i)),x(String(i))},className:`w-full px-3 py-2 pr-7 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`}),(0,k.jsx)(`span`,{className:`absolute right-2 top-1/2 -translate-y-1/2 text-xs text-bambu-gray`,children:`g`})]}),(0,k.jsxs)(`span`,{className:`text-xs text-bambu-gray shrink-0`,children:[`/ `,e.label_weight,`g`]})]})]}),(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:m(`inventory.measuredWeight`)}),(0,k.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,k.jsxs)(`div`,{className:`relative flex-1`,children:[(0,k.jsx)(`input`,{type:`number`,value:g,min:0,onFocus:()=>y(!0),onChange:e=>{_(e.target.value)},onBlur:()=>{y(!1);let n=g.trim(),r=Number(n),i=e.core_weight,a=e.core_weight+e.label_weight;if(!n||!Number.isFinite(r)||ra){h(m(`inventory.measuredWeightError`,{min:i,max:a}),`error`),_(String(j));return}let o=Math.round(r),s=Math.max(0,Math.min(e.label_weight,o-e.core_weight));t(`weight_used`,Math.max(0,e.label_weight-s)),_(String(o))},className:`w-full px-3 py-2 pr-7 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`}),(0,k.jsx)(`span`,{className:`absolute right-2 top-1/2 -translate-y-1/2 text-xs text-bambu-gray`,children:`g`})]}),(0,k.jsxs)(`span`,{className:`text-xs text-bambu-gray shrink-0`,children:[`/ `,e.core_weight+e.label_weight,`g`]})]})]}),(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:m(`inventory.costPerKg`,`Cost per kg`)}),(0,k.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,k.jsxs)(`div`,{className:`relative flex-1`,children:[(0,k.jsx)(`span`,{className:`absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray text-sm pointer-events-none`,children:i}),(0,k.jsx)(`input`,{type:`number`,value:e.cost_per_kg??``,min:0,step:.01,placeholder:`0.00`,onChange:e=>{t(`cost_per_kg`,e.target.value===``?null:parseFloat(e.target.value))},style:{paddingLeft:`${Math.max(2,i.length*.6+1)}rem`},className:`w-full py-2 pr-3 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`})]})})]}),!d&&(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,htmlFor:`spool-material-number`,children:m(`inventory.materialNumber`)}),(0,k.jsx)(`input`,{id:`spool-material-number`,type:`text`,list:`spool-material-number-options`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`,placeholder:m(`inventory.materialNumberPlaceholder`),value:e.material_number,maxLength:64,onChange:e=>t(`material_number`,e.target.value)}),s.length>0&&(0,k.jsx)(`datalist`,{id:`spool-material-number-options`,children:s.map(e=>(0,k.jsx)(`option`,{value:e},e))}),(0,k.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:m(`inventory.materialNumberHelp`)})]}),(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,htmlFor:`spool-category`,children:m(`inventory.category`)}),(0,k.jsx)(`input`,{id:`spool-category`,type:`text`,list:`spool-category-options`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`,placeholder:m(`inventory.categoryPlaceholder`),value:e.category,maxLength:50,onChange:e=>t(`category`,e.target.value)}),a.length>0&&(0,k.jsx)(`datalist`,{id:`spool-category-options`,children:a.map(e=>(0,k.jsx)(`option`,{value:e},e))})]}),(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,htmlFor:`spool-low-stock-threshold`,children:m(`inventory.lowStockThresholdOverride`)}),(0,k.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,k.jsxs)(`div`,{className:`relative flex-1`,children:[(0,k.jsx)(`input`,{id:`spool-low-stock-threshold`,type:`number`,className:`w-full px-3 py-2 pr-8 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`,placeholder:String(u),value:e.low_stock_threshold_pct??``,min:1,max:99,step:1,onChange:e=>{let n=e.target.value;if(n===``){t(`low_stock_threshold_pct`,null);return}let r=Number(n);Number.isFinite(r)&&t(`low_stock_threshold_pct`,Math.min(99,Math.max(1,Math.round(r))))}}),(0,k.jsx)(`span`,{className:`absolute right-3 top-1/2 -translate-y-1/2 text-xs text-bambu-gray pointer-events-none`,children:`%`})]})}),(0,k.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:m(`inventory.lowStockThresholdOverrideHelp`,{global:u})})]}),(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,htmlFor:`spool-storage-location`,children:m(`inventory.storageLocation`)}),(0,k.jsxs)(`select`,{id:`spool-storage-location`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`,value:e.location_id??``,onChange:e=>{let n=e.target.value;if(!n){t(`location_id`,null);return}t(`location_id`,Number(n))},children:[(0,k.jsx)(`option`,{value:``,children:m(`inventory.storageLocationNone`)}),c.map(e=>(0,k.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),l&&(0,k.jsxs)(`div`,{className:`mt-2 flex gap-2`,children:[(0,k.jsx)(`input`,{type:`text`,maxLength:255,className:`flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`,placeholder:m(`locations.createPlaceholder`),value:w,onChange:e=>T(e.target.value)}),(0,k.jsx)(`button`,{type:`button`,className:`px-3 py-2 text-sm rounded-lg bg-bambu-dark-tertiary text-white hover:bg-bambu-gray-dark disabled:opacity-50`,disabled:!w.trim()||E,onClick:async()=>{let e=w.trim();if(!(!e||!l)){D(!0);try{let n=await l(e);n&&(t(`location_id`,n.id),T(``))}finally{D(!1)}}},children:m(`locations.addShort`)})]})]}),f&&(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,htmlFor:`spool-last-dried`,children:m(`inventory.lastDried`)}),(0,k.jsxs)(`div`,{className:`flex gap-2`,children:[(0,k.jsx)(`input`,{id:`spool-last-dried`,type:`datetime-local`,className:`flex-1 min-w-0 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`,value:e.last_dried_at,onChange:e=>t(`last_dried_at`,e.target.value)}),(0,k.jsx)(`button`,{type:`button`,className:`px-3 py-2 text-sm rounded-lg bg-bambu-dark-tertiary text-white hover:bg-bambu-gray-dark`,onClick:()=>t(`last_dried_at`,p(new Date)),children:m(`inventory.lastDriedNow`)})]}),(0,k.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:m(`inventory.lastDriedHelp`)})]}),(0,k.jsxs)(`div`,{className:`sm:col-span-2`,children:[(0,k.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:m(`inventory.note`)}),(0,k.jsx)(`textarea`,{className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green resize-none min-h-[80px]`,placeholder:m(`inventory.notePlaceholder`),value:e.note,onChange:e=>t(`note`,e.target.value)})]})]})}export{E as a,M as i,L as n,T as o,F as r,D as s,z as t}; \ No newline at end of file diff --git a/static/assets/AmsUnitCard-Dim7pnZ8.js b/static/assets/AmsUnitCard-CeSWF1rR.js similarity index 99% rename from static/assets/AmsUnitCard-Dim7pnZ8.js rename to static/assets/AmsUnitCard-CeSWF1rR.js index 54f2785ed..2bc73c0ff 100644 --- a/static/assets/AmsUnitCard-Dim7pnZ8.js +++ b/static/assets/AmsUnitCard-CeSWF1rR.js @@ -1 +1 @@ -import{C as e,w as t}from"./client-DnySrlFv.js";import{K as n,W as r}from"./index-0t--Yqoi.js";var i=e();function a(e){return e?`#${e.slice(0,6)}`:`#808080`}function o(e){return!e.tray_type||e.tray_type===``}function s(e){return e<=3?`AMS ${String.fromCharCode(65+e)}`:e>=128&&e<=135?`AMS HT ${String.fromCharCode(65+e-128)}`:`AMS ${e}`}function c({className:e}){return(0,i.jsx)(`svg`,{className:e,viewBox:`0 0 36 54`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:(0,i.jsx)(`path`,{d:`M17.8131 0.00538C18.4463 -0.15091 20.3648 3.14642 20.8264 3.84781C25.4187 10.816 35.3089 26.9368 35.9383 34.8694C37.4182 53.5822 11.882 61.3357 2.53721 45.3789C-1.73471 38.0791 0.016 32.2049 3.178 25.0232C6.99221 16.3662 12.6411 7.90372 17.8131 0.00538ZM18.3738 7.24807L17.5881 7.48441C14.4452 12.9431 10.917 18.2341 8.19369 23.9368C4.6808 31.29 1.18317 38.5479 7.69403 45.5657C17.3058 55.9228 34.9847 46.8808 31.4604 32.8681C29.2558 24.0969 22.4207 15.2913 18.3776 7.24807H18.3738Z`,fill:`#C3C2C1`})})}function l({className:e}){return(0,i.jsxs)(`svg`,{className:e,viewBox:`0 0 35 53`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,i.jsx)(`path`,{d:`M17.3165 0.0038C17.932 -0.14959 19.7971 3.08645 20.2458 3.77481C24.7103 10.6135 34.3251 26.4346 34.937 34.2198C36.3757 52.5848 11.5505 60.1942 2.46584 44.534C-1.68714 37.3735 0.0148 31.6085 3.08879 24.5603C6.79681 16.0605 12.2884 7.75907 17.3165 0.0038ZM17.8615 7.11561L17.0977 7.34755C14.0423 12.7048 10.6124 17.8974 7.96483 23.4941C4.54975 30.7107 1.14949 37.8337 7.47908 44.721C16.8233 54.8856 34.01 46.0117 30.5838 32.2595C28.4405 23.6512 21.7957 15.0093 17.8652 7.11561H17.8615Z`,fill:`#C3C2C1`}),(0,i.jsx)(`path`,{d:`M5.03547 30.112C9.64453 30.4936 11.632 35.7985 16.4154 35.791C19.6339 35.7873 20.2161 33.2283 22.3853 31.6197C31.6776 24.7286 33.5835 37.4894 27.9881 44.4254C18.1878 56.5653 -1.16063 44.6013 5.03917 30.1158L5.03547 30.112Z`,fill:`#1F8FEB`})]})}function u({className:e}){return(0,i.jsxs)(`svg`,{className:e,viewBox:`0 0 36 54`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,i.jsx)(`path`,{d:`M17.9625 4.48059L4.77216 26.3154L2.08228 40.2175L10.0224 50.8414H23.1594L33.3246 42.1693V30.2455L17.9625 4.48059Z`,fill:`#1F8FEB`}),(0,i.jsx)(`path`,{d:`M17.7948 0.00538C18.4273 -0.15091 20.3438 3.14642 20.8048 3.84781C25.3921 10.816 35.2715 26.9368 35.9001 34.8694C37.3784 53.5822 11.8702 61.3357 2.53562 45.3789C-1.73163 38.0829 0.0134 32.2087 3.1757 25.027C6.98574 16.3662 12.6284 7.90372 17.7948 0.00538ZM18.3549 7.24807L17.57 7.48441C14.4306 12.9431 10.9063 18.2341 8.1859 23.9368C4.67686 31.29 1.18305 38.5479 7.68679 45.5657C17.2881 55.9228 34.9476 46.8808 31.4271 32.8681C29.2249 24.0969 22.3974 15.2913 18.3587 7.24807H18.3549Z`,fill:`#C3C2C1`})]})}function d({className:e}){return(0,i.jsxs)(`svg`,{className:e,viewBox:`0 0 12 20`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,i.jsx)(`path`,{d:`M6 0.5C4.6 0.5 3.5 1.6 3.5 3V12.1C2.6 12.8 2 13.9 2 15C2 17.2 3.8 19 6 19C8.2 19 10 17.2 10 15C10 13.9 9.4 12.8 8.5 12.1V3C8.5 1.6 7.4 0.5 6 0.5Z`,stroke:`#C3C2C1`,strokeWidth:`1`,fill:`none`}),(0,i.jsx)(`circle`,{cx:`6`,cy:`15`,r:`2.5`,stroke:`#C3C2C1`,strokeWidth:`1`,fill:`none`})]})}function f({className:e}){return(0,i.jsxs)(`svg`,{className:e,viewBox:`0 0 12 20`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,i.jsx)(`rect`,{x:`4.5`,y:`8`,width:`3`,height:`4.5`,fill:`#d4a017`,rx:`0.5`}),(0,i.jsx)(`circle`,{cx:`6`,cy:`15`,r:`2`,fill:`#d4a017`}),(0,i.jsx)(`path`,{d:`M6 0.5C4.6 0.5 3.5 1.6 3.5 3V12.1C2.6 12.8 2 13.9 2 15C2 17.2 3.8 19 6 19C8.2 19 10 17.2 10 15C10 13.9 9.4 12.8 8.5 12.1V3C8.5 1.6 7.4 0.5 6 0.5Z`,stroke:`#C3C2C1`,strokeWidth:`1`,fill:`none`})]})}function p({className:e}){return(0,i.jsxs)(`svg`,{className:e,viewBox:`0 0 12 20`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,i.jsx)(`rect`,{x:`4.5`,y:`3`,width:`3`,height:`9.5`,fill:`#c62828`,rx:`0.5`}),(0,i.jsx)(`circle`,{cx:`6`,cy:`15`,r:`2`,fill:`#c62828`}),(0,i.jsx)(`path`,{d:`M6 0.5C4.6 0.5 3.5 1.6 3.5 3V12.1C2.6 12.8 2 13.9 2 15C2 17.2 3.8 19 6 19C8.2 19 10 17.2 10 15C10 13.9 9.4 12.8 8.5 12.1V3C8.5 1.6 7.4 0.5 6 0.5Z`,stroke:`#C3C2C1`,strokeWidth:`1`,fill:`none`})]})}function m({humidity:e,goodThreshold:t=40,fairThreshold:n=60}){let r,a;return e<=t?(r=`#22a352`,a=c):e<=n?(r=`#d4a017`,a=l):(r=`#c62828`,a=u),(0,i.jsxs)(`div`,{className:`flex items-center gap-0.5`,children:[(0,i.jsx)(a,{className:`w-3 h-3.5`}),(0,i.jsxs)(`span`,{className:`font-medium tabular-nums text-xs`,style:{color:r},children:[e,`%`]})]})}function h({temp:e,goodThreshold:t=28,fairThreshold:n=35}){let r,a;return e<=t?(r=`#22a352`,a=d):e<=n?(r=`#d4a017`,a=f):(r=`#c62828`,a=p),(0,i.jsxs)(`div`,{className:`flex items-center gap-0.5`,children:[(0,i.jsx)(a,{className:`w-3 h-3.5`}),(0,i.jsxs)(`span`,{className:`font-medium tabular-nums text-xs`,style:{color:r},children:[e,`°C`]})]})}function g({side:e}){return(0,i.jsx)(`span`,{className:`inline-flex items-center justify-center w-4 h-4 text-[9px] font-bold rounded`,style:{backgroundColor:`#1a4d2e`,color:`#00ae42`},children:e})}function _({tray:e,slotIndex:t,isActive:s,fillOverride:c,spoolmanFill:l,accessibleLabel:u,onClick:d}){let f=o(e),p=r(e),m=a(e.tray_color),h=e.remain!==null&&e.remain!==void 0&&e.remain>=0?e.remain:null,g=l??(c===0&&h!==null&&h>0?null:c)??h;return(0,i.jsxs)(`div`,{className:`relative flex flex-col items-center p-2.5 rounded-lg border transition-all ${s?`ring-2 ring-bambu-green border-bambu-green bg-bambu-green/10`:`border-transparent`} ${d?`cursor-pointer hover:border-bambu-gray hover:bg-bambu-dark-tertiary`:``}`,onClick:d,onKeyDown:d?e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),d())}:void 0,role:d?`button`:void 0,tabIndex:d?0:void 0,"aria-pressed":d?s:void 0,"aria-label":d?u:void 0,title:d?u:void 0,"data-testid":d?`ams-slot`:void 0,children:[(0,i.jsxs)(`div`,{className:`relative w-16 h-16 mb-1`,children:[f?(0,i.jsx)(`div`,{className:`w-full h-full rounded-full border-2 border-dashed border-gray-500 flex items-center justify-center`,children:(0,i.jsx)(`div`,{className:`w-3 h-3 rounded-full bg-gray-600`})}):(0,i.jsxs)(`svg`,{viewBox:`0 0 56 56`,className:`w-full h-full`,children:[(0,i.jsx)(`circle`,{cx:`28`,cy:`28`,r:`26`,fill:m}),(0,i.jsx)(`circle`,{cx:`28`,cy:`28`,r:`20`,fill:m,style:{filter:`brightness(0.85)`}}),(0,i.jsx)(`ellipse`,{cx:`20`,cy:`20`,rx:`6`,ry:`4`,fill:`white`,opacity:`0.3`}),(0,i.jsx)(`circle`,{cx:`28`,cy:`28`,r:`8`,fill:`#2d2d2d`}),(0,i.jsx)(`circle`,{cx:`28`,cy:`28`,r:`5`,fill:`#1a1a1a`})]}),s&&(0,i.jsx)(`div`,{className:`absolute -bottom-1 left-1/2 -translate-x-1/2 w-2.5 h-2.5 bg-bambu-green rounded-full`})]}),(0,i.jsx)(`span`,{className:`text-sm text-bambu-gray-light truncate max-w-full`,title:p===`reset`?`Spool loaded — slot not configured`:void 0,children:f?p===`reset`?`?`:`Empty`:e.tray_type||`Unknown`}),!f&&g!==null&&g>=0&&(0,i.jsx)(`div`,{className:`w-full h-1 bg-bambu-dark-tertiary rounded-full overflow-hidden mt-1`,children:(0,i.jsx)(`div`,{className:`h-full rounded-full transition-all`,style:{width:`${g}%`,backgroundColor:n(g)}})}),(0,i.jsx)(`span`,{className:`absolute top-1 right-1 rounded bg-bambu-dark-tertiary px-1.5 py-0.5 text-[10px] font-semibold text-bambu-gray-light`,children:t+1})]})}function v({unit:e,activeSlot:n,onConfigureSlot:r,isDualNozzle:a,nozzleSide:c,thresholds:l,fillOverrides:u,spoolmanFillOverrides:d}){let{t:f}=t(),p=e.tray||[],v=e.is_ams_ht,y=v?1:4,b=s(e.id);return(0,i.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-[var(--border-color)] p-3 shadow-sm`,children:[(0,i.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,i.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,i.jsx)(`span`,{className:`text-white font-medium text-base`,children:b}),a&&c&&(0,i.jsx)(g,{side:c})]}),(0,i.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.temp!=null&&(0,i.jsx)(h,{temp:e.temp,goodThreshold:l?.tempGood,fairThreshold:l?.tempFair}),e.humidity!=null&&(0,i.jsx)(m,{humidity:e.humidity,goodThreshold:l?.humidityGood,fairThreshold:l?.humidityFair})]})]}),(0,i.jsx)(`div`,{className:`grid ${v?`grid-cols-1 max-w-[100px] mx-auto`:`grid-cols-4`} gap-2`,children:Array.from({length:y}).map((t,a)=>{let s=p[a]||{id:a,tray_color:null,tray_type:``,tray_sub_brands:null,tray_id_name:null,tray_info_idx:null,remain:-1,k:null,cali_idx:null,tag_uid:null,tray_uuid:null,nozzle_temp_min:null,nozzle_temp_max:null};return(0,i.jsx)(_,{tray:s,slotIndex:a,isActive:n===a,fillOverride:u?.[`${e.id}-${a}`]??null,spoolmanFill:d?.[`${e.id}-${a}`]??null,accessibleLabel:f(`configureAmsSlot.slotLabel`,{ams:b,slot:a+1}),onClick:r?()=>r(e.id,a,o(s)?null:s):void 0},a)})})]})}export{h as i,m as n,g as r,v as t}; \ No newline at end of file +import{C as e,w as t}from"./client-DnySrlFv.js";import{K as n,W as r}from"./index-Cxa-KVmA.js";var i=e();function a(e){return e?`#${e.slice(0,6)}`:`#808080`}function o(e){return!e.tray_type||e.tray_type===``}function s(e){return e<=3?`AMS ${String.fromCharCode(65+e)}`:e>=128&&e<=135?`AMS HT ${String.fromCharCode(65+e-128)}`:`AMS ${e}`}function c({className:e}){return(0,i.jsx)(`svg`,{className:e,viewBox:`0 0 36 54`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:(0,i.jsx)(`path`,{d:`M17.8131 0.00538C18.4463 -0.15091 20.3648 3.14642 20.8264 3.84781C25.4187 10.816 35.3089 26.9368 35.9383 34.8694C37.4182 53.5822 11.882 61.3357 2.53721 45.3789C-1.73471 38.0791 0.016 32.2049 3.178 25.0232C6.99221 16.3662 12.6411 7.90372 17.8131 0.00538ZM18.3738 7.24807L17.5881 7.48441C14.4452 12.9431 10.917 18.2341 8.19369 23.9368C4.6808 31.29 1.18317 38.5479 7.69403 45.5657C17.3058 55.9228 34.9847 46.8808 31.4604 32.8681C29.2558 24.0969 22.4207 15.2913 18.3776 7.24807H18.3738Z`,fill:`#C3C2C1`})})}function l({className:e}){return(0,i.jsxs)(`svg`,{className:e,viewBox:`0 0 35 53`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,i.jsx)(`path`,{d:`M17.3165 0.0038C17.932 -0.14959 19.7971 3.08645 20.2458 3.77481C24.7103 10.6135 34.3251 26.4346 34.937 34.2198C36.3757 52.5848 11.5505 60.1942 2.46584 44.534C-1.68714 37.3735 0.0148 31.6085 3.08879 24.5603C6.79681 16.0605 12.2884 7.75907 17.3165 0.0038ZM17.8615 7.11561L17.0977 7.34755C14.0423 12.7048 10.6124 17.8974 7.96483 23.4941C4.54975 30.7107 1.14949 37.8337 7.47908 44.721C16.8233 54.8856 34.01 46.0117 30.5838 32.2595C28.4405 23.6512 21.7957 15.0093 17.8652 7.11561H17.8615Z`,fill:`#C3C2C1`}),(0,i.jsx)(`path`,{d:`M5.03547 30.112C9.64453 30.4936 11.632 35.7985 16.4154 35.791C19.6339 35.7873 20.2161 33.2283 22.3853 31.6197C31.6776 24.7286 33.5835 37.4894 27.9881 44.4254C18.1878 56.5653 -1.16063 44.6013 5.03917 30.1158L5.03547 30.112Z`,fill:`#1F8FEB`})]})}function u({className:e}){return(0,i.jsxs)(`svg`,{className:e,viewBox:`0 0 36 54`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,i.jsx)(`path`,{d:`M17.9625 4.48059L4.77216 26.3154L2.08228 40.2175L10.0224 50.8414H23.1594L33.3246 42.1693V30.2455L17.9625 4.48059Z`,fill:`#1F8FEB`}),(0,i.jsx)(`path`,{d:`M17.7948 0.00538C18.4273 -0.15091 20.3438 3.14642 20.8048 3.84781C25.3921 10.816 35.2715 26.9368 35.9001 34.8694C37.3784 53.5822 11.8702 61.3357 2.53562 45.3789C-1.73163 38.0829 0.0134 32.2087 3.1757 25.027C6.98574 16.3662 12.6284 7.90372 17.7948 0.00538ZM18.3549 7.24807L17.57 7.48441C14.4306 12.9431 10.9063 18.2341 8.1859 23.9368C4.67686 31.29 1.18305 38.5479 7.68679 45.5657C17.2881 55.9228 34.9476 46.8808 31.4271 32.8681C29.2249 24.0969 22.3974 15.2913 18.3587 7.24807H18.3549Z`,fill:`#C3C2C1`})]})}function d({className:e}){return(0,i.jsxs)(`svg`,{className:e,viewBox:`0 0 12 20`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,i.jsx)(`path`,{d:`M6 0.5C4.6 0.5 3.5 1.6 3.5 3V12.1C2.6 12.8 2 13.9 2 15C2 17.2 3.8 19 6 19C8.2 19 10 17.2 10 15C10 13.9 9.4 12.8 8.5 12.1V3C8.5 1.6 7.4 0.5 6 0.5Z`,stroke:`#C3C2C1`,strokeWidth:`1`,fill:`none`}),(0,i.jsx)(`circle`,{cx:`6`,cy:`15`,r:`2.5`,stroke:`#C3C2C1`,strokeWidth:`1`,fill:`none`})]})}function f({className:e}){return(0,i.jsxs)(`svg`,{className:e,viewBox:`0 0 12 20`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,i.jsx)(`rect`,{x:`4.5`,y:`8`,width:`3`,height:`4.5`,fill:`#d4a017`,rx:`0.5`}),(0,i.jsx)(`circle`,{cx:`6`,cy:`15`,r:`2`,fill:`#d4a017`}),(0,i.jsx)(`path`,{d:`M6 0.5C4.6 0.5 3.5 1.6 3.5 3V12.1C2.6 12.8 2 13.9 2 15C2 17.2 3.8 19 6 19C8.2 19 10 17.2 10 15C10 13.9 9.4 12.8 8.5 12.1V3C8.5 1.6 7.4 0.5 6 0.5Z`,stroke:`#C3C2C1`,strokeWidth:`1`,fill:`none`})]})}function p({className:e}){return(0,i.jsxs)(`svg`,{className:e,viewBox:`0 0 12 20`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,i.jsx)(`rect`,{x:`4.5`,y:`3`,width:`3`,height:`9.5`,fill:`#c62828`,rx:`0.5`}),(0,i.jsx)(`circle`,{cx:`6`,cy:`15`,r:`2`,fill:`#c62828`}),(0,i.jsx)(`path`,{d:`M6 0.5C4.6 0.5 3.5 1.6 3.5 3V12.1C2.6 12.8 2 13.9 2 15C2 17.2 3.8 19 6 19C8.2 19 10 17.2 10 15C10 13.9 9.4 12.8 8.5 12.1V3C8.5 1.6 7.4 0.5 6 0.5Z`,stroke:`#C3C2C1`,strokeWidth:`1`,fill:`none`})]})}function m({humidity:e,goodThreshold:t=40,fairThreshold:n=60}){let r,a;return e<=t?(r=`#22a352`,a=c):e<=n?(r=`#d4a017`,a=l):(r=`#c62828`,a=u),(0,i.jsxs)(`div`,{className:`flex items-center gap-0.5`,children:[(0,i.jsx)(a,{className:`w-3 h-3.5`}),(0,i.jsxs)(`span`,{className:`font-medium tabular-nums text-xs`,style:{color:r},children:[e,`%`]})]})}function h({temp:e,goodThreshold:t=28,fairThreshold:n=35}){let r,a;return e<=t?(r=`#22a352`,a=d):e<=n?(r=`#d4a017`,a=f):(r=`#c62828`,a=p),(0,i.jsxs)(`div`,{className:`flex items-center gap-0.5`,children:[(0,i.jsx)(a,{className:`w-3 h-3.5`}),(0,i.jsxs)(`span`,{className:`font-medium tabular-nums text-xs`,style:{color:r},children:[e,`°C`]})]})}function g({side:e}){return(0,i.jsx)(`span`,{className:`inline-flex items-center justify-center w-4 h-4 text-[9px] font-bold rounded`,style:{backgroundColor:`#1a4d2e`,color:`#00ae42`},children:e})}function _({tray:e,slotIndex:t,isActive:s,fillOverride:c,spoolmanFill:l,accessibleLabel:u,onClick:d}){let f=o(e),p=r(e),m=a(e.tray_color),h=e.remain!==null&&e.remain!==void 0&&e.remain>=0?e.remain:null,g=l??(c===0&&h!==null&&h>0?null:c)??h;return(0,i.jsxs)(`div`,{className:`relative flex flex-col items-center p-2.5 rounded-lg border transition-all ${s?`ring-2 ring-bambu-green border-bambu-green bg-bambu-green/10`:`border-transparent`} ${d?`cursor-pointer hover:border-bambu-gray hover:bg-bambu-dark-tertiary`:``}`,onClick:d,onKeyDown:d?e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),d())}:void 0,role:d?`button`:void 0,tabIndex:d?0:void 0,"aria-pressed":d?s:void 0,"aria-label":d?u:void 0,title:d?u:void 0,"data-testid":d?`ams-slot`:void 0,children:[(0,i.jsxs)(`div`,{className:`relative w-16 h-16 mb-1`,children:[f?(0,i.jsx)(`div`,{className:`w-full h-full rounded-full border-2 border-dashed border-gray-500 flex items-center justify-center`,children:(0,i.jsx)(`div`,{className:`w-3 h-3 rounded-full bg-gray-600`})}):(0,i.jsxs)(`svg`,{viewBox:`0 0 56 56`,className:`w-full h-full`,children:[(0,i.jsx)(`circle`,{cx:`28`,cy:`28`,r:`26`,fill:m}),(0,i.jsx)(`circle`,{cx:`28`,cy:`28`,r:`20`,fill:m,style:{filter:`brightness(0.85)`}}),(0,i.jsx)(`ellipse`,{cx:`20`,cy:`20`,rx:`6`,ry:`4`,fill:`white`,opacity:`0.3`}),(0,i.jsx)(`circle`,{cx:`28`,cy:`28`,r:`8`,fill:`#2d2d2d`}),(0,i.jsx)(`circle`,{cx:`28`,cy:`28`,r:`5`,fill:`#1a1a1a`})]}),s&&(0,i.jsx)(`div`,{className:`absolute -bottom-1 left-1/2 -translate-x-1/2 w-2.5 h-2.5 bg-bambu-green rounded-full`})]}),(0,i.jsx)(`span`,{className:`text-sm text-bambu-gray-light truncate max-w-full`,title:p===`reset`?`Spool loaded — slot not configured`:void 0,children:f?p===`reset`?`?`:`Empty`:e.tray_type||`Unknown`}),!f&&g!==null&&g>=0&&(0,i.jsx)(`div`,{className:`w-full h-1 bg-bambu-dark-tertiary rounded-full overflow-hidden mt-1`,children:(0,i.jsx)(`div`,{className:`h-full rounded-full transition-all`,style:{width:`${g}%`,backgroundColor:n(g)}})}),(0,i.jsx)(`span`,{className:`absolute top-1 right-1 rounded bg-bambu-dark-tertiary px-1.5 py-0.5 text-[10px] font-semibold text-bambu-gray-light`,children:t+1})]})}function v({unit:e,activeSlot:n,onConfigureSlot:r,isDualNozzle:a,nozzleSide:c,thresholds:l,fillOverrides:u,spoolmanFillOverrides:d}){let{t:f}=t(),p=e.tray||[],v=e.is_ams_ht,y=v?1:4,b=s(e.id);return(0,i.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-[var(--border-color)] p-3 shadow-sm`,children:[(0,i.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,i.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,i.jsx)(`span`,{className:`text-white font-medium text-base`,children:b}),a&&c&&(0,i.jsx)(g,{side:c})]}),(0,i.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.temp!=null&&(0,i.jsx)(h,{temp:e.temp,goodThreshold:l?.tempGood,fairThreshold:l?.tempFair}),e.humidity!=null&&(0,i.jsx)(m,{humidity:e.humidity,goodThreshold:l?.humidityGood,fairThreshold:l?.humidityFair})]})]}),(0,i.jsx)(`div`,{className:`grid ${v?`grid-cols-1 max-w-[100px] mx-auto`:`grid-cols-4`} gap-2`,children:Array.from({length:y}).map((t,a)=>{let s=p[a]||{id:a,tray_color:null,tray_type:``,tray_sub_brands:null,tray_id_name:null,tray_info_idx:null,remain:-1,k:null,cali_idx:null,tag_uid:null,tray_uuid:null,nozzle_temp_min:null,nozzle_temp_max:null};return(0,i.jsx)(_,{tray:s,slotIndex:a,isActive:n===a,fillOverride:u?.[`${e.id}-${a}`]??null,spoolmanFill:d?.[`${e.id}-${a}`]??null,accessibleLabel:f(`configureAmsSlot.slotLabel`,{ams:b,slot:a+1}),onClick:r?()=>r(e.id,a,o(s)?null:s):void 0},a)})})]})}export{h as i,m as n,g as r,v as t}; \ No newline at end of file diff --git a/static/assets/ArchivesPage-CSganGGR.js b/static/assets/ArchivesPage-BrcJqnr-.js similarity index 99% rename from static/assets/ArchivesPage-CSganGGR.js rename to static/assets/ArchivesPage-BrcJqnr-.js index 55b527042..768ced8e4 100644 --- a/static/assets/ArchivesPage-CSganGGR.js +++ b/static/assets/ArchivesPage-BrcJqnr-.js @@ -1,4 +1,4 @@ -import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,p as i,w as a,x as o}from"./client-DnySrlFv.js";import{n as s}from"./QueryClientProvider-Ce8_sN3w.js";import{t as c}from"./useQuery-BBCjCezC.js";import{t as l}from"./useMutation-B-Tr2hIP.js";import{t as u}from"./createLucideIcon-DvBYJlWL.js";import{t as d}from"./arrow-up-down-BdyOV_2F.js";import{t as f}from"./RichTextEditor-BBu-zZie.js";import{t as p}from"./box-DAdKb9s5.js";import{t as m}from"./calendar-BLKPnWqV.js";import{t as h}from"./check-Ck0cMLU4.js";import{a as g,i as _,n as v,r as y}from"./info-ROUoQhJR.js";import{n as b,t as x}from"./chevrons-right-DTJgqnxZ.js";import{n as S,r as C}from"./ToastContext-BRX0SW3C.js";import{t as w}from"./coins-4u6IPkR-.js";import{t as T}from"./cog-Dol1I0kq.js";import{t as E}from"./columns-2-DVEObeDC.js";import{t as D}from"./copy-Cu_0GKCU.js";import{t as O}from"./ellipsis-vertical-t2D7cYyp.js";import{t as k}from"./file-box-04V4jZ9_.js";import{t as ee}from"./file-spreadsheet-WxOA9vYy.js";import{n as A,t as te}from"./ContextMenu-BOFgRmSk.js";import{n as j,t as ne}from"./scan-search-BDoNAXzz.js";import{t as M}from"./funnel-C3dyAMK9.js";import{t as N}from"./gauge-D21zgWMb.js";import{t as re}from"./git-compare-J4KX0xAJ.js";import{n as ie,t as ae}from"./SliceModal-TzmWgODN.js";import{t as oe}from"./history-B4lOLL01.js";import{t as se}from"./layout-grid-DkD3u6wa.js";import{t as ce}from"./list-CLcpeoSz.js";import{t as P}from"./loader-circle-BEmFtawu.js";import{t as le}from"./package-BGUevlqS.js";import{t as F}from"./pause-DFb6GX_6.js";import{t as ue}from"./pen-line-BWR04BX-.js";import{t as de}from"./play-DIDYtk2S.js";import{t as fe}from"./qr-code-CCCo2-Br.js";import{t as pe}from"./search-0n0CBc74.js";import{t as me}from"./skip-forward-BsuMfFkw.js";import{t as he}from"./sticky-note-BH0LPqRx.js";import{t as I}from"./triangle-alert-Dt_1FcBy.js";import{t as L}from"./x-DR-Trv6U.js";import{i as R,n as z,t as B}from"./Card-Bzc64K35.js";import{t as ge}from"./file-DDkFXH-b.js";import{t as V}from"./Button-DDr6eAFy.js";import{a as _e,i as ve,l as H,o as ye,v as be}from"./date-G9KUauqz.js";import{$t as xe,An as Se,At as U,Cn as Ce,Et as we,F as Te,It as Ee,Jt as De,L as Oe,Ln as ke,Lt as Ae,M as je,Mn as Me,Mt as Ne,On as Pe,Ot as Fe,P as Ie,Pn as Le,Pt as Re,R as ze,Rn as W,Rt as Be,T as Ve,Ut as He,Vn as Ue,Vt as We,Zt as G,_t as K,at as Ge,b as Ke,bt as qe,cn as Je,hn as Ye,j as Xe,jn as Ze,jt as Qe,kt as $e,tn as et,un as tt,vn as nt,wn as q,xn as rt,xt as it,y as at,yn as ot,yt as st}from"./index-0t--Yqoi.js";import{n as ct,r as lt,t as ut}from"./PhotoGalleryModal-C8-A6a4s.js";import{a as dt,o as ft}from"./slicer-DgCA7cW6.js";import{t as pt}from"./filamentTypes-Dysa4k6j.js";import{t as mt}from"./ColumnConfigModal-DrIkn1Rf.js";import{t as ht}from"./purify.es-F_7NWVtX.js";var gt=u(`calendar-days`,[[`path`,{d:`M8 2v4`,key:`1cmpym`}],[`path`,{d:`M16 2v4`,key:`4m81vk`}],[`rect`,{width:`18`,height:`18`,x:`3`,y:`4`,rx:`2`,key:`1hopcy`}],[`path`,{d:`M3 10h18`,key:`8toen8`}],[`path`,{d:`M8 14h.01`,key:`6423bh`}],[`path`,{d:`M12 14h.01`,key:`1etili`}],[`path`,{d:`M16 14h.01`,key:`1gbofw`}],[`path`,{d:`M8 18h.01`,key:`lrp35t`}],[`path`,{d:`M12 18h.01`,key:`mhygvu`}],[`path`,{d:`M16 18h.01`,key:`kzsmim`}]]),_t=u(`clipboard-list`,[[`rect`,{width:`8`,height:`4`,x:`8`,y:`2`,rx:`1`,ry:`1`,key:`tgr4d6`}],[`path`,{d:`M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2`,key:`116196`}],[`path`,{d:`M12 11h4`,key:`1jrz19`}],[`path`,{d:`M12 16h4`,key:`n85exb`}],[`path`,{d:`M8 11h.01`,key:`1dfujw`}],[`path`,{d:`M8 16h.01`,key:`18s6g9`}]]),vt=u(`file-code`,[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M10 12.5 8 15l2 2.5`,key:`1tg20x`}],[`path`,{d:`m14 12.5 2 2.5-2 2.5`,key:`yinavb`}]]),J=u(`file-play`,[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M15.033 13.44a.647.647 0 0 1 0 1.12l-4.065 2.352a.645.645 0 0 1-.968-.56v-4.704a.645.645 0 0 1 .967-.56z`,key:`1tzo1f`}]]),yt=u(`git-branch`,[[`line`,{x1:`6`,x2:`6`,y1:`3`,y2:`15`,key:`17qcm7`}],[`circle`,{cx:`18`,cy:`6`,r:`3`,key:`1h7g24`}],[`circle`,{cx:`6`,cy:`18`,r:`3`,key:`fqmcym`}],[`path`,{d:`M18 9a9 9 0 0 1-9 9`,key:`n2h4wq`}]]),bt=u(`scissors`,[[`circle`,{cx:`6`,cy:`6`,r:`3`,key:`1lh9wr`}],[`path`,{d:`M8.12 8.12 12 12`,key:`1alkpv`}],[`path`,{d:`M20 4 8.12 15.88`,key:`xgtan2`}],[`circle`,{cx:`6`,cy:`18`,r:`3`,key:`fqmcym`}],[`path`,{d:`M14.8 14.8 20 20`,key:`ptml3r`}]]),xt=u(`skip-back`,[[`path`,{d:`M17.971 4.285A2 2 0 0 1 21 6v12a2 2 0 0 1-3.029 1.715l-9.997-5.998a2 2 0 0 1-.003-3.432z`,key:`15892j`}],[`path`,{d:`M3 20V4`,key:`1ptbpl`}]]),Y=u(`volume-2`,[[`path`,{d:`M11 4.702a.705.705 0 0 0-1.203-.498L6.413 7.587A1.4 1.4 0 0 1 5.416 8H3a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h2.416a1.4 1.4 0 0 1 .997.413l3.383 3.384A.705.705 0 0 0 11 19.298z`,key:`uqj9uw`}],[`path`,{d:`M16 9a5 5 0 0 1 0 6`,key:`1q6k2b`}],[`path`,{d:`M19.364 18.364a9 9 0 0 0 0-12.728`,key:`ijwkga`}]]),St=u(`volume-x`,[[`path`,{d:`M11 4.702a.705.705 0 0 0-1.203-.498L6.413 7.587A1.4 1.4 0 0 1 5.416 8H3a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h2.416a1.4 1.4 0 0 1 .997.413l3.383 3.384A.705.705 0 0 0 11 19.298z`,key:`uqj9uw`}],[`line`,{x1:`22`,x2:`16`,y1:`9`,y2:`15`,key:`1ewh16`}],[`line`,{x1:`16`,x2:`22`,y1:`9`,y2:`15`,key:`5ykzw1`}]]),X=e(n(),1),Z=t();function Ct({onClose:e,initialFiles:t}){let{t:n}=a(),i=s(),{showToast:o}=S(),c=(0,X.useRef)(null),[u,d]=(0,X.useState)(()=>t?.filter(e=>e.name.endsWith(`.3mf`)).map(e=>({file:e,status:`pending`}))||[]),[f,p]=(0,X.useState)(!1),[m,h]=(0,X.useState)(null);(0,X.useEffect)(()=>{let t=t=>{t.key===`Escape`&&e()};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e]);let g=l({mutationFn:e=>r.uploadArchivesBulk(e),onSuccess:e=>{h(e),i.invalidateQueries({queryKey:[`archives`]}),i.invalidateQueries({queryKey:[`archiveStats`]}),d(t=>t.map(t=>{let n=e.results.find(e=>e.filename===t.file.name),r=e.errors.find(e=>e.filename===t.file.name);return n?{...t,status:`success`,archiveId:n.id}:r?{...t,status:`error`,error:r.error}:t})),e.failed===0?o(`${e.uploaded} file${e.uploaded===1?``:`s`} uploaded`):e.uploaded===0?o(`Failed to upload ${e.failed} file${e.failed===1?``:`s`}`,`error`):o(`${e.uploaded} uploaded, ${e.failed} failed`,`warning`)},onError:()=>{d(e=>e.map(e=>({...e,status:`error`,error:`Upload failed`}))),o(`Upload failed`,`error`)}}),_=(0,X.useCallback)(e=>{e.preventDefault(),p(!0)},[]),v=(0,X.useCallback)(e=>{e.preventDefault(),p(!1)},[]),b=(0,X.useCallback)(e=>{e.preventDefault(),p(!1);let t=Array.from(e.dataTransfer.files).filter(e=>e.name.endsWith(`.3mf`));t.length>0&&d(e=>[...e,...t.map(e=>({file:e,status:`pending`}))])},[]),x=(0,X.useCallback)(e=>{let t=Array.from(e.target.files||[]).filter(e=>e.name.endsWith(`.3mf`));t.length>0&&d(e=>[...e,...t.map(e=>({file:e,status:`pending`}))]),c.current&&(c.current.value=``)},[]),w=(0,X.useCallback)(e=>{d(t=>t.filter((t,n)=>n!==e))},[]),T=()=>{if(u.length===0)return;let e=u.filter(e=>e.status===`pending`);e.length!==0&&(d(e=>e.map(e=>e.status===`pending`?{...e,status:`uploading`}:e)),g.mutate(e.map(e=>e.file)))},E=u.filter(e=>e.status===`pending`).length,D=g.isPending;return(0,Z.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,children:(0,Z.jsx)(B,{className:`w-full max-w-2xl max-h-[90vh] flex flex-col`,children:(0,Z.jsxs)(z,{className:`p-0 flex flex-col h-full`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,Z.jsx)(`h2`,{className:`text-xl font-semibold text-white`,children:n(`uploadModal.title`)}),(0,Z.jsx)(`button`,{onClick:e,className:`text-bambu-gray hover:text-white transition-colors`,children:(0,Z.jsx)(L,{className:`w-5 h-5`})})]}),(0,Z.jsx)(`div`,{className:`p-4`,children:(0,Z.jsxs)(`div`,{className:`border-2 border-dashed rounded-lg p-8 text-center transition-colors ${f?`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary hover:border-bambu-gray`}`,onDragOver:_,onDragLeave:v,onDrop:b,children:[(0,Z.jsx)($e,{className:`w-12 h-12 mx-auto mb-4 text-bambu-gray`}),(0,Z.jsx)(`p`,{className:`text-white mb-2`,children:n(`uploadModal.dragDrop`)}),(0,Z.jsx)(`p`,{className:`text-bambu-gray text-sm mb-4`,children:n(`uploadModal.or`)}),(0,Z.jsx)(V,{variant:`secondary`,onClick:()=>c.current?.click(),disabled:D,children:n(`uploadModal.browseFiles`)}),(0,Z.jsx)(`input`,{ref:c,type:`file`,accept:`.3mf`,multiple:!0,className:`hidden`,onChange:x})]})}),(0,Z.jsx)(`div`,{className:`px-4 pb-4`,children:(0,Z.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`uploadModal.extractionInfo`)})}),u.length>0&&(0,Z.jsx)(`div`,{className:`px-4 pb-4 max-h-60 overflow-y-auto`,children:(0,Z.jsx)(`div`,{className:`space-y-2`,children:u.map((e,t)=>(0,Z.jsxs)(`div`,{className:`flex items-center gap-3 p-3 bg-bambu-dark rounded-lg`,children:[(0,Z.jsx)(A,{className:`w-5 h-5 text-bambu-gray flex-shrink-0`}),(0,Z.jsx)(`span`,{className:`flex-1 text-white text-sm truncate`,children:e.file.name}),(0,Z.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[(e.file.size/(1024*1024)).toFixed(1),` MB`]}),e.status===`pending`&&(0,Z.jsx)(`button`,{onClick:()=>w(t),className:`text-bambu-gray hover:text-red-600 dark:hover:text-red-400 transition-colors`,disabled:D,children:(0,Z.jsx)(L,{className:`w-4 h-4`})}),e.status===`uploading`&&(0,Z.jsx)(P,{className:`w-4 h-4 text-bambu-green animate-spin`}),e.status===`success`&&(0,Z.jsx)(C,{className:`w-4 h-4 text-bambu-green`}),e.status===`error`&&(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`span`,{className:`text-xs text-red-700 dark:text-red-400`,children:e.error}),(0,Z.jsx)(y,{className:`w-4 h-4 text-red-600 dark:text-red-400`})]})]},`${e.file.name}-${t}`))})}),m&&(0,Z.jsx)(`div`,{className:`px-4 pb-4`,children:(0,Z.jsx)(`div`,{className:`p-3 bg-bambu-dark rounded-lg`,children:(0,Z.jsxs)(`p`,{className:`text-sm text-white`,children:[(0,Z.jsx)(`span`,{className:`text-bambu-green`,children:m.uploaded}),` `,n(`uploadModal.uploaded`),m.failed>0&&(0,Z.jsxs)(Z.Fragment,{children:[`, `,(0,Z.jsx)(`span`,{className:`text-red-700 dark:text-red-400`,children:m.failed}),` `,n(`uploadModal.failed`)]})]})})}),(0,Z.jsxs)(`div`,{className:`flex gap-3 p-4 border-t border-bambu-dark-tertiary`,children:[(0,Z.jsx)(V,{variant:`secondary`,onClick:e,className:`flex-1`,children:n(m?`common.close`:`common.cancel`)}),!m&&(0,Z.jsx)(V,{onClick:T,disabled:E===0||D,className:`flex-1`,children:D?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(P,{className:`w-4 h-4 animate-spin`}),n(`uploadModal.uploading`)]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)($e,{className:`w-4 h-4`}),n(`uploadModal.upload`),` `,E>0&&`(${E})`]})})]})]})})})}var wt=365;function Tt({onClose:e,initialDays:t}){let{t:n}=a(),i=s(),{showToast:o}=S(),[u,d]=(0,X.useState)(t??wt),[f,p]=(0,X.useState)(!1),[m,h]=(0,X.useState)(u);(0,X.useEffect)(()=>{let e=window.setTimeout(()=>h(u),300);return()=>window.clearTimeout(e)},[u]);let g=c({queryKey:[`archive-purge-preview`,m,f],queryFn:()=>r.previewArchivePurge(m,f),enabled:m>=1}),_=l({mutationFn:()=>r.executeArchivePurge(u,f),onSuccess:t=>{o(n(`archivePurge.toast.success`,{count:t.deleted}),`success`),i.invalidateQueries({queryKey:[`archives`]}),i.invalidateQueries({queryKey:[`archive-stats`]}),e()},onError:e=>o(e.message||n(`archivePurge.toast.failed`),`error`)});(0,X.useEffect)(()=>{let t=t=>{t.key===`Escape`&&!_.isPending&&e()};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e,_.isPending]);let v=g.data,y=v?.count??0,b=v?.total_bytes??0,x=y>0&&!_.isPending;return(0,Z.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4`,children:(0,Z.jsxs)(`div`,{className:`bg-white dark:bg-gray-900 rounded-lg shadow-xl max-w-lg w-full`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-gray-200 dark:border-gray-700`,children:[(0,Z.jsxs)(`h2`,{className:`text-lg font-semibold text-gray-900 dark:text-gray-100 flex items-center gap-2`,children:[(0,Z.jsx)(U,{className:`w-5 h-5`}),n(`archivePurge.title`)]}),(0,Z.jsx)(`button`,{onClick:e,className:`text-gray-400 hover:text-gray-600 dark:hover:text-gray-200`,"aria-label":n(`common.close`),disabled:_.isPending,children:(0,Z.jsx)(L,{className:`w-5 h-5`})})]}),(0,Z.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,Z.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400`,children:n(`archivePurge.description`)}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{htmlFor:`archive-purge-days`,className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:n(`archivePurge.ageLabel`)}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Z.jsx)(`input`,{id:`archive-purge-days`,type:`number`,min:1,max:3650,value:u,onChange:e=>d(Math.max(1,Math.min(3650,parseInt(e.target.value||`0`,10)||0))),className:`w-24 rounded border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-800 text-sm px-2 py-1 text-gray-900 dark:text-gray-100`}),(0,Z.jsx)(`span`,{className:`text-sm text-gray-600 dark:text-gray-400`,children:n(`archivePurge.days`)})]})]}),(0,Z.jsxs)(`div`,{className:`rounded border border-gray-200 dark:border-gray-700 bg-gray-50 dark:bg-gray-800/30 p-3`,children:[(0,Z.jsx)(`div`,{className:`text-xs font-semibold uppercase tracking-wide text-gray-600 dark:text-gray-300 mb-2`,children:n(`archivePurge.effectsTitle`)}),(0,Z.jsxs)(`ul`,{className:`text-xs text-gray-700 dark:text-gray-300 space-y-1 list-disc pl-4`,children:[(0,Z.jsx)(`li`,{children:n(`archivePurge.effect1`)}),(0,Z.jsx)(`li`,{children:n(`archivePurge.effect2`)}),(0,Z.jsx)(`li`,{children:n(`archivePurge.effect3`)}),(0,Z.jsx)(`li`,{children:n(`archivePurge.effect4`)})]})]}),(0,Z.jsx)(`div`,{className:`rounded border border-gray-200 dark:border-gray-700 bg-gray-50 dark:bg-gray-800/50 p-3`,children:g.isLoading||g.isFetching?(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-gray-500 dark:text-gray-400`,children:[(0,Z.jsx)(P,{className:`w-4 h-4 animate-spin`}),` `,n(`archivePurge.previewLoading`)]}):g.isError?(0,Z.jsx)(`div`,{className:`text-sm text-red-600 dark:text-red-400`,children:g.error?.message??n(`archivePurge.previewFailed`)}):(0,Z.jsxs)(`div`,{className:`text-sm text-gray-900 dark:text-gray-100`,children:[(0,Z.jsx)(`div`,{className:`font-medium`,children:n(`archivePurge.previewSummary`,{count:y,size:ge(b)})}),v?.sample_filenames&&v.sample_filenames.length>0&&(0,Z.jsxs)(`ul`,{className:`mt-2 text-xs text-gray-600 dark:text-gray-400 space-y-0.5 list-disc pl-4`,children:[v.sample_filenames.map(e=>(0,Z.jsx)(`li`,{className:`truncate`,children:e},e)),y>v.sample_filenames.length&&(0,Z.jsx)(`li`,{className:`list-none italic text-gray-500`,children:n(`archivePurge.andMore`,{count:y-v.sample_filenames.length})})]})]})}),(0,Z.jsxs)(`label`,{className:`flex gap-2 items-start rounded border border-gray-200 dark:border-gray-700 px-3 py-2 cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-800/50`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,checked:f,onChange:e=>p(e.target.checked),disabled:_.isPending,className:`mt-0.5 shrink-0`}),(0,Z.jsxs)(`span`,{className:`text-xs text-gray-700 dark:text-gray-300`,children:[(0,Z.jsx)(`span`,{className:`font-medium block mb-0.5`,children:n(`archivePurge.purgeStatsLabel`)}),(0,Z.jsx)(`span`,{className:`text-gray-500 dark:text-gray-400`,children:n(`archivePurge.purgeStatsHint`)})]})]}),(0,Z.jsxs)(`div`,{className:`flex gap-2 items-start text-xs text-amber-700 dark:text-amber-400 bg-amber-50 dark:bg-amber-900/20 rounded px-3 py-2`,children:[(0,Z.jsx)(I,{className:`w-4 h-4 mt-0.5 shrink-0`}),(0,Z.jsx)(`span`,{children:n(`archivePurge.warning`)})]})]}),(0,Z.jsxs)(`div`,{className:`flex justify-end gap-2 p-4 border-t border-gray-200 dark:border-gray-700`,children:[(0,Z.jsx)(V,{variant:`secondary`,onClick:e,disabled:_.isPending,children:n(`common.cancel`)}),(0,Z.jsx)(V,{variant:`danger`,disabled:!x,onClick:()=>_.mutate(),children:_.isPending?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(P,{className:`w-4 h-4 animate-spin mr-1`}),n(`archivePurge.purging`)]}):n(`archivePurge.confirmCta`,{count:y})})]})]})})}function Et({archiveId:e,archiveName:t,onClose:n}){let{t:r}=a();return(0,X.useEffect)(()=>{let e=e=>{e.key===`Escape`&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n]),(0,Z.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:n,children:(0,Z.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-2xl max-h-[85vh] flex flex-col`,onClick:e=>e.stopPropagation(),children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,Z.jsx)(oe,{className:`w-5 h-5 text-bambu-green flex-shrink-0`}),(0,Z.jsx)(`h2`,{className:`text-lg font-semibold text-white truncate`,title:t||``,children:r(`archives.runLog.modalTitle`,{name:t||r(`archives.runLog.modalTitleFallback`)})})]}),(0,Z.jsx)(`button`,{onClick:n,className:`text-bambu-gray hover:text-white transition-colors`,title:r(`common.close`),children:(0,Z.jsx)(L,{className:`w-5 h-5`})})]}),(0,Z.jsx)(`div`,{className:`p-6 overflow-y-auto flex-1`,children:(0,Z.jsx)(ze,{archiveId:e})})]})})}function Dt({selectedIds:e,existingTags:t,onClose:n}){let i=s(),{showToast:a}=S(),[o,c]=(0,X.useState)(``),[u,d]=(0,X.useState)(new Set),[f,p]=(0,X.useState)(`add`);(0,X.useEffect)(()=>{let e=e=>{e.key===`Escape`&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n]);let m=l({mutationFn:async()=>{let t=Array.from(u),n=0;for(let i of e)try{let e=await r.getArchive(i),a=e.tags?e.tags.split(`,`).map(e=>e.trim()).filter(Boolean):[],o;o=f===`add`?[...new Set([...a,...t])]:a.filter(e=>!u.has(e)),await r.updateArchive(i,{tags:o.join(`, `)}),n++}catch(e){throw console.error(`Failed to update archive ${i}:`,e),Error(`Failed on archive ${i}: ${e instanceof Error?e.message:`Unknown error`}`)}return{count:n,mode:f,tags:t}},onSuccess:({count:e,mode:t,tags:r})=>{i.invalidateQueries({queryKey:[`archives`]}),a(`${t===`add`?`Added`:`Removed`} ${r.length} tag${r.length===1?``:`s`} ${t===`add`?`to`:`from`} ${e} archive${e===1?``:`s`}`),n()},onError:e=>{a(e.message||`Failed to update tags`,`error`)}}),h=e=>{d(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},g=()=>{o.trim()&&!u.has(o.trim())&&(d(e=>new Set([...e,o.trim()])),c(``))};return(0,Z.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,children:(0,Z.jsx)(B,{className:`w-full max-w-md`,children:(0,Z.jsxs)(z,{className:`p-0`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(Re,{className:`w-5 h-5 text-bambu-green`}),(0,Z.jsx)(`h2`,{className:`text-xl font-semibold text-white`,children:f===`add`?`Add Tags`:`Remove Tags`})]}),(0,Z.jsx)(`button`,{onClick:n,className:`text-bambu-gray hover:text-white transition-colors`,children:(0,Z.jsx)(L,{className:`w-5 h-5`})})]}),(0,Z.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,Z.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[f===`add`?`Add`:`Remove`,` tags for `,e.length,` selected archive`,e.length===1?``:`s`]}),(0,Z.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Z.jsx)(V,{size:`sm`,variant:f===`add`?`primary`:`secondary`,onClick:()=>p(`add`),children:`Add Tags`}),(0,Z.jsx)(V,{size:`sm`,variant:f===`remove`?`primary`:`secondary`,onClick:()=>p(`remove`),children:`Remove Tags`})]}),f===`add`&&(0,Z.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Z.jsx)(`input`,{type:`text`,placeholder:`Enter new tag...`,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`,value:o,onChange:e=>c(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),g())}}),(0,Z.jsx)(V,{size:`sm`,variant:`secondary`,onClick:g,disabled:!o.trim(),children:(0,Z.jsx)(G,{className:`w-4 h-4`})})]}),t.length>0&&(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:`Existing tags:`}),(0,Z.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:t.map(e=>(0,Z.jsx)(`button`,{onClick:()=>h(e),className:`px-2 py-1 rounded text-sm transition-colors ${u.has(e)?`bg-bambu-green text-white`:`bg-bambu-dark-tertiary text-bambu-gray-light hover:bg-bambu-dark`}`,children:e},e))})]}),u.size>0&&(0,Z.jsxs)(`div`,{children:[(0,Z.jsxs)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:[`Tags to `,f===`add`?`add`:`remove`,`:`]}),(0,Z.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:Array.from(u).map(e=>(0,Z.jsxs)(`span`,{className:`px-2 py-1 rounded text-sm flex items-center gap-1 ${f===`add`?`bg-green-100 dark:bg-green-500/20 text-green-700 dark:text-green-400`:`bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400`}`,children:[e,(0,Z.jsx)(`button`,{onClick:()=>h(e),className:`hover:opacity-70`,children:(0,Z.jsx)(L,{className:`w-3 h-3`})})]},e))})]})]}),(0,Z.jsxs)(`div`,{className:`flex gap-3 p-4 border-t border-bambu-dark-tertiary`,children:[(0,Z.jsx)(V,{variant:`secondary`,onClick:n,className:`flex-1`,children:`Cancel`}),(0,Z.jsx)(V,{onClick:()=>m.mutate(),disabled:u.size===0||m.isPending,className:`flex-1`,children:m.isPending?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(P,{className:`w-4 h-4 animate-spin`}),`Processing...`]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(Re,{className:`w-4 h-4`}),f===`add`?`Add Tags`:`Remove Tags`]})})]})]})})})}function Ot({selectedIds:e,onClose:t}){let{t:n}=a(),i=s(),{showToast:o}=S(),[u,d]=(0,X.useState)(``),{data:f,isLoading:p}=c({queryKey:[`projects`],queryFn:()=>r.getProjects()}),m=(0,X.useMemo)(()=>f?Te([...f].sort((e,t)=>e.name.localeCompare(t.name))):void 0,[f]),h=u.trim().toLowerCase(),g=h?m?.filter(e=>e.name.toLowerCase().includes(h)):m,_=(m?.length??0)>5;(0,X.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]);let y=()=>Oe(i),b=l({mutationFn:async t=>(await r.addArchivesToProject(t,e),t),onSuccess:n=>{let r=f?.find(e=>e.id===n);y(),o(`Added ${e.length} archive${e.length===1?``:`s`} to "${r?.name}"`),t()},onError:()=>{o(`Failed to assign project`,`error`)}}),x=l({mutationFn:async()=>{for(let t of e)await r.updateArchive(t,{project_id:null});return e.length},onSuccess:e=>{y(),o(`Removed ${e} archive${e===1?``:`s`} from project`),t()},onError:()=>{o(`Failed to remove from project`,`error`)}}),C=b.isPending||x.isPending;return(0,Z.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,children:(0,Z.jsx)(B,{className:`w-full max-w-md max-h-[80vh] flex flex-col`,children:(0,Z.jsxs)(z,{className:`p-0 flex flex-col min-h-0`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary shrink-0`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(ot,{className:`w-5 h-5 text-bambu-green`}),(0,Z.jsx)(`h2`,{className:`text-xl font-semibold text-white`,children:`Assign to Project`})]}),(0,Z.jsx)(`button`,{onClick:t,className:`text-bambu-gray hover:text-white transition-colors`,disabled:C,children:(0,Z.jsx)(L,{className:`w-5 h-5`})})]}),(0,Z.jsxs)(`div`,{className:`p-4 space-y-3 overflow-y-auto min-h-0`,children:[(0,Z.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[`Assign `,e.length,` selected archive`,e.length===1?``:`s`,` to a project`]}),p?(0,Z.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,Z.jsx)(P,{className:`w-6 h-6 animate-spin text-bambu-gray`})}):(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsxs)(`button`,{onClick:()=>x.mutate(),disabled:C,className:`w-full flex items-center gap-3 p-3 rounded-lg bg-bambu-dark hover:bg-bambu-dark-tertiary border border-bambu-dark-tertiary transition-colors text-left disabled:opacity-50`,children:[(0,Z.jsx)(`div`,{className:`w-8 h-8 rounded-full bg-red-500/20 flex items-center justify-center shrink-0`,children:(0,Z.jsx)(v,{className:`w-4 h-4 text-red-600 dark:text-red-400`})}),(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(`p`,{className:`text-white font-medium`,children:`Remove from project`}),(0,Z.jsx)(`p`,{className:`text-sm text-bambu-gray truncate`,children:`Clear project assignment`})]}),x.isPending&&(0,Z.jsx)(P,{className:`w-4 h-4 animate-spin text-bambu-gray shrink-0`})]}),m&&m.length>0&&(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 py-2`,children:[(0,Z.jsx)(`div`,{className:`flex-1 h-px bg-bambu-dark-tertiary`}),(0,Z.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:`or assign to`}),(0,Z.jsx)(`div`,{className:`flex-1 h-px bg-bambu-dark-tertiary`})]}),_&&(0,Z.jsxs)(`div`,{className:`relative`,children:[(0,Z.jsx)(pe,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`}),(0,Z.jsx)(`input`,{type:`text`,value:u,onChange:e=>d(e.target.value),placeholder:n(`archives.menu.searchProjects`),className:`w-full pl-9 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray text-sm focus:border-bambu-green focus:outline-none`})]}),g?.map(e=>(0,Z.jsxs)(`button`,{onClick:()=>b.mutate(e.id),disabled:C,className:`w-full flex items-center gap-3 p-3 rounded-lg bg-bambu-dark hover:bg-bambu-dark-tertiary border border-bambu-dark-tertiary transition-colors text-left disabled:opacity-50`,children:[(0,Z.jsx)(`div`,{className:`w-8 h-8 rounded-full flex items-center justify-center shrink-0`,style:{backgroundColor:e.color?`${e.color}20`:`rgb(var(--bambu-green) / 0.2)`},children:(0,Z.jsx)(ot,{className:`w-4 h-4`,style:{color:e.color||`rgb(var(--bambu-green))`}})}),(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(`p`,{className:`text-white font-medium truncate`,children:e.name}),(0,Z.jsxs)(`p`,{className:`text-sm text-bambu-gray truncate`,children:[e.archive_count,` archive`,e.archive_count===1?``:`s`,e.status&&` • ${e.status}`]})]}),b.isPending&&b.variables===e.id&&(0,Z.jsx)(P,{className:`w-4 h-4 animate-spin text-bambu-gray shrink-0`})]},e.id)),(!m||m.length===0)&&(0,Z.jsx)(`p`,{className:`text-center text-bambu-gray py-4`,children:`No projects yet. Create one from the Projects page.`}),m&&m.length>0&&g?.length===0&&(0,Z.jsx)(`p`,{className:`text-center text-bambu-gray text-sm py-4`,children:`—`})]})]}),(0,Z.jsx)(`div`,{className:`flex gap-3 p-4 border-t border-bambu-dark-tertiary shrink-0`,children:(0,Z.jsx)(V,{variant:`secondary`,onClick:t,className:`flex-1`,disabled:C,children:`Cancel`})})]})})})}function kt(e,t){return new Date(e,t+1,0).getDate()}function At(e,t){return new Date(e,t,1).getDay()}var jt=[`January`,`February`,`March`,`April`,`May`,`June`,`July`,`August`,`September`,`October`,`November`,`December`],Mt=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`];function Nt({archives:e,onArchiveClick:t,highlightedArchiveId:n}){let i=new Date,[a,o]=(0,X.useState)(i.getMonth()),[s,c]=(0,X.useState)(i.getFullYear()),[l,u]=(0,X.useState)(null),[d,f]=(0,X.useState)(null),p=(0,X.useMemo)(()=>{let t=new Map;return e.forEach(e=>{let n=be(e.completed_at||e.created_at)||new Date,r=`${n.getFullYear()}-${String(n.getMonth()+1).padStart(2,`0`)}-${String(n.getDate()).padStart(2,`0`)}`,i=t.get(r)||[];i.push(e),t.set(r,i)}),t},[e]),m=kt(s,a),h=At(s,a),g=()=>{a===0?(o(11),c(s-1)):o(a-1)},_=()=>{a===11?(o(0),c(s+1)):o(a+1)},v=()=>{o(i.getMonth()),c(i.getFullYear())},y=[];for(let e=0;e{e!==l&&f(null),u(e)};return(0,Z.jsxs)(`div`,{className:`flex flex-col lg:flex-row gap-6`,children:[(0,Z.jsxs)(`div`,{className:`flex-1`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between mb-4`,children:[(0,Z.jsx)(`button`,{onClick:g,className:`p-2 hover:bg-bambu-dark-tertiary rounded-lg transition-colors`,children:(0,Z.jsx)(Ze,{className:`w-5 h-5 text-bambu-gray`})}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Z.jsxs)(`h2`,{className:`text-lg font-semibold text-white`,children:[jt[a],` `,s]}),(0,Z.jsx)(`button`,{onClick:v,className:`px-2 py-1 text-xs bg-bambu-dark-tertiary hover:bg-bambu-green/20 text-bambu-gray hover:text-white rounded transition-colors`,children:`Today`})]}),(0,Z.jsx)(`button`,{onClick:_,className:`p-2 hover:bg-bambu-dark-tertiary rounded-lg transition-colors`,children:(0,Z.jsx)(Me,{className:`w-5 h-5 text-bambu-gray`})})]}),(0,Z.jsx)(`div`,{className:`grid grid-cols-7 gap-1 mb-1`,children:Mt.map(e=>(0,Z.jsx)(`div`,{className:`text-center text-xs text-bambu-gray py-2`,children:e},e))}),(0,Z.jsx)(`div`,{className:`grid grid-cols-7 gap-1`,children:y.map((e,t)=>{if(e===null)return(0,Z.jsx)(`div`,{className:`aspect-square`},`empty-${t}`);let n=`${s}-${String(a+1).padStart(2,`0`)}-${String(e).padStart(2,`0`)}`,r=p.get(n)||[],o=r.length>0,c=e===i.getDate()&&a===i.getMonth()&&s===i.getFullYear(),u=n===l,d=r.filter(e=>e.status===`completed`).length,f=r.filter(e=>e.status===`failed`).length;return(0,Z.jsxs)(`button`,{onClick:()=>x(u?null:n),className:`aspect-square rounded-lg p-1 flex flex-col items-center justify-center transition-colors relative ${u?`bg-bambu-green text-white`:c?`bg-bambu-green/20 text-white ring-2 ring-bambu-green`:o?`bg-bambu-dark-tertiary hover:bg-bambu-dark-tertiary/70 text-white`:`hover:bg-bambu-dark-tertiary/50 text-bambu-gray`}`,children:[(0,Z.jsx)(`span`,{className:`text-sm font-medium ${c&&!u?`text-bambu-green`:``}`,children:e}),o&&(0,Z.jsxs)(`div`,{className:`absolute bottom-1 left-1/2 -translate-x-1/2 flex items-center gap-1`,children:[(0,Z.jsx)(`div`,{className:`w-2 h-2 rounded-full ${f>0&&d===0?`bg-red-400`:f>0?`bg-yellow-400`:`bg-green-400`}`}),(0,Z.jsx)(`span`,{className:`text-xs font-medium`,children:r.length})]})]},e)})}),(0,Z.jsx)(`div`,{className:`mt-4 pt-4 border-t border-bambu-dark-tertiary`,children:(0,Z.jsxs)(`div`,{className:`grid grid-cols-3 gap-4 text-center`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`div`,{className:`text-2xl font-bold text-white`,children:e.filter(e=>{let t=be(e.completed_at||e.created_at)||new Date;return t.getMonth()===a&&t.getFullYear()===s}).length}),(0,Z.jsx)(`div`,{className:`text-xs text-bambu-gray`,children:`Prints this month`})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`div`,{className:`text-2xl font-bold text-green-700 dark:text-green-400`,children:e.filter(e=>{let t=be(e.completed_at||e.created_at)||new Date;return t.getMonth()===a&&t.getFullYear()===s&&e.status===`completed`}).length}),(0,Z.jsx)(`div`,{className:`text-xs text-bambu-gray`,children:`Successful`})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`div`,{className:`text-2xl font-bold text-red-700 dark:text-red-400`,children:e.filter(e=>{let t=be(e.completed_at||e.created_at)||new Date;return t.getMonth()===a&&t.getFullYear()===s&&e.status===`failed`}).length}),(0,Z.jsx)(`div`,{className:`text-xs text-bambu-gray`,children:`Failed`})]})]})})]}),(0,Z.jsx)(`div`,{className:`lg:w-80 bg-bambu-dark rounded-xl p-4`,children:l?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`h3`,{className:`text-sm font-medium text-bambu-gray mb-3`,children:new Date(l+`T12:00:00`).toLocaleDateString(`en-US`,{weekday:`long`,month:`long`,day:`numeric`,year:`numeric`})}),b.length>0?(0,Z.jsx)(`div`,{className:`calendar-scroll space-y-2 max-h-96 overflow-y-auto`,children:b.map(e=>{let i=e.id===d||e.id===n;return(0,Z.jsxs)(`button`,{onClick:()=>{f(e.id),t?.(e)},className:`w-full flex items-center gap-3 p-2 rounded-lg transition-colors text-left ${i?``:`hover:bg-bambu-dark-tertiary`}`,style:i?{outline:`4px solid #facc15`,outlineOffset:`2px`}:void 0,children:[e.thumbnail_path?(0,Z.jsx)(`img`,{src:r.getArchiveThumbnail(e.id),alt:``,className:`w-12 h-12 rounded object-cover`}):(0,Z.jsx)(`div`,{className:`w-12 h-12 rounded bg-bambu-dark-tertiary flex items-center justify-center`,children:(0,Z.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:`3MF`})}),(0,Z.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Z.jsx)(`p`,{className:`text-sm text-white truncate`,children:e.print_name||e.filename}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-xs`,children:[(0,Z.jsx)(`span`,{className:e.status===`failed`?`text-red-700 dark:text-red-400`:`text-green-700 dark:text-green-400`,children:e.status===`failed`?`Failed`:`Completed`}),e.filament_color&&(0,Z.jsx)(`div`,{className:`flex gap-0.5`,children:e.filament_color.split(`,`).map((e,t)=>(0,Z.jsx)(`div`,{className:`w-3 h-3 rounded-full border border-black/20`,style:{backgroundColor:e}},t))})]})]})]},e.id)})}):(0,Z.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:`No prints on this day`})]}):(0,Z.jsx)(`div`,{className:`text-center py-8`,children:(0,Z.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:`Select a day to see prints`})})})]})}function Pt({archiveId:e,archiveName:t,onClose:n}){let i=r.getArchiveQRCodeUrl(e,300);return(0,X.useEffect)(()=>{let e=e=>{e.key===`Escape`&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n]),(0,Z.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:n,children:(0,Z.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-sm`,onClick:e=>e.stopPropagation(),children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,Z.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:`QR Code`}),(0,Z.jsx)(`button`,{onClick:n,className:`text-bambu-gray hover:text-white transition-colors`,children:(0,Z.jsx)(L,{className:`w-5 h-5`})})]}),(0,Z.jsxs)(`div`,{className:`p-6 flex flex-col items-center`,children:[(0,Z.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4 text-center truncate max-w-full`,children:t}),(0,Z.jsx)(`div`,{className:`bg-white p-4 rounded-lg mb-4`,children:(0,Z.jsx)(`img`,{src:i,alt:`QR Code`,className:`w-64 h-64`})}),(0,Z.jsx)(`p`,{className:`text-xs text-bambu-gray mb-4 text-center`,children:`Scan to open this archive`}),(0,Z.jsxs)(V,{onClick:()=>{let e=document.createElement(`a`);e.href=i,e.download=`${t}_qrcode.png`,e.click()},className:`w-full`,children:[(0,Z.jsx)(q,{className:`w-4 h-4`}),`Download QR Code`]})]})]})})}function Q({archiveId:e,archiveName:t,onClose:n}){let i=s(),[a,u]=(0,X.useState)(!1),[d,p]=(0,X.useState)(null),[h,g]=(0,X.useState)({}),{data:_,isLoading:v,error:y}=c({queryKey:[`archive-project-page`,e],queryFn:()=>r.getArchiveProjectPage(e)}),b=l({mutationFn:t=>r.updateArchiveProjectPage(e,t),onSuccess:()=>{i.invalidateQueries({queryKey:[`archive-project-page`,e]}),u(!1),g({})}});(0,X.useEffect)(()=>{let e=e=>{e.key===`Escape`&&(d===null?a?w():n():p(null))};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[d,a,n]);let x=[..._?.model_pictures||[],..._?.profile_pictures||[]],S=()=>{g({title:_?.title||``,description:_?.description||``,designer:_?.designer||``,license:_?.license||``,profile_title:_?.profile_title||``,profile_description:_?.profile_description||``}),u(!0)},C=()=>{b.mutate(h)},w=()=>{u(!1),g({})},T=e=>ht.sanitize(e,{ALLOWED_TAGS:[`p`,`br`,`b`,`strong`,`i`,`em`,`u`,`a`,`ul`,`ol`,`li`,`figure`,`img`],ALLOWED_ATTR:[`href`,`src`,`target`,`rel`,`style`],ADD_ATTR:[`target`]}),E=_&&(_.title||_.description||_.designer||_.profile_title||x.length>0);return(0,Z.jsxs)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:e=>{e.target===e.currentTarget&&n()},children:[(0,Z.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl max-w-4xl w-full max-h-[90vh] overflow-hidden flex flex-col`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Z.jsx)(rt,{className:`w-5 h-5 text-bambu-green`}),(0,Z.jsxs)(`h2`,{className:`text-lg font-semibold text-white`,children:[`Project Page`,t&&(0,Z.jsxs)(`span`,{className:`text-bambu-gray ml-2`,children:[`- `,t]})]})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[!a&&E&&(0,Z.jsxs)(V,{variant:`ghost`,size:`sm`,onClick:S,children:[(0,Z.jsx)(ue,{className:`w-4 h-4 mr-1`}),`Edit`]}),a&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(V,{variant:`ghost`,size:`sm`,onClick:w,children:`Cancel`}),(0,Z.jsxs)(V,{variant:`primary`,size:`sm`,onClick:C,disabled:b.isPending,children:[(0,Z.jsx)(He,{className:`w-4 h-4 mr-1`}),`Save`]})]}),(0,Z.jsx)(`button`,{onClick:n,className:`p-2 hover:bg-bambu-dark-tertiary rounded-lg transition-colors`,children:(0,Z.jsx)(L,{className:`w-5 h-5 text-bambu-gray`})})]})]}),(0,Z.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-6`,children:[v&&(0,Z.jsx)(`div`,{className:`flex items-center justify-center py-12`,children:(0,Z.jsx)(`div`,{className:`animate-spin rounded-full h-8 w-8 border-2 border-bambu-green border-t-transparent`})}),y&&(0,Z.jsx)(`div`,{className:`text-red-700 dark:text-red-400 text-center py-12`,children:`Failed to load project page data`}),_&&!E&&(0,Z.jsxs)(`div`,{className:`text-bambu-gray text-center py-12`,children:[(0,Z.jsx)(rt,{className:`w-12 h-12 mx-auto mb-4 opacity-50`}),(0,Z.jsx)(`p`,{children:`No project page data found in this 3MF file.`}),(0,Z.jsx)(`p`,{className:`text-sm mt-2`,children:`Project pages are typically included in files downloaded from MakerWorld.`})]}),_&&E&&(0,Z.jsxs)(`div`,{className:`space-y-6`,children:[(0,Z.jsxs)(`div`,{className:`space-y-4`,children:[a?(0,Z.jsx)(`input`,{type:`text`,value:h.title||``,onChange:e=>g({...h,title:e.target.value}),placeholder:`Title`,className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded-lg px-4 py-2 text-white text-xl font-semibold`}):_.title&&(0,Z.jsx)(`h3`,{className:`text-xl font-semibold text-white`,children:_.title}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap gap-4 text-sm`,children:[a?(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(Fe,{className:`w-4 h-4 text-bambu-gray`}),(0,Z.jsx)(`input`,{type:`text`,value:h.designer||``,onChange:e=>g({...h,designer:e.target.value}),placeholder:`Designer`,className:`bg-bambu-dark border border-bambu-dark-tertiary rounded px-2 py-1 text-white`})]}):_.designer&&(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray`,children:[(0,Z.jsx)(Fe,{className:`w-4 h-4`}),(0,Z.jsx)(`span`,{children:_.designer}),_.designer_user_id&&(0,Z.jsx)(`a`,{href:`https://makerworld.com/en/@${_.designer_user_id}`,target:`_blank`,rel:`noopener noreferrer`,className:`text-bambu-green hover:underline`,children:(0,Z.jsx)(Ce,{className:`w-3 h-3`})})]}),_.creation_date&&(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray`,children:[(0,Z.jsx)(m,{className:`w-4 h-4`}),(0,Z.jsx)(`span`,{children:_.creation_date})]}),a?(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(rt,{className:`w-4 h-4 text-bambu-gray`}),(0,Z.jsx)(`input`,{type:`text`,value:h.license||``,onChange:e=>g({...h,license:e.target.value}),placeholder:`License`,className:`bg-bambu-dark border border-bambu-dark-tertiary rounded px-2 py-1 text-white`})]}):_.license&&(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray`,children:[(0,Z.jsx)(rt,{className:`w-4 h-4`}),(0,Z.jsx)(`span`,{children:_.license})]}),_.origin&&(0,Z.jsx)(`span`,{className:`px-2 py-0.5 bg-bambu-dark rounded text-bambu-gray`,children:_.origin})]})]}),(_.description||a)&&(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsx)(`h4`,{className:`text-sm font-medium text-bambu-gray uppercase tracking-wide`,children:`Description`}),a?(0,Z.jsx)(f,{content:h.description||``,onChange:e=>g({...h,description:e}),placeholder:`Enter description...`}):(0,Z.jsx)(`div`,{className:`prose prose-invert prose-sm max-w-none text-bambu-gray-light`,dangerouslySetInnerHTML:{__html:T(_.description||``)}})]}),(_.profile_title||_.profile_description||a)&&(0,Z.jsxs)(`div`,{className:`space-y-2 p-4 bg-bambu-dark rounded-lg`,children:[(0,Z.jsx)(`h4`,{className:`text-sm font-medium text-bambu-gray uppercase tracking-wide`,children:`Print Profile`}),a?(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsx)(`input`,{type:`text`,value:h.profile_title||``,onChange:e=>g({...h,profile_title:e.target.value}),placeholder:`Profile Title`,className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-white`}),(0,Z.jsx)(f,{content:h.profile_description||``,onChange:e=>g({...h,profile_description:e}),placeholder:`Profile description...`})]}):(0,Z.jsxs)(Z.Fragment,{children:[_.profile_title&&(0,Z.jsx)(`p`,{className:`text-white font-medium`,children:_.profile_title}),_.profile_description&&(0,Z.jsx)(`div`,{className:`prose prose-invert prose-sm max-w-none text-bambu-gray-light`,dangerouslySetInnerHTML:{__html:T(_.profile_description)}}),_.profile_user_name&&(0,Z.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[`by `,_.profile_user_name]})]})]}),x.length>0&&(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsxs)(`h4`,{className:`text-sm font-medium text-bambu-gray uppercase tracking-wide flex items-center gap-2`,children:[(0,Z.jsx)(tt,{className:`w-4 h-4`}),`Images (`,x.length,`)`]}),(0,Z.jsx)(`div`,{className:`grid grid-cols-3 sm:grid-cols-4 md:grid-cols-5 gap-2`,children:x.map((e,t)=>(0,Z.jsx)(`button`,{onClick:()=>p(t),className:`aspect-square rounded-lg overflow-hidden border border-bambu-dark-tertiary hover:border-bambu-green transition-colors`,children:(0,Z.jsx)(`img`,{src:o(e.url),alt:e.name,className:`w-full h-full object-cover`})},e.path))})]}),_.design_model_id&&(0,Z.jsx)(`div`,{className:`pt-4 border-t border-bambu-dark-tertiary`,children:(0,Z.jsxs)(`a`,{href:`https://makerworld.com/en/models/${_.design_model_id}`,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-2 text-bambu-green hover:underline`,children:[(0,Z.jsx)(Ce,{className:`w-4 h-4`}),`View on MakerWorld`]})})]})]})]}),d!==null&&x[d]&&(0,Z.jsxs)(`div`,{className:`fixed inset-0 bg-black/90 flex items-center justify-center z-60`,onClick:()=>p(null),children:[(0,Z.jsx)(`button`,{onClick:e=>{e.stopPropagation(),p(Math.max(0,d-1))},disabled:d===0,className:`absolute left-4 p-2 bg-bambu-dark-secondary rounded-full hover:bg-bambu-dark-tertiary disabled:opacity-30`,children:(0,Z.jsx)(Ze,{className:`w-6 h-6 text-white`})}),(0,Z.jsx)(`img`,{src:o(x[d].url),alt:x[d].name,className:`max-w-[90vw] max-h-[90vh] object-contain`,onClick:e=>e.stopPropagation()}),(0,Z.jsx)(`button`,{onClick:e=>{e.stopPropagation(),p(Math.min(x.length-1,d+1))},disabled:d===x.length-1,className:`absolute right-4 p-2 bg-bambu-dark-secondary rounded-full hover:bg-bambu-dark-tertiary disabled:opacity-30`,children:(0,Z.jsx)(Me,{className:`w-6 h-6 text-white`})}),(0,Z.jsx)(`button`,{onClick:()=>p(null),className:`absolute top-4 right-4 p-2 bg-bambu-dark-secondary rounded-full hover:bg-bambu-dark-tertiary`,children:(0,Z.jsx)(L,{className:`w-6 h-6 text-white`})}),(0,Z.jsxs)(`div`,{className:`absolute bottom-4 text-white text-sm`,children:[d+1,` / `,x.length]})]})]})}var Ft=[.25,.5,.75,1,1.5,2,3,4];function It({archiveId:e,timelapseSrc:t,onClose:n,onSave:i}){let{showToast:a}=S(),o=(0,X.useRef)(null),s=(0,X.useRef)(null),[u,d]=(0,X.useState)(!1),[f,p]=(0,X.useState)(0),[m,h]=(0,X.useState)(0),[g,_]=(0,X.useState)(0),[v,y]=(0,X.useState)(0),[b,x]=(0,X.useState)(1),[C,w]=(0,X.useState)(null),[T,E]=(0,X.useState)(null),[D,O]=(0,X.useState)(.8),[k,ee]=(0,X.useState)(!1),{data:A,isLoading:te}=c({queryKey:[`timelapse-info`,e],queryFn:()=>r.getTimelapseInfo(e)}),{data:ne}=c({queryKey:[`timelapse-thumbnails`,e],queryFn:()=>r.getTimelapseThumbnails(e,15)}),M=l({mutationFn:()=>r.processTimelapse(e,{trimStart:g,trimEnd:v,speed:b,saveMode:`replace`},C||void 0),onSuccess:e=>{a(e.message,`success`),i?.(),n()},onError:e=>{a(e.message||`Processing failed`,`error`)}});(0,X.useEffect)(()=>{A?.duration&&v===0&&y(A.duration)},[A?.duration,v]),(0,X.useEffect)(()=>{let e=e=>{e.key===`Escape`&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n]),(0,X.useEffect)(()=>{let e=o.current;if(!e)return;let t=()=>{let t=e.currentTime;p(t),t>=v&&(e.currentTime=g)},n=()=>{h(e.duration),v===0&&y(e.duration)},r=()=>d(!0),i=()=>d(!1);return e.addEventListener(`timeupdate`,t),e.addEventListener(`durationchange`,n),e.addEventListener(`play`,r),e.addEventListener(`pause`,i),()=>{e.removeEventListener(`timeupdate`,t),e.removeEventListener(`durationchange`,n),e.removeEventListener(`play`,r),e.removeEventListener(`pause`,i)}},[g,v]),(0,X.useEffect)(()=>{let e=s.current,t=o.current;!e||!t||!T||(e.currentTime=t.currentTime,e.playbackRate=t.playbackRate,u&&!k?e.play().catch(()=>{}):e.pause())},[u,T,k]),(0,X.useEffect)(()=>{s.current&&(s.current.volume=k?0:D)},[D,k]),(0,X.useEffect)(()=>{o.current&&(o.current.playbackRate=b),s.current&&(s.current.playbackRate=b)},[b]);let re=(0,X.useCallback)(()=>{let e=o.current;e&&(u?e.pause():(e.currentTime{let t=o.current;t&&(t.currentTime=Math.max(g,Math.min(v,e)))},ae=e=>{let t=e.target.files?.[0];t&&(T&&URL.revokeObjectURL(T),w(t),E(URL.createObjectURL(t)))},oe=()=>{T&&URL.revokeObjectURL(T),w(null),E(null)};(0,X.useEffect)(()=>()=>{T&&URL.revokeObjectURL(T)},[T]);let se=v-g,ce=se/b;return te?(0,Z.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/80`,children:(0,Z.jsxs)(`div`,{className:`flex items-center gap-3 text-white`,children:[(0,Z.jsx)(P,{className:`w-6 h-6 animate-spin`}),`Loading video info...`]})}):(0,Z.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/80`,children:(0,Z.jsxs)(`div`,{className:`relative bg-bambu-dark-secondary rounded-xl max-w-5xl w-full mx-4 max-h-[90vh] overflow-hidden flex flex-col`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary shrink-0`,children:[(0,Z.jsxs)(`h3`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,Z.jsx)(j,{className:`w-5 h-5 text-bambu-green`}),`Edit Timelapse`]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(V,{variant:`primary`,size:`sm`,onClick:()=>M.mutate(),disabled:M.isPending,children:M.isPending?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(P,{className:`w-4 h-4 animate-spin`}),`Processing...`]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(He,{className:`w-4 h-4`}),`Save`]})}),(0,Z.jsx)(`button`,{onClick:n,className:`p-1 hover:bg-bambu-dark-tertiary rounded transition-colors`,children:(0,Z.jsx)(L,{className:`w-5 h-5 text-bambu-gray`})})]})]}),(0,Z.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-4 space-y-4`,children:[(0,Z.jsxs)(`div`,{className:`relative`,children:[(0,Z.jsx)(`video`,{ref:o,src:t,className:`w-full rounded-lg bg-black`,onClick:re,muted:!!T}),!u&&(0,Z.jsx)(`button`,{onClick:re,className:`absolute inset-0 flex items-center justify-center bg-black/30 hover:bg-black/40 transition-colors`,children:(0,Z.jsx)(`div`,{className:`p-4 bg-bambu-green rounded-full`,children:(0,Z.jsx)(de,{className:`w-8 h-8 text-white`})})}),T&&(0,Z.jsx)(`audio`,{ref:s,src:T,loop:!0})]}),(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-bambu-gray`,children:[(0,Z.jsx)(bt,{className:`w-4 h-4`}),(0,Z.jsx)(`span`,{children:`Trim`}),(0,Z.jsxs)(`span`,{className:`ml-auto`,children:[H(g),` - `,H(v),` (`,H(se),`)`]})]}),(0,Z.jsxs)(`div`,{className:`relative h-16 bg-bambu-dark rounded-lg overflow-hidden`,children:[(0,Z.jsx)(`div`,{className:`absolute inset-0 flex`,children:ne?.thumbnails.map((e,t)=>(0,Z.jsx)(`div`,{className:`flex-1 bg-cover bg-center`,style:{backgroundImage:`url(data:image/jpeg;base64,${e})`}},t))}),(0,Z.jsx)(`div`,{className:`absolute inset-y-0 left-0 bg-black/60`,style:{width:`${g/m*100}%`}}),(0,Z.jsx)(`div`,{className:`absolute inset-y-0 right-0 bg-black/60`,style:{width:`${(m-v)/m*100}%`}}),(0,Z.jsx)(`div`,{className:`absolute inset-y-0 border-2 border-bambu-green`,style:{left:`${g/m*100}%`,right:`${(m-v)/m*100}%`}}),(0,Z.jsx)(`div`,{className:`absolute top-0 bottom-0 w-0.5 bg-white shadow-lg`,style:{left:`${f/m*100}%`}}),(0,Z.jsx)(`input`,{type:`range`,min:0,max:m,step:.1,value:g,onChange:e=>{let t=parseFloat(e.target.value);t{let t=parseFloat(e.target.value);t>g+1&&y(t)},className:`absolute inset-0 w-full opacity-0 cursor-ew-resize`,style:{clipPath:`inset(0 0 0 50%)`}})]}),(0,Z.jsx)(`input`,{type:`range`,min:0,max:m,step:.1,value:f,onChange:e=>ie(parseFloat(e.target.value)),className:`w-full h-1 bg-bambu-dark-tertiary rounded-lg appearance-none cursor-pointer +import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,p as i,w as a,x as o}from"./client-DnySrlFv.js";import{n as s}from"./QueryClientProvider-Ce8_sN3w.js";import{t as c}from"./useQuery-BBCjCezC.js";import{t as l}from"./useMutation-B-Tr2hIP.js";import{t as u}from"./createLucideIcon-DvBYJlWL.js";import{t as d}from"./arrow-up-down-BdyOV_2F.js";import{t as f}from"./RichTextEditor-CsfJOD7X.js";import{t as p}from"./box-DAdKb9s5.js";import{t as m}from"./calendar-BLKPnWqV.js";import{t as h}from"./check-Ck0cMLU4.js";import{a as g,i as _,n as v,r as y}from"./info-ROUoQhJR.js";import{n as b,t as x}from"./chevrons-right-DTJgqnxZ.js";import{n as S,r as C}from"./ToastContext-BRX0SW3C.js";import{t as w}from"./coins-4u6IPkR-.js";import{t as T}from"./cog-Dol1I0kq.js";import{t as E}from"./columns-2-DVEObeDC.js";import{t as D}from"./copy-Cu_0GKCU.js";import{t as O}from"./ellipsis-vertical-t2D7cYyp.js";import{t as k}from"./file-box-04V4jZ9_.js";import{t as ee}from"./file-spreadsheet-WxOA9vYy.js";import{n as A,t as te}from"./ContextMenu-CwroFwVJ.js";import{n as j,t as ne}from"./scan-search-BDoNAXzz.js";import{t as M}from"./funnel-C3dyAMK9.js";import{t as N}from"./gauge-D21zgWMb.js";import{t as re}from"./git-compare-J4KX0xAJ.js";import{n as ie,t as ae}from"./SliceModal-YlJTMEj6.js";import{t as oe}from"./history-B4lOLL01.js";import{t as se}from"./layout-grid-DkD3u6wa.js";import{t as ce}from"./list-CLcpeoSz.js";import{t as P}from"./loader-circle-BEmFtawu.js";import{t as le}from"./package-BGUevlqS.js";import{t as F}from"./pause-DFb6GX_6.js";import{t as ue}from"./pen-line-BWR04BX-.js";import{t as de}from"./play-DIDYtk2S.js";import{t as fe}from"./qr-code-CCCo2-Br.js";import{t as pe}from"./search-0n0CBc74.js";import{t as me}from"./skip-forward-BsuMfFkw.js";import{t as he}from"./sticky-note-BH0LPqRx.js";import{t as I}from"./triangle-alert-Dt_1FcBy.js";import{t as L}from"./x-DR-Trv6U.js";import{i as R,n as z,t as B}from"./Card-Bzc64K35.js";import{t as ge}from"./file-DDkFXH-b.js";import{t as V}from"./Button-DDr6eAFy.js";import{a as _e,i as ve,l as H,o as ye,v as be}from"./date-G9KUauqz.js";import{$t as xe,An as Se,At as U,Cn as Ce,Et as we,F as Te,It as Ee,Jt as De,L as Oe,Ln as ke,Lt as Ae,M as je,Mn as Me,Mt as Ne,On as Pe,Ot as Fe,P as Ie,Pn as Le,Pt as Re,R as ze,Rn as W,Rt as Be,T as Ve,Ut as He,Vn as Ue,Vt as We,Zt as G,_t as K,at as Ge,b as Ke,bt as qe,cn as Je,hn as Ye,j as Xe,jn as Ze,jt as Qe,kt as $e,tn as et,un as tt,vn as nt,wn as q,xn as rt,xt as it,y as at,yn as ot,yt as st}from"./index-Cxa-KVmA.js";import{n as ct,r as lt,t as ut}from"./PhotoGalleryModal-BPFizk3N.js";import{a as dt,o as ft}from"./slicer-DgCA7cW6.js";import{t as pt}from"./filamentTypes-Dysa4k6j.js";import{t as mt}from"./ColumnConfigModal-BBpKz9m6.js";import{t as ht}from"./purify.es-F_7NWVtX.js";var gt=u(`calendar-days`,[[`path`,{d:`M8 2v4`,key:`1cmpym`}],[`path`,{d:`M16 2v4`,key:`4m81vk`}],[`rect`,{width:`18`,height:`18`,x:`3`,y:`4`,rx:`2`,key:`1hopcy`}],[`path`,{d:`M3 10h18`,key:`8toen8`}],[`path`,{d:`M8 14h.01`,key:`6423bh`}],[`path`,{d:`M12 14h.01`,key:`1etili`}],[`path`,{d:`M16 14h.01`,key:`1gbofw`}],[`path`,{d:`M8 18h.01`,key:`lrp35t`}],[`path`,{d:`M12 18h.01`,key:`mhygvu`}],[`path`,{d:`M16 18h.01`,key:`kzsmim`}]]),_t=u(`clipboard-list`,[[`rect`,{width:`8`,height:`4`,x:`8`,y:`2`,rx:`1`,ry:`1`,key:`tgr4d6`}],[`path`,{d:`M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2`,key:`116196`}],[`path`,{d:`M12 11h4`,key:`1jrz19`}],[`path`,{d:`M12 16h4`,key:`n85exb`}],[`path`,{d:`M8 11h.01`,key:`1dfujw`}],[`path`,{d:`M8 16h.01`,key:`18s6g9`}]]),vt=u(`file-code`,[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M10 12.5 8 15l2 2.5`,key:`1tg20x`}],[`path`,{d:`m14 12.5 2 2.5-2 2.5`,key:`yinavb`}]]),J=u(`file-play`,[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M15.033 13.44a.647.647 0 0 1 0 1.12l-4.065 2.352a.645.645 0 0 1-.968-.56v-4.704a.645.645 0 0 1 .967-.56z`,key:`1tzo1f`}]]),yt=u(`git-branch`,[[`line`,{x1:`6`,x2:`6`,y1:`3`,y2:`15`,key:`17qcm7`}],[`circle`,{cx:`18`,cy:`6`,r:`3`,key:`1h7g24`}],[`circle`,{cx:`6`,cy:`18`,r:`3`,key:`fqmcym`}],[`path`,{d:`M18 9a9 9 0 0 1-9 9`,key:`n2h4wq`}]]),bt=u(`scissors`,[[`circle`,{cx:`6`,cy:`6`,r:`3`,key:`1lh9wr`}],[`path`,{d:`M8.12 8.12 12 12`,key:`1alkpv`}],[`path`,{d:`M20 4 8.12 15.88`,key:`xgtan2`}],[`circle`,{cx:`6`,cy:`18`,r:`3`,key:`fqmcym`}],[`path`,{d:`M14.8 14.8 20 20`,key:`ptml3r`}]]),xt=u(`skip-back`,[[`path`,{d:`M17.971 4.285A2 2 0 0 1 21 6v12a2 2 0 0 1-3.029 1.715l-9.997-5.998a2 2 0 0 1-.003-3.432z`,key:`15892j`}],[`path`,{d:`M3 20V4`,key:`1ptbpl`}]]),Y=u(`volume-2`,[[`path`,{d:`M11 4.702a.705.705 0 0 0-1.203-.498L6.413 7.587A1.4 1.4 0 0 1 5.416 8H3a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h2.416a1.4 1.4 0 0 1 .997.413l3.383 3.384A.705.705 0 0 0 11 19.298z`,key:`uqj9uw`}],[`path`,{d:`M16 9a5 5 0 0 1 0 6`,key:`1q6k2b`}],[`path`,{d:`M19.364 18.364a9 9 0 0 0 0-12.728`,key:`ijwkga`}]]),St=u(`volume-x`,[[`path`,{d:`M11 4.702a.705.705 0 0 0-1.203-.498L6.413 7.587A1.4 1.4 0 0 1 5.416 8H3a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h2.416a1.4 1.4 0 0 1 .997.413l3.383 3.384A.705.705 0 0 0 11 19.298z`,key:`uqj9uw`}],[`line`,{x1:`22`,x2:`16`,y1:`9`,y2:`15`,key:`1ewh16`}],[`line`,{x1:`16`,x2:`22`,y1:`9`,y2:`15`,key:`5ykzw1`}]]),X=e(n(),1),Z=t();function Ct({onClose:e,initialFiles:t}){let{t:n}=a(),i=s(),{showToast:o}=S(),c=(0,X.useRef)(null),[u,d]=(0,X.useState)(()=>t?.filter(e=>e.name.endsWith(`.3mf`)).map(e=>({file:e,status:`pending`}))||[]),[f,p]=(0,X.useState)(!1),[m,h]=(0,X.useState)(null);(0,X.useEffect)(()=>{let t=t=>{t.key===`Escape`&&e()};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e]);let g=l({mutationFn:e=>r.uploadArchivesBulk(e),onSuccess:e=>{h(e),i.invalidateQueries({queryKey:[`archives`]}),i.invalidateQueries({queryKey:[`archiveStats`]}),d(t=>t.map(t=>{let n=e.results.find(e=>e.filename===t.file.name),r=e.errors.find(e=>e.filename===t.file.name);return n?{...t,status:`success`,archiveId:n.id}:r?{...t,status:`error`,error:r.error}:t})),e.failed===0?o(`${e.uploaded} file${e.uploaded===1?``:`s`} uploaded`):e.uploaded===0?o(`Failed to upload ${e.failed} file${e.failed===1?``:`s`}`,`error`):o(`${e.uploaded} uploaded, ${e.failed} failed`,`warning`)},onError:()=>{d(e=>e.map(e=>({...e,status:`error`,error:`Upload failed`}))),o(`Upload failed`,`error`)}}),_=(0,X.useCallback)(e=>{e.preventDefault(),p(!0)},[]),v=(0,X.useCallback)(e=>{e.preventDefault(),p(!1)},[]),b=(0,X.useCallback)(e=>{e.preventDefault(),p(!1);let t=Array.from(e.dataTransfer.files).filter(e=>e.name.endsWith(`.3mf`));t.length>0&&d(e=>[...e,...t.map(e=>({file:e,status:`pending`}))])},[]),x=(0,X.useCallback)(e=>{let t=Array.from(e.target.files||[]).filter(e=>e.name.endsWith(`.3mf`));t.length>0&&d(e=>[...e,...t.map(e=>({file:e,status:`pending`}))]),c.current&&(c.current.value=``)},[]),w=(0,X.useCallback)(e=>{d(t=>t.filter((t,n)=>n!==e))},[]),T=()=>{if(u.length===0)return;let e=u.filter(e=>e.status===`pending`);e.length!==0&&(d(e=>e.map(e=>e.status===`pending`?{...e,status:`uploading`}:e)),g.mutate(e.map(e=>e.file)))},E=u.filter(e=>e.status===`pending`).length,D=g.isPending;return(0,Z.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,children:(0,Z.jsx)(B,{className:`w-full max-w-2xl max-h-[90vh] flex flex-col`,children:(0,Z.jsxs)(z,{className:`p-0 flex flex-col h-full`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,Z.jsx)(`h2`,{className:`text-xl font-semibold text-white`,children:n(`uploadModal.title`)}),(0,Z.jsx)(`button`,{onClick:e,className:`text-bambu-gray hover:text-white transition-colors`,children:(0,Z.jsx)(L,{className:`w-5 h-5`})})]}),(0,Z.jsx)(`div`,{className:`p-4`,children:(0,Z.jsxs)(`div`,{className:`border-2 border-dashed rounded-lg p-8 text-center transition-colors ${f?`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary hover:border-bambu-gray`}`,onDragOver:_,onDragLeave:v,onDrop:b,children:[(0,Z.jsx)($e,{className:`w-12 h-12 mx-auto mb-4 text-bambu-gray`}),(0,Z.jsx)(`p`,{className:`text-white mb-2`,children:n(`uploadModal.dragDrop`)}),(0,Z.jsx)(`p`,{className:`text-bambu-gray text-sm mb-4`,children:n(`uploadModal.or`)}),(0,Z.jsx)(V,{variant:`secondary`,onClick:()=>c.current?.click(),disabled:D,children:n(`uploadModal.browseFiles`)}),(0,Z.jsx)(`input`,{ref:c,type:`file`,accept:`.3mf`,multiple:!0,className:`hidden`,onChange:x})]})}),(0,Z.jsx)(`div`,{className:`px-4 pb-4`,children:(0,Z.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`uploadModal.extractionInfo`)})}),u.length>0&&(0,Z.jsx)(`div`,{className:`px-4 pb-4 max-h-60 overflow-y-auto`,children:(0,Z.jsx)(`div`,{className:`space-y-2`,children:u.map((e,t)=>(0,Z.jsxs)(`div`,{className:`flex items-center gap-3 p-3 bg-bambu-dark rounded-lg`,children:[(0,Z.jsx)(A,{className:`w-5 h-5 text-bambu-gray flex-shrink-0`}),(0,Z.jsx)(`span`,{className:`flex-1 text-white text-sm truncate`,children:e.file.name}),(0,Z.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[(e.file.size/(1024*1024)).toFixed(1),` MB`]}),e.status===`pending`&&(0,Z.jsx)(`button`,{onClick:()=>w(t),className:`text-bambu-gray hover:text-red-600 dark:hover:text-red-400 transition-colors`,disabled:D,children:(0,Z.jsx)(L,{className:`w-4 h-4`})}),e.status===`uploading`&&(0,Z.jsx)(P,{className:`w-4 h-4 text-bambu-green animate-spin`}),e.status===`success`&&(0,Z.jsx)(C,{className:`w-4 h-4 text-bambu-green`}),e.status===`error`&&(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`span`,{className:`text-xs text-red-700 dark:text-red-400`,children:e.error}),(0,Z.jsx)(y,{className:`w-4 h-4 text-red-600 dark:text-red-400`})]})]},`${e.file.name}-${t}`))})}),m&&(0,Z.jsx)(`div`,{className:`px-4 pb-4`,children:(0,Z.jsx)(`div`,{className:`p-3 bg-bambu-dark rounded-lg`,children:(0,Z.jsxs)(`p`,{className:`text-sm text-white`,children:[(0,Z.jsx)(`span`,{className:`text-bambu-green`,children:m.uploaded}),` `,n(`uploadModal.uploaded`),m.failed>0&&(0,Z.jsxs)(Z.Fragment,{children:[`, `,(0,Z.jsx)(`span`,{className:`text-red-700 dark:text-red-400`,children:m.failed}),` `,n(`uploadModal.failed`)]})]})})}),(0,Z.jsxs)(`div`,{className:`flex gap-3 p-4 border-t border-bambu-dark-tertiary`,children:[(0,Z.jsx)(V,{variant:`secondary`,onClick:e,className:`flex-1`,children:n(m?`common.close`:`common.cancel`)}),!m&&(0,Z.jsx)(V,{onClick:T,disabled:E===0||D,className:`flex-1`,children:D?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(P,{className:`w-4 h-4 animate-spin`}),n(`uploadModal.uploading`)]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)($e,{className:`w-4 h-4`}),n(`uploadModal.upload`),` `,E>0&&`(${E})`]})})]})]})})})}var wt=365;function Tt({onClose:e,initialDays:t}){let{t:n}=a(),i=s(),{showToast:o}=S(),[u,d]=(0,X.useState)(t??wt),[f,p]=(0,X.useState)(!1),[m,h]=(0,X.useState)(u);(0,X.useEffect)(()=>{let e=window.setTimeout(()=>h(u),300);return()=>window.clearTimeout(e)},[u]);let g=c({queryKey:[`archive-purge-preview`,m,f],queryFn:()=>r.previewArchivePurge(m,f),enabled:m>=1}),_=l({mutationFn:()=>r.executeArchivePurge(u,f),onSuccess:t=>{o(n(`archivePurge.toast.success`,{count:t.deleted}),`success`),i.invalidateQueries({queryKey:[`archives`]}),i.invalidateQueries({queryKey:[`archive-stats`]}),e()},onError:e=>o(e.message||n(`archivePurge.toast.failed`),`error`)});(0,X.useEffect)(()=>{let t=t=>{t.key===`Escape`&&!_.isPending&&e()};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e,_.isPending]);let v=g.data,y=v?.count??0,b=v?.total_bytes??0,x=y>0&&!_.isPending;return(0,Z.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4`,children:(0,Z.jsxs)(`div`,{className:`bg-white dark:bg-gray-900 rounded-lg shadow-xl max-w-lg w-full`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-gray-200 dark:border-gray-700`,children:[(0,Z.jsxs)(`h2`,{className:`text-lg font-semibold text-gray-900 dark:text-gray-100 flex items-center gap-2`,children:[(0,Z.jsx)(U,{className:`w-5 h-5`}),n(`archivePurge.title`)]}),(0,Z.jsx)(`button`,{onClick:e,className:`text-gray-400 hover:text-gray-600 dark:hover:text-gray-200`,"aria-label":n(`common.close`),disabled:_.isPending,children:(0,Z.jsx)(L,{className:`w-5 h-5`})})]}),(0,Z.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,Z.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400`,children:n(`archivePurge.description`)}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{htmlFor:`archive-purge-days`,className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:n(`archivePurge.ageLabel`)}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Z.jsx)(`input`,{id:`archive-purge-days`,type:`number`,min:1,max:3650,value:u,onChange:e=>d(Math.max(1,Math.min(3650,parseInt(e.target.value||`0`,10)||0))),className:`w-24 rounded border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-800 text-sm px-2 py-1 text-gray-900 dark:text-gray-100`}),(0,Z.jsx)(`span`,{className:`text-sm text-gray-600 dark:text-gray-400`,children:n(`archivePurge.days`)})]})]}),(0,Z.jsxs)(`div`,{className:`rounded border border-gray-200 dark:border-gray-700 bg-gray-50 dark:bg-gray-800/30 p-3`,children:[(0,Z.jsx)(`div`,{className:`text-xs font-semibold uppercase tracking-wide text-gray-600 dark:text-gray-300 mb-2`,children:n(`archivePurge.effectsTitle`)}),(0,Z.jsxs)(`ul`,{className:`text-xs text-gray-700 dark:text-gray-300 space-y-1 list-disc pl-4`,children:[(0,Z.jsx)(`li`,{children:n(`archivePurge.effect1`)}),(0,Z.jsx)(`li`,{children:n(`archivePurge.effect2`)}),(0,Z.jsx)(`li`,{children:n(`archivePurge.effect3`)}),(0,Z.jsx)(`li`,{children:n(`archivePurge.effect4`)})]})]}),(0,Z.jsx)(`div`,{className:`rounded border border-gray-200 dark:border-gray-700 bg-gray-50 dark:bg-gray-800/50 p-3`,children:g.isLoading||g.isFetching?(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-gray-500 dark:text-gray-400`,children:[(0,Z.jsx)(P,{className:`w-4 h-4 animate-spin`}),` `,n(`archivePurge.previewLoading`)]}):g.isError?(0,Z.jsx)(`div`,{className:`text-sm text-red-600 dark:text-red-400`,children:g.error?.message??n(`archivePurge.previewFailed`)}):(0,Z.jsxs)(`div`,{className:`text-sm text-gray-900 dark:text-gray-100`,children:[(0,Z.jsx)(`div`,{className:`font-medium`,children:n(`archivePurge.previewSummary`,{count:y,size:ge(b)})}),v?.sample_filenames&&v.sample_filenames.length>0&&(0,Z.jsxs)(`ul`,{className:`mt-2 text-xs text-gray-600 dark:text-gray-400 space-y-0.5 list-disc pl-4`,children:[v.sample_filenames.map(e=>(0,Z.jsx)(`li`,{className:`truncate`,children:e},e)),y>v.sample_filenames.length&&(0,Z.jsx)(`li`,{className:`list-none italic text-gray-500`,children:n(`archivePurge.andMore`,{count:y-v.sample_filenames.length})})]})]})}),(0,Z.jsxs)(`label`,{className:`flex gap-2 items-start rounded border border-gray-200 dark:border-gray-700 px-3 py-2 cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-800/50`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,checked:f,onChange:e=>p(e.target.checked),disabled:_.isPending,className:`mt-0.5 shrink-0`}),(0,Z.jsxs)(`span`,{className:`text-xs text-gray-700 dark:text-gray-300`,children:[(0,Z.jsx)(`span`,{className:`font-medium block mb-0.5`,children:n(`archivePurge.purgeStatsLabel`)}),(0,Z.jsx)(`span`,{className:`text-gray-500 dark:text-gray-400`,children:n(`archivePurge.purgeStatsHint`)})]})]}),(0,Z.jsxs)(`div`,{className:`flex gap-2 items-start text-xs text-amber-700 dark:text-amber-400 bg-amber-50 dark:bg-amber-900/20 rounded px-3 py-2`,children:[(0,Z.jsx)(I,{className:`w-4 h-4 mt-0.5 shrink-0`}),(0,Z.jsx)(`span`,{children:n(`archivePurge.warning`)})]})]}),(0,Z.jsxs)(`div`,{className:`flex justify-end gap-2 p-4 border-t border-gray-200 dark:border-gray-700`,children:[(0,Z.jsx)(V,{variant:`secondary`,onClick:e,disabled:_.isPending,children:n(`common.cancel`)}),(0,Z.jsx)(V,{variant:`danger`,disabled:!x,onClick:()=>_.mutate(),children:_.isPending?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(P,{className:`w-4 h-4 animate-spin mr-1`}),n(`archivePurge.purging`)]}):n(`archivePurge.confirmCta`,{count:y})})]})]})})}function Et({archiveId:e,archiveName:t,onClose:n}){let{t:r}=a();return(0,X.useEffect)(()=>{let e=e=>{e.key===`Escape`&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n]),(0,Z.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:n,children:(0,Z.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-2xl max-h-[85vh] flex flex-col`,onClick:e=>e.stopPropagation(),children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,Z.jsx)(oe,{className:`w-5 h-5 text-bambu-green flex-shrink-0`}),(0,Z.jsx)(`h2`,{className:`text-lg font-semibold text-white truncate`,title:t||``,children:r(`archives.runLog.modalTitle`,{name:t||r(`archives.runLog.modalTitleFallback`)})})]}),(0,Z.jsx)(`button`,{onClick:n,className:`text-bambu-gray hover:text-white transition-colors`,title:r(`common.close`),children:(0,Z.jsx)(L,{className:`w-5 h-5`})})]}),(0,Z.jsx)(`div`,{className:`p-6 overflow-y-auto flex-1`,children:(0,Z.jsx)(ze,{archiveId:e})})]})})}function Dt({selectedIds:e,existingTags:t,onClose:n}){let i=s(),{showToast:a}=S(),[o,c]=(0,X.useState)(``),[u,d]=(0,X.useState)(new Set),[f,p]=(0,X.useState)(`add`);(0,X.useEffect)(()=>{let e=e=>{e.key===`Escape`&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n]);let m=l({mutationFn:async()=>{let t=Array.from(u),n=0;for(let i of e)try{let e=await r.getArchive(i),a=e.tags?e.tags.split(`,`).map(e=>e.trim()).filter(Boolean):[],o;o=f===`add`?[...new Set([...a,...t])]:a.filter(e=>!u.has(e)),await r.updateArchive(i,{tags:o.join(`, `)}),n++}catch(e){throw console.error(`Failed to update archive ${i}:`,e),Error(`Failed on archive ${i}: ${e instanceof Error?e.message:`Unknown error`}`)}return{count:n,mode:f,tags:t}},onSuccess:({count:e,mode:t,tags:r})=>{i.invalidateQueries({queryKey:[`archives`]}),a(`${t===`add`?`Added`:`Removed`} ${r.length} tag${r.length===1?``:`s`} ${t===`add`?`to`:`from`} ${e} archive${e===1?``:`s`}`),n()},onError:e=>{a(e.message||`Failed to update tags`,`error`)}}),h=e=>{d(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},g=()=>{o.trim()&&!u.has(o.trim())&&(d(e=>new Set([...e,o.trim()])),c(``))};return(0,Z.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,children:(0,Z.jsx)(B,{className:`w-full max-w-md`,children:(0,Z.jsxs)(z,{className:`p-0`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(Re,{className:`w-5 h-5 text-bambu-green`}),(0,Z.jsx)(`h2`,{className:`text-xl font-semibold text-white`,children:f===`add`?`Add Tags`:`Remove Tags`})]}),(0,Z.jsx)(`button`,{onClick:n,className:`text-bambu-gray hover:text-white transition-colors`,children:(0,Z.jsx)(L,{className:`w-5 h-5`})})]}),(0,Z.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,Z.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[f===`add`?`Add`:`Remove`,` tags for `,e.length,` selected archive`,e.length===1?``:`s`]}),(0,Z.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Z.jsx)(V,{size:`sm`,variant:f===`add`?`primary`:`secondary`,onClick:()=>p(`add`),children:`Add Tags`}),(0,Z.jsx)(V,{size:`sm`,variant:f===`remove`?`primary`:`secondary`,onClick:()=>p(`remove`),children:`Remove Tags`})]}),f===`add`&&(0,Z.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Z.jsx)(`input`,{type:`text`,placeholder:`Enter new tag...`,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`,value:o,onChange:e=>c(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),g())}}),(0,Z.jsx)(V,{size:`sm`,variant:`secondary`,onClick:g,disabled:!o.trim(),children:(0,Z.jsx)(G,{className:`w-4 h-4`})})]}),t.length>0&&(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:`Existing tags:`}),(0,Z.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:t.map(e=>(0,Z.jsx)(`button`,{onClick:()=>h(e),className:`px-2 py-1 rounded text-sm transition-colors ${u.has(e)?`bg-bambu-green text-white`:`bg-bambu-dark-tertiary text-bambu-gray-light hover:bg-bambu-dark`}`,children:e},e))})]}),u.size>0&&(0,Z.jsxs)(`div`,{children:[(0,Z.jsxs)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:[`Tags to `,f===`add`?`add`:`remove`,`:`]}),(0,Z.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:Array.from(u).map(e=>(0,Z.jsxs)(`span`,{className:`px-2 py-1 rounded text-sm flex items-center gap-1 ${f===`add`?`bg-green-100 dark:bg-green-500/20 text-green-700 dark:text-green-400`:`bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400`}`,children:[e,(0,Z.jsx)(`button`,{onClick:()=>h(e),className:`hover:opacity-70`,children:(0,Z.jsx)(L,{className:`w-3 h-3`})})]},e))})]})]}),(0,Z.jsxs)(`div`,{className:`flex gap-3 p-4 border-t border-bambu-dark-tertiary`,children:[(0,Z.jsx)(V,{variant:`secondary`,onClick:n,className:`flex-1`,children:`Cancel`}),(0,Z.jsx)(V,{onClick:()=>m.mutate(),disabled:u.size===0||m.isPending,className:`flex-1`,children:m.isPending?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(P,{className:`w-4 h-4 animate-spin`}),`Processing...`]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(Re,{className:`w-4 h-4`}),f===`add`?`Add Tags`:`Remove Tags`]})})]})]})})})}function Ot({selectedIds:e,onClose:t}){let{t:n}=a(),i=s(),{showToast:o}=S(),[u,d]=(0,X.useState)(``),{data:f,isLoading:p}=c({queryKey:[`projects`],queryFn:()=>r.getProjects()}),m=(0,X.useMemo)(()=>f?Te([...f].sort((e,t)=>e.name.localeCompare(t.name))):void 0,[f]),h=u.trim().toLowerCase(),g=h?m?.filter(e=>e.name.toLowerCase().includes(h)):m,_=(m?.length??0)>5;(0,X.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]);let y=()=>Oe(i),b=l({mutationFn:async t=>(await r.addArchivesToProject(t,e),t),onSuccess:n=>{let r=f?.find(e=>e.id===n);y(),o(`Added ${e.length} archive${e.length===1?``:`s`} to "${r?.name}"`),t()},onError:()=>{o(`Failed to assign project`,`error`)}}),x=l({mutationFn:async()=>{for(let t of e)await r.updateArchive(t,{project_id:null});return e.length},onSuccess:e=>{y(),o(`Removed ${e} archive${e===1?``:`s`} from project`),t()},onError:()=>{o(`Failed to remove from project`,`error`)}}),C=b.isPending||x.isPending;return(0,Z.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,children:(0,Z.jsx)(B,{className:`w-full max-w-md max-h-[80vh] flex flex-col`,children:(0,Z.jsxs)(z,{className:`p-0 flex flex-col min-h-0`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary shrink-0`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(ot,{className:`w-5 h-5 text-bambu-green`}),(0,Z.jsx)(`h2`,{className:`text-xl font-semibold text-white`,children:`Assign to Project`})]}),(0,Z.jsx)(`button`,{onClick:t,className:`text-bambu-gray hover:text-white transition-colors`,disabled:C,children:(0,Z.jsx)(L,{className:`w-5 h-5`})})]}),(0,Z.jsxs)(`div`,{className:`p-4 space-y-3 overflow-y-auto min-h-0`,children:[(0,Z.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[`Assign `,e.length,` selected archive`,e.length===1?``:`s`,` to a project`]}),p?(0,Z.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,Z.jsx)(P,{className:`w-6 h-6 animate-spin text-bambu-gray`})}):(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsxs)(`button`,{onClick:()=>x.mutate(),disabled:C,className:`w-full flex items-center gap-3 p-3 rounded-lg bg-bambu-dark hover:bg-bambu-dark-tertiary border border-bambu-dark-tertiary transition-colors text-left disabled:opacity-50`,children:[(0,Z.jsx)(`div`,{className:`w-8 h-8 rounded-full bg-red-500/20 flex items-center justify-center shrink-0`,children:(0,Z.jsx)(v,{className:`w-4 h-4 text-red-600 dark:text-red-400`})}),(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(`p`,{className:`text-white font-medium`,children:`Remove from project`}),(0,Z.jsx)(`p`,{className:`text-sm text-bambu-gray truncate`,children:`Clear project assignment`})]}),x.isPending&&(0,Z.jsx)(P,{className:`w-4 h-4 animate-spin text-bambu-gray shrink-0`})]}),m&&m.length>0&&(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 py-2`,children:[(0,Z.jsx)(`div`,{className:`flex-1 h-px bg-bambu-dark-tertiary`}),(0,Z.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:`or assign to`}),(0,Z.jsx)(`div`,{className:`flex-1 h-px bg-bambu-dark-tertiary`})]}),_&&(0,Z.jsxs)(`div`,{className:`relative`,children:[(0,Z.jsx)(pe,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`}),(0,Z.jsx)(`input`,{type:`text`,value:u,onChange:e=>d(e.target.value),placeholder:n(`archives.menu.searchProjects`),className:`w-full pl-9 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray text-sm focus:border-bambu-green focus:outline-none`})]}),g?.map(e=>(0,Z.jsxs)(`button`,{onClick:()=>b.mutate(e.id),disabled:C,className:`w-full flex items-center gap-3 p-3 rounded-lg bg-bambu-dark hover:bg-bambu-dark-tertiary border border-bambu-dark-tertiary transition-colors text-left disabled:opacity-50`,children:[(0,Z.jsx)(`div`,{className:`w-8 h-8 rounded-full flex items-center justify-center shrink-0`,style:{backgroundColor:e.color?`${e.color}20`:`rgb(var(--bambu-green) / 0.2)`},children:(0,Z.jsx)(ot,{className:`w-4 h-4`,style:{color:e.color||`rgb(var(--bambu-green))`}})}),(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(`p`,{className:`text-white font-medium truncate`,children:e.name}),(0,Z.jsxs)(`p`,{className:`text-sm text-bambu-gray truncate`,children:[e.archive_count,` archive`,e.archive_count===1?``:`s`,e.status&&` • ${e.status}`]})]}),b.isPending&&b.variables===e.id&&(0,Z.jsx)(P,{className:`w-4 h-4 animate-spin text-bambu-gray shrink-0`})]},e.id)),(!m||m.length===0)&&(0,Z.jsx)(`p`,{className:`text-center text-bambu-gray py-4`,children:`No projects yet. Create one from the Projects page.`}),m&&m.length>0&&g?.length===0&&(0,Z.jsx)(`p`,{className:`text-center text-bambu-gray text-sm py-4`,children:`—`})]})]}),(0,Z.jsx)(`div`,{className:`flex gap-3 p-4 border-t border-bambu-dark-tertiary shrink-0`,children:(0,Z.jsx)(V,{variant:`secondary`,onClick:t,className:`flex-1`,disabled:C,children:`Cancel`})})]})})})}function kt(e,t){return new Date(e,t+1,0).getDate()}function At(e,t){return new Date(e,t,1).getDay()}var jt=[`January`,`February`,`March`,`April`,`May`,`June`,`July`,`August`,`September`,`October`,`November`,`December`],Mt=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`];function Nt({archives:e,onArchiveClick:t,highlightedArchiveId:n}){let i=new Date,[a,o]=(0,X.useState)(i.getMonth()),[s,c]=(0,X.useState)(i.getFullYear()),[l,u]=(0,X.useState)(null),[d,f]=(0,X.useState)(null),p=(0,X.useMemo)(()=>{let t=new Map;return e.forEach(e=>{let n=be(e.completed_at||e.created_at)||new Date,r=`${n.getFullYear()}-${String(n.getMonth()+1).padStart(2,`0`)}-${String(n.getDate()).padStart(2,`0`)}`,i=t.get(r)||[];i.push(e),t.set(r,i)}),t},[e]),m=kt(s,a),h=At(s,a),g=()=>{a===0?(o(11),c(s-1)):o(a-1)},_=()=>{a===11?(o(0),c(s+1)):o(a+1)},v=()=>{o(i.getMonth()),c(i.getFullYear())},y=[];for(let e=0;e{e!==l&&f(null),u(e)};return(0,Z.jsxs)(`div`,{className:`flex flex-col lg:flex-row gap-6`,children:[(0,Z.jsxs)(`div`,{className:`flex-1`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between mb-4`,children:[(0,Z.jsx)(`button`,{onClick:g,className:`p-2 hover:bg-bambu-dark-tertiary rounded-lg transition-colors`,children:(0,Z.jsx)(Ze,{className:`w-5 h-5 text-bambu-gray`})}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Z.jsxs)(`h2`,{className:`text-lg font-semibold text-white`,children:[jt[a],` `,s]}),(0,Z.jsx)(`button`,{onClick:v,className:`px-2 py-1 text-xs bg-bambu-dark-tertiary hover:bg-bambu-green/20 text-bambu-gray hover:text-white rounded transition-colors`,children:`Today`})]}),(0,Z.jsx)(`button`,{onClick:_,className:`p-2 hover:bg-bambu-dark-tertiary rounded-lg transition-colors`,children:(0,Z.jsx)(Me,{className:`w-5 h-5 text-bambu-gray`})})]}),(0,Z.jsx)(`div`,{className:`grid grid-cols-7 gap-1 mb-1`,children:Mt.map(e=>(0,Z.jsx)(`div`,{className:`text-center text-xs text-bambu-gray py-2`,children:e},e))}),(0,Z.jsx)(`div`,{className:`grid grid-cols-7 gap-1`,children:y.map((e,t)=>{if(e===null)return(0,Z.jsx)(`div`,{className:`aspect-square`},`empty-${t}`);let n=`${s}-${String(a+1).padStart(2,`0`)}-${String(e).padStart(2,`0`)}`,r=p.get(n)||[],o=r.length>0,c=e===i.getDate()&&a===i.getMonth()&&s===i.getFullYear(),u=n===l,d=r.filter(e=>e.status===`completed`).length,f=r.filter(e=>e.status===`failed`).length;return(0,Z.jsxs)(`button`,{onClick:()=>x(u?null:n),className:`aspect-square rounded-lg p-1 flex flex-col items-center justify-center transition-colors relative ${u?`bg-bambu-green text-white`:c?`bg-bambu-green/20 text-white ring-2 ring-bambu-green`:o?`bg-bambu-dark-tertiary hover:bg-bambu-dark-tertiary/70 text-white`:`hover:bg-bambu-dark-tertiary/50 text-bambu-gray`}`,children:[(0,Z.jsx)(`span`,{className:`text-sm font-medium ${c&&!u?`text-bambu-green`:``}`,children:e}),o&&(0,Z.jsxs)(`div`,{className:`absolute bottom-1 left-1/2 -translate-x-1/2 flex items-center gap-1`,children:[(0,Z.jsx)(`div`,{className:`w-2 h-2 rounded-full ${f>0&&d===0?`bg-red-400`:f>0?`bg-yellow-400`:`bg-green-400`}`}),(0,Z.jsx)(`span`,{className:`text-xs font-medium`,children:r.length})]})]},e)})}),(0,Z.jsx)(`div`,{className:`mt-4 pt-4 border-t border-bambu-dark-tertiary`,children:(0,Z.jsxs)(`div`,{className:`grid grid-cols-3 gap-4 text-center`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`div`,{className:`text-2xl font-bold text-white`,children:e.filter(e=>{let t=be(e.completed_at||e.created_at)||new Date;return t.getMonth()===a&&t.getFullYear()===s}).length}),(0,Z.jsx)(`div`,{className:`text-xs text-bambu-gray`,children:`Prints this month`})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`div`,{className:`text-2xl font-bold text-green-700 dark:text-green-400`,children:e.filter(e=>{let t=be(e.completed_at||e.created_at)||new Date;return t.getMonth()===a&&t.getFullYear()===s&&e.status===`completed`}).length}),(0,Z.jsx)(`div`,{className:`text-xs text-bambu-gray`,children:`Successful`})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`div`,{className:`text-2xl font-bold text-red-700 dark:text-red-400`,children:e.filter(e=>{let t=be(e.completed_at||e.created_at)||new Date;return t.getMonth()===a&&t.getFullYear()===s&&e.status===`failed`}).length}),(0,Z.jsx)(`div`,{className:`text-xs text-bambu-gray`,children:`Failed`})]})]})})]}),(0,Z.jsx)(`div`,{className:`lg:w-80 bg-bambu-dark rounded-xl p-4`,children:l?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`h3`,{className:`text-sm font-medium text-bambu-gray mb-3`,children:new Date(l+`T12:00:00`).toLocaleDateString(`en-US`,{weekday:`long`,month:`long`,day:`numeric`,year:`numeric`})}),b.length>0?(0,Z.jsx)(`div`,{className:`calendar-scroll space-y-2 max-h-96 overflow-y-auto`,children:b.map(e=>{let i=e.id===d||e.id===n;return(0,Z.jsxs)(`button`,{onClick:()=>{f(e.id),t?.(e)},className:`w-full flex items-center gap-3 p-2 rounded-lg transition-colors text-left ${i?``:`hover:bg-bambu-dark-tertiary`}`,style:i?{outline:`4px solid #facc15`,outlineOffset:`2px`}:void 0,children:[e.thumbnail_path?(0,Z.jsx)(`img`,{src:r.getArchiveThumbnail(e.id),alt:``,className:`w-12 h-12 rounded object-cover`}):(0,Z.jsx)(`div`,{className:`w-12 h-12 rounded bg-bambu-dark-tertiary flex items-center justify-center`,children:(0,Z.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:`3MF`})}),(0,Z.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Z.jsx)(`p`,{className:`text-sm text-white truncate`,children:e.print_name||e.filename}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-xs`,children:[(0,Z.jsx)(`span`,{className:e.status===`failed`?`text-red-700 dark:text-red-400`:`text-green-700 dark:text-green-400`,children:e.status===`failed`?`Failed`:`Completed`}),e.filament_color&&(0,Z.jsx)(`div`,{className:`flex gap-0.5`,children:e.filament_color.split(`,`).map((e,t)=>(0,Z.jsx)(`div`,{className:`w-3 h-3 rounded-full border border-black/20`,style:{backgroundColor:e}},t))})]})]})]},e.id)})}):(0,Z.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:`No prints on this day`})]}):(0,Z.jsx)(`div`,{className:`text-center py-8`,children:(0,Z.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:`Select a day to see prints`})})})]})}function Pt({archiveId:e,archiveName:t,onClose:n}){let i=r.getArchiveQRCodeUrl(e,300);return(0,X.useEffect)(()=>{let e=e=>{e.key===`Escape`&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n]),(0,Z.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:n,children:(0,Z.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-sm`,onClick:e=>e.stopPropagation(),children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,Z.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:`QR Code`}),(0,Z.jsx)(`button`,{onClick:n,className:`text-bambu-gray hover:text-white transition-colors`,children:(0,Z.jsx)(L,{className:`w-5 h-5`})})]}),(0,Z.jsxs)(`div`,{className:`p-6 flex flex-col items-center`,children:[(0,Z.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4 text-center truncate max-w-full`,children:t}),(0,Z.jsx)(`div`,{className:`bg-white p-4 rounded-lg mb-4`,children:(0,Z.jsx)(`img`,{src:i,alt:`QR Code`,className:`w-64 h-64`})}),(0,Z.jsx)(`p`,{className:`text-xs text-bambu-gray mb-4 text-center`,children:`Scan to open this archive`}),(0,Z.jsxs)(V,{onClick:()=>{let e=document.createElement(`a`);e.href=i,e.download=`${t}_qrcode.png`,e.click()},className:`w-full`,children:[(0,Z.jsx)(q,{className:`w-4 h-4`}),`Download QR Code`]})]})]})})}function Q({archiveId:e,archiveName:t,onClose:n}){let i=s(),[a,u]=(0,X.useState)(!1),[d,p]=(0,X.useState)(null),[h,g]=(0,X.useState)({}),{data:_,isLoading:v,error:y}=c({queryKey:[`archive-project-page`,e],queryFn:()=>r.getArchiveProjectPage(e)}),b=l({mutationFn:t=>r.updateArchiveProjectPage(e,t),onSuccess:()=>{i.invalidateQueries({queryKey:[`archive-project-page`,e]}),u(!1),g({})}});(0,X.useEffect)(()=>{let e=e=>{e.key===`Escape`&&(d===null?a?w():n():p(null))};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[d,a,n]);let x=[..._?.model_pictures||[],..._?.profile_pictures||[]],S=()=>{g({title:_?.title||``,description:_?.description||``,designer:_?.designer||``,license:_?.license||``,profile_title:_?.profile_title||``,profile_description:_?.profile_description||``}),u(!0)},C=()=>{b.mutate(h)},w=()=>{u(!1),g({})},T=e=>ht.sanitize(e,{ALLOWED_TAGS:[`p`,`br`,`b`,`strong`,`i`,`em`,`u`,`a`,`ul`,`ol`,`li`,`figure`,`img`],ALLOWED_ATTR:[`href`,`src`,`target`,`rel`,`style`],ADD_ATTR:[`target`]}),E=_&&(_.title||_.description||_.designer||_.profile_title||x.length>0);return(0,Z.jsxs)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:e=>{e.target===e.currentTarget&&n()},children:[(0,Z.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl max-w-4xl w-full max-h-[90vh] overflow-hidden flex flex-col`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Z.jsx)(rt,{className:`w-5 h-5 text-bambu-green`}),(0,Z.jsxs)(`h2`,{className:`text-lg font-semibold text-white`,children:[`Project Page`,t&&(0,Z.jsxs)(`span`,{className:`text-bambu-gray ml-2`,children:[`- `,t]})]})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[!a&&E&&(0,Z.jsxs)(V,{variant:`ghost`,size:`sm`,onClick:S,children:[(0,Z.jsx)(ue,{className:`w-4 h-4 mr-1`}),`Edit`]}),a&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(V,{variant:`ghost`,size:`sm`,onClick:w,children:`Cancel`}),(0,Z.jsxs)(V,{variant:`primary`,size:`sm`,onClick:C,disabled:b.isPending,children:[(0,Z.jsx)(He,{className:`w-4 h-4 mr-1`}),`Save`]})]}),(0,Z.jsx)(`button`,{onClick:n,className:`p-2 hover:bg-bambu-dark-tertiary rounded-lg transition-colors`,children:(0,Z.jsx)(L,{className:`w-5 h-5 text-bambu-gray`})})]})]}),(0,Z.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-6`,children:[v&&(0,Z.jsx)(`div`,{className:`flex items-center justify-center py-12`,children:(0,Z.jsx)(`div`,{className:`animate-spin rounded-full h-8 w-8 border-2 border-bambu-green border-t-transparent`})}),y&&(0,Z.jsx)(`div`,{className:`text-red-700 dark:text-red-400 text-center py-12`,children:`Failed to load project page data`}),_&&!E&&(0,Z.jsxs)(`div`,{className:`text-bambu-gray text-center py-12`,children:[(0,Z.jsx)(rt,{className:`w-12 h-12 mx-auto mb-4 opacity-50`}),(0,Z.jsx)(`p`,{children:`No project page data found in this 3MF file.`}),(0,Z.jsx)(`p`,{className:`text-sm mt-2`,children:`Project pages are typically included in files downloaded from MakerWorld.`})]}),_&&E&&(0,Z.jsxs)(`div`,{className:`space-y-6`,children:[(0,Z.jsxs)(`div`,{className:`space-y-4`,children:[a?(0,Z.jsx)(`input`,{type:`text`,value:h.title||``,onChange:e=>g({...h,title:e.target.value}),placeholder:`Title`,className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded-lg px-4 py-2 text-white text-xl font-semibold`}):_.title&&(0,Z.jsx)(`h3`,{className:`text-xl font-semibold text-white`,children:_.title}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap gap-4 text-sm`,children:[a?(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(Fe,{className:`w-4 h-4 text-bambu-gray`}),(0,Z.jsx)(`input`,{type:`text`,value:h.designer||``,onChange:e=>g({...h,designer:e.target.value}),placeholder:`Designer`,className:`bg-bambu-dark border border-bambu-dark-tertiary rounded px-2 py-1 text-white`})]}):_.designer&&(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray`,children:[(0,Z.jsx)(Fe,{className:`w-4 h-4`}),(0,Z.jsx)(`span`,{children:_.designer}),_.designer_user_id&&(0,Z.jsx)(`a`,{href:`https://makerworld.com/en/@${_.designer_user_id}`,target:`_blank`,rel:`noopener noreferrer`,className:`text-bambu-green hover:underline`,children:(0,Z.jsx)(Ce,{className:`w-3 h-3`})})]}),_.creation_date&&(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray`,children:[(0,Z.jsx)(m,{className:`w-4 h-4`}),(0,Z.jsx)(`span`,{children:_.creation_date})]}),a?(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(rt,{className:`w-4 h-4 text-bambu-gray`}),(0,Z.jsx)(`input`,{type:`text`,value:h.license||``,onChange:e=>g({...h,license:e.target.value}),placeholder:`License`,className:`bg-bambu-dark border border-bambu-dark-tertiary rounded px-2 py-1 text-white`})]}):_.license&&(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray`,children:[(0,Z.jsx)(rt,{className:`w-4 h-4`}),(0,Z.jsx)(`span`,{children:_.license})]}),_.origin&&(0,Z.jsx)(`span`,{className:`px-2 py-0.5 bg-bambu-dark rounded text-bambu-gray`,children:_.origin})]})]}),(_.description||a)&&(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsx)(`h4`,{className:`text-sm font-medium text-bambu-gray uppercase tracking-wide`,children:`Description`}),a?(0,Z.jsx)(f,{content:h.description||``,onChange:e=>g({...h,description:e}),placeholder:`Enter description...`}):(0,Z.jsx)(`div`,{className:`prose prose-invert prose-sm max-w-none text-bambu-gray-light`,dangerouslySetInnerHTML:{__html:T(_.description||``)}})]}),(_.profile_title||_.profile_description||a)&&(0,Z.jsxs)(`div`,{className:`space-y-2 p-4 bg-bambu-dark rounded-lg`,children:[(0,Z.jsx)(`h4`,{className:`text-sm font-medium text-bambu-gray uppercase tracking-wide`,children:`Print Profile`}),a?(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsx)(`input`,{type:`text`,value:h.profile_title||``,onChange:e=>g({...h,profile_title:e.target.value}),placeholder:`Profile Title`,className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-white`}),(0,Z.jsx)(f,{content:h.profile_description||``,onChange:e=>g({...h,profile_description:e}),placeholder:`Profile description...`})]}):(0,Z.jsxs)(Z.Fragment,{children:[_.profile_title&&(0,Z.jsx)(`p`,{className:`text-white font-medium`,children:_.profile_title}),_.profile_description&&(0,Z.jsx)(`div`,{className:`prose prose-invert prose-sm max-w-none text-bambu-gray-light`,dangerouslySetInnerHTML:{__html:T(_.profile_description)}}),_.profile_user_name&&(0,Z.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[`by `,_.profile_user_name]})]})]}),x.length>0&&(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsxs)(`h4`,{className:`text-sm font-medium text-bambu-gray uppercase tracking-wide flex items-center gap-2`,children:[(0,Z.jsx)(tt,{className:`w-4 h-4`}),`Images (`,x.length,`)`]}),(0,Z.jsx)(`div`,{className:`grid grid-cols-3 sm:grid-cols-4 md:grid-cols-5 gap-2`,children:x.map((e,t)=>(0,Z.jsx)(`button`,{onClick:()=>p(t),className:`aspect-square rounded-lg overflow-hidden border border-bambu-dark-tertiary hover:border-bambu-green transition-colors`,children:(0,Z.jsx)(`img`,{src:o(e.url),alt:e.name,className:`w-full h-full object-cover`})},e.path))})]}),_.design_model_id&&(0,Z.jsx)(`div`,{className:`pt-4 border-t border-bambu-dark-tertiary`,children:(0,Z.jsxs)(`a`,{href:`https://makerworld.com/en/models/${_.design_model_id}`,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-2 text-bambu-green hover:underline`,children:[(0,Z.jsx)(Ce,{className:`w-4 h-4`}),`View on MakerWorld`]})})]})]})]}),d!==null&&x[d]&&(0,Z.jsxs)(`div`,{className:`fixed inset-0 bg-black/90 flex items-center justify-center z-60`,onClick:()=>p(null),children:[(0,Z.jsx)(`button`,{onClick:e=>{e.stopPropagation(),p(Math.max(0,d-1))},disabled:d===0,className:`absolute left-4 p-2 bg-bambu-dark-secondary rounded-full hover:bg-bambu-dark-tertiary disabled:opacity-30`,children:(0,Z.jsx)(Ze,{className:`w-6 h-6 text-white`})}),(0,Z.jsx)(`img`,{src:o(x[d].url),alt:x[d].name,className:`max-w-[90vw] max-h-[90vh] object-contain`,onClick:e=>e.stopPropagation()}),(0,Z.jsx)(`button`,{onClick:e=>{e.stopPropagation(),p(Math.min(x.length-1,d+1))},disabled:d===x.length-1,className:`absolute right-4 p-2 bg-bambu-dark-secondary rounded-full hover:bg-bambu-dark-tertiary disabled:opacity-30`,children:(0,Z.jsx)(Me,{className:`w-6 h-6 text-white`})}),(0,Z.jsx)(`button`,{onClick:()=>p(null),className:`absolute top-4 right-4 p-2 bg-bambu-dark-secondary rounded-full hover:bg-bambu-dark-tertiary`,children:(0,Z.jsx)(L,{className:`w-6 h-6 text-white`})}),(0,Z.jsxs)(`div`,{className:`absolute bottom-4 text-white text-sm`,children:[d+1,` / `,x.length]})]})]})}var Ft=[.25,.5,.75,1,1.5,2,3,4];function It({archiveId:e,timelapseSrc:t,onClose:n,onSave:i}){let{showToast:a}=S(),o=(0,X.useRef)(null),s=(0,X.useRef)(null),[u,d]=(0,X.useState)(!1),[f,p]=(0,X.useState)(0),[m,h]=(0,X.useState)(0),[g,_]=(0,X.useState)(0),[v,y]=(0,X.useState)(0),[b,x]=(0,X.useState)(1),[C,w]=(0,X.useState)(null),[T,E]=(0,X.useState)(null),[D,O]=(0,X.useState)(.8),[k,ee]=(0,X.useState)(!1),{data:A,isLoading:te}=c({queryKey:[`timelapse-info`,e],queryFn:()=>r.getTimelapseInfo(e)}),{data:ne}=c({queryKey:[`timelapse-thumbnails`,e],queryFn:()=>r.getTimelapseThumbnails(e,15)}),M=l({mutationFn:()=>r.processTimelapse(e,{trimStart:g,trimEnd:v,speed:b,saveMode:`replace`},C||void 0),onSuccess:e=>{a(e.message,`success`),i?.(),n()},onError:e=>{a(e.message||`Processing failed`,`error`)}});(0,X.useEffect)(()=>{A?.duration&&v===0&&y(A.duration)},[A?.duration,v]),(0,X.useEffect)(()=>{let e=e=>{e.key===`Escape`&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n]),(0,X.useEffect)(()=>{let e=o.current;if(!e)return;let t=()=>{let t=e.currentTime;p(t),t>=v&&(e.currentTime=g)},n=()=>{h(e.duration),v===0&&y(e.duration)},r=()=>d(!0),i=()=>d(!1);return e.addEventListener(`timeupdate`,t),e.addEventListener(`durationchange`,n),e.addEventListener(`play`,r),e.addEventListener(`pause`,i),()=>{e.removeEventListener(`timeupdate`,t),e.removeEventListener(`durationchange`,n),e.removeEventListener(`play`,r),e.removeEventListener(`pause`,i)}},[g,v]),(0,X.useEffect)(()=>{let e=s.current,t=o.current;!e||!t||!T||(e.currentTime=t.currentTime,e.playbackRate=t.playbackRate,u&&!k?e.play().catch(()=>{}):e.pause())},[u,T,k]),(0,X.useEffect)(()=>{s.current&&(s.current.volume=k?0:D)},[D,k]),(0,X.useEffect)(()=>{o.current&&(o.current.playbackRate=b),s.current&&(s.current.playbackRate=b)},[b]);let re=(0,X.useCallback)(()=>{let e=o.current;e&&(u?e.pause():(e.currentTime{let t=o.current;t&&(t.currentTime=Math.max(g,Math.min(v,e)))},ae=e=>{let t=e.target.files?.[0];t&&(T&&URL.revokeObjectURL(T),w(t),E(URL.createObjectURL(t)))},oe=()=>{T&&URL.revokeObjectURL(T),w(null),E(null)};(0,X.useEffect)(()=>()=>{T&&URL.revokeObjectURL(T)},[T]);let se=v-g,ce=se/b;return te?(0,Z.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/80`,children:(0,Z.jsxs)(`div`,{className:`flex items-center gap-3 text-white`,children:[(0,Z.jsx)(P,{className:`w-6 h-6 animate-spin`}),`Loading video info...`]})}):(0,Z.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/80`,children:(0,Z.jsxs)(`div`,{className:`relative bg-bambu-dark-secondary rounded-xl max-w-5xl w-full mx-4 max-h-[90vh] overflow-hidden flex flex-col`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary shrink-0`,children:[(0,Z.jsxs)(`h3`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,Z.jsx)(j,{className:`w-5 h-5 text-bambu-green`}),`Edit Timelapse`]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(V,{variant:`primary`,size:`sm`,onClick:()=>M.mutate(),disabled:M.isPending,children:M.isPending?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(P,{className:`w-4 h-4 animate-spin`}),`Processing...`]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(He,{className:`w-4 h-4`}),`Save`]})}),(0,Z.jsx)(`button`,{onClick:n,className:`p-1 hover:bg-bambu-dark-tertiary rounded transition-colors`,children:(0,Z.jsx)(L,{className:`w-5 h-5 text-bambu-gray`})})]})]}),(0,Z.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-4 space-y-4`,children:[(0,Z.jsxs)(`div`,{className:`relative`,children:[(0,Z.jsx)(`video`,{ref:o,src:t,className:`w-full rounded-lg bg-black`,onClick:re,muted:!!T}),!u&&(0,Z.jsx)(`button`,{onClick:re,className:`absolute inset-0 flex items-center justify-center bg-black/30 hover:bg-black/40 transition-colors`,children:(0,Z.jsx)(`div`,{className:`p-4 bg-bambu-green rounded-full`,children:(0,Z.jsx)(de,{className:`w-8 h-8 text-white`})})}),T&&(0,Z.jsx)(`audio`,{ref:s,src:T,loop:!0})]}),(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-bambu-gray`,children:[(0,Z.jsx)(bt,{className:`w-4 h-4`}),(0,Z.jsx)(`span`,{children:`Trim`}),(0,Z.jsxs)(`span`,{className:`ml-auto`,children:[H(g),` - `,H(v),` (`,H(se),`)`]})]}),(0,Z.jsxs)(`div`,{className:`relative h-16 bg-bambu-dark rounded-lg overflow-hidden`,children:[(0,Z.jsx)(`div`,{className:`absolute inset-0 flex`,children:ne?.thumbnails.map((e,t)=>(0,Z.jsx)(`div`,{className:`flex-1 bg-cover bg-center`,style:{backgroundImage:`url(data:image/jpeg;base64,${e})`}},t))}),(0,Z.jsx)(`div`,{className:`absolute inset-y-0 left-0 bg-black/60`,style:{width:`${g/m*100}%`}}),(0,Z.jsx)(`div`,{className:`absolute inset-y-0 right-0 bg-black/60`,style:{width:`${(m-v)/m*100}%`}}),(0,Z.jsx)(`div`,{className:`absolute inset-y-0 border-2 border-bambu-green`,style:{left:`${g/m*100}%`,right:`${(m-v)/m*100}%`}}),(0,Z.jsx)(`div`,{className:`absolute top-0 bottom-0 w-0.5 bg-white shadow-lg`,style:{left:`${f/m*100}%`}}),(0,Z.jsx)(`input`,{type:`range`,min:0,max:m,step:.1,value:g,onChange:e=>{let t=parseFloat(e.target.value);t{let t=parseFloat(e.target.value);t>g+1&&y(t)},className:`absolute inset-0 w-full opacity-0 cursor-ew-resize`,style:{clipPath:`inset(0 0 0 50%)`}})]}),(0,Z.jsx)(`input`,{type:`range`,min:0,max:m,step:.1,value:f,onChange:e=>ie(parseFloat(e.target.value)),className:`w-full h-1 bg-bambu-dark-tertiary rounded-lg appearance-none cursor-pointer [&::-webkit-slider-thumb]:appearance-none [&::-webkit-slider-thumb]:w-3 [&::-webkit-slider-thumb]:h-3 [&::-webkit-slider-thumb]:bg-bambu-green [&::-webkit-slider-thumb]:rounded-full [&::-webkit-slider-thumb]:cursor-pointer`}),(0,Z.jsx)(`div`,{className:`flex items-center justify-center gap-2`,children:(0,Z.jsx)(`button`,{onClick:re,className:`p-2 bg-bambu-green hover:bg-bambu-green-dark rounded-lg transition-colors`,children:u?(0,Z.jsx)(F,{className:`w-5 h-5 text-white`}):(0,Z.jsx)(de,{className:`w-5 h-5 text-white`})})})]}),(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-bambu-gray`,children:[(0,Z.jsx)(N,{className:`w-4 h-4`}),(0,Z.jsx)(`span`,{children:`Speed`}),(0,Z.jsxs)(`span`,{className:`ml-auto`,children:[b,`x (output: `,H(ce),`)`]})]}),(0,Z.jsx)(`div`,{className:`flex gap-1`,children:Ft.map(e=>(0,Z.jsxs)(`button`,{onClick:()=>x(e),className:`flex-1 px-2 py-2 text-sm rounded transition-colors ${b===e?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:[e,`x`]},e))})]}),(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-bambu-gray`,children:[(0,Z.jsx)(et,{className:`w-4 h-4`}),(0,Z.jsx)(`span`,{children:`Music Overlay`})]}),C?(0,Z.jsxs)(`div`,{className:`flex items-center gap-3 p-3 bg-bambu-dark rounded-lg`,children:[(0,Z.jsx)(et,{className:`w-5 h-5 text-bambu-green`}),(0,Z.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Z.jsx)(`p`,{className:`text-sm text-white truncate`,children:C.name}),(0,Z.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[(C.size/1024/1024).toFixed(1),` MB`]})]}),(0,Z.jsx)(`button`,{onClick:()=>ee(!k),className:`p-2 hover:bg-bambu-dark-tertiary rounded transition-colors`,children:k?(0,Z.jsx)(St,{className:`w-4 h-4 text-bambu-gray`}):(0,Z.jsx)(Y,{className:`w-4 h-4 text-bambu-green`})}),(0,Z.jsx)(`input`,{type:`range`,min:0,max:1,step:.1,value:D,onChange:e=>O(parseFloat(e.target.value)),className:`w-20 h-1 bg-bambu-dark-tertiary rounded-lg appearance-none cursor-pointer diff --git a/static/assets/AssignToAmsModal-CcnpBCWY.js b/static/assets/AssignToAmsModal-dWQ_DHhy.js similarity index 99% rename from static/assets/AssignToAmsModal-CcnpBCWY.js rename to static/assets/AssignToAmsModal-dWQ_DHhy.js index 1a6bfee54..75559fa1f 100644 --- a/static/assets/AssignToAmsModal-CcnpBCWY.js +++ b/static/assets/AssignToAmsModal-dWQ_DHhy.js @@ -1 +1 @@ -import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,w as i}from"./client-DnySrlFv.js";import{n as a}from"./QueryClientProvider-Ce8_sN3w.js";import{t as o}from"./useQuery-BBCjCezC.js";import{t as s}from"./useMutation-B-Tr2hIP.js";import{t as c}from"./check-Ck0cMLU4.js";import{n as l}from"./info-ROUoQhJR.js";import{r as ee}from"./ToastContext-BRX0SW3C.js";import{t as u}from"./loader-circle-BEmFtawu.js";import{t as te}from"./x-DR-Trv6U.js";import{K as ne,_t as re,cn as ie,ft as ae,lt as oe}from"./index-0t--Yqoi.js";import{r as se,t as ce}from"./AmsUnitCard-Dim7pnZ8.js";import{n as le}from"./spoolPaint-CrvpHqdD.js";var d=e(n(),1),f=t();function p(e){return e<=3?`AMS ${String.fromCharCode(65+e)}`:e>=128&&e<=135?`AMS HT ${String.fromCharCode(65+e-128)}`:`AMS ${e}`}function m(e){return!e.tray_type||e.tray_type===``}function ue(e){return e?`#${e.slice(0,6)}`:`#808080`}var h=[`a[href]`,`button:not([disabled])`,`input:not([disabled]):not([type="hidden"])`,`select:not([disabled])`,`textarea:not([disabled])`,`[tabindex]:not([tabindex="-1"])`].join(`,`);function de(e){return Array.from(e.querySelectorAll(h)).filter(e=>!e.hasAttribute(`hidden`)&&e.getAttribute(`aria-hidden`)!==`true`)}var g=e=>(e??``).trim().toUpperCase();function fe(e,t){let n=g(e),r=g(t);return!n||!r?`none`:n===r?`exact`:r.includes(n)||n.includes(r)?`partial`:`none`}function pe(e,t){let n=g(e),r=g(t);return!n||!r?!1:n===r}function _({isOpen:e,onClose:t,spool:n,printerId:h,variant:g=`dialog`,spoolmanMode:_=!1}){let{t:v}=i(),y=a(),b=(0,d.useRef)(null),[me,he]=(0,d.useState)(h),[x,S]=(0,d.useState)(null),[ge,C]=(0,d.useState)(null),[w,T]=(0,d.useState)(null),[E,D]=(0,d.useState)(!1),[O,k]=(0,d.useState)(null),[A,j]=(0,d.useState)(null);(0,d.useEffect)(()=>{e&&(he(h),S(null),C(null),T(null),D(!1),k(null),j(null))},[e,h,n.id]);let M=h===null,N=M,P=h??me,{data:_e=[],isLoading:ve}=o({queryKey:[`printers`],queryFn:()=>r.getPrinters(),enabled:e&&M}),ye=(0,d.useMemo)(()=>_e.filter(e=>e.is_active!==!1),[_e]);(0,d.useEffect)(()=>{if(!e)return;let t=document.body.style.overflow,n=document.activeElement instanceof HTMLElement?document.activeElement:null;document.body.style.overflow=`hidden`;let r=b.current;return((r?de(r)[0]:null)??r)?.focus(),()=>{document.body.style.overflow=t,n?.isConnected&&n.focus()}},[e]);let F=(0,d.useCallback)(e=>{if(E)return;if(e.key===`Escape`){e.preventDefault(),t();return}if(e.key!==`Tab`)return;let n=b.current;if(!n)return;let r=de(n);if(r.length===0){e.preventDefault(),n.focus();return}let i=r[0],a=r[r.length-1],o=document.activeElement;e.shiftKey&&(o===i||!n.contains(o))?(e.preventDefault(),a.focus()):!e.shiftKey&&(o===a||!n.contains(o))&&(e.preventDefault(),i.focus())},[t,E]);(0,d.useEffect)(()=>{if(e)return document.addEventListener(`keydown`,F),()=>document.removeEventListener(`keydown`,F)},[e,F]);let{data:I,isLoading:be}=o({queryKey:[`printerStatus`,P],queryFn:()=>r.getPrinterStatus(P),enabled:e&&P!==null,refetchInterval:5e3}),{data:xe}=o({queryKey:[`printer`,P],queryFn:()=>r.getPrinter(P),enabled:e&&P!==null}),{data:L}=o({queryKey:[`settings`],queryFn:()=>r.getSettings(),enabled:e,staleTime:300*1e3}),{data:R}=o({queryKey:[`spool-assignments`,P],queryFn:()=>r.getAssignments(P),enabled:e&&P!==null,staleTime:30*1e3}),{data:Se=[]}=o({queryKey:[`spoolman-slot-assignments`,P],queryFn:()=>r.getSpoolmanSlotAssignments(P??void 0),enabled:e&&!!_&&P!==null,staleTime:30*1e3}),z=_?Se.find(e=>e.spoolman_spool_id===n.id):void 0,B=(0,d.useMemo)(()=>{let e={};if(!R)return e;for(let t of R){let n=t.spool;if(n&&n.label_weight>0&&n.weight_used!=null){let r=Math.round(Math.max(0,n.label_weight-n.weight_used)/n.label_weight*100);e[`${t.ams_id}-${t.tray_id}`]=r}}return e},[R]),Ce=L?{humidityGood:Number(L.ams_humidity_good)||40,humidityFair:Number(L.ams_humidity_fair)||60,tempGood:Number(L.ams_temp_good)||28,tempFair:Number(L.ams_temp_fair)||35}:void 0,we=I?.connected??!1,V=(0,d.useMemo)(()=>I?.ams??[],[I?.ams]),Te=(0,d.useMemo)(()=>V.filter(e=>!e.is_ams_ht),[V]),H=(0,d.useMemo)(()=>V.filter(e=>e.is_ams_ht),[V]),U=(0,d.useMemo)(()=>[...I?.vt_tray??[]].sort((e,t)=>(e.id??254)-(t.id??254)),[I?.vt_tray]),W=xe?.nozzle_count===2||I?.temperatures?.nozzle_2!==void 0,G=(0,d.useRef)({});(0,d.useEffect)(()=>{G.current={}},[P]),(0,d.useEffect)(()=>{I?.ams_extruder_map&&Object.keys(I.ams_extruder_map).length>0&&(G.current=I.ams_extruder_map)},[I?.ams_extruder_map]);let Ee=I?.ams_extruder_map&&Object.keys(I.ams_extruder_map).length>0?I.ams_extruder_map:G.current,K=I?.fila_switch?.installed===!0,q=(0,d.useCallback)(e=>{if(!W)return null;let t=Ee[String(e)];return t===void 0?K?null:(e>=128?e-128:e)===1?`L`:`R`:t===1?`L`:`R`},[W,Ee,K]),J=s({mutationFn:async({amsId:e,trayId:t})=>{if(!P)throw Error(`No printer selected`);return _?await r.assignSpoolmanSlot({spoolman_spool_id:n.id,printer_id:P,ams_id:e,tray_id:t}):await r.assignSpool({spool_id:n.id,printer_id:P,ams_id:e,tray_id:t})},onSuccess:e=>{T(`success`);let n=e&&`pending_config`in e&&e.pending_config;C(n?v(`spoolbuddy.modal.assignPendingInsert`,`Assigned. Slot will configure when you insert the spool.`):v(`spoolbuddy.modal.assignSuccess`,`Assigned!`)),y.invalidateQueries({queryKey:[`slotPresets`]}),y.invalidateQueries({queryKey:[`spool-assignments`]}),y.invalidateQueries({queryKey:[`spoolman-slot-assignments`]}),y.invalidateQueries({queryKey:[`spoolman-slot-assignments-all`]}),y.invalidateQueries({queryKey:[`inventory-spools`]}),y.invalidateQueries({queryKey:[`spoolman-inventory-spools`]}),setTimeout(()=>t(),n?2500:1500)},onError:e=>{T(`error`),C(e instanceof Error?e.message:v(`spoolbuddy.modal.assignError`,`Failed to assign spool.`))}}),Y=J.isPending,De=(0,d.useCallback)((e,t)=>{if(e===254||e===255){let n=e===254?254:254+t;return U.find(e=>(e.id??254)===n)||null}return V.find(t=>t.id===e)?.tray?.find(e=>e.id===t)||null},[V,U]),X=(0,d.useCallback)((e,t)=>e<=3?`${p(e)} ${v(`ams.slot`,`Slot`)} ${t+1}`:e>=128&&e<=135?p(e):W?e===254||e===255&&t===0?v(`printers.extL`,`Ext-L`):v(`printers.extR`,`Ext-R`):v(`printers.ext`,`Ext`),[v,W]),Z=(0,d.useCallback)((e,t)=>{T(`info`),C(v(`spoolbuddy.modal.assigning`,`Configuring slot...`)),J.mutate({amsId:e,trayId:t})},[J,v]),Q=(0,d.useCallback)((e,t)=>{if(!Y){if(!L?.disable_filament_warnings){let r=De(e,t);if(r&&!m(r)){let i=r.tray_sub_brands||r.tray_type||``,a=fe(n.material,i),o=n.slicer_filament_name||n.slicer_filament,s=r.tray_type||``,c=pe(o,s);if(a!==`exact`){let r;r=a===`none`&&!c?`material_profile`:a===`partial`&&!c?`partial_profile`:a===`none`?`material`:`partial`;let l=X(e,t);j({amsId:e,trayId:t}),k({type:r,spoolMaterial:n.material||``,trayMaterial:i||``,spoolProfile:o||void 0,trayProfile:s||void 0,location:l}),D(!0);return}}}Z(e,t)}},[Y,L?.disable_filament_warnings,n,De,X,Z]),Oe=(0,d.useCallback)((e,t)=>{if(!Y){if(N){S({amsId:e,trayId:t}),C(null),T(null);return}Q(e,t)}},[N,Y,Q]),ke=(0,d.useCallback)(()=>{x&&Q(x.amsId,x.trayId)},[Q,x]),Ae=(0,d.useCallback)(()=>{A&&(D(!1),k(null),Z(A.amsId,A.trayId),j(null))},[A,Z]),je=(0,d.useMemo)(()=>{let e=[];for(let t of H){let n=t.tray?.[0]||{id:0,tray_color:null,tray_type:``,tray_sub_brands:null,tray_id_name:null,tray_info_idx:null,remain:-1,k:null,cali_idx:null,tag_uid:null,tray_uuid:null,nozzle_temp_min:null,nozzle_temp_max:null},r=B[`${t.id}-0`]??null,i=n.remain!=null&&n.remain>=0?n.remain:null,a=r===0&&i!==null&&i>0?null:r;e.push({key:`ht-${t.id}`,label:p(t.id),amsId:t.id,trayId:0,tray:n,isEmpty:m(n),nozzleSide:q(t.id),effectiveFill:a??i})}for(let t of U){let n=t.id??254,r=n-254,i=B[`255-${r}`]??null,a=t.remain!=null&&t.remain>=0?t.remain:null,o=i===0&&a!==null&&a>0?null:i;e.push({key:`ext-${n}`,label:W?n===254?v(`printers.extL`,`Ext-L`):v(`printers.extR`,`Ext-R`):v(`printers.ext`,`Ext`),amsId:255,trayId:r,tray:t,isEmpty:m(t),nozzleSide:W?n===254?`L`:`R`:null,effectiveFill:o??a})}return e},[H,U,W,v,q,B]);if(!e)return null;let Me=le(n)??oe(n.rgba),Ne=x?X(x.amsId,x.trayId):null,$=g===`dialog`;return(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(`div`,{className:$?`fixed inset-0 z-[60] flex items-center justify-center bg-black/45 dark:bg-black/70 p-2 sm:p-4 backdrop-blur-sm animate-fade-in`:`fixed inset-0 z-[60] bg-bambu-dark`,onClick:$&&!Y?t:void 0,children:(0,f.jsxs)(`div`,{ref:b,role:`dialog`,"aria-modal":`true`,"aria-labelledby":`assign-to-ams-title`,tabIndex:-1,className:$?`bg-bambu-dark-secondary text-white font-sans w-full max-w-3xl h-[calc(100vh-1rem)] sm:h-[calc(100vh-2rem)] max-h-[820px] border border-[var(--border-color)] rounded-xl sm:rounded-2xl shadow-2xl flex flex-col overflow-hidden animate-slide-up`:`w-full h-full bg-bambu-dark flex flex-col`,onClick:e=>e.stopPropagation(),children:[(0,f.jsxs)(`div`,{className:`flex items-center justify-between bg-bambu-dark-secondary px-5 py-3 border-b border-[var(--border-color)] shrink-0`,children:[(0,f.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0`,children:[(0,f.jsx)(`div`,{className:`w-7 h-7 rounded-full shrink-0`,style:Me}),(0,f.jsx)(`div`,{className:`min-w-0`,children:(0,f.jsxs)(`h2`,{id:`assign-to-ams-title`,className:`text-sm font-semibold text-white truncate`,children:[v(`spoolbuddy.modal.assignToAmsTitle`,`Assign to AMS`),(0,f.jsxs)(`span`,{className:`font-normal text-bambu-gray-light ml-2`,children:[ae(n.color_name,n.rgba,n.color_name_is_synthesized)||v(`spoolbuddy.spool.unknownColor`),` • `,n.brand,` `,n.material,n.subtype&&` ${n.subtype}`]}),(0,f.jsxs)(`span`,{className:`text-[10px] font-mono text-bambu-gray ml-2 shrink-0`,children:[`#`,n.id]})]})})]}),(0,f.jsx)(`button`,{onClick:t,disabled:Y,"aria-label":v(`common.close`,`Close`),className:`p-2 rounded-lg text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary transition-colors shrink-0 disabled:opacity-50`,children:(0,f.jsx)(te,{className:`w-5 h-5`})})]}),M&&(0,f.jsxs)(`div`,{className:`bg-bambu-dark-secondary px-5 py-3 border-b border-[var(--border-color)] shrink-0`,children:[(0,f.jsxs)(`label`,{htmlFor:`assign-spool-printer`,className:`flex items-center gap-2 text-sm font-medium text-white mb-2`,children:[(0,f.jsx)(`span`,{className:`inline-flex h-5 w-5 items-center justify-center rounded-full bg-bambu-green text-[11px] font-bold text-[#ffffff]`,children:`1`}),v(`printModal.selectPrinter`)]}),(0,f.jsxs)(`select`,{id:`assign-spool-printer`,"aria-label":v(`printModal.selectPrinter`),value:me??``,onChange:e=>{he(e.target.value?Number(e.target.value):null),S(null),C(null),T(null)},disabled:Y||ve,className:`w-full bg-bambu-dark border border-[var(--border-color)] rounded-lg px-3 py-2.5 text-sm text-white focus:outline-none focus:border-bambu-green disabled:opacity-50`,children:[(0,f.jsx)(`option`,{value:``,children:ve?v(`common.loading`):ye.length===0?v(`common.noPrinters`):v(`printModal.selectPrinter`)}),ye.map(e=>(0,f.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),ge&&(0,f.jsxs)(`div`,{className:`mx-5 mt-3 p-3 rounded-lg flex items-center gap-3 border shrink-0 ${w===`info`?`bg-blue-50 border-blue-300 dark:bg-blue-500/10 dark:border-blue-500/40`:w===`success`?`bg-green-50 border-green-300 dark:bg-green-500/10 dark:border-green-500/40`:`bg-red-50 border-red-300 dark:bg-red-500/10 dark:border-red-500/40`}`,children:[w===`info`&&(0,f.jsx)(u,{className:`w-4 h-4 text-blue-600 dark:text-blue-400 animate-spin shrink-0`}),w===`success`&&(0,f.jsx)(ee,{className:`w-4 h-4 text-green-600 dark:text-green-400 shrink-0`}),w===`error`&&(0,f.jsx)(l,{className:`w-4 h-4 text-red-600 dark:text-red-400 shrink-0`}),(0,f.jsx)(`span`,{className:`text-sm ${w===`info`?`text-blue-700 dark:text-blue-300`:w===`success`?`text-green-700 dark:text-green-300`:`text-red-700 dark:text-red-300`}`,children:ge})]}),(0,f.jsx)(`div`,{className:`flex-1 min-h-0 flex flex-col`,children:(0,f.jsxs)(`section`,{className:`flex min-h-[18rem] flex-col gap-3 bg-bambu-dark p-4 lg:min-h-0 lg:overflow-y-auto`,children:[M&&(0,f.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-medium text-white shrink-0`,children:[(0,f.jsx)(`span`,{className:`inline-flex h-5 w-5 items-center justify-center rounded-full bg-bambu-green text-[11px] font-bold text-[#ffffff]`,children:`2`}),v(`printModal.selectSlot`)]}),P?be?(0,f.jsxs)(`div`,{className:`flex flex-1 items-center justify-center text-bambu-gray-light`,children:[(0,f.jsx)(u,{className:`mr-2 h-5 w-5 animate-spin text-bambu-green`}),v(`common.loading`)]}):we?V.length===0&&U.length===0?(0,f.jsx)(`div`,{className:`flex flex-1 items-center justify-center rounded-xl border border-dashed border-[var(--border-color)] bg-bambu-dark-secondary p-8`,children:(0,f.jsxs)(`div`,{className:`text-center text-bambu-gray`,children:[(0,f.jsx)(ie,{className:`w-12 h-12 mx-auto mb-3 opacity-60`}),(0,f.jsx)(`p`,{className:`text-base text-bambu-gray-light mb-1`,children:v(`spoolbuddy.ams.noData`,`No AMS detected`)}),(0,f.jsx)(`p`,{className:`text-sm`,children:v(`spoolbuddy.ams.connectAms`,`Connect an AMS to see filament slots`)})]})}):(0,f.jsxs)(f.Fragment,{children:[Te.length>0&&(0,f.jsx)(`div`,{className:`grid grid-cols-1 xl:grid-cols-2 gap-3`,children:Te.map(e=>(0,f.jsx)(ce,{unit:e,activeSlot:x?.amsId===e.id?x.trayId:z?.ams_id===e.id?z.tray_id??null:null,onConfigureSlot:(t,n)=>Oe(e.id,n),isDualNozzle:W,nozzleSide:q(e.id),thresholds:Ce,fillOverrides:B},e.id))}),je.length>0&&(0,f.jsx)(`div`,{className:`flex flex-wrap gap-2 shrink-0`,children:je.map(({key:e,label:t,amsId:n,trayId:r,tray:i,isEmpty:a,nozzleSide:o,effectiveFill:s})=>{let c=ue(i.tray_color),l=x?x.amsId===n&&x.trayId===r:!!z&&z.ams_id===n&&z.tray_id===r;return(0,f.jsxs)(`button`,{type:`button`,"aria-pressed":l,title:X(n,r),onClick:()=>Oe(n,r),className:`bg-bambu-dark-secondary border rounded-lg px-3 py-2 hover:bg-bambu-dark-tertiary transition-all flex items-center gap-2 ${l?`ring-2 ring-bambu-green border-bambu-green bg-bambu-green/10`:`border-[var(--border-color)]`} ${Y?`opacity-50 pointer-events-none`:``}`,children:[(0,f.jsx)(`div`,{className:`relative w-10 h-10 shrink-0`,children:a?(0,f.jsx)(`div`,{className:`w-full h-full rounded-full border-2 border-dashed border-gray-500 flex items-center justify-center`,children:(0,f.jsx)(`div`,{className:`w-1.5 h-1.5 rounded-full bg-gray-600`})}):(0,f.jsxs)(`svg`,{viewBox:`0 0 56 56`,className:`w-full h-full`,children:[(0,f.jsx)(`circle`,{cx:`28`,cy:`28`,r:`26`,fill:c}),(0,f.jsx)(`circle`,{cx:`28`,cy:`28`,r:`20`,fill:c,style:{filter:`brightness(0.85)`}}),(0,f.jsx)(`ellipse`,{cx:`20`,cy:`20`,rx:`6`,ry:`4`,fill:`white`,opacity:`0.3`}),(0,f.jsx)(`circle`,{cx:`28`,cy:`28`,r:`8`,fill:`#2d2d2d`}),(0,f.jsx)(`circle`,{cx:`28`,cy:`28`,r:`5`,fill:`#1a1a1a`})]})}),(0,f.jsxs)(`div`,{className:`min-w-0 text-left`,children:[(0,f.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,f.jsx)(`span`,{className:`text-xs text-bambu-gray font-medium`,children:t}),o&&(0,f.jsx)(se,{side:o})]}),(0,f.jsx)(`div`,{className:`text-sm text-white truncate`,children:a?v(`ams.empty`):i.tray_type||`?`})]}),!a&&s!=null&&s>=0&&(0,f.jsx)(`div`,{className:`w-1.5 h-8 bg-bambu-dark-tertiary rounded-full overflow-hidden shrink-0 flex flex-col-reverse`,children:(0,f.jsx)(`div`,{className:`w-full rounded-full`,style:{height:`${s}%`,backgroundColor:ne(s)}})})]},e)})})]}):(0,f.jsx)(`div`,{className:`flex flex-1 items-center justify-center rounded-xl border border-red-300 bg-red-50 p-8 dark:border-red-500/30 dark:bg-red-500/5`,children:(0,f.jsx)(`p`,{className:`text-base text-red-700 dark:text-red-300`,children:v(`spoolbuddy.ams.printerDisconnected`,`Printer disconnected`)})}):(0,f.jsx)(`div`,{className:`flex flex-1 items-center justify-center rounded-xl border border-dashed border-[var(--border-color)] bg-bambu-dark-secondary p-8`,children:(0,f.jsxs)(`div`,{className:`text-center text-bambu-gray`,children:[(0,f.jsx)(ie,{className:`w-12 h-12 mx-auto mb-3 opacity-60`}),(0,f.jsx)(`p`,{className:`text-base text-bambu-gray-light`,children:v(`printModal.selectPrinter`)})]})})]})}),(0,f.jsxs)(`div`,{className:`flex items-center gap-3 bg-bambu-dark-secondary px-5 py-3 border-t border-[var(--border-color)] shrink-0`,children:[N&&(0,f.jsxs)(`div`,{className:`min-w-0 flex-1 text-sm`,children:[(0,f.jsxs)(`span`,{className:`text-bambu-gray`,children:[v(`printModal.selectSlot`),`: `]}),(0,f.jsx)(`span`,{className:Ne?`font-medium text-white`:`text-bambu-gray`,children:Ne||`—`})]}),(0,f.jsx)(`button`,{onClick:t,disabled:Y,className:`px-5 py-2.5 rounded-lg border border-[var(--border-color)] text-sm font-medium bg-bambu-dark-tertiary text-white hover:bg-bambu-dark transition-colors min-h-[44px] disabled:opacity-50`,children:v(w===`success`?`common.close`:`common.cancel`)}),N&&(0,f.jsxs)(`button`,{type:`button`,onClick:ke,disabled:!P||!x||Y||w===`success`,className:`inline-flex min-h-[44px] items-center gap-2 rounded-lg bg-bambu-green px-5 py-2.5 text-sm font-semibold text-[#ffffff] transition-colors hover:bg-bambu-green-dark disabled:cursor-not-allowed disabled:opacity-40`,children:[Y?(0,f.jsx)(u,{className:`h-4 w-4 animate-spin`}):(0,f.jsx)(c,{className:`h-4 w-4`}),v(`inventory.assignSpool`)]})]})]})}),E&&O&&(()=>{let e=``;return O.type===`material`?e=v(`inventory.assignMismatchMessage`,{spoolMaterial:O.spoolMaterial,trayMaterial:O.trayMaterial,location:O.location}):O.type===`partial`?e=v(`inventory.assignPartialMismatchMessage`,{spoolMaterial:O.spoolMaterial,trayMaterial:O.trayMaterial,location:O.location}):O.type===`material_profile`?e=`${v(`inventory.assignMismatchMessage`,{spoolMaterial:O.spoolMaterial,trayMaterial:O.trayMaterial,location:O.location})}\n\n${v(`inventory.assignProfileMismatchMessage`,{spoolProfile:O.spoolProfile||v(`common.unknown`),trayProfile:O.trayProfile||v(`common.unknown`),location:O.location})}`:O.type===`partial_profile`&&(e=`${v(`inventory.assignPartialMismatchMessage`,{spoolMaterial:O.spoolMaterial,trayMaterial:O.trayMaterial,location:O.location})}\n\n${v(`inventory.assignProfileMismatchMessage`,{spoolProfile:O.spoolProfile||v(`common.unknown`),trayProfile:O.trayProfile||v(`common.unknown`),location:O.location})}`),e=`${e}\n\n${v(`inventory.assignReconfigureNote`)}`,(0,f.jsx)(re,{title:v(`inventory.assignMismatchTitle`),message:e,confirmText:v(`inventory.assignMismatchConfirm`),variant:`warning`,overlayZIndex:`z-[70]`,isLoading:J.isPending,onConfirm:Ae,onCancel:()=>{J.isPending||(D(!1),j(null),k(null))}})})()]})}export{_ as t}; \ No newline at end of file +import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,w as i}from"./client-DnySrlFv.js";import{n as a}from"./QueryClientProvider-Ce8_sN3w.js";import{t as o}from"./useQuery-BBCjCezC.js";import{t as s}from"./useMutation-B-Tr2hIP.js";import{t as c}from"./check-Ck0cMLU4.js";import{n as l}from"./info-ROUoQhJR.js";import{r as ee}from"./ToastContext-BRX0SW3C.js";import{t as u}from"./loader-circle-BEmFtawu.js";import{t as te}from"./x-DR-Trv6U.js";import{K as ne,_t as re,cn as ie,ft as ae,lt as oe}from"./index-Cxa-KVmA.js";import{r as se,t as ce}from"./AmsUnitCard-CeSWF1rR.js";import{n as le}from"./spoolPaint-CrvpHqdD.js";var d=e(n(),1),f=t();function p(e){return e<=3?`AMS ${String.fromCharCode(65+e)}`:e>=128&&e<=135?`AMS HT ${String.fromCharCode(65+e-128)}`:`AMS ${e}`}function m(e){return!e.tray_type||e.tray_type===``}function ue(e){return e?`#${e.slice(0,6)}`:`#808080`}var h=[`a[href]`,`button:not([disabled])`,`input:not([disabled]):not([type="hidden"])`,`select:not([disabled])`,`textarea:not([disabled])`,`[tabindex]:not([tabindex="-1"])`].join(`,`);function de(e){return Array.from(e.querySelectorAll(h)).filter(e=>!e.hasAttribute(`hidden`)&&e.getAttribute(`aria-hidden`)!==`true`)}var g=e=>(e??``).trim().toUpperCase();function fe(e,t){let n=g(e),r=g(t);return!n||!r?`none`:n===r?`exact`:r.includes(n)||n.includes(r)?`partial`:`none`}function pe(e,t){let n=g(e),r=g(t);return!n||!r?!1:n===r}function _({isOpen:e,onClose:t,spool:n,printerId:h,variant:g=`dialog`,spoolmanMode:_=!1}){let{t:v}=i(),y=a(),b=(0,d.useRef)(null),[me,he]=(0,d.useState)(h),[x,S]=(0,d.useState)(null),[ge,C]=(0,d.useState)(null),[w,T]=(0,d.useState)(null),[E,D]=(0,d.useState)(!1),[O,k]=(0,d.useState)(null),[A,j]=(0,d.useState)(null);(0,d.useEffect)(()=>{e&&(he(h),S(null),C(null),T(null),D(!1),k(null),j(null))},[e,h,n.id]);let M=h===null,N=M,P=h??me,{data:_e=[],isLoading:ve}=o({queryKey:[`printers`],queryFn:()=>r.getPrinters(),enabled:e&&M}),ye=(0,d.useMemo)(()=>_e.filter(e=>e.is_active!==!1),[_e]);(0,d.useEffect)(()=>{if(!e)return;let t=document.body.style.overflow,n=document.activeElement instanceof HTMLElement?document.activeElement:null;document.body.style.overflow=`hidden`;let r=b.current;return((r?de(r)[0]:null)??r)?.focus(),()=>{document.body.style.overflow=t,n?.isConnected&&n.focus()}},[e]);let F=(0,d.useCallback)(e=>{if(E)return;if(e.key===`Escape`){e.preventDefault(),t();return}if(e.key!==`Tab`)return;let n=b.current;if(!n)return;let r=de(n);if(r.length===0){e.preventDefault(),n.focus();return}let i=r[0],a=r[r.length-1],o=document.activeElement;e.shiftKey&&(o===i||!n.contains(o))?(e.preventDefault(),a.focus()):!e.shiftKey&&(o===a||!n.contains(o))&&(e.preventDefault(),i.focus())},[t,E]);(0,d.useEffect)(()=>{if(e)return document.addEventListener(`keydown`,F),()=>document.removeEventListener(`keydown`,F)},[e,F]);let{data:I,isLoading:be}=o({queryKey:[`printerStatus`,P],queryFn:()=>r.getPrinterStatus(P),enabled:e&&P!==null,refetchInterval:5e3}),{data:xe}=o({queryKey:[`printer`,P],queryFn:()=>r.getPrinter(P),enabled:e&&P!==null}),{data:L}=o({queryKey:[`settings`],queryFn:()=>r.getSettings(),enabled:e,staleTime:300*1e3}),{data:R}=o({queryKey:[`spool-assignments`,P],queryFn:()=>r.getAssignments(P),enabled:e&&P!==null,staleTime:30*1e3}),{data:Se=[]}=o({queryKey:[`spoolman-slot-assignments`,P],queryFn:()=>r.getSpoolmanSlotAssignments(P??void 0),enabled:e&&!!_&&P!==null,staleTime:30*1e3}),z=_?Se.find(e=>e.spoolman_spool_id===n.id):void 0,B=(0,d.useMemo)(()=>{let e={};if(!R)return e;for(let t of R){let n=t.spool;if(n&&n.label_weight>0&&n.weight_used!=null){let r=Math.round(Math.max(0,n.label_weight-n.weight_used)/n.label_weight*100);e[`${t.ams_id}-${t.tray_id}`]=r}}return e},[R]),Ce=L?{humidityGood:Number(L.ams_humidity_good)||40,humidityFair:Number(L.ams_humidity_fair)||60,tempGood:Number(L.ams_temp_good)||28,tempFair:Number(L.ams_temp_fair)||35}:void 0,we=I?.connected??!1,V=(0,d.useMemo)(()=>I?.ams??[],[I?.ams]),Te=(0,d.useMemo)(()=>V.filter(e=>!e.is_ams_ht),[V]),H=(0,d.useMemo)(()=>V.filter(e=>e.is_ams_ht),[V]),U=(0,d.useMemo)(()=>[...I?.vt_tray??[]].sort((e,t)=>(e.id??254)-(t.id??254)),[I?.vt_tray]),W=xe?.nozzle_count===2||I?.temperatures?.nozzle_2!==void 0,G=(0,d.useRef)({});(0,d.useEffect)(()=>{G.current={}},[P]),(0,d.useEffect)(()=>{I?.ams_extruder_map&&Object.keys(I.ams_extruder_map).length>0&&(G.current=I.ams_extruder_map)},[I?.ams_extruder_map]);let Ee=I?.ams_extruder_map&&Object.keys(I.ams_extruder_map).length>0?I.ams_extruder_map:G.current,K=I?.fila_switch?.installed===!0,q=(0,d.useCallback)(e=>{if(!W)return null;let t=Ee[String(e)];return t===void 0?K?null:(e>=128?e-128:e)===1?`L`:`R`:t===1?`L`:`R`},[W,Ee,K]),J=s({mutationFn:async({amsId:e,trayId:t})=>{if(!P)throw Error(`No printer selected`);return _?await r.assignSpoolmanSlot({spoolman_spool_id:n.id,printer_id:P,ams_id:e,tray_id:t}):await r.assignSpool({spool_id:n.id,printer_id:P,ams_id:e,tray_id:t})},onSuccess:e=>{T(`success`);let n=e&&`pending_config`in e&&e.pending_config;C(n?v(`spoolbuddy.modal.assignPendingInsert`,`Assigned. Slot will configure when you insert the spool.`):v(`spoolbuddy.modal.assignSuccess`,`Assigned!`)),y.invalidateQueries({queryKey:[`slotPresets`]}),y.invalidateQueries({queryKey:[`spool-assignments`]}),y.invalidateQueries({queryKey:[`spoolman-slot-assignments`]}),y.invalidateQueries({queryKey:[`spoolman-slot-assignments-all`]}),y.invalidateQueries({queryKey:[`inventory-spools`]}),y.invalidateQueries({queryKey:[`spoolman-inventory-spools`]}),setTimeout(()=>t(),n?2500:1500)},onError:e=>{T(`error`),C(e instanceof Error?e.message:v(`spoolbuddy.modal.assignError`,`Failed to assign spool.`))}}),Y=J.isPending,De=(0,d.useCallback)((e,t)=>{if(e===254||e===255){let n=e===254?254:254+t;return U.find(e=>(e.id??254)===n)||null}return V.find(t=>t.id===e)?.tray?.find(e=>e.id===t)||null},[V,U]),X=(0,d.useCallback)((e,t)=>e<=3?`${p(e)} ${v(`ams.slot`,`Slot`)} ${t+1}`:e>=128&&e<=135?p(e):W?e===254||e===255&&t===0?v(`printers.extL`,`Ext-L`):v(`printers.extR`,`Ext-R`):v(`printers.ext`,`Ext`),[v,W]),Z=(0,d.useCallback)((e,t)=>{T(`info`),C(v(`spoolbuddy.modal.assigning`,`Configuring slot...`)),J.mutate({amsId:e,trayId:t})},[J,v]),Q=(0,d.useCallback)((e,t)=>{if(!Y){if(!L?.disable_filament_warnings){let r=De(e,t);if(r&&!m(r)){let i=r.tray_sub_brands||r.tray_type||``,a=fe(n.material,i),o=n.slicer_filament_name||n.slicer_filament,s=r.tray_type||``,c=pe(o,s);if(a!==`exact`){let r;r=a===`none`&&!c?`material_profile`:a===`partial`&&!c?`partial_profile`:a===`none`?`material`:`partial`;let l=X(e,t);j({amsId:e,trayId:t}),k({type:r,spoolMaterial:n.material||``,trayMaterial:i||``,spoolProfile:o||void 0,trayProfile:s||void 0,location:l}),D(!0);return}}}Z(e,t)}},[Y,L?.disable_filament_warnings,n,De,X,Z]),Oe=(0,d.useCallback)((e,t)=>{if(!Y){if(N){S({amsId:e,trayId:t}),C(null),T(null);return}Q(e,t)}},[N,Y,Q]),ke=(0,d.useCallback)(()=>{x&&Q(x.amsId,x.trayId)},[Q,x]),Ae=(0,d.useCallback)(()=>{A&&(D(!1),k(null),Z(A.amsId,A.trayId),j(null))},[A,Z]),je=(0,d.useMemo)(()=>{let e=[];for(let t of H){let n=t.tray?.[0]||{id:0,tray_color:null,tray_type:``,tray_sub_brands:null,tray_id_name:null,tray_info_idx:null,remain:-1,k:null,cali_idx:null,tag_uid:null,tray_uuid:null,nozzle_temp_min:null,nozzle_temp_max:null},r=B[`${t.id}-0`]??null,i=n.remain!=null&&n.remain>=0?n.remain:null,a=r===0&&i!==null&&i>0?null:r;e.push({key:`ht-${t.id}`,label:p(t.id),amsId:t.id,trayId:0,tray:n,isEmpty:m(n),nozzleSide:q(t.id),effectiveFill:a??i})}for(let t of U){let n=t.id??254,r=n-254,i=B[`255-${r}`]??null,a=t.remain!=null&&t.remain>=0?t.remain:null,o=i===0&&a!==null&&a>0?null:i;e.push({key:`ext-${n}`,label:W?n===254?v(`printers.extL`,`Ext-L`):v(`printers.extR`,`Ext-R`):v(`printers.ext`,`Ext`),amsId:255,trayId:r,tray:t,isEmpty:m(t),nozzleSide:W?n===254?`L`:`R`:null,effectiveFill:o??a})}return e},[H,U,W,v,q,B]);if(!e)return null;let Me=le(n)??oe(n.rgba),Ne=x?X(x.amsId,x.trayId):null,$=g===`dialog`;return(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(`div`,{className:$?`fixed inset-0 z-[60] flex items-center justify-center bg-black/45 dark:bg-black/70 p-2 sm:p-4 backdrop-blur-sm animate-fade-in`:`fixed inset-0 z-[60] bg-bambu-dark`,onClick:$&&!Y?t:void 0,children:(0,f.jsxs)(`div`,{ref:b,role:`dialog`,"aria-modal":`true`,"aria-labelledby":`assign-to-ams-title`,tabIndex:-1,className:$?`bg-bambu-dark-secondary text-white font-sans w-full max-w-3xl h-[calc(100vh-1rem)] sm:h-[calc(100vh-2rem)] max-h-[820px] border border-[var(--border-color)] rounded-xl sm:rounded-2xl shadow-2xl flex flex-col overflow-hidden animate-slide-up`:`w-full h-full bg-bambu-dark flex flex-col`,onClick:e=>e.stopPropagation(),children:[(0,f.jsxs)(`div`,{className:`flex items-center justify-between bg-bambu-dark-secondary px-5 py-3 border-b border-[var(--border-color)] shrink-0`,children:[(0,f.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0`,children:[(0,f.jsx)(`div`,{className:`w-7 h-7 rounded-full shrink-0`,style:Me}),(0,f.jsx)(`div`,{className:`min-w-0`,children:(0,f.jsxs)(`h2`,{id:`assign-to-ams-title`,className:`text-sm font-semibold text-white truncate`,children:[v(`spoolbuddy.modal.assignToAmsTitle`,`Assign to AMS`),(0,f.jsxs)(`span`,{className:`font-normal text-bambu-gray-light ml-2`,children:[ae(n.color_name,n.rgba,n.color_name_is_synthesized)||v(`spoolbuddy.spool.unknownColor`),` • `,n.brand,` `,n.material,n.subtype&&` ${n.subtype}`]}),(0,f.jsxs)(`span`,{className:`text-[10px] font-mono text-bambu-gray ml-2 shrink-0`,children:[`#`,n.id]})]})})]}),(0,f.jsx)(`button`,{onClick:t,disabled:Y,"aria-label":v(`common.close`,`Close`),className:`p-2 rounded-lg text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary transition-colors shrink-0 disabled:opacity-50`,children:(0,f.jsx)(te,{className:`w-5 h-5`})})]}),M&&(0,f.jsxs)(`div`,{className:`bg-bambu-dark-secondary px-5 py-3 border-b border-[var(--border-color)] shrink-0`,children:[(0,f.jsxs)(`label`,{htmlFor:`assign-spool-printer`,className:`flex items-center gap-2 text-sm font-medium text-white mb-2`,children:[(0,f.jsx)(`span`,{className:`inline-flex h-5 w-5 items-center justify-center rounded-full bg-bambu-green text-[11px] font-bold text-[#ffffff]`,children:`1`}),v(`printModal.selectPrinter`)]}),(0,f.jsxs)(`select`,{id:`assign-spool-printer`,"aria-label":v(`printModal.selectPrinter`),value:me??``,onChange:e=>{he(e.target.value?Number(e.target.value):null),S(null),C(null),T(null)},disabled:Y||ve,className:`w-full bg-bambu-dark border border-[var(--border-color)] rounded-lg px-3 py-2.5 text-sm text-white focus:outline-none focus:border-bambu-green disabled:opacity-50`,children:[(0,f.jsx)(`option`,{value:``,children:ve?v(`common.loading`):ye.length===0?v(`common.noPrinters`):v(`printModal.selectPrinter`)}),ye.map(e=>(0,f.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),ge&&(0,f.jsxs)(`div`,{className:`mx-5 mt-3 p-3 rounded-lg flex items-center gap-3 border shrink-0 ${w===`info`?`bg-blue-50 border-blue-300 dark:bg-blue-500/10 dark:border-blue-500/40`:w===`success`?`bg-green-50 border-green-300 dark:bg-green-500/10 dark:border-green-500/40`:`bg-red-50 border-red-300 dark:bg-red-500/10 dark:border-red-500/40`}`,children:[w===`info`&&(0,f.jsx)(u,{className:`w-4 h-4 text-blue-600 dark:text-blue-400 animate-spin shrink-0`}),w===`success`&&(0,f.jsx)(ee,{className:`w-4 h-4 text-green-600 dark:text-green-400 shrink-0`}),w===`error`&&(0,f.jsx)(l,{className:`w-4 h-4 text-red-600 dark:text-red-400 shrink-0`}),(0,f.jsx)(`span`,{className:`text-sm ${w===`info`?`text-blue-700 dark:text-blue-300`:w===`success`?`text-green-700 dark:text-green-300`:`text-red-700 dark:text-red-300`}`,children:ge})]}),(0,f.jsx)(`div`,{className:`flex-1 min-h-0 flex flex-col`,children:(0,f.jsxs)(`section`,{className:`flex min-h-[18rem] flex-col gap-3 bg-bambu-dark p-4 lg:min-h-0 lg:overflow-y-auto`,children:[M&&(0,f.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-medium text-white shrink-0`,children:[(0,f.jsx)(`span`,{className:`inline-flex h-5 w-5 items-center justify-center rounded-full bg-bambu-green text-[11px] font-bold text-[#ffffff]`,children:`2`}),v(`printModal.selectSlot`)]}),P?be?(0,f.jsxs)(`div`,{className:`flex flex-1 items-center justify-center text-bambu-gray-light`,children:[(0,f.jsx)(u,{className:`mr-2 h-5 w-5 animate-spin text-bambu-green`}),v(`common.loading`)]}):we?V.length===0&&U.length===0?(0,f.jsx)(`div`,{className:`flex flex-1 items-center justify-center rounded-xl border border-dashed border-[var(--border-color)] bg-bambu-dark-secondary p-8`,children:(0,f.jsxs)(`div`,{className:`text-center text-bambu-gray`,children:[(0,f.jsx)(ie,{className:`w-12 h-12 mx-auto mb-3 opacity-60`}),(0,f.jsx)(`p`,{className:`text-base text-bambu-gray-light mb-1`,children:v(`spoolbuddy.ams.noData`,`No AMS detected`)}),(0,f.jsx)(`p`,{className:`text-sm`,children:v(`spoolbuddy.ams.connectAms`,`Connect an AMS to see filament slots`)})]})}):(0,f.jsxs)(f.Fragment,{children:[Te.length>0&&(0,f.jsx)(`div`,{className:`grid grid-cols-1 xl:grid-cols-2 gap-3`,children:Te.map(e=>(0,f.jsx)(ce,{unit:e,activeSlot:x?.amsId===e.id?x.trayId:z?.ams_id===e.id?z.tray_id??null:null,onConfigureSlot:(t,n)=>Oe(e.id,n),isDualNozzle:W,nozzleSide:q(e.id),thresholds:Ce,fillOverrides:B},e.id))}),je.length>0&&(0,f.jsx)(`div`,{className:`flex flex-wrap gap-2 shrink-0`,children:je.map(({key:e,label:t,amsId:n,trayId:r,tray:i,isEmpty:a,nozzleSide:o,effectiveFill:s})=>{let c=ue(i.tray_color),l=x?x.amsId===n&&x.trayId===r:!!z&&z.ams_id===n&&z.tray_id===r;return(0,f.jsxs)(`button`,{type:`button`,"aria-pressed":l,title:X(n,r),onClick:()=>Oe(n,r),className:`bg-bambu-dark-secondary border rounded-lg px-3 py-2 hover:bg-bambu-dark-tertiary transition-all flex items-center gap-2 ${l?`ring-2 ring-bambu-green border-bambu-green bg-bambu-green/10`:`border-[var(--border-color)]`} ${Y?`opacity-50 pointer-events-none`:``}`,children:[(0,f.jsx)(`div`,{className:`relative w-10 h-10 shrink-0`,children:a?(0,f.jsx)(`div`,{className:`w-full h-full rounded-full border-2 border-dashed border-gray-500 flex items-center justify-center`,children:(0,f.jsx)(`div`,{className:`w-1.5 h-1.5 rounded-full bg-gray-600`})}):(0,f.jsxs)(`svg`,{viewBox:`0 0 56 56`,className:`w-full h-full`,children:[(0,f.jsx)(`circle`,{cx:`28`,cy:`28`,r:`26`,fill:c}),(0,f.jsx)(`circle`,{cx:`28`,cy:`28`,r:`20`,fill:c,style:{filter:`brightness(0.85)`}}),(0,f.jsx)(`ellipse`,{cx:`20`,cy:`20`,rx:`6`,ry:`4`,fill:`white`,opacity:`0.3`}),(0,f.jsx)(`circle`,{cx:`28`,cy:`28`,r:`8`,fill:`#2d2d2d`}),(0,f.jsx)(`circle`,{cx:`28`,cy:`28`,r:`5`,fill:`#1a1a1a`})]})}),(0,f.jsxs)(`div`,{className:`min-w-0 text-left`,children:[(0,f.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,f.jsx)(`span`,{className:`text-xs text-bambu-gray font-medium`,children:t}),o&&(0,f.jsx)(se,{side:o})]}),(0,f.jsx)(`div`,{className:`text-sm text-white truncate`,children:a?v(`ams.empty`):i.tray_type||`?`})]}),!a&&s!=null&&s>=0&&(0,f.jsx)(`div`,{className:`w-1.5 h-8 bg-bambu-dark-tertiary rounded-full overflow-hidden shrink-0 flex flex-col-reverse`,children:(0,f.jsx)(`div`,{className:`w-full rounded-full`,style:{height:`${s}%`,backgroundColor:ne(s)}})})]},e)})})]}):(0,f.jsx)(`div`,{className:`flex flex-1 items-center justify-center rounded-xl border border-red-300 bg-red-50 p-8 dark:border-red-500/30 dark:bg-red-500/5`,children:(0,f.jsx)(`p`,{className:`text-base text-red-700 dark:text-red-300`,children:v(`spoolbuddy.ams.printerDisconnected`,`Printer disconnected`)})}):(0,f.jsx)(`div`,{className:`flex flex-1 items-center justify-center rounded-xl border border-dashed border-[var(--border-color)] bg-bambu-dark-secondary p-8`,children:(0,f.jsxs)(`div`,{className:`text-center text-bambu-gray`,children:[(0,f.jsx)(ie,{className:`w-12 h-12 mx-auto mb-3 opacity-60`}),(0,f.jsx)(`p`,{className:`text-base text-bambu-gray-light`,children:v(`printModal.selectPrinter`)})]})})]})}),(0,f.jsxs)(`div`,{className:`flex items-center gap-3 bg-bambu-dark-secondary px-5 py-3 border-t border-[var(--border-color)] shrink-0`,children:[N&&(0,f.jsxs)(`div`,{className:`min-w-0 flex-1 text-sm`,children:[(0,f.jsxs)(`span`,{className:`text-bambu-gray`,children:[v(`printModal.selectSlot`),`: `]}),(0,f.jsx)(`span`,{className:Ne?`font-medium text-white`:`text-bambu-gray`,children:Ne||`—`})]}),(0,f.jsx)(`button`,{onClick:t,disabled:Y,className:`px-5 py-2.5 rounded-lg border border-[var(--border-color)] text-sm font-medium bg-bambu-dark-tertiary text-white hover:bg-bambu-dark transition-colors min-h-[44px] disabled:opacity-50`,children:v(w===`success`?`common.close`:`common.cancel`)}),N&&(0,f.jsxs)(`button`,{type:`button`,onClick:ke,disabled:!P||!x||Y||w===`success`,className:`inline-flex min-h-[44px] items-center gap-2 rounded-lg bg-bambu-green px-5 py-2.5 text-sm font-semibold text-[#ffffff] transition-colors hover:bg-bambu-green-dark disabled:cursor-not-allowed disabled:opacity-40`,children:[Y?(0,f.jsx)(u,{className:`h-4 w-4 animate-spin`}):(0,f.jsx)(c,{className:`h-4 w-4`}),v(`inventory.assignSpool`)]})]})]})}),E&&O&&(()=>{let e=``;return O.type===`material`?e=v(`inventory.assignMismatchMessage`,{spoolMaterial:O.spoolMaterial,trayMaterial:O.trayMaterial,location:O.location}):O.type===`partial`?e=v(`inventory.assignPartialMismatchMessage`,{spoolMaterial:O.spoolMaterial,trayMaterial:O.trayMaterial,location:O.location}):O.type===`material_profile`?e=`${v(`inventory.assignMismatchMessage`,{spoolMaterial:O.spoolMaterial,trayMaterial:O.trayMaterial,location:O.location})}\n\n${v(`inventory.assignProfileMismatchMessage`,{spoolProfile:O.spoolProfile||v(`common.unknown`),trayProfile:O.trayProfile||v(`common.unknown`),location:O.location})}`:O.type===`partial_profile`&&(e=`${v(`inventory.assignPartialMismatchMessage`,{spoolMaterial:O.spoolMaterial,trayMaterial:O.trayMaterial,location:O.location})}\n\n${v(`inventory.assignProfileMismatchMessage`,{spoolProfile:O.spoolProfile||v(`common.unknown`),trayProfile:O.trayProfile||v(`common.unknown`),location:O.location})}`),e=`${e}\n\n${v(`inventory.assignReconfigureNote`)}`,(0,f.jsx)(re,{title:v(`inventory.assignMismatchTitle`),message:e,confirmText:v(`inventory.assignMismatchConfirm`),variant:`warning`,overlayZIndex:`z-[70]`,isLoading:J.isPending,onConfirm:Ae,onCancel:()=>{J.isPending||(D(!1),j(null),k(null))}})})()]})}export{_ as t}; \ No newline at end of file diff --git a/static/assets/CamWallPage-B93EYwGu.js b/static/assets/CamWallPage-BDGEzKQE.js similarity index 92% rename from static/assets/CamWallPage-B93EYwGu.js rename to static/assets/CamWallPage-BDGEzKQE.js index 89621fc08..0954f0298 100644 --- a/static/assets/CamWallPage-B93EYwGu.js +++ b/static/assets/CamWallPage-BDGEzKQE.js @@ -1 +1 @@ -import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,g as i,w as a}from"./client-DnySrlFv.js";import{t as o}from"./useQuery-BBCjCezC.js";import{a as s,t as c}from"./CameraWall-Cv6o1Fp5.js";import{Bn as l,Wn as u,yt as d,zn as f}from"./index-0t--Yqoi.js";var p=e(n(),1),m=t(),h=5e3,g=4,_=8,v=1,y=16,b=2,x=60;function S(e,t,n,r){let i=parseInt(e??``,10);return Number.isFinite(i)?Math.min(r,Math.max(n,i)):t}function C(e,t,n,r,i,a){return e.has(t)?S(e.get(t),r,i,a):S(localStorage.getItem(n),r,i,a)}function w(e){let t=e.get(`size`)?.toLowerCase(),n=s.indexOf(t);if(n>=0)return n+1;let r=parseInt(localStorage.getItem(`camWallTileSize`)??``,10);return r>=1&&r<=4?r:2}function T(){let{t:e}=a(),t=l(),{authEnabled:n,loading:s,user:S}=d(),[T]=u(),E=T.get(`token`),D=E!=null&&E!==``,[O,k]=(0,p.useState)(()=>C(T,`maxLive`,`camWallMaxLive`,g,v,y)),[A,j]=(0,p.useState)(()=>C(T,`interval`,`camWallSnapshotSec`,_,b,x)),[M]=(0,p.useState)(()=>w(T)),[N,P]=(0,p.useState)(()=>{let e=T.get(`status`)??localStorage.getItem(`camWallStatusMode`);return(D?[`off`,`compact`]:[`off`,`compact`,`full`]).includes(e)?e:`compact`});(0,p.useEffect)(()=>{if(D)return i(E),()=>i(null)},[D,E]);let F=o({queryKey:[`camwall-printers`,E],queryFn:()=>r.getCamWallPrinters(E??void 0),enabled:D,refetchInterval:h}),I=o({queryKey:[`printers`],queryFn:()=>r.getPrinters(),enabled:!D&&!s&&(!n||S!==null),refetchInterval:h}),L=(0,p.useMemo)(()=>{let e=new Map;for(let t of F.data??[])e.set(t.id,{connected:t.connected,state:t.state,progress:t.progress,remaining_time:t.remaining_time,layer_num:t.layer_num,total_layers:t.total_layers,hms_errors:t.hms_errors});return e},[F.data]);if(!D&&s)return(0,m.jsx)(`div`,{className:`flex min-h-screen items-center justify-center bg-bambu-dark text-bambu-gray`,children:e(`common.loading`)});if(!D&&n&&!S)return(0,m.jsx)(f,{to:`/login`,replace:!0,state:{from:t}});let R=D?F:I,z=D?F.data??[]:I.data??[];return R.isError?(0,m.jsx)(`div`,{className:`flex min-h-screen items-center justify-center bg-bambu-dark p-6 text-center`,children:(0,m.jsx)(`p`,{className:`max-w-md text-sm text-red-400`,children:e(D?`printers.camWall.page.tokenRejected`:`printers.camWall.page.loadFailed`)})}):(0,m.jsx)(`div`,{className:`min-h-screen bg-bambu-dark p-4`,children:(0,m.jsx)(c,{printers:z,maxLive:O,snapshotIntervalSec:A,statusMode:N,tileSize:M,statuses:D?L:void 0,showSettings:!D,onTileClick:D?void 0:e=>window.open(`/camera/${e}`,`camera-${e}`),onChangeMaxLive:e=>{k(e),localStorage.setItem(`camWallMaxLive`,String(e))},onChangeSnapshotIntervalSec:e=>{j(e),localStorage.setItem(`camWallSnapshotSec`,String(e))},onChangeStatusMode:e=>{P(e),localStorage.setItem(`camWallStatusMode`,e)}})})}export{T as CamWallPage,T as default}; \ No newline at end of file +import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,g as i,w as a}from"./client-DnySrlFv.js";import{t as o}from"./useQuery-BBCjCezC.js";import{a as s,t as c}from"./CameraWall-D-W28jK-.js";import{Bn as l,Wn as u,yt as d,zn as f}from"./index-Cxa-KVmA.js";var p=e(n(),1),m=t(),h=5e3,g=4,_=8,v=1,y=16,b=2,x=60;function S(e,t,n,r){let i=parseInt(e??``,10);return Number.isFinite(i)?Math.min(r,Math.max(n,i)):t}function C(e,t,n,r,i,a){return e.has(t)?S(e.get(t),r,i,a):S(localStorage.getItem(n),r,i,a)}function w(e){let t=e.get(`size`)?.toLowerCase(),n=s.indexOf(t);if(n>=0)return n+1;let r=parseInt(localStorage.getItem(`camWallTileSize`)??``,10);return r>=1&&r<=4?r:2}function T(){let{t:e}=a(),t=l(),{authEnabled:n,loading:s,user:S}=d(),[T]=u(),E=T.get(`token`),D=E!=null&&E!==``,[O,k]=(0,p.useState)(()=>C(T,`maxLive`,`camWallMaxLive`,g,v,y)),[A,j]=(0,p.useState)(()=>C(T,`interval`,`camWallSnapshotSec`,_,b,x)),[M]=(0,p.useState)(()=>w(T)),[N,P]=(0,p.useState)(()=>{let e=T.get(`status`)??localStorage.getItem(`camWallStatusMode`);return(D?[`off`,`compact`]:[`off`,`compact`,`full`]).includes(e)?e:`compact`});(0,p.useEffect)(()=>{if(D)return i(E),()=>i(null)},[D,E]);let F=o({queryKey:[`camwall-printers`,E],queryFn:()=>r.getCamWallPrinters(E??void 0),enabled:D,refetchInterval:h}),I=o({queryKey:[`printers`],queryFn:()=>r.getPrinters(),enabled:!D&&!s&&(!n||S!==null),refetchInterval:h}),L=(0,p.useMemo)(()=>{let e=new Map;for(let t of F.data??[])e.set(t.id,{connected:t.connected,state:t.state,progress:t.progress,remaining_time:t.remaining_time,layer_num:t.layer_num,total_layers:t.total_layers,hms_errors:t.hms_errors});return e},[F.data]);if(!D&&s)return(0,m.jsx)(`div`,{className:`flex min-h-screen items-center justify-center bg-bambu-dark text-bambu-gray`,children:e(`common.loading`)});if(!D&&n&&!S)return(0,m.jsx)(f,{to:`/login`,replace:!0,state:{from:t}});let R=D?F:I,z=D?F.data??[]:I.data??[];return R.isError?(0,m.jsx)(`div`,{className:`flex min-h-screen items-center justify-center bg-bambu-dark p-6 text-center`,children:(0,m.jsx)(`p`,{className:`max-w-md text-sm text-red-400`,children:e(D?`printers.camWall.page.tokenRejected`:`printers.camWall.page.loadFailed`)})}):(0,m.jsx)(`div`,{className:`min-h-screen bg-bambu-dark p-4`,children:(0,m.jsx)(c,{printers:z,maxLive:O,snapshotIntervalSec:A,statusMode:N,tileSize:M,statuses:D?L:void 0,showSettings:!D,onTileClick:D?void 0:e=>window.open(`/camera/${e}`,`camera-${e}`),onChangeMaxLive:e=>{k(e),localStorage.setItem(`camWallMaxLive`,String(e))},onChangeSnapshotIntervalSec:e=>{j(e),localStorage.setItem(`camWallSnapshotSec`,String(e))},onChangeStatusMode:e=>{P(e),localStorage.setItem(`camWallStatusMode`,e)}})})}export{T as CamWallPage,T as default}; \ No newline at end of file diff --git a/static/assets/CameraDiagnoseModal-38LtfiVu.js b/static/assets/CameraDiagnoseModal-BwHHipUP.js similarity index 99% rename from static/assets/CameraDiagnoseModal-38LtfiVu.js rename to static/assets/CameraDiagnoseModal-BwHHipUP.js index 2b628f419..d03b07792 100644 --- a/static/assets/CameraDiagnoseModal-38LtfiVu.js +++ b/static/assets/CameraDiagnoseModal-BwHHipUP.js @@ -1 +1 @@ -import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,w as i,x as a}from"./client-DnySrlFv.js";import{t as o}from"./useQuery-BBCjCezC.js";import{t as s}from"./useMutation-B-Tr2hIP.js";import{t as c}from"./createLucideIcon-DvBYJlWL.js";import{t as l}from"./box-DAdKb9s5.js";import{n as u,r as d}from"./info-ROUoQhJR.js";import{n as f}from"./ToastContext-BRX0SW3C.js";import{t as p}from"./loader-circle-BEmFtawu.js";import{t as m}from"./maximize-2-kPQ77q72.js";import{t as h}from"./x-DR-Trv6U.js";import{An as g,Ft as _,Lt as v,Rt as y,_t as b,kn as x,yt as S}from"./index-0t--Yqoi.js";var C=c(`minimize`,[[`path`,{d:`M8 3v3a2 2 0 0 1-2 2H3`,key:`hohbtr`}],[`path`,{d:`M21 8h-3a2 2 0 0 1-2-2V3`,key:`5jw1f3`}],[`path`,{d:`M3 16h3a2 2 0 0 1 2 2v3`,key:`198tvr`}],[`path`,{d:`M16 21v-3a2 2 0 0 1 2-2h3`,key:`ph8mxp`}]]),w=t();function T({on:e,className:t=`w-5 h-5`}){let n=e?`#facc15`:`none`,r=e?`#78350f`:`currentColor`;return(0,w.jsxs)(`svg`,{viewBox:`0 0 32 32`,fill:`none`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,className:t,children:[(0,w.jsxs)(`g`,{stroke:r,opacity:+!!e,children:[(0,w.jsx)(`line`,{x1:`16`,y1:`2`,x2:`16`,y2:`6`}),(0,w.jsx)(`line`,{x1:`6.1`,y1:`6.1`,x2:`8.9`,y2:`8.9`}),(0,w.jsx)(`line`,{x1:`25.9`,y1:`6.1`,x2:`23.1`,y2:`8.9`}),(0,w.jsx)(`line`,{x1:`2`,y1:`16`,x2:`6`,y2:`16`}),(0,w.jsx)(`line`,{x1:`30`,y1:`16`,x2:`26`,y2:`16`})]}),(0,w.jsx)(`path`,{d:`M12 24v-2.3c0-.9-.4-1.7-1-2.3C9.2 17.6 8 15.4 8 13c0-4.4 3.6-8 8-8s8 3.6 8 8c0 2.4-1.2 4.6-3 6.4-.6.6-1 1.4-1 2.3V24`,fill:n,stroke:r}),(0,w.jsx)(`path`,{d:`M12 24h8`,stroke:r}),(0,w.jsx)(`path`,{d:`M12 27h8`,stroke:r}),(0,w.jsx)(`path`,{d:`M13 30h6`,stroke:r})]})}var E=e(n(),1);function D(e,t,n){let r=Math.max(0,Math.min(e.width-1,Math.floor(t))),i=(Math.max(0,Math.min(e.height-1,Math.floor(n)))*e.width+r)*4,a=e.data[i],o=e.data[i+1],s=e.data[i+2];return!e.data[i+3]||a===0&&o===0&&s===0?null:a+(o<<8)+(s<<16)}function O(e,t,n,r,i){let a=Math.min(e.width/t,e.height/n);if(!(a>0))return null;let o=(r-e.left-(e.width-t*a)/2)/a,s=(i-e.top-(e.height-n*a)/2)/a;return o<0||s<0||o>=t||s>=n?null:{x:o,y:s}}var k=({className:e})=>(0,w.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,className:e,children:[(0,w.jsx)(`rect`,{x:`2`,y:`15`,width:`5`,height:`5`,rx:`0.5`}),(0,w.jsx)(`rect`,{x:`9.5`,y:`15`,width:`5`,height:`5`,rx:`0.5`,fill:`currentColor`,opacity:`0.3`}),(0,w.jsx)(`rect`,{x:`17`,y:`15`,width:`5`,height:`5`,rx:`0.5`}),(0,w.jsx)(`path`,{d:`M4 12 C4 6, 14 6, 14 12`}),(0,w.jsx)(`polyline`,{points:`12,10 14,12 12,14`})]});function A({printerId:e,isOpen:t,onClose:n}){let{t:c}=i(),{showToast:u}=f(),{hasPermission:g}=S(),[_,x]=(0,E.useState)(new Set),[C,T]=(0,E.useState)(!1),[A,j]=(0,E.useState)(!1),[M,N]=(0,E.useState)(!1),P=(0,E.useRef)(null),F=(0,E.useRef)(null),I=(0,E.useRef)(null),{data:L}=o({queryKey:[`printerStatus`,e],queryFn:()=>r.getPrinterStatus(e),refetchInterval:3e4,enabled:t}),{data:R,refetch:z}=o({queryKey:[`printableObjects`,e],queryFn:()=>r.getPrintableObjects(e),enabled:t,refetchInterval:t?5e3:!1}),B=(R?.objects.length??0)>0,V=B&&L?.cover_url?a(`${L.cover_url}?view=top`):null,H=B&&L?.cover_url?a(`${L.cover_url}?view=pick`):null,U=(0,E.useMemo)(()=>(R?.objects??[]).filter(e=>!e.skipped),[R]),W=(0,E.useMemo)(()=>U.filter(e=>_.has(e.id)),[U,_]),G=U.length>0&&W.length===U.length,K=G&&_.size>0,q=_.size>0&&(L?.layer_num??0)>1&&g(`printers:control`),J=s({mutationFn:t=>r.skipObjects(e,t),onSuccess:async e=>{u(e.message||c(`printers.skipObjects.objectsSkipped`)),await z(),T(!1),x(new Set),n()},onError:e=>{T(!1),u(e.message||c(`printers.toast.failedToSkipObjects`),`error`)}});(0,E.useEffect)(()=>{t||(x(new Set),T(!1),j(!1))},[t]),(0,E.useEffect)(()=>{if(P.current=null,N(!1),!t||!H)return;let e=!1,n=new Image;return n.onload=()=>{if(e)return;let t=document.createElement(`canvas`);t.width=n.naturalWidth||512,t.height=n.naturalHeight||512;let r=t.getContext(`2d`,{willReadFrequently:!0});r&&(r.drawImage(n,0,0),P.current=r.getImageData(0,0,t.width,t.height),N(!0))},n.onerror=()=>{e||N(!1)},n.src=H,()=>{e=!0}},[t,H]),(0,E.useEffect)(()=>{let e=P.current;if(!e||!R)return;let t=new Set(R.objects.filter(e=>e.skipped).map(e=>e.id));for(let n of[F.current,I.current]){if(!n)continue;n.width=e.width,n.height=e.height;let r=n.getContext(`2d`);if(!r)continue;let i=r.createImageData(e.width,e.height);for(let n=0;n{e.skipped||x(t=>{let n=new Set(t);return n.has(e.id)?n.delete(e.id):n.add(e.id),n})},X=e=>{let t=P.current;if(!t)return;let n=O(e.currentTarget.getBoundingClientRect(),t.width,t.height,e.clientX,e.clientY);if(!n)return;let r=D(t,n.x,n.y),i=R?.objects.find(e=>e.id===r);i&&Y(i)},Z=(e=!1)=>(0,w.jsxs)(`div`,{className:`relative aspect-square overflow-hidden rounded-lg border border-gray-300 bg-gray-900 dark:border-gray-600 ${M?`cursor-crosshair`:``}`,children:[V?(0,w.jsx)(`img`,{src:V,alt:c(`printers.printPreview`),className:`absolute inset-0 h-full w-full object-contain`}):(0,w.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center`,children:(0,w.jsx)(l,{className:`h-10 w-10 text-gray-500`})}),(0,w.jsx)(`canvas`,{ref:e?I:F,onClick:X,className:`absolute inset-0 h-full w-full object-contain`,"aria-label":c(`printers.skipObjects.selectObjectsToSkip`)}),!e&&V&&(0,w.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),j(!0)},className:`absolute right-2 top-2 rounded bg-black/65 p-1.5 text-white/80 hover:text-white`,title:c(`common.expand`),children:(0,w.jsx)(m,{className:`h-4 w-4`})}),!M&&V&&(0,w.jsx)(`div`,{className:`absolute bottom-2 left-2 rounded bg-black/70 px-2 py-1 text-[10px] text-white/80`,children:c(`common.unavailable`)})]});return t?(0,w.jsxs)(w.Fragment,{children:[(0,w.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center p-4`,onClick:n,onKeyDown:e=>{e.key===`Escape`&&(A?j(!1):n())},tabIndex:-1,ref:e=>e?.focus(),children:[(0,w.jsx)(`div`,{className:`absolute inset-0 bg-black/55`}),(0,w.jsxs)(`section`,{className:`relative z-10 flex max-h-[88vh] w-full max-w-[980px] flex-col overflow-hidden rounded-lg border border-gray-200 bg-white shadow-2xl dark:border-bambu-dark-tertiary dark:bg-bambu-dark`,onClick:e=>e.stopPropagation(),"aria-label":c(`printers.skipObjects.title`),children:[(0,w.jsxs)(`header`,{className:`flex items-center justify-between border-b border-gray-200 bg-gray-50 px-4 py-3 dark:border-bambu-dark-tertiary dark:bg-bambu-dark`,children:[(0,w.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,w.jsx)(k,{className:`h-5 w-5 text-bambu-green`}),(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`h2`,{className:`text-sm font-semibold text-gray-900 dark:text-white`,children:c(`printers.skipObjects.title`)}),(0,w.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-bambu-gray`,children:c(`printers.skipObjects.selectObjectsToSkip`)})]})]}),(0,w.jsx)(`button`,{type:`button`,onClick:n,className:`rounded p-1 text-gray-500 hover:text-gray-900 dark:text-bambu-gray dark:hover:text-white`,children:(0,w.jsx)(h,{className:`h-5 w-5`})})]}),R?R.objects.length===0?(0,w.jsxs)(`div`,{className:`px-4 py-12 text-center text-bambu-gray`,children:[(0,w.jsx)(`p`,{className:`text-sm`,children:c(`printers.noObjectsFound`)}),(0,w.jsx)(`p`,{className:`mt-1 text-xs opacity-70`,children:c(`printers.objectsLoadedOnPrintStart`)})]}):(0,w.jsxs)(w.Fragment,{children:[(L?.layer_num??0)<=1&&(0,w.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-amber-400/20 bg-amber-500/10 px-4 py-2 text-xs text-amber-400`,children:[(0,w.jsx)(d,{className:`h-4 w-4 flex-shrink-0`}),c(`printers.skipObjects.waitForLayer`,{layer:L?.layer_num??0})]}),(0,w.jsxs)(`div`,{className:`grid min-h-0 flex-1 grid-cols-[minmax(320px,1fr)_minmax(340px,0.9fr)] overflow-hidden max-md:grid-cols-1 max-md:overflow-y-auto`,children:[(0,w.jsxs)(`div`,{className:`border-r border-gray-200 bg-gray-50 p-4 dark:border-bambu-dark-tertiary dark:bg-bambu-dark-secondary max-md:border-b-0 max-md:border-r-0`,children:[Z(),(0,w.jsxs)(`div`,{className:`mt-3 flex items-center justify-between text-xs text-gray-500 dark:text-bambu-gray`,children:[(0,w.jsxs)(`span`,{children:[_.size,`/`,U.length]}),(0,w.jsxs)(`span`,{children:[R.skipped_count,` `,c(`printers.skipObjects.skipped`)]})]})]}),(0,w.jsxs)(`div`,{className:`flex min-h-0 flex-col`,children:[(0,w.jsxs)(`button`,{type:`button`,onClick:()=>x(G?new Set:new Set(U.map(e=>e.id))),className:`flex items-center gap-3 border-b border-gray-200 px-4 py-3 text-left text-sm font-semibold text-gray-900 hover:bg-gray-50 dark:border-bambu-dark-tertiary dark:text-white dark:hover:bg-white/5`,children:[G?(0,w.jsx)(y,{className:`h-5 w-5 text-bambu-green`}):(0,w.jsx)(v,{className:`h-5 w-5 text-bambu-gray`}),(0,w.jsx)(`span`,{className:`flex-1`,children:c(G?`common.deselectAll`:`common.selectAll`)}),(0,w.jsx)(`span`,{className:`text-xs font-normal text-bambu-gray`,children:U.length})]}),(0,w.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:R.objects.map((e,t)=>{let n=_.has(e.id);return(0,w.jsxs)(`button`,{type:`button`,onClick:()=>Y(e),disabled:e.skipped,className:`flex w-full items-center gap-3 border-b border-gray-200 px-4 py-2.5 text-left transition-colors dark:border-bambu-dark-tertiary/60 ${e.skipped?`cursor-not-allowed bg-red-500/5 opacity-55`:n?`bg-bambu-green/15 hover:bg-bambu-green/20`:`hover:bg-gray-50 dark:hover:bg-white/5`}`,children:[e.skipped||n?(0,w.jsx)(y,{className:`h-5 w-5 flex-shrink-0 ${e.skipped?`text-red-400`:`text-bambu-green`}`}):(0,w.jsx)(v,{className:`h-5 w-5 flex-shrink-0 text-bambu-gray`}),(0,w.jsx)(`span`,{className:`w-8 flex-shrink-0 text-xs font-bold text-bambu-gray`,children:t+1}),(0,w.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-sm ${e.skipped?`text-red-400 line-through`:`text-gray-900 dark:text-white`}`,children:e.name}),(0,w.jsxs)(`span`,{className:`text-[10px] text-bambu-gray`,children:[`ID `,e.id]})]},e.id)})})]})]}),(0,w.jsxs)(`footer`,{className:`flex items-center gap-3 border-t border-gray-200 bg-gray-50 px-4 py-3 dark:border-bambu-dark-tertiary dark:bg-bambu-dark`,children:[(0,w.jsx)(`span`,{className:`mr-auto text-sm text-gray-600 dark:text-bambu-gray`,children:_.size===0?c(`printers.skipObjects.noObjectsSelected`):`${_.size}/${U.length}`}),(0,w.jsx)(`button`,{type:`button`,onClick:n,className:`rounded-md border border-gray-300 px-4 py-2 text-sm text-gray-700 hover:bg-gray-100 dark:border-bambu-dark-tertiary dark:text-white dark:hover:bg-white/5`,children:c(`common.cancel`)}),(0,w.jsx)(`button`,{type:`button`,onClick:()=>T(!0),disabled:!q||J.isPending,className:`rounded-md bg-red-500 px-4 py-2 text-sm font-semibold text-white hover:bg-red-600 disabled:cursor-not-allowed disabled:opacity-35`,children:J.isPending?c(`printers.skipObjects.skipping`):c(`printers.skipObjects.skipSelected`)})]})]}):(0,w.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,w.jsx)(p,{className:`h-6 w-6 animate-spin text-bambu-gray`})})]})]}),C&&(0,w.jsx)(b,{variant:`warning`,title:c(`printers.skipObjects.confirmTitle`),message:K?c(`printers.skipObjects.confirmAllMessage`):W.length===1?c(`printers.skipObjects.confirmMessage`,{name:W[0].name}):c(`printers.skipObjects.confirmMultipleMessage`,{count:W.length}),confirmText:c(`printers.skipObjects.skipSelected`),isLoading:J.isPending,onConfirm:()=>J.mutate([..._]),onCancel:()=>T(!1)}),A&&(0,w.jsxs)(`div`,{className:`fixed inset-0 z-[60] flex items-center justify-center bg-black/90 p-8`,onClick:()=>j(!1),children:[(0,w.jsx)(`button`,{type:`button`,onClick:()=>j(!1),className:`absolute right-4 top-4 rounded p-2 text-white/70 hover:text-white`,children:(0,w.jsx)(h,{className:`h-6 w-6`})}),(0,w.jsx)(`div`,{className:`aspect-square max-h-[86vh] w-full max-w-[86vh]`,onClick:e=>e.stopPropagation(),children:Z(!0)})]})]}):null}function j({status:e}){return e===`ok`?(0,w.jsx)(g,{className:`w-5 h-5 text-bambu-green flex-shrink-0`}):e===`failed`?(0,w.jsx)(u,{className:`w-5 h-5 text-red-600 dark:text-red-400 flex-shrink-0`}):(0,w.jsx)(x,{className:`w-5 h-5 text-bambu-gray flex-shrink-0`})}function M({printerId:e,printerName:t,onClose:n}){let{t:a}=i(),o=s({mutationFn:()=>r.diagnoseCamera(e)});(0,E.useEffect)(()=>{o.mutate()},[]),(0,E.useEffect)(()=>{let e=e=>{e.key===`Escape`&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n]);let c=o.data;return(0,w.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:n,children:(0,w.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-lg flex flex-col`,onClick:e=>e.stopPropagation(),children:[(0,w.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,w.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,w.jsx)(_,{className:`w-5 h-5 text-bambu-green flex-shrink-0`}),(0,w.jsx)(`h2`,{className:`text-lg font-semibold text-white truncate`,children:a(`camera.diagnose.modalTitle`,{name:t||``})})]}),(0,w.jsx)(`button`,{onClick:n,className:`text-bambu-gray hover:text-white transition-colors`,title:a(`common.close`),children:(0,w.jsx)(h,{className:`w-5 h-5`})})]}),(0,w.jsxs)(`div`,{className:`p-6 space-y-4`,children:[o.isPending&&(0,w.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray`,children:[(0,w.jsx)(p,{className:`w-4 h-4 animate-spin`}),(0,w.jsx)(`span`,{children:a(`camera.diagnose.running`)})]}),o.isError&&(0,w.jsx)(`div`,{className:`rounded-lg bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30 px-4 py-3 text-sm text-red-700 dark:text-red-300`,children:a(`camera.diagnose.runFailed`,{error:o.error.message})}),c&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`ol`,{className:`space-y-2`,children:c.stages.map(e=>(0,w.jsxs)(`li`,{className:`flex items-center gap-3 bg-bambu-dark rounded-lg px-4 py-2.5`,children:[(0,w.jsx)(j,{status:e.status}),(0,w.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,w.jsx)(`div`,{className:`text-sm text-white`,children:a(`camera.diagnose.stage.${e.name}`)}),e.code&&(0,w.jsx)(`div`,{className:`text-xs text-bambu-gray font-mono`,children:e.code})]}),(0,w.jsxs)(`div`,{className:`text-xs text-bambu-gray tabular-nums flex-shrink-0`,children:[e.duration_ms,` ms`]})]},e.name))}),(0,w.jsx)(`div`,{className:c.overall_status===`ok`?`rounded-lg bg-bambu-green/10 border border-bambu-green/30 px-4 py-3 text-sm text-bambu-green`:`rounded-lg bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30 px-4 py-3 text-sm text-red-700 dark:text-red-300`,children:a(`camera.diagnose.summary.${c.summary_code}`,{defaultValue:a(`camera.diagnose.summary.unknown_failure`)})}),(0,w.jsx)(`div`,{className:`text-xs text-bambu-gray space-y-0.5`,children:(0,w.jsxs)(`div`,{children:[(0,w.jsxs)(`span`,{className:`text-bambu-gray/60`,children:[a(`camera.diagnose.meta.protocol`),`: `]}),(0,w.jsx)(`span`,{className:`font-mono`,children:c.protocol}),` • `,(0,w.jsxs)(`span`,{className:`text-bambu-gray/60`,children:[a(`camera.diagnose.meta.port`),`: `]}),(0,w.jsx)(`span`,{className:`font-mono`,children:c.port}),` • `,(0,w.jsxs)(`span`,{className:`text-bambu-gray/60`,children:[a(`camera.diagnose.meta.profile`),`: `]}),(0,w.jsx)(`span`,{className:`font-mono`,children:c.profile})]})})]})]}),(0,w.jsxs)(`div`,{className:`px-6 py-4 border-t border-bambu-dark-tertiary flex justify-end gap-2`,children:[(0,w.jsx)(`button`,{onClick:()=>o.mutate(),disabled:o.isPending,className:`px-4 py-2 bg-bambu-dark hover:bg-bambu-dark-tertiary disabled:opacity-50 text-white text-sm rounded-lg transition-colors`,children:a(`camera.diagnose.retry`)}),(0,w.jsx)(`button`,{onClick:n,className:`px-4 py-2 bg-bambu-green hover:bg-bambu-green/90 text-white text-sm rounded-lg transition-colors`,children:a(`common.close`)})]})]})})}export{C as a,T as i,k as n,A as r,M as t}; \ No newline at end of file +import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,w as i,x as a}from"./client-DnySrlFv.js";import{t as o}from"./useQuery-BBCjCezC.js";import{t as s}from"./useMutation-B-Tr2hIP.js";import{t as c}from"./createLucideIcon-DvBYJlWL.js";import{t as l}from"./box-DAdKb9s5.js";import{n as u,r as d}from"./info-ROUoQhJR.js";import{n as f}from"./ToastContext-BRX0SW3C.js";import{t as p}from"./loader-circle-BEmFtawu.js";import{t as m}from"./maximize-2-kPQ77q72.js";import{t as h}from"./x-DR-Trv6U.js";import{An as g,Ft as _,Lt as v,Rt as y,_t as b,kn as x,yt as S}from"./index-Cxa-KVmA.js";var C=c(`minimize`,[[`path`,{d:`M8 3v3a2 2 0 0 1-2 2H3`,key:`hohbtr`}],[`path`,{d:`M21 8h-3a2 2 0 0 1-2-2V3`,key:`5jw1f3`}],[`path`,{d:`M3 16h3a2 2 0 0 1 2 2v3`,key:`198tvr`}],[`path`,{d:`M16 21v-3a2 2 0 0 1 2-2h3`,key:`ph8mxp`}]]),w=t();function T({on:e,className:t=`w-5 h-5`}){let n=e?`#facc15`:`none`,r=e?`#78350f`:`currentColor`;return(0,w.jsxs)(`svg`,{viewBox:`0 0 32 32`,fill:`none`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,className:t,children:[(0,w.jsxs)(`g`,{stroke:r,opacity:+!!e,children:[(0,w.jsx)(`line`,{x1:`16`,y1:`2`,x2:`16`,y2:`6`}),(0,w.jsx)(`line`,{x1:`6.1`,y1:`6.1`,x2:`8.9`,y2:`8.9`}),(0,w.jsx)(`line`,{x1:`25.9`,y1:`6.1`,x2:`23.1`,y2:`8.9`}),(0,w.jsx)(`line`,{x1:`2`,y1:`16`,x2:`6`,y2:`16`}),(0,w.jsx)(`line`,{x1:`30`,y1:`16`,x2:`26`,y2:`16`})]}),(0,w.jsx)(`path`,{d:`M12 24v-2.3c0-.9-.4-1.7-1-2.3C9.2 17.6 8 15.4 8 13c0-4.4 3.6-8 8-8s8 3.6 8 8c0 2.4-1.2 4.6-3 6.4-.6.6-1 1.4-1 2.3V24`,fill:n,stroke:r}),(0,w.jsx)(`path`,{d:`M12 24h8`,stroke:r}),(0,w.jsx)(`path`,{d:`M12 27h8`,stroke:r}),(0,w.jsx)(`path`,{d:`M13 30h6`,stroke:r})]})}var E=e(n(),1);function D(e,t,n){let r=Math.max(0,Math.min(e.width-1,Math.floor(t))),i=(Math.max(0,Math.min(e.height-1,Math.floor(n)))*e.width+r)*4,a=e.data[i],o=e.data[i+1],s=e.data[i+2];return!e.data[i+3]||a===0&&o===0&&s===0?null:a+(o<<8)+(s<<16)}function O(e,t,n,r,i){let a=Math.min(e.width/t,e.height/n);if(!(a>0))return null;let o=(r-e.left-(e.width-t*a)/2)/a,s=(i-e.top-(e.height-n*a)/2)/a;return o<0||s<0||o>=t||s>=n?null:{x:o,y:s}}var k=({className:e})=>(0,w.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,className:e,children:[(0,w.jsx)(`rect`,{x:`2`,y:`15`,width:`5`,height:`5`,rx:`0.5`}),(0,w.jsx)(`rect`,{x:`9.5`,y:`15`,width:`5`,height:`5`,rx:`0.5`,fill:`currentColor`,opacity:`0.3`}),(0,w.jsx)(`rect`,{x:`17`,y:`15`,width:`5`,height:`5`,rx:`0.5`}),(0,w.jsx)(`path`,{d:`M4 12 C4 6, 14 6, 14 12`}),(0,w.jsx)(`polyline`,{points:`12,10 14,12 12,14`})]});function A({printerId:e,isOpen:t,onClose:n}){let{t:c}=i(),{showToast:u}=f(),{hasPermission:g}=S(),[_,x]=(0,E.useState)(new Set),[C,T]=(0,E.useState)(!1),[A,j]=(0,E.useState)(!1),[M,N]=(0,E.useState)(!1),P=(0,E.useRef)(null),F=(0,E.useRef)(null),I=(0,E.useRef)(null),{data:L}=o({queryKey:[`printerStatus`,e],queryFn:()=>r.getPrinterStatus(e),refetchInterval:3e4,enabled:t}),{data:R,refetch:z}=o({queryKey:[`printableObjects`,e],queryFn:()=>r.getPrintableObjects(e),enabled:t,refetchInterval:t?5e3:!1}),B=(R?.objects.length??0)>0,V=B&&L?.cover_url?a(`${L.cover_url}?view=top`):null,H=B&&L?.cover_url?a(`${L.cover_url}?view=pick`):null,U=(0,E.useMemo)(()=>(R?.objects??[]).filter(e=>!e.skipped),[R]),W=(0,E.useMemo)(()=>U.filter(e=>_.has(e.id)),[U,_]),G=U.length>0&&W.length===U.length,K=G&&_.size>0,q=_.size>0&&(L?.layer_num??0)>1&&g(`printers:control`),J=s({mutationFn:t=>r.skipObjects(e,t),onSuccess:async e=>{u(e.message||c(`printers.skipObjects.objectsSkipped`)),await z(),T(!1),x(new Set),n()},onError:e=>{T(!1),u(e.message||c(`printers.toast.failedToSkipObjects`),`error`)}});(0,E.useEffect)(()=>{t||(x(new Set),T(!1),j(!1))},[t]),(0,E.useEffect)(()=>{if(P.current=null,N(!1),!t||!H)return;let e=!1,n=new Image;return n.onload=()=>{if(e)return;let t=document.createElement(`canvas`);t.width=n.naturalWidth||512,t.height=n.naturalHeight||512;let r=t.getContext(`2d`,{willReadFrequently:!0});r&&(r.drawImage(n,0,0),P.current=r.getImageData(0,0,t.width,t.height),N(!0))},n.onerror=()=>{e||N(!1)},n.src=H,()=>{e=!0}},[t,H]),(0,E.useEffect)(()=>{let e=P.current;if(!e||!R)return;let t=new Set(R.objects.filter(e=>e.skipped).map(e=>e.id));for(let n of[F.current,I.current]){if(!n)continue;n.width=e.width,n.height=e.height;let r=n.getContext(`2d`);if(!r)continue;let i=r.createImageData(e.width,e.height);for(let n=0;n{e.skipped||x(t=>{let n=new Set(t);return n.has(e.id)?n.delete(e.id):n.add(e.id),n})},X=e=>{let t=P.current;if(!t)return;let n=O(e.currentTarget.getBoundingClientRect(),t.width,t.height,e.clientX,e.clientY);if(!n)return;let r=D(t,n.x,n.y),i=R?.objects.find(e=>e.id===r);i&&Y(i)},Z=(e=!1)=>(0,w.jsxs)(`div`,{className:`relative aspect-square overflow-hidden rounded-lg border border-gray-300 bg-gray-900 dark:border-gray-600 ${M?`cursor-crosshair`:``}`,children:[V?(0,w.jsx)(`img`,{src:V,alt:c(`printers.printPreview`),className:`absolute inset-0 h-full w-full object-contain`}):(0,w.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center`,children:(0,w.jsx)(l,{className:`h-10 w-10 text-gray-500`})}),(0,w.jsx)(`canvas`,{ref:e?I:F,onClick:X,className:`absolute inset-0 h-full w-full object-contain`,"aria-label":c(`printers.skipObjects.selectObjectsToSkip`)}),!e&&V&&(0,w.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),j(!0)},className:`absolute right-2 top-2 rounded bg-black/65 p-1.5 text-white/80 hover:text-white`,title:c(`common.expand`),children:(0,w.jsx)(m,{className:`h-4 w-4`})}),!M&&V&&(0,w.jsx)(`div`,{className:`absolute bottom-2 left-2 rounded bg-black/70 px-2 py-1 text-[10px] text-white/80`,children:c(`common.unavailable`)})]});return t?(0,w.jsxs)(w.Fragment,{children:[(0,w.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center p-4`,onClick:n,onKeyDown:e=>{e.key===`Escape`&&(A?j(!1):n())},tabIndex:-1,ref:e=>e?.focus(),children:[(0,w.jsx)(`div`,{className:`absolute inset-0 bg-black/55`}),(0,w.jsxs)(`section`,{className:`relative z-10 flex max-h-[88vh] w-full max-w-[980px] flex-col overflow-hidden rounded-lg border border-gray-200 bg-white shadow-2xl dark:border-bambu-dark-tertiary dark:bg-bambu-dark`,onClick:e=>e.stopPropagation(),"aria-label":c(`printers.skipObjects.title`),children:[(0,w.jsxs)(`header`,{className:`flex items-center justify-between border-b border-gray-200 bg-gray-50 px-4 py-3 dark:border-bambu-dark-tertiary dark:bg-bambu-dark`,children:[(0,w.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,w.jsx)(k,{className:`h-5 w-5 text-bambu-green`}),(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`h2`,{className:`text-sm font-semibold text-gray-900 dark:text-white`,children:c(`printers.skipObjects.title`)}),(0,w.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-bambu-gray`,children:c(`printers.skipObjects.selectObjectsToSkip`)})]})]}),(0,w.jsx)(`button`,{type:`button`,onClick:n,className:`rounded p-1 text-gray-500 hover:text-gray-900 dark:text-bambu-gray dark:hover:text-white`,children:(0,w.jsx)(h,{className:`h-5 w-5`})})]}),R?R.objects.length===0?(0,w.jsxs)(`div`,{className:`px-4 py-12 text-center text-bambu-gray`,children:[(0,w.jsx)(`p`,{className:`text-sm`,children:c(`printers.noObjectsFound`)}),(0,w.jsx)(`p`,{className:`mt-1 text-xs opacity-70`,children:c(`printers.objectsLoadedOnPrintStart`)})]}):(0,w.jsxs)(w.Fragment,{children:[(L?.layer_num??0)<=1&&(0,w.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-amber-400/20 bg-amber-500/10 px-4 py-2 text-xs text-amber-400`,children:[(0,w.jsx)(d,{className:`h-4 w-4 flex-shrink-0`}),c(`printers.skipObjects.waitForLayer`,{layer:L?.layer_num??0})]}),(0,w.jsxs)(`div`,{className:`grid min-h-0 flex-1 grid-cols-[minmax(320px,1fr)_minmax(340px,0.9fr)] overflow-hidden max-md:grid-cols-1 max-md:overflow-y-auto`,children:[(0,w.jsxs)(`div`,{className:`border-r border-gray-200 bg-gray-50 p-4 dark:border-bambu-dark-tertiary dark:bg-bambu-dark-secondary max-md:border-b-0 max-md:border-r-0`,children:[Z(),(0,w.jsxs)(`div`,{className:`mt-3 flex items-center justify-between text-xs text-gray-500 dark:text-bambu-gray`,children:[(0,w.jsxs)(`span`,{children:[_.size,`/`,U.length]}),(0,w.jsxs)(`span`,{children:[R.skipped_count,` `,c(`printers.skipObjects.skipped`)]})]})]}),(0,w.jsxs)(`div`,{className:`flex min-h-0 flex-col`,children:[(0,w.jsxs)(`button`,{type:`button`,onClick:()=>x(G?new Set:new Set(U.map(e=>e.id))),className:`flex items-center gap-3 border-b border-gray-200 px-4 py-3 text-left text-sm font-semibold text-gray-900 hover:bg-gray-50 dark:border-bambu-dark-tertiary dark:text-white dark:hover:bg-white/5`,children:[G?(0,w.jsx)(y,{className:`h-5 w-5 text-bambu-green`}):(0,w.jsx)(v,{className:`h-5 w-5 text-bambu-gray`}),(0,w.jsx)(`span`,{className:`flex-1`,children:c(G?`common.deselectAll`:`common.selectAll`)}),(0,w.jsx)(`span`,{className:`text-xs font-normal text-bambu-gray`,children:U.length})]}),(0,w.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:R.objects.map((e,t)=>{let n=_.has(e.id);return(0,w.jsxs)(`button`,{type:`button`,onClick:()=>Y(e),disabled:e.skipped,className:`flex w-full items-center gap-3 border-b border-gray-200 px-4 py-2.5 text-left transition-colors dark:border-bambu-dark-tertiary/60 ${e.skipped?`cursor-not-allowed bg-red-500/5 opacity-55`:n?`bg-bambu-green/15 hover:bg-bambu-green/20`:`hover:bg-gray-50 dark:hover:bg-white/5`}`,children:[e.skipped||n?(0,w.jsx)(y,{className:`h-5 w-5 flex-shrink-0 ${e.skipped?`text-red-400`:`text-bambu-green`}`}):(0,w.jsx)(v,{className:`h-5 w-5 flex-shrink-0 text-bambu-gray`}),(0,w.jsx)(`span`,{className:`w-8 flex-shrink-0 text-xs font-bold text-bambu-gray`,children:t+1}),(0,w.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-sm ${e.skipped?`text-red-400 line-through`:`text-gray-900 dark:text-white`}`,children:e.name}),(0,w.jsxs)(`span`,{className:`text-[10px] text-bambu-gray`,children:[`ID `,e.id]})]},e.id)})})]})]}),(0,w.jsxs)(`footer`,{className:`flex items-center gap-3 border-t border-gray-200 bg-gray-50 px-4 py-3 dark:border-bambu-dark-tertiary dark:bg-bambu-dark`,children:[(0,w.jsx)(`span`,{className:`mr-auto text-sm text-gray-600 dark:text-bambu-gray`,children:_.size===0?c(`printers.skipObjects.noObjectsSelected`):`${_.size}/${U.length}`}),(0,w.jsx)(`button`,{type:`button`,onClick:n,className:`rounded-md border border-gray-300 px-4 py-2 text-sm text-gray-700 hover:bg-gray-100 dark:border-bambu-dark-tertiary dark:text-white dark:hover:bg-white/5`,children:c(`common.cancel`)}),(0,w.jsx)(`button`,{type:`button`,onClick:()=>T(!0),disabled:!q||J.isPending,className:`rounded-md bg-red-500 px-4 py-2 text-sm font-semibold text-white hover:bg-red-600 disabled:cursor-not-allowed disabled:opacity-35`,children:J.isPending?c(`printers.skipObjects.skipping`):c(`printers.skipObjects.skipSelected`)})]})]}):(0,w.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,w.jsx)(p,{className:`h-6 w-6 animate-spin text-bambu-gray`})})]})]}),C&&(0,w.jsx)(b,{variant:`warning`,title:c(`printers.skipObjects.confirmTitle`),message:K?c(`printers.skipObjects.confirmAllMessage`):W.length===1?c(`printers.skipObjects.confirmMessage`,{name:W[0].name}):c(`printers.skipObjects.confirmMultipleMessage`,{count:W.length}),confirmText:c(`printers.skipObjects.skipSelected`),isLoading:J.isPending,onConfirm:()=>J.mutate([..._]),onCancel:()=>T(!1)}),A&&(0,w.jsxs)(`div`,{className:`fixed inset-0 z-[60] flex items-center justify-center bg-black/90 p-8`,onClick:()=>j(!1),children:[(0,w.jsx)(`button`,{type:`button`,onClick:()=>j(!1),className:`absolute right-4 top-4 rounded p-2 text-white/70 hover:text-white`,children:(0,w.jsx)(h,{className:`h-6 w-6`})}),(0,w.jsx)(`div`,{className:`aspect-square max-h-[86vh] w-full max-w-[86vh]`,onClick:e=>e.stopPropagation(),children:Z(!0)})]})]}):null}function j({status:e}){return e===`ok`?(0,w.jsx)(g,{className:`w-5 h-5 text-bambu-green flex-shrink-0`}):e===`failed`?(0,w.jsx)(u,{className:`w-5 h-5 text-red-600 dark:text-red-400 flex-shrink-0`}):(0,w.jsx)(x,{className:`w-5 h-5 text-bambu-gray flex-shrink-0`})}function M({printerId:e,printerName:t,onClose:n}){let{t:a}=i(),o=s({mutationFn:()=>r.diagnoseCamera(e)});(0,E.useEffect)(()=>{o.mutate()},[]),(0,E.useEffect)(()=>{let e=e=>{e.key===`Escape`&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n]);let c=o.data;return(0,w.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:n,children:(0,w.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-lg flex flex-col`,onClick:e=>e.stopPropagation(),children:[(0,w.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,w.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,w.jsx)(_,{className:`w-5 h-5 text-bambu-green flex-shrink-0`}),(0,w.jsx)(`h2`,{className:`text-lg font-semibold text-white truncate`,children:a(`camera.diagnose.modalTitle`,{name:t||``})})]}),(0,w.jsx)(`button`,{onClick:n,className:`text-bambu-gray hover:text-white transition-colors`,title:a(`common.close`),children:(0,w.jsx)(h,{className:`w-5 h-5`})})]}),(0,w.jsxs)(`div`,{className:`p-6 space-y-4`,children:[o.isPending&&(0,w.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray`,children:[(0,w.jsx)(p,{className:`w-4 h-4 animate-spin`}),(0,w.jsx)(`span`,{children:a(`camera.diagnose.running`)})]}),o.isError&&(0,w.jsx)(`div`,{className:`rounded-lg bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30 px-4 py-3 text-sm text-red-700 dark:text-red-300`,children:a(`camera.diagnose.runFailed`,{error:o.error.message})}),c&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`ol`,{className:`space-y-2`,children:c.stages.map(e=>(0,w.jsxs)(`li`,{className:`flex items-center gap-3 bg-bambu-dark rounded-lg px-4 py-2.5`,children:[(0,w.jsx)(j,{status:e.status}),(0,w.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,w.jsx)(`div`,{className:`text-sm text-white`,children:a(`camera.diagnose.stage.${e.name}`)}),e.code&&(0,w.jsx)(`div`,{className:`text-xs text-bambu-gray font-mono`,children:e.code})]}),(0,w.jsxs)(`div`,{className:`text-xs text-bambu-gray tabular-nums flex-shrink-0`,children:[e.duration_ms,` ms`]})]},e.name))}),(0,w.jsx)(`div`,{className:c.overall_status===`ok`?`rounded-lg bg-bambu-green/10 border border-bambu-green/30 px-4 py-3 text-sm text-bambu-green`:`rounded-lg bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30 px-4 py-3 text-sm text-red-700 dark:text-red-300`,children:a(`camera.diagnose.summary.${c.summary_code}`,{defaultValue:a(`camera.diagnose.summary.unknown_failure`)})}),(0,w.jsx)(`div`,{className:`text-xs text-bambu-gray space-y-0.5`,children:(0,w.jsxs)(`div`,{children:[(0,w.jsxs)(`span`,{className:`text-bambu-gray/60`,children:[a(`camera.diagnose.meta.protocol`),`: `]}),(0,w.jsx)(`span`,{className:`font-mono`,children:c.protocol}),` • `,(0,w.jsxs)(`span`,{className:`text-bambu-gray/60`,children:[a(`camera.diagnose.meta.port`),`: `]}),(0,w.jsx)(`span`,{className:`font-mono`,children:c.port}),` • `,(0,w.jsxs)(`span`,{className:`text-bambu-gray/60`,children:[a(`camera.diagnose.meta.profile`),`: `]}),(0,w.jsx)(`span`,{className:`font-mono`,children:c.profile})]})})]})]}),(0,w.jsxs)(`div`,{className:`px-6 py-4 border-t border-bambu-dark-tertiary flex justify-end gap-2`,children:[(0,w.jsx)(`button`,{onClick:()=>o.mutate(),disabled:o.isPending,className:`px-4 py-2 bg-bambu-dark hover:bg-bambu-dark-tertiary disabled:opacity-50 text-white text-sm rounded-lg transition-colors`,children:a(`camera.diagnose.retry`)}),(0,w.jsx)(`button`,{onClick:n,className:`px-4 py-2 bg-bambu-green hover:bg-bambu-green/90 text-white text-sm rounded-lg transition-colors`,children:a(`common.close`)})]})]})})}export{C as a,T as i,k as n,A as r,M as t}; \ No newline at end of file diff --git a/static/assets/CameraPage-2mgwi0u3.js b/static/assets/CameraPage-D1WovNYe.js similarity index 98% rename from static/assets/CameraPage-2mgwi0u3.js rename to static/assets/CameraPage-D1WovNYe.js index 359e79f88..fc6cfe457 100644 --- a/static/assets/CameraPage-2mgwi0u3.js +++ b/static/assets/CameraPage-D1WovNYe.js @@ -1 +1 @@ -import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,S as r,a as i,d as a,l as o,w as ee}from"./client-DnySrlFv.js";import{n as te}from"./QueryClientProvider-Ce8_sN3w.js";import{t as s}from"./useQuery-BBCjCezC.js";import{t as ne}from"./useMutation-B-Tr2hIP.js";import{t as c}from"./createLucideIcon-DvBYJlWL.js";import{n as re}from"./ToastContext-BRX0SW3C.js";import{a as ie,i as ae,n as oe,r as se,t as ce}from"./CameraDiagnoseModal-38LtfiVu.js";import{t as le}from"./triangle-alert-Dt_1FcBy.js";import{n as ue,t as de}from"./zoom-out-DNNe6DMN.js";import{Ct as fe,Ft as pe,Kt as me,Pn as he,Un as ge,Wn as _e,n as ve,yt as ye}from"./index-0t--Yqoi.js";var be=c(`maximize`,[[`path`,{d:`M8 3H5a2 2 0 0 0-2 2v3`,key:`1dcmit`}],[`path`,{d:`M21 8V5a2 2 0 0 0-2-2h-3`,key:`1e4gt3`}],[`path`,{d:`M3 16v3a2 2 0 0 0 2 2h3`,key:`wsl5sc`}],[`path`,{d:`M16 21h3a2 2 0 0 0 2-2v-3`,key:`18trek`}]]),l=e(n(),1),u=t(),d=5,xe=2e3,Se=3e4,Ce=5e3;function f(){let{t:e}=ee(),t=te(),{showToast:n}=re(),{hasPermission:c,authEnabled:f,user:we}=ye(),{printerId:Te}=ge(),p=parseInt(Te||`0`,10),[Ee]=_e(),De=parseInt(Ee.get(`fps`)||`15`,10),Oe=Math.min(Math.max(isNaN(De)?15:De,1),30);ve();let{data:ke,isPending:Ae}=s({queryKey:[`camera-stream-token`,we?.id??null],queryFn:()=>i.getCameraStreamToken(),enabled:f?!!we:!0,staleTime:3e3*1e3}),m=ke?.token??a(),[h,je]=(0,l.useState)(`stream`),[Me,Ne]=(0,l.useState)(!1),[Pe,g]=(0,l.useState)(!1),[_,v]=(0,l.useState)(!1),[y,b]=(0,l.useState)(!0),[x,S]=(0,l.useState)(Date.now()),[C,w]=(0,l.useState)(!1),[Fe,Ie]=(0,l.useState)(!1),[T,E]=(0,l.useState)(0),[D,O]=(0,l.useState)(!1),[Le,Re]=(0,l.useState)(0),[k,A]=(0,l.useState)(1),[j,M]=(0,l.useState)({x:0,y:0}),[N,P]=(0,l.useState)(!1),[F,ze]=(0,l.useState)({x:0,y:0}),[Be,I]=(0,l.useState)(null),[L,R]=(0,l.useState)(null),z=(0,l.useRef)(null),B=(0,l.useRef)(null),V=(0,l.useRef)(null),H=(0,l.useRef)(null),U=(0,l.useRef)(null),W=(0,l.useRef)(0),{data:G}=s({queryKey:[`printer`,p],queryFn:()=>i.getPrinter(p),enabled:p>0}),{data:K}=s({queryKey:[`printerStatus`,p],queryFn:()=>i.getPrinterStatus(p),refetchInterval:3e4,enabled:p>0}),Ve=ne({mutationFn:e=>i.setChamberLight(p,e),onMutate:async e=>{await t.cancelQueries({queryKey:[`printerStatus`,p]});let n=t.getQueryData([`printerStatus`,p]);return t.setQueryData([`printerStatus`,p],t=>({...t,chamber_light:e})),{previousStatus:n}},onSuccess:(e,t)=>{n(`Chamber light ${t?`on`:`off`}`)},onError:(r,i,a)=>{a?.previousStatus&&t.setQueryData([`printerStatus`,p],a.previousStatus),n(r.message||e(`printers.toast.failedToControlChamberLight`),`error`)}}),q=(K?.state===`RUNNING`||K?.state===`PAUSE`)&&(K?.printable_objects_count??0)>=2;(0,l.useEffect)(()=>(G&&(document.title=`${G.name} - Camera`),()=>{document.title=`Bambuddy`}),[G]);let J=(0,l.useRef)(!1);(0,l.useEffect)(()=>{let e=`/api/v1/printers/${p}/camera/stop`;J.current=!1;let t=()=>{if(p>0&&!J.current){J.current=!0;let t={},n=o();n&&(t.Authorization=`Bearer ${n}`),fetch(e,{method:`POST`,keepalive:!0,headers:t}).catch(()=>{})}},n=()=>{t()};window.addEventListener(`beforeunload`,n);let r=z.current;return()=>{window.removeEventListener(`beforeunload`,n),r&&(r.src=``),t()}},[p]),(0,l.useEffect)(()=>{if(y&&!C){let e=setTimeout(()=>{b(!1)},h===`stream`?3e3:2e4);return()=>clearTimeout(e)}},[h,y,x,C]),(0,l.useEffect)(()=>{let e=()=>{Ie(!!document.fullscreenElement),A(1),M({x:0,y:0}),h===`stream`&&!C&&(z.current&&(z.current.src=``),setTimeout(()=>{b(!0),S(Date.now())},200))};return document.addEventListener(`fullscreenchange`,e),()=>document.removeEventListener(`fullscreenchange`,e)},[h,C]),(0,l.useEffect)(()=>{let e,t=()=>{clearTimeout(e),e=setTimeout(()=>{localStorage.setItem(`cameraWindowState`,JSON.stringify({width:window.outerWidth,height:window.outerHeight,left:window.screenX,top:window.screenY}))},500)};return window.addEventListener(`resize`,t),()=>{clearTimeout(e),window.removeEventListener(`resize`,t)}},[]),(0,l.useEffect)(()=>()=>{V.current&&clearTimeout(V.current),H.current&&clearInterval(H.current),U.current&&clearInterval(U.current)},[]);let Y=(0,l.useCallback)(()=>{if(T>=d){O(!1),v(!0);return}let e=Math.min(xe*2**T,Se);O(!0),Re(Math.ceil(e/1e3)),H.current=setInterval(()=>{Re(e=>e<=1?(H.current&&clearInterval(H.current),0):e-1)},1e3),V.current=setTimeout(()=>{E(e=>e+1),O(!1),b(!0),v(!1),z.current&&(z.current.src=``),S(Date.now())},e)},[T]);(0,l.useEffect)(()=>{if(h!==`stream`||y||D||C){U.current&&=(clearInterval(U.current),null);return}return W.current=0,U.current=setInterval(async()=>{try{let e=await i.getCameraStatus(p);if(!(e.stalled||!e.active&&!_)){W.current=0;return}if(W.current+=1,W.current<2)return;W.current=0,console.log(`Stream issue detected: stalled=${e.stalled}, active=${e.active}, reconnecting...`),U.current&&=(clearInterval(U.current),null),b(!1),Y()}catch{}},Ce),()=>{U.current&&=(clearInterval(U.current),null)}},[h,y,_,D,C,p,Y]);let He=()=>{b(!1),h===`stream`&&T{if(b(!1),v(!1),E(0),W.current=0,O(!1),V.current&&clearTimeout(V.current),H.current&&clearInterval(H.current),z.current&&!localStorage.getItem(`cameraWindowState`)){let e=z.current,t=e.naturalWidth,n=e.naturalHeight;if(t>0&&n>0){let e=window.outerWidth-window.innerWidth,r=window.outerHeight-window.innerHeight,i=t+16+e,a=n+45+16+r;try{window.resizeTo(i,a)}catch{}}}},We=()=>{if(p>0){let e={},t=o();t&&(e.Authorization=`Bearer ${t}`),fetch(`/api/v1/printers/${p}/camera/stop`,{method:`POST`,headers:e}).catch(()=>{})}},Ge=e=>{h===e||C||(w(!0),b(!0),v(!1),E(0),O(!1),A(1),M({x:0,y:0}),V.current&&clearTimeout(V.current),H.current&&clearInterval(H.current),z.current&&(z.current.src=``),h===`stream`&&We(),setTimeout(()=>{je(e),S(Date.now()),w(!1)},100))},X=()=>{C||(w(!0),b(!0),v(!1),E(0),O(!1),V.current&&clearTimeout(V.current),H.current&&clearInterval(H.current),z.current&&(z.current.src=``),h===`stream`&&We(),setTimeout(()=>{S(Date.now()),w(!1)},100))},Ke=()=>{B.current&&(document.fullscreenElement?document.exitFullscreen():B.current.requestFullscreen())},qe=()=>{A(e=>Math.min(e+.5,4))},Je=()=>{A(e=>{let t=Math.max(e-.5,1);return t===1&&M({x:0,y:0}),t})},Ye=e=>{e.preventDefault(),e.deltaY<0?qe():Je()},Xe=e=>{k>1&&(e.preventDefault(),P(!0),ze({x:e.clientX-j.x,y:e.clientY-j.y}))},Z=(0,l.useCallback)(()=>{if(!B.current)return{x:300,y:200};let e=B.current.getBoundingClientRect(),t=e.width*(k-1)/2,n=e.height*(k-1)/2;return{x:Math.max(50,t),y:Math.max(50,n)}},[k]),Ze=e=>{if(N&&k>1){let t=e.clientX-F.x,n=e.clientY-F.y,r=Z();M({x:Math.max(-r.x,Math.min(r.x,t)),y:Math.max(-r.y,Math.min(r.y,n))})}},Qe=()=>{P(!1)},$e=e=>{if(e.length<2)return 0;let t=e[0].clientX-e[1].clientX,n=e[0].clientY-e[1].clientY;return Math.sqrt(t*t+n*n)},et=e=>e.length<2?{x:e[0].clientX,y:e[0].clientY}:{x:(e[0].clientX+e[1].clientX)/2,y:(e[0].clientY+e[1].clientY)/2},tt=e=>{e.touches.length===2?(e.preventDefault(),I($e(e.touches)),R(et(e.touches))):e.touches.length===1&&k>1&&(e.preventDefault(),P(!0),ze({x:e.touches[0].clientX-j.x,y:e.touches[0].clientY-j.y}))},nt=e=>{if(e.touches.length===2&&Be!==null){e.preventDefault();let t=$e(e.touches),n=t/Be;A(e=>{let t=Math.max(1,Math.min(4,e*n));return t===1&&M({x:0,y:0}),t}),I(t);let r=et(e.touches);if(L){let e=Z();M(t=>({x:Math.max(-e.x,Math.min(e.x,t.x+(r.x-L.x))),y:Math.max(-e.y,Math.min(e.y,t.y+(r.y-L.y)))}))}R(r)}else if(e.touches.length===1&&N&&k>1){e.preventDefault();let t=e.touches[0].clientX-F.x,n=e.touches[0].clientY-F.y,r=Z();M({x:Math.max(-r.x,Math.min(r.x,t)),y:Math.max(-r.y,Math.min(r.y,n))})}},rt=e=>{e.touches.length<2&&(I(null),R(null)),e.touches.length===0&&P(!1)},it=()=>{A(1),M({x:0,y:0})},Q=C||!m&&(f||Ae)?``:(e=>m?`${e}&token=${encodeURIComponent(m)}`:r(e))(h===`stream`?`/api/v1/printers/${p}/camera/stream?fps=${Oe}&t=${x}`:`/api/v1/printers/${p}/camera/snapshot?t=${x}`),$=y||C||D;return p?(0,u.jsxs)(`div`,{ref:B,className:`min-h-screen bg-black flex flex-col`,children:[(0,u.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2 bg-bambu-dark-secondary border-b border-bambu-dark-tertiary`,children:[(0,u.jsxs)(`h1`,{className:`text-sm font-medium text-white flex items-center gap-2`,children:[(0,u.jsx)(he,{className:`w-4 h-4`}),G?.name||`Printer ${p}`]}),(0,u.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,u.jsxs)(`div`,{className:`flex bg-bambu-dark rounded p-0.5`,children:[(0,u.jsx)(`button`,{onClick:()=>Ge(`stream`),disabled:$,className:`px-3 py-1 text-xs rounded transition-colors ${h===`stream`?`bg-bambu-green text-white`:`text-bambu-gray hover:text-white disabled:opacity-50`}`,children:e(`camera.live`)}),(0,u.jsx)(`button`,{onClick:()=>Ge(`snapshot`),disabled:$,className:`px-3 py-1 text-xs rounded transition-colors ${h===`snapshot`?`bg-bambu-green text-white`:`text-bambu-gray hover:text-white disabled:opacity-50`}`,children:e(`camera.snapshot`)})]}),(0,u.jsx)(`button`,{onClick:()=>Ve.mutate(!K?.chamber_light),disabled:!K?.connected||Ve.isPending||!c(`printers:control`),className:`p-1.5 rounded disabled:opacity-50 ${K?.chamber_light?`bg-yellow-500/20 hover:bg-yellow-500/30`:`hover:bg-bambu-dark-tertiary`}`,title:c(`printers:control`)?e(`camera.chamberLight`):e(`printers.permission.noControl`),children:(0,u.jsx)(ae,{on:K?.chamber_light??!1,className:`w-4 h-4`})}),(0,u.jsx)(`button`,{onClick:()=>Ne(!0),disabled:!q||!c(`printers:control`),className:`p-1.5 rounded disabled:opacity-50 ${q&&c(`printers:control`)?`hover:bg-bambu-dark-tertiary`:``}`,title:c(`printers:control`)?e(q?`printers.skipObjects.tooltip`:`printers.skipObjects.onlyWhilePrinting`):e(`printers.permission.noControl`),children:(0,u.jsx)(oe,{className:`w-4 h-4 text-bambu-gray`})}),(0,u.jsx)(`button`,{onClick:X,disabled:$,className:`p-1.5 hover:bg-bambu-dark-tertiary rounded disabled:opacity-50`,title:e(h===`stream`?`camera.restartStream`:`camera.refreshSnapshot`),children:(0,u.jsx)(me,{className:`w-4 h-4 text-bambu-gray ${$?`animate-spin`:``}`})}),(0,u.jsx)(`button`,{onClick:()=>g(!0),className:`p-1.5 hover:bg-bambu-dark-tertiary rounded`,title:e(`camera.diagnose.button`),children:(0,u.jsx)(pe,{className:`w-4 h-4 text-bambu-gray`})}),(0,u.jsx)(`button`,{onClick:Ke,className:`p-1.5 hover:bg-bambu-dark-tertiary rounded`,title:e(Fe?`camera.exitFullscreen`:`camera.fullscreen`),children:Fe?(0,u.jsx)(ie,{className:`w-4 h-4 text-bambu-gray`}):(0,u.jsx)(be,{className:`w-4 h-4 text-bambu-gray`})})]})]}),(0,u.jsx)(`div`,{className:`flex-1 flex items-center justify-center p-2 overflow-hidden`,onWheel:Ye,onMouseMove:Ze,onMouseUp:Qe,onMouseLeave:Qe,onTouchStart:tt,onTouchMove:nt,onTouchEnd:rt,style:{touchAction:`none`},children:(0,u.jsxs)(`div`,{className:`relative w-full h-full flex items-center justify-center`,children:[(y||C)&&!D&&(0,u.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-black/50 z-10`,children:(0,u.jsxs)(`div`,{className:`text-center`,children:[(0,u.jsx)(me,{className:`w-8 h-8 text-bambu-gray animate-spin mx-auto mb-2`}),(0,u.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(h===`stream`?`camera.connectingToCamera`:`camera.capturingSnapshot`)})]})}),D&&(0,u.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-black/80 z-10`,children:(0,u.jsxs)(`div`,{className:`text-center p-4`,children:[(0,u.jsx)(fe,{className:`w-10 h-10 text-orange-400 mx-auto mb-3`}),(0,u.jsx)(`p`,{className:`text-white mb-2`,children:e(`camera.connectionLost`)}),(0,u.jsx)(`p`,{className:`text-sm text-bambu-gray mb-3`,children:e(`camera.reconnecting`,{countdown:Le,attempt:Math.min(T+1,d),max:d})}),(0,u.jsx)(`button`,{onClick:X,className:`px-4 py-2 bg-bambu-green text-white text-sm rounded hover:bg-bambu-green/80 transition-colors`,children:e(`camera.reconnectNow`)})]})}),_&&!D&&(0,u.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-black z-10`,children:(0,u.jsxs)(`div`,{className:`text-center p-4`,children:[(0,u.jsx)(le,{className:`w-12 h-12 text-orange-400 mx-auto mb-3`}),(0,u.jsx)(`p`,{className:`text-white mb-2`,children:e(`camera.cameraUnavailable`)}),(0,u.jsx)(`p`,{className:`text-xs text-bambu-gray mb-4 max-w-md`,children:e(`camera.cameraUnavailableDesc`)}),(0,u.jsxs)(`div`,{className:`flex gap-2 justify-center`,children:[(0,u.jsx)(`button`,{onClick:X,className:`px-4 py-2 bg-bambu-green text-white rounded hover:bg-bambu-green/80 transition-colors`,children:e(`camera.retry`)}),(0,u.jsx)(`button`,{onClick:()=>g(!0),className:`px-4 py-2 bg-bambu-dark border border-bambu-dark-tertiary text-bambu-gray hover:text-white rounded transition-colors`,children:e(`camera.diagnose.button`)})]})]})}),(0,u.jsx)(`img`,{ref:z,src:Q,alt:e(`camera.cameraStream`),className:`max-w-full max-h-full object-contain select-none`,style:{transform:`scale(${k}) translate(${j.x/k}px, ${j.y/k}px) rotate(${G?.camera_rotation||0}deg)`,...G?.camera_rotation===90||G?.camera_rotation===270?{maxWidth:`100vh`,maxHeight:`100vw`}:{},cursor:k>1?N?`grabbing`:`grab`:`default`},onError:Q?He:void 0,onLoad:Q?Ue:void 0,onMouseDown:Xe,draggable:!1},x),(0,u.jsxs)(`div`,{className:`absolute bottom-4 left-4 flex items-center gap-1.5 bg-black/60 rounded-lg px-2 py-1.5`,children:[(0,u.jsx)(`button`,{onClick:Je,disabled:k<=1,className:`p-1.5 hover:bg-white/10 rounded disabled:opacity-30`,title:e(`camera.zoomOut`),children:(0,u.jsx)(de,{className:`w-4 h-4 text-white`})}),(0,u.jsxs)(`button`,{onClick:it,className:`px-2 py-1 text-sm text-white hover:bg-white/10 rounded min-w-[48px]`,title:e(`camera.resetZoom`),children:[Math.round(k*100),`%`]}),(0,u.jsx)(`button`,{onClick:qe,disabled:k>=4,className:`p-1.5 hover:bg-white/10 rounded disabled:opacity-30`,title:e(`camera.zoomIn`),children:(0,u.jsx)(ue,{className:`w-4 h-4 text-white`})})]})]})}),(0,u.jsx)(se,{printerId:p,isOpen:Me,onClose:()=>Ne(!1)}),Pe&&(0,u.jsx)(ce,{printerId:p,printerName:G?.name||null,onClose:()=>g(!1)})]}):(0,u.jsx)(`div`,{className:`min-h-screen bg-black flex items-center justify-center`,children:(0,u.jsx)(`p`,{className:`text-white`,children:e(`camera.invalidPrinterId`)})})}export{f as CameraPage}; \ No newline at end of file +import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,S as r,a as i,d as a,l as o,w as ee}from"./client-DnySrlFv.js";import{n as te}from"./QueryClientProvider-Ce8_sN3w.js";import{t as s}from"./useQuery-BBCjCezC.js";import{t as ne}from"./useMutation-B-Tr2hIP.js";import{t as c}from"./createLucideIcon-DvBYJlWL.js";import{n as re}from"./ToastContext-BRX0SW3C.js";import{a as ie,i as ae,n as oe,r as se,t as ce}from"./CameraDiagnoseModal-BwHHipUP.js";import{t as le}from"./triangle-alert-Dt_1FcBy.js";import{n as ue,t as de}from"./zoom-out-DNNe6DMN.js";import{Ct as fe,Ft as pe,Kt as me,Pn as he,Un as ge,Wn as _e,n as ve,yt as ye}from"./index-Cxa-KVmA.js";var be=c(`maximize`,[[`path`,{d:`M8 3H5a2 2 0 0 0-2 2v3`,key:`1dcmit`}],[`path`,{d:`M21 8V5a2 2 0 0 0-2-2h-3`,key:`1e4gt3`}],[`path`,{d:`M3 16v3a2 2 0 0 0 2 2h3`,key:`wsl5sc`}],[`path`,{d:`M16 21h3a2 2 0 0 0 2-2v-3`,key:`18trek`}]]),l=e(n(),1),u=t(),d=5,xe=2e3,Se=3e4,Ce=5e3;function f(){let{t:e}=ee(),t=te(),{showToast:n}=re(),{hasPermission:c,authEnabled:f,user:we}=ye(),{printerId:Te}=ge(),p=parseInt(Te||`0`,10),[Ee]=_e(),De=parseInt(Ee.get(`fps`)||`15`,10),Oe=Math.min(Math.max(isNaN(De)?15:De,1),30);ve();let{data:ke,isPending:Ae}=s({queryKey:[`camera-stream-token`,we?.id??null],queryFn:()=>i.getCameraStreamToken(),enabled:f?!!we:!0,staleTime:3e3*1e3}),m=ke?.token??a(),[h,je]=(0,l.useState)(`stream`),[Me,Ne]=(0,l.useState)(!1),[Pe,g]=(0,l.useState)(!1),[_,v]=(0,l.useState)(!1),[y,b]=(0,l.useState)(!0),[x,S]=(0,l.useState)(Date.now()),[C,w]=(0,l.useState)(!1),[Fe,Ie]=(0,l.useState)(!1),[T,E]=(0,l.useState)(0),[D,O]=(0,l.useState)(!1),[Le,Re]=(0,l.useState)(0),[k,A]=(0,l.useState)(1),[j,M]=(0,l.useState)({x:0,y:0}),[N,P]=(0,l.useState)(!1),[F,ze]=(0,l.useState)({x:0,y:0}),[Be,I]=(0,l.useState)(null),[L,R]=(0,l.useState)(null),z=(0,l.useRef)(null),B=(0,l.useRef)(null),V=(0,l.useRef)(null),H=(0,l.useRef)(null),U=(0,l.useRef)(null),W=(0,l.useRef)(0),{data:G}=s({queryKey:[`printer`,p],queryFn:()=>i.getPrinter(p),enabled:p>0}),{data:K}=s({queryKey:[`printerStatus`,p],queryFn:()=>i.getPrinterStatus(p),refetchInterval:3e4,enabled:p>0}),Ve=ne({mutationFn:e=>i.setChamberLight(p,e),onMutate:async e=>{await t.cancelQueries({queryKey:[`printerStatus`,p]});let n=t.getQueryData([`printerStatus`,p]);return t.setQueryData([`printerStatus`,p],t=>({...t,chamber_light:e})),{previousStatus:n}},onSuccess:(e,t)=>{n(`Chamber light ${t?`on`:`off`}`)},onError:(r,i,a)=>{a?.previousStatus&&t.setQueryData([`printerStatus`,p],a.previousStatus),n(r.message||e(`printers.toast.failedToControlChamberLight`),`error`)}}),q=(K?.state===`RUNNING`||K?.state===`PAUSE`)&&(K?.printable_objects_count??0)>=2;(0,l.useEffect)(()=>(G&&(document.title=`${G.name} - Camera`),()=>{document.title=`Bambuddy`}),[G]);let J=(0,l.useRef)(!1);(0,l.useEffect)(()=>{let e=`/api/v1/printers/${p}/camera/stop`;J.current=!1;let t=()=>{if(p>0&&!J.current){J.current=!0;let t={},n=o();n&&(t.Authorization=`Bearer ${n}`),fetch(e,{method:`POST`,keepalive:!0,headers:t}).catch(()=>{})}},n=()=>{t()};window.addEventListener(`beforeunload`,n);let r=z.current;return()=>{window.removeEventListener(`beforeunload`,n),r&&(r.src=``),t()}},[p]),(0,l.useEffect)(()=>{if(y&&!C){let e=setTimeout(()=>{b(!1)},h===`stream`?3e3:2e4);return()=>clearTimeout(e)}},[h,y,x,C]),(0,l.useEffect)(()=>{let e=()=>{Ie(!!document.fullscreenElement),A(1),M({x:0,y:0}),h===`stream`&&!C&&(z.current&&(z.current.src=``),setTimeout(()=>{b(!0),S(Date.now())},200))};return document.addEventListener(`fullscreenchange`,e),()=>document.removeEventListener(`fullscreenchange`,e)},[h,C]),(0,l.useEffect)(()=>{let e,t=()=>{clearTimeout(e),e=setTimeout(()=>{localStorage.setItem(`cameraWindowState`,JSON.stringify({width:window.outerWidth,height:window.outerHeight,left:window.screenX,top:window.screenY}))},500)};return window.addEventListener(`resize`,t),()=>{clearTimeout(e),window.removeEventListener(`resize`,t)}},[]),(0,l.useEffect)(()=>()=>{V.current&&clearTimeout(V.current),H.current&&clearInterval(H.current),U.current&&clearInterval(U.current)},[]);let Y=(0,l.useCallback)(()=>{if(T>=d){O(!1),v(!0);return}let e=Math.min(xe*2**T,Se);O(!0),Re(Math.ceil(e/1e3)),H.current=setInterval(()=>{Re(e=>e<=1?(H.current&&clearInterval(H.current),0):e-1)},1e3),V.current=setTimeout(()=>{E(e=>e+1),O(!1),b(!0),v(!1),z.current&&(z.current.src=``),S(Date.now())},e)},[T]);(0,l.useEffect)(()=>{if(h!==`stream`||y||D||C){U.current&&=(clearInterval(U.current),null);return}return W.current=0,U.current=setInterval(async()=>{try{let e=await i.getCameraStatus(p);if(!(e.stalled||!e.active&&!_)){W.current=0;return}if(W.current+=1,W.current<2)return;W.current=0,console.log(`Stream issue detected: stalled=${e.stalled}, active=${e.active}, reconnecting...`),U.current&&=(clearInterval(U.current),null),b(!1),Y()}catch{}},Ce),()=>{U.current&&=(clearInterval(U.current),null)}},[h,y,_,D,C,p,Y]);let He=()=>{b(!1),h===`stream`&&T{if(b(!1),v(!1),E(0),W.current=0,O(!1),V.current&&clearTimeout(V.current),H.current&&clearInterval(H.current),z.current&&!localStorage.getItem(`cameraWindowState`)){let e=z.current,t=e.naturalWidth,n=e.naturalHeight;if(t>0&&n>0){let e=window.outerWidth-window.innerWidth,r=window.outerHeight-window.innerHeight,i=t+16+e,a=n+45+16+r;try{window.resizeTo(i,a)}catch{}}}},We=()=>{if(p>0){let e={},t=o();t&&(e.Authorization=`Bearer ${t}`),fetch(`/api/v1/printers/${p}/camera/stop`,{method:`POST`,headers:e}).catch(()=>{})}},Ge=e=>{h===e||C||(w(!0),b(!0),v(!1),E(0),O(!1),A(1),M({x:0,y:0}),V.current&&clearTimeout(V.current),H.current&&clearInterval(H.current),z.current&&(z.current.src=``),h===`stream`&&We(),setTimeout(()=>{je(e),S(Date.now()),w(!1)},100))},X=()=>{C||(w(!0),b(!0),v(!1),E(0),O(!1),V.current&&clearTimeout(V.current),H.current&&clearInterval(H.current),z.current&&(z.current.src=``),h===`stream`&&We(),setTimeout(()=>{S(Date.now()),w(!1)},100))},Ke=()=>{B.current&&(document.fullscreenElement?document.exitFullscreen():B.current.requestFullscreen())},qe=()=>{A(e=>Math.min(e+.5,4))},Je=()=>{A(e=>{let t=Math.max(e-.5,1);return t===1&&M({x:0,y:0}),t})},Ye=e=>{e.preventDefault(),e.deltaY<0?qe():Je()},Xe=e=>{k>1&&(e.preventDefault(),P(!0),ze({x:e.clientX-j.x,y:e.clientY-j.y}))},Z=(0,l.useCallback)(()=>{if(!B.current)return{x:300,y:200};let e=B.current.getBoundingClientRect(),t=e.width*(k-1)/2,n=e.height*(k-1)/2;return{x:Math.max(50,t),y:Math.max(50,n)}},[k]),Ze=e=>{if(N&&k>1){let t=e.clientX-F.x,n=e.clientY-F.y,r=Z();M({x:Math.max(-r.x,Math.min(r.x,t)),y:Math.max(-r.y,Math.min(r.y,n))})}},Qe=()=>{P(!1)},$e=e=>{if(e.length<2)return 0;let t=e[0].clientX-e[1].clientX,n=e[0].clientY-e[1].clientY;return Math.sqrt(t*t+n*n)},et=e=>e.length<2?{x:e[0].clientX,y:e[0].clientY}:{x:(e[0].clientX+e[1].clientX)/2,y:(e[0].clientY+e[1].clientY)/2},tt=e=>{e.touches.length===2?(e.preventDefault(),I($e(e.touches)),R(et(e.touches))):e.touches.length===1&&k>1&&(e.preventDefault(),P(!0),ze({x:e.touches[0].clientX-j.x,y:e.touches[0].clientY-j.y}))},nt=e=>{if(e.touches.length===2&&Be!==null){e.preventDefault();let t=$e(e.touches),n=t/Be;A(e=>{let t=Math.max(1,Math.min(4,e*n));return t===1&&M({x:0,y:0}),t}),I(t);let r=et(e.touches);if(L){let e=Z();M(t=>({x:Math.max(-e.x,Math.min(e.x,t.x+(r.x-L.x))),y:Math.max(-e.y,Math.min(e.y,t.y+(r.y-L.y)))}))}R(r)}else if(e.touches.length===1&&N&&k>1){e.preventDefault();let t=e.touches[0].clientX-F.x,n=e.touches[0].clientY-F.y,r=Z();M({x:Math.max(-r.x,Math.min(r.x,t)),y:Math.max(-r.y,Math.min(r.y,n))})}},rt=e=>{e.touches.length<2&&(I(null),R(null)),e.touches.length===0&&P(!1)},it=()=>{A(1),M({x:0,y:0})},Q=C||!m&&(f||Ae)?``:(e=>m?`${e}&token=${encodeURIComponent(m)}`:r(e))(h===`stream`?`/api/v1/printers/${p}/camera/stream?fps=${Oe}&t=${x}`:`/api/v1/printers/${p}/camera/snapshot?t=${x}`),$=y||C||D;return p?(0,u.jsxs)(`div`,{ref:B,className:`min-h-screen bg-black flex flex-col`,children:[(0,u.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2 bg-bambu-dark-secondary border-b border-bambu-dark-tertiary`,children:[(0,u.jsxs)(`h1`,{className:`text-sm font-medium text-white flex items-center gap-2`,children:[(0,u.jsx)(he,{className:`w-4 h-4`}),G?.name||`Printer ${p}`]}),(0,u.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,u.jsxs)(`div`,{className:`flex bg-bambu-dark rounded p-0.5`,children:[(0,u.jsx)(`button`,{onClick:()=>Ge(`stream`),disabled:$,className:`px-3 py-1 text-xs rounded transition-colors ${h===`stream`?`bg-bambu-green text-white`:`text-bambu-gray hover:text-white disabled:opacity-50`}`,children:e(`camera.live`)}),(0,u.jsx)(`button`,{onClick:()=>Ge(`snapshot`),disabled:$,className:`px-3 py-1 text-xs rounded transition-colors ${h===`snapshot`?`bg-bambu-green text-white`:`text-bambu-gray hover:text-white disabled:opacity-50`}`,children:e(`camera.snapshot`)})]}),(0,u.jsx)(`button`,{onClick:()=>Ve.mutate(!K?.chamber_light),disabled:!K?.connected||Ve.isPending||!c(`printers:control`),className:`p-1.5 rounded disabled:opacity-50 ${K?.chamber_light?`bg-yellow-500/20 hover:bg-yellow-500/30`:`hover:bg-bambu-dark-tertiary`}`,title:c(`printers:control`)?e(`camera.chamberLight`):e(`printers.permission.noControl`),children:(0,u.jsx)(ae,{on:K?.chamber_light??!1,className:`w-4 h-4`})}),(0,u.jsx)(`button`,{onClick:()=>Ne(!0),disabled:!q||!c(`printers:control`),className:`p-1.5 rounded disabled:opacity-50 ${q&&c(`printers:control`)?`hover:bg-bambu-dark-tertiary`:``}`,title:c(`printers:control`)?e(q?`printers.skipObjects.tooltip`:`printers.skipObjects.onlyWhilePrinting`):e(`printers.permission.noControl`),children:(0,u.jsx)(oe,{className:`w-4 h-4 text-bambu-gray`})}),(0,u.jsx)(`button`,{onClick:X,disabled:$,className:`p-1.5 hover:bg-bambu-dark-tertiary rounded disabled:opacity-50`,title:e(h===`stream`?`camera.restartStream`:`camera.refreshSnapshot`),children:(0,u.jsx)(me,{className:`w-4 h-4 text-bambu-gray ${$?`animate-spin`:``}`})}),(0,u.jsx)(`button`,{onClick:()=>g(!0),className:`p-1.5 hover:bg-bambu-dark-tertiary rounded`,title:e(`camera.diagnose.button`),children:(0,u.jsx)(pe,{className:`w-4 h-4 text-bambu-gray`})}),(0,u.jsx)(`button`,{onClick:Ke,className:`p-1.5 hover:bg-bambu-dark-tertiary rounded`,title:e(Fe?`camera.exitFullscreen`:`camera.fullscreen`),children:Fe?(0,u.jsx)(ie,{className:`w-4 h-4 text-bambu-gray`}):(0,u.jsx)(be,{className:`w-4 h-4 text-bambu-gray`})})]})]}),(0,u.jsx)(`div`,{className:`flex-1 flex items-center justify-center p-2 overflow-hidden`,onWheel:Ye,onMouseMove:Ze,onMouseUp:Qe,onMouseLeave:Qe,onTouchStart:tt,onTouchMove:nt,onTouchEnd:rt,style:{touchAction:`none`},children:(0,u.jsxs)(`div`,{className:`relative w-full h-full flex items-center justify-center`,children:[(y||C)&&!D&&(0,u.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-black/50 z-10`,children:(0,u.jsxs)(`div`,{className:`text-center`,children:[(0,u.jsx)(me,{className:`w-8 h-8 text-bambu-gray animate-spin mx-auto mb-2`}),(0,u.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(h===`stream`?`camera.connectingToCamera`:`camera.capturingSnapshot`)})]})}),D&&(0,u.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-black/80 z-10`,children:(0,u.jsxs)(`div`,{className:`text-center p-4`,children:[(0,u.jsx)(fe,{className:`w-10 h-10 text-orange-400 mx-auto mb-3`}),(0,u.jsx)(`p`,{className:`text-white mb-2`,children:e(`camera.connectionLost`)}),(0,u.jsx)(`p`,{className:`text-sm text-bambu-gray mb-3`,children:e(`camera.reconnecting`,{countdown:Le,attempt:Math.min(T+1,d),max:d})}),(0,u.jsx)(`button`,{onClick:X,className:`px-4 py-2 bg-bambu-green text-white text-sm rounded hover:bg-bambu-green/80 transition-colors`,children:e(`camera.reconnectNow`)})]})}),_&&!D&&(0,u.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-black z-10`,children:(0,u.jsxs)(`div`,{className:`text-center p-4`,children:[(0,u.jsx)(le,{className:`w-12 h-12 text-orange-400 mx-auto mb-3`}),(0,u.jsx)(`p`,{className:`text-white mb-2`,children:e(`camera.cameraUnavailable`)}),(0,u.jsx)(`p`,{className:`text-xs text-bambu-gray mb-4 max-w-md`,children:e(`camera.cameraUnavailableDesc`)}),(0,u.jsxs)(`div`,{className:`flex gap-2 justify-center`,children:[(0,u.jsx)(`button`,{onClick:X,className:`px-4 py-2 bg-bambu-green text-white rounded hover:bg-bambu-green/80 transition-colors`,children:e(`camera.retry`)}),(0,u.jsx)(`button`,{onClick:()=>g(!0),className:`px-4 py-2 bg-bambu-dark border border-bambu-dark-tertiary text-bambu-gray hover:text-white rounded transition-colors`,children:e(`camera.diagnose.button`)})]})]})}),(0,u.jsx)(`img`,{ref:z,src:Q,alt:e(`camera.cameraStream`),className:`max-w-full max-h-full object-contain select-none`,style:{transform:`scale(${k}) translate(${j.x/k}px, ${j.y/k}px) rotate(${G?.camera_rotation||0}deg)`,...G?.camera_rotation===90||G?.camera_rotation===270?{maxWidth:`100vh`,maxHeight:`100vw`}:{},cursor:k>1?N?`grabbing`:`grab`:`default`},onError:Q?He:void 0,onLoad:Q?Ue:void 0,onMouseDown:Xe,draggable:!1},x),(0,u.jsxs)(`div`,{className:`absolute bottom-4 left-4 flex items-center gap-1.5 bg-black/60 rounded-lg px-2 py-1.5`,children:[(0,u.jsx)(`button`,{onClick:Je,disabled:k<=1,className:`p-1.5 hover:bg-white/10 rounded disabled:opacity-30`,title:e(`camera.zoomOut`),children:(0,u.jsx)(de,{className:`w-4 h-4 text-white`})}),(0,u.jsxs)(`button`,{onClick:it,className:`px-2 py-1 text-sm text-white hover:bg-white/10 rounded min-w-[48px]`,title:e(`camera.resetZoom`),children:[Math.round(k*100),`%`]}),(0,u.jsx)(`button`,{onClick:qe,disabled:k>=4,className:`p-1.5 hover:bg-white/10 rounded disabled:opacity-30`,title:e(`camera.zoomIn`),children:(0,u.jsx)(ue,{className:`w-4 h-4 text-white`})})]})]})}),(0,u.jsx)(se,{printerId:p,isOpen:Me,onClose:()=>Ne(!1)}),Pe&&(0,u.jsx)(ce,{printerId:p,printerName:G?.name||null,onClose:()=>g(!1)})]}):(0,u.jsx)(`div`,{className:`min-h-screen bg-black flex items-center justify-center`,children:(0,u.jsx)(`p`,{className:`text-white`,children:e(`camera.invalidPrinterId`)})})}export{f as CameraPage}; \ No newline at end of file diff --git a/static/assets/CameraWall-Cv6o1Fp5.js b/static/assets/CameraWall-D-W28jK-.js similarity index 99% rename from static/assets/CameraWall-Cv6o1Fp5.js rename to static/assets/CameraWall-D-W28jK-.js index 8566db4e2..128fd757f 100644 --- a/static/assets/CameraWall-Cv6o1Fp5.js +++ b/static/assets/CameraWall-D-W28jK-.js @@ -1 +1 @@ -import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,S as r,a as i,l as a,w as o}from"./client-DnySrlFv.js";import{n as s}from"./QueryClientProvider-Ce8_sN3w.js";import{t as c}from"./useMutation-B-Tr2hIP.js";import{t as l}from"./useQueries-Be6PMvSC.js";import{t as u}from"./createLucideIcon-DvBYJlWL.js";import{r as d,t as f}from"./info-ROUoQhJR.js";import{n as p}from"./ToastContext-BRX0SW3C.js";import{t as m}from"./loader-circle-BEmFtawu.js";import{t as h}from"./triangle-alert-Dt_1FcBy.js";import{t as g}from"./x-DR-Trv6U.js";import{o as _}from"./date-G9KUauqz.js";import{At as v,Cn as y,Ct as b,Vt as x}from"./index-0t--Yqoi.js";var S=u(`video-off`,[[`path`,{d:`M10.66 6H14a2 2 0 0 1 2 2v2.5l5.248-3.062A.5.5 0 0 1 22 7.87v8.196`,key:`w8jjjt`}],[`path`,{d:`M16 16a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h2`,key:`1xawa7`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}]]),C=e(n(),1),w=[`s`,`m`,`l`,`xl`];function T(e){switch(e){case 1:return`grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5`;case 3:return`grid-cols-1 lg:grid-cols-2`;case 4:return`grid-cols-1`;default:return`grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4`}}var E=t(),D=8;function O(e,t){if(t>0)return`error`;switch(e){case`RUNNING`:return`printing`;case`PAUSE`:return`paused`;case`FINISH`:case`FAILED`:return`finished`;default:return`idle`}}var k={printing:`bg-bambu-green/85 text-black`,paused:`bg-amber-500/85 text-black`,finished:`bg-sky-500/80 text-white`,error:`bg-red-500/85 text-white`,idle:`bg-bambu-dark-tertiary/80 text-bambu-gray`};function A({printerId:e,printerName:t,cameraRotation:n=0,mode:i,snapshotIntervalMs:s,connected:c,onClick:l,statusMode:u=`off`,printerState:d=null,progress:f=null,remainingMin:p=null,layerNum:m=null,totalLayers:g=null,printName:v=null,hmsErrorCount:y=0}){let{t:x}=o(),[w,T]=(0,C.useState)(0),[A,j]=(0,C.useState)(!1),M=(0,C.useRef)(i);(0,C.useEffect)(()=>{let t=M.current===`live`,n=i===`live`;if(M.current=i,t&&!n){let t={},n=a();n&&(t.Authorization=`Bearer ${n}`),fetch(`/api/v1/printers/${e}/camera/stop`,{method:`POST`,keepalive:!0,headers:t}).catch(()=>{})}j(!1),T(e=>e+1)},[i,e]),(0,C.useEffect)(()=>()=>{if(M.current===`live`){let t={},n=a();n&&(t.Authorization=`Bearer ${n}`),fetch(`/api/v1/printers/${e}/camera/stop`,{method:`POST`,keepalive:!0,headers:t}).catch(()=>{})}},[e]),(0,C.useEffect)(()=>{if(i!==`snapshot`)return;let e=setInterval(()=>T(e=>e+1),s);return()=>clearInterval(e)},[i,s]);let N=r(`/api/v1/printers/${e}/camera/stream?fps=${D}&t=${w}`),P=r(`/api/v1/printers/${e}/camera/snapshot?t=${w}`),F=l!=null,I=n?`rotate(${n}deg)`:void 0,L=O(d,y),R=c&&u!==`off`&&L!==`idle`,z=c&&u===`full`&&(L===`printing`||L===`paused`),B=v??null,V=f==null?null:Math.round(f),H=m!=null&&g!=null&&g>0,U=p!=null&&p>0,W=`group relative aspect-video w-full overflow-hidden rounded-lg border border-bambu-dark-tertiary bg-black text-left ${F?`focus:outline-none focus:ring-2 focus:ring-bambu-green`:`cursor-default`}`,G=(0,E.jsxs)(E.Fragment,{children:[!c||i===`paused`?(0,E.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-bambu-dark/60`,children:c?(0,E.jsx)(S,{className:`h-8 w-8 text-bambu-gray/70`,"aria-hidden":`true`}):(0,E.jsx)(b,{className:`h-8 w-8 text-bambu-gray/70`,"aria-hidden":`true`})}):A?(0,E.jsxs)(`div`,{className:`absolute inset-0 flex flex-col items-center justify-center gap-1 bg-black/80 text-bambu-gray`,children:[(0,E.jsx)(S,{className:`h-7 w-7`,"aria-hidden":`true`}),(0,E.jsx)(`span`,{className:`text-xs`,children:x(`printers.camWall.noSignal`)})]}):(0,E.jsx)(`img`,{src:i===`live`?N:P,alt:t,draggable:!1,loading:`lazy`,className:`h-full w-full select-none object-contain`,style:{transform:I},onError:()=>j(!0)},`${i}-${w}`),R&&(0,E.jsxs)(`span`,{className:`absolute left-2 top-2 flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] font-semibold uppercase tracking-wide ${k[L]}`,children:[y>0&&(0,E.jsx)(h,{className:`h-3 w-3`,"aria-hidden":`true`}),(0,E.jsx)(`span`,{children:x(`printers.status.${L}`)})]}),(0,E.jsx)(`span`,{className:`absolute right-2 top-2 rounded px-1.5 py-0.5 text-[10px] font-semibold uppercase tracking-wide ${i===`live`?`bg-red-500/80 text-white`:i===`snapshot`?`bg-amber-500/70 text-black`:`bg-bambu-dark-tertiary/70 text-bambu-gray`}`,children:x(i===`live`?`printers.camWall.live`:i===`snapshot`?`printers.camWall.snap`:`printers.camWall.off`)}),(0,E.jsxs)(`div`,{className:`absolute inset-x-0 bottom-0 bg-gradient-to-t from-black/85 via-black/55 to-transparent px-2 pb-1.5 pt-3 text-white`,children:[z&&(0,E.jsxs)(`div`,{className:`mb-0.5 space-y-0.5 text-[11px] leading-tight text-white/90`,children:[B&&(0,E.jsx)(`div`,{className:`truncate`,title:B,children:B}),(0,E.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-0.5 text-bambu-gray`,children:[V!=null&&(0,E.jsxs)(`span`,{className:`font-semibold text-white`,children:[V,`%`]}),H&&(0,E.jsx)(`span`,{children:x(`printers.camWall.layer`,{cur:m,total:g})}),U&&(0,E.jsx)(`span`,{children:x(`printers.camWall.timeLeft`,{time:_((p??0)*60)})})]})]}),(0,E.jsx)(`span`,{className:`block truncate text-xs font-medium`,children:t})]})]});return F?(0,E.jsx)(`button`,{type:`button`,onClick:l,className:W,title:t,children:G}):(0,E.jsx)(`div`,{className:W,title:t,children:G})}var j=new Set([`0700_8011`,`0701_8011`,`0702_8011`,`0703_8011`,`0704_8011`,`0705_8011`,`0706_8011`,`0707_8011`,`07FF_8011`]),M=`0500050000010007`;function N(e){switch(e){case 1:return{labelKey:`hmsErrors.severityError`,color:`text-red-600 dark:text-red-400`,bgColor:`bg-red-100 dark:bg-red-500/20`,Icon:h};case 2:return{labelKey:`hmsErrors.severityWarning`,color:`text-orange-700 dark:text-orange-400`,bgColor:`bg-orange-100 dark:bg-orange-500/20`,Icon:h};case 3:return{labelKey:`hmsErrors.severityNotice`,color:`text-blue-700 dark:text-blue-400`,bgColor:`bg-blue-100 dark:bg-blue-500/20`,Icon:f};default:return{labelKey:`hmsErrors.severityUnknown`,color:`text-bambu-gray`,bgColor:`bg-bambu-dark-tertiary`,Icon:d}}}function P(e){return e.severity===1||e.severity===2}function F(e,t){let n=e>>16&65535||(e>>8&255)<<8|e&255,r=t&65535;return`${n.toString(16).padStart(4,`0`).toUpperCase()}_${r.toString(16).padStart(4,`0`).toUpperCase()}`}function I(e){if(e.full_code&&e.full_code.length===16)return e.full_code.match(/.{4}/g).join(`-`);let t=parseInt(e.code.replace(`0x`,``),16)||0;return F(e.attr,t).replace(`_`,`-`)}function L(e){if(!(e.severity>=1))return!1;if((e.actions?.length??0)>0)return!0;let t=e.full_code?.length===16&&e.severity===3;return!!e.description&&!t}function R(e){return e.filter(L)}function z(e){return e.filter(e=>!L(e))}function B(){return`https://wiki.bambulab.com/en/hms/home`}function V({printerName:e,errors:t,onClose:n,printerId:r,hasPermission:a,runoutGuidance:l}){let{t:u}=o(),{showToast:f}=p(),_=s(),b=c({mutationFn:()=>i.clearHMSErrors(r),onSuccess:()=>{f(u(`hmsErrors.clearSuccess`),`success`),n()},onError:()=>{f(u(`hmsErrors.clearFailed`),`error`)}}),x=R(t),S=z(t);(0,C.useEffect)(()=>{let e=e=>{e.key===`Escape`&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n]);let w=c({mutationFn:e=>i.executeHMSAction(r,{action:e.action,print_error:e.print_error,job_id:e.job_id}),onSuccess:()=>{_.invalidateQueries({queryKey:[`printerStatus`,r]}),f(u(`hmsErrors.actionSuccess`,`Action sent to printer`),`success`),n()},onError:e=>{f(`${u(`hmsErrors.actionFailed`,`Failed to send action`)}: ${e.message}`,`error`)}});return(0,E.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,children:(0,E.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg shadow-xl max-w-lg w-full max-h-[80vh] flex flex-col`,children:[(0,E.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,E.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,E.jsx)(h,{className:`w-5 h-5 text-orange-600 dark:text-orange-400`}),(0,E.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:u(`hmsErrors.title`,{name:e})})]}),(0,E.jsx)(`button`,{onClick:n,className:`p-1 hover:bg-bambu-dark-tertiary rounded-lg transition-colors`,children:(0,E.jsx)(g,{className:`w-5 h-5 text-bambu-gray`})})]}),(0,E.jsx)(`div`,{className:`flex-1 overflow-y-auto p-4`,children:x.length===0&&S.length===0?(0,E.jsxs)(`div`,{className:`text-center py-8 text-bambu-gray`,children:[(0,E.jsx)(d,{className:`w-12 h-12 mx-auto mb-3 opacity-30`}),(0,E.jsx)(`p`,{children:u(`hmsErrors.noErrors`)})]}):(0,E.jsxs)(`div`,{className:`space-y-3`,children:[x.map((e,t)=>{let{labelKey:n,color:r,bgColor:i,Icon:o}=N(e.severity),s=parseInt(e.code.replace(`0x`,``),16)||0,c=F(e.attr,s),d=e.description||u(`hmsErrors.unknownCode`),f=e.full_code===M;f&&(d=u(`hmsErrors.mqttVerifyFailedDescription`));let p=f?u(`hmsErrors.mqttVerifyFailedRemedy`):null;l&&j.has(c)&&(d=l.expectedSlotLabel&&l.ranOutSlotLabel?u(`hmsErrors.runoutExpectedSlot`,{expected:l.expectedSlotLabel,ranOut:l.ranOutSlotLabel}):l.expectedSlotLabel?u(`hmsErrors.runoutExpectedSlotOnly`,{expected:l.expectedSlotLabel}):u(`hmsErrors.runoutSlotUnknown`));let h=B(),g=I(e);return(0,E.jsx)(`div`,{className:`p-4 rounded-lg ${i} border border-white/10`,children:(0,E.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,E.jsx)(o,{className:`w-5 h-5 ${r} flex-shrink-0 mt-0.5`}),(0,E.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,E.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,E.jsxs)(`span`,{className:`font-mono text-sm ${r}`,children:[`[`,g,`]`]}),(0,E.jsx)(`span`,{className:`text-xs px-2 py-0.5 rounded-full ${i} ${r}`,children:u(n)})]}),(0,E.jsx)(`p`,{className:`text-sm text-bambu-gray mb-2`,children:d}),p&&(0,E.jsx)(`p`,{className:`text-sm text-bambu-gray mb-2`,children:p}),e.actions&&e.actions.length>0&&(0,E.jsx)(`div`,{className:`flex flex-wrap gap-2 my-2`,children:e.actions.map(t=>{let n=w.variables,r=w.isPending&&n?.action===t&&n?.print_error===(e.full_code||c.replace(`_`,``));return(0,E.jsxs)(`button`,{onClick:()=>{w.mutate({action:t,print_error:e.full_code||c.replace(`_`,``),job_id:e.job_id??null})},disabled:!a(`printers:control`)||w.isPending,className:`flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium rounded-lg bg-white/10 hover:bg-white/20 active:bg-white/30 text-white border border-white/20 hover:border-white/30 transition-colors disabled:opacity-50 disabled:cursor-not-allowed flex-shrink-0`,children:[r&&(0,E.jsx)(m,{className:`w-4 h-4 animate-spin`}),u(`hmsErrors.actions.${t}`,t)]},t)})}),(0,E.jsxs)(`a`,{href:h,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-1 text-xs text-bambu-green hover:underline`,children:[(0,E.jsx)(y,{className:`w-3 h-3`}),u(`hmsErrors.viewOnWiki`)]})]})]})},`${e.code}-${t}`)}),S.length>0&&(0,E.jsxs)(`details`,{className:`rounded-lg border border-white/10 p-3`,"data-testid":`hms-uncounted`,children:[(0,E.jsx)(`summary`,{className:`cursor-pointer text-sm text-bambu-gray`,children:u(`hmsErrors.uncountedSummary`,{n:S.length})}),(0,E.jsx)(`p`,{className:`mt-2 text-xs text-bambu-gray`,children:u(`hmsErrors.uncountedHint`)}),(0,E.jsx)(`ul`,{className:`mt-2 space-y-2`,children:S.map((e,t)=>(0,E.jsxs)(`li`,{className:`text-xs`,children:[(0,E.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,E.jsxs)(`span`,{className:`font-mono text-bambu-gray`,children:[`[`,I(e),`]`]}),(0,E.jsx)(`span`,{className:`text-bambu-gray`,children:u(N(e.severity).labelKey)})]}),e.description&&(0,E.jsx)(`p`,{className:`mt-0.5 text-bambu-gray`,children:e.description})]},`${e.full_code||e.code}-${t}`))})]})]})}),(0,E.jsxs)(`div`,{className:`p-4 border-t border-bambu-dark-tertiary flex items-center justify-between gap-3`,children:[(0,E.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:u(`hmsErrors.clearInstructions`)}),t.length>0&&(0,E.jsxs)(`button`,{onClick:()=>b.mutate(),disabled:!a(`printers:control`)||b.isPending,className:`flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium rounded-lg bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400 hover:bg-red-200 dark:hover:bg-red-500/30 transition-colors disabled:opacity-50 disabled:cursor-not-allowed flex-shrink-0`,children:[b.isPending?(0,E.jsx)(m,{className:`w-4 h-4 animate-spin`}):(0,E.jsx)(v,{className:`w-4 h-4`}),u(`hmsErrors.clearErrors`)]})]})]})})}var H=1,U=16,W=2,G=60,K=[`off`,`compact`,`full`];function q({printers:e,maxLive:t,snapshotIntervalSec:n,statusMode:r,onTileClick:a,onChangeMaxLive:s,onChangeSnapshotIntervalSec:c,onChangeStatusMode:u,statuses:d,showSettings:f=!0,tileSize:p=2}){let{t:m}=o(),h=(0,C.useRef)(new Map),g=d?[]:e,_=l({queries:g.map(e=>({queryKey:[`printerStatus`,e.id],queryFn:()=>i.getPrinterStatus(e.id),staleTime:5e3}))}),v=(0,C.useMemo)(()=>{let e=new Map;return g.forEach((t,n)=>{e.set(t.id,_[n]?.data)}),e},[e,_,d]),y=d??v,[b,S]=(0,C.useState)(()=>new Set),[w,D]=(0,C.useState)(!1),O=(0,C.useRef)(null);(0,C.useEffect)(()=>{if(!w)return;let e=e=>{O.current&&!O.current.contains(e.target)&&D(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[w]),(0,C.useEffect)(()=>{let e=new IntersectionObserver(e=>{S(t=>{let n=new Set(t);for(let t of e){let e=Number(t.target.dataset.printerId);Number.isFinite(e)&&(t.isIntersecting?n.add(e):n.delete(e))}return n})},{threshold:.4});for(let[,t]of h.current)t&&e.observe(t);return()=>e.disconnect()},[e]);let k=(0,C.useMemo)(()=>{let n=new Map,r=Math.max(0,t);for(let t of e){let e=y.get(t.id)?.connected??!1;if(!b.has(t.id)||!e){n.set(t.id,`paused`);continue}r>0?(n.set(t.id,`live`),--r):n.set(t.id,`snapshot`)}return n},[e,b,t,y]);return e.length===0?(0,E.jsx)(`div`,{className:`rounded-lg border border-bambu-dark-tertiary bg-bambu-dark p-6 text-center text-bambu-gray`,children:m(`printers.camWall.noPrinters`)}):(0,E.jsxs)(`div`,{className:`space-y-3`,children:[(0,E.jsxs)(`div`,{className:`flex items-center justify-between text-xs text-bambu-gray`,children:[(0,E.jsx)(`span`,{children:m(`printers.camWall.summary`,{live:Array.from(k.values()).filter(e=>e===`live`).length,snap:Array.from(k.values()).filter(e=>e===`snapshot`).length,total:e.length})}),f&&(0,E.jsxs)(`div`,{className:`relative`,ref:O,children:[(0,E.jsxs)(`button`,{type:`button`,onClick:()=>D(e=>!e),className:`flex h-7 items-center gap-1 rounded-md border border-bambu-dark-tertiary bg-bambu-dark px-2 text-white hover:bg-bambu-dark-tertiary`,title:m(`printers.camWall.settings.title`),children:[(0,E.jsx)(x,{className:`h-3.5 w-3.5`}),(0,E.jsx)(`span`,{children:m(`printers.camWall.settings.title`)})]}),w&&(0,E.jsxs)(`div`,{className:`absolute right-0 top-9 z-30 w-72 space-y-3 rounded-lg border border-bambu-dark-tertiary bg-bambu-dark-secondary p-3 shadow-xl`,children:[(0,E.jsxs)(`label`,{className:`block space-y-1`,children:[(0,E.jsx)(`span`,{className:`text-xs font-medium text-white`,children:m(`printers.camWall.settings.maxLive`)}),(0,E.jsx)(`input`,{type:`number`,min:H,max:U,value:t,onChange:e=>{s(Math.min(U,Math.max(H,Number(e.target.value)||H)))},className:`w-full rounded-md border border-bambu-dark-tertiary bg-bambu-dark px-2 py-1 text-sm text-white`}),(0,E.jsx)(`span`,{className:`block text-[11px] text-bambu-gray`,children:m(`printers.camWall.settings.maxLiveHint`)})]}),(0,E.jsxs)(`label`,{className:`block space-y-1`,children:[(0,E.jsx)(`span`,{className:`text-xs font-medium text-white`,children:m(`printers.camWall.settings.snapshotInterval`)}),(0,E.jsx)(`input`,{type:`number`,min:W,max:G,value:n,onChange:e=>{c(Math.min(G,Math.max(W,Number(e.target.value)||W)))},className:`w-full rounded-md border border-bambu-dark-tertiary bg-bambu-dark px-2 py-1 text-sm text-white`}),(0,E.jsx)(`span`,{className:`block text-[11px] text-bambu-gray`,children:m(`printers.camWall.settings.snapshotIntervalHint`)})]}),(0,E.jsxs)(`div`,{className:`space-y-1`,children:[(0,E.jsx)(`span`,{className:`block text-xs font-medium text-white`,children:m(`printers.camWall.settings.statusOverlay`)}),(0,E.jsx)(`div`,{role:`radiogroup`,"aria-label":m(`printers.camWall.settings.statusOverlay`),className:`flex overflow-hidden rounded-md border border-bambu-dark-tertiary`,children:K.map(e=>(0,E.jsx)(`button`,{type:`button`,role:`radio`,"aria-checked":r===e,onClick:()=>u(e),className:`flex-1 px-2 py-1 text-xs ${r===e?`bg-bambu-green text-black font-semibold`:`bg-bambu-dark text-white hover:bg-bambu-dark-tertiary`}`,children:m(`printers.camWall.statusMode.${e}`)},e))}),(0,E.jsx)(`span`,{className:`block text-[11px] text-bambu-gray`,children:m(`printers.camWall.settings.statusOverlayHint`)})]})]})]})]}),(0,E.jsx)(`div`,{className:`grid gap-3 ${T(p)}`,"data-testid":`camwall-grid`,children:e.map(e=>{let t=k.get(e.id)??`paused`;return(0,E.jsx)(`div`,{ref:t=>{h.current.set(e.id,t)},"data-printer-id":e.id,children:(0,E.jsx)(A,{printerId:e.id,printerName:e.name,cameraRotation:e.camera_rotation,mode:t,snapshotIntervalMs:n*1e3,connected:y.get(e.id)?.connected??!1,statusMode:r,printerState:y.get(e.id)?.state??null,progress:y.get(e.id)?.progress??null,remainingMin:y.get(e.id)?.remaining_time??null,layerNum:y.get(e.id)?.layer_num??null,totalLayers:y.get(e.id)?.total_layers??null,printName:y.get(e.id)?.subtask_name??y.get(e.id)?.gcode_file??null,hmsErrorCount:R(y.get(e.id)?.hms_errors??[]).length,onClick:a?()=>a(e.id,e.name):void 0})},e.id)})})]})}export{w as a,P as i,V as n,R as r,q as t}; \ No newline at end of file +import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,S as r,a as i,l as a,w as o}from"./client-DnySrlFv.js";import{n as s}from"./QueryClientProvider-Ce8_sN3w.js";import{t as c}from"./useMutation-B-Tr2hIP.js";import{t as l}from"./useQueries-Be6PMvSC.js";import{t as u}from"./createLucideIcon-DvBYJlWL.js";import{r as d,t as f}from"./info-ROUoQhJR.js";import{n as p}from"./ToastContext-BRX0SW3C.js";import{t as m}from"./loader-circle-BEmFtawu.js";import{t as h}from"./triangle-alert-Dt_1FcBy.js";import{t as g}from"./x-DR-Trv6U.js";import{o as _}from"./date-G9KUauqz.js";import{At as v,Cn as y,Ct as b,Vt as x}from"./index-Cxa-KVmA.js";var S=u(`video-off`,[[`path`,{d:`M10.66 6H14a2 2 0 0 1 2 2v2.5l5.248-3.062A.5.5 0 0 1 22 7.87v8.196`,key:`w8jjjt`}],[`path`,{d:`M16 16a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h2`,key:`1xawa7`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}]]),C=e(n(),1),w=[`s`,`m`,`l`,`xl`];function T(e){switch(e){case 1:return`grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5`;case 3:return`grid-cols-1 lg:grid-cols-2`;case 4:return`grid-cols-1`;default:return`grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4`}}var E=t(),D=8;function O(e,t){if(t>0)return`error`;switch(e){case`RUNNING`:return`printing`;case`PAUSE`:return`paused`;case`FINISH`:case`FAILED`:return`finished`;default:return`idle`}}var k={printing:`bg-bambu-green/85 text-black`,paused:`bg-amber-500/85 text-black`,finished:`bg-sky-500/80 text-white`,error:`bg-red-500/85 text-white`,idle:`bg-bambu-dark-tertiary/80 text-bambu-gray`};function A({printerId:e,printerName:t,cameraRotation:n=0,mode:i,snapshotIntervalMs:s,connected:c,onClick:l,statusMode:u=`off`,printerState:d=null,progress:f=null,remainingMin:p=null,layerNum:m=null,totalLayers:g=null,printName:v=null,hmsErrorCount:y=0}){let{t:x}=o(),[w,T]=(0,C.useState)(0),[A,j]=(0,C.useState)(!1),M=(0,C.useRef)(i);(0,C.useEffect)(()=>{let t=M.current===`live`,n=i===`live`;if(M.current=i,t&&!n){let t={},n=a();n&&(t.Authorization=`Bearer ${n}`),fetch(`/api/v1/printers/${e}/camera/stop`,{method:`POST`,keepalive:!0,headers:t}).catch(()=>{})}j(!1),T(e=>e+1)},[i,e]),(0,C.useEffect)(()=>()=>{if(M.current===`live`){let t={},n=a();n&&(t.Authorization=`Bearer ${n}`),fetch(`/api/v1/printers/${e}/camera/stop`,{method:`POST`,keepalive:!0,headers:t}).catch(()=>{})}},[e]),(0,C.useEffect)(()=>{if(i!==`snapshot`)return;let e=setInterval(()=>T(e=>e+1),s);return()=>clearInterval(e)},[i,s]);let N=r(`/api/v1/printers/${e}/camera/stream?fps=${D}&t=${w}`),P=r(`/api/v1/printers/${e}/camera/snapshot?t=${w}`),F=l!=null,I=n?`rotate(${n}deg)`:void 0,L=O(d,y),R=c&&u!==`off`&&L!==`idle`,z=c&&u===`full`&&(L===`printing`||L===`paused`),B=v??null,V=f==null?null:Math.round(f),H=m!=null&&g!=null&&g>0,U=p!=null&&p>0,W=`group relative aspect-video w-full overflow-hidden rounded-lg border border-bambu-dark-tertiary bg-black text-left ${F?`focus:outline-none focus:ring-2 focus:ring-bambu-green`:`cursor-default`}`,G=(0,E.jsxs)(E.Fragment,{children:[!c||i===`paused`?(0,E.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-bambu-dark/60`,children:c?(0,E.jsx)(S,{className:`h-8 w-8 text-bambu-gray/70`,"aria-hidden":`true`}):(0,E.jsx)(b,{className:`h-8 w-8 text-bambu-gray/70`,"aria-hidden":`true`})}):A?(0,E.jsxs)(`div`,{className:`absolute inset-0 flex flex-col items-center justify-center gap-1 bg-black/80 text-bambu-gray`,children:[(0,E.jsx)(S,{className:`h-7 w-7`,"aria-hidden":`true`}),(0,E.jsx)(`span`,{className:`text-xs`,children:x(`printers.camWall.noSignal`)})]}):(0,E.jsx)(`img`,{src:i===`live`?N:P,alt:t,draggable:!1,loading:`lazy`,className:`h-full w-full select-none object-contain`,style:{transform:I},onError:()=>j(!0)},`${i}-${w}`),R&&(0,E.jsxs)(`span`,{className:`absolute left-2 top-2 flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] font-semibold uppercase tracking-wide ${k[L]}`,children:[y>0&&(0,E.jsx)(h,{className:`h-3 w-3`,"aria-hidden":`true`}),(0,E.jsx)(`span`,{children:x(`printers.status.${L}`)})]}),(0,E.jsx)(`span`,{className:`absolute right-2 top-2 rounded px-1.5 py-0.5 text-[10px] font-semibold uppercase tracking-wide ${i===`live`?`bg-red-500/80 text-white`:i===`snapshot`?`bg-amber-500/70 text-black`:`bg-bambu-dark-tertiary/70 text-bambu-gray`}`,children:x(i===`live`?`printers.camWall.live`:i===`snapshot`?`printers.camWall.snap`:`printers.camWall.off`)}),(0,E.jsxs)(`div`,{className:`absolute inset-x-0 bottom-0 bg-gradient-to-t from-black/85 via-black/55 to-transparent px-2 pb-1.5 pt-3 text-white`,children:[z&&(0,E.jsxs)(`div`,{className:`mb-0.5 space-y-0.5 text-[11px] leading-tight text-white/90`,children:[B&&(0,E.jsx)(`div`,{className:`truncate`,title:B,children:B}),(0,E.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-0.5 text-bambu-gray`,children:[V!=null&&(0,E.jsxs)(`span`,{className:`font-semibold text-white`,children:[V,`%`]}),H&&(0,E.jsx)(`span`,{children:x(`printers.camWall.layer`,{cur:m,total:g})}),U&&(0,E.jsx)(`span`,{children:x(`printers.camWall.timeLeft`,{time:_((p??0)*60)})})]})]}),(0,E.jsx)(`span`,{className:`block truncate text-xs font-medium`,children:t})]})]});return F?(0,E.jsx)(`button`,{type:`button`,onClick:l,className:W,title:t,children:G}):(0,E.jsx)(`div`,{className:W,title:t,children:G})}var j=new Set([`0700_8011`,`0701_8011`,`0702_8011`,`0703_8011`,`0704_8011`,`0705_8011`,`0706_8011`,`0707_8011`,`07FF_8011`]),M=`0500050000010007`;function N(e){switch(e){case 1:return{labelKey:`hmsErrors.severityError`,color:`text-red-600 dark:text-red-400`,bgColor:`bg-red-100 dark:bg-red-500/20`,Icon:h};case 2:return{labelKey:`hmsErrors.severityWarning`,color:`text-orange-700 dark:text-orange-400`,bgColor:`bg-orange-100 dark:bg-orange-500/20`,Icon:h};case 3:return{labelKey:`hmsErrors.severityNotice`,color:`text-blue-700 dark:text-blue-400`,bgColor:`bg-blue-100 dark:bg-blue-500/20`,Icon:f};default:return{labelKey:`hmsErrors.severityUnknown`,color:`text-bambu-gray`,bgColor:`bg-bambu-dark-tertiary`,Icon:d}}}function P(e){return e.severity===1||e.severity===2}function F(e,t){let n=e>>16&65535||(e>>8&255)<<8|e&255,r=t&65535;return`${n.toString(16).padStart(4,`0`).toUpperCase()}_${r.toString(16).padStart(4,`0`).toUpperCase()}`}function I(e){if(e.full_code&&e.full_code.length===16)return e.full_code.match(/.{4}/g).join(`-`);let t=parseInt(e.code.replace(`0x`,``),16)||0;return F(e.attr,t).replace(`_`,`-`)}function L(e){if(!(e.severity>=1))return!1;if((e.actions?.length??0)>0)return!0;let t=e.full_code?.length===16&&e.severity===3;return!!e.description&&!t}function R(e){return e.filter(L)}function z(e){return e.filter(e=>!L(e))}function B(){return`https://wiki.bambulab.com/en/hms/home`}function V({printerName:e,errors:t,onClose:n,printerId:r,hasPermission:a,runoutGuidance:l}){let{t:u}=o(),{showToast:f}=p(),_=s(),b=c({mutationFn:()=>i.clearHMSErrors(r),onSuccess:()=>{f(u(`hmsErrors.clearSuccess`),`success`),n()},onError:()=>{f(u(`hmsErrors.clearFailed`),`error`)}}),x=R(t),S=z(t);(0,C.useEffect)(()=>{let e=e=>{e.key===`Escape`&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n]);let w=c({mutationFn:e=>i.executeHMSAction(r,{action:e.action,print_error:e.print_error,job_id:e.job_id}),onSuccess:()=>{_.invalidateQueries({queryKey:[`printerStatus`,r]}),f(u(`hmsErrors.actionSuccess`,`Action sent to printer`),`success`),n()},onError:e=>{f(`${u(`hmsErrors.actionFailed`,`Failed to send action`)}: ${e.message}`,`error`)}});return(0,E.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,children:(0,E.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg shadow-xl max-w-lg w-full max-h-[80vh] flex flex-col`,children:[(0,E.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,E.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,E.jsx)(h,{className:`w-5 h-5 text-orange-600 dark:text-orange-400`}),(0,E.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:u(`hmsErrors.title`,{name:e})})]}),(0,E.jsx)(`button`,{onClick:n,className:`p-1 hover:bg-bambu-dark-tertiary rounded-lg transition-colors`,children:(0,E.jsx)(g,{className:`w-5 h-5 text-bambu-gray`})})]}),(0,E.jsx)(`div`,{className:`flex-1 overflow-y-auto p-4`,children:x.length===0&&S.length===0?(0,E.jsxs)(`div`,{className:`text-center py-8 text-bambu-gray`,children:[(0,E.jsx)(d,{className:`w-12 h-12 mx-auto mb-3 opacity-30`}),(0,E.jsx)(`p`,{children:u(`hmsErrors.noErrors`)})]}):(0,E.jsxs)(`div`,{className:`space-y-3`,children:[x.map((e,t)=>{let{labelKey:n,color:r,bgColor:i,Icon:o}=N(e.severity),s=parseInt(e.code.replace(`0x`,``),16)||0,c=F(e.attr,s),d=e.description||u(`hmsErrors.unknownCode`),f=e.full_code===M;f&&(d=u(`hmsErrors.mqttVerifyFailedDescription`));let p=f?u(`hmsErrors.mqttVerifyFailedRemedy`):null;l&&j.has(c)&&(d=l.expectedSlotLabel&&l.ranOutSlotLabel?u(`hmsErrors.runoutExpectedSlot`,{expected:l.expectedSlotLabel,ranOut:l.ranOutSlotLabel}):l.expectedSlotLabel?u(`hmsErrors.runoutExpectedSlotOnly`,{expected:l.expectedSlotLabel}):u(`hmsErrors.runoutSlotUnknown`));let h=B(),g=I(e);return(0,E.jsx)(`div`,{className:`p-4 rounded-lg ${i} border border-white/10`,children:(0,E.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,E.jsx)(o,{className:`w-5 h-5 ${r} flex-shrink-0 mt-0.5`}),(0,E.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,E.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,E.jsxs)(`span`,{className:`font-mono text-sm ${r}`,children:[`[`,g,`]`]}),(0,E.jsx)(`span`,{className:`text-xs px-2 py-0.5 rounded-full ${i} ${r}`,children:u(n)})]}),(0,E.jsx)(`p`,{className:`text-sm text-bambu-gray mb-2`,children:d}),p&&(0,E.jsx)(`p`,{className:`text-sm text-bambu-gray mb-2`,children:p}),e.actions&&e.actions.length>0&&(0,E.jsx)(`div`,{className:`flex flex-wrap gap-2 my-2`,children:e.actions.map(t=>{let n=w.variables,r=w.isPending&&n?.action===t&&n?.print_error===(e.full_code||c.replace(`_`,``));return(0,E.jsxs)(`button`,{onClick:()=>{w.mutate({action:t,print_error:e.full_code||c.replace(`_`,``),job_id:e.job_id??null})},disabled:!a(`printers:control`)||w.isPending,className:`flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium rounded-lg bg-white/10 hover:bg-white/20 active:bg-white/30 text-white border border-white/20 hover:border-white/30 transition-colors disabled:opacity-50 disabled:cursor-not-allowed flex-shrink-0`,children:[r&&(0,E.jsx)(m,{className:`w-4 h-4 animate-spin`}),u(`hmsErrors.actions.${t}`,t)]},t)})}),(0,E.jsxs)(`a`,{href:h,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-1 text-xs text-bambu-green hover:underline`,children:[(0,E.jsx)(y,{className:`w-3 h-3`}),u(`hmsErrors.viewOnWiki`)]})]})]})},`${e.code}-${t}`)}),S.length>0&&(0,E.jsxs)(`details`,{className:`rounded-lg border border-white/10 p-3`,"data-testid":`hms-uncounted`,children:[(0,E.jsx)(`summary`,{className:`cursor-pointer text-sm text-bambu-gray`,children:u(`hmsErrors.uncountedSummary`,{n:S.length})}),(0,E.jsx)(`p`,{className:`mt-2 text-xs text-bambu-gray`,children:u(`hmsErrors.uncountedHint`)}),(0,E.jsx)(`ul`,{className:`mt-2 space-y-2`,children:S.map((e,t)=>(0,E.jsxs)(`li`,{className:`text-xs`,children:[(0,E.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,E.jsxs)(`span`,{className:`font-mono text-bambu-gray`,children:[`[`,I(e),`]`]}),(0,E.jsx)(`span`,{className:`text-bambu-gray`,children:u(N(e.severity).labelKey)})]}),e.description&&(0,E.jsx)(`p`,{className:`mt-0.5 text-bambu-gray`,children:e.description})]},`${e.full_code||e.code}-${t}`))})]})]})}),(0,E.jsxs)(`div`,{className:`p-4 border-t border-bambu-dark-tertiary flex items-center justify-between gap-3`,children:[(0,E.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:u(`hmsErrors.clearInstructions`)}),t.length>0&&(0,E.jsxs)(`button`,{onClick:()=>b.mutate(),disabled:!a(`printers:control`)||b.isPending,className:`flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium rounded-lg bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400 hover:bg-red-200 dark:hover:bg-red-500/30 transition-colors disabled:opacity-50 disabled:cursor-not-allowed flex-shrink-0`,children:[b.isPending?(0,E.jsx)(m,{className:`w-4 h-4 animate-spin`}):(0,E.jsx)(v,{className:`w-4 h-4`}),u(`hmsErrors.clearErrors`)]})]})]})})}var H=1,U=16,W=2,G=60,K=[`off`,`compact`,`full`];function q({printers:e,maxLive:t,snapshotIntervalSec:n,statusMode:r,onTileClick:a,onChangeMaxLive:s,onChangeSnapshotIntervalSec:c,onChangeStatusMode:u,statuses:d,showSettings:f=!0,tileSize:p=2}){let{t:m}=o(),h=(0,C.useRef)(new Map),g=d?[]:e,_=l({queries:g.map(e=>({queryKey:[`printerStatus`,e.id],queryFn:()=>i.getPrinterStatus(e.id),staleTime:5e3}))}),v=(0,C.useMemo)(()=>{let e=new Map;return g.forEach((t,n)=>{e.set(t.id,_[n]?.data)}),e},[e,_,d]),y=d??v,[b,S]=(0,C.useState)(()=>new Set),[w,D]=(0,C.useState)(!1),O=(0,C.useRef)(null);(0,C.useEffect)(()=>{if(!w)return;let e=e=>{O.current&&!O.current.contains(e.target)&&D(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[w]),(0,C.useEffect)(()=>{let e=new IntersectionObserver(e=>{S(t=>{let n=new Set(t);for(let t of e){let e=Number(t.target.dataset.printerId);Number.isFinite(e)&&(t.isIntersecting?n.add(e):n.delete(e))}return n})},{threshold:.4});for(let[,t]of h.current)t&&e.observe(t);return()=>e.disconnect()},[e]);let k=(0,C.useMemo)(()=>{let n=new Map,r=Math.max(0,t);for(let t of e){let e=y.get(t.id)?.connected??!1;if(!b.has(t.id)||!e){n.set(t.id,`paused`);continue}r>0?(n.set(t.id,`live`),--r):n.set(t.id,`snapshot`)}return n},[e,b,t,y]);return e.length===0?(0,E.jsx)(`div`,{className:`rounded-lg border border-bambu-dark-tertiary bg-bambu-dark p-6 text-center text-bambu-gray`,children:m(`printers.camWall.noPrinters`)}):(0,E.jsxs)(`div`,{className:`space-y-3`,children:[(0,E.jsxs)(`div`,{className:`flex items-center justify-between text-xs text-bambu-gray`,children:[(0,E.jsx)(`span`,{children:m(`printers.camWall.summary`,{live:Array.from(k.values()).filter(e=>e===`live`).length,snap:Array.from(k.values()).filter(e=>e===`snapshot`).length,total:e.length})}),f&&(0,E.jsxs)(`div`,{className:`relative`,ref:O,children:[(0,E.jsxs)(`button`,{type:`button`,onClick:()=>D(e=>!e),className:`flex h-7 items-center gap-1 rounded-md border border-bambu-dark-tertiary bg-bambu-dark px-2 text-white hover:bg-bambu-dark-tertiary`,title:m(`printers.camWall.settings.title`),children:[(0,E.jsx)(x,{className:`h-3.5 w-3.5`}),(0,E.jsx)(`span`,{children:m(`printers.camWall.settings.title`)})]}),w&&(0,E.jsxs)(`div`,{className:`absolute right-0 top-9 z-30 w-72 space-y-3 rounded-lg border border-bambu-dark-tertiary bg-bambu-dark-secondary p-3 shadow-xl`,children:[(0,E.jsxs)(`label`,{className:`block space-y-1`,children:[(0,E.jsx)(`span`,{className:`text-xs font-medium text-white`,children:m(`printers.camWall.settings.maxLive`)}),(0,E.jsx)(`input`,{type:`number`,min:H,max:U,value:t,onChange:e=>{s(Math.min(U,Math.max(H,Number(e.target.value)||H)))},className:`w-full rounded-md border border-bambu-dark-tertiary bg-bambu-dark px-2 py-1 text-sm text-white`}),(0,E.jsx)(`span`,{className:`block text-[11px] text-bambu-gray`,children:m(`printers.camWall.settings.maxLiveHint`)})]}),(0,E.jsxs)(`label`,{className:`block space-y-1`,children:[(0,E.jsx)(`span`,{className:`text-xs font-medium text-white`,children:m(`printers.camWall.settings.snapshotInterval`)}),(0,E.jsx)(`input`,{type:`number`,min:W,max:G,value:n,onChange:e=>{c(Math.min(G,Math.max(W,Number(e.target.value)||W)))},className:`w-full rounded-md border border-bambu-dark-tertiary bg-bambu-dark px-2 py-1 text-sm text-white`}),(0,E.jsx)(`span`,{className:`block text-[11px] text-bambu-gray`,children:m(`printers.camWall.settings.snapshotIntervalHint`)})]}),(0,E.jsxs)(`div`,{className:`space-y-1`,children:[(0,E.jsx)(`span`,{className:`block text-xs font-medium text-white`,children:m(`printers.camWall.settings.statusOverlay`)}),(0,E.jsx)(`div`,{role:`radiogroup`,"aria-label":m(`printers.camWall.settings.statusOverlay`),className:`flex overflow-hidden rounded-md border border-bambu-dark-tertiary`,children:K.map(e=>(0,E.jsx)(`button`,{type:`button`,role:`radio`,"aria-checked":r===e,onClick:()=>u(e),className:`flex-1 px-2 py-1 text-xs ${r===e?`bg-bambu-green text-black font-semibold`:`bg-bambu-dark text-white hover:bg-bambu-dark-tertiary`}`,children:m(`printers.camWall.statusMode.${e}`)},e))}),(0,E.jsx)(`span`,{className:`block text-[11px] text-bambu-gray`,children:m(`printers.camWall.settings.statusOverlayHint`)})]})]})]})]}),(0,E.jsx)(`div`,{className:`grid gap-3 ${T(p)}`,"data-testid":`camwall-grid`,children:e.map(e=>{let t=k.get(e.id)??`paused`;return(0,E.jsx)(`div`,{ref:t=>{h.current.set(e.id,t)},"data-printer-id":e.id,children:(0,E.jsx)(A,{printerId:e.id,printerName:e.name,cameraRotation:e.camera_rotation,mode:t,snapshotIntervalMs:n*1e3,connected:y.get(e.id)?.connected??!1,statusMode:r,printerState:y.get(e.id)?.state??null,progress:y.get(e.id)?.progress??null,remainingMin:y.get(e.id)?.remaining_time??null,layerNum:y.get(e.id)?.layer_num??null,totalLayers:y.get(e.id)?.total_layers??null,printName:y.get(e.id)?.subtask_name??y.get(e.id)?.gcode_file??null,hmsErrorCount:R(y.get(e.id)?.hms_errors??[]).length,onClick:a?()=>a(e.id,e.name):void 0})},e.id)})})]})}export{w as a,P as i,V as n,R as r,q as t}; \ No newline at end of file diff --git a/static/assets/ColumnConfigModal-DrIkn1Rf.js b/static/assets/ColumnConfigModal-BBpKz9m6.js similarity index 98% rename from static/assets/ColumnConfigModal-DrIkn1Rf.js rename to static/assets/ColumnConfigModal-BBpKz9m6.js index 068624472..508f3432d 100644 --- a/static/assets/ColumnConfigModal-DrIkn1Rf.js +++ b/static/assets/ColumnConfigModal-BBpKz9m6.js @@ -1 +1 @@ -import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,w as r}from"./client-DnySrlFv.js";import{a as i,i as a}from"./info-ROUoQhJR.js";import{t as o}from"./eye-off-6CkaxYwP.js";import{t as s}from"./grip-vertical-C_1RDxRw.js";import{n as c,t as l}from"./Card-Bzc64K35.js";import{t as u}from"./Button-DDr6eAFy.js";import{Gt as d,Sn as f}from"./index-0t--Yqoi.js";var p=e(n(),1),m=t();function h({isOpen:e,onClose:t,columns:n,defaultColumns:h,onSave:g}){let{t:_}=r(),[v,y]=(0,p.useState)(n),[b,x]=(0,p.useState)(null),S=(0,p.useRef)(null);if((0,p.useEffect)(()=>{e&&y(n.map(e=>({...e})))},[e,n]),(0,p.useEffect)(()=>{if(!e)return;let n=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,n),()=>window.removeEventListener(`keydown`,n)},[e,t]),!e)return null;let C=e=>{y(t=>t.map((t,n)=>n===e?{...t,visible:!t.visible}:t))},w=(e,t)=>{t<0||t>=v.length||y(n=>{let r=[...n],[i]=r.splice(e,1);return r.splice(t,0,i),r})},T=(e,t)=>{S.current=t,x(t),e.dataTransfer.effectAllowed=`move`},E=(e,t)=>{e.preventDefault(),e.dataTransfer.dropEffect=`move`;let n=S.current;n!==null&&n!==t&&(w(n,t),S.current=t,x(t))},D=e=>{e.preventDefault()},O=()=>{S.current=null,x(null)},k=()=>{y(h.map(e=>({...e})))},A=()=>{g(v),t()},j=v.filter(e=>e.visible).length;return(0,m.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,onClick:t,children:(0,m.jsx)(l,{className:`w-full max-w-md max-h-[80vh] flex flex-col`,onClick:e=>e.stopPropagation(),children:(0,m.jsxs)(c,{className:`p-6 flex flex-col min-h-0`,children:[(0,m.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-2`,children:_(`inventory.configureColumns`)}),(0,m.jsxs)(`p`,{className:`text-sm text-bambu-gray mb-4`,children:[_(`inventory.configureColumnsDesc`),(0,m.jsxs)(`span`,{className:`ml-2 text-bambu-gray/60`,children:[`(`,j,` `,_(`inventory.of`),` `,v.length,` `,_(`inventory.visible`),`)`]})]}),(0,m.jsx)(`div`,{className:`space-y-1 overflow-y-auto flex-1 min-h-0 pr-1`,children:v.map((e,t)=>(0,m.jsxs)(`div`,{className:`flex items-center gap-2 p-2 rounded-lg border transition-colors ${b===t?`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary bg-bambu-dark-tertiary/50`} ${e.visible?``:`opacity-50`}`,draggable:!0,onDragStart:e=>T(e,t),onDragOver:e=>E(e,t),onDrop:D,onDragEnd:O,children:[(0,m.jsx)(`div`,{className:`cursor-grab text-bambu-gray/50 hover:text-bambu-gray`,children:(0,m.jsx)(s,{className:`w-4 h-4`})}),(0,m.jsx)(`span`,{className:`flex-1 font-medium text-sm text-white`,children:e.label}),(0,m.jsxs)(`div`,{className:`flex items-center gap-0.5`,children:[(0,m.jsx)(`button`,{onClick:()=>w(t,t-1),disabled:t===0,className:`p-1 rounded text-bambu-gray hover:bg-bambu-dark-secondary disabled:opacity-30 disabled:cursor-not-allowed`,title:_(`inventory.moveUp`),children:(0,m.jsx)(a,{className:`w-4 h-4`})}),(0,m.jsx)(`button`,{onClick:()=>w(t,t+1),disabled:t===v.length-1,className:`p-1 rounded text-bambu-gray hover:bg-bambu-dark-secondary disabled:opacity-30 disabled:cursor-not-allowed`,title:_(`inventory.moveDown`),children:(0,m.jsx)(i,{className:`w-4 h-4`})})]}),(0,m.jsx)(`button`,{onClick:()=>C(t),className:`p-1.5 rounded transition-colors ${e.visible?`text-bambu-green hover:bg-bambu-green/10`:`text-bambu-gray/50 hover:bg-bambu-dark-secondary`}`,title:e.visible?_(`inventory.hideColumn`):_(`inventory.showColumn`),children:e.visible?(0,m.jsx)(f,{className:`w-4 h-4`}):(0,m.jsx)(o,{className:`w-4 h-4`})})]},e.id))}),(0,m.jsxs)(`div`,{className:`flex items-center gap-3 mt-4 pt-4 border-t border-bambu-dark-tertiary`,children:[(0,m.jsxs)(u,{variant:`secondary`,onClick:k,className:`mr-auto`,children:[(0,m.jsx)(d,{className:`w-4 h-4`}),_(`inventory.reset`)]}),(0,m.jsx)(u,{variant:`secondary`,onClick:t,children:_(`inventory.cancel`)}),(0,m.jsx)(u,{onClick:A,children:_(`inventory.applyChanges`)})]})]})})})}export{h as t}; \ No newline at end of file +import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,w as r}from"./client-DnySrlFv.js";import{a as i,i as a}from"./info-ROUoQhJR.js";import{t as o}from"./eye-off-6CkaxYwP.js";import{t as s}from"./grip-vertical-C_1RDxRw.js";import{n as c,t as l}from"./Card-Bzc64K35.js";import{t as u}from"./Button-DDr6eAFy.js";import{Gt as d,Sn as f}from"./index-Cxa-KVmA.js";var p=e(n(),1),m=t();function h({isOpen:e,onClose:t,columns:n,defaultColumns:h,onSave:g}){let{t:_}=r(),[v,y]=(0,p.useState)(n),[b,x]=(0,p.useState)(null),S=(0,p.useRef)(null);if((0,p.useEffect)(()=>{e&&y(n.map(e=>({...e})))},[e,n]),(0,p.useEffect)(()=>{if(!e)return;let n=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,n),()=>window.removeEventListener(`keydown`,n)},[e,t]),!e)return null;let C=e=>{y(t=>t.map((t,n)=>n===e?{...t,visible:!t.visible}:t))},w=(e,t)=>{t<0||t>=v.length||y(n=>{let r=[...n],[i]=r.splice(e,1);return r.splice(t,0,i),r})},T=(e,t)=>{S.current=t,x(t),e.dataTransfer.effectAllowed=`move`},E=(e,t)=>{e.preventDefault(),e.dataTransfer.dropEffect=`move`;let n=S.current;n!==null&&n!==t&&(w(n,t),S.current=t,x(t))},D=e=>{e.preventDefault()},O=()=>{S.current=null,x(null)},k=()=>{y(h.map(e=>({...e})))},A=()=>{g(v),t()},j=v.filter(e=>e.visible).length;return(0,m.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,onClick:t,children:(0,m.jsx)(l,{className:`w-full max-w-md max-h-[80vh] flex flex-col`,onClick:e=>e.stopPropagation(),children:(0,m.jsxs)(c,{className:`p-6 flex flex-col min-h-0`,children:[(0,m.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-2`,children:_(`inventory.configureColumns`)}),(0,m.jsxs)(`p`,{className:`text-sm text-bambu-gray mb-4`,children:[_(`inventory.configureColumnsDesc`),(0,m.jsxs)(`span`,{className:`ml-2 text-bambu-gray/60`,children:[`(`,j,` `,_(`inventory.of`),` `,v.length,` `,_(`inventory.visible`),`)`]})]}),(0,m.jsx)(`div`,{className:`space-y-1 overflow-y-auto flex-1 min-h-0 pr-1`,children:v.map((e,t)=>(0,m.jsxs)(`div`,{className:`flex items-center gap-2 p-2 rounded-lg border transition-colors ${b===t?`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary bg-bambu-dark-tertiary/50`} ${e.visible?``:`opacity-50`}`,draggable:!0,onDragStart:e=>T(e,t),onDragOver:e=>E(e,t),onDrop:D,onDragEnd:O,children:[(0,m.jsx)(`div`,{className:`cursor-grab text-bambu-gray/50 hover:text-bambu-gray`,children:(0,m.jsx)(s,{className:`w-4 h-4`})}),(0,m.jsx)(`span`,{className:`flex-1 font-medium text-sm text-white`,children:e.label}),(0,m.jsxs)(`div`,{className:`flex items-center gap-0.5`,children:[(0,m.jsx)(`button`,{onClick:()=>w(t,t-1),disabled:t===0,className:`p-1 rounded text-bambu-gray hover:bg-bambu-dark-secondary disabled:opacity-30 disabled:cursor-not-allowed`,title:_(`inventory.moveUp`),children:(0,m.jsx)(a,{className:`w-4 h-4`})}),(0,m.jsx)(`button`,{onClick:()=>w(t,t+1),disabled:t===v.length-1,className:`p-1 rounded text-bambu-gray hover:bg-bambu-dark-secondary disabled:opacity-30 disabled:cursor-not-allowed`,title:_(`inventory.moveDown`),children:(0,m.jsx)(i,{className:`w-4 h-4`})})]}),(0,m.jsx)(`button`,{onClick:()=>C(t),className:`p-1.5 rounded transition-colors ${e.visible?`text-bambu-green hover:bg-bambu-green/10`:`text-bambu-gray/50 hover:bg-bambu-dark-secondary`}`,title:e.visible?_(`inventory.hideColumn`):_(`inventory.showColumn`),children:e.visible?(0,m.jsx)(f,{className:`w-4 h-4`}):(0,m.jsx)(o,{className:`w-4 h-4`})})]},e.id))}),(0,m.jsxs)(`div`,{className:`flex items-center gap-3 mt-4 pt-4 border-t border-bambu-dark-tertiary`,children:[(0,m.jsxs)(u,{variant:`secondary`,onClick:k,className:`mr-auto`,children:[(0,m.jsx)(d,{className:`w-4 h-4`}),_(`inventory.reset`)]}),(0,m.jsx)(u,{variant:`secondary`,onClick:t,children:_(`inventory.cancel`)}),(0,m.jsx)(u,{onClick:A,children:_(`inventory.applyChanges`)})]})]})})})}export{h as t}; \ No newline at end of file diff --git a/static/assets/ConfigureAmsSlotModal-D0mYskEf.js b/static/assets/ConfigureAmsSlotModal-BgpDvjjX.js similarity index 99% rename from static/assets/ConfigureAmsSlotModal-D0mYskEf.js rename to static/assets/ConfigureAmsSlotModal-BgpDvjjX.js index 273e6dd54..724ee22b8 100644 --- a/static/assets/ConfigureAmsSlotModal-D0mYskEf.js +++ b/static/assets/ConfigureAmsSlotModal-BgpDvjjX.js @@ -1 +1 @@ -import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,w as i}from"./client-DnySrlFv.js";import{n as a}from"./QueryClientProvider-Ce8_sN3w.js";import{t as o}from"./useQuery-BBCjCezC.js";import{t as s}from"./useMutation-B-Tr2hIP.js";import{a as c}from"./info-ROUoQhJR.js";import{n as l}from"./ToastContext-BRX0SW3C.js";import{t as u}from"./loader-circle-BEmFtawu.js";import{t as d}from"./package-BGUevlqS.js";import{t as f}from"./search-0n0CBc74.js";import{t as p}from"./settings-2-Cvn837lh.js";import{t as ee}from"./x-DR-Trv6U.js";import{t as m}from"./Button-DDr6eAFy.js";import{An as h,Gt as g,U as _,_t as v,ft as y,lt as b,sn as x}from"./index-0t--Yqoi.js";import{a as S,i as C,n as w,r as T}from"./slicerPrinterMatch-CUdoNag2.js";import{p as E}from"./utils-DVekehs6.js";import{t as te}from"./inventorySearch-C_D57LMP.js";import{t as ne}from"./useCancellableTimeout-3XQzNJkJ.js";var D=e(n(),1),O=t();function k({isOpen:e,onClose:t,tagUid:n,trayUuid:c,printerId:d,amsId:p,trayId:h}){let{t:g}=i(),_=a(),{showToast:v}=l(),[y,S]=(0,D.useState)(``),C=c||n,{data:w,isLoading:T}=o({queryKey:[`unlinked-spools`],queryFn:r.getUnlinkedSpools,enabled:e}),E=(0,D.useMemo)(()=>w?w.filter(e=>{if(!y)return!0;let t=y.toLowerCase();return e.filament_name&&e.filament_name.toLowerCase().includes(t)||e.filament_vendor&&e.filament_vendor.toLowerCase().includes(t)||e.filament_material&&e.filament_material.toLowerCase().includes(t)||String(e.id).includes(t)}):[],[w,y]),te=s({mutationFn:e=>r.linkSpool(e,{spoolTag:C,printerId:d,amsId:p,trayId:h}),onSuccess:()=>{_.invalidateQueries({queryKey:[`unlinked-spools`]}),_.invalidateQueries({queryKey:[`linked-spools`]}),_.invalidateQueries({queryKey:[`spoolman-slot-assignments`]}),v(g(`spoolman.linkSuccess`),`success`),t()},onError:e=>{v(e.message||g(`spoolman.linkFailed`),`error`)}});return e?(0,O.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[(0,O.jsx)(`div`,{className:`absolute inset-0 bg-black/60 backdrop-blur-sm`,onClick:t}),(0,O.jsxs)(`div`,{className:`relative bg-bambu-dark-secondary rounded-xl shadow-xl w-full max-w-md mx-4 max-h-[80vh] flex flex-col border border-bambu-dark-tertiary`,children:[(0,O.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-white/10`,children:[(0,O.jsxs)(`div`,{children:[(0,O.jsxs)(`h3`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,O.jsx)(x,{className:`w-5 h-5 text-bambu-green`}),g(`spoolman.selectSpool`)]}),(0,O.jsxs)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:[`AMS `,p,` T`,h,` · Printer #`,d]})]}),(0,O.jsx)(`button`,{onClick:t,className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,O.jsx)(ee,{className:`w-5 h-5`})})]}),(0,O.jsxs)(`div`,{className:`p-4 border-b border-white/10`,children:[(0,O.jsxs)(`div`,{className:`relative`,children:[(0,O.jsx)(f,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,O.jsx)(`input`,{type:`text`,value:y,onChange:e=>S(e.target.value),placeholder:g(`inventory.searchSpools`),className:`w-full pl-9 pr-3 py-2 bg-bambu-dark rounded-lg border border-white/10 text-white text-sm placeholder:text-bambu-gray focus:outline-none focus:border-bambu-green`})]}),(c||n)&&(0,O.jsxs)(`p`,{className:`text-xs text-bambu-gray mt-2 font-mono truncate`,title:c||n,children:[`Tag: `,c||n]})]}),(0,O.jsx)(`div`,{className:`flex-1 overflow-y-auto p-2 min-h-0`,children:T?(0,O.jsx)(`div`,{className:`flex justify-center py-8`,children:(0,O.jsx)(u,{className:`w-6 h-6 animate-spin text-bambu-green`})}):E.length===0?(0,O.jsx)(`p`,{className:`text-center text-bambu-gray py-8 text-sm`,children:g(`inventory.noSpoolsMatch`)}):E.map(e=>(0,O.jsxs)(`button`,{onClick:()=>te.mutate(e.id),disabled:te.isPending||!C,className:`w-full flex items-center gap-3 p-3 rounded-lg hover:bg-white/5 transition-colors text-left`,children:[(0,O.jsx)(`span`,{className:`w-6 h-6 rounded-full border border-black/20 flex-shrink-0`,style:b(e.filament_color_hex)}),(0,O.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,O.jsx)(`div`,{className:`text-sm text-white font-medium truncate`,children:e.filament_name||g(`spoolman.spoolId`)}),(0,O.jsxs)(`div`,{className:`text-xs text-bambu-gray truncate`,children:[e.filament_vendor?`${e.filament_vendor} · `:``,e.filament_material||`Unknown`,` · #`,e.id]})]}),(0,O.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:e.remaining_weight==null?`—`:`${Math.round(e.remaining_weight)}g`})]},e.id))}),(0,O.jsx)(`div`,{className:`p-4 border-t border-white/10 flex justify-end`,children:(0,O.jsx)(m,{variant:`ghost`,onClick:t,children:g(`inventory.cancel`)||`Cancel`})})]})]}):null}function A({isOpen:e,onClose:t,printerId:n,amsId:c,trayId:p,trayInfo:h,spoolmanEnabled:g}){let{t:_}=i(),x=a(),{showToast:S}=l(),[C,w]=(0,D.useState)(!1),[T,E]=(0,D.useState)(null),[ne,k]=(0,D.useState)(null);(0,D.useEffect)(()=>{E(null),k(null)},[C]);let[A,re]=(0,D.useState)(``),[j,ie]=(0,D.useState)(null),[M,ae]=(0,D.useState)(!1),[N,oe]=(0,D.useState)(null);(0,D.useEffect)(()=>{e&&w(!1)},[e]);let{data:se,isLoading:ce}=o({queryKey:[`inventory-spools`,`assign-modal`],queryFn:()=>r.getSpools(!0),enabled:e&&!g}),{data:le}=o({queryKey:[`spool-assignments`],queryFn:()=>r.getAssignments(),enabled:e}),{data:ue}=o({queryKey:[`settings`],queryFn:()=>r.getSettings(),enabled:e}),{data:de,isLoading:P}=o({queryKey:[`spoolman-inventory-spools`,`assign-modal`],queryFn:()=>r.getSpoolmanInventorySpools(!1),enabled:e&&!!g}),{data:F}=o({queryKey:[`spoolman-slot-assignments-all`],queryFn:()=>r.getSpoolmanSlotAssignments(),enabled:e&&!!g}),I=(0,D.useMemo)(()=>F?new Set(F.filter(e=>!(e.printer_id===n&&e.ams_id===c&&e.tray_id===p)).map(e=>e.spoolman_spool_id)):new Set,[F,n,c,p]),L=()=>{r.refreshPrinterStatus(n).catch(()=>{}),x.invalidateQueries({queryKey:[`printerStatus`,n]})},R=s({mutationFn:e=>r.assignSpool({spool_id:e,printer_id:n,ams_id:c,tray_id:p}),onSuccess:e=>{x.setQueryData([`spool-assignments`],t=>{let r=(t||[]).filter(e=>!(e.printer_id===n&&e.ams_id===c&&e.tray_id===p));return r.push(e),r}),x.invalidateQueries({queryKey:[`spool-assignments`]}),L(),S(_(e.pending_config?`inventory.assignPendingInsert`:`inventory.assignSuccess`),`success`),ae(!1),ie(null),oe(null),t()},onError:e=>{S(`${_(`inventory.assignFailed`)}: ${e.message}`,`error`)}}),z=s({mutationFn:e=>r.assignSpoolmanSlot({spoolman_spool_id:e,printer_id:n,ams_id:c,tray_id:p}),onSuccess:()=>{x.invalidateQueries({queryKey:[`spoolman-inventory-spools`]}),x.invalidateQueries({queryKey:[`spoolman-slot-assignments`]}),L(),S(_(`inventory.assignSuccess`),`success`),t()},onError:e=>{S(`${_(`inventory.assignFailed`)}: ${e.message}`,`error`)}}),B=e=>(e??``).trim().toUpperCase(),V=(e,t)=>{let n=B(e),r=B(t);return!n||!r?`none`:n===r?`exact`:r.includes(n)||n.includes(r)?`partial`:`none`},H=e=>e.split(`@`)[0].trim(),fe=(e,t)=>{let n=H(B(e)),r=H(B(t));return!n||!r?!1:n===r};if(!e)return null;let pe=new Set((le||[]).filter(e=>!(e.printer_id===n&&e.ams_id===c&&e.tray_id===p)).map(e=>e.spool_id)),U=se?.filter(e=>!e.archived_at&&(C||!pe.has(e.id))),W=U;if(!C){let e=H(B(h?.profile)),t=B(h?.material||h?.type);(e||t)&&(W=W?.filter(n=>{let r=H(B(n.slicer_filament_name||n.slicer_filament)),i=B(n.material);return e&&r&&r===e?!0:t&&i?i===t||t.includes(i)||i.includes(t):!r&&!i}))}A&&W&&(W=te(W,A));let me=()=>{if(ne!==null){z.mutate(ne);return}if(!T)return;let e=se?.find(e=>e.id===T);if(!e){S(_(`inventory.assignFailed`),`error`);return}if(!ue?.disable_filament_warnings&&h){let t=h.material||h.type,n=V(e.material,t),r=e.slicer_filament_name||e.slicer_filament,i=h.profile||h.type,a=fe(r,i);if(n!==`exact`){let o;o=n===`none`&&!a?`material_profile`:n===`partial`&&!a?`partial_profile`:n===`none`?`material`:`partial`,ie(T),oe({type:o,spoolMaterial:e.material||``,trayMaterial:t||``,spoolProfile:r||void 0,trayProfile:i||void 0}),ae(!0);return}}R.mutate(T)},he=()=>{j&&(R.mutate(j),ae(!1),ie(null))};return(0,O.jsxs)(O.Fragment,{children:[(0,O.jsxs)(`div`,{className:`fixed inset-0 z-[100] flex items-start sm:items-center justify-center p-4 overflow-y-auto`,children:[(0,O.jsx)(`div`,{className:`absolute inset-0 bg-black/60 backdrop-blur-sm`,onClick:t}),(0,O.jsxs)(`div`,{className:`relative w-full max-w-2xl bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl max-h-[90vh] overflow-hidden flex flex-col my-auto`,children:[(0,O.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,O.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,O.jsx)(d,{className:`w-5 h-5 text-bambu-green`}),(0,O.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:_(`inventory.assignSpool`)})]}),(0,O.jsx)(`button`,{onClick:t,className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,O.jsx)(ee,{className:`w-5 h-5`})})]}),(0,O.jsxs)(`div`,{className:`p-4 space-y-4 overflow-y-auto`,children:[h&&(0,O.jsxs)(`div`,{className:`p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,O.jsxs)(`p`,{className:`text-xs text-bambu-gray mb-1`,children:[_(`inventory.selectSpool`),`:`]}),(0,O.jsxs)(`div`,{className:`flex items-center gap-2`,children:[h.color&&(0,O.jsx)(`span`,{className:`w-4 h-4 rounded-full border border-black/20`,style:b(h.color)}),(0,O.jsx)(`span`,{className:`text-white font-medium`,children:h.type||_(`ams.emptySlot`)}),(0,O.jsxs)(`span`,{className:`text-bambu-gray`,children:[`(`,h.location,`)`]})]})]}),(0,O.jsxs)(`div`,{className:`relative`,children:[(0,O.jsx)(f,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,O.jsx)(`input`,{type:`text`,value:A,onChange:e=>re(e.target.value),placeholder:_(`inventory.searchSpools`),className:`w-full pl-9 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray focus:outline-none focus:border-bambu-green`})]}),(0,O.jsxs)(`div`,{className:`space-y-3`,children:[!g&&(ce?(0,O.jsx)(`div`,{className:`flex justify-center py-8`,children:(0,O.jsx)(u,{className:`w-6 h-6 text-bambu-green animate-spin`})}):W&&W.length>0?(0,O.jsx)(`div`,{className:`max-h-96 overflow-y-auto grid grid-cols-2 sm:grid-cols-3 gap-2`,children:W.map(e=>(0,O.jsxs)(`button`,{onClick:()=>{E(e.id),k(null)},title:e.note||void 0,className:`p-2.5 rounded-lg border text-left transition-colors ${T===e.id?`bg-bambu-green/20 border-bambu-green`:`bg-bambu-dark border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:[(0,O.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,O.jsxs)(`p`,{className:`text-white text-sm font-medium truncate`,children:[e.brand?`${e.brand} `:``,e.material,e.subtype?` ${e.subtype}`:``]}),(0,O.jsxs)(`span`,{className:`text-[10px] font-mono text-bambu-gray shrink-0`,children:[`#`,e.id]})]}),(0,O.jsxs)(`div`,{className:`flex items-center gap-1.5 mt-1`,children:[e.rgba&&(0,O.jsx)(`span`,{className:`w-3 h-3 rounded-full border border-black/20 flex-shrink-0`,style:b(e.rgba)}),(0,O.jsx)(`span`,{className:`text-xs text-bambu-gray truncate`,children:y(e.color_name,e.rgba,e.color_name_is_synthesized)||``})]}),e.label_weight&&(0,O.jsxs)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:[Math.max(0,Math.round(e.label_weight-e.weight_used)),` / `,e.label_weight,`g`]}),e.note&&(0,O.jsx)(`p`,{className:`text-[10px] text-bambu-gray/70 mt-1 truncate`,title:e.note,children:e.note})]},e.id))}):U&&U.length===0?(0,O.jsxs)(`div`,{className:`text-center py-8 text-bambu-gray`,children:[(0,O.jsx)(`p`,{children:_(`inventory.noAvailableSpools`)}),se&&(0,O.jsxs)(`p`,{className:`text-[10px] mt-2 opacity-60`,children:[se.length,` fetched · `,se.filter(e=>e.archived_at).length,` archived ·`,` `,se.filter(e=>pe.has(e.id)).length,` assigned to other slots`]})]}):(0,O.jsxs)(`div`,{className:`text-center py-8 text-bambu-gray`,children:[(0,O.jsx)(`p`,{children:_(`inventory.noSpoolsMatch`)}),U&&(0,O.jsxs)(`p`,{className:`text-[10px] mt-2 opacity-60`,children:[U.length,` unassigned spools — `,U.length-(W?.length??0),` filtered by tray match. Try "Show all spools".`]})]})),g&&(0,O.jsx)(O.Fragment,{children:P?(0,O.jsx)(`div`,{className:`flex justify-center py-4`,children:(0,O.jsx)(u,{className:`w-5 h-5 text-bambu-green animate-spin`})}):de&&de.filter(e=>!e.archived_at&&!I.has(e.id)).length>0?(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)(`p`,{className:`text-xs font-medium text-bambu-gray uppercase tracking-wide pt-1`,children:_(`inventory.spoolmanSpools`)}),(0,O.jsx)(`div`,{className:`max-h-64 overflow-y-auto grid grid-cols-2 sm:grid-cols-3 gap-2`,children:te(de.filter(e=>!e.archived_at&&!I.has(e.id)),A).map(e=>(0,O.jsxs)(`button`,{onClick:()=>{k(e.id),E(null)},title:e.note||void 0,className:`p-2.5 rounded-lg border text-left transition-colors ${ne===e.id?`bg-bambu-green/20 border-bambu-green`:`bg-bambu-dark border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:[(0,O.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,O.jsxs)(`p`,{className:`text-white text-sm font-medium truncate`,children:[e.brand?`${e.brand} `:``,e.material,e.subtype?` ${e.subtype}`:``]}),(0,O.jsxs)(`span`,{className:`text-[10px] font-mono text-bambu-gray shrink-0`,children:[`#`,e.id]})]}),(0,O.jsxs)(`div`,{className:`flex items-center gap-1.5 mt-1`,children:[e.rgba&&(0,O.jsx)(`span`,{className:`w-3 h-3 rounded-full border border-black/20 flex-shrink-0`,style:b(e.rgba)}),(0,O.jsx)(`span`,{className:`text-xs text-bambu-gray truncate`,children:y(e.color_name,e.rgba,e.color_name_is_synthesized)||``})]}),e.label_weight&&(0,O.jsxs)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:[Math.max(0,Math.round(e.label_weight-e.weight_used)),` / `,e.label_weight,`g`]}),e.note&&(0,O.jsx)(`p`,{className:`text-[10px] text-bambu-gray/70 mt-1 truncate`,title:e.note,children:e.note})]},`spoolman-${e.id}`))})]}):null})]})]}),(0,O.jsxs)(`div`,{className:`flex justify-between items-center p-4 border-t border-bambu-dark-tertiary`,children:[(0,O.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,O.jsx)(`input`,{id:`disable-filtering-toggle`,type:`checkbox`,checked:C,onChange:()=>w(e=>!e),className:`accent-bambu-green w-4 h-4 rounded focus:ring-0 border-bambu-dark-tertiary`}),(0,O.jsx)(`label`,{htmlFor:`disable-filtering-toggle`,className:`text-xs text-bambu-gray select-none cursor-pointer`,children:_(`inventory.showAllSpools`)})]}),(0,O.jsxs)(`div`,{className:`flex gap-2`,children:[(0,O.jsx)(m,{variant:`secondary`,onClick:t,children:_(`common.cancel`)}),(0,O.jsx)(m,{onClick:me,disabled:!T&&ne===null||R.isPending||z.isPending,children:R.isPending||z.isPending?(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)(u,{className:`w-4 h-4 animate-spin`}),_(`inventory.assigning`)]}):(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)(d,{className:`w-4 h-4`}),_(`inventory.assignSpool`)]})})]})]}),R.isError&&(0,O.jsx)(`div`,{className:`mx-4 mb-4 p-2 bg-red-100 dark:bg-red-500/20 border border-red-300 dark:border-red-500/50 rounded text-sm text-red-700 dark:text-red-400`,children:R.error.message})]})]}),M&&h&&T&&N&&(()=>{let e=``;return N.type===`material`?e=_(`inventory.assignMismatchMessage`,{spoolMaterial:N.spoolMaterial,trayMaterial:N.trayMaterial,location:h.location}):N.type===`partial`?e=_(`inventory.assignPartialMismatchMessage`,{spoolMaterial:N.spoolMaterial,trayMaterial:N.trayMaterial,location:h.location}):N.type===`material_profile`?e=`${_(`inventory.assignMismatchMessage`,{spoolMaterial:N.spoolMaterial,trayMaterial:N.trayMaterial,location:h.location})}\n\n${_(`inventory.assignProfileMismatchMessage`,{spoolProfile:N.spoolProfile||_(`common.unknown`),trayProfile:N.trayProfile||_(`common.unknown`),location:h.location})}`:N.type===`partial_profile`&&(e=`${_(`inventory.assignPartialMismatchMessage`,{spoolMaterial:N.spoolMaterial,trayMaterial:N.trayMaterial,location:h.location})}\n\n${_(`inventory.assignProfileMismatchMessage`,{spoolProfile:N.spoolProfile||_(`common.unknown`),trayProfile:N.trayProfile||_(`common.unknown`),location:h.location})}`),e=`${e}\n\n${_(`inventory.assignReconfigureNote`)}`,(0,O.jsx)(v,{title:_(`inventory.assignMismatchTitle`),message:e,confirmText:_(`inventory.assignMismatchConfirm`),variant:`warning`,overlayZIndex:`z-[110]`,isLoading:R.isPending,onConfirm:he,onCancel:()=>{R.isPending||(ae(!1),ie(null),oe(null))}})})()]})}function re(e){let t=e.includes(`_`)?e.split(`_`)[0]:e;return t.startsWith(`GFS`)?`GF`+t.slice(3):(t.startsWith(`PFUS`)||t.startsWith(`PFSP`),t)}var j=[`PLA`,`PETG`,`PCTG`,`ABS`,`ASA`,`TPU`,`PC`,`PA`,`NYLON`,`PVA`,`HIPS`,`PP`,`PET`];function ie(e){let t=e.replace(/@.+$/,``).trim(),n=t.toUpperCase(),r=n.match(/\bSUPPORT\s+FOR\s+/);if(r){let e=n.slice(r.index+r[0].length);for(let n of j)if(RegExp(`\\b${n}\\b`).test(e))return{material:n,brand:t.slice(0,r.index).trim(),variant:`Support`}}for(let e of j){let r=RegExp(`\\b${e}\\b`,`i`);if(r.test(n)){let n=t.split(r);return{material:e,brand:n[0]?.trim()||``,variant:n[1]?.trim()||``}}}let i=t.split(/\s+/);return i.length>=2?{material:i[1],brand:i[0],variant:i.slice(2).join(` `)}:{material:t,brand:``,variant:``}}function M(e){return`${e.extruder_id??0}|${e.name}|${e.k_value}`}function ae(e,t){return t===void 0?!1:e.some(e=>(e.extruder_id??0)===t)}function N(e,t,n){return ae(e,n)?e.find(e=>e.slot_id===t&&(e.extruder_id??0)===n):e.find(e=>e.slot_id===t)}function oe(e,t,n){return t?` \u00b7 ${e.extruder_id===1?n(`common.left`):n(`common.right`)}`:``}function se(e){return!e.startsWith(`GF`)&&!e.startsWith(`P1`)}var ce={white:`FFFFFF`,black:`000000`,red:`FF0000`,green:`00FF00`,blue:`0000FF`,yellow:`FFFF00`,cyan:`00FFFF`,magenta:`FF00FF`,orange:`FFA500`,purple:`800080`,pink:`FFC0CB`,brown:`8B4513`,gray:`808080`,grey:`808080`,"jade white":`FFFEF2`,ivory:`FFFFF0`,beige:`F5F5DC`,cream:`FFFDD0`,silver:`C0C0C0`,gold:`FFD700`,bronze:`CD7F32`,copper:`B87333`,navy:`000080`,teal:`008080`,olive:`808000`,maroon:`800000`,coral:`FF7F50`,salmon:`FA8072`,lime:`32CD32`,mint:`98FF98`,"forest green":`228B22`,"sky blue":`87CEEB`,"royal blue":`4169E1`,turquoise:`40E0D0`,lavender:`E6E6FA`,violet:`EE82EE`,plum:`DDA0DD`,tan:`D2B48C`,chocolate:`D2691E`,charcoal:`36454F`,slate:`708090`,transparent:`000000`,natural:`F5F5DC`,wood:`DEB887`},le=[{name:`White`,hex:`FFFFFF`},{name:`Black`,hex:`000000`},{name:`Red`,hex:`FF0000`},{name:`Blue`,hex:`0000FF`},{name:`Green`,hex:`00AA00`},{name:`Yellow`,hex:`FFFF00`},{name:`Orange`,hex:`FFA500`},{name:`Gray`,hex:`808080`}],ue=[{name:`Cyan`,hex:`00FFFF`},{name:`Magenta`,hex:`FF00FF`},{name:`Purple`,hex:`800080`},{name:`Pink`,hex:`FFC0CB`},{name:`Brown`,hex:`8B4513`},{name:`Beige`,hex:`F5F5DC`},{name:`Navy`,hex:`000080`},{name:`Teal`,hex:`008080`},{name:`Lime`,hex:`32CD32`},{name:`Gold`,hex:`FFD700`},{name:`Silver`,hex:`C0C0C0`},{name:`Maroon`,hex:`800000`},{name:`Olive`,hex:`808000`},{name:`Coral`,hex:`FF7F50`},{name:`Salmon`,hex:`FA8072`},{name:`Turquoise`,hex:`40E0D0`},{name:`Violet`,hex:`EE82EE`},{name:`Indigo`,hex:`4B0082`},{name:`Chocolate`,hex:`D2691E`},{name:`Tan`,hex:`D2B48C`},{name:`Slate`,hex:`708090`},{name:`Charcoal`,hex:`36454F`},{name:`Ivory`,hex:`FFFFF0`},{name:`Cream`,hex:`FFFDD0`}];function de(e){return ce[e.toLowerCase().trim()]||null}function P({isOpen:e,onClose:t,printerId:n,slotInfo:a,nozzleDiameter:d=`0.4`,printerModel:f,onSuccess:v,fullScreen:y}){let{t:x}=i(),{showToast:te}=l(),[k,A]=(0,D.useState)(``),[ce,P]=(0,D.useState)(``),[F,I]=(0,D.useState)(null),L=(0,D.useRef)(null);L.current=F;let[R,z]=(0,D.useState)(``),[B,V]=(0,D.useState)(``),[H,fe]=(0,D.useState)(``),[pe,U]=(0,D.useState)(!1),[W,me]=(0,D.useState)(!1),he=(0,D.useRef)(``),{schedule:ge}=ne(),{data:G,isLoading:_e,isError:ve}=o({queryKey:[`cloudSettings`],queryFn:()=>r.getCloudSettings(),enabled:e,retry:!1}),{data:ye}=o({queryKey:[`orcaCloudProfilesForAmsSlot`],queryFn:()=>r.orcaCloudListProfiles(),enabled:e,retry:!1}),{data:K,isLoading:be}=o({queryKey:[`localPresets`],queryFn:()=>r.getLocalPresets(),enabled:e}),{data:q,isLoading:xe}=o({queryKey:[`builtinFilaments`],queryFn:()=>r.getBuiltinFilaments(),enabled:e,staleTime:1/0}),{data:J,isLoading:Se}=o({queryKey:[`kprofiles`,n,d],queryFn:()=>r.getKProfiles(n,d),enabled:e&&!!n}),{data:Ce}=o({queryKey:[`colorCatalog`],queryFn:()=>r.getColorCatalog(),enabled:e,staleTime:1/0}),{data:Y}=o({queryKey:[`slicerPrinterModels`],queryFn:r.getSlicerPrinterModels,enabled:e,staleTime:1/0}),{data:X}=o({queryKey:[`slot-spool-defaults`,n,a.amsId,a.trayId],queryFn:()=>r.getSlotSpoolDefaults(n,a.amsId,a.trayId),enabled:e,staleTime:0}),we=(0,D.useMemo)(()=>w(Y??{}),[Y]),Te=(0,D.useMemo)(()=>{if(!f||!Y)return null;for(let[e,t]of Object.entries(Y))if(t===f)return`${e.startsWith(`Bambu Lab `)?e:`Bambu Lab ${e}`} ${d} nozzle`;return null},[f,Y,d]),Ee=s({mutationFn:async()=>{if(!k)throw Error(`No filament preset selected`);let e=k.startsWith(`local_`),t=k.startsWith(`builtin_`),i=k.startsWith(`orca_`)?k.replace(`orca_`,``):k,o=!e&&!t?ye?.filament.find(e=>e.setting_id===i):void 0,s=!!o,c=o??null,l=e?parseInt(k.replace(`local_`,``),10):null,u=t?k.replace(`builtin_`,``):null,f=e?K?.filament.find(e=>e.id===l):null,p=t?q?.find(e=>e.filament_id===u):null,ee=!e&&!t&&!s?G?.filament.find(e=>e.setting_id===k):null;if(!e&&!t&&!s&&!ee)throw Error(`Selected preset not found`);if(e&&!f)throw Error(`Selected local preset not found`);if(t&&!p)throw Error(`Selected builtin preset not found`);if(s&&!c)throw Error(`Selected Orca Cloud preset not found`);let m=e?f.name:t?p.name:s?c.name:ee.name,h=ie(m),g=L.current?.slot_id??-1,_=R||a.trayColor?.slice(0,6)||`FFFFFF`,v=m.replace(/@.+$/,``).trim(),y,b,S=h.material.toUpperCase(),C={PLA:`GFL99`,"PLA-CF":`GFL98`,"PLA SILK":`GFL96`,"PLA HIGH SPEED":`GFL95`,PETG:`GFG99`,"PETG HF":`GFG96`,"PETG-CF":`GFG98`,PCTG:`GFG97`,ABS:`GFB99`,ASA:`GFB98`,PC:`GFC99`,PA:`GFN99`,"PA-CF":`GFN98`,NYLON:`GFN99`,TPU:`GFU99`,PVA:`GFS99`,HIPS:`GFS98`,PE:`GFP99`,PP:`GFP97`};if(e){let e=(j.includes(S)?S:f?.filament_type||h.material||``).toUpperCase();y=C[e]||C[e.replace(/[-\s]?CF$/,``)]||C[e.replace(/\+$/,``)]||C[e.split(/[-\s]/)[0]]||``,b=``}else if(s)y=``,b=``;else if(t)y=u,b=``;else{if(y=re(k),b=k,!k.startsWith(`GFS`))try{let e=await r.getCloudSettingDetail(k),t=e.setting?.filament_id,n=e.filament_id||(typeof t==`string`?t:``);n&&(y=n)}catch(e){console.warn(`Failed to fetch preset detail for filament_id:`,e)}/^(PFUS|PFSP|PFCN)/.test(y)&&(console.warn(`Cloud preset ${k} carries no filament_id in either place; sending no tray_info_idx so the printer keeps a resolvable one.`),y=``)}let w=e&&f?.nozzle_temp_min?f.nozzle_temp_min:190,T=e&&f?.nozzle_temp_max?f.nozzle_temp_max:230;if(!e||t||s||!f?.nozzle_temp_min&&!f?.nozzle_temp_max){let t=(e?j.includes(S)?S:f?.filament_type||h.material||``:h.material).toUpperCase();t.includes(`PLA`)?(w=190,T=230):t.includes(`PETG`)?(w=220,T=260):t.includes(`ABS`)||t.includes(`ASA`)?(w=240,T=280):t.includes(`TPU`)?(w=200,T=240):t===`PCTG`?(w=220,T=260):t.includes(`PC`)?(w=260,T=300):(t.includes(`PA`)||t.includes(`NYLON`))&&(w=250,T=290)}let E=L.current?.k_value?parseFloat(L.current.k_value):0,ne=e?j.includes(S)?S:f?.filament_type||h.material||`PLA`:s&&j.includes(S)?S:h.material||`PLA`,D=await r.configureAmsSlot(n,a.amsId,a.trayId,{tray_info_idx:y,tray_type:ne,tray_sub_brands:v,tray_color:_+`FF`,nozzle_temp_min:w,nozzle_temp_max:T,cali_idx:g,nozzle_diameter:d,setting_id:b,kprofile_filament_id:L.current?.filament_id,kprofile_setting_id:L.current?.setting_id||void 0,k_value:E,orca_profile_id:s?i:void 0});s&&D.orca_fallback_reason&&te(x(`configureAmsSlot.orcaFallback.${D.orca_fallback_reason}`,{material:ne}),`warning`);let O=e?`local_${l}`:t?`builtin_${u}`:k,A=e?`local`:t?`builtin`:s?`orca_cloud`:`cloud`;try{await r.saveSlotPreset(n,a.amsId,a.trayId,O,v,A,D.tray_info_idx)}catch(e){console.warn(`Failed to save slot preset mapping:`,e)}return D},onSuccess:()=>{U(!0),v?.(),ge(()=>{U(!1),t()},1500)}}),De=s({mutationFn:async()=>r.resetAmsSlot(n,a.amsId,a.trayId),onSuccess:()=>{U(!0),v?.(),ge(()=>{U(!1),t()},1500)}}),Oe=(0,D.useMemo)(()=>{let e=H.toLowerCase(),t=[],n=new Set,r=a.savedPresetId,i=a.trayInfoIdx;if(ye?.filament)for(let r of ye.filament){let i=`orca_${r.setting_id}`;if(n.add(r.setting_id),n.add(i),!(e&&!r.name.toLowerCase().includes(e))){if(f){let e=T(r.name,Y??{});if(e&&!C(e,f))continue}t.push({id:i,name:r.name,source:`orca_cloud`,isUser:!0})}}if(G?.filament)for(let a of G.filament){if(n.has(a.setting_id))continue;n.add(a.setting_id);let o=r===a.setting_id||i&&(a.setting_id===i||re(a.setting_id)===i);if(!(e&&!a.name.toLowerCase().includes(e))){if(!o&&f){let e=T(a.name,Y??{});if(e&&!C(e,f))continue}t.push({id:a.setting_id,name:a.name,source:`cloud`,isUser:se(a.setting_id)})}}if(K?.filament){let n=a.savedPresetId;for(let r of K.filament){let i=`local_${r.id}`;if(!(e&&!r.name.toLowerCase().includes(e))){if(n!==i&&Te){let e=null;if(r.compatible_printers)try{let t=JSON.parse(r.compatible_printers);Array.isArray(t)&&(e=t.filter(e=>typeof e==`string`))}catch{e=null}if(S({name:r.name,compatible_printers:e},`filament`,Te,we)===`mismatch`)continue}t.push({id:i,name:r.name,source:`local`,isUser:!1})}}}if(q)for(let r of q){if(n.has(r.filament_id))continue;let i=r.filament_id.startsWith(`GF`)?`GFS`+r.filament_id.slice(2):r.filament_id;n.has(i)||(!e||r.name.toLowerCase().includes(e))&&t.push({id:`builtin_${r.filament_id}`,name:r.name,source:`builtin`,isUser:!1})}return t.sort((e,t)=>{let n={local:0,orca_cloud:1,cloud:2,builtin:3};return e.source===t.source?e.isUser&&!t.isUser?-1:!e.isUser&&t.isUser?1:e.name.localeCompare(t.name):n[e.source]-n[t.source]})},[ye?.filament,G?.filament,K?.filament,q,H,f,a.savedPresetId,a.trayInfoIdx,Te,we,Y]),Z=(0,D.useMemo)(()=>{if(!k)return null;let e=null,t=``;if(k.startsWith(`local_`)){let t=parseInt(k.replace(`local_`,``),10);e=K?.filament.find(e=>e.id===t)?.name||null}else if(k.startsWith(`builtin_`)){let n=k.replace(`builtin_`,``);e=q?.find(e=>e.filament_id===n)?.name||null,t=E(n)}else{let n=k.startsWith(`orca_`)?k.replace(`orca_`,``):k,r=ye?.filament.find(e=>e.setting_id===n);if(r)e=r.name;else if(G?.filament){let n=G.filament.find(e=>e.setting_id===k);e=n?.name||null,n&&(t=E(n.setting_id))}}if(!e)return null;let n=e.replace(/@.+$/,``).trim();n.startsWith(`# `)&&(n=n.slice(2).trim());let r=ie(n);return{fullName:n,material:r.material,brand:r.brand,filamentId:t}},[k,G?.filament,K?.filament,q,ye?.filament]),ke=Z?.fullName||``,Ae=(0,D.useMemo)(()=>{if(!Ce||!Z)return[];let{fullName:e,brand:t}=Z,n=e.replace(/^(Bambu\s*(Lab)?|eSUN|Polymaker|Overture|Sunlu|Hatchbox)\s*/i,``).trim();return Ce.filter(e=>{let r=(e.material||``).toUpperCase(),i=e.manufacturer.toUpperCase();if(!(r===n.toUpperCase()||r.includes(n.toUpperCase())||n.toUpperCase().includes(r)))return!1;if(t){let e=t.toUpperCase();if(!i.includes(e)&&!e.includes(i))return!1}return!0})},[Ce,Z]),je=(0,D.useMemo)(()=>new Set((J?.profiles??[]).map(e=>e.extruder_id??0)).size>1,[J?.profiles]),Q=(0,D.useMemo)(()=>{if(!J?.profiles)return[];if(!Z){let e=a.caliIdx;if(e!=null&&e>0){let t=N(J.profiles,e,a.extruderId);if(t)return[t]}return[]}let{fullName:e,material:t,brand:n,filamentId:r}=Z,i=e.toUpperCase(),o=t.toUpperCase(),s=n.toUpperCase()===`GENERIC`?``:n.toUpperCase(),c=r;if(!o||o.length<2)return[];let l=J.profiles.filter(e=>{if(c){let t=E(e.filament_id);if(t&&t===c)return!0}let t=e.name.toUpperCase();if(s)return!(!t.includes(s)||!t.includes(o));if(t.includes(i)||t.includes(o))return!0;let n={NYLON:[`PA`,`PA-CF`,`PA6`],PA:[`NYLON`]}[o]||[];for(let e of n)if(t.includes(e))return!0;return!1}),u=ae(J.profiles,a.extruderId)?l.filter(e=>(e.extruder_id??0)===a.extruderId):l,d=new Map;for(let e of u){let t=M(e);d.has(t)||d.set(t,e)}let f=Array.from(d.values()),p=a.caliIdx;if((ce&&k===ce||c&&c===E(a.trayInfoIdx))&&p!=null&&p>0&&!f.some(e=>e.slot_id===p)){let e=N(J.profiles,p,a.extruderId);e&&f.unshift(e)}return f},[J?.profiles,Z,a.extruderId,a.caliIdx,a.trayInfoIdx,k,ce]),$=(0,D.useMemo)(()=>{if(!J?.profiles)return[];let e=new Set(Q.map(e=>M(e))),t=new Map;for(let n of J.profiles){let r=M(n);e.has(r)||t.has(r)||t.set(r,n)}return Array.from(t.values()).sort((e,t)=>e.name.localeCompare(t.name))},[J?.profiles,Q]),Me=Q.length>0||$.length>0,Ne=(0,D.useCallback)(e=>{if(!e){I(null);return}I(Q.find(t=>M(t)===e)||$.find(t=>M(t)===e)||null)},[Q,$]);(0,D.useEffect)(()=>{if(e){if(X?.slicer_filament)A(X.slicer_filament),P(X.slicer_filament);else if(a.savedPresetId)A(a.savedPresetId),P(a.savedPresetId);else if(a.trayInfoIdx&&G?.filament){let e=G.filament.find(e=>e.setting_id===a.trayInfoIdx);e||=G.filament.find(e=>re(e.setting_id)===a.trayInfoIdx),e&&(A(e.setting_id),P(e.setting_id))}else if(a.trayInfoIdx&&q?.length){let e=a.trayInfoIdx,t=q.find(t=>t.filament_id===e);t&&(A(`builtin_${t.filament_id}`),P(`builtin_${t.filament_id}`))}if(a.trayColor){let e=a.trayColor.slice(0,6);e&&z(e)}}else A(``),P(``),I(null),z(``),V(``),fe(``),U(!1),he.current=``},[e,X?.slicer_filament,a.savedPresetId,a.trayInfoIdx,a.trayColor,G?.filament,q]),(0,D.useEffect)(()=>{if(Q.length>0){if(X?.cali_idx!=null){let e=N(Q,X.cali_idx,X.extruder??a.extruderId);if(e){I(e);return}}if(a.caliIdx!=null&&a.caliIdx>0){let e=N(Q,a.caliIdx,a.extruderId);if(e){I(e);return}}I(Q[0])}else I(null)},[k,Q,X?.cali_idx,X?.extruder,a.caliIdx,a.extruderId]);let Pe=(0,D.useCallback)(e=>{e.key===`Escape`&&t()},[t]);(0,D.useEffect)(()=>{if(e)return document.addEventListener(`keydown`,Pe),()=>document.removeEventListener(`keydown`,Pe)},[e,Pe]);let Fe=_e&&!ve||be||xe||Se;if((0,D.useEffect)(()=>{if(!Fe&&k&&k!==he.current){let e=requestAnimationFrame(()=>{let e=document.querySelector(`[class*="fixed inset-0 z-50"]`)?.querySelector(`[data-preset-id="${CSS.escape(k)}"]`);e&&(he.current=k,e.scrollIntoView({block:`nearest`}))});return()=>cancelAnimationFrame(e)}},[k,Fe]),!e)return null;let Ie=k&&!Ee.isPending,Le=R||a.trayColor||`FFFFFF`;return(0,O.jsxs)(`div`,{className:`fixed inset-0 z-50 flex ${y?``:`items-center justify-center`}`,children:[!y&&(0,O.jsx)(`div`,{className:`absolute inset-0 bg-black/60 backdrop-blur-sm`,onClick:t}),(0,O.jsxs)(`div`,{className:y?`relative w-full h-full bg-bambu-dark-secondary flex flex-col`:`relative w-full max-w-lg mx-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl`,children:[(0,O.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary shrink-0`,children:[(0,O.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,O.jsx)(p,{className:`w-5 h-5 text-bambu-blue`}),(0,O.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:x(`configureAmsSlot.title`)}),y&&(0,O.jsxs)(`div`,{className:`flex items-center gap-2 ml-4 text-sm text-bambu-gray`,children:[(0,O.jsx)(`span`,{className:`text-white/30`,children:`|`}),a.trayColor&&(0,O.jsx)(`span`,{className:`w-4 h-4 rounded-full border border-black/20`,style:b(a.trayColor)}),(0,O.jsx)(`span`,{className:`text-white/70`,children:x(`configureAmsSlot.slotLabel`,{ams:_(a.amsId,a.trayCount),slot:a.trayId+1})}),a.traySubBrands&&(0,O.jsxs)(`span`,{children:[`(`,a.traySubBrands,`)`]})]})]}),(0,O.jsx)(`button`,{onClick:t,className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,O.jsx)(ee,{className:`w-5 h-5`})})]}),(0,O.jsxs)(`div`,{className:`p-4 overflow-y-auto ${y?`flex-1 min-h-0`:`space-y-4 max-h-[60vh]`}`,children:[pe&&(0,O.jsx)(`div`,{className:`absolute inset-0 bg-bambu-dark-secondary/95 z-10 flex items-center justify-center rounded-xl`,children:(0,O.jsxs)(`div`,{className:`text-center space-y-3`,children:[(0,O.jsx)(h,{className:`w-16 h-16 text-bambu-green mx-auto`}),(0,O.jsx)(`p`,{className:`text-lg font-semibold text-white`,children:x(`configureAmsSlot.slotConfigured`)}),(0,O.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:x(`configureAmsSlot.settingsSentToPrinter`)})]})}),!y&&(0,O.jsxs)(`div`,{className:`p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,O.jsx)(`p`,{className:`text-xs text-bambu-gray mb-1`,children:x(`configureAmsSlot.configuringSlot`)}),(0,O.jsxs)(`div`,{className:`flex items-center gap-2`,children:[a.trayColor&&(0,O.jsx)(`span`,{className:`w-4 h-4 rounded-full border border-black/20`,style:b(a.trayColor)}),(0,O.jsx)(`span`,{className:`text-white font-medium`,children:x(`configureAmsSlot.slotLabel`,{ams:_(a.amsId,a.trayCount),slot:a.trayId+1})}),a.traySubBrands&&(0,O.jsxs)(`span`,{className:`text-bambu-gray`,children:[`(`,a.traySubBrands,`)`]})]})]}),Fe?(0,O.jsx)(`div`,{className:`flex justify-center py-8`,children:(0,O.jsx)(u,{className:`w-6 h-6 text-bambu-green animate-spin`})}):y?(0,O.jsxs)(`div`,{className:`flex gap-4 h-full`,children:[(0,O.jsxs)(`div`,{className:`w-1/2 flex flex-col min-h-0`,children:[(0,O.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-2`,children:[x(`configureAmsSlot.filamentProfile`),` `,(0,O.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:`*`})]}),(0,O.jsx)(`input`,{type:`text`,placeholder:x(`configureAmsSlot.searchPresets`),value:H,onChange:e=>fe(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder:text-bambu-gray focus:border-bambu-green focus:outline-none mb-2 shrink-0`}),(0,O.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto space-y-1`,children:Oe.length===0?(0,O.jsx)(`p`,{className:`text-center py-4 text-bambu-gray`,children:G?.filament?.length===0&&!K?.filament?.length?x(`configureAmsSlot.noPresetsAvailable`):x(`configureAmsSlot.noMatchingPresets`)}):Oe.map(e=>(0,O.jsx)(`button`,{"data-preset-id":e.id,onClick:()=>A(e.id),className:`group w-full p-2 rounded-lg border text-left transition-colors ${k===e.id?`bg-bambu-green/20 border-bambu-green`:`bg-bambu-dark border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:(0,O.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,O.jsx)(`span`,{className:`text-white text-sm truncate group-hover:whitespace-normal group-hover:break-all`,title:e.name,children:e.name}),(0,O.jsxs)(`div`,{className:`flex items-center gap-1 flex-shrink-0`,children:[e.source===`local`&&(0,O.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-green-100 dark:bg-green-500/20 text-green-700 dark:text-green-400`,children:x(`profiles.localProfiles.badge`)}),e.source===`orca_cloud`&&(0,O.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-purple-100 dark:bg-purple-500/20 text-purple-700 dark:text-purple-400`,children:x(`configureAmsSlot.orcaCloud`)}),e.source===`cloud`&&(0,O.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-bambu-blue/20 text-bambu-blue`,children:x(`configureAmsSlot.bambuCloud`)}),e.source===`builtin`&&(0,O.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400`,children:x(`configureAmsSlot.builtin`)})]})]})},e.id))})]}),(0,O.jsxs)(`div`,{className:`w-1/2 flex flex-col gap-4 min-h-0 overflow-y-auto`,children:[(0,O.jsxs)(`div`,{children:[(0,O.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-2`,children:[x(`configureAmsSlot.kProfileLabel`),ke&&(0,O.jsx)(`span`,{className:`ml-2 text-xs text-bambu-blue`,children:x(`configureAmsSlot.filteringFor`,{material:ke})})]}),Me?(0,O.jsxs)(`div`,{className:`relative`,children:[(0,O.jsxs)(`select`,{value:F?M(F):``,onChange:e=>Ne(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 appearance-none pr-10`,children:[(0,O.jsx)(`option`,{value:``,children:x(`configureAmsSlot.noKProfile`)}),Q.map(e=>(0,O.jsxs)(`option`,{value:M(e),children:[e.name,` (K=`,e.k_value,`)`,oe(e,je,x)]},M(e))),$.length>0&&(0,O.jsx)(`optgroup`,{label:x(`configureAmsSlot.otherKProfiles`),children:$.map(e=>(0,O.jsxs)(`option`,{value:M(e),children:[e.name,` (K=`,e.k_value,`)`,oe(e,je,x)]},M(e)))})]}),(0,O.jsx)(c,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]}):k?(0,O.jsx)(`p`,{className:`text-sm text-bambu-gray italic py-2`,children:x(`configureAmsSlot.noMatchingKProfiles`)}):(0,O.jsx)(`span`,{className:`inline-block text-xs px-2 py-1 rounded bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400 border border-amber-300 dark:border-amber-500/30`,children:x(`configureAmsSlot.selectFilamentFirst`)}),F&&(0,O.jsx)(`p`,{className:`text-xs text-bambu-green mt-1`,children:x(`configureAmsSlot.kFromCalibration`,{value:F.k_value})})]}),(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-2`,children:x(`configureAmsSlot.customColorLabel`)}),Ae.length>0&&(0,O.jsxs)(`div`,{className:`mb-3`,children:[(0,O.jsx)(`p`,{className:`text-xs text-bambu-gray mb-1.5`,children:x(`configureAmsSlot.presetColors`,{name:Z?.fullName})}),(0,O.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:Ae.map(e=>(0,O.jsxs)(`button`,{onClick:()=>{z(e.hex_color.replace(`#`,``).toUpperCase()),V(e.color_name)},className:`h-7 px-2 rounded-md border-2 transition-all flex items-center gap-1.5 ${R===e.hex_color.replace(`#`,``).toUpperCase()?`border-bambu-green scale-105`:`border-white/20 hover:border-white/40`}`,title:e.color_name,children:[(0,O.jsx)(`span`,{className:`w-4 h-4 rounded-full border border-black/20 flex-shrink-0`,style:{backgroundColor:e.hex_color}}),(0,O.jsx)(`span`,{className:`text-xs text-white/80 whitespace-nowrap`,children:e.color_name})]},e.id))})]}),(0,O.jsxs)(`div`,{className:`flex flex-wrap gap-1.5 mb-2`,children:[le.map(e=>(0,O.jsx)(`button`,{onClick:()=>{z(e.hex),V(e.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${R===e.hex?`border-bambu-green scale-110`:`border-white/20 hover:border-white/40`}`,style:{backgroundColor:`#${e.hex}`},title:e.name},e.hex)),(0,O.jsx)(`button`,{onClick:()=>me(!W),className:`w-7 h-7 rounded-md border-2 border-white/20 hover:border-white/40 flex items-center justify-center text-white/60 hover:text-white/80 transition-all text-xs`,title:x(W?`configureAmsSlot.showLessColors`:`configureAmsSlot.showMoreColors`),children:W?`−`:`+`})]}),W&&(0,O.jsx)(`div`,{className:`flex flex-wrap gap-1.5 mb-2`,children:ue.map(e=>(0,O.jsx)(`button`,{onClick:()=>{z(e.hex),V(e.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${R===e.hex?`border-bambu-green scale-110`:`border-white/20 hover:border-white/40`}`,style:{backgroundColor:`#${e.hex}`},title:e.name},e.hex))}),(0,O.jsxs)(`div`,{className:`flex gap-2 items-center`,children:[(0,O.jsx)(`div`,{className:`w-10 h-10 rounded-lg border-2 border-white/20 flex-shrink-0`,style:b(Le)}),(0,O.jsx)(`input`,{type:`text`,placeholder:x(`configureAmsSlot.colorPlaceholder`),value:B,onChange:e=>{let t=e.target.value;V(t);let n=de(t);if(n)z(n);else{let e=t.replace(/[^0-9A-Fa-f]/g,``).toUpperCase();e.length===6?z(e):e.length===3&&z(e.split(``).map(e=>e+e).join(``))}},className:`flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder:text-bambu-gray focus:border-bambu-green focus:outline-none text-sm`}),R&&(0,O.jsx)(`button`,{onClick:()=>{z(``),V(``)},className:`px-2 py-1 text-xs text-bambu-gray hover:text-white bg-bambu-dark-tertiary rounded`,title:x(`configureAmsSlot.clearCustomColor`),children:x(`configureAmsSlot.clear`)})]}),R&&(0,O.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1.5`,children:x(`configureAmsSlot.hexLabel`,{hex:R})})]})]})]}):(0,O.jsxs)(O.Fragment,{children:[(0,O.jsxs)(`div`,{children:[(0,O.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-2`,children:[x(`configureAmsSlot.filamentProfile`),` `,(0,O.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:`*`})]}),(0,O.jsxs)(`div`,{className:`relative`,children:[(0,O.jsx)(`input`,{type:`text`,placeholder:x(`configureAmsSlot.searchPresets`),value:H,onChange:e=>fe(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder:text-bambu-gray focus:border-bambu-green focus:outline-none mb-2`}),(0,O.jsx)(`div`,{className:`max-h-48 overflow-y-auto space-y-1`,children:Oe.length===0?(0,O.jsx)(`p`,{className:`text-center py-4 text-bambu-gray`,children:G?.filament?.length===0&&!K?.filament?.length?x(`configureAmsSlot.noPresetsAvailable`):x(`configureAmsSlot.noMatchingPresets`)}):Oe.map(e=>(0,O.jsx)(`button`,{"data-preset-id":e.id,onClick:()=>A(e.id),className:`group w-full p-2 rounded-lg border text-left transition-colors ${k===e.id?`bg-bambu-green/20 border-bambu-green`:`bg-bambu-dark border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:(0,O.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,O.jsx)(`span`,{className:`text-white text-sm truncate group-hover:whitespace-normal group-hover:break-all`,title:e.name,children:e.name}),(0,O.jsxs)(`div`,{className:`flex items-center gap-1 flex-shrink-0`,children:[e.source===`local`&&(0,O.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-green-100 dark:bg-green-500/20 text-green-700 dark:text-green-400`,children:x(`profiles.localProfiles.badge`)}),e.source===`orca_cloud`&&(0,O.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-purple-100 dark:bg-purple-500/20 text-purple-700 dark:text-purple-400`,children:x(`configureAmsSlot.orcaCloud`)}),e.source===`cloud`&&(0,O.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-bambu-blue/20 text-bambu-blue`,children:x(`configureAmsSlot.bambuCloud`)}),e.source===`builtin`&&(0,O.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400`,children:x(`configureAmsSlot.builtin`)})]})]})},e.id))})]})]}),(0,O.jsxs)(`div`,{children:[(0,O.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-2`,children:[x(`configureAmsSlot.kProfileLabel`),ke&&(0,O.jsx)(`span`,{className:`ml-2 text-xs text-bambu-blue`,children:x(`configureAmsSlot.filteringFor`,{material:ke})})]}),Me?(0,O.jsxs)(`div`,{className:`relative`,children:[(0,O.jsxs)(`select`,{value:F?M(F):``,onChange:e=>Ne(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 appearance-none pr-10`,children:[(0,O.jsx)(`option`,{value:``,children:x(`configureAmsSlot.noKProfile`)}),Q.map(e=>(0,O.jsxs)(`option`,{value:M(e),children:[e.name,` (K=`,e.k_value,`)`,oe(e,je,x)]},M(e))),$.length>0&&(0,O.jsx)(`optgroup`,{label:x(`configureAmsSlot.otherKProfiles`),children:$.map(e=>(0,O.jsxs)(`option`,{value:M(e),children:[e.name,` (K=`,e.k_value,`)`,oe(e,je,x)]},M(e)))})]}),(0,O.jsx)(c,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]}):k?(0,O.jsx)(`p`,{className:`text-sm text-bambu-gray italic py-2`,children:x(`configureAmsSlot.noMatchingKProfiles`)}):(0,O.jsx)(`span`,{className:`inline-block text-xs px-2 py-1 rounded bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400 border border-amber-300 dark:border-amber-500/30`,children:x(`configureAmsSlot.selectFilamentFirst`)}),F&&(0,O.jsx)(`p`,{className:`text-xs text-bambu-green mt-1`,children:x(`configureAmsSlot.kFromCalibration`,{value:F.k_value})})]}),(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-2`,children:x(`configureAmsSlot.customColorLabel`)}),Ae.length>0&&(0,O.jsxs)(`div`,{className:`mb-3`,children:[(0,O.jsx)(`p`,{className:`text-xs text-bambu-gray mb-1.5`,children:x(`configureAmsSlot.presetColors`,{name:Z?.fullName})}),(0,O.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:Ae.map(e=>(0,O.jsxs)(`button`,{onClick:()=>{z(e.hex_color.replace(`#`,``).toUpperCase()),V(e.color_name)},className:`h-7 px-2 rounded-md border-2 transition-all flex items-center gap-1.5 ${R===e.hex_color.replace(`#`,``).toUpperCase()?`border-bambu-green scale-105`:`border-white/20 hover:border-white/40`}`,title:e.color_name,children:[(0,O.jsx)(`span`,{className:`w-4 h-4 rounded-full border border-black/20 flex-shrink-0`,style:{backgroundColor:e.hex_color}}),(0,O.jsx)(`span`,{className:`text-xs text-white/80 whitespace-nowrap`,children:e.color_name})]},e.id))})]}),(0,O.jsxs)(`div`,{className:`flex flex-wrap gap-1.5 mb-2`,children:[le.map(e=>(0,O.jsx)(`button`,{onClick:()=>{z(e.hex),V(e.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${R===e.hex?`border-bambu-green scale-110`:`border-white/20 hover:border-white/40`}`,style:{backgroundColor:`#${e.hex}`},title:e.name},e.hex)),(0,O.jsx)(`button`,{onClick:()=>me(!W),className:`w-7 h-7 rounded-md border-2 border-white/20 hover:border-white/40 flex items-center justify-center text-white/60 hover:text-white/80 transition-all text-xs`,title:x(W?`configureAmsSlot.showLessColors`:`configureAmsSlot.showMoreColors`),children:W?`−`:`+`})]}),W&&(0,O.jsx)(`div`,{className:`flex flex-wrap gap-1.5 mb-2`,children:ue.map(e=>(0,O.jsx)(`button`,{onClick:()=>{z(e.hex),V(e.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${R===e.hex?`border-bambu-green scale-110`:`border-white/20 hover:border-white/40`}`,style:{backgroundColor:`#${e.hex}`},title:e.name},e.hex))}),(0,O.jsxs)(`div`,{className:`flex gap-2 items-center`,children:[(0,O.jsx)(`div`,{className:`w-10 h-10 rounded-lg border-2 border-white/20 flex-shrink-0`,style:b(Le)}),(0,O.jsx)(`input`,{type:`text`,placeholder:x(`configureAmsSlot.colorPlaceholder`),value:B,onChange:e=>{let t=e.target.value;V(t);let n=de(t);if(n)z(n);else{let e=t.replace(/[^0-9A-Fa-f]/g,``).toUpperCase();e.length===6?z(e):e.length===3&&z(e.split(``).map(e=>e+e).join(``))}},className:`flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder:text-bambu-gray focus:border-bambu-green focus:outline-none text-sm`}),R&&(0,O.jsx)(`button`,{onClick:()=>{z(``),V(``)},className:`px-2 py-1 text-xs text-bambu-gray hover:text-white bg-bambu-dark-tertiary rounded`,title:x(`configureAmsSlot.clearCustomColor`),children:x(`configureAmsSlot.clear`)})]}),R&&(0,O.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1.5`,children:x(`configureAmsSlot.hexLabel`,{hex:R})})]})]})]}),(0,O.jsxs)(`div`,{className:`flex justify-between p-4 border-t border-bambu-dark-tertiary shrink-0`,children:[(0,O.jsx)(m,{variant:`secondary`,onClick:()=>De.mutate(),disabled:De.isPending||Ee.isPending,className:`text-red-600 dark:text-red-400 hover:text-red-700 dark:hover:text-red-300 hover:bg-red-50 dark:hover:bg-red-500/10`,children:De.isPending?(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)(u,{className:`w-4 h-4 animate-spin`}),x(`configureAmsSlot.resetting`)]}):(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)(g,{className:`w-4 h-4`}),x(`configureAmsSlot.resetSlot`)]})}),(0,O.jsxs)(`div`,{className:`flex gap-2`,children:[(0,O.jsx)(m,{variant:`secondary`,onClick:t,children:x(`configureAmsSlot.cancel`)}),(0,O.jsx)(m,{onClick:()=>Ee.mutate(),disabled:!Ie,children:Ee.isPending?(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)(u,{className:`w-4 h-4 animate-spin`}),x(`configureAmsSlot.configuring`)]}):(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)(p,{className:`w-4 h-4`}),x(`configureAmsSlot.configureSlot`)]})})]})]}),(Ee.isError||De.isError)&&(0,O.jsx)(`div`,{className:`mx-4 mb-4 p-2 bg-red-100 dark:bg-red-500/20 border border-red-300 dark:border-red-500/50 rounded text-sm text-red-700 dark:text-red-400`,children:Ee.error?.message||De.error?.message})]})]})}export{A as n,k as r,P as t}; \ No newline at end of file +import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,w as i}from"./client-DnySrlFv.js";import{n as a}from"./QueryClientProvider-Ce8_sN3w.js";import{t as o}from"./useQuery-BBCjCezC.js";import{t as s}from"./useMutation-B-Tr2hIP.js";import{a as c}from"./info-ROUoQhJR.js";import{n as l}from"./ToastContext-BRX0SW3C.js";import{t as u}from"./loader-circle-BEmFtawu.js";import{t as d}from"./package-BGUevlqS.js";import{t as f}from"./search-0n0CBc74.js";import{t as p}from"./settings-2-Cvn837lh.js";import{t as ee}from"./x-DR-Trv6U.js";import{t as m}from"./Button-DDr6eAFy.js";import{An as h,Gt as g,U as _,_t as v,ft as y,lt as b,sn as x}from"./index-Cxa-KVmA.js";import{a as S,i as C,n as w,r as T}from"./slicerPrinterMatch-CUdoNag2.js";import{p as E}from"./utils-subfXwl6.js";import{t as te}from"./inventorySearch-TJiB5tGt.js";import{t as ne}from"./useCancellableTimeout-3XQzNJkJ.js";var D=e(n(),1),O=t();function k({isOpen:e,onClose:t,tagUid:n,trayUuid:c,printerId:d,amsId:p,trayId:h}){let{t:g}=i(),_=a(),{showToast:v}=l(),[y,S]=(0,D.useState)(``),C=c||n,{data:w,isLoading:T}=o({queryKey:[`unlinked-spools`],queryFn:r.getUnlinkedSpools,enabled:e}),E=(0,D.useMemo)(()=>w?w.filter(e=>{if(!y)return!0;let t=y.toLowerCase();return e.filament_name&&e.filament_name.toLowerCase().includes(t)||e.filament_vendor&&e.filament_vendor.toLowerCase().includes(t)||e.filament_material&&e.filament_material.toLowerCase().includes(t)||String(e.id).includes(t)}):[],[w,y]),te=s({mutationFn:e=>r.linkSpool(e,{spoolTag:C,printerId:d,amsId:p,trayId:h}),onSuccess:()=>{_.invalidateQueries({queryKey:[`unlinked-spools`]}),_.invalidateQueries({queryKey:[`linked-spools`]}),_.invalidateQueries({queryKey:[`spoolman-slot-assignments`]}),v(g(`spoolman.linkSuccess`),`success`),t()},onError:e=>{v(e.message||g(`spoolman.linkFailed`),`error`)}});return e?(0,O.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[(0,O.jsx)(`div`,{className:`absolute inset-0 bg-black/60 backdrop-blur-sm`,onClick:t}),(0,O.jsxs)(`div`,{className:`relative bg-bambu-dark-secondary rounded-xl shadow-xl w-full max-w-md mx-4 max-h-[80vh] flex flex-col border border-bambu-dark-tertiary`,children:[(0,O.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-white/10`,children:[(0,O.jsxs)(`div`,{children:[(0,O.jsxs)(`h3`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,O.jsx)(x,{className:`w-5 h-5 text-bambu-green`}),g(`spoolman.selectSpool`)]}),(0,O.jsxs)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:[`AMS `,p,` T`,h,` · Printer #`,d]})]}),(0,O.jsx)(`button`,{onClick:t,className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,O.jsx)(ee,{className:`w-5 h-5`})})]}),(0,O.jsxs)(`div`,{className:`p-4 border-b border-white/10`,children:[(0,O.jsxs)(`div`,{className:`relative`,children:[(0,O.jsx)(f,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,O.jsx)(`input`,{type:`text`,value:y,onChange:e=>S(e.target.value),placeholder:g(`inventory.searchSpools`),className:`w-full pl-9 pr-3 py-2 bg-bambu-dark rounded-lg border border-white/10 text-white text-sm placeholder:text-bambu-gray focus:outline-none focus:border-bambu-green`})]}),(c||n)&&(0,O.jsxs)(`p`,{className:`text-xs text-bambu-gray mt-2 font-mono truncate`,title:c||n,children:[`Tag: `,c||n]})]}),(0,O.jsx)(`div`,{className:`flex-1 overflow-y-auto p-2 min-h-0`,children:T?(0,O.jsx)(`div`,{className:`flex justify-center py-8`,children:(0,O.jsx)(u,{className:`w-6 h-6 animate-spin text-bambu-green`})}):E.length===0?(0,O.jsx)(`p`,{className:`text-center text-bambu-gray py-8 text-sm`,children:g(`inventory.noSpoolsMatch`)}):E.map(e=>(0,O.jsxs)(`button`,{onClick:()=>te.mutate(e.id),disabled:te.isPending||!C,className:`w-full flex items-center gap-3 p-3 rounded-lg hover:bg-white/5 transition-colors text-left`,children:[(0,O.jsx)(`span`,{className:`w-6 h-6 rounded-full border border-black/20 flex-shrink-0`,style:b(e.filament_color_hex)}),(0,O.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,O.jsx)(`div`,{className:`text-sm text-white font-medium truncate`,children:e.filament_name||g(`spoolman.spoolId`)}),(0,O.jsxs)(`div`,{className:`text-xs text-bambu-gray truncate`,children:[e.filament_vendor?`${e.filament_vendor} · `:``,e.filament_material||`Unknown`,` · #`,e.id]})]}),(0,O.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:e.remaining_weight==null?`—`:`${Math.round(e.remaining_weight)}g`})]},e.id))}),(0,O.jsx)(`div`,{className:`p-4 border-t border-white/10 flex justify-end`,children:(0,O.jsx)(m,{variant:`ghost`,onClick:t,children:g(`inventory.cancel`)||`Cancel`})})]})]}):null}function A({isOpen:e,onClose:t,printerId:n,amsId:c,trayId:p,trayInfo:h,spoolmanEnabled:g}){let{t:_}=i(),x=a(),{showToast:S}=l(),[C,w]=(0,D.useState)(!1),[T,E]=(0,D.useState)(null),[ne,k]=(0,D.useState)(null);(0,D.useEffect)(()=>{E(null),k(null)},[C]);let[A,re]=(0,D.useState)(``),[j,ie]=(0,D.useState)(null),[M,ae]=(0,D.useState)(!1),[N,oe]=(0,D.useState)(null);(0,D.useEffect)(()=>{e&&w(!1)},[e]);let{data:se,isLoading:ce}=o({queryKey:[`inventory-spools`,`assign-modal`],queryFn:()=>r.getSpools(!0),enabled:e&&!g}),{data:le}=o({queryKey:[`spool-assignments`],queryFn:()=>r.getAssignments(),enabled:e}),{data:ue}=o({queryKey:[`settings`],queryFn:()=>r.getSettings(),enabled:e}),{data:de,isLoading:P}=o({queryKey:[`spoolman-inventory-spools`,`assign-modal`],queryFn:()=>r.getSpoolmanInventorySpools(!1),enabled:e&&!!g}),{data:F}=o({queryKey:[`spoolman-slot-assignments-all`],queryFn:()=>r.getSpoolmanSlotAssignments(),enabled:e&&!!g}),I=(0,D.useMemo)(()=>F?new Set(F.filter(e=>!(e.printer_id===n&&e.ams_id===c&&e.tray_id===p)).map(e=>e.spoolman_spool_id)):new Set,[F,n,c,p]),L=()=>{r.refreshPrinterStatus(n).catch(()=>{}),x.invalidateQueries({queryKey:[`printerStatus`,n]})},R=s({mutationFn:e=>r.assignSpool({spool_id:e,printer_id:n,ams_id:c,tray_id:p}),onSuccess:e=>{x.setQueryData([`spool-assignments`],t=>{let r=(t||[]).filter(e=>!(e.printer_id===n&&e.ams_id===c&&e.tray_id===p));return r.push(e),r}),x.invalidateQueries({queryKey:[`spool-assignments`]}),L(),S(_(e.pending_config?`inventory.assignPendingInsert`:`inventory.assignSuccess`),`success`),ae(!1),ie(null),oe(null),t()},onError:e=>{S(`${_(`inventory.assignFailed`)}: ${e.message}`,`error`)}}),z=s({mutationFn:e=>r.assignSpoolmanSlot({spoolman_spool_id:e,printer_id:n,ams_id:c,tray_id:p}),onSuccess:()=>{x.invalidateQueries({queryKey:[`spoolman-inventory-spools`]}),x.invalidateQueries({queryKey:[`spoolman-slot-assignments`]}),L(),S(_(`inventory.assignSuccess`),`success`),t()},onError:e=>{S(`${_(`inventory.assignFailed`)}: ${e.message}`,`error`)}}),B=e=>(e??``).trim().toUpperCase(),V=(e,t)=>{let n=B(e),r=B(t);return!n||!r?`none`:n===r?`exact`:r.includes(n)||n.includes(r)?`partial`:`none`},H=e=>e.split(`@`)[0].trim(),fe=(e,t)=>{let n=H(B(e)),r=H(B(t));return!n||!r?!1:n===r};if(!e)return null;let pe=new Set((le||[]).filter(e=>!(e.printer_id===n&&e.ams_id===c&&e.tray_id===p)).map(e=>e.spool_id)),U=se?.filter(e=>!e.archived_at&&(C||!pe.has(e.id))),W=U;if(!C){let e=H(B(h?.profile)),t=B(h?.material||h?.type);(e||t)&&(W=W?.filter(n=>{let r=H(B(n.slicer_filament_name||n.slicer_filament)),i=B(n.material);return e&&r&&r===e?!0:t&&i?i===t||t.includes(i)||i.includes(t):!r&&!i}))}A&&W&&(W=te(W,A));let me=()=>{if(ne!==null){z.mutate(ne);return}if(!T)return;let e=se?.find(e=>e.id===T);if(!e){S(_(`inventory.assignFailed`),`error`);return}if(!ue?.disable_filament_warnings&&h){let t=h.material||h.type,n=V(e.material,t),r=e.slicer_filament_name||e.slicer_filament,i=h.profile||h.type,a=fe(r,i);if(n!==`exact`){let o;o=n===`none`&&!a?`material_profile`:n===`partial`&&!a?`partial_profile`:n===`none`?`material`:`partial`,ie(T),oe({type:o,spoolMaterial:e.material||``,trayMaterial:t||``,spoolProfile:r||void 0,trayProfile:i||void 0}),ae(!0);return}}R.mutate(T)},he=()=>{j&&(R.mutate(j),ae(!1),ie(null))};return(0,O.jsxs)(O.Fragment,{children:[(0,O.jsxs)(`div`,{className:`fixed inset-0 z-[100] flex items-start sm:items-center justify-center p-4 overflow-y-auto`,children:[(0,O.jsx)(`div`,{className:`absolute inset-0 bg-black/60 backdrop-blur-sm`,onClick:t}),(0,O.jsxs)(`div`,{className:`relative w-full max-w-2xl bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl max-h-[90vh] overflow-hidden flex flex-col my-auto`,children:[(0,O.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,O.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,O.jsx)(d,{className:`w-5 h-5 text-bambu-green`}),(0,O.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:_(`inventory.assignSpool`)})]}),(0,O.jsx)(`button`,{onClick:t,className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,O.jsx)(ee,{className:`w-5 h-5`})})]}),(0,O.jsxs)(`div`,{className:`p-4 space-y-4 overflow-y-auto`,children:[h&&(0,O.jsxs)(`div`,{className:`p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,O.jsxs)(`p`,{className:`text-xs text-bambu-gray mb-1`,children:[_(`inventory.selectSpool`),`:`]}),(0,O.jsxs)(`div`,{className:`flex items-center gap-2`,children:[h.color&&(0,O.jsx)(`span`,{className:`w-4 h-4 rounded-full border border-black/20`,style:b(h.color)}),(0,O.jsx)(`span`,{className:`text-white font-medium`,children:h.type||_(`ams.emptySlot`)}),(0,O.jsxs)(`span`,{className:`text-bambu-gray`,children:[`(`,h.location,`)`]})]})]}),(0,O.jsxs)(`div`,{className:`relative`,children:[(0,O.jsx)(f,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,O.jsx)(`input`,{type:`text`,value:A,onChange:e=>re(e.target.value),placeholder:_(`inventory.searchSpools`),className:`w-full pl-9 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray focus:outline-none focus:border-bambu-green`})]}),(0,O.jsxs)(`div`,{className:`space-y-3`,children:[!g&&(ce?(0,O.jsx)(`div`,{className:`flex justify-center py-8`,children:(0,O.jsx)(u,{className:`w-6 h-6 text-bambu-green animate-spin`})}):W&&W.length>0?(0,O.jsx)(`div`,{className:`max-h-96 overflow-y-auto grid grid-cols-2 sm:grid-cols-3 gap-2`,children:W.map(e=>(0,O.jsxs)(`button`,{onClick:()=>{E(e.id),k(null)},title:e.note||void 0,className:`p-2.5 rounded-lg border text-left transition-colors ${T===e.id?`bg-bambu-green/20 border-bambu-green`:`bg-bambu-dark border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:[(0,O.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,O.jsxs)(`p`,{className:`text-white text-sm font-medium truncate`,children:[e.brand?`${e.brand} `:``,e.material,e.subtype?` ${e.subtype}`:``]}),(0,O.jsxs)(`span`,{className:`text-[10px] font-mono text-bambu-gray shrink-0`,children:[`#`,e.id]})]}),(0,O.jsxs)(`div`,{className:`flex items-center gap-1.5 mt-1`,children:[e.rgba&&(0,O.jsx)(`span`,{className:`w-3 h-3 rounded-full border border-black/20 flex-shrink-0`,style:b(e.rgba)}),(0,O.jsx)(`span`,{className:`text-xs text-bambu-gray truncate`,children:y(e.color_name,e.rgba,e.color_name_is_synthesized)||``})]}),e.label_weight&&(0,O.jsxs)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:[Math.max(0,Math.round(e.label_weight-e.weight_used)),` / `,e.label_weight,`g`]}),e.note&&(0,O.jsx)(`p`,{className:`text-[10px] text-bambu-gray/70 mt-1 truncate`,title:e.note,children:e.note})]},e.id))}):U&&U.length===0?(0,O.jsxs)(`div`,{className:`text-center py-8 text-bambu-gray`,children:[(0,O.jsx)(`p`,{children:_(`inventory.noAvailableSpools`)}),se&&(0,O.jsxs)(`p`,{className:`text-[10px] mt-2 opacity-60`,children:[se.length,` fetched · `,se.filter(e=>e.archived_at).length,` archived ·`,` `,se.filter(e=>pe.has(e.id)).length,` assigned to other slots`]})]}):(0,O.jsxs)(`div`,{className:`text-center py-8 text-bambu-gray`,children:[(0,O.jsx)(`p`,{children:_(`inventory.noSpoolsMatch`)}),U&&(0,O.jsxs)(`p`,{className:`text-[10px] mt-2 opacity-60`,children:[U.length,` unassigned spools — `,U.length-(W?.length??0),` filtered by tray match. Try "Show all spools".`]})]})),g&&(0,O.jsx)(O.Fragment,{children:P?(0,O.jsx)(`div`,{className:`flex justify-center py-4`,children:(0,O.jsx)(u,{className:`w-5 h-5 text-bambu-green animate-spin`})}):de&&de.filter(e=>!e.archived_at&&!I.has(e.id)).length>0?(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)(`p`,{className:`text-xs font-medium text-bambu-gray uppercase tracking-wide pt-1`,children:_(`inventory.spoolmanSpools`)}),(0,O.jsx)(`div`,{className:`max-h-64 overflow-y-auto grid grid-cols-2 sm:grid-cols-3 gap-2`,children:te(de.filter(e=>!e.archived_at&&!I.has(e.id)),A).map(e=>(0,O.jsxs)(`button`,{onClick:()=>{k(e.id),E(null)},title:e.note||void 0,className:`p-2.5 rounded-lg border text-left transition-colors ${ne===e.id?`bg-bambu-green/20 border-bambu-green`:`bg-bambu-dark border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:[(0,O.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,O.jsxs)(`p`,{className:`text-white text-sm font-medium truncate`,children:[e.brand?`${e.brand} `:``,e.material,e.subtype?` ${e.subtype}`:``]}),(0,O.jsxs)(`span`,{className:`text-[10px] font-mono text-bambu-gray shrink-0`,children:[`#`,e.id]})]}),(0,O.jsxs)(`div`,{className:`flex items-center gap-1.5 mt-1`,children:[e.rgba&&(0,O.jsx)(`span`,{className:`w-3 h-3 rounded-full border border-black/20 flex-shrink-0`,style:b(e.rgba)}),(0,O.jsx)(`span`,{className:`text-xs text-bambu-gray truncate`,children:y(e.color_name,e.rgba,e.color_name_is_synthesized)||``})]}),e.label_weight&&(0,O.jsxs)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:[Math.max(0,Math.round(e.label_weight-e.weight_used)),` / `,e.label_weight,`g`]}),e.note&&(0,O.jsx)(`p`,{className:`text-[10px] text-bambu-gray/70 mt-1 truncate`,title:e.note,children:e.note})]},`spoolman-${e.id}`))})]}):null})]})]}),(0,O.jsxs)(`div`,{className:`flex justify-between items-center p-4 border-t border-bambu-dark-tertiary`,children:[(0,O.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,O.jsx)(`input`,{id:`disable-filtering-toggle`,type:`checkbox`,checked:C,onChange:()=>w(e=>!e),className:`accent-bambu-green w-4 h-4 rounded focus:ring-0 border-bambu-dark-tertiary`}),(0,O.jsx)(`label`,{htmlFor:`disable-filtering-toggle`,className:`text-xs text-bambu-gray select-none cursor-pointer`,children:_(`inventory.showAllSpools`)})]}),(0,O.jsxs)(`div`,{className:`flex gap-2`,children:[(0,O.jsx)(m,{variant:`secondary`,onClick:t,children:_(`common.cancel`)}),(0,O.jsx)(m,{onClick:me,disabled:!T&&ne===null||R.isPending||z.isPending,children:R.isPending||z.isPending?(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)(u,{className:`w-4 h-4 animate-spin`}),_(`inventory.assigning`)]}):(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)(d,{className:`w-4 h-4`}),_(`inventory.assignSpool`)]})})]})]}),R.isError&&(0,O.jsx)(`div`,{className:`mx-4 mb-4 p-2 bg-red-100 dark:bg-red-500/20 border border-red-300 dark:border-red-500/50 rounded text-sm text-red-700 dark:text-red-400`,children:R.error.message})]})]}),M&&h&&T&&N&&(()=>{let e=``;return N.type===`material`?e=_(`inventory.assignMismatchMessage`,{spoolMaterial:N.spoolMaterial,trayMaterial:N.trayMaterial,location:h.location}):N.type===`partial`?e=_(`inventory.assignPartialMismatchMessage`,{spoolMaterial:N.spoolMaterial,trayMaterial:N.trayMaterial,location:h.location}):N.type===`material_profile`?e=`${_(`inventory.assignMismatchMessage`,{spoolMaterial:N.spoolMaterial,trayMaterial:N.trayMaterial,location:h.location})}\n\n${_(`inventory.assignProfileMismatchMessage`,{spoolProfile:N.spoolProfile||_(`common.unknown`),trayProfile:N.trayProfile||_(`common.unknown`),location:h.location})}`:N.type===`partial_profile`&&(e=`${_(`inventory.assignPartialMismatchMessage`,{spoolMaterial:N.spoolMaterial,trayMaterial:N.trayMaterial,location:h.location})}\n\n${_(`inventory.assignProfileMismatchMessage`,{spoolProfile:N.spoolProfile||_(`common.unknown`),trayProfile:N.trayProfile||_(`common.unknown`),location:h.location})}`),e=`${e}\n\n${_(`inventory.assignReconfigureNote`)}`,(0,O.jsx)(v,{title:_(`inventory.assignMismatchTitle`),message:e,confirmText:_(`inventory.assignMismatchConfirm`),variant:`warning`,overlayZIndex:`z-[110]`,isLoading:R.isPending,onConfirm:he,onCancel:()=>{R.isPending||(ae(!1),ie(null),oe(null))}})})()]})}function re(e){let t=e.includes(`_`)?e.split(`_`)[0]:e;return t.startsWith(`GFS`)?`GF`+t.slice(3):(t.startsWith(`PFUS`)||t.startsWith(`PFSP`),t)}var j=[`PLA`,`PETG`,`PCTG`,`ABS`,`ASA`,`TPU`,`PC`,`PA`,`NYLON`,`PVA`,`HIPS`,`PP`,`PET`];function ie(e){let t=e.replace(/@.+$/,``).trim(),n=t.toUpperCase(),r=n.match(/\bSUPPORT\s+FOR\s+/);if(r){let e=n.slice(r.index+r[0].length);for(let n of j)if(RegExp(`\\b${n}\\b`).test(e))return{material:n,brand:t.slice(0,r.index).trim(),variant:`Support`}}for(let e of j){let r=RegExp(`\\b${e}\\b`,`i`);if(r.test(n)){let n=t.split(r);return{material:e,brand:n[0]?.trim()||``,variant:n[1]?.trim()||``}}}let i=t.split(/\s+/);return i.length>=2?{material:i[1],brand:i[0],variant:i.slice(2).join(` `)}:{material:t,brand:``,variant:``}}function M(e){return`${e.extruder_id??0}|${e.name}|${e.k_value}`}function ae(e,t){return t===void 0?!1:e.some(e=>(e.extruder_id??0)===t)}function N(e,t,n){return ae(e,n)?e.find(e=>e.slot_id===t&&(e.extruder_id??0)===n):e.find(e=>e.slot_id===t)}function oe(e,t,n){return t?` \u00b7 ${e.extruder_id===1?n(`common.left`):n(`common.right`)}`:``}function se(e){return!e.startsWith(`GF`)&&!e.startsWith(`P1`)}var ce={white:`FFFFFF`,black:`000000`,red:`FF0000`,green:`00FF00`,blue:`0000FF`,yellow:`FFFF00`,cyan:`00FFFF`,magenta:`FF00FF`,orange:`FFA500`,purple:`800080`,pink:`FFC0CB`,brown:`8B4513`,gray:`808080`,grey:`808080`,"jade white":`FFFEF2`,ivory:`FFFFF0`,beige:`F5F5DC`,cream:`FFFDD0`,silver:`C0C0C0`,gold:`FFD700`,bronze:`CD7F32`,copper:`B87333`,navy:`000080`,teal:`008080`,olive:`808000`,maroon:`800000`,coral:`FF7F50`,salmon:`FA8072`,lime:`32CD32`,mint:`98FF98`,"forest green":`228B22`,"sky blue":`87CEEB`,"royal blue":`4169E1`,turquoise:`40E0D0`,lavender:`E6E6FA`,violet:`EE82EE`,plum:`DDA0DD`,tan:`D2B48C`,chocolate:`D2691E`,charcoal:`36454F`,slate:`708090`,transparent:`000000`,natural:`F5F5DC`,wood:`DEB887`},le=[{name:`White`,hex:`FFFFFF`},{name:`Black`,hex:`000000`},{name:`Red`,hex:`FF0000`},{name:`Blue`,hex:`0000FF`},{name:`Green`,hex:`00AA00`},{name:`Yellow`,hex:`FFFF00`},{name:`Orange`,hex:`FFA500`},{name:`Gray`,hex:`808080`}],ue=[{name:`Cyan`,hex:`00FFFF`},{name:`Magenta`,hex:`FF00FF`},{name:`Purple`,hex:`800080`},{name:`Pink`,hex:`FFC0CB`},{name:`Brown`,hex:`8B4513`},{name:`Beige`,hex:`F5F5DC`},{name:`Navy`,hex:`000080`},{name:`Teal`,hex:`008080`},{name:`Lime`,hex:`32CD32`},{name:`Gold`,hex:`FFD700`},{name:`Silver`,hex:`C0C0C0`},{name:`Maroon`,hex:`800000`},{name:`Olive`,hex:`808000`},{name:`Coral`,hex:`FF7F50`},{name:`Salmon`,hex:`FA8072`},{name:`Turquoise`,hex:`40E0D0`},{name:`Violet`,hex:`EE82EE`},{name:`Indigo`,hex:`4B0082`},{name:`Chocolate`,hex:`D2691E`},{name:`Tan`,hex:`D2B48C`},{name:`Slate`,hex:`708090`},{name:`Charcoal`,hex:`36454F`},{name:`Ivory`,hex:`FFFFF0`},{name:`Cream`,hex:`FFFDD0`}];function de(e){return ce[e.toLowerCase().trim()]||null}function P({isOpen:e,onClose:t,printerId:n,slotInfo:a,nozzleDiameter:d=`0.4`,printerModel:f,onSuccess:v,fullScreen:y}){let{t:x}=i(),{showToast:te}=l(),[k,A]=(0,D.useState)(``),[ce,P]=(0,D.useState)(``),[F,I]=(0,D.useState)(null),L=(0,D.useRef)(null);L.current=F;let[R,z]=(0,D.useState)(``),[B,V]=(0,D.useState)(``),[H,fe]=(0,D.useState)(``),[pe,U]=(0,D.useState)(!1),[W,me]=(0,D.useState)(!1),he=(0,D.useRef)(``),{schedule:ge}=ne(),{data:G,isLoading:_e,isError:ve}=o({queryKey:[`cloudSettings`],queryFn:()=>r.getCloudSettings(),enabled:e,retry:!1}),{data:ye}=o({queryKey:[`orcaCloudProfilesForAmsSlot`],queryFn:()=>r.orcaCloudListProfiles(),enabled:e,retry:!1}),{data:K,isLoading:be}=o({queryKey:[`localPresets`],queryFn:()=>r.getLocalPresets(),enabled:e}),{data:q,isLoading:xe}=o({queryKey:[`builtinFilaments`],queryFn:()=>r.getBuiltinFilaments(),enabled:e,staleTime:1/0}),{data:J,isLoading:Se}=o({queryKey:[`kprofiles`,n,d],queryFn:()=>r.getKProfiles(n,d),enabled:e&&!!n}),{data:Ce}=o({queryKey:[`colorCatalog`],queryFn:()=>r.getColorCatalog(),enabled:e,staleTime:1/0}),{data:Y}=o({queryKey:[`slicerPrinterModels`],queryFn:r.getSlicerPrinterModels,enabled:e,staleTime:1/0}),{data:X}=o({queryKey:[`slot-spool-defaults`,n,a.amsId,a.trayId],queryFn:()=>r.getSlotSpoolDefaults(n,a.amsId,a.trayId),enabled:e,staleTime:0}),we=(0,D.useMemo)(()=>w(Y??{}),[Y]),Te=(0,D.useMemo)(()=>{if(!f||!Y)return null;for(let[e,t]of Object.entries(Y))if(t===f)return`${e.startsWith(`Bambu Lab `)?e:`Bambu Lab ${e}`} ${d} nozzle`;return null},[f,Y,d]),Ee=s({mutationFn:async()=>{if(!k)throw Error(`No filament preset selected`);let e=k.startsWith(`local_`),t=k.startsWith(`builtin_`),i=k.startsWith(`orca_`)?k.replace(`orca_`,``):k,o=!e&&!t?ye?.filament.find(e=>e.setting_id===i):void 0,s=!!o,c=o??null,l=e?parseInt(k.replace(`local_`,``),10):null,u=t?k.replace(`builtin_`,``):null,f=e?K?.filament.find(e=>e.id===l):null,p=t?q?.find(e=>e.filament_id===u):null,ee=!e&&!t&&!s?G?.filament.find(e=>e.setting_id===k):null;if(!e&&!t&&!s&&!ee)throw Error(`Selected preset not found`);if(e&&!f)throw Error(`Selected local preset not found`);if(t&&!p)throw Error(`Selected builtin preset not found`);if(s&&!c)throw Error(`Selected Orca Cloud preset not found`);let m=e?f.name:t?p.name:s?c.name:ee.name,h=ie(m),g=L.current?.slot_id??-1,_=R||a.trayColor?.slice(0,6)||`FFFFFF`,v=m.replace(/@.+$/,``).trim(),y,b,S=h.material.toUpperCase(),C={PLA:`GFL99`,"PLA-CF":`GFL98`,"PLA SILK":`GFL96`,"PLA HIGH SPEED":`GFL95`,PETG:`GFG99`,"PETG HF":`GFG96`,"PETG-CF":`GFG98`,PCTG:`GFG97`,ABS:`GFB99`,ASA:`GFB98`,PC:`GFC99`,PA:`GFN99`,"PA-CF":`GFN98`,NYLON:`GFN99`,TPU:`GFU99`,PVA:`GFS99`,HIPS:`GFS98`,PE:`GFP99`,PP:`GFP97`};if(e){let e=(j.includes(S)?S:f?.filament_type||h.material||``).toUpperCase();y=C[e]||C[e.replace(/[-\s]?CF$/,``)]||C[e.replace(/\+$/,``)]||C[e.split(/[-\s]/)[0]]||``,b=``}else if(s)y=``,b=``;else if(t)y=u,b=``;else{if(y=re(k),b=k,!k.startsWith(`GFS`))try{let e=await r.getCloudSettingDetail(k),t=e.setting?.filament_id,n=e.filament_id||(typeof t==`string`?t:``);n&&(y=n)}catch(e){console.warn(`Failed to fetch preset detail for filament_id:`,e)}/^(PFUS|PFSP|PFCN)/.test(y)&&(console.warn(`Cloud preset ${k} carries no filament_id in either place; sending no tray_info_idx so the printer keeps a resolvable one.`),y=``)}let w=e&&f?.nozzle_temp_min?f.nozzle_temp_min:190,T=e&&f?.nozzle_temp_max?f.nozzle_temp_max:230;if(!e||t||s||!f?.nozzle_temp_min&&!f?.nozzle_temp_max){let t=(e?j.includes(S)?S:f?.filament_type||h.material||``:h.material).toUpperCase();t.includes(`PLA`)?(w=190,T=230):t.includes(`PETG`)?(w=220,T=260):t.includes(`ABS`)||t.includes(`ASA`)?(w=240,T=280):t.includes(`TPU`)?(w=200,T=240):t===`PCTG`?(w=220,T=260):t.includes(`PC`)?(w=260,T=300):(t.includes(`PA`)||t.includes(`NYLON`))&&(w=250,T=290)}let E=L.current?.k_value?parseFloat(L.current.k_value):0,ne=e?j.includes(S)?S:f?.filament_type||h.material||`PLA`:s&&j.includes(S)?S:h.material||`PLA`,D=await r.configureAmsSlot(n,a.amsId,a.trayId,{tray_info_idx:y,tray_type:ne,tray_sub_brands:v,tray_color:_+`FF`,nozzle_temp_min:w,nozzle_temp_max:T,cali_idx:g,nozzle_diameter:d,setting_id:b,kprofile_filament_id:L.current?.filament_id,kprofile_setting_id:L.current?.setting_id||void 0,k_value:E,orca_profile_id:s?i:void 0});s&&D.orca_fallback_reason&&te(x(`configureAmsSlot.orcaFallback.${D.orca_fallback_reason}`,{material:ne}),`warning`);let O=e?`local_${l}`:t?`builtin_${u}`:k,A=e?`local`:t?`builtin`:s?`orca_cloud`:`cloud`;try{await r.saveSlotPreset(n,a.amsId,a.trayId,O,v,A,D.tray_info_idx)}catch(e){console.warn(`Failed to save slot preset mapping:`,e)}return D},onSuccess:()=>{U(!0),v?.(),ge(()=>{U(!1),t()},1500)}}),De=s({mutationFn:async()=>r.resetAmsSlot(n,a.amsId,a.trayId),onSuccess:()=>{U(!0),v?.(),ge(()=>{U(!1),t()},1500)}}),Oe=(0,D.useMemo)(()=>{let e=H.toLowerCase(),t=[],n=new Set,r=a.savedPresetId,i=a.trayInfoIdx;if(ye?.filament)for(let r of ye.filament){let i=`orca_${r.setting_id}`;if(n.add(r.setting_id),n.add(i),!(e&&!r.name.toLowerCase().includes(e))){if(f){let e=T(r.name,Y??{});if(e&&!C(e,f))continue}t.push({id:i,name:r.name,source:`orca_cloud`,isUser:!0})}}if(G?.filament)for(let a of G.filament){if(n.has(a.setting_id))continue;n.add(a.setting_id);let o=r===a.setting_id||i&&(a.setting_id===i||re(a.setting_id)===i);if(!(e&&!a.name.toLowerCase().includes(e))){if(!o&&f){let e=T(a.name,Y??{});if(e&&!C(e,f))continue}t.push({id:a.setting_id,name:a.name,source:`cloud`,isUser:se(a.setting_id)})}}if(K?.filament){let n=a.savedPresetId;for(let r of K.filament){let i=`local_${r.id}`;if(!(e&&!r.name.toLowerCase().includes(e))){if(n!==i&&Te){let e=null;if(r.compatible_printers)try{let t=JSON.parse(r.compatible_printers);Array.isArray(t)&&(e=t.filter(e=>typeof e==`string`))}catch{e=null}if(S({name:r.name,compatible_printers:e},`filament`,Te,we)===`mismatch`)continue}t.push({id:i,name:r.name,source:`local`,isUser:!1})}}}if(q)for(let r of q){if(n.has(r.filament_id))continue;let i=r.filament_id.startsWith(`GF`)?`GFS`+r.filament_id.slice(2):r.filament_id;n.has(i)||(!e||r.name.toLowerCase().includes(e))&&t.push({id:`builtin_${r.filament_id}`,name:r.name,source:`builtin`,isUser:!1})}return t.sort((e,t)=>{let n={local:0,orca_cloud:1,cloud:2,builtin:3};return e.source===t.source?e.isUser&&!t.isUser?-1:!e.isUser&&t.isUser?1:e.name.localeCompare(t.name):n[e.source]-n[t.source]})},[ye?.filament,G?.filament,K?.filament,q,H,f,a.savedPresetId,a.trayInfoIdx,Te,we,Y]),Z=(0,D.useMemo)(()=>{if(!k)return null;let e=null,t=``;if(k.startsWith(`local_`)){let t=parseInt(k.replace(`local_`,``),10);e=K?.filament.find(e=>e.id===t)?.name||null}else if(k.startsWith(`builtin_`)){let n=k.replace(`builtin_`,``);e=q?.find(e=>e.filament_id===n)?.name||null,t=E(n)}else{let n=k.startsWith(`orca_`)?k.replace(`orca_`,``):k,r=ye?.filament.find(e=>e.setting_id===n);if(r)e=r.name;else if(G?.filament){let n=G.filament.find(e=>e.setting_id===k);e=n?.name||null,n&&(t=E(n.setting_id))}}if(!e)return null;let n=e.replace(/@.+$/,``).trim();n.startsWith(`# `)&&(n=n.slice(2).trim());let r=ie(n);return{fullName:n,material:r.material,brand:r.brand,filamentId:t}},[k,G?.filament,K?.filament,q,ye?.filament]),ke=Z?.fullName||``,Ae=(0,D.useMemo)(()=>{if(!Ce||!Z)return[];let{fullName:e,brand:t}=Z,n=e.replace(/^(Bambu\s*(Lab)?|eSUN|Polymaker|Overture|Sunlu|Hatchbox)\s*/i,``).trim();return Ce.filter(e=>{let r=(e.material||``).toUpperCase(),i=e.manufacturer.toUpperCase();if(!(r===n.toUpperCase()||r.includes(n.toUpperCase())||n.toUpperCase().includes(r)))return!1;if(t){let e=t.toUpperCase();if(!i.includes(e)&&!e.includes(i))return!1}return!0})},[Ce,Z]),je=(0,D.useMemo)(()=>new Set((J?.profiles??[]).map(e=>e.extruder_id??0)).size>1,[J?.profiles]),Q=(0,D.useMemo)(()=>{if(!J?.profiles)return[];if(!Z){let e=a.caliIdx;if(e!=null&&e>0){let t=N(J.profiles,e,a.extruderId);if(t)return[t]}return[]}let{fullName:e,material:t,brand:n,filamentId:r}=Z,i=e.toUpperCase(),o=t.toUpperCase(),s=n.toUpperCase()===`GENERIC`?``:n.toUpperCase(),c=r;if(!o||o.length<2)return[];let l=J.profiles.filter(e=>{if(c){let t=E(e.filament_id);if(t&&t===c)return!0}let t=e.name.toUpperCase();if(s)return!(!t.includes(s)||!t.includes(o));if(t.includes(i)||t.includes(o))return!0;let n={NYLON:[`PA`,`PA-CF`,`PA6`],PA:[`NYLON`]}[o]||[];for(let e of n)if(t.includes(e))return!0;return!1}),u=ae(J.profiles,a.extruderId)?l.filter(e=>(e.extruder_id??0)===a.extruderId):l,d=new Map;for(let e of u){let t=M(e);d.has(t)||d.set(t,e)}let f=Array.from(d.values()),p=a.caliIdx;if((ce&&k===ce||c&&c===E(a.trayInfoIdx))&&p!=null&&p>0&&!f.some(e=>e.slot_id===p)){let e=N(J.profiles,p,a.extruderId);e&&f.unshift(e)}return f},[J?.profiles,Z,a.extruderId,a.caliIdx,a.trayInfoIdx,k,ce]),$=(0,D.useMemo)(()=>{if(!J?.profiles)return[];let e=new Set(Q.map(e=>M(e))),t=new Map;for(let n of J.profiles){let r=M(n);e.has(r)||t.has(r)||t.set(r,n)}return Array.from(t.values()).sort((e,t)=>e.name.localeCompare(t.name))},[J?.profiles,Q]),Me=Q.length>0||$.length>0,Ne=(0,D.useCallback)(e=>{if(!e){I(null);return}I(Q.find(t=>M(t)===e)||$.find(t=>M(t)===e)||null)},[Q,$]);(0,D.useEffect)(()=>{if(e){if(X?.slicer_filament)A(X.slicer_filament),P(X.slicer_filament);else if(a.savedPresetId)A(a.savedPresetId),P(a.savedPresetId);else if(a.trayInfoIdx&&G?.filament){let e=G.filament.find(e=>e.setting_id===a.trayInfoIdx);e||=G.filament.find(e=>re(e.setting_id)===a.trayInfoIdx),e&&(A(e.setting_id),P(e.setting_id))}else if(a.trayInfoIdx&&q?.length){let e=a.trayInfoIdx,t=q.find(t=>t.filament_id===e);t&&(A(`builtin_${t.filament_id}`),P(`builtin_${t.filament_id}`))}if(a.trayColor){let e=a.trayColor.slice(0,6);e&&z(e)}}else A(``),P(``),I(null),z(``),V(``),fe(``),U(!1),he.current=``},[e,X?.slicer_filament,a.savedPresetId,a.trayInfoIdx,a.trayColor,G?.filament,q]),(0,D.useEffect)(()=>{if(Q.length>0){if(X?.cali_idx!=null){let e=N(Q,X.cali_idx,X.extruder??a.extruderId);if(e){I(e);return}}if(a.caliIdx!=null&&a.caliIdx>0){let e=N(Q,a.caliIdx,a.extruderId);if(e){I(e);return}}I(Q[0])}else I(null)},[k,Q,X?.cali_idx,X?.extruder,a.caliIdx,a.extruderId]);let Pe=(0,D.useCallback)(e=>{e.key===`Escape`&&t()},[t]);(0,D.useEffect)(()=>{if(e)return document.addEventListener(`keydown`,Pe),()=>document.removeEventListener(`keydown`,Pe)},[e,Pe]);let Fe=_e&&!ve||be||xe||Se;if((0,D.useEffect)(()=>{if(!Fe&&k&&k!==he.current){let e=requestAnimationFrame(()=>{let e=document.querySelector(`[class*="fixed inset-0 z-50"]`)?.querySelector(`[data-preset-id="${CSS.escape(k)}"]`);e&&(he.current=k,e.scrollIntoView({block:`nearest`}))});return()=>cancelAnimationFrame(e)}},[k,Fe]),!e)return null;let Ie=k&&!Ee.isPending,Le=R||a.trayColor||`FFFFFF`;return(0,O.jsxs)(`div`,{className:`fixed inset-0 z-50 flex ${y?``:`items-center justify-center`}`,children:[!y&&(0,O.jsx)(`div`,{className:`absolute inset-0 bg-black/60 backdrop-blur-sm`,onClick:t}),(0,O.jsxs)(`div`,{className:y?`relative w-full h-full bg-bambu-dark-secondary flex flex-col`:`relative w-full max-w-lg mx-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl`,children:[(0,O.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary shrink-0`,children:[(0,O.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,O.jsx)(p,{className:`w-5 h-5 text-bambu-blue`}),(0,O.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:x(`configureAmsSlot.title`)}),y&&(0,O.jsxs)(`div`,{className:`flex items-center gap-2 ml-4 text-sm text-bambu-gray`,children:[(0,O.jsx)(`span`,{className:`text-white/30`,children:`|`}),a.trayColor&&(0,O.jsx)(`span`,{className:`w-4 h-4 rounded-full border border-black/20`,style:b(a.trayColor)}),(0,O.jsx)(`span`,{className:`text-white/70`,children:x(`configureAmsSlot.slotLabel`,{ams:_(a.amsId,a.trayCount),slot:a.trayId+1})}),a.traySubBrands&&(0,O.jsxs)(`span`,{children:[`(`,a.traySubBrands,`)`]})]})]}),(0,O.jsx)(`button`,{onClick:t,className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,O.jsx)(ee,{className:`w-5 h-5`})})]}),(0,O.jsxs)(`div`,{className:`p-4 overflow-y-auto ${y?`flex-1 min-h-0`:`space-y-4 max-h-[60vh]`}`,children:[pe&&(0,O.jsx)(`div`,{className:`absolute inset-0 bg-bambu-dark-secondary/95 z-10 flex items-center justify-center rounded-xl`,children:(0,O.jsxs)(`div`,{className:`text-center space-y-3`,children:[(0,O.jsx)(h,{className:`w-16 h-16 text-bambu-green mx-auto`}),(0,O.jsx)(`p`,{className:`text-lg font-semibold text-white`,children:x(`configureAmsSlot.slotConfigured`)}),(0,O.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:x(`configureAmsSlot.settingsSentToPrinter`)})]})}),!y&&(0,O.jsxs)(`div`,{className:`p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,O.jsx)(`p`,{className:`text-xs text-bambu-gray mb-1`,children:x(`configureAmsSlot.configuringSlot`)}),(0,O.jsxs)(`div`,{className:`flex items-center gap-2`,children:[a.trayColor&&(0,O.jsx)(`span`,{className:`w-4 h-4 rounded-full border border-black/20`,style:b(a.trayColor)}),(0,O.jsx)(`span`,{className:`text-white font-medium`,children:x(`configureAmsSlot.slotLabel`,{ams:_(a.amsId,a.trayCount),slot:a.trayId+1})}),a.traySubBrands&&(0,O.jsxs)(`span`,{className:`text-bambu-gray`,children:[`(`,a.traySubBrands,`)`]})]})]}),Fe?(0,O.jsx)(`div`,{className:`flex justify-center py-8`,children:(0,O.jsx)(u,{className:`w-6 h-6 text-bambu-green animate-spin`})}):y?(0,O.jsxs)(`div`,{className:`flex gap-4 h-full`,children:[(0,O.jsxs)(`div`,{className:`w-1/2 flex flex-col min-h-0`,children:[(0,O.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-2`,children:[x(`configureAmsSlot.filamentProfile`),` `,(0,O.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:`*`})]}),(0,O.jsx)(`input`,{type:`text`,placeholder:x(`configureAmsSlot.searchPresets`),value:H,onChange:e=>fe(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder:text-bambu-gray focus:border-bambu-green focus:outline-none mb-2 shrink-0`}),(0,O.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto space-y-1`,children:Oe.length===0?(0,O.jsx)(`p`,{className:`text-center py-4 text-bambu-gray`,children:G?.filament?.length===0&&!K?.filament?.length?x(`configureAmsSlot.noPresetsAvailable`):x(`configureAmsSlot.noMatchingPresets`)}):Oe.map(e=>(0,O.jsx)(`button`,{"data-preset-id":e.id,onClick:()=>A(e.id),className:`group w-full p-2 rounded-lg border text-left transition-colors ${k===e.id?`bg-bambu-green/20 border-bambu-green`:`bg-bambu-dark border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:(0,O.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,O.jsx)(`span`,{className:`text-white text-sm truncate group-hover:whitespace-normal group-hover:break-all`,title:e.name,children:e.name}),(0,O.jsxs)(`div`,{className:`flex items-center gap-1 flex-shrink-0`,children:[e.source===`local`&&(0,O.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-green-100 dark:bg-green-500/20 text-green-700 dark:text-green-400`,children:x(`profiles.localProfiles.badge`)}),e.source===`orca_cloud`&&(0,O.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-purple-100 dark:bg-purple-500/20 text-purple-700 dark:text-purple-400`,children:x(`configureAmsSlot.orcaCloud`)}),e.source===`cloud`&&(0,O.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-bambu-blue/20 text-bambu-blue`,children:x(`configureAmsSlot.bambuCloud`)}),e.source===`builtin`&&(0,O.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400`,children:x(`configureAmsSlot.builtin`)})]})]})},e.id))})]}),(0,O.jsxs)(`div`,{className:`w-1/2 flex flex-col gap-4 min-h-0 overflow-y-auto`,children:[(0,O.jsxs)(`div`,{children:[(0,O.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-2`,children:[x(`configureAmsSlot.kProfileLabel`),ke&&(0,O.jsx)(`span`,{className:`ml-2 text-xs text-bambu-blue`,children:x(`configureAmsSlot.filteringFor`,{material:ke})})]}),Me?(0,O.jsxs)(`div`,{className:`relative`,children:[(0,O.jsxs)(`select`,{value:F?M(F):``,onChange:e=>Ne(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 appearance-none pr-10`,children:[(0,O.jsx)(`option`,{value:``,children:x(`configureAmsSlot.noKProfile`)}),Q.map(e=>(0,O.jsxs)(`option`,{value:M(e),children:[e.name,` (K=`,e.k_value,`)`,oe(e,je,x)]},M(e))),$.length>0&&(0,O.jsx)(`optgroup`,{label:x(`configureAmsSlot.otherKProfiles`),children:$.map(e=>(0,O.jsxs)(`option`,{value:M(e),children:[e.name,` (K=`,e.k_value,`)`,oe(e,je,x)]},M(e)))})]}),(0,O.jsx)(c,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]}):k?(0,O.jsx)(`p`,{className:`text-sm text-bambu-gray italic py-2`,children:x(`configureAmsSlot.noMatchingKProfiles`)}):(0,O.jsx)(`span`,{className:`inline-block text-xs px-2 py-1 rounded bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400 border border-amber-300 dark:border-amber-500/30`,children:x(`configureAmsSlot.selectFilamentFirst`)}),F&&(0,O.jsx)(`p`,{className:`text-xs text-bambu-green mt-1`,children:x(`configureAmsSlot.kFromCalibration`,{value:F.k_value})})]}),(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-2`,children:x(`configureAmsSlot.customColorLabel`)}),Ae.length>0&&(0,O.jsxs)(`div`,{className:`mb-3`,children:[(0,O.jsx)(`p`,{className:`text-xs text-bambu-gray mb-1.5`,children:x(`configureAmsSlot.presetColors`,{name:Z?.fullName})}),(0,O.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:Ae.map(e=>(0,O.jsxs)(`button`,{onClick:()=>{z(e.hex_color.replace(`#`,``).toUpperCase()),V(e.color_name)},className:`h-7 px-2 rounded-md border-2 transition-all flex items-center gap-1.5 ${R===e.hex_color.replace(`#`,``).toUpperCase()?`border-bambu-green scale-105`:`border-white/20 hover:border-white/40`}`,title:e.color_name,children:[(0,O.jsx)(`span`,{className:`w-4 h-4 rounded-full border border-black/20 flex-shrink-0`,style:{backgroundColor:e.hex_color}}),(0,O.jsx)(`span`,{className:`text-xs text-white/80 whitespace-nowrap`,children:e.color_name})]},e.id))})]}),(0,O.jsxs)(`div`,{className:`flex flex-wrap gap-1.5 mb-2`,children:[le.map(e=>(0,O.jsx)(`button`,{onClick:()=>{z(e.hex),V(e.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${R===e.hex?`border-bambu-green scale-110`:`border-white/20 hover:border-white/40`}`,style:{backgroundColor:`#${e.hex}`},title:e.name},e.hex)),(0,O.jsx)(`button`,{onClick:()=>me(!W),className:`w-7 h-7 rounded-md border-2 border-white/20 hover:border-white/40 flex items-center justify-center text-white/60 hover:text-white/80 transition-all text-xs`,title:x(W?`configureAmsSlot.showLessColors`:`configureAmsSlot.showMoreColors`),children:W?`−`:`+`})]}),W&&(0,O.jsx)(`div`,{className:`flex flex-wrap gap-1.5 mb-2`,children:ue.map(e=>(0,O.jsx)(`button`,{onClick:()=>{z(e.hex),V(e.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${R===e.hex?`border-bambu-green scale-110`:`border-white/20 hover:border-white/40`}`,style:{backgroundColor:`#${e.hex}`},title:e.name},e.hex))}),(0,O.jsxs)(`div`,{className:`flex gap-2 items-center`,children:[(0,O.jsx)(`div`,{className:`w-10 h-10 rounded-lg border-2 border-white/20 flex-shrink-0`,style:b(Le)}),(0,O.jsx)(`input`,{type:`text`,placeholder:x(`configureAmsSlot.colorPlaceholder`),value:B,onChange:e=>{let t=e.target.value;V(t);let n=de(t);if(n)z(n);else{let e=t.replace(/[^0-9A-Fa-f]/g,``).toUpperCase();e.length===6?z(e):e.length===3&&z(e.split(``).map(e=>e+e).join(``))}},className:`flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder:text-bambu-gray focus:border-bambu-green focus:outline-none text-sm`}),R&&(0,O.jsx)(`button`,{onClick:()=>{z(``),V(``)},className:`px-2 py-1 text-xs text-bambu-gray hover:text-white bg-bambu-dark-tertiary rounded`,title:x(`configureAmsSlot.clearCustomColor`),children:x(`configureAmsSlot.clear`)})]}),R&&(0,O.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1.5`,children:x(`configureAmsSlot.hexLabel`,{hex:R})})]})]})]}):(0,O.jsxs)(O.Fragment,{children:[(0,O.jsxs)(`div`,{children:[(0,O.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-2`,children:[x(`configureAmsSlot.filamentProfile`),` `,(0,O.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:`*`})]}),(0,O.jsxs)(`div`,{className:`relative`,children:[(0,O.jsx)(`input`,{type:`text`,placeholder:x(`configureAmsSlot.searchPresets`),value:H,onChange:e=>fe(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder:text-bambu-gray focus:border-bambu-green focus:outline-none mb-2`}),(0,O.jsx)(`div`,{className:`max-h-48 overflow-y-auto space-y-1`,children:Oe.length===0?(0,O.jsx)(`p`,{className:`text-center py-4 text-bambu-gray`,children:G?.filament?.length===0&&!K?.filament?.length?x(`configureAmsSlot.noPresetsAvailable`):x(`configureAmsSlot.noMatchingPresets`)}):Oe.map(e=>(0,O.jsx)(`button`,{"data-preset-id":e.id,onClick:()=>A(e.id),className:`group w-full p-2 rounded-lg border text-left transition-colors ${k===e.id?`bg-bambu-green/20 border-bambu-green`:`bg-bambu-dark border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:(0,O.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,O.jsx)(`span`,{className:`text-white text-sm truncate group-hover:whitespace-normal group-hover:break-all`,title:e.name,children:e.name}),(0,O.jsxs)(`div`,{className:`flex items-center gap-1 flex-shrink-0`,children:[e.source===`local`&&(0,O.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-green-100 dark:bg-green-500/20 text-green-700 dark:text-green-400`,children:x(`profiles.localProfiles.badge`)}),e.source===`orca_cloud`&&(0,O.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-purple-100 dark:bg-purple-500/20 text-purple-700 dark:text-purple-400`,children:x(`configureAmsSlot.orcaCloud`)}),e.source===`cloud`&&(0,O.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-bambu-blue/20 text-bambu-blue`,children:x(`configureAmsSlot.bambuCloud`)}),e.source===`builtin`&&(0,O.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400`,children:x(`configureAmsSlot.builtin`)})]})]})},e.id))})]})]}),(0,O.jsxs)(`div`,{children:[(0,O.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-2`,children:[x(`configureAmsSlot.kProfileLabel`),ke&&(0,O.jsx)(`span`,{className:`ml-2 text-xs text-bambu-blue`,children:x(`configureAmsSlot.filteringFor`,{material:ke})})]}),Me?(0,O.jsxs)(`div`,{className:`relative`,children:[(0,O.jsxs)(`select`,{value:F?M(F):``,onChange:e=>Ne(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 appearance-none pr-10`,children:[(0,O.jsx)(`option`,{value:``,children:x(`configureAmsSlot.noKProfile`)}),Q.map(e=>(0,O.jsxs)(`option`,{value:M(e),children:[e.name,` (K=`,e.k_value,`)`,oe(e,je,x)]},M(e))),$.length>0&&(0,O.jsx)(`optgroup`,{label:x(`configureAmsSlot.otherKProfiles`),children:$.map(e=>(0,O.jsxs)(`option`,{value:M(e),children:[e.name,` (K=`,e.k_value,`)`,oe(e,je,x)]},M(e)))})]}),(0,O.jsx)(c,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]}):k?(0,O.jsx)(`p`,{className:`text-sm text-bambu-gray italic py-2`,children:x(`configureAmsSlot.noMatchingKProfiles`)}):(0,O.jsx)(`span`,{className:`inline-block text-xs px-2 py-1 rounded bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400 border border-amber-300 dark:border-amber-500/30`,children:x(`configureAmsSlot.selectFilamentFirst`)}),F&&(0,O.jsx)(`p`,{className:`text-xs text-bambu-green mt-1`,children:x(`configureAmsSlot.kFromCalibration`,{value:F.k_value})})]}),(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-2`,children:x(`configureAmsSlot.customColorLabel`)}),Ae.length>0&&(0,O.jsxs)(`div`,{className:`mb-3`,children:[(0,O.jsx)(`p`,{className:`text-xs text-bambu-gray mb-1.5`,children:x(`configureAmsSlot.presetColors`,{name:Z?.fullName})}),(0,O.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:Ae.map(e=>(0,O.jsxs)(`button`,{onClick:()=>{z(e.hex_color.replace(`#`,``).toUpperCase()),V(e.color_name)},className:`h-7 px-2 rounded-md border-2 transition-all flex items-center gap-1.5 ${R===e.hex_color.replace(`#`,``).toUpperCase()?`border-bambu-green scale-105`:`border-white/20 hover:border-white/40`}`,title:e.color_name,children:[(0,O.jsx)(`span`,{className:`w-4 h-4 rounded-full border border-black/20 flex-shrink-0`,style:{backgroundColor:e.hex_color}}),(0,O.jsx)(`span`,{className:`text-xs text-white/80 whitespace-nowrap`,children:e.color_name})]},e.id))})]}),(0,O.jsxs)(`div`,{className:`flex flex-wrap gap-1.5 mb-2`,children:[le.map(e=>(0,O.jsx)(`button`,{onClick:()=>{z(e.hex),V(e.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${R===e.hex?`border-bambu-green scale-110`:`border-white/20 hover:border-white/40`}`,style:{backgroundColor:`#${e.hex}`},title:e.name},e.hex)),(0,O.jsx)(`button`,{onClick:()=>me(!W),className:`w-7 h-7 rounded-md border-2 border-white/20 hover:border-white/40 flex items-center justify-center text-white/60 hover:text-white/80 transition-all text-xs`,title:x(W?`configureAmsSlot.showLessColors`:`configureAmsSlot.showMoreColors`),children:W?`−`:`+`})]}),W&&(0,O.jsx)(`div`,{className:`flex flex-wrap gap-1.5 mb-2`,children:ue.map(e=>(0,O.jsx)(`button`,{onClick:()=>{z(e.hex),V(e.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${R===e.hex?`border-bambu-green scale-110`:`border-white/20 hover:border-white/40`}`,style:{backgroundColor:`#${e.hex}`},title:e.name},e.hex))}),(0,O.jsxs)(`div`,{className:`flex gap-2 items-center`,children:[(0,O.jsx)(`div`,{className:`w-10 h-10 rounded-lg border-2 border-white/20 flex-shrink-0`,style:b(Le)}),(0,O.jsx)(`input`,{type:`text`,placeholder:x(`configureAmsSlot.colorPlaceholder`),value:B,onChange:e=>{let t=e.target.value;V(t);let n=de(t);if(n)z(n);else{let e=t.replace(/[^0-9A-Fa-f]/g,``).toUpperCase();e.length===6?z(e):e.length===3&&z(e.split(``).map(e=>e+e).join(``))}},className:`flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder:text-bambu-gray focus:border-bambu-green focus:outline-none text-sm`}),R&&(0,O.jsx)(`button`,{onClick:()=>{z(``),V(``)},className:`px-2 py-1 text-xs text-bambu-gray hover:text-white bg-bambu-dark-tertiary rounded`,title:x(`configureAmsSlot.clearCustomColor`),children:x(`configureAmsSlot.clear`)})]}),R&&(0,O.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1.5`,children:x(`configureAmsSlot.hexLabel`,{hex:R})})]})]})]}),(0,O.jsxs)(`div`,{className:`flex justify-between p-4 border-t border-bambu-dark-tertiary shrink-0`,children:[(0,O.jsx)(m,{variant:`secondary`,onClick:()=>De.mutate(),disabled:De.isPending||Ee.isPending,className:`text-red-600 dark:text-red-400 hover:text-red-700 dark:hover:text-red-300 hover:bg-red-50 dark:hover:bg-red-500/10`,children:De.isPending?(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)(u,{className:`w-4 h-4 animate-spin`}),x(`configureAmsSlot.resetting`)]}):(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)(g,{className:`w-4 h-4`}),x(`configureAmsSlot.resetSlot`)]})}),(0,O.jsxs)(`div`,{className:`flex gap-2`,children:[(0,O.jsx)(m,{variant:`secondary`,onClick:t,children:x(`configureAmsSlot.cancel`)}),(0,O.jsx)(m,{onClick:()=>Ee.mutate(),disabled:!Ie,children:Ee.isPending?(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)(u,{className:`w-4 h-4 animate-spin`}),x(`configureAmsSlot.configuring`)]}):(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)(p,{className:`w-4 h-4`}),x(`configureAmsSlot.configureSlot`)]})})]})]}),(Ee.isError||De.isError)&&(0,O.jsx)(`div`,{className:`mx-4 mb-4 p-2 bg-red-100 dark:bg-red-500/20 border border-red-300 dark:border-red-500/50 rounded text-sm text-red-700 dark:text-red-400`,children:Ee.error?.message||De.error?.message})]})]})}export{A as n,k as r,P as t}; \ No newline at end of file diff --git a/static/assets/ConnectAuthorizePage-m6XXoE23.js b/static/assets/ConnectAuthorizePage-CIbOgIV8.js similarity index 98% rename from static/assets/ConnectAuthorizePage-m6XXoE23.js rename to static/assets/ConnectAuthorizePage-CIbOgIV8.js index 6df46d4aa..458d515e5 100644 --- a/static/assets/ConnectAuthorizePage-m6XXoE23.js +++ b/static/assets/ConnectAuthorizePage-CIbOgIV8.js @@ -1 +1 @@ -import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,t as i,w as a}from"./client-DnySrlFv.js";import{t as o}from"./link-2-MI-QCMh8.js";import{t as s}from"./loader-circle-BEmFtawu.js";import{t as c}from"./triangle-alert-Dt_1FcBy.js";import{Wn as l,yt as u}from"./index-0t--Yqoi.js";var d=e(n(),1),f=t();function p(e,t){let n=new URL(e);for(let[e,r]of Object.entries(t))r&&n.searchParams.set(e,r);return n.toString()}function m(){let{t:e}=a(),{authEnabled:t,loading:n}=u(),[m]=l(),[h,g]=(0,d.useState)({kind:`loading`}),_=(0,d.useRef)(!1),v=m.get(`client_id`)??``,y=m.get(`redirect_uri`)??``,b=m.get(`state`)??``,x=m.get(`code_challenge`)??``,S=m.get(`code_challenge_method`)??``,C=async()=>{g({kind:`redirecting`});try{let e=await r.connectAuthorize({client_id:v,redirect_uri:y,code_challenge:x,code_challenge_method:`S256`});window.location.replace(p(e.redirect_uri,{code:e.code,state:b}))}catch(t){g({kind:`error`,message:t instanceof Error?t.message:e(`connectedApps.authorize.failed`)})}};return(0,d.useEffect)(()=>{if(!(n||_.current)){if(_.current=!0,!t){g({kind:`error`,message:e(`connectedApps.authorize.authDisabled`)});return}if(!v||!y||!x||S!==`S256`){g({kind:`error`,message:e(`connectedApps.authorize.invalidRequest`)});return}r.getConnectAuthorizeInfo(v,y).then(e=>{e.already_granted?C():g({kind:`consent`,info:e})}).catch(t=>{g({kind:`error`,message:t instanceof i&&t.status===409?e(`connectedApps.authorize.authDisabled`):e(`connectedApps.authorize.invalidRequest`)})})}},[n,t]),(0,f.jsx)(`div`,{className:`min-h-screen flex items-center justify-center bg-bambu-dark p-4`,children:(0,f.jsxs)(`div`,{className:`max-w-md w-full space-y-6 p-8 bg-gradient-to-br from-bambu-card to-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary shadow-lg`,children:[(h.kind===`loading`||h.kind===`redirecting`)&&(0,f.jsxs)(`div`,{className:`flex flex-col items-center gap-3 text-bambu-gray`,role:`status`,children:[(0,f.jsx)(s,{className:`w-8 h-8 animate-spin text-bambu-green`}),(0,f.jsx)(`p`,{children:h.kind===`loading`?e(`connectedApps.authorize.checking`):e(`connectedApps.authorize.redirecting`)})]}),h.kind===`error`&&(0,f.jsxs)(`div`,{className:`text-center space-y-3`,children:[(0,f.jsx)(c,{className:`w-10 h-10 mx-auto text-yellow-600 dark:text-yellow-400`}),(0,f.jsx)(`h1`,{className:`text-xl font-semibold text-white`,children:e(`connectedApps.authorize.errorTitle`)}),(0,f.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:h.message})]}),h.kind===`consent`&&(0,f.jsxs)(f.Fragment,{children:[(0,f.jsxs)(`div`,{className:`text-center space-y-3`,children:[(0,f.jsx)(`div`,{className:`w-14 h-14 mx-auto rounded-full bg-bambu-green/20 flex items-center justify-center`,children:(0,f.jsx)(o,{className:`w-7 h-7 text-bambu-green`})}),(0,f.jsx)(`h1`,{className:`text-xl font-semibold text-white text-balance`,children:e(`connectedApps.authorize.title`,{app:h.info.app_name})}),(0,f.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`connectedApps.authorize.signedInAs`,{username:h.info.username})})]}),(0,f.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`connectedApps.authorize.sharedData`,{app:h.info.app_name})}),(0,f.jsxs)(`div`,{className:`flex gap-3`,children:[(0,f.jsx)(`button`,{type:`button`,onClick:()=>{window.location.replace(p(y,{error:`access_denied`,state:b}))},className:`flex-1 px-4 py-2 bg-bambu-dark-tertiary text-white rounded-md hover:bg-bambu-dark-tertiary/80 focus:outline-none focus-visible:ring-2 focus-visible:ring-bambu-green`,children:e(`connectedApps.authorize.deny`)}),(0,f.jsx)(`button`,{type:`button`,onClick:()=>void C(),className:`flex-1 px-4 py-2 bg-bambu-green text-white rounded-md hover:bg-bambu-green/90 focus:outline-none focus-visible:ring-2 focus-visible:ring-white`,children:e(`connectedApps.authorize.allow`)})]})]})]})})}export{m as ConnectAuthorizePage}; \ No newline at end of file +import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,t as i,w as a}from"./client-DnySrlFv.js";import{t as o}from"./link-2-MI-QCMh8.js";import{t as s}from"./loader-circle-BEmFtawu.js";import{t as c}from"./triangle-alert-Dt_1FcBy.js";import{Wn as l,yt as u}from"./index-Cxa-KVmA.js";var d=e(n(),1),f=t();function p(e,t){let n=new URL(e);for(let[e,r]of Object.entries(t))r&&n.searchParams.set(e,r);return n.toString()}function m(){let{t:e}=a(),{authEnabled:t,loading:n}=u(),[m]=l(),[h,g]=(0,d.useState)({kind:`loading`}),_=(0,d.useRef)(!1),v=m.get(`client_id`)??``,y=m.get(`redirect_uri`)??``,b=m.get(`state`)??``,x=m.get(`code_challenge`)??``,S=m.get(`code_challenge_method`)??``,C=async()=>{g({kind:`redirecting`});try{let e=await r.connectAuthorize({client_id:v,redirect_uri:y,code_challenge:x,code_challenge_method:`S256`});window.location.replace(p(e.redirect_uri,{code:e.code,state:b}))}catch(t){g({kind:`error`,message:t instanceof Error?t.message:e(`connectedApps.authorize.failed`)})}};return(0,d.useEffect)(()=>{if(!(n||_.current)){if(_.current=!0,!t){g({kind:`error`,message:e(`connectedApps.authorize.authDisabled`)});return}if(!v||!y||!x||S!==`S256`){g({kind:`error`,message:e(`connectedApps.authorize.invalidRequest`)});return}r.getConnectAuthorizeInfo(v,y).then(e=>{e.already_granted?C():g({kind:`consent`,info:e})}).catch(t=>{g({kind:`error`,message:t instanceof i&&t.status===409?e(`connectedApps.authorize.authDisabled`):e(`connectedApps.authorize.invalidRequest`)})})}},[n,t]),(0,f.jsx)(`div`,{className:`min-h-screen flex items-center justify-center bg-bambu-dark p-4`,children:(0,f.jsxs)(`div`,{className:`max-w-md w-full space-y-6 p-8 bg-gradient-to-br from-bambu-card to-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary shadow-lg`,children:[(h.kind===`loading`||h.kind===`redirecting`)&&(0,f.jsxs)(`div`,{className:`flex flex-col items-center gap-3 text-bambu-gray`,role:`status`,children:[(0,f.jsx)(s,{className:`w-8 h-8 animate-spin text-bambu-green`}),(0,f.jsx)(`p`,{children:h.kind===`loading`?e(`connectedApps.authorize.checking`):e(`connectedApps.authorize.redirecting`)})]}),h.kind===`error`&&(0,f.jsxs)(`div`,{className:`text-center space-y-3`,children:[(0,f.jsx)(c,{className:`w-10 h-10 mx-auto text-yellow-600 dark:text-yellow-400`}),(0,f.jsx)(`h1`,{className:`text-xl font-semibold text-white`,children:e(`connectedApps.authorize.errorTitle`)}),(0,f.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:h.message})]}),h.kind===`consent`&&(0,f.jsxs)(f.Fragment,{children:[(0,f.jsxs)(`div`,{className:`text-center space-y-3`,children:[(0,f.jsx)(`div`,{className:`w-14 h-14 mx-auto rounded-full bg-bambu-green/20 flex items-center justify-center`,children:(0,f.jsx)(o,{className:`w-7 h-7 text-bambu-green`})}),(0,f.jsx)(`h1`,{className:`text-xl font-semibold text-white text-balance`,children:e(`connectedApps.authorize.title`,{app:h.info.app_name})}),(0,f.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`connectedApps.authorize.signedInAs`,{username:h.info.username})})]}),(0,f.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`connectedApps.authorize.sharedData`,{app:h.info.app_name})}),(0,f.jsxs)(`div`,{className:`flex gap-3`,children:[(0,f.jsx)(`button`,{type:`button`,onClick:()=>{window.location.replace(p(y,{error:`access_denied`,state:b}))},className:`flex-1 px-4 py-2 bg-bambu-dark-tertiary text-white rounded-md hover:bg-bambu-dark-tertiary/80 focus:outline-none focus-visible:ring-2 focus-visible:ring-bambu-green`,children:e(`connectedApps.authorize.deny`)}),(0,f.jsx)(`button`,{type:`button`,onClick:()=>void C(),className:`flex-1 px-4 py-2 bg-bambu-green text-white rounded-md hover:bg-bambu-green/90 focus:outline-none focus-visible:ring-2 focus-visible:ring-white`,children:e(`connectedApps.authorize.allow`)})]})]})]})})}export{m as ConnectAuthorizePage}; \ No newline at end of file diff --git a/static/assets/ContextMenu-BOFgRmSk.js b/static/assets/ContextMenu-CwroFwVJ.js similarity index 98% rename from static/assets/ContextMenu-BOFgRmSk.js rename to static/assets/ContextMenu-CwroFwVJ.js index 289fcca4e..5cfd72ffb 100644 --- a/static/assets/ContextMenu-BOFgRmSk.js +++ b/static/assets/ContextMenu-CwroFwVJ.js @@ -1 +1 @@ -import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n}from"./client-DnySrlFv.js";import{t as r}from"./createLucideIcon-DvBYJlWL.js";import{t as i}from"./search-0n0CBc74.js";import{Mn as a}from"./index-0t--Yqoi.js";var o=r(`file`,[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}]]),s=e(n(),1),c=t();function l({items:e,searchPlaceholder:t,onClose:n,className:r,onMouseEnter:a,onMouseLeave:o}){let[l,u]=(0,s.useState)(``),d=(0,s.useRef)(null);(0,s.useEffect)(()=>{if(t){let e=window.setTimeout(()=>d.current?.focus(),0);return()=>window.clearTimeout(e)}},[t]);let f=l.trim().toLowerCase(),p=t&&f?e.filter(e=>e.label.toLowerCase().includes(f)):e;return(0,c.jsxs)(`div`,{className:r,onMouseEnter:a,onMouseLeave:o,children:[t&&(0,c.jsx)(`div`,{className:`sticky top-0 z-[1] px-2 py-1.5 bg-bambu-dark-secondary border-b border-bambu-dark-tertiary`,children:(0,c.jsxs)(`div`,{className:`relative`,children:[(0,c.jsx)(i,{className:`absolute left-2 top-1/2 -translate-y-1/2 w-3.5 h-3.5 text-bambu-gray pointer-events-none`}),(0,c.jsx)(`input`,{ref:d,type:`text`,value:l,onChange:e=>u(e.target.value),onKeyDown:e=>{if(e.key===`Enter`){let e=p.find(e=>!e.disabled);e&&(e.onClick(),n())}},placeholder:t,className:`w-full pl-7 pr-2 py-1 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]})}),p.map((e,t)=>(0,c.jsxs)(`button`,{onClick:()=>{e.disabled||(e.onClick(),n())},disabled:e.disabled,className:`w-full flex items-center gap-2 px-3 py-2 text-sm text-left transition-colors ${e.disabled?`text-bambu-gray cursor-not-allowed`:e.danger?`text-red-700 dark:text-red-400 hover:bg-red-50 dark:hover:bg-red-400/10`:`text-white hover:bg-bambu-dark-tertiary`}`,children:[e.icon&&(0,c.jsx)(`span`,{className:`w-4 h-4 flex-shrink-0 flex items-center justify-center`,children:e.icon}),(0,c.jsx)(`span`,{className:`flex-1 truncate`,children:e.label})]},t)),t&&p.length===0&&(0,c.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray text-center italic`,children:`—`})]})}function u({x:e,y:t,items:n,onClose:r,anchorRef:i}){let o=(0,s.useRef)(null),[u,d]=(0,s.useState)(null),f=(0,s.useRef)(null),[p,m]=(0,s.useState)({x:e,y:t,visible:!1}),[h,g]=(0,s.useState)(!1),[_,v]=(0,s.useState)({});(0,s.useEffect)(()=>{let e=e=>{let t=e.target;o.current?.contains(t)||i?.current?.contains(t)||r()},t=e=>{e.key===`Escape`&&r()},n=e=>{o.current&&o.current.contains(e.target)||r()};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),document.addEventListener(`scroll`,n,!0),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t),document.removeEventListener(`scroll`,n,!0),f.current&&clearTimeout(f.current)}},[r,i]),(0,s.useLayoutEffect)(()=>{if(o.current){o.current.style.visibility=`hidden`,o.current.style.display=`block`;let n=o.current.getBoundingClientRect(),r=window.innerWidth,i=window.innerHeight,a=e,s=t;e+n.width>r-8&&(a=Math.max(8,r-n.width-8)),a<8&&(a=8),t+n.height>i-8&&(s=Math.max(8,i-n.height-8)),s<8&&(s=8),g(r-a-n.width<180&&a>180),m({x:a,y:s,visible:!0})}},[e,t]);let y=(e,t)=>{f.current&&=(clearTimeout(f.current),null);let n=t.getBoundingClientRect(),r=window.innerHeight-n.top-8<300&&n.top>300;v(t=>({...t,[e]:r?`bottom`:`top`})),d(e)},b=()=>{f.current=window.setTimeout(()=>{d(null)},150)};return(0,c.jsx)(`div`,{ref:o,className:`fixed z-50 min-w-[180px] max-w-[280px] bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl py-1`,style:{left:p.x,top:p.y,visibility:p.visible?`visible`:`hidden`},children:n.map((e,t)=>{if(e.divider)return(0,c.jsx)(`div`,{className:`my-1 border-t border-bambu-dark-tertiary`},t);let n=e.submenu&&e.submenu.length>0;return(0,c.jsxs)(`div`,{className:`relative`,onMouseEnter:e=>n&&y(t,e.currentTarget),onMouseLeave:()=>n&&b(),children:[(0,c.jsxs)(`button`,{onMouseEnter:e=>n&&y(t,e.currentTarget.parentElement),onClick:()=>{n?d(u===t?null:t):e.disabled||(e.onClick(),r())},disabled:e.disabled,title:e.title,className:`group w-full flex items-center gap-2 px-3 py-2 text-sm text-left transition-colors ${e.disabled?`text-bambu-gray cursor-not-allowed`:e.danger?`text-red-700 dark:text-red-400 hover:bg-red-50 dark:hover:bg-red-400/10`:`text-white hover:bg-bambu-dark-tertiary`} ${n&&u===t?`bg-bambu-dark-tertiary`:``}`,children:[e.icon&&(0,c.jsx)(`span`,{className:`w-4 h-4 flex-shrink-0 flex items-center justify-center`,children:e.icon}),(0,c.jsx)(`span`,{className:`flex-1`,children:e.label}),n&&(0,c.jsx)(a,{className:`w-4 h-4 text-bambu-gray`})]}),n&&u===t&&(0,c.jsx)(l,{items:e.submenu,searchPlaceholder:e.submenuSearchPlaceholder,onClose:r,className:`absolute min-w-[200px] bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl py-1 overflow-hidden max-h-[300px] overflow-y-auto z-[60] ${h?`right-full mr-1`:`left-full ml-1`} ${_[t]===`bottom`?`bottom-0`:`top-0`}`,onMouseEnter:()=>{f.current&&=(clearTimeout(f.current),null)},onMouseLeave:()=>b()})]},t)})})}export{o as n,u as t}; \ No newline at end of file +import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n}from"./client-DnySrlFv.js";import{t as r}from"./createLucideIcon-DvBYJlWL.js";import{t as i}from"./search-0n0CBc74.js";import{Mn as a}from"./index-Cxa-KVmA.js";var o=r(`file`,[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}]]),s=e(n(),1),c=t();function l({items:e,searchPlaceholder:t,onClose:n,className:r,onMouseEnter:a,onMouseLeave:o}){let[l,u]=(0,s.useState)(``),d=(0,s.useRef)(null);(0,s.useEffect)(()=>{if(t){let e=window.setTimeout(()=>d.current?.focus(),0);return()=>window.clearTimeout(e)}},[t]);let f=l.trim().toLowerCase(),p=t&&f?e.filter(e=>e.label.toLowerCase().includes(f)):e;return(0,c.jsxs)(`div`,{className:r,onMouseEnter:a,onMouseLeave:o,children:[t&&(0,c.jsx)(`div`,{className:`sticky top-0 z-[1] px-2 py-1.5 bg-bambu-dark-secondary border-b border-bambu-dark-tertiary`,children:(0,c.jsxs)(`div`,{className:`relative`,children:[(0,c.jsx)(i,{className:`absolute left-2 top-1/2 -translate-y-1/2 w-3.5 h-3.5 text-bambu-gray pointer-events-none`}),(0,c.jsx)(`input`,{ref:d,type:`text`,value:l,onChange:e=>u(e.target.value),onKeyDown:e=>{if(e.key===`Enter`){let e=p.find(e=>!e.disabled);e&&(e.onClick(),n())}},placeholder:t,className:`w-full pl-7 pr-2 py-1 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]})}),p.map((e,t)=>(0,c.jsxs)(`button`,{onClick:()=>{e.disabled||(e.onClick(),n())},disabled:e.disabled,className:`w-full flex items-center gap-2 px-3 py-2 text-sm text-left transition-colors ${e.disabled?`text-bambu-gray cursor-not-allowed`:e.danger?`text-red-700 dark:text-red-400 hover:bg-red-50 dark:hover:bg-red-400/10`:`text-white hover:bg-bambu-dark-tertiary`}`,children:[e.icon&&(0,c.jsx)(`span`,{className:`w-4 h-4 flex-shrink-0 flex items-center justify-center`,children:e.icon}),(0,c.jsx)(`span`,{className:`flex-1 truncate`,children:e.label})]},t)),t&&p.length===0&&(0,c.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray text-center italic`,children:`—`})]})}function u({x:e,y:t,items:n,onClose:r,anchorRef:i}){let o=(0,s.useRef)(null),[u,d]=(0,s.useState)(null),f=(0,s.useRef)(null),[p,m]=(0,s.useState)({x:e,y:t,visible:!1}),[h,g]=(0,s.useState)(!1),[_,v]=(0,s.useState)({});(0,s.useEffect)(()=>{let e=e=>{let t=e.target;o.current?.contains(t)||i?.current?.contains(t)||r()},t=e=>{e.key===`Escape`&&r()},n=e=>{o.current&&o.current.contains(e.target)||r()};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),document.addEventListener(`scroll`,n,!0),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t),document.removeEventListener(`scroll`,n,!0),f.current&&clearTimeout(f.current)}},[r,i]),(0,s.useLayoutEffect)(()=>{if(o.current){o.current.style.visibility=`hidden`,o.current.style.display=`block`;let n=o.current.getBoundingClientRect(),r=window.innerWidth,i=window.innerHeight,a=e,s=t;e+n.width>r-8&&(a=Math.max(8,r-n.width-8)),a<8&&(a=8),t+n.height>i-8&&(s=Math.max(8,i-n.height-8)),s<8&&(s=8),g(r-a-n.width<180&&a>180),m({x:a,y:s,visible:!0})}},[e,t]);let y=(e,t)=>{f.current&&=(clearTimeout(f.current),null);let n=t.getBoundingClientRect(),r=window.innerHeight-n.top-8<300&&n.top>300;v(t=>({...t,[e]:r?`bottom`:`top`})),d(e)},b=()=>{f.current=window.setTimeout(()=>{d(null)},150)};return(0,c.jsx)(`div`,{ref:o,className:`fixed z-50 min-w-[180px] max-w-[280px] bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl py-1`,style:{left:p.x,top:p.y,visibility:p.visible?`visible`:`hidden`},children:n.map((e,t)=>{if(e.divider)return(0,c.jsx)(`div`,{className:`my-1 border-t border-bambu-dark-tertiary`},t);let n=e.submenu&&e.submenu.length>0;return(0,c.jsxs)(`div`,{className:`relative`,onMouseEnter:e=>n&&y(t,e.currentTarget),onMouseLeave:()=>n&&b(),children:[(0,c.jsxs)(`button`,{onMouseEnter:e=>n&&y(t,e.currentTarget.parentElement),onClick:()=>{n?d(u===t?null:t):e.disabled||(e.onClick(),r())},disabled:e.disabled,title:e.title,className:`group w-full flex items-center gap-2 px-3 py-2 text-sm text-left transition-colors ${e.disabled?`text-bambu-gray cursor-not-allowed`:e.danger?`text-red-700 dark:text-red-400 hover:bg-red-50 dark:hover:bg-red-400/10`:`text-white hover:bg-bambu-dark-tertiary`} ${n&&u===t?`bg-bambu-dark-tertiary`:``}`,children:[e.icon&&(0,c.jsx)(`span`,{className:`w-4 h-4 flex-shrink-0 flex items-center justify-center`,children:e.icon}),(0,c.jsx)(`span`,{className:`flex-1`,children:e.label}),n&&(0,c.jsx)(a,{className:`w-4 h-4 text-bambu-gray`})]}),n&&u===t&&(0,c.jsx)(l,{items:e.submenu,searchPlaceholder:e.submenuSearchPlaceholder,onClose:r,className:`absolute min-w-[200px] bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl py-1 overflow-hidden max-h-[300px] overflow-y-auto z-[60] ${h?`right-full mr-1`:`left-full ml-1`} ${_[t]===`bottom`?`bottom-0`:`top-0`}`,onMouseEnter:()=>{f.current&&=(clearTimeout(f.current),null)},onMouseLeave:()=>b()})]},t)})})}export{o as n,u as t}; \ No newline at end of file diff --git a/static/assets/ExternalLinkPage--eeDFa4j.js b/static/assets/ExternalLinkPage-BN4q7Gs-.js similarity index 97% rename from static/assets/ExternalLinkPage--eeDFa4j.js rename to static/assets/ExternalLinkPage-BN4q7Gs-.js index f39ce6679..7797db938 100644 --- a/static/assets/ExternalLinkPage--eeDFa4j.js +++ b/static/assets/ExternalLinkPage-BN4q7Gs-.js @@ -1 +1 @@ -import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,w as i}from"./client-DnySrlFv.js";import{t as a}from"./useQuery-BBCjCezC.js";import{t as o}from"./loader-circle-BEmFtawu.js";import{t as s}from"./triangle-alert-Dt_1FcBy.js";import{Un as c,Vn as l,vt as u}from"./index-0t--Yqoi.js";var d=e(n(),1),f=t();function p(){let{t:e}=i(),{id:t}=c(),{mode:n}=u(),l=(0,d.useRef)(null),p=m(l);g(l);let{data:h,isLoading:_,error:v}=a({queryKey:[`external-link`,t],queryFn:()=>r.getExternalLink(Number(t)),enabled:!!t});return _?(0,f.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,f.jsx)(o,{className:`w-8 h-8 text-bambu-green animate-spin`})}):v||!h?(0,f.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-4 text-bambu-gray`,children:[(0,f.jsx)(s,{className:`w-12 h-12`}),(0,f.jsx)(`p`,{children:e(`common.linkNotFound`)})]}):(0,f.jsx)(`iframe`,{ref:l,src:h.url,onLoad:p,className:`h-full w-full border-0`,style:{colorScheme:n},title:h.name,sandbox:`allow-scripts allow-same-origin allow-forms allow-popups allow-popups-to-escape-sandbox`})}function m(e){let{resolvedMode:t,darkStyle:n,darkBackground:r,darkAccent:i,lightStyle:a,lightBackground:o,lightAccent:s}=u(),c=t===`dark`,l=c?n:a,f=c?r:o,p=c?i:s,m=(0,d.useCallback)(()=>{let n=e.current;if(!n?.contentWindow)return;let r;try{r=new URL(n.src).origin}catch{return}n.contentWindow.postMessage({type:`bambuddy:theme`,mode:t,style:l,background:f,accent:p,canNavigate:!0},r)},[e,t,l,f,p]);return(0,d.useEffect)(()=>m(),[m]),(0,d.useEffect)(()=>{let t=t=>{t.source===e.current?.contentWindow&&t.data?.type===`bambuddy:theme-request`&&m()};return window.addEventListener(`message`,t),()=>window.removeEventListener(`message`,t)},[e,m]),m}var h=512;function g(e){let t=l();(0,d.useEffect)(()=>{let n=n=>{let r=e.current;if(!r?.contentWindow||n.source!==r.contentWindow||n.data?.type!==`bambuddy:navigate`)return;let i;try{i=new URL(r.src).origin}catch{return}if(n.origin!==i)return;let a=_(n.data.path);a!==null&&t(a)};return window.addEventListener(`message`,n),()=>window.removeEventListener(`message`,n)},[e,t])}function _(e){if(typeof e!=`string`||e.length>h||!e.startsWith(`/`)||e.startsWith(`//`)||e.includes(`\\`))return null;let t;try{t=new URL(e,window.location.origin)}catch{return null}return t.origin===window.location.origin?t.pathname+t.search+t.hash:null}export{p as ExternalLinkPage}; \ No newline at end of file +import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,w as i}from"./client-DnySrlFv.js";import{t as a}from"./useQuery-BBCjCezC.js";import{t as o}from"./loader-circle-BEmFtawu.js";import{t as s}from"./triangle-alert-Dt_1FcBy.js";import{Un as c,Vn as l,vt as u}from"./index-Cxa-KVmA.js";var d=e(n(),1),f=t();function p(){let{t:e}=i(),{id:t}=c(),{mode:n}=u(),l=(0,d.useRef)(null),p=m(l);g(l);let{data:h,isLoading:_,error:v}=a({queryKey:[`external-link`,t],queryFn:()=>r.getExternalLink(Number(t)),enabled:!!t});return _?(0,f.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,f.jsx)(o,{className:`w-8 h-8 text-bambu-green animate-spin`})}):v||!h?(0,f.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-4 text-bambu-gray`,children:[(0,f.jsx)(s,{className:`w-12 h-12`}),(0,f.jsx)(`p`,{children:e(`common.linkNotFound`)})]}):(0,f.jsx)(`iframe`,{ref:l,src:h.url,onLoad:p,className:`h-full w-full border-0`,style:{colorScheme:n},title:h.name,sandbox:`allow-scripts allow-same-origin allow-forms allow-popups allow-popups-to-escape-sandbox`})}function m(e){let{resolvedMode:t,darkStyle:n,darkBackground:r,darkAccent:i,lightStyle:a,lightBackground:o,lightAccent:s}=u(),c=t===`dark`,l=c?n:a,f=c?r:o,p=c?i:s,m=(0,d.useCallback)(()=>{let n=e.current;if(!n?.contentWindow)return;let r;try{r=new URL(n.src).origin}catch{return}n.contentWindow.postMessage({type:`bambuddy:theme`,mode:t,style:l,background:f,accent:p,canNavigate:!0},r)},[e,t,l,f,p]);return(0,d.useEffect)(()=>m(),[m]),(0,d.useEffect)(()=>{let t=t=>{t.source===e.current?.contentWindow&&t.data?.type===`bambuddy:theme-request`&&m()};return window.addEventListener(`message`,t),()=>window.removeEventListener(`message`,t)},[e,m]),m}var h=512;function g(e){let t=l();(0,d.useEffect)(()=>{let n=n=>{let r=e.current;if(!r?.contentWindow||n.source!==r.contentWindow||n.data?.type!==`bambuddy:navigate`)return;let i;try{i=new URL(r.src).origin}catch{return}if(n.origin!==i)return;let a=_(n.data.path);a!==null&&t(a)};return window.addEventListener(`message`,n),()=>window.removeEventListener(`message`,n)},[e,t])}function _(e){if(typeof e!=`string`||e.length>h||!e.startsWith(`/`)||e.startsWith(`//`)||e.includes(`\\`))return null;let t;try{t=new URL(e,window.location.origin)}catch{return null}return t.origin===window.location.origin?t.pathname+t.search+t.hash:null}export{p as ExternalLinkPage}; \ No newline at end of file diff --git a/static/assets/FileManagerPage-FtcjfbEh.js b/static/assets/FileManagerPage-BASV0fq8.js similarity index 99% rename from static/assets/FileManagerPage-FtcjfbEh.js rename to static/assets/FileManagerPage-BASV0fq8.js index ba4f2125a..3abe7aca6 100644 --- a/static/assets/FileManagerPage-FtcjfbEh.js +++ b/static/assets/FileManagerPage-BASV0fq8.js @@ -1,5 +1,5 @@ -const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/PdfPreviewModal-Con0pW4P.js","assets/chunk-aKtaBQYM.js","assets/index-0t--Yqoi.js","assets/QueryClientProvider-Ce8_sN3w.js","assets/client-DnySrlFv.js","assets/useMutation-B-Tr2hIP.js","assets/useQueries-Be6PMvSC.js","assets/useQuery-BBCjCezC.js","assets/createLucideIcon-DvBYJlWL.js","assets/arrow-down-Cj0DZhNf.js","assets/arrow-up-D-pfJ3WZ.js","assets/calendar-BLKPnWqV.js","assets/check-Ck0cMLU4.js","assets/info-ROUoQhJR.js","assets/ToastContext-BRX0SW3C.js","assets/loader-circle-BEmFtawu.js","assets/x-DR-Trv6U.js","assets/file-DDkFXH-b.js","assets/triangle-alert-Dt_1FcBy.js","assets/react-dom-B8Dg6xzp.js","assets/Button-DDr6eAFy.js","assets/Card-Bzc64K35.js","assets/filamentSwatchHelpers-D3oXQSGk.js","assets/date-G9KUauqz.js","assets/index-LBjsy7mY.css","assets/zoom-out-DNNe6DMN.js","assets/usePreviewFullscreen-ButueZqN.js","assets/maximize-2-kPQ77q72.js","assets/minimize-2-dqT-k7oI.js","assets/SpreadsheetPreviewModal-CVALSyS0.js","assets/file-spreadsheet-WxOA9vYy.js","assets/ImagePreviewModal-VVWd1NOq.js"])))=>i.map(i=>d[i]); -import{i as e,n as t,t as n}from"./chunk-aKtaBQYM.js";import{C as r,D as i,a,w as o,x as s}from"./client-DnySrlFv.js";import{n as c}from"./QueryClientProvider-Ce8_sN3w.js";import{t as l}from"./useQuery-BBCjCezC.js";import{t as u}from"./useMutation-B-Tr2hIP.js";import{t as d}from"./useQueries-Be6PMvSC.js";import{t as f}from"./createLucideIcon-DvBYJlWL.js";import{t as p}from"./box-DAdKb9s5.js";import{t as m}from"./briefcase-Dau7xqMY.js";import{t as h}from"./check-Ck0cMLU4.js";import{a as g,t as _}from"./info-ROUoQhJR.js";import{n as v}from"./ToastContext-BRX0SW3C.js";import{t as y}from"./cog-Dol1I0kq.js";import{t as b}from"./columns-2-DVEObeDC.js";import{t as x}from"./ellipsis-vertical-t2D7cYyp.js";import{t as S}from"./file-box-04V4jZ9_.js";import{t as C}from"./file-spreadsheet-WxOA9vYy.js";import{n as w,t as T}from"./ContextMenu-BOFgRmSk.js";import{t as E}from"./funnel-C3dyAMK9.js";import{t as D}from"./SliceModal-TzmWgODN.js";import{t as O}from"./hard-drive-CgXAHN37.js";import{t as k}from"./layout-grid-DkD3u6wa.js";import{t as A}from"./link-2-MI-QCMh8.js";import{t as ee}from"./list-CLcpeoSz.js";import{t as j}from"./loader-circle-BEmFtawu.js";import{t as M}from"./lock-MLqgWH4Q.js";import{t as te}from"./play-DIDYtk2S.js";import{t as N}from"./search-0n0CBc74.js";import{t as ne}from"./sticky-note-BH0LPqRx.js";import{t as re}from"./triangle-alert-Dt_1FcBy.js";import{t as ie}from"./unlink-C098nwOf.js";import{t as ae}from"./x-DR-Trv6U.js";import{t as oe}from"./file-DDkFXH-b.js";import{t as P}from"./Button-DDr6eAFy.js";import{n as se,o as ce,v as le}from"./date-G9KUauqz.js";import{$t as ue,At as de,Cn as fe,Dt as pe,F,Jt as me,Kn as I,Kt as L,Ln as he,Lt as ge,Mn as _e,On as ve,Ot as ye,Pn as be,Pt as xe,Rn as Se,Rt as Ce,Sn as we,Ut as Te,Vn as Ee,Wn as De,Zt as Oe,_t as ke,b as Ae,cn as je,hn as Me,kt as Ne,sn as Pe,un as Fe,vn as Ie,wn as Le,xn as Re,yt as ze}from"./index-0t--Yqoi.js";import{n as Be,t as Ve}from"./usePreviewFullscreen-ButueZqN.js";import{n as He,r as Ue,t as We}from"./PhotoGalleryModal-C8-A6a4s.js";import{a as Ge,o as Ke,r as qe,t as Je}from"./slicer-DgCA7cW6.js";import{n as Ye,t as Xe}from"./FileUploadModal-CpDg524n.js";import{n as Ze,t as Qe}from"./libraryFiles-B0B1SFfn.js";var $e=f(`arrow-down-wide-narrow`,[[`path`,{d:`m3 16 4 4 4-4`,key:`1co6wj`}],[`path`,{d:`M7 20V4`,key:`1yoxec`}],[`path`,{d:`M11 4h10`,key:`1w87gc`}],[`path`,{d:`M11 8h7`,key:`djye34`}],[`path`,{d:`M11 12h4`,key:`q8tih4`}]]),et=f(`arrow-up-narrow-wide`,[[`path`,{d:`m3 8 4-4 4 4`,key:`11wl7u`}],[`path`,{d:`M7 4v16`,key:`1glfcx`}],[`path`,{d:`M11 12h4`,key:`q8tih4`}],[`path`,{d:`M11 16h7`,key:`uosisv`}],[`path`,{d:`M11 20h10`,key:`jvxblo`}]]),tt=f(`calendar-clock`,[[`path`,{d:`M16 14v2.2l1.6 1`,key:`fo4ql5`}],[`path`,{d:`M16 2v4`,key:`4m81vk`}],[`path`,{d:`M21 7.5V6a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h3.5`,key:`1osxxc`}],[`path`,{d:`M3 10h5`,key:`r794hk`}],[`path`,{d:`M8 2v4`,key:`1cmpym`}],[`circle`,{cx:`16`,cy:`16`,r:`6`,key:`qoo3c4`}]]),nt=f(`combine`,[[`path`,{d:`M14 3a1 1 0 0 1 1 1v5a1 1 0 0 1-1 1`,key:`1l7d7l`}],[`path`,{d:`M19 3a1 1 0 0 1 1 1v5a1 1 0 0 1-1 1`,key:`9955pe`}],[`path`,{d:`m7 15 3 3`,key:`4hkfgk`}],[`path`,{d:`m7 21 3-3H5a2 2 0 0 1-2-2v-2`,key:`1xljwe`}],[`rect`,{x:`14`,y:`14`,width:`7`,height:`7`,rx:`1`,key:`1cdgtw`}],[`rect`,{x:`3`,y:`3`,width:`7`,height:`7`,rx:`1`,key:`zi3rio`}]]),rt=f(`folder-plus`,[[`path`,{d:`M12 10v6`,key:`1bos4e`}],[`path`,{d:`M9 13h6`,key:`1uhe8q`}],[`path`,{d:`M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z`,key:`1kt360`}]]),it=f(`folder-symlink`,[[`path`,{d:`M2 9.35V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H20a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2v-3a2 2 0 0 1 2-2h7`,key:`y8kt7d`}],[`path`,{d:`m8 16 3-3-3-3`,key:`rlqrt1`}]]),at=f(`move-right`,[[`path`,{d:`M18 8L22 12L18 16`,key:`1r0oui`}],[`path`,{d:`M2 12H22`,key:`1m8cig`}]]),ot=f(`panel-right-close`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M15 3v18`,key:`14nvp0`}],[`path`,{d:`m8 9 3 3-3 3`,key:`12hl5m`}]]),st=f(`panel-right-open`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M15 3v18`,key:`14nvp0`}],[`path`,{d:`m10 15-3-3 3-3`,key:`1pgupc`}]]),R=e(i(),1),z=r();function ct({icon:e,label:t,dropdownLabel:n,onPrimary:r,items:i}){let[a,o]=(0,R.useState)(!1),s=(0,R.useRef)(null);return(0,R.useEffect)(()=>{if(!a)return;let e=e=>{s.current&&!s.current.contains(e.target)&&o(!1)},t=e=>{e.key===`Escape`&&(e.stopPropagation(),o(!1))};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[a]),i.length===0?(0,z.jsxs)(P,{variant:`secondary`,size:`sm`,onClick:r,children:[e,t]}):(0,z.jsxs)(`div`,{className:`relative inline-flex`,ref:s,children:[(0,z.jsxs)(`div`,{className:`flex relative z-50`,children:[(0,z.jsxs)(P,{variant:`secondary`,size:`sm`,onClick:()=>{o(!1),r()},className:`rounded-r-none`,children:[e,t]}),(0,z.jsx)(P,{variant:`secondary`,size:`sm`,onClick:()=>o(e=>!e),"aria-label":n,"aria-haspopup":`menu`,"aria-expanded":a,className:`rounded-l-none border-l border-bambu-dark px-2`,children:(0,z.jsx)(g,{className:`w-4 h-4 transition-transform ${a?`rotate-180`:``}`})})]}),a&&(0,z.jsx)(`div`,{role:`menu`,className:`absolute right-0 top-full mt-1 w-56 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg z-50 py-1`,children:i.map(e=>(0,z.jsxs)(`button`,{type:`button`,role:`menuitem`,onClick:()=>{o(!1),e.onClick()},className:`w-full text-left px-3 py-2 text-sm text-bambu-gray-light hover:bg-bambu-dark-tertiary hover:text-white transition-colors flex items-center gap-2`,children:[(0,z.jsx)(fe,{className:`w-4 h-4 flex-shrink-0`}),e.label]},e.key))})]})}function lt({archiveId:e,libraryFileId:t,title:n,fileType:r,onClose:i,onSliceWithBambuddy:c,onSnapshot:u}){let{t:d}=o(),{showToast:f}=v(),{data:m}=l({queryKey:[`settings`],queryFn:a.getSettings}),g=Ke(m?.open_in_slicer,m?.preferred_slicer),_=t!=null,[b,x]=(0,R.useState)(null),[S,C]=(0,R.useState)(null),[w,T]=(0,R.useState)(!0),[E,D]=(0,R.useState)(null),[O,k]=(0,R.useState)(!1),[A,ee]=(0,R.useState)(null),[M,te]=(0,R.useState)(0),[N,ne]=(0,R.useState)(null),[re,ie]=(0,R.useState)(!1),[ae,oe]=(0,R.useState)(!1),se=(0,R.useRef)(null),ce=(0,R.useRef)(null),le=Ve(),{isFullscreen:ue,toggleFullscreen:de}=le,pe=.35;(0,R.useEffect)(()=>{if(T(!0),_){let e=(r||``).toLowerCase(),t=e===`3mf`||e===`gcode.3mf`||e===`stl`||e===`step`||e===`stp`;C({has_model:t,has_source:!1,build_volume:{x:256,y:256,z:256},filament_colors:[]}),x(t?`3d`:null),T(!1);return}if(!e){C(null),x(null),T(!1);return}a.getArchiveCapabilities(e).then(e=>{C(e),e.has_model&&x(`3d`),T(!1)}).catch(()=>{C({has_model:!0,has_source:!1,build_volume:{x:256,y:256,z:256},filament_colors:[]}),x(`3d`),T(!1)})},[e,r,_]),(0,R.useEffect)(()=>{if(k(!0),ee(null),te(0),_){let e=(r||``).toLowerCase();if(!t||!(e===`3mf`||e===`gcode.3mf`)){D(null),k(!1);return}a.getLibraryFilePlates(t).then(e=>D(e)).catch(()=>D(null)).finally(()=>k(!1));return}if(!e){D(null),k(!1);return}a.getArchivePlates(e).then(e=>D(e)).catch(()=>D(null)).finally(()=>k(!1))},[e,r,_,t]);let F=(0,R.useMemo)(()=>E?.plates??[],[E]),me=(E?.is_multi_plate??!1)&&F.length>1,I=ue&&me,L=A==null?null:F.find(e=>e.index===A)??null,he=e=>e.object_count??e.objects?.length??0,ge=F.reduce((e,t)=>e+he(t),0),_e=L?he(L):ge,ve=L?d(`modelViewer.plateNumber`,{number:L.index}):d(`modelViewer.allPlates`),ye=F.length>0,be=(0,R.useRef)(null),xe=(0,R.useRef)(null),[Se,Ce]=(0,R.useState)(10),[we,Te]=(0,R.useState)(3),Ee=F.length>Se,De=Math.max(1,Math.ceil(F.length/Se)),Oe=Ee?F.slice(M*Se,(M+1)*Se):F;(0,R.useEffect)(()=>{if(!I){Ce(10),Te(3);return}let e=be.current,t=xe.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));Te(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);Ce(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()}},[I,F.length]),(0,R.useEffect)(()=>{if(!Ee){te(0);return}te(e=>Math.min(e,De-1))},[F.length,Ee,De]),(0,R.useEffect)(()=>{if(!Ee||A==null)return;let e=F.findIndex(e=>e.index===A);if(e<0)return;let t=Math.floor(e/Se);te(e=>e===t?e:t)},[F,Se,A,Ee]),(0,R.useEffect)(()=>{if(!I){ne(null),oe(!1);return}if(ae)return;let e=se.current,t=ce.current;if(!e||!t)return;let n=e.clientHeight;if(!n)return;let r=Math.max(240,n*pe),i=Math.max(160,n-10-r),a=Math.min(t.scrollHeight,i);ne(Math.max(160,a))},[I,ae,F.length,M,10,160,240,pe]),(0,R.useEffect)(()=>{if(!re)return;let e=e=>{let t=se.current;if(!t)return;let n=t.getBoundingClientRect(),r=n.height;if(!r)return;let i=Math.max(240,r*pe),a=Math.max(160,r-10-i);ne(Math.min(a,Math.max(160,e.clientY-n.top)))},t=()=>{ie(!1),oe(!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=``}},[re,10,160,240,pe]);let ke=g===`orcaslicer`?[`orcaslicer`,`bambu_studio`]:[`bambu_studio`,`orcaslicer`],Ae=_?ke.filter(e=>qe(r,e)):ke,Me=Ae.length>0,Ne=Je(r),Pe=!!(_&&m?.use_slicer_api&&c&&Ne),Fe=async r=>{if(!Me)return;let i=n||`model`;try{if(_){let{token:e}=await a.createLibrarySlicerToken(t),n=a.getLibrarySlicerDownloadUrl(t,e,i);Ge(`${window.location.origin}${n}`,r)}else{let{token:t}=await a.createArchiveSlicerToken(e),n=a.getArchiveSlicerDownloadUrl(e,t,i);Ge(`${window.location.origin}${n}`,r)}}catch{f(d(`modelViewer.openInSlicerFailed`),`error`),Ge(_?`${window.location.origin}${a.getLibraryFileDownloadUrl(t)}`:`${window.location.origin}${a.getArchiveForSlicer(e,i)}`,r)}},Ie=Pe?Ae:Ae.slice(1),Le=e=>d(e===`orcaslicer`?`settings.slicerOrcaSlicer`:`settings.slicerBambuStudio`),Re=Ie.map(e=>({key:e,label:d(`modelViewer.openInSlicerWith`,{slicer:Le(e)}),onClick:()=>Fe(e)}));return(0,z.jsxs)(Be,{title:n,fullscreen:le,onClose:i,closeOnBackdropClick:!0,titleExtra:ye?(0,z.jsxs)(`span`,{className:`text-xs text-bambu-gray bg-bambu-dark-tertiary/70 px-2 py-1 rounded whitespace-nowrap`,children:[ve,`: `,d(`modelViewer.objectCount`,{count:_e})]}):void 0,actions:(0,z.jsx)(z.Fragment,{children:Pe?(0,z.jsx)(ct,{icon:(0,z.jsx)(y,{className:`w-4 h-4`}),label:d(`slice.action`),dropdownLabel:d(`modelViewer.moreSlicerOptions`),onPrimary:()=>c?.(),items:Re}):Me?(0,z.jsx)(ct,{icon:(0,z.jsx)(fe,{className:`w-4 h-4`}),label:Ae[0]===g?d(`modelViewer.openInSlicer`):d(`modelViewer.openInSlicerWith`,{slicer:Le(Ae[0])}),dropdownLabel:d(`modelViewer.moreSlicerOptions`),onPrimary:()=>Fe(Ae[0]),items:Re}):(0,z.jsxs)(P,{variant:`secondary`,size:`sm`,disabled:!0,children:[(0,z.jsx)(fe,{className:`w-4 h-4`}),d(`modelViewer.openInSlicer`)]})}),children:[S&&(0,z.jsx)(`div`,{className:`flex border-b border-bambu-dark-tertiary`,children:(0,z.jsxs)(`button`,{onClick:()=>S.has_model&&x(`3d`),disabled:!S.has_model,className:`flex items-center gap-2 px-6 py-3 text-sm font-medium transition-colors ${b===`3d`?`text-bambu-green border-b-2 border-bambu-green`:S.has_model?`text-bambu-gray hover:text-white`:`text-bambu-gray/30 cursor-not-allowed`}`,children:[(0,z.jsx)(p,{className:`w-4 h-4`}),d(`modelViewer.tabs.model`),!S.has_model&&(0,z.jsxs)(`span`,{className:`text-xs`,children:[`(`,d(`modelViewer.notAvailable`),`)`]})]})}),(0,z.jsx)(`div`,{className:`flex-1 overflow-hidden p-4`,children:w?(0,z.jsx)(`div`,{className:`w-full h-full flex items-center justify-center`,children:(0,z.jsx)(j,{className:`w-8 h-8 animate-spin text-bambu-green`})}):b===`3d`&&S?(0,z.jsxs)(`div`,{ref:se,className:`w-full h-full flex flex-col ${I?`gap-0 min-h-0`:`gap-3`}`,children:[me&&(0,z.jsxs)(`div`,{ref:ce,style:I&&N!=null?{height:N}:void 0,className:`rounded-lg border border-bambu-dark-tertiary bg-bambu-dark p-3 ${I?`flex flex-col shrink-0`:``}`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-bambu-gray mb-2`,children:[(0,z.jsx)(je,{className:`w-4 h-4`}),d(`modelViewer.plates`),O&&(0,z.jsx)(j,{className:`w-3 h-3 animate-spin`})]}),(0,z.jsxs)(`div`,{className:I?`flex flex-col min-h-0 flex-1`:void 0,children:[(0,z.jsx)(`div`,{ref:xe,className:I?`min-h-0 overflow-hidden pr-1 flex-1`:void 0,children:(0,z.jsxs)(`div`,{ref:be,className:I?`grid gap-2`:`grid grid-cols-2 md:grid-cols-3 gap-2`,style:I?{gridTemplateColumns:`repeat(${we}, minmax(0, 1fr))`}:void 0,children:[(0,z.jsxs)(`button`,{type:`button`,onClick:()=>ee(null),className:`flex items-center rounded-lg border text-left transition-colors ${I?`gap-1.5 p-1.5 w-full`:`gap-2 p-2`} ${A==null?`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary bg-bambu-dark-secondary hover:border-bambu-gray`}`,children:[(0,z.jsx)(`div`,{className:`rounded bg-bambu-dark-tertiary flex items-center justify-center ${I?`w-8 h-8`:`w-10 h-10`}`,children:(0,z.jsx)(je,{className:`${I?`w-4 h-4`:`w-5 h-5`} text-bambu-gray`})}),(0,z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,z.jsx)(`p`,{className:`${I?`text-xs`:`text-sm`} text-white font-medium truncate`,children:d(`modelViewer.allPlates`)}),(0,z.jsx)(`p`,{className:`${I?`text-[10px]`:`text-xs`} text-bambu-gray truncate`,children:d(`modelViewer.plateCount`,{count:F.length})})]}),A==null&&(0,z.jsx)(h,{className:`${I?`w-3.5 h-3.5`:`w-4 h-4`} text-bambu-green flex-shrink-0`})]}),Oe.map(e=>(0,z.jsxs)(`button`,{type:`button`,onClick:()=>ee(e.index),className:`flex items-center rounded-lg border text-left transition-colors ${I?`gap-1.5 p-1.5 w-full`:`gap-2 p-2`} ${A===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,z.jsx)(`img`,{src:s(e.thumbnail_url),alt:`Plate ${e.index}`,className:`${I?`w-8 h-8`:`w-10 h-10`} rounded object-cover bg-bambu-dark-tertiary`}):(0,z.jsx)(`div`,{className:`rounded bg-bambu-dark-tertiary flex items-center justify-center ${I?`w-8 h-8`:`w-10 h-10`}`,children:(0,z.jsx)(je,{className:`${I?`w-4 h-4`:`w-5 h-5`} text-bambu-gray`})}),(0,z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,z.jsx)(`p`,{className:`${I?`text-xs`:`text-sm`} text-white font-medium truncate`,children:e.name||d(`modelViewer.plateNumber`,{number:e.index})}),(0,z.jsx)(`p`,{className:`${I?`text-[10px]`:`text-xs`} text-bambu-gray truncate`,children:d(`modelViewer.objectCount`,{count:e.object_count??e.objects?.length??0})})]}),A===e.index&&(0,z.jsx)(h,{className:`${I?`w-3.5 h-3.5`:`w-4 h-4`} text-bambu-green flex-shrink-0`})]},e.index))]})}),(L||Ee)&&(0,z.jsxs)(`div`,{className:`mt-auto pt-3 flex items-center gap-4 text-xs text-bambu-gray overflow-x-auto`,children:[L&&(0,z.jsxs)(`div`,{className:`flex items-center gap-3 whitespace-nowrap`,children:[(0,z.jsx)(`span`,{children:d(`modelViewer.plateNumber`,{number:L.index})}),L.print_time_seconds!=null&&(0,z.jsx)(`span`,{children:d(`modelViewer.eta`,{minutes:Math.round(L.print_time_seconds/60)})}),L.filament_used_grams!=null&&(0,z.jsxs)(`span`,{children:[L.filament_used_grams.toFixed(1),` g`]}),L.filaments.length>0&&(0,z.jsx)(`span`,{children:d(`modelViewer.filamentCount`,{count:L.filaments.length})})]}),Ee&&(0,z.jsxs)(`div`,{className:`flex items-center gap-2 whitespace-nowrap ${L?`ml-auto`:``}`,children:[(0,z.jsx)(`span`,{children:d(`modelViewer.pagination.pageOf`,{current:M+1,total:De})}),(0,z.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,z.jsx)(`button`,{type:`button`,onClick:()=>te(e=>Math.max(e-1,0)),disabled:M===0,className:`px-2 py-1 rounded border text-xs ${M===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:d(`modelViewer.pagination.prev`)}),(()=>{let e=Math.max(0,M-2),t=Math.min(De,e+5);t-e<5&&(e=Math.max(0,t-5));let n=Array.from({length:t-e},(t,n)=>e+n);return(0,z.jsxs)(z.Fragment,{children:[e>0&&(0,z.jsx)(`button`,{type:`button`,onClick:()=>te(0),className:`px-2 py-1 rounded border text-xs ${M===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,z.jsx)(`span`,{className:`px-1`,children:`…`}),n.map(e=>(0,z.jsx)(`button`,{type:`button`,onClick:()=>te(e),className:`px-2 py-1 rounded border text-xs ${M===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)),tte(De-1),className:`px-2 py-1 rounded border text-xs ${M===De-1?`border-bambu-green text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:text-white hover:border-bambu-gray`}`,children:De})]})})(),(0,z.jsx)(`button`,{type:`button`,onClick:()=>te(e=>Math.min(e+1,De-1)),disabled:M>=De-1,className:`px-2 py-1 rounded border text-xs ${M>=De-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:d(`modelViewer.pagination.next`)})]})]})]})]})]}),I&&(0,z.jsx)(`div`,{role:`separator`,"aria-orientation":`horizontal`,onMouseDown:e=>{e.preventDefault(),ie(!0),oe(!0)},className:`h-2 cursor-row-resize flex items-center justify-center ${re?`bg-bambu-dark-tertiary`:`bg-bambu-dark-secondary/60 hover:bg-bambu-dark-tertiary`}`,children:(0,z.jsx)(`div`,{className:`w-12 h-1 rounded-full bg-bambu-gray/50`})}),(0,z.jsx)(`div`,{className:`flex-1 ${I?`min-h-0`:``}`,"data-testid":`model-viewer-area`,onDoubleClick:de,children:(0,z.jsx)(Ye,{url:_?a.getLibraryFileDownloadUrl(t):S.has_source?a.getSource3mfDownloadUrl(e):a.getArchiveDownload(e),fileType:r,buildVolume:S.build_volume,filamentColors:S.filament_colors,selectedPlateId:A,className:`w-full h-full`,onSnapshot:u})})]}):(0,z.jsx)(`div`,{className:`w-full h-full flex items-center justify-center text-bambu-gray`,children:d(`modelViewer.noPreview`)})})]})}var ut=100;function dt(e){let t=e.lastIndexOf(`.`);return t>0?e.slice(0,t):e}function ft({files:e,folderId:t,canSlice:n,onClose:r,onCombined:i}){let{t:s}=o(),l=c(),{showToast:d}=v(),[f,p]=(0,R.useState)(()=>Object.fromEntries(e.map(e=>[e.id,1]))),[m,h]=(0,R.useState)(null),[g,_]=(0,R.useState)(n),y=e.reduce((e,t)=>e+(f[t.id]||0),0),b=(0,R.useMemo)(()=>e.length===1?`${dt(e[0].filename)} x${f[e[0].id]||1}`:s(`fileManager.combine.defaultName`,{name:dt(e[0]?.filename??``),count:e.length-1}),[e,f,s]),x=(m??b).trim(),S=u({mutationFn:()=>a.combineLibraryFiles(e.map(e=>({file_id:e.id,copies:f[e.id]||1})),x,t),onSuccess:e=>{l.invalidateQueries({queryKey:[`library-files`]}),l.invalidateQueries({queryKey:[`library-stats`]}),d(s(`fileManager.combine.done`,{filename:e.filename,count:y}),`success`),i(e,g&&n)},onError:e=>d(e.message,`error`)});(0,R.useEffect)(()=>{let e=e=>{e.key===`Escape`&&!S.isPending&&r()};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[r,S.isPending]);let C=y>ut,w=e.some(e=>!f[e.id]||f[e.id]<1),T=`combine-files-title`;return(0,z.jsxs)(`div`,{className:`fixed inset-0 z-[60] flex items-center justify-center`,children:[(0,z.jsx)(`div`,{className:`absolute inset-0 bg-black/60`,onClick:()=>!S.isPending&&r()}),(0,z.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":T,children:[(0,z.jsxs)(`div`,{className:`flex items-center justify-between gap-4 px-5 py-4 border-b border-bambu-dark-tertiary`,children:[(0,z.jsxs)(`h3`,{id:T,className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,z.jsx)(nt,{className:`w-4 h-4 text-bambu-green`}),s(`fileManager.combine.title`)]}),(0,z.jsx)(`button`,{type:`button`,className:`p-1.5 text-bambu-gray hover:text-white rounded`,onClick:r,"aria-label":s(`common.close`),children:(0,z.jsx)(ae,{className:`w-5 h-5`})})]}),(0,z.jsx)(`p`,{className:`px-5 pt-3 text-sm text-bambu-gray`,children:s(`fileManager.combine.description`)}),(0,z.jsxs)(`div`,{className:`px-5 py-3`,children:[(0,z.jsx)(`label`,{htmlFor:`combine-name`,className:`block text-xs text-bambu-gray mb-1`,children:s(`fileManager.combine.nameLabel`)}),(0,z.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,z.jsx)(`input`,{id:`combine-name`,type:`text`,value:m??b,onChange:e=>h(e.target.value),maxLength:200,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`}),(0,z.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:`.3mf`})]})]}),(0,z.jsxs)(`div`,{className:`overflow-y-auto flex-1 max-h-[20rem] border-y border-bambu-dark-tertiary`,children:[(0,z.jsxs)(`div`,{className:`flex justify-between px-5 py-2 text-xs text-bambu-gray`,children:[(0,z.jsx)(`span`,{children:s(`fileManager.combine.model`)}),(0,z.jsx)(`span`,{children:s(`fileManager.combine.copies`)})]}),(0,z.jsx)(`ul`,{className:`divide-y divide-bambu-dark-tertiary/40`,children:e.map(e=>(0,z.jsxs)(`li`,{className:`flex items-center gap-3 px-5 py-2`,children:[(0,z.jsx)(`span`,{className:`text-sm text-white truncate flex-1`,title:e.filename,children:e.filename}),(0,z.jsx)(`input`,{type:`number`,min:1,max:ut,value:f[e.id]||``,onChange:t=>{let n=parseInt(t.target.value,10);p(t=>({...t,[e.id]:Number.isNaN(n)?0:n}))},"aria-label":s(`fileManager.combine.copiesFor`,{filename:e.filename}),className:`w-20 px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-sm text-white text-right focus:outline-none focus:border-bambu-green`})]},e.id))})]}),(0,z.jsxs)(`div`,{className:`px-5 py-3 space-y-2 text-sm`,children:[(0,z.jsx)(`div`,{className:C?`text-red-400`:`text-bambu-gray`,children:C?s(`fileManager.combine.tooMany`,{max:ut}):s(`fileManager.combine.total`,{count:y})}),n&&(0,z.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,z.jsx)(`input`,{type:`checkbox`,checked:g,onChange:e=>_(e.target.checked),className:`accent-bambu-green`}),(0,z.jsx)(`span`,{className:`text-white`,children:s(`fileManager.combine.sliceNext`)})]})]}),(0,z.jsxs)(`div`,{className:`px-5 py-4 border-t border-bambu-dark-tertiary flex justify-end gap-2`,children:[(0,z.jsx)(P,{type:`button`,variant:`secondary`,onClick:r,disabled:S.isPending,children:s(`common.cancel`)}),(0,z.jsxs)(P,{type:`button`,onClick:()=>S.mutate(),disabled:S.isPending||C||w||!x,children:[S.isPending&&(0,z.jsx)(j,{className:`w-4 h-4 animate-spin`}),s(`fileManager.combine.submit`)]})]})]})]})}var pt=[`library-tags`];function mt({open:e,fileIds:t,onClose:n}){let{t:r}=o(),i=c(),{showToast:s}=v(),[d,f]=(0,R.useState)(`add`),[p,m]=(0,R.useState)(new Set),[h,g]=(0,R.useState)(``),[_,y]=(0,R.useState)(``);(0,R.useEffect)(()=>{e||(f(`add`),m(new Set),g(``),y(``))},[e]);let{data:b=[],isLoading:x}=l({queryKey:pt,queryFn:a.getLibraryTags,enabled:e}),S=(0,R.useMemo)(()=>{let e=h.trim().toLowerCase();return e?b.filter(t=>t.name.toLowerCase().includes(e)):b},[b,h]),C=e=>{m(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},w=u({mutationFn:e=>a.createLibraryTag(e),onSuccess:e=>{m(t=>new Set(t).add(e.id)),y(``),i.invalidateQueries({queryKey:pt})},onError:e=>{s(e.message||r(`fileManager.tags.saveFailed`),`error`)}}),T=u({mutationFn:()=>a.bulkAssignLibraryTags(t,Array.from(p),d),onSuccess:e=>{s(d===`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:pt}),n()},onError:e=>{s(e.message||r(`fileManager.tags.applyFailed`),`error`)}});if((0,R.useEffect)(()=>{if(!e)return;let t=e=>{e.key===`Escape`&&!T.isPending&&!w.isPending&&n()};return document.addEventListener(`keydown`,t),()=>document.removeEventListener(`keydown`,t)},[e,n,T.isPending,w.isPending]),!e)return null;let E=!_.trim()||w.isPending||b.some(e=>e.name.toLowerCase()===_.trim().toLowerCase()),D=`bulk-tags-picker-title`;return(0,z.jsxs)(`div`,{className:`fixed inset-0 z-[60] flex items-center justify-center`,children:[(0,z.jsx)(`div`,{className:`absolute inset-0 bg-black/60`,onClick:()=>!T.isPending&&n()}),(0,z.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":D,children:[(0,z.jsxs)(`div`,{className:`flex items-center justify-between gap-4 px-5 py-4 border-b border-bambu-dark-tertiary`,children:[(0,z.jsxs)(`h3`,{id:D,className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,z.jsx)(xe,{className:`w-4 h-4 text-bambu-green`}),r(`fileManager.tags.bulkTitle`,{count:t.length})]}),(0,z.jsx)(`button`,{type:`button`,className:`p-1.5 text-bambu-gray hover:text-white rounded`,onClick:n,"aria-label":r(`common.close`),children:(0,z.jsx)(ae,{className:`w-5 h-5`})})]}),(0,z.jsxs)(`div`,{className:`px-5 py-3 border-b border-bambu-dark-tertiary flex gap-4 text-sm`,children:[(0,z.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,z.jsx)(`input`,{type:`radio`,name:`bulk-action`,checked:d===`add`,onChange:()=>f(`add`),className:`accent-bambu-green`}),(0,z.jsx)(`span`,{className:`text-white`,children:r(`fileManager.tags.actionAdd`)})]}),(0,z.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,z.jsx)(`input`,{type:`radio`,name:`bulk-action`,checked:d===`remove`,onChange:()=>f(`remove`),className:`accent-bambu-green`}),(0,z.jsx)(`span`,{className:`text-white`,children:r(`fileManager.tags.actionRemove`)})]})]}),(0,z.jsx)(`div`,{className:`px-5 py-3 border-b border-bambu-dark-tertiary`,children:(0,z.jsx)(`input`,{type:`text`,value:h,onChange:e=>g(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,z.jsx)(`div`,{className:`overflow-y-auto flex-1 min-h-[8rem] max-h-[24rem]`,children:x?(0,z.jsxs)(`div`,{className:`flex items-center justify-center py-12 text-bambu-gray`,children:[(0,z.jsx)(j,{className:`w-5 h-5 animate-spin mr-2`}),r(`common.loading`)]}):S.length===0?(0,z.jsx)(`div`,{className:`py-12 text-center text-bambu-gray text-sm`,children:b.length===0?r(`fileManager.tags.empty`):r(`fileManager.tags.noMatches`)}):(0,z.jsx)(`ul`,{className:`divide-y divide-bambu-dark-tertiary/40`,children:S.map(e=>(0,z.jsx)(`li`,{children:(0,z.jsxs)(`label`,{className:`flex items-center gap-3 px-5 py-2 hover:bg-bambu-dark-tertiary/30 cursor-pointer`,children:[(0,z.jsx)(`input`,{type:`checkbox`,checked:p.has(e.id),onChange:()=>C(e.id),className:`accent-bambu-green`}),(0,z.jsx)(`span`,{className:`text-sm text-white truncate flex-1`,children:e.name}),(0,z.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:e.file_count})]})},e.id))})}),d===`add`&&(0,z.jsxs)(`div`,{className:`px-5 py-3 border-t border-bambu-dark-tertiary flex gap-2`,children:[(0,z.jsx)(`input`,{type:`text`,value:_,onChange:e=>y(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`&&!E&&(e.preventDefault(),w.mutate(_.trim()))}}),(0,z.jsxs)(P,{type:`button`,variant:`secondary`,onClick:()=>w.mutate(_.trim()),disabled:E,children:[w.isPending?(0,z.jsx)(j,{className:`w-4 h-4 animate-spin`}):(0,z.jsx)(Oe,{className:`w-4 h-4`}),r(`fileManager.tags.createButton`)]})]}),(0,z.jsxs)(`div`,{className:`px-5 py-4 border-t border-bambu-dark-tertiary flex justify-end gap-2`,children:[(0,z.jsx)(P,{type:`button`,variant:`secondary`,onClick:n,disabled:T.isPending,children:r(`common.cancel`)}),(0,z.jsxs)(P,{type:`button`,onClick:()=>T.mutate(),disabled:p.size===0||T.isPending||t.length===0,children:[T.isPending&&(0,z.jsx)(j,{className:`w-4 h-4 animate-spin`}),r(d===`add`?`fileManager.tags.applyAdd`:`fileManager.tags.applyRemove`)]})]})]})]})}function ht(e,t){let n=t||{};return(e[e.length-1]===``?[...e,``]:e).join((n.padRight?` `:``)+`,`+(n.padLeft===!1?``:` `)).trim()}var gt=/^[$_\p{ID_Start}][$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,_t=/^[$_\p{ID_Start}][-$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,vt={};function yt(e,t){return((t||vt).jsx?_t:gt).test(e)}var bt=/[ \t\n\f\r]/g;function xt(e){return typeof e==`object`?e.type===`text`?St(e.value):!1:St(e)}function St(e){return e.replace(bt,``)===``}var Ct=class{constructor(e,t,n){this.normal=t,this.property=e,n&&(this.space=n)}};Ct.prototype.normal={},Ct.prototype.property={},Ct.prototype.space=void 0;function wt(e,t){let n={},r={};for(let t of e)Object.assign(n,t.property),Object.assign(r,t.normal);return new Ct(n,r,t)}function Tt(e){return e.toLowerCase()}var B=class{constructor(e,t){this.attribute=t,this.property=e}};B.prototype.attribute=``,B.prototype.booleanish=!1,B.prototype.boolean=!1,B.prototype.commaOrSpaceSeparated=!1,B.prototype.commaSeparated=!1,B.prototype.defined=!1,B.prototype.mustUseProperty=!1,B.prototype.number=!1,B.prototype.overloadedBoolean=!1,B.prototype.property=``,B.prototype.spaceSeparated=!1,B.prototype.space=void 0;var Et=t({boolean:()=>V,booleanish:()=>H,commaOrSpaceSeparated:()=>G,commaSeparated:()=>kt,number:()=>U,overloadedBoolean:()=>Ot,spaceSeparated:()=>W}),Dt=0,V=At(),H=At(),Ot=At(),U=At(),W=At(),kt=At(),G=At();function At(){return 2**++Dt}var jt=Object.keys(Et),K=class extends B{constructor(e,t,n,r){let i=-1;if(super(e,t),Mt(this,`space`,r),typeof n==`number`)for(;++i4&&n.slice(0,4)===`data`&&Gt.test(t)){if(t.charAt(4)===`-`){let e=t.slice(5).replace(Wt,Jt);r=`data`+e.charAt(0).toUpperCase()+e.slice(1)}else{let e=t.slice(4);if(!Wt.test(e)){let n=e.replace(Ut,qt);n.charAt(0)!==`-`&&(n=`-`+n),t=`data`+n}}i=K}return new i(r,t)}function qt(e){return`-`+e.toLowerCase()}function Jt(e){return e.charAt(1).toUpperCase()}var Yt=wt([Pt,Lt,zt,Bt,Vt],`html`),Xt=wt([Pt,Rt,zt,Bt,Vt],`svg`);function Zt(e){return e.join(` `).trim()}var Qt=n(((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=` +const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/PdfPreviewModal-gJCfcyUW.js","assets/chunk-aKtaBQYM.js","assets/index-Cxa-KVmA.js","assets/QueryClientProvider-Ce8_sN3w.js","assets/client-DnySrlFv.js","assets/useMutation-B-Tr2hIP.js","assets/useQueries-Be6PMvSC.js","assets/useQuery-BBCjCezC.js","assets/createLucideIcon-DvBYJlWL.js","assets/arrow-down-Cj0DZhNf.js","assets/arrow-up-D-pfJ3WZ.js","assets/calendar-BLKPnWqV.js","assets/check-Ck0cMLU4.js","assets/info-ROUoQhJR.js","assets/ToastContext-BRX0SW3C.js","assets/loader-circle-BEmFtawu.js","assets/x-DR-Trv6U.js","assets/file-DDkFXH-b.js","assets/triangle-alert-Dt_1FcBy.js","assets/react-dom-B8Dg6xzp.js","assets/Button-DDr6eAFy.js","assets/Card-Bzc64K35.js","assets/filamentSwatchHelpers-D3oXQSGk.js","assets/date-G9KUauqz.js","assets/index-LBjsy7mY.css","assets/zoom-out-DNNe6DMN.js","assets/usePreviewFullscreen-ButueZqN.js","assets/maximize-2-kPQ77q72.js","assets/minimize-2-dqT-k7oI.js","assets/SpreadsheetPreviewModal-KGR-XjV_.js","assets/file-spreadsheet-WxOA9vYy.js","assets/ImagePreviewModal-NAGAMcx7.js"])))=>i.map(i=>d[i]); +import{i as e,n as t,t as n}from"./chunk-aKtaBQYM.js";import{C as r,D as i,a,w as o,x as s}from"./client-DnySrlFv.js";import{n as c}from"./QueryClientProvider-Ce8_sN3w.js";import{t as l}from"./useQuery-BBCjCezC.js";import{t as u}from"./useMutation-B-Tr2hIP.js";import{t as d}from"./useQueries-Be6PMvSC.js";import{t as f}from"./createLucideIcon-DvBYJlWL.js";import{t as p}from"./box-DAdKb9s5.js";import{t as m}from"./briefcase-Dau7xqMY.js";import{t as h}from"./check-Ck0cMLU4.js";import{a as g,t as _}from"./info-ROUoQhJR.js";import{n as v}from"./ToastContext-BRX0SW3C.js";import{t as y}from"./cog-Dol1I0kq.js";import{t as b}from"./columns-2-DVEObeDC.js";import{t as x}from"./ellipsis-vertical-t2D7cYyp.js";import{t as S}from"./file-box-04V4jZ9_.js";import{t as C}from"./file-spreadsheet-WxOA9vYy.js";import{n as w,t as T}from"./ContextMenu-CwroFwVJ.js";import{t as E}from"./funnel-C3dyAMK9.js";import{t as D}from"./SliceModal-YlJTMEj6.js";import{t as O}from"./hard-drive-CgXAHN37.js";import{t as k}from"./layout-grid-DkD3u6wa.js";import{t as A}from"./link-2-MI-QCMh8.js";import{t as ee}from"./list-CLcpeoSz.js";import{t as j}from"./loader-circle-BEmFtawu.js";import{t as M}from"./lock-MLqgWH4Q.js";import{t as te}from"./play-DIDYtk2S.js";import{t as N}from"./search-0n0CBc74.js";import{t as ne}from"./sticky-note-BH0LPqRx.js";import{t as re}from"./triangle-alert-Dt_1FcBy.js";import{t as ie}from"./unlink-C098nwOf.js";import{t as ae}from"./x-DR-Trv6U.js";import{t as oe}from"./file-DDkFXH-b.js";import{t as P}from"./Button-DDr6eAFy.js";import{n as se,o as ce,v as le}from"./date-G9KUauqz.js";import{$t as ue,At as de,Cn as fe,Dt as pe,F,Jt as me,Kn as I,Kt as L,Ln as he,Lt as ge,Mn as _e,On as ve,Ot as ye,Pn as be,Pt as xe,Rn as Se,Rt as Ce,Sn as we,Ut as Te,Vn as Ee,Wn as De,Zt as Oe,_t as ke,b as Ae,cn as je,hn as Me,kt as Ne,sn as Pe,un as Fe,vn as Ie,wn as Le,xn as Re,yt as ze}from"./index-Cxa-KVmA.js";import{n as Be,t as Ve}from"./usePreviewFullscreen-ButueZqN.js";import{n as He,r as Ue,t as We}from"./PhotoGalleryModal-BPFizk3N.js";import{a as Ge,o as Ke,r as qe,t as Je}from"./slicer-DgCA7cW6.js";import{n as Ye,t as Xe}from"./FileUploadModal-Dee1GxH_.js";import{n as Ze,t as Qe}from"./libraryFiles-B0B1SFfn.js";var $e=f(`arrow-down-wide-narrow`,[[`path`,{d:`m3 16 4 4 4-4`,key:`1co6wj`}],[`path`,{d:`M7 20V4`,key:`1yoxec`}],[`path`,{d:`M11 4h10`,key:`1w87gc`}],[`path`,{d:`M11 8h7`,key:`djye34`}],[`path`,{d:`M11 12h4`,key:`q8tih4`}]]),et=f(`arrow-up-narrow-wide`,[[`path`,{d:`m3 8 4-4 4 4`,key:`11wl7u`}],[`path`,{d:`M7 4v16`,key:`1glfcx`}],[`path`,{d:`M11 12h4`,key:`q8tih4`}],[`path`,{d:`M11 16h7`,key:`uosisv`}],[`path`,{d:`M11 20h10`,key:`jvxblo`}]]),tt=f(`calendar-clock`,[[`path`,{d:`M16 14v2.2l1.6 1`,key:`fo4ql5`}],[`path`,{d:`M16 2v4`,key:`4m81vk`}],[`path`,{d:`M21 7.5V6a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h3.5`,key:`1osxxc`}],[`path`,{d:`M3 10h5`,key:`r794hk`}],[`path`,{d:`M8 2v4`,key:`1cmpym`}],[`circle`,{cx:`16`,cy:`16`,r:`6`,key:`qoo3c4`}]]),nt=f(`combine`,[[`path`,{d:`M14 3a1 1 0 0 1 1 1v5a1 1 0 0 1-1 1`,key:`1l7d7l`}],[`path`,{d:`M19 3a1 1 0 0 1 1 1v5a1 1 0 0 1-1 1`,key:`9955pe`}],[`path`,{d:`m7 15 3 3`,key:`4hkfgk`}],[`path`,{d:`m7 21 3-3H5a2 2 0 0 1-2-2v-2`,key:`1xljwe`}],[`rect`,{x:`14`,y:`14`,width:`7`,height:`7`,rx:`1`,key:`1cdgtw`}],[`rect`,{x:`3`,y:`3`,width:`7`,height:`7`,rx:`1`,key:`zi3rio`}]]),rt=f(`folder-plus`,[[`path`,{d:`M12 10v6`,key:`1bos4e`}],[`path`,{d:`M9 13h6`,key:`1uhe8q`}],[`path`,{d:`M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z`,key:`1kt360`}]]),it=f(`folder-symlink`,[[`path`,{d:`M2 9.35V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H20a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2v-3a2 2 0 0 1 2-2h7`,key:`y8kt7d`}],[`path`,{d:`m8 16 3-3-3-3`,key:`rlqrt1`}]]),at=f(`move-right`,[[`path`,{d:`M18 8L22 12L18 16`,key:`1r0oui`}],[`path`,{d:`M2 12H22`,key:`1m8cig`}]]),ot=f(`panel-right-close`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M15 3v18`,key:`14nvp0`}],[`path`,{d:`m8 9 3 3-3 3`,key:`12hl5m`}]]),st=f(`panel-right-open`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M15 3v18`,key:`14nvp0`}],[`path`,{d:`m10 15-3-3 3-3`,key:`1pgupc`}]]),R=e(i(),1),z=r();function ct({icon:e,label:t,dropdownLabel:n,onPrimary:r,items:i}){let[a,o]=(0,R.useState)(!1),s=(0,R.useRef)(null);return(0,R.useEffect)(()=>{if(!a)return;let e=e=>{s.current&&!s.current.contains(e.target)&&o(!1)},t=e=>{e.key===`Escape`&&(e.stopPropagation(),o(!1))};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[a]),i.length===0?(0,z.jsxs)(P,{variant:`secondary`,size:`sm`,onClick:r,children:[e,t]}):(0,z.jsxs)(`div`,{className:`relative inline-flex`,ref:s,children:[(0,z.jsxs)(`div`,{className:`flex relative z-50`,children:[(0,z.jsxs)(P,{variant:`secondary`,size:`sm`,onClick:()=>{o(!1),r()},className:`rounded-r-none`,children:[e,t]}),(0,z.jsx)(P,{variant:`secondary`,size:`sm`,onClick:()=>o(e=>!e),"aria-label":n,"aria-haspopup":`menu`,"aria-expanded":a,className:`rounded-l-none border-l border-bambu-dark px-2`,children:(0,z.jsx)(g,{className:`w-4 h-4 transition-transform ${a?`rotate-180`:``}`})})]}),a&&(0,z.jsx)(`div`,{role:`menu`,className:`absolute right-0 top-full mt-1 w-56 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg z-50 py-1`,children:i.map(e=>(0,z.jsxs)(`button`,{type:`button`,role:`menuitem`,onClick:()=>{o(!1),e.onClick()},className:`w-full text-left px-3 py-2 text-sm text-bambu-gray-light hover:bg-bambu-dark-tertiary hover:text-white transition-colors flex items-center gap-2`,children:[(0,z.jsx)(fe,{className:`w-4 h-4 flex-shrink-0`}),e.label]},e.key))})]})}function lt({archiveId:e,libraryFileId:t,title:n,fileType:r,onClose:i,onSliceWithBambuddy:c,onSnapshot:u}){let{t:d}=o(),{showToast:f}=v(),{data:m}=l({queryKey:[`settings`],queryFn:a.getSettings}),g=Ke(m?.open_in_slicer,m?.preferred_slicer),_=t!=null,[b,x]=(0,R.useState)(null),[S,C]=(0,R.useState)(null),[w,T]=(0,R.useState)(!0),[E,D]=(0,R.useState)(null),[O,k]=(0,R.useState)(!1),[A,ee]=(0,R.useState)(null),[M,te]=(0,R.useState)(0),[N,ne]=(0,R.useState)(null),[re,ie]=(0,R.useState)(!1),[ae,oe]=(0,R.useState)(!1),se=(0,R.useRef)(null),ce=(0,R.useRef)(null),le=Ve(),{isFullscreen:ue,toggleFullscreen:de}=le,pe=.35;(0,R.useEffect)(()=>{if(T(!0),_){let e=(r||``).toLowerCase(),t=e===`3mf`||e===`gcode.3mf`||e===`stl`||e===`step`||e===`stp`;C({has_model:t,has_source:!1,build_volume:{x:256,y:256,z:256},filament_colors:[]}),x(t?`3d`:null),T(!1);return}if(!e){C(null),x(null),T(!1);return}a.getArchiveCapabilities(e).then(e=>{C(e),e.has_model&&x(`3d`),T(!1)}).catch(()=>{C({has_model:!0,has_source:!1,build_volume:{x:256,y:256,z:256},filament_colors:[]}),x(`3d`),T(!1)})},[e,r,_]),(0,R.useEffect)(()=>{if(k(!0),ee(null),te(0),_){let e=(r||``).toLowerCase();if(!t||!(e===`3mf`||e===`gcode.3mf`)){D(null),k(!1);return}a.getLibraryFilePlates(t).then(e=>D(e)).catch(()=>D(null)).finally(()=>k(!1));return}if(!e){D(null),k(!1);return}a.getArchivePlates(e).then(e=>D(e)).catch(()=>D(null)).finally(()=>k(!1))},[e,r,_,t]);let F=(0,R.useMemo)(()=>E?.plates??[],[E]),me=(E?.is_multi_plate??!1)&&F.length>1,I=ue&&me,L=A==null?null:F.find(e=>e.index===A)??null,he=e=>e.object_count??e.objects?.length??0,ge=F.reduce((e,t)=>e+he(t),0),_e=L?he(L):ge,ve=L?d(`modelViewer.plateNumber`,{number:L.index}):d(`modelViewer.allPlates`),ye=F.length>0,be=(0,R.useRef)(null),xe=(0,R.useRef)(null),[Se,Ce]=(0,R.useState)(10),[we,Te]=(0,R.useState)(3),Ee=F.length>Se,De=Math.max(1,Math.ceil(F.length/Se)),Oe=Ee?F.slice(M*Se,(M+1)*Se):F;(0,R.useEffect)(()=>{if(!I){Ce(10),Te(3);return}let e=be.current,t=xe.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));Te(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);Ce(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()}},[I,F.length]),(0,R.useEffect)(()=>{if(!Ee){te(0);return}te(e=>Math.min(e,De-1))},[F.length,Ee,De]),(0,R.useEffect)(()=>{if(!Ee||A==null)return;let e=F.findIndex(e=>e.index===A);if(e<0)return;let t=Math.floor(e/Se);te(e=>e===t?e:t)},[F,Se,A,Ee]),(0,R.useEffect)(()=>{if(!I){ne(null),oe(!1);return}if(ae)return;let e=se.current,t=ce.current;if(!e||!t)return;let n=e.clientHeight;if(!n)return;let r=Math.max(240,n*pe),i=Math.max(160,n-10-r),a=Math.min(t.scrollHeight,i);ne(Math.max(160,a))},[I,ae,F.length,M,10,160,240,pe]),(0,R.useEffect)(()=>{if(!re)return;let e=e=>{let t=se.current;if(!t)return;let n=t.getBoundingClientRect(),r=n.height;if(!r)return;let i=Math.max(240,r*pe),a=Math.max(160,r-10-i);ne(Math.min(a,Math.max(160,e.clientY-n.top)))},t=()=>{ie(!1),oe(!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=``}},[re,10,160,240,pe]);let ke=g===`orcaslicer`?[`orcaslicer`,`bambu_studio`]:[`bambu_studio`,`orcaslicer`],Ae=_?ke.filter(e=>qe(r,e)):ke,Me=Ae.length>0,Ne=Je(r),Pe=!!(_&&m?.use_slicer_api&&c&&Ne),Fe=async r=>{if(!Me)return;let i=n||`model`;try{if(_){let{token:e}=await a.createLibrarySlicerToken(t),n=a.getLibrarySlicerDownloadUrl(t,e,i);Ge(`${window.location.origin}${n}`,r)}else{let{token:t}=await a.createArchiveSlicerToken(e),n=a.getArchiveSlicerDownloadUrl(e,t,i);Ge(`${window.location.origin}${n}`,r)}}catch{f(d(`modelViewer.openInSlicerFailed`),`error`),Ge(_?`${window.location.origin}${a.getLibraryFileDownloadUrl(t)}`:`${window.location.origin}${a.getArchiveForSlicer(e,i)}`,r)}},Ie=Pe?Ae:Ae.slice(1),Le=e=>d(e===`orcaslicer`?`settings.slicerOrcaSlicer`:`settings.slicerBambuStudio`),Re=Ie.map(e=>({key:e,label:d(`modelViewer.openInSlicerWith`,{slicer:Le(e)}),onClick:()=>Fe(e)}));return(0,z.jsxs)(Be,{title:n,fullscreen:le,onClose:i,closeOnBackdropClick:!0,titleExtra:ye?(0,z.jsxs)(`span`,{className:`text-xs text-bambu-gray bg-bambu-dark-tertiary/70 px-2 py-1 rounded whitespace-nowrap`,children:[ve,`: `,d(`modelViewer.objectCount`,{count:_e})]}):void 0,actions:(0,z.jsx)(z.Fragment,{children:Pe?(0,z.jsx)(ct,{icon:(0,z.jsx)(y,{className:`w-4 h-4`}),label:d(`slice.action`),dropdownLabel:d(`modelViewer.moreSlicerOptions`),onPrimary:()=>c?.(),items:Re}):Me?(0,z.jsx)(ct,{icon:(0,z.jsx)(fe,{className:`w-4 h-4`}),label:Ae[0]===g?d(`modelViewer.openInSlicer`):d(`modelViewer.openInSlicerWith`,{slicer:Le(Ae[0])}),dropdownLabel:d(`modelViewer.moreSlicerOptions`),onPrimary:()=>Fe(Ae[0]),items:Re}):(0,z.jsxs)(P,{variant:`secondary`,size:`sm`,disabled:!0,children:[(0,z.jsx)(fe,{className:`w-4 h-4`}),d(`modelViewer.openInSlicer`)]})}),children:[S&&(0,z.jsx)(`div`,{className:`flex border-b border-bambu-dark-tertiary`,children:(0,z.jsxs)(`button`,{onClick:()=>S.has_model&&x(`3d`),disabled:!S.has_model,className:`flex items-center gap-2 px-6 py-3 text-sm font-medium transition-colors ${b===`3d`?`text-bambu-green border-b-2 border-bambu-green`:S.has_model?`text-bambu-gray hover:text-white`:`text-bambu-gray/30 cursor-not-allowed`}`,children:[(0,z.jsx)(p,{className:`w-4 h-4`}),d(`modelViewer.tabs.model`),!S.has_model&&(0,z.jsxs)(`span`,{className:`text-xs`,children:[`(`,d(`modelViewer.notAvailable`),`)`]})]})}),(0,z.jsx)(`div`,{className:`flex-1 overflow-hidden p-4`,children:w?(0,z.jsx)(`div`,{className:`w-full h-full flex items-center justify-center`,children:(0,z.jsx)(j,{className:`w-8 h-8 animate-spin text-bambu-green`})}):b===`3d`&&S?(0,z.jsxs)(`div`,{ref:se,className:`w-full h-full flex flex-col ${I?`gap-0 min-h-0`:`gap-3`}`,children:[me&&(0,z.jsxs)(`div`,{ref:ce,style:I&&N!=null?{height:N}:void 0,className:`rounded-lg border border-bambu-dark-tertiary bg-bambu-dark p-3 ${I?`flex flex-col shrink-0`:``}`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-bambu-gray mb-2`,children:[(0,z.jsx)(je,{className:`w-4 h-4`}),d(`modelViewer.plates`),O&&(0,z.jsx)(j,{className:`w-3 h-3 animate-spin`})]}),(0,z.jsxs)(`div`,{className:I?`flex flex-col min-h-0 flex-1`:void 0,children:[(0,z.jsx)(`div`,{ref:xe,className:I?`min-h-0 overflow-hidden pr-1 flex-1`:void 0,children:(0,z.jsxs)(`div`,{ref:be,className:I?`grid gap-2`:`grid grid-cols-2 md:grid-cols-3 gap-2`,style:I?{gridTemplateColumns:`repeat(${we}, minmax(0, 1fr))`}:void 0,children:[(0,z.jsxs)(`button`,{type:`button`,onClick:()=>ee(null),className:`flex items-center rounded-lg border text-left transition-colors ${I?`gap-1.5 p-1.5 w-full`:`gap-2 p-2`} ${A==null?`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary bg-bambu-dark-secondary hover:border-bambu-gray`}`,children:[(0,z.jsx)(`div`,{className:`rounded bg-bambu-dark-tertiary flex items-center justify-center ${I?`w-8 h-8`:`w-10 h-10`}`,children:(0,z.jsx)(je,{className:`${I?`w-4 h-4`:`w-5 h-5`} text-bambu-gray`})}),(0,z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,z.jsx)(`p`,{className:`${I?`text-xs`:`text-sm`} text-white font-medium truncate`,children:d(`modelViewer.allPlates`)}),(0,z.jsx)(`p`,{className:`${I?`text-[10px]`:`text-xs`} text-bambu-gray truncate`,children:d(`modelViewer.plateCount`,{count:F.length})})]}),A==null&&(0,z.jsx)(h,{className:`${I?`w-3.5 h-3.5`:`w-4 h-4`} text-bambu-green flex-shrink-0`})]}),Oe.map(e=>(0,z.jsxs)(`button`,{type:`button`,onClick:()=>ee(e.index),className:`flex items-center rounded-lg border text-left transition-colors ${I?`gap-1.5 p-1.5 w-full`:`gap-2 p-2`} ${A===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,z.jsx)(`img`,{src:s(e.thumbnail_url),alt:`Plate ${e.index}`,className:`${I?`w-8 h-8`:`w-10 h-10`} rounded object-cover bg-bambu-dark-tertiary`}):(0,z.jsx)(`div`,{className:`rounded bg-bambu-dark-tertiary flex items-center justify-center ${I?`w-8 h-8`:`w-10 h-10`}`,children:(0,z.jsx)(je,{className:`${I?`w-4 h-4`:`w-5 h-5`} text-bambu-gray`})}),(0,z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,z.jsx)(`p`,{className:`${I?`text-xs`:`text-sm`} text-white font-medium truncate`,children:e.name||d(`modelViewer.plateNumber`,{number:e.index})}),(0,z.jsx)(`p`,{className:`${I?`text-[10px]`:`text-xs`} text-bambu-gray truncate`,children:d(`modelViewer.objectCount`,{count:e.object_count??e.objects?.length??0})})]}),A===e.index&&(0,z.jsx)(h,{className:`${I?`w-3.5 h-3.5`:`w-4 h-4`} text-bambu-green flex-shrink-0`})]},e.index))]})}),(L||Ee)&&(0,z.jsxs)(`div`,{className:`mt-auto pt-3 flex items-center gap-4 text-xs text-bambu-gray overflow-x-auto`,children:[L&&(0,z.jsxs)(`div`,{className:`flex items-center gap-3 whitespace-nowrap`,children:[(0,z.jsx)(`span`,{children:d(`modelViewer.plateNumber`,{number:L.index})}),L.print_time_seconds!=null&&(0,z.jsx)(`span`,{children:d(`modelViewer.eta`,{minutes:Math.round(L.print_time_seconds/60)})}),L.filament_used_grams!=null&&(0,z.jsxs)(`span`,{children:[L.filament_used_grams.toFixed(1),` g`]}),L.filaments.length>0&&(0,z.jsx)(`span`,{children:d(`modelViewer.filamentCount`,{count:L.filaments.length})})]}),Ee&&(0,z.jsxs)(`div`,{className:`flex items-center gap-2 whitespace-nowrap ${L?`ml-auto`:``}`,children:[(0,z.jsx)(`span`,{children:d(`modelViewer.pagination.pageOf`,{current:M+1,total:De})}),(0,z.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,z.jsx)(`button`,{type:`button`,onClick:()=>te(e=>Math.max(e-1,0)),disabled:M===0,className:`px-2 py-1 rounded border text-xs ${M===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:d(`modelViewer.pagination.prev`)}),(()=>{let e=Math.max(0,M-2),t=Math.min(De,e+5);t-e<5&&(e=Math.max(0,t-5));let n=Array.from({length:t-e},(t,n)=>e+n);return(0,z.jsxs)(z.Fragment,{children:[e>0&&(0,z.jsx)(`button`,{type:`button`,onClick:()=>te(0),className:`px-2 py-1 rounded border text-xs ${M===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,z.jsx)(`span`,{className:`px-1`,children:`…`}),n.map(e=>(0,z.jsx)(`button`,{type:`button`,onClick:()=>te(e),className:`px-2 py-1 rounded border text-xs ${M===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)),tte(De-1),className:`px-2 py-1 rounded border text-xs ${M===De-1?`border-bambu-green text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:text-white hover:border-bambu-gray`}`,children:De})]})})(),(0,z.jsx)(`button`,{type:`button`,onClick:()=>te(e=>Math.min(e+1,De-1)),disabled:M>=De-1,className:`px-2 py-1 rounded border text-xs ${M>=De-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:d(`modelViewer.pagination.next`)})]})]})]})]})]}),I&&(0,z.jsx)(`div`,{role:`separator`,"aria-orientation":`horizontal`,onMouseDown:e=>{e.preventDefault(),ie(!0),oe(!0)},className:`h-2 cursor-row-resize flex items-center justify-center ${re?`bg-bambu-dark-tertiary`:`bg-bambu-dark-secondary/60 hover:bg-bambu-dark-tertiary`}`,children:(0,z.jsx)(`div`,{className:`w-12 h-1 rounded-full bg-bambu-gray/50`})}),(0,z.jsx)(`div`,{className:`flex-1 ${I?`min-h-0`:``}`,"data-testid":`model-viewer-area`,onDoubleClick:de,children:(0,z.jsx)(Ye,{url:_?a.getLibraryFileDownloadUrl(t):S.has_source?a.getSource3mfDownloadUrl(e):a.getArchiveDownload(e),fileType:r,buildVolume:S.build_volume,filamentColors:S.filament_colors,selectedPlateId:A,className:`w-full h-full`,onSnapshot:u})})]}):(0,z.jsx)(`div`,{className:`w-full h-full flex items-center justify-center text-bambu-gray`,children:d(`modelViewer.noPreview`)})})]})}var ut=100;function dt(e){let t=e.lastIndexOf(`.`);return t>0?e.slice(0,t):e}function ft({files:e,folderId:t,canSlice:n,onClose:r,onCombined:i}){let{t:s}=o(),l=c(),{showToast:d}=v(),[f,p]=(0,R.useState)(()=>Object.fromEntries(e.map(e=>[e.id,1]))),[m,h]=(0,R.useState)(null),[g,_]=(0,R.useState)(n),y=e.reduce((e,t)=>e+(f[t.id]||0),0),b=(0,R.useMemo)(()=>e.length===1?`${dt(e[0].filename)} x${f[e[0].id]||1}`:s(`fileManager.combine.defaultName`,{name:dt(e[0]?.filename??``),count:e.length-1}),[e,f,s]),x=(m??b).trim(),S=u({mutationFn:()=>a.combineLibraryFiles(e.map(e=>({file_id:e.id,copies:f[e.id]||1})),x,t),onSuccess:e=>{l.invalidateQueries({queryKey:[`library-files`]}),l.invalidateQueries({queryKey:[`library-stats`]}),d(s(`fileManager.combine.done`,{filename:e.filename,count:y}),`success`),i(e,g&&n)},onError:e=>d(e.message,`error`)});(0,R.useEffect)(()=>{let e=e=>{e.key===`Escape`&&!S.isPending&&r()};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[r,S.isPending]);let C=y>ut,w=e.some(e=>!f[e.id]||f[e.id]<1),T=`combine-files-title`;return(0,z.jsxs)(`div`,{className:`fixed inset-0 z-[60] flex items-center justify-center`,children:[(0,z.jsx)(`div`,{className:`absolute inset-0 bg-black/60`,onClick:()=>!S.isPending&&r()}),(0,z.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":T,children:[(0,z.jsxs)(`div`,{className:`flex items-center justify-between gap-4 px-5 py-4 border-b border-bambu-dark-tertiary`,children:[(0,z.jsxs)(`h3`,{id:T,className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,z.jsx)(nt,{className:`w-4 h-4 text-bambu-green`}),s(`fileManager.combine.title`)]}),(0,z.jsx)(`button`,{type:`button`,className:`p-1.5 text-bambu-gray hover:text-white rounded`,onClick:r,"aria-label":s(`common.close`),children:(0,z.jsx)(ae,{className:`w-5 h-5`})})]}),(0,z.jsx)(`p`,{className:`px-5 pt-3 text-sm text-bambu-gray`,children:s(`fileManager.combine.description`)}),(0,z.jsxs)(`div`,{className:`px-5 py-3`,children:[(0,z.jsx)(`label`,{htmlFor:`combine-name`,className:`block text-xs text-bambu-gray mb-1`,children:s(`fileManager.combine.nameLabel`)}),(0,z.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,z.jsx)(`input`,{id:`combine-name`,type:`text`,value:m??b,onChange:e=>h(e.target.value),maxLength:200,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`}),(0,z.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:`.3mf`})]})]}),(0,z.jsxs)(`div`,{className:`overflow-y-auto flex-1 max-h-[20rem] border-y border-bambu-dark-tertiary`,children:[(0,z.jsxs)(`div`,{className:`flex justify-between px-5 py-2 text-xs text-bambu-gray`,children:[(0,z.jsx)(`span`,{children:s(`fileManager.combine.model`)}),(0,z.jsx)(`span`,{children:s(`fileManager.combine.copies`)})]}),(0,z.jsx)(`ul`,{className:`divide-y divide-bambu-dark-tertiary/40`,children:e.map(e=>(0,z.jsxs)(`li`,{className:`flex items-center gap-3 px-5 py-2`,children:[(0,z.jsx)(`span`,{className:`text-sm text-white truncate flex-1`,title:e.filename,children:e.filename}),(0,z.jsx)(`input`,{type:`number`,min:1,max:ut,value:f[e.id]||``,onChange:t=>{let n=parseInt(t.target.value,10);p(t=>({...t,[e.id]:Number.isNaN(n)?0:n}))},"aria-label":s(`fileManager.combine.copiesFor`,{filename:e.filename}),className:`w-20 px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-sm text-white text-right focus:outline-none focus:border-bambu-green`})]},e.id))})]}),(0,z.jsxs)(`div`,{className:`px-5 py-3 space-y-2 text-sm`,children:[(0,z.jsx)(`div`,{className:C?`text-red-400`:`text-bambu-gray`,children:C?s(`fileManager.combine.tooMany`,{max:ut}):s(`fileManager.combine.total`,{count:y})}),n&&(0,z.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,z.jsx)(`input`,{type:`checkbox`,checked:g,onChange:e=>_(e.target.checked),className:`accent-bambu-green`}),(0,z.jsx)(`span`,{className:`text-white`,children:s(`fileManager.combine.sliceNext`)})]})]}),(0,z.jsxs)(`div`,{className:`px-5 py-4 border-t border-bambu-dark-tertiary flex justify-end gap-2`,children:[(0,z.jsx)(P,{type:`button`,variant:`secondary`,onClick:r,disabled:S.isPending,children:s(`common.cancel`)}),(0,z.jsxs)(P,{type:`button`,onClick:()=>S.mutate(),disabled:S.isPending||C||w||!x,children:[S.isPending&&(0,z.jsx)(j,{className:`w-4 h-4 animate-spin`}),s(`fileManager.combine.submit`)]})]})]})]})}var pt=[`library-tags`];function mt({open:e,fileIds:t,onClose:n}){let{t:r}=o(),i=c(),{showToast:s}=v(),[d,f]=(0,R.useState)(`add`),[p,m]=(0,R.useState)(new Set),[h,g]=(0,R.useState)(``),[_,y]=(0,R.useState)(``);(0,R.useEffect)(()=>{e||(f(`add`),m(new Set),g(``),y(``))},[e]);let{data:b=[],isLoading:x}=l({queryKey:pt,queryFn:a.getLibraryTags,enabled:e}),S=(0,R.useMemo)(()=>{let e=h.trim().toLowerCase();return e?b.filter(t=>t.name.toLowerCase().includes(e)):b},[b,h]),C=e=>{m(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},w=u({mutationFn:e=>a.createLibraryTag(e),onSuccess:e=>{m(t=>new Set(t).add(e.id)),y(``),i.invalidateQueries({queryKey:pt})},onError:e=>{s(e.message||r(`fileManager.tags.saveFailed`),`error`)}}),T=u({mutationFn:()=>a.bulkAssignLibraryTags(t,Array.from(p),d),onSuccess:e=>{s(d===`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:pt}),n()},onError:e=>{s(e.message||r(`fileManager.tags.applyFailed`),`error`)}});if((0,R.useEffect)(()=>{if(!e)return;let t=e=>{e.key===`Escape`&&!T.isPending&&!w.isPending&&n()};return document.addEventListener(`keydown`,t),()=>document.removeEventListener(`keydown`,t)},[e,n,T.isPending,w.isPending]),!e)return null;let E=!_.trim()||w.isPending||b.some(e=>e.name.toLowerCase()===_.trim().toLowerCase()),D=`bulk-tags-picker-title`;return(0,z.jsxs)(`div`,{className:`fixed inset-0 z-[60] flex items-center justify-center`,children:[(0,z.jsx)(`div`,{className:`absolute inset-0 bg-black/60`,onClick:()=>!T.isPending&&n()}),(0,z.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":D,children:[(0,z.jsxs)(`div`,{className:`flex items-center justify-between gap-4 px-5 py-4 border-b border-bambu-dark-tertiary`,children:[(0,z.jsxs)(`h3`,{id:D,className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,z.jsx)(xe,{className:`w-4 h-4 text-bambu-green`}),r(`fileManager.tags.bulkTitle`,{count:t.length})]}),(0,z.jsx)(`button`,{type:`button`,className:`p-1.5 text-bambu-gray hover:text-white rounded`,onClick:n,"aria-label":r(`common.close`),children:(0,z.jsx)(ae,{className:`w-5 h-5`})})]}),(0,z.jsxs)(`div`,{className:`px-5 py-3 border-b border-bambu-dark-tertiary flex gap-4 text-sm`,children:[(0,z.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,z.jsx)(`input`,{type:`radio`,name:`bulk-action`,checked:d===`add`,onChange:()=>f(`add`),className:`accent-bambu-green`}),(0,z.jsx)(`span`,{className:`text-white`,children:r(`fileManager.tags.actionAdd`)})]}),(0,z.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,z.jsx)(`input`,{type:`radio`,name:`bulk-action`,checked:d===`remove`,onChange:()=>f(`remove`),className:`accent-bambu-green`}),(0,z.jsx)(`span`,{className:`text-white`,children:r(`fileManager.tags.actionRemove`)})]})]}),(0,z.jsx)(`div`,{className:`px-5 py-3 border-b border-bambu-dark-tertiary`,children:(0,z.jsx)(`input`,{type:`text`,value:h,onChange:e=>g(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,z.jsx)(`div`,{className:`overflow-y-auto flex-1 min-h-[8rem] max-h-[24rem]`,children:x?(0,z.jsxs)(`div`,{className:`flex items-center justify-center py-12 text-bambu-gray`,children:[(0,z.jsx)(j,{className:`w-5 h-5 animate-spin mr-2`}),r(`common.loading`)]}):S.length===0?(0,z.jsx)(`div`,{className:`py-12 text-center text-bambu-gray text-sm`,children:b.length===0?r(`fileManager.tags.empty`):r(`fileManager.tags.noMatches`)}):(0,z.jsx)(`ul`,{className:`divide-y divide-bambu-dark-tertiary/40`,children:S.map(e=>(0,z.jsx)(`li`,{children:(0,z.jsxs)(`label`,{className:`flex items-center gap-3 px-5 py-2 hover:bg-bambu-dark-tertiary/30 cursor-pointer`,children:[(0,z.jsx)(`input`,{type:`checkbox`,checked:p.has(e.id),onChange:()=>C(e.id),className:`accent-bambu-green`}),(0,z.jsx)(`span`,{className:`text-sm text-white truncate flex-1`,children:e.name}),(0,z.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:e.file_count})]})},e.id))})}),d===`add`&&(0,z.jsxs)(`div`,{className:`px-5 py-3 border-t border-bambu-dark-tertiary flex gap-2`,children:[(0,z.jsx)(`input`,{type:`text`,value:_,onChange:e=>y(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`&&!E&&(e.preventDefault(),w.mutate(_.trim()))}}),(0,z.jsxs)(P,{type:`button`,variant:`secondary`,onClick:()=>w.mutate(_.trim()),disabled:E,children:[w.isPending?(0,z.jsx)(j,{className:`w-4 h-4 animate-spin`}):(0,z.jsx)(Oe,{className:`w-4 h-4`}),r(`fileManager.tags.createButton`)]})]}),(0,z.jsxs)(`div`,{className:`px-5 py-4 border-t border-bambu-dark-tertiary flex justify-end gap-2`,children:[(0,z.jsx)(P,{type:`button`,variant:`secondary`,onClick:n,disabled:T.isPending,children:r(`common.cancel`)}),(0,z.jsxs)(P,{type:`button`,onClick:()=>T.mutate(),disabled:p.size===0||T.isPending||t.length===0,children:[T.isPending&&(0,z.jsx)(j,{className:`w-4 h-4 animate-spin`}),r(d===`add`?`fileManager.tags.applyAdd`:`fileManager.tags.applyRemove`)]})]})]})]})}function ht(e,t){let n=t||{};return(e[e.length-1]===``?[...e,``]:e).join((n.padRight?` `:``)+`,`+(n.padLeft===!1?``:` `)).trim()}var gt=/^[$_\p{ID_Start}][$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,_t=/^[$_\p{ID_Start}][-$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,vt={};function yt(e,t){return((t||vt).jsx?_t:gt).test(e)}var bt=/[ \t\n\f\r]/g;function xt(e){return typeof e==`object`?e.type===`text`?St(e.value):!1:St(e)}function St(e){return e.replace(bt,``)===``}var Ct=class{constructor(e,t,n){this.normal=t,this.property=e,n&&(this.space=n)}};Ct.prototype.normal={},Ct.prototype.property={},Ct.prototype.space=void 0;function wt(e,t){let n={},r={};for(let t of e)Object.assign(n,t.property),Object.assign(r,t.normal);return new Ct(n,r,t)}function Tt(e){return e.toLowerCase()}var B=class{constructor(e,t){this.attribute=t,this.property=e}};B.prototype.attribute=``,B.prototype.booleanish=!1,B.prototype.boolean=!1,B.prototype.commaOrSpaceSeparated=!1,B.prototype.commaSeparated=!1,B.prototype.defined=!1,B.prototype.mustUseProperty=!1,B.prototype.number=!1,B.prototype.overloadedBoolean=!1,B.prototype.property=``,B.prototype.spaceSeparated=!1,B.prototype.space=void 0;var Et=t({boolean:()=>V,booleanish:()=>H,commaOrSpaceSeparated:()=>G,commaSeparated:()=>kt,number:()=>U,overloadedBoolean:()=>Ot,spaceSeparated:()=>W}),Dt=0,V=At(),H=At(),Ot=At(),U=At(),W=At(),kt=At(),G=At();function At(){return 2**++Dt}var jt=Object.keys(Et),K=class extends B{constructor(e,t,n,r){let i=-1;if(super(e,t),Mt(this,`space`,r),typeof n==`number`)for(;++i4&&n.slice(0,4)===`data`&&Gt.test(t)){if(t.charAt(4)===`-`){let e=t.slice(5).replace(Wt,Jt);r=`data`+e.charAt(0).toUpperCase()+e.slice(1)}else{let e=t.slice(4);if(!Wt.test(e)){let n=e.replace(Ut,qt);n.charAt(0)!==`-`&&(n=`-`+n),t=`data`+n}}i=K}return new i(r,t)}function qt(e){return`-`+e.toLowerCase()}function Jt(e){return e.charAt(1).toUpperCase()}var Yt=wt([Pt,Lt,zt,Bt,Vt],`html`),Xt=wt([Pt,Rt,zt,Bt,Vt],`svg`);function Zt(e){return e.join(` `).trim()}var Qt=n(((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})),$t=n((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(Qt());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}})),en=n((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))}})),tn=n(((e,t)=>{var n=(e&&e.__importDefault||function(e){return e&&e.__esModule?e:{default:e}})($t()),r=en();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})),nn=an(`end`),rn=an(`start`);function an(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 on(e){let t=rn(e),n=nn(e);if(t&&n)return{start:t,end:n}}function sn(e){return!e||typeof e!=`object`?``:`position`in e||`type`in e?ln(e.position):`start`in e||`end`in e?ln(e):`line`in e||`column`in e?cn(e):``}function cn(e){return un(e&&e.line)+`:`+un(e&&e.column)}function ln(e){return cn(e&&e.start)+`-`+cn(e&&e.end)}function un(e){return e&&typeof e==`number`?e:1}var q=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=sn(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}};q.prototype.file=``,q.prototype.name=``,q.prototype.reason=``,q.prototype.message=``,q.prototype.stack=``,q.prototype.column=void 0,q.prototype.line=void 0,q.prototype.ancestors=void 0,q.prototype.cause=void 0,q.prototype.fatal=void 0,q.prototype.place=void 0,q.prototype.ruleId=void 0,q.prototype.source=void 0;var dn=e(tn(),1),fn={}.hasOwnProperty,pn=new Map,mn=/[A-Z]/g,hn=new Set([`table`,`tbody`,`thead`,`tfoot`,`tr`]),gn=new Set([`td`,`th`]);function _n(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=Dn(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=En(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`?Xt:Yt,stylePropertyNameCase:t.stylePropertyNameCase||`dom`,tableCellAlignToStyle:t.tableCellAlignToStyle!==!1},a=vn(i,e,void 0);return a&&typeof a!=`string`?a:i.create(e,i.Fragment,{children:a||void 0},void 0)}function vn(e,t,n){if(t.type===`element`)return yn(e,t,n);if(t.type===`mdxFlowExpression`||t.type===`mdxTextExpression`)return bn(e,t);if(t.type===`mdxJsxFlowElement`||t.type===`mdxJsxTextElement`)return Sn(e,t,n);if(t.type===`mdxjsEsm`)return xn(e,t);if(t.type===`root`)return Cn(e,t,n);if(t.type===`text`)return J(e,t)}function yn(e,t,n){let r=e.schema,i=r;t.tagName.toLowerCase()===`svg`&&r.space===`html`&&(i=Xt,e.schema=i),e.ancestors.push(t);let a=Nn(e,t.tagName,!1),o=On(e,t),s=An(e,t);return hn.has(t.tagName)&&(s=s.filter(function(e){return typeof e==`string`?!xt(e):!0})),wn(e,o,a,t),Tn(o,s),e.ancestors.pop(),e.schema=r,e.create(t,a,o,n)}function bn(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)}Pn(e,t.position)}function xn(e,t){if(t.data&&t.data.estree&&e.evaluater)return e.evaluater.evaluateProgram(t.data.estree);Pn(e,t.position)}function Sn(e,t,n){let r=e.schema,i=r;t.name===`svg`&&r.space===`html`&&(i=Xt,e.schema=i),e.ancestors.push(t);let a=t.name===null?e.Fragment:Nn(e,t.name,!0),o=kn(e,t),s=An(e,t);return wn(e,o,a,t),Tn(o,s),e.ancestors.pop(),e.schema=r,e.create(t,a,o,n)}function Cn(e,t,n){let r={};return Tn(r,An(e,t)),e.create(t,e.Fragment,r,n)}function J(e,t){return t.value}function wn(e,t,n,r){typeof n!=`string`&&n!==e.Fragment&&e.passNode&&(t.node=r)}function Tn(e,t){if(t.length>0){let n=t.length>1?t:t[0];n&&(e.children=n)}}function En(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 Dn(e,t){return n;function n(n,r,i,a){let o=Array.isArray(i.children),s=rn(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 On(e,t){let n={},r,i;for(i in t.properties)if(i!==`children`&&fn.call(t.properties,i)){let a=jn(e,i,t.properties[i]);if(a){let[i,o]=a;e.tableCellAlignToStyle&&i===`align`&&typeof o==`string`&&gn.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 kn(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 Pn(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 Pn(e,t.position);else a=r.value===null?!0:r.value;n[i]=a}return n}function An(e,t){let n=[],r=-1,i=e.passKeys?new Map:pn;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?(Y(e,e.length,0,t),e):t}var qn={}.hasOwnProperty;function Jn(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 Qn(e){return e.replace(/[\t\n\r ]+/g,` `).replace(/^ | $/g,``).toLowerCase().toUpperCase()}var $n=cr(/[A-Za-z]/),er=cr(/[\dA-Za-z]/),tr=cr(/[#-'*+\--9=?A-Z^-~]/);function nr(e){return e!==null&&(e<32||e===127)}var rr=cr(/\d/),ir=cr(/[\dA-Fa-f]/),ar=cr(/[!-/:-@[-`{-~]/);function X(e){return e!==null&&e<-2}function Z(e){return e!==null&&(e<0||e===32)}function Q(e){return e===-2||e===-1||e===32}var or=cr(/\p{P}|\p{S}/u),sr=cr(/\s/);function cr(e){return t;function t(t){return t!==null&&t>-1&&e.test(String.fromCharCode(t))}}function lr(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 $(e,t,n,r){let i=r?r-1:1/0,a=0;return o;function o(r){return Q(r)?(e.enter(n),s(r)):t(r)}function s(r){return Q(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 hr(e,t,n){return $(e,e.attempt(this.parser.constructs.document,t,n),`linePrefix`,this.parser.constructs.disable.null.includes(`codeIndented`)?void 0:4)}function gr(e){if(e===null||Z(e)||sr(e))return 1;if(or(e))return 2}function _r(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};xr(d,-c),xr(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=Kn(l,[[`enter`,e[r][1],t],[`exit`,e[r][1],t]])),l=Kn(l,[[`enter`,i,t],[`enter`,o,t],[`exit`,o,t],[`enter`,a,t]]),l=Kn(l,_r(t.parser.constructs.insideSpan.null,e.slice(r+1,n),t)),l=Kn(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=Kn(l,[[`enter`,e[n][1],t],[`exit`,e[n][1],t]])):u=0,Y(e,r-1,n-r+3,l),n=r+l.length-u-2;break}}for(n=-1;++n0&&Q(t)?$(e,v,`linePrefix`,a+1)(t):v(t)}function v(t){return t===null||X(t)?e.check(Pr,h,b)(t):(e.enter(`codeFlowValue`),y(t))}function y(t){return t===null||X(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`),Q(t)?$(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`),Q(t)?$(e,d,`whitespace`)(t):d(t)):n(t)}function d(r){return r===null||X(r)?(e.exit(`codeFencedFence`),t(r)):n(r)}}}function Lr(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 Rr={name:`codeIndented`,tokenize:Br},zr={partial:!0,tokenize:Vr};function Br(e,t,n){let r=this;return i;function i(t){return e.enter(`codeIndented`),$(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):X(t)?e.attempt(zr,o,c)(t):(e.enter(`codeFlowValue`),s(t))}function s(t){return t===null||X(t)?(e.exit(`codeFlowValue`),o(t)):(e.consume(t),s)}function c(n){return e.exit(`codeIndented`),t(n)}}function Vr(e,t,n){let r=this;return i;function i(t){return r.parser.lazy[r.now().line]?n(t):X(t)?(e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),i):$(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):X(e)?i(e):n(e)}}var Hr={name:`codeText`,previous:Wr,resolve:Ur,tokenize:Gr};function Ur(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&&qr(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),qr(this.left,e)}unshift(e){this.setCursor(0),this.right.push(e)}unshiftMany(e){this.setCursor(0),qr(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 ti(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||nr(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||X(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||Z(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):X(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||X(t)||s++>999?(e.exit(`chunkString`),u(t)):(e.consume(t),c||=!Q(t),t===92?f:d)}function f(t){return t===91||t===92||t===93?(e.consume(t),s++,d):d(t)}}function ri(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):X(t)?(e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),$(e,l,`linePrefix`)):(e.enter(`chunkString`,{contentType:`string`}),u(t))}function u(t){return t===o||t===null||X(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 ii(e,t){let n;return r;function r(i){return X(i)?(e.enter(`lineEnding`),e.consume(i),e.exit(`lineEnding`),n=!0,r):Q(i)?$(e,r,n?`linePrefix`:`lineSuffix`)(i):t(i)}}var ai={name:`definition`,tokenize:si},oi={partial:!0,tokenize:ci};function si(e,t,n){let r=this,i;return a;function a(t){return e.enter(`definition`),o(t)}function o(t){return ni.call(r,e,s,n,`definitionLabel`,`definitionLabelMarker`,`definitionLabelString`)(t)}function s(t){return i=Qn(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 Z(t)?ii(e,l)(t):l(t)}function l(t){return ti(e,u,n,`definitionDestination`,`definitionDestinationLiteral`,`definitionDestinationLiteralMarker`,`definitionDestinationRaw`,`definitionDestinationString`)(t)}function u(t){return e.attempt(oi,d,d)(t)}function d(t){return Q(t)?$(e,f,`whitespace`)(t):f(t)}function f(a){return a===null||X(a)?(e.exit(`definition`),r.parser.defined.push(i),t(a)):n(a)}}function ci(e,t,n){return r;function r(t){return Z(t)?ii(e,i)(t):n(t)}function i(t){return ri(e,a,n,`definitionTitle`,`definitionTitleMarker`,`definitionTitleString`)(t)}function a(t){return Q(t)?$(e,o,`whitespace`)(t):o(t)}function o(e){return e===null||X(e)?t(e):n(e)}}var li={name:`hardBreakEscape`,tokenize:ui};function ui(e,t,n){return r;function r(t){return e.enter(`hardBreakEscape`),e.consume(t),i}function i(r){return X(r)?(e.exit(`hardBreakEscape`),t(r)):n(r)}}var di={name:`headingAtx`,resolve:fi,tokenize:pi};function fi(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`},Y(e,r,n-r+1,[[`enter`,i,t],[`enter`,a,t],[`exit`,a,t],[`exit`,i,t]])),e}function pi(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||Z(t)?(e.exit(`atxHeadingSequence`),s(t)):n(t)}function s(n){return n===35?(e.enter(`atxHeadingSequence`),c(n)):n===null||X(n)?(e.exit(`atxHeading`),t(n)):Q(n)?$(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||Z(t)?(e.exit(`atxHeadingText`),s(t)):(e.consume(t),l)}}var mi=`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(`.`),hi=[`pre`,`script`,`style`,`textarea`],gi={concrete:!0,name:`htmlFlow`,resolveTo:yi,tokenize:bi},_i={partial:!0,tokenize:Si},vi={partial:!0,tokenize:xi};function yi(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 bi(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:ne):$n(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):$n(a)?(e.consume(a),i=4,r.interrupt?t:ne):n(a)}function p(i){return i===45?(e.consume(i),r.interrupt?t:ne):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 $n(t)?(e.consume(t),o=String.fromCharCode(t),g):n(t)}function g(s){if(s===null||s===47||s===62||Z(s)){let c=s===47,l=o.toLowerCase();return!c&&!a&&hi.includes(l)?(i=1,r.interrupt?t(s):O(s)):mi.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||er(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 Q(t)?(e.consume(t),v):E(t)}function y(t){return t===47?(e.consume(t),E):t===58||t===95||$n(t)?(e.consume(t),b):Q(t)?(e.consume(t),y):E(t)}function b(t){return t===45||t===46||t===58||t===95||er(t)?(e.consume(t),b):x(t)}function x(t){return t===61?(e.consume(t),S):Q(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):Q(t)?(e.consume(t),S):w(t)}function C(t){return t===c?(e.consume(t),c=null,T):t===null||X(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||Z(t)?x(t):(e.consume(t),w)}function T(e){return e===47||e===62||Q(e)?y(e):n(e)}function E(t){return t===62?(e.consume(t),D):n(t)}function D(t){return t===null||X(t)?O(t):Q(t)?(e.consume(t),D):n(t)}function O(t){return t===45&&i===2?(e.consume(t),j):t===60&&i===1?(e.consume(t),M):t===62&&i===4?(e.consume(t),re):t===63&&i===3?(e.consume(t),ne):t===93&&i===5?(e.consume(t),N):X(t)&&(i===6||i===7)?(e.exit(`htmlFlowData`),e.check(_i,ie,k)(t)):t===null||X(t)?(e.exit(`htmlFlowData`),k(t)):(e.consume(t),O)}function k(t){return e.check(vi,A,ie)(t)}function A(t){return e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),ee}function ee(t){return t===null||X(t)?k(t):(e.enter(`htmlFlowData`),O(t))}function j(t){return t===45?(e.consume(t),ne):O(t)}function M(t){return t===47?(e.consume(t),o=``,te):O(t)}function te(t){if(t===62){let n=o.toLowerCase();return hi.includes(n)?(e.consume(t),re):O(t)}return $n(t)&&o.length<8?(e.consume(t),o+=String.fromCharCode(t),te):O(t)}function N(t){return t===93?(e.consume(t),ne):O(t)}function ne(t){return t===62?(e.consume(t),re):t===45&&i===2?(e.consume(t),ne):O(t)}function re(t){return t===null||X(t)?(e.exit(`htmlFlowData`),ie(t)):(e.consume(t),re)}function ie(n){return e.exit(`htmlFlow`),t(n)}}function xi(e,t,n){let r=this;return i;function i(t){return X(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 Si(e,t,n){return r;function r(r){return e.enter(`lineEnding`),e.consume(r),e.exit(`lineEnding`),e.attempt(wr,t,n)}}var Ci={name:`htmlText`,tokenize:wi};function wi(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):$n(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):$n(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):X(t)?(o=d,M(t)):(e.consume(t),d)}function f(t){return t===45?(e.consume(t),p):d(t)}function p(e){return e===62?j(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):X(t)?(o=h,M(t)):(e.consume(t),h)}function g(t){return t===93?(e.consume(t),_):h(t)}function _(t){return t===62?j(t):t===93?(e.consume(t),_):h(t)}function v(t){return t===null||t===62?j(t):X(t)?(o=v,M(t)):(e.consume(t),v)}function y(t){return t===null?n(t):t===63?(e.consume(t),b):X(t)?(o=y,M(t)):(e.consume(t),y)}function b(e){return e===62?j(e):y(e)}function x(t){return $n(t)?(e.consume(t),S):n(t)}function S(t){return t===45||er(t)?(e.consume(t),S):C(t)}function C(t){return X(t)?(o=C,M(t)):Q(t)?(e.consume(t),C):j(t)}function w(t){return t===45||er(t)?(e.consume(t),w):t===47||t===62||Z(t)?T(t):n(t)}function T(t){return t===47?(e.consume(t),j):t===58||t===95||$n(t)?(e.consume(t),E):X(t)?(o=T,M(t)):Q(t)?(e.consume(t),T):j(t)}function E(t){return t===45||t===46||t===58||t===95||er(t)?(e.consume(t),E):D(t)}function D(t){return t===61?(e.consume(t),O):X(t)?(o=D,M(t)):Q(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):X(t)?(o=O,M(t)):Q(t)?(e.consume(t),O):(e.consume(t),A)}function k(t){return t===i?(e.consume(t),i=void 0,ee):t===null?n(t):X(t)?(o=k,M(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||Z(t)?T(t):(e.consume(t),A)}function ee(e){return e===47||e===62||Z(e)?T(e):n(e)}function j(r){return r===62?(e.consume(r),e.exit(`htmlTextData`),e.exit(`htmlText`),t):n(r)}function M(t){return e.exit(`htmlTextData`),e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),te}function te(t){return Q(t)?$(e,N,`linePrefix`,r.parser.constructs.disable.null.includes(`codeIndented`)?void 0:4)(t):N(t)}function N(t){return e.enter(`htmlTextData`),o(t)}}var Ti={name:`labelEnd`,resolveAll:ki,resolveTo:Ai,tokenize:ji},Ei={tokenize:Mi},Di={tokenize:Ni},Oi={tokenize:Pi};function ki(e){let t=-1,n=[];for(;++t=3&&(a===null||X(a))?(e.exit(`thematicBreak`),t(a)):n(a)}function c(t){return t===i?(e.consume(t),r++,c):(e.exit(`thematicBreakSequence`),Q(t)?$(e,s,`whitespace`)(t):s(t))}}var Ui={continuation:{tokenize:qi},exit:Yi,name:`list`,tokenize:Ki},Wi={partial:!0,tokenize:Xi},Gi={partial:!0,tokenize:Ji};function Ki(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:rr(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(Vi,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 rr(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(wr,r.interrupt?n:u,e.attempt(Wi,f,d))}function u(e){return r.containerState.initialBlankLine=!0,a++,f(e)}function d(t){return Q(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 qi(e,t,n){let r=this;return r.containerState._closeFlow=void 0,e.check(wr,i,a);function i(n){return r.containerState.furtherBlankLines=r.containerState.furtherBlankLines||r.containerState.initialBlankLine,$(e,t,`listItemIndent`,r.containerState.size+1)(n)}function a(n){return r.containerState.furtherBlankLines||!Q(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(Gi,t,o)(n))}function o(i){return r.containerState._closeFlow=!0,r.interrupt=void 0,$(e,e.attempt(Ui,t,n),`linePrefix`,r.parser.constructs.disable.null.includes(`codeIndented`)?void 0:4)(i)}}function Ji(e,t,n){let r=this;return $(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 Yi(e){e.exit(this.containerState.type)}function Xi(e,t,n){let r=this;return $(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!Q(e)&&i&&i[1].type===`listItemPrefixWhitespace`?t(e):n(e)}}var Zi={name:`setextUnderline`,resolveTo:Qi,tokenize:$i};function Qi(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 $i(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`),Q(t)?$(e,c,`lineSuffix`)(t):c(t))}function c(r){return r===null||X(r)?(e.exit(`setextHeadingLine`),t(r)):n(r)}}var ea={tokenize:ta};function ta(e){let t=this,n=e.attempt(wr,r,e.attempt(this.parser.constructs.flowInitial,i,$(e,e.attempt(this.parser.constructs.flow,i,e.attempt(Xr,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 na={resolveAll:oa()},ra=aa(`string`),ia=aa(`text`);function aa(e){return{resolveAll:oa(e===`text`?sa: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(;++iga,contentInitial:()=>ua,disable:()=>_a,document:()=>la,flow:()=>fa,flowInitial:()=>da,insideSpan:()=>ha,string:()=>pa,text:()=>ma}),la={42:Ui,43:Ui,45:Ui,48:Ui,49:Ui,50:Ui,51:Ui,52:Ui,53:Ui,54:Ui,55:Ui,56:Ui,57:Ui,62:Er},ua={91:ai},da={[-2]:Rr,[-1]:Rr,32:Rr},fa={35:di,42:Vi,45:[Zi,Vi],60:gi,61:Zi,95:Vi,96:Fr,126:Fr},pa={38:Mr,92:Ar},ma={[-5]:zi,[-4]:zi,[-3]:zi,33:Fi,38:Mr,42:vr,60:[Sr,Ci],91:Li,92:[li,Ar],93:Ti,95:vr,96:Hr},ha={null:[vr,na]},ga={null:[42,95]},_a={null:[]};function va(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=Kn(o,e),g(),o[o.length-1]===null?(w(t,0),l.events=_r(a,l.events,l),l.events):[]}function f(e,t){return ba(p(e),t)}function p(e){return ya(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 ba(e,t){let n=-1,r=[],i;for(;++n0){let e=a.tokenStack[a.tokenStack.length-1];(e[1]||Pa).call(a,void 0,e[0])}for(r.position={start:ja(e.length>0?e[0][1].start:{line:1,column:1,offset:0}),end:ja(e.length>0?e[e.length-2][1].end:{line:1,column:1,offset:0})},d=-1;++d0&&n.push({type:`text`,value:` `}),n}function Yo(e){let t=0,n=e.charCodeAt(t);for(;n===9||n===32;)t++,n=e.charCodeAt(t);return e.slice(t)}function Xo(e,t){let n=Wo(e,t),r=n.one(e,void 0),i=ko(n),a=Array.isArray(r)?{type:`root`,children:r}:r||{type:`root`,children:[]};return i&&(`children`in a,a.children.push({type:`text`,value:` -`},i)),a}function Zo(e,t){return e&&`run`in e?async function(n,r){let i=Xo(n,{file:r,...t});await e.run(i,r)}:function(n,r){return Xo(n,{file:r,...e||t})}}function Qo(e){if(e)throw e}var $o=n(((e,t)=>{var n=Object.prototype.hasOwnProperty,r=Object.prototype.toString,i=Object.defineProperty,a=Object.getOwnPropertyDescriptor,o=function(e){return typeof Array.isArray==`function`?Array.isArray(e):r.call(e)===`[object Array]`},s=function(e){if(!e||r.call(e)!==`[object Object]`)return!1;var t=n.call(e,`constructor`),i=e.constructor&&e.constructor.prototype&&n.call(e.constructor.prototype,`isPrototypeOf`);if(e.constructor&&!t&&!i)return!1;for(var a in e);return a===void 0||n.call(e,a)},c=function(e,t){i&&t.name===`__proto__`?i(e,t.name,{enumerable:!0,configurable:!0,value:t.newValue,writable:!0}):e[t.name]=t.newValue},l=function(e,t){if(t===`__proto__`){if(!n.call(e,t))return;if(a)return a(e,t).value}return e[t]};t.exports=function e(){var t,n,r,i,a,u,d=arguments[0],f=1,p=arguments.length,m=!1;for(typeof d==`boolean`&&(m=d,d=arguments[1]||{},f=2),(d==null||typeof d!=`object`&&typeof d!=`function`)&&(d={});ft.length,o;r&&t.push(i);try{o=e.apply(this,t)}catch(e){let t=e;if(r&&n)throw t;return i(t)}r||(o&&o.then&&typeof o.then==`function`?o.then(a,i):o instanceof Error?i(o):a(o))}function i(e,...r){n||(n=!0,t(e,...r))}function a(e){i(null,e)}}var rs={basename:is,dirname:as,extname:os,join:ss,sep:`/`};function is(e,t){if(t!==void 0&&typeof t!=`string`)throw TypeError(`"ext" argument must be a string`);us(e);let n=0,r=-1,i=e.length,a;if(t===void 0||t.length===0||t.length>e.length){for(;i--;)if(e.codePointAt(i)===47){if(a){n=i+1;break}}else r<0&&(a=!0,r=i+1);return r<0?``:e.slice(n,r)}if(t===e)return``;let o=-1,s=t.length-1;for(;i--;)if(e.codePointAt(i)===47){if(a){n=i+1;break}}else o<0&&(a=!0,o=i+1),s>-1&&(e.codePointAt(i)===t.codePointAt(s--)?s<0&&(r=i):(s=-1,r=o));return n===r?r=o:r<0&&(r=e.length),e.slice(n,r)}function as(e){if(us(e),e.length===0)return`.`;let t=-1,n=e.length,r;for(;--n;)if(e.codePointAt(n)===47){if(r){t=n;break}}else r||=!0;return t<0?e.codePointAt(0)===47?`/`:`.`:t===1&&e.codePointAt(0)===47?`//`:e.slice(0,t)}function os(e){us(e);let t=e.length,n=-1,r=0,i=-1,a=0,o;for(;t--;){let s=e.codePointAt(t);if(s===47){if(o){r=t+1;break}continue}n<0&&(o=!0,n=t+1),s===46?i<0?i=t:a!==1&&(a=1):i>-1&&(a=-1)}return i<0||n<0||a===0||a===1&&i===n-1&&i===r+1?``:e.slice(i,n)}function ss(...e){let t=-1,n;for(;++t0&&e.codePointAt(e.length-1)===47&&(n+=`/`),t?`/`+n:n}function ls(e,t){let n=``,r=0,i=-1,a=0,o=-1,s,c;for(;++o<=e.length;){if(o2){if(c=n.lastIndexOf(`/`),c!==n.length-1){c<0?(n=``,r=0):(n=n.slice(0,c),r=n.length-1-n.lastIndexOf(`/`)),i=o,a=0;continue}}else if(n.length>0){n=``,r=0,i=o,a=0;continue}}t&&(n=n.length>0?n+`/..`:`..`,r=2)}else n.length>0?n+=`/`+e.slice(i+1,o):n=e.slice(i+1,o),r=o-i-1;i=o,a=0}else s===46&&a>-1?a++:a=-1}return n}function us(e){if(typeof e!=`string`)throw TypeError(`Path must be a string. Received `+JSON.stringify(e))}var ds={cwd:fs};function fs(){return`/`}function ps(e){return!!(typeof e==`object`&&e&&`href`in e&&e.href&&`protocol`in e&&e.protocol&&e.auth===void 0)}function ms(e){if(typeof e==`string`)e=new URL(e);else if(!ps(e)){let t=TypeError('The "path" argument must be of type string or an instance of URL. Received `'+e+"`");throw t.code=`ERR_INVALID_ARG_TYPE`,t}if(e.protocol!==`file:`){let e=TypeError(`The URL must be of scheme file`);throw e.code=`ERR_INVALID_URL_SCHEME`,e}return hs(e)}function hs(e){if(e.hostname!==``){let e=TypeError(`File URL host must be "localhost" or empty on darwin`);throw e.code=`ERR_INVALID_FILE_URL_HOST`,e}let t=e.pathname,n=-1;for(;++n0){let[r,...a]=t,o=n[i][1];es(o)&&es(r)&&(r=(0,Cs.default)(!0,o,r)),n[i]=[e,r,...a]}}}}().freeze();function Es(e,t){if(typeof t!=`function`)throw TypeError("Cannot `"+e+"` without `parser`")}function Ds(e,t){if(typeof t!=`function`)throw TypeError("Cannot `"+e+"` without `compiler`")}function Os(e,t){if(t)throw Error("Cannot call `"+e+"` on a frozen processor.\nCreate a new processor first, by calling it: use `processor()` instead of `processor`.")}function ks(e){if(!es(e)||typeof e.type!=`string`)throw TypeError("Expected node, got `"+e+"`")}function As(e,t,n){if(!n)throw Error("`"+e+"` finished async. Use `"+t+"` instead")}function js(e){return Ms(e)?e:new _s(e)}function Ms(e){return!!(e&&typeof e==`object`&&`message`in e&&`messages`in e)}function Ns(e){return typeof e==`string`||Ps(e)}function Ps(e){return!!(e&&typeof e==`object`&&`byteLength`in e&&`byteOffset`in e)}var Fs=[],Is={allowDangerousHtml:!0},Ls=/^(https?|ircs?|mailto|xmpp)$/i,Rs=[{from:`astPlugins`,id:`remove-buggy-html-in-markdown-parser`},{from:`allowDangerousHtml`,id:`remove-buggy-html-in-markdown-parser`},{from:`allowNode`,id:`replace-allownode-allowedtypes-and-disallowedtypes`,to:`allowElement`},{from:`allowedTypes`,id:`replace-allownode-allowedtypes-and-disallowedtypes`,to:`allowedElements`},{from:`disallowedTypes`,id:`replace-allownode-allowedtypes-and-disallowedtypes`,to:`disallowedElements`},{from:`escapeHtml`,id:`remove-buggy-html-in-markdown-parser`},{from:`includeElementIndex`,id:`#remove-includeelementindex`},{from:`includeNodeIndex`,id:`change-includenodeindex-to-includeelementindex`},{from:`linkTarget`,id:`remove-linktarget`},{from:`plugins`,id:`change-plugins-to-remarkplugins`,to:`remarkPlugins`},{from:`rawSourcePos`,id:`#remove-rawsourcepos`},{from:`renderers`,id:`change-renderers-to-components`,to:`components`},{from:`source`,id:`change-source-to-children`,to:`children`},{from:`sourcePos`,id:`#remove-sourcepos`},{from:`transformImageUri`,id:`#add-urltransform`,to:`urlTransform`},{from:`transformLinkUri`,id:`#add-urltransform`,to:`urlTransform`}];function zs(e){let t=Bs(e),n=Vs(e);return Hs(t.runSync(t.parse(n),n),e)}function Bs(e){let t=e.rehypePlugins||Fs,n=e.remarkPlugins||Fs,r=e.remarkRehypeOptions?{...e.remarkRehypeOptions,...Is}:Is;return Ts().use(Fa).use(n).use(Zo,r).use(t)}function Vs(e){let t=e.children||``,n=new _s;return typeof t==`string`?n.value=t:``+t,n}function Hs(e,t){let n=t.allowedElements,r=t.allowElement,i=t.components,a=t.disallowedElements,o=t.skipHtml,s=t.unwrapDisallowed,c=t.urlTransform||Us;for(let e of Rs)Object.hasOwn(t,e.from)&&``+e.from+(e.to?"use `"+e.to+"` instead":`remove it`)+e.id;return t.className&&(e={type:`element`,tagName:`div`,properties:{className:t.className},children:e.type===`root`?e.children:[e]}),Vo(e,l),_n(e,{Fragment:z.Fragment,components:i,ignoreInvalidStyle:!0,jsx:z.jsx,jsxs:z.jsxs,passKeys:!0,passNode:!0});function l(e,t,i){if(e.type===`raw`&&i&&typeof t==`number`)return o?i.children.splice(t,1):i.children[t]={type:`text`,value:e.value},t;if(e.type===`element`){let t;for(t in Rn)if(Object.hasOwn(Rn,t)&&Object.hasOwn(e.properties,t)){let n=e.properties[t],r=Rn[t];(r===null||r.includes(e.tagName))&&(e.properties[t]=c(String(n||``),t,e))}}if(e.type===`element`){let o=n?!n.includes(e.tagName):a?a.includes(e.tagName):!1;if(!o&&r&&typeof t==`number`&&(o=!r(e,t,i)),o&&i&&typeof t==`number`)return s&&e.children?i.children.splice(t,1,...e.children):i.children.splice(t,1),t}}}function Us(e){let t=e.indexOf(`:`),n=e.indexOf(`?`),r=e.indexOf(`#`),i=e.indexOf(`/`);return t===-1||i!==-1&&t>i||n!==-1&&t>n||r!==-1&&t>r||Ls.test(e.slice(0,t))?e:``}$s.peek=Qs;function Ws(){this.buffer()}function Gs(e){this.enter({type:`footnoteReference`,identifier:``,label:``},e)}function Ks(){this.buffer()}function qs(e){this.enter({type:`footnoteDefinition`,identifier:``,label:``,children:[]},e)}function Js(e){let t=this.resume(),n=this.stack[this.stack.length-1];n.type,n.identifier=Qn(this.sliceSerialize(e)).toLowerCase(),n.label=t}function Ys(e){this.exit(e)}function Xs(e){let t=this.resume(),n=this.stack[this.stack.length-1];n.type,n.identifier=Qn(this.sliceSerialize(e)).toLowerCase(),n.label=t}function Zs(e){this.exit(e)}function Qs(){return`[`}function $s(e,t,n,r){let i=n.createTracker(r),a=i.move(`[^`),o=n.enter(`footnoteReference`),s=n.enter(`reference`);return a+=i.move(n.safe(n.associationId(e),{after:`]`,before:a})),s(),o(),a+=i.move(`]`),a}function ec(){return{enter:{gfmFootnoteCallString:Ws,gfmFootnoteCall:Gs,gfmFootnoteDefinitionLabelString:Ks,gfmFootnoteDefinition:qs},exit:{gfmFootnoteCallString:Js,gfmFootnoteCall:Ys,gfmFootnoteDefinitionLabelString:Xs,gfmFootnoteDefinition:Zs}}}ic.peek=ac;function tc(){return{canContainEols:[`delete`],enter:{strikethrough:nc},exit:{strikethrough:rc}}}function nc(e){this.enter({type:`delete`,children:[]},e)}function rc(e){this.exit(e)}function ic(e,t,n,r){let i=n.createTracker(r),a=n.enter(`strikethrough`),o=i.move(`~~`);return o+=n.containerPhrasing(e,{...i.current(),before:o,after:`~`}),o+=i.move(`~~`),a(),o}function ac(){return`~`}function oc(){return{enter:{table:sc,tableData:dc,tableHeader:dc,tableRow:lc},exit:{codeText:fc,table:cc,tableData:uc,tableHeader:uc,tableRow:uc}}}function sc(e){let t=e._align;this.enter({type:`table`,align:t.map(function(e){return e===`none`?null:e}),children:[]},e),this.data.inTable=!0}function cc(e){this.exit(e),this.data.inTable=void 0}function lc(e){this.enter({type:`tableRow`,children:[]},e)}function uc(e){this.exit(e)}function dc(e){this.enter({type:`tableCell`,children:[]},e)}function fc(e){let t=this.resume();this.data.inTable&&(t=t.replace(/\\([\\|])/g,pc));let n=this.stack[this.stack.length-1];n.type,n.value=t,this.exit(e)}function pc(e,t){return t===`|`?t:e}function mc(){return{exit:{taskListCheckValueChecked:hc,taskListCheckValueUnchecked:hc,paragraph:gc}}}function hc(e){let t=this.stack[this.stack.length-2];t.type,t.checked=e.type===`taskListCheckValueChecked`}function gc(e){let t=this.stack[this.stack.length-2];if(t&&t.type===`listItem`&&typeof t.checked==`boolean`){let e=this.stack[this.stack.length-1];e.type;let n=e.children[0];if(n&&n.type===`text`){let r=t.children,i=-1,a;for(;++i999||s===93&&!o||s===null||s===91||Z(s))return n(s);if(s===93){e.exit(`chunkString`);let a=e.exit(`gfmFootnoteCallString`);return i.includes(Qn(r.sliceSerialize(a)))?(e.enter(`gfmFootnoteCallLabelMarker`),e.consume(s),e.exit(`gfmFootnoteCallLabelMarker`),e.exit(`gfmFootnoteCall`),t):n(s)}return Z(s)||(o=!0),a++,e.consume(s),s===92?u:l}function u(t){return t===91||t===92||t===93?(e.consume(t),a++,l):l(t)}}function Sc(e,t,n){let r=this,i=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]),a,o=0,s;return c;function c(t){return e.enter(`gfmFootnoteDefinition`)._container=!0,e.enter(`gfmFootnoteDefinitionLabel`),e.enter(`gfmFootnoteDefinitionLabelMarker`),e.consume(t),e.exit(`gfmFootnoteDefinitionLabelMarker`),l}function l(t){return t===94?(e.enter(`gfmFootnoteDefinitionMarker`),e.consume(t),e.exit(`gfmFootnoteDefinitionMarker`),e.enter(`gfmFootnoteDefinitionLabelString`),e.enter(`chunkString`).contentType=`string`,u):n(t)}function u(t){if(o>999||t===93&&!s||t===null||t===91||Z(t))return n(t);if(t===93){e.exit(`chunkString`);let n=e.exit(`gfmFootnoteDefinitionLabelString`);return a=Qn(r.sliceSerialize(n)),e.enter(`gfmFootnoteDefinitionLabelMarker`),e.consume(t),e.exit(`gfmFootnoteDefinitionLabelMarker`),e.exit(`gfmFootnoteDefinitionLabel`),f}return Z(t)||(s=!0),o++,e.consume(t),t===92?d:u}function d(t){return t===91||t===92||t===93?(e.consume(t),o++,u):u(t)}function f(t){return t===58?(e.enter(`definitionMarker`),e.consume(t),e.exit(`definitionMarker`),i.includes(a)||i.push(a),$(e,p,`gfmFootnoteDefinitionWhitespace`)):n(t)}function p(e){return t(e)}}function Cc(e,t,n){return e.check(wr,t,e.attempt(_c,t,n))}function wc(e){e.exit(`gfmFootnoteDefinition`)}function Tc(e,t,n){let r=this;return $(e,i,`gfmFootnoteDefinitionIndent`,5);function i(e){let i=r.events[r.events.length-1];return i&&i[1].type===`gfmFootnoteDefinitionIndent`&&i[2].sliceSerialize(i[1],!0).length===4?t(e):n(e)}}function Ec(e){let t=(e||{}).singleTilde,n={name:`strikethrough`,tokenize:i,resolveAll:r};return t??=!0,{text:{126:n},insideSpan:{null:[n]},attentionMarkers:{null:[126]}};function r(e,t){let n=-1;for(;++n1?r(a):(e.consume(a),o++,c);if(o<2&&!t)return r(a);let l=e.exit(`strikethroughSequenceTemporary`),u=gr(a);return l._open=!u||u===2&&!!s,l._close=!s||s===2&&!!u,n(a)}}}var Dc=class{constructor(){this.map=[]}add(e,t,n){Oc(this,e,t,n)}consume(e){if(this.map.sort(function(e,t){return e[0]-t[0]}),this.map.length===0)return;let t=this.map.length,n=[];for(;t>0;)--t,n.push(e.slice(this.map[t][0]+this.map[t][1]),this.map[t][2]),e.length=this.map[t][0];n.push(e.slice()),e.length=0;let r=n.pop();for(;r;){for(let t of r)e.push(t);r=n.pop()}this.map.length=0}};function Oc(e,t,n,r){let i=0;if(!(n===0&&r.length===0)){for(;i-1;){let e=r.events[t][1].type;if(e===`lineEnding`||e===`linePrefix`)t--;else break}let i=t>-1?r.events[t][1].type:null,a=i===`tableHead`||i===`tableRow`?S:c;return a===S&&r.parser.lazy[r.now().line]?n(e):a(e)}function c(t){return e.enter(`tableHead`),e.enter(`tableRow`),l(t)}function l(e){return e===124?u(e):(o=!0,a+=1,u(e))}function u(t){return t===null?n(t):X(t)?a>1?(a=0,r.interrupt=!0,e.exit(`tableRow`),e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),p):n(t):Q(t)?$(e,u,`whitespace`)(t):(a+=1,o&&(o=!1,i+=1),t===124?(e.enter(`tableCellDivider`),e.consume(t),e.exit(`tableCellDivider`),o=!0,u):(e.enter(`data`),d(t)))}function d(t){return t===null||t===124||Z(t)?(e.exit(`data`),u(t)):(e.consume(t),t===92?f:d)}function f(t){return t===92||t===124?(e.consume(t),d):d(t)}function p(t){return r.interrupt=!1,r.parser.lazy[r.now().line]?n(t):(e.enter(`tableDelimiterRow`),o=!1,Q(t)?$(e,m,`linePrefix`,r.parser.constructs.disable.null.includes(`codeIndented`)?void 0:4)(t):m(t))}function m(t){return t===45||t===58?g(t):t===124?(o=!0,e.enter(`tableCellDivider`),e.consume(t),e.exit(`tableCellDivider`),h):x(t)}function h(t){return Q(t)?$(e,g,`whitespace`)(t):g(t)}function g(t){return t===58?(a+=1,o=!0,e.enter(`tableDelimiterMarker`),e.consume(t),e.exit(`tableDelimiterMarker`),_):t===45?(a+=1,_(t)):t===null||X(t)?b(t):x(t)}function _(t){return t===45?(e.enter(`tableDelimiterFiller`),v(t)):x(t)}function v(t){return t===45?(e.consume(t),v):t===58?(o=!0,e.exit(`tableDelimiterFiller`),e.enter(`tableDelimiterMarker`),e.consume(t),e.exit(`tableDelimiterMarker`),y):(e.exit(`tableDelimiterFiller`),y(t))}function y(t){return Q(t)?$(e,b,`whitespace`)(t):b(t)}function b(n){return n===124?m(n):n===null||X(n)?!o||i!==a?x(n):(e.exit(`tableDelimiterRow`),e.exit(`tableHead`),t(n)):x(n)}function x(e){return n(e)}function S(t){return e.enter(`tableRow`),C(t)}function C(n){return n===124?(e.enter(`tableCellDivider`),e.consume(n),e.exit(`tableCellDivider`),C):n===null||X(n)?(e.exit(`tableRow`),t(n)):Q(n)?$(e,C,`whitespace`)(n):(e.enter(`data`),w(n))}function w(t){return t===null||t===124||Z(t)?(e.exit(`data`),C(t)):(e.consume(t),t===92?T:w)}function T(t){return t===92||t===124?(e.consume(t),w):w(t)}}function Mc(e,t){let n=-1,r=!0,i=0,a=[0,0,0,0],o=[0,0,0,0],s=!1,c=0,l,u,d,f=new Dc;for(;++nn[2]+1){let t=n[2]+1,r=n[3]-n[2]-1;e.add(t,r,[])}}e.add(n[3]+1,0,[[`exit`,o,t]])}return i!==void 0&&(a.end=Object.assign({},Fc(t.events,i)),e.add(i,0,[[`exit`,a,t]]),a=void 0),a}function Pc(e,t,n,r,i){let a=[],o=Fc(t.events,n);i&&(i.end=Object.assign({},o),a.push([`exit`,i,t])),r.end=Object.assign({},o),a.push([`exit`,r,t]),e.add(n+1,0,a)}function Fc(e,t){let n=e[t],r=n[0]===`enter`?`start`:`end`;return n[1][r]}var Ic={name:`tasklistCheck`,tokenize:Rc};function Lc(){return{text:{91:Ic}}}function Rc(e,t,n){let r=this;return i;function i(t){return r.previous!==null||!r._gfmTasklistFirstContentOfListItem?n(t):(e.enter(`taskListCheck`),e.enter(`taskListCheckMarker`),e.consume(t),e.exit(`taskListCheckMarker`),a)}function a(t){return Z(t)?(e.enter(`taskListCheckValueUnchecked`),e.consume(t),e.exit(`taskListCheckValueUnchecked`),o):t===88||t===120?(e.enter(`taskListCheckValueChecked`),e.consume(t),e.exit(`taskListCheckValueChecked`),o):n(t)}function o(t){return t===93?(e.enter(`taskListCheckMarker`),e.consume(t),e.exit(`taskListCheckMarker`),e.exit(`taskListCheck`),s):n(t)}function s(r){return X(r)?t(r):Q(r)?e.check({tokenize:zc},t,n)(r):n(r)}}function zc(e,t,n){return $(e,r,`whitespace`);function r(e){return e===null?n(e):t(e)}}function Bc(){let e=this.data(),t=e.micromarkExtensions||=[],n=e.fromMarkdownExtensions||=[];t.push(vc(),Ec(),Ac(),Lc()),n.push(ec(),tc(),oc(),mc())}var Vc=`fileManager.readmeCollapsed`;function Hc({folderId:e}){let{t}=o(),[n,r]=(0,R.useState)(()=>localStorage.getItem(Vc)===`1`);(0,R.useEffect)(()=>{localStorage.setItem(Vc,n?`1`:`0`)},[n]);let{data:i,isLoading:s,error:c}=l({queryKey:[`folder-readme`,e],queryFn:()=>a.getLibraryFolderReadme(e),retry:!1,staleTime:3e4});return s||c||!i?null:n?(0,z.jsxs)(`div`,{className:`mb-2 lg:mb-0 order-first lg:order-none lg:w-10 lg:flex-shrink-0 lg:h-full`,children:[(0,z.jsxs)(`button`,{type:`button`,onClick:()=>r(!1),title:t(`fileManager.readme.show`),"aria-label":t(`fileManager.readme.show`),className:`flex lg:hidden w-full items-center gap-2 px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg hover:bg-bambu-dark/40 transition-colors`,children:[(0,z.jsx)(Re,{className:`w-4 h-4 text-bambu-green flex-shrink-0`}),(0,z.jsx)(`span`,{className:`text-sm font-medium text-white truncate`,children:i.filename}),(0,z.jsx)(st,{className:`w-4 h-4 text-bambu-gray flex-shrink-0 ml-auto`})]}),(0,z.jsxs)(`button`,{type:`button`,onClick:()=>r(!1),title:t(`fileManager.readme.show`),"aria-label":t(`fileManager.readme.show`),className:`hidden lg:flex h-full w-10 flex-col items-center gap-2 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg hover:bg-bambu-dark/40 transition-colors`,children:[(0,z.jsx)(st,{className:`w-4 h-4 text-bambu-green flex-shrink-0`}),(0,z.jsx)(`span`,{className:`text-xs font-medium text-bambu-gray [writing-mode:vertical-rl] rotate-180 select-none`,children:t(`fileManager.readme.label`)})]})]}):(0,z.jsxs)(`div`,{className:`mb-4 lg:mb-0 order-first lg:order-none lg:w-80 xl:w-96 lg:flex-shrink-0 lg:h-full flex flex-col bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg overflow-hidden`,children:[(0,z.jsxs)(`div`,{className:`flex items-center justify-between gap-2 px-3 py-2`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,z.jsx)(Re,{className:`w-4 h-4 text-bambu-green flex-shrink-0`}),(0,z.jsx)(`span`,{className:`text-sm font-medium text-white truncate`,title:i.filename,children:i.filename}),i.truncated&&(0,z.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400 flex-shrink-0`,children:t(`fileManager.readme.truncated`)})]}),(0,z.jsx)(`button`,{type:`button`,onClick:()=>r(!0),title:t(`fileManager.readme.hide`),"aria-label":t(`fileManager.readme.hide`),className:`p-1 rounded text-bambu-gray hover:text-white hover:bg-bambu-dark/40 transition-colors flex-shrink-0`,children:(0,z.jsx)(ot,{className:`w-4 h-4`})})]}),(0,z.jsx)(`div`,{className:`px-4 py-3 border-t border-bambu-dark-tertiary flex-1 overflow-y-auto max-h-96 lg:max-h-none text-sm text-bambu-gray-light leading-relaxed space-y-2`,children:(0,z.jsx)(zs,{remarkPlugins:[Bc],components:{h1:({children:e})=>(0,z.jsx)(`h1`,{className:`text-lg font-semibold text-white mt-2 mb-1`,children:e}),h2:({children:e})=>(0,z.jsx)(`h2`,{className:`text-base font-semibold text-white mt-2 mb-1`,children:e}),h3:({children:e})=>(0,z.jsx)(`h3`,{className:`text-sm font-semibold text-white mt-2 mb-1`,children:e}),p:({children:e})=>(0,z.jsx)(`p`,{className:`my-1`,children:e}),ul:({children:e})=>(0,z.jsx)(`ul`,{className:`list-disc list-inside space-y-0.5 ml-2`,children:e}),ol:({children:e})=>(0,z.jsx)(`ol`,{className:`list-decimal list-inside space-y-0.5 ml-2`,children:e}),li:({children:e})=>(0,z.jsx)(`li`,{children:e}),code:({children:e,...t})=>t.className?(0,z.jsx)(`code`,{className:`block p-2 bg-bambu-dark rounded text-xs font-mono text-bambu-gray-light overflow-x-auto`,children:e}):(0,z.jsx)(`code`,{className:`px-1 py-0.5 bg-bambu-dark rounded text-xs font-mono text-bambu-green`,children:e}),pre:({children:e})=>(0,z.jsx)(`pre`,{className:`my-2`,children:e}),blockquote:({children:e})=>(0,z.jsx)(`blockquote`,{className:`border-l-2 border-bambu-dark-tertiary pl-3 text-bambu-gray italic`,children:e}),a:({children:e,href:t})=>(0,z.jsx)(`a`,{href:t,target:`_blank`,rel:`noopener noreferrer`,className:`text-bambu-green hover:underline`,children:e}),table:({children:e})=>(0,z.jsx)(`div`,{className:`overflow-x-auto`,children:(0,z.jsx)(`table`,{className:`min-w-full text-xs border-collapse`,children:e})}),th:({children:e})=>(0,z.jsx)(`th`,{className:`border border-bambu-dark-tertiary px-2 py-1 text-left font-semibold text-white`,children:e}),td:({children:e})=>(0,z.jsx)(`td`,{className:`border border-bambu-dark-tertiary px-2 py-1`,children:e}),hr:()=>(0,z.jsx)(`hr`,{className:`border-bambu-dark-tertiary my-2`})},children:i.content})})]})}function Uc({open:e,onClose:t,onPickTag:n}){let{t:r}=o(),i=c(),{showToast:s}=v(),[d,f]=(0,R.useState)(!1),[p,m]=(0,R.useState)(null),[h,g]=(0,R.useState)(``),[_,y]=(0,R.useState)(null),{data:b=[],isLoading:x}=l({queryKey:pt,queryFn:a.getLibraryTags,enabled:e}),S=()=>{i.invalidateQueries({queryKey:pt}),i.invalidateQueries({queryKey:[`library-files`]})},C=u({mutationFn:async()=>{let e=h.trim();if(!e)throw Error(r(`fileManager.tags.nameRequired`));return p?a.updateLibraryTag(p.id,e):a.createLibraryTag(e)},onSuccess:()=>{s(r(p?`fileManager.tags.updated`:`fileManager.tags.created`),`success`),f(!1),m(null),g(``),S()},onError:e=>{s(e.message||r(`fileManager.tags.saveFailed`),`error`)}}),w=u({mutationFn:e=>a.deleteLibraryTag(e),onSuccess:()=>{s(r(`fileManager.tags.deleted`),`success`),y(null),S()},onError:e=>{s(e.message||r(`fileManager.tags.deleteFailed`),`error`)}}),T=()=>{m(null),g(``),f(!0)},E=e=>{m(e),g(e.name),f(!0)},D=(0,R.useCallback)(()=>{C.isPending||(f(!1),m(null),g(``))},[C.isPending]);(0,R.useEffect)(()=>{if(!e)return;let n=e=>{e.key===`Escape`&&(C.isPending||w.isPending||(d?D():_||t()))};return document.addEventListener(`keydown`,n),()=>document.removeEventListener(`keydown`,n)},[e,d,_,C.isPending,w.isPending,D,t]);let O=e=>{e.preventDefault(),C.mutate()};if(!e)return null;let k=`library-tags-modal-title`,A=`library-tag-editor-title`;return(0,z.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[(0,z.jsx)(`div`,{className:`absolute inset-0 bg-black/60`,onClick:()=>{C.isPending||w.isPending||t()}}),(0,z.jsxs)(`div`,{className:`relative w-full max-w-4xl 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":k,children:[(0,z.jsxs)(`div`,{className:`flex items-center justify-between gap-4 px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,z.jsxs)(`h2`,{id:k,className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,z.jsx)(xe,{className:`w-5 h-5 text-bambu-green`}),r(`fileManager.tags.title`)]}),(0,z.jsx)(`p`,{className:`text-bambu-gray text-sm mt-0.5`,children:r(`fileManager.tags.subtitle`)})]}),(0,z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,z.jsxs)(P,{onClick:T,children:[(0,z.jsx)(Oe,{className:`w-4 h-4`}),r(`fileManager.tags.add`)]}),(0,z.jsx)(`button`,{type:`button`,className:`p-1.5 text-bambu-gray hover:text-white rounded`,onClick:t,"aria-label":r(`common.close`),children:(0,z.jsx)(ae,{className:`w-5 h-5`})})]})]}),(0,z.jsx)(`div`,{className:`overflow-y-auto`,children:x?(0,z.jsxs)(`div`,{className:`flex items-center justify-center py-16 text-bambu-gray`,children:[(0,z.jsx)(j,{className:`w-6 h-6 animate-spin mr-2`}),r(`common.loading`)]}):b.length===0?(0,z.jsx)(`div`,{className:`py-16 text-center text-bambu-gray`,children:r(`fileManager.tags.empty`)}):(0,z.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,z.jsx)(`thead`,{children:(0,z.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary text-left text-bambu-gray`,children:[(0,z.jsx)(`th`,{className:`px-4 py-3 font-medium`,children:r(`fileManager.tags.name`)}),(0,z.jsx)(`th`,{className:`px-4 py-3 font-medium text-right`,children:r(`fileManager.tags.fileCount`)}),(0,z.jsx)(`th`,{className:`px-4 py-3 font-medium text-right w-32`,children:r(`common.actions`)})]})}),(0,z.jsx)(`tbody`,{children:b.map(e=>(0,z.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/60 hover:bg-bambu-dark-tertiary/30 ${n?`cursor-pointer`:``}`,onClick:()=>{n&&(n(e.id),t())},children:[(0,z.jsx)(`td`,{className:`px-4 py-3 text-white font-medium`,children:e.name}),(0,z.jsx)(`td`,{className:`px-4 py-3 text-right text-bambu-gray`,children:e.file_count}),(0,z.jsx)(`td`,{className:`px-4 py-3 text-right`,onClick:e=>e.stopPropagation(),children:(0,z.jsxs)(`div`,{className:`flex items-center justify-end gap-1`,children:[(0,z.jsx)(`button`,{type:`button`,className:`p-1.5 text-bambu-gray hover:text-bambu-green rounded`,onClick:()=>E(e),title:r(`common.edit`),"aria-label":r(`fileManager.tags.editAria`,{name:e.name}),children:(0,z.jsx)(ue,{className:`w-4 h-4`})}),(0,z.jsx)(`button`,{type:`button`,className:`p-1.5 text-bambu-gray hover:text-red-600 dark:hover:text-red-400 rounded`,onClick:()=>y(e),title:r(`common.delete`),"aria-label":r(`fileManager.tags.deleteAria`,{name:e.name}),children:(0,z.jsx)(de,{className:`w-4 h-4`})})]})})]},e.id))})]})})]}),d&&(0,z.jsxs)(`div`,{className:`fixed inset-0 z-[60] flex items-center justify-center`,children:[(0,z.jsx)(`div`,{className:`absolute inset-0 bg-black/60`,onClick:D}),(0,z.jsxs)(`div`,{className:`relative w-full max-w-md mx-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl p-6 shadow-2xl`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":A,children:[(0,z.jsx)(`h3`,{id:A,className:`text-lg font-semibold text-white mb-4`,children:r(p?`fileManager.tags.edit`:`fileManager.tags.add`)}),(0,z.jsxs)(`form`,{onSubmit:O,children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,htmlFor:`library-tag-name`,children:r(`fileManager.tags.name`)}),(0,z.jsx)(`input`,{id:`library-tag-name`,type:`text`,maxLength:64,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green mb-4`,placeholder:r(`fileManager.tags.createPlaceholder`),value:h,onChange:e=>g(e.target.value),autoFocus:!0}),(0,z.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,z.jsx)(P,{type:`button`,variant:`secondary`,onClick:D,children:r(`common.cancel`)}),(0,z.jsxs)(P,{type:`submit`,disabled:C.isPending||!h.trim(),children:[C.isPending&&(0,z.jsx)(j,{className:`w-4 h-4 animate-spin`}),r(`common.save`)]})]})]})]})]}),_&&(0,z.jsx)(ke,{title:r(`fileManager.tags.confirmDelete`,{name:_.name}),message:_.file_count>0?r(`fileManager.tags.confirmDeleteInUseMessage`,{count:_.file_count}):r(`fileManager.tags.confirmDeleteMessage`),confirmText:r(`common.delete`),variant:`danger`,isLoading:w.isPending,onConfirm:()=>w.mutate(_.id),onCancel:()=>y(null)})]})}function Wc({file:e,canEdit:t,onClose:n}){let{t:r}=o(),{showToast:i}=v(),s=c(),{data:d}=l({queryKey:[`library-file`,e.id],queryFn:()=>a.getLibraryFile(e.id)}),[f,p]=(0,R.useState)(``),[m,h]=(0,R.useState)(``),[g,_]=(0,R.useState)([]),[y,b]=(0,R.useState)(!1),[x,S]=(0,R.useState)(null),C=(0,R.useRef)(null),w=(0,R.useRef)(null);(0,R.useEffect)(()=>{!d||w.current===d.id||(w.current=d.id,p(d.notes??``),h(d.external_url??``),_(d.photos??[]))},[d]),(0,R.useEffect)(()=>{if(x!==null)return;let e=e=>{e.key===`Escape`&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[x,n]);let T=()=>{s.invalidateQueries({queryKey:[`library-files`]}),s.invalidateQueries({queryKey:[`library-file`,e.id]})},E=u({mutationFn:()=>a.updateLibraryFile(e.id,{notes:f,external_url:m.trim()}),onSuccess:()=>{T(),i(r(`fileManager.details.saved`),`success`),n()},onError:()=>{i(r(`fileManager.details.saveFailed`),`error`)}}),D=!!d&&(f!==(d.notes??``)||m.trim()!==(d.external_url??``)),O=async t=>{let n=t.target.files?.[0];if(n){b(!0);try{_((await a.uploadLibraryFilePhoto(e.id,n)).photos),T()}catch{i(r(`fileManager.details.uploadFailed`),`error`)}finally{b(!1),C.current&&(C.current.value=``)}}},k=async t=>{try{let n=(await a.deleteLibraryFilePhoto(e.id,t)).photos??[];_(n),n.length===0&&S(null),T()}catch{i(r(`fileManager.details.deleteFailed`),`error`)}},A=e=>{e.preventDefault(),!(!t||!D)&&E.mutate()},ee=m.trim(),M=[{label:r(`fileManager.details.size`),value:oe(e.file_size)},{label:r(`fileManager.details.type`),value:e.file_type.toUpperCase()}];if(d?.print_name&&M.push({label:r(`fileManager.details.printName`),value:d.print_name}),d?.print_time_seconds&&M.push({label:r(`fileManager.details.printTime`),value:ce(d.print_time_seconds)}),d?.filament_used_grams&&M.push({label:r(`fileManager.details.filament`),value:`${d.filament_used_grams.toFixed(1)} g`}),d?.sliced_for_model&&M.push({label:r(`fileManager.details.slicedFor`),value:d.sliced_for_model}),d?.source_url){let e=/^https?:\/\//i.test(d.source_url);M.push({label:r(`fileManager.details.source`),value:e?(0,z.jsxs)(`a`,{href:d.source_url,target:`_blank`,rel:`noopener noreferrer`,className:`text-bambu-green hover:underline inline-flex items-center gap-1 min-w-0`,children:[(0,z.jsx)(`span`,{className:`truncate`,children:d.source_url}),(0,z.jsx)(fe,{className:`w-3 h-3 flex-shrink-0`})]}):(0,z.jsx)(`span`,{className:`truncate`,children:d.source_url})})}return M.push({label:r(`fileManager.details.created`),value:se(e.created_at)}),M.push({label:r(`fileManager.details.modified`),value:se(e.fs_modified_at??d?.updated_at??e.created_at)}),(0,z.jsxs)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:n,children:[(0,z.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-lg max-h-[90vh] flex flex-col`,onClick:e=>e.stopPropagation(),children:[(0,z.jsxs)(`div`,{className:`flex items-center justify-between gap-3 px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,z.jsxs)(`div`,{className:`min-w-0`,children:[(0,z.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:r(`fileManager.details.title`)}),(0,z.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,z.jsx)(`h2`,{className:`text-lg font-semibold text-white truncate`,title:e.filename,children:e.filename}),(0,z.jsx)(`span`,{className:`flex-shrink-0 text-xs px-1.5 py-0.5 rounded font-medium bg-bambu-dark-tertiary text-bambu-gray`,children:e.file_type.toUpperCase()})]})]}),(0,z.jsx)(`button`,{type:`button`,onClick:n,className:`text-bambu-gray hover:text-white transition-colors flex-shrink-0`,"aria-label":r(`common.close`),children:(0,z.jsx)(ae,{className:`w-5 h-5`})})]}),(0,z.jsxs)(`form`,{onSubmit:A,className:`p-6 space-y-4 overflow-y-auto flex-1`,children:[(0,z.jsx)(`dl`,{className:`grid grid-cols-[auto_1fr] gap-x-4 gap-y-1 text-sm`,children:M.map(e=>(0,z.jsxs)(`div`,{className:`contents`,children:[(0,z.jsx)(`dt`,{className:`text-bambu-gray whitespace-nowrap`,children:e.label}),(0,z.jsx)(`dd`,{className:`text-white min-w-0 truncate`,children:e.value})]},e.label))}),(0,z.jsxs)(`div`,{children:[(0,z.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[(0,z.jsx)(ne,{className:`w-4 h-4 inline mr-1`}),r(`fileManager.details.notes`)]}),(0,z.jsx)(`textarea`,{value:f,onChange:e=>p(e.target.value),rows:3,disabled:!t,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none resize-none disabled:opacity-60`,placeholder:r(`fileManager.details.notesPlaceholder`)})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[(0,z.jsx)(Pe,{className:`w-4 h-4 inline mr-1`}),r(`fileManager.details.externalLink`)]}),(0,z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,z.jsx)(`input`,{type:`url`,value:m,onChange:e=>h(e.target.value),disabled:!t,className:`flex-1 min-w-0 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none disabled:opacity-60`,placeholder:r(`fileManager.details.externalLinkPlaceholder`)}),ee&&(0,z.jsx)(`a`,{href:ee,target:`_blank`,rel:`noopener noreferrer`,className:`p-2 rounded-lg text-bambu-gray hover:text-bambu-green hover:bg-bambu-dark transition-colors`,title:r(`fileManager.details.openLink`),"aria-label":r(`fileManager.details.openLink`),children:(0,z.jsx)(fe,{className:`w-4 h-4`})})]})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[(0,z.jsx)(be,{className:`w-4 h-4 inline mr-1`}),r(`fileManager.details.photos`)]}),(0,z.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[g.map((n,i)=>(0,z.jsxs)(`div`,{className:`relative group`,children:[(0,z.jsx)(`button`,{type:`button`,onClick:()=>S(i),className:`block w-20 h-20 rounded-lg overflow-hidden border border-bambu-dark-tertiary hover:border-bambu-green transition-colors`,children:(0,z.jsx)(`img`,{src:a.getLibraryFilePhotoUrl(e.id,n),alt:r(`fileManager.details.photos`),className:`w-full h-full object-cover`})}),t&&(0,z.jsx)(`button`,{type:`button`,onClick:()=>k(n),className:`absolute -top-1 -right-1 p-1 bg-red-500 rounded-full can-hover:opacity-0 group-hover:opacity-100 focus-visible:opacity-100 transition-opacity`,title:r(`fileManager.details.deletePhoto`),"aria-label":r(`fileManager.details.deletePhoto`),children:(0,z.jsx)(de,{className:`w-3 h-3 text-white`})})]},n)),t&&(0,z.jsxs)(`label`,{className:`w-20 h-20 flex items-center justify-center border-2 border-dashed border-bambu-dark-tertiary rounded-lg cursor-pointer hover:border-bambu-green transition-colors`,title:r(`fileManager.details.addPhoto`),children:[(0,z.jsx)(`input`,{ref:C,type:`file`,accept:`image/jpeg,image/png,image/webp`,onChange:O,className:`hidden`,disabled:y,"aria-label":r(`fileManager.details.addPhoto`)}),y?(0,z.jsx)(j,{className:`w-6 h-6 text-bambu-gray animate-spin`}):(0,z.jsx)(Oe,{className:`w-6 h-6 text-bambu-gray`})]}),g.length===0&&!t&&(0,z.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:r(`fileManager.details.noPhotos`)})]})]}),(0,z.jsxs)(`div`,{className:`flex gap-3 pt-2`,children:[(0,z.jsx)(P,{type:`button`,variant:`secondary`,onClick:n,className:`flex-1`,children:r(`common.close`)}),t&&(0,z.jsxs)(P,{type:`submit`,variant:`primary`,className:`flex-1`,disabled:!D||E.isPending,children:[E.isPending?(0,z.jsx)(j,{className:`w-4 h-4 animate-spin`}):(0,z.jsx)(Te,{className:`w-4 h-4`}),r(`fileManager.details.save`)]})]})]})]}),x!==null&&g.length>0&&(0,z.jsx)(We,{archiveName:e.filename,photos:g,initialIndex:x,getPhotoUrl:t=>a.getLibraryFilePhotoUrl(e.id,t),onClose:()=>S(null),onDelete:t?k:void 0})]})}var Gc=90;function Kc({onClose:e}){let{t}=o(),n=c(),{showToast:r}=v(),[i,s]=(0,R.useState)(Gc),[d,f]=(0,R.useState)(!0),[p,m]=(0,R.useState)(i);(0,R.useEffect)(()=>{let e=window.setTimeout(()=>m(i),300);return()=>window.clearTimeout(e)},[i]);let h=l({queryKey:[`library-purge-preview`,p,d],queryFn:()=>a.previewLibraryPurge(p,d),enabled:p>=1}),g=u({mutationFn:()=>a.executeLibraryPurge(i,d),onSuccess:i=>{r(t(`libraryPurge.toast.success`,{count:i.moved_to_trash}),`success`),n.invalidateQueries({queryKey:[`library-files`]}),n.invalidateQueries({queryKey:[`library-folders`]}),n.invalidateQueries({queryKey:[`library-trash`]}),n.invalidateQueries({queryKey:[`library-trash-count`]}),e()},onError:e=>r(e.message||t(`libraryPurge.toast.failed`),`error`)});(0,R.useEffect)(()=>{let t=t=>{t.key===`Escape`&&!g.isPending&&e()};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e,g.isPending]);let _=h.data,y=_?.count??0,b=_?.total_bytes??0,x=y>0&&!g.isPending;return(0,z.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4`,children:(0,z.jsxs)(`div`,{className:`bg-white dark:bg-gray-900 rounded-lg shadow-xl max-w-lg w-full`,children:[(0,z.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-gray-200 dark:border-gray-700`,children:[(0,z.jsxs)(`h2`,{className:`text-lg font-semibold text-gray-900 dark:text-gray-100 flex items-center gap-2`,children:[(0,z.jsx)(de,{className:`w-5 h-5`}),t(`libraryPurge.title`)]}),(0,z.jsx)(`button`,{onClick:e,className:`text-gray-400 hover:text-gray-600 dark:hover:text-gray-200`,"aria-label":t(`common.close`),disabled:g.isPending,children:(0,z.jsx)(ae,{className:`w-5 h-5`})})]}),(0,z.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,z.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400`,children:t(`libraryPurge.description`)}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{htmlFor:`purge-days`,className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:t(`libraryPurge.ageLabel`)}),(0,z.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,z.jsx)(`input`,{id:`purge-days`,type:`number`,min:1,max:3650,value:i,onChange:e=>s(Math.max(1,Math.min(3650,parseInt(e.target.value||`0`,10)||0))),className:`w-24 rounded border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-800 text-sm px-2 py-1 text-gray-900 dark:text-gray-100`}),(0,z.jsx)(`span`,{className:`text-sm text-gray-600 dark:text-gray-400`,children:t(`libraryPurge.days`)})]})]}),(0,z.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-gray-700 dark:text-gray-300`,children:[(0,z.jsx)(`input`,{type:`checkbox`,checked:d,onChange:e=>f(e.target.checked),className:`rounded border-gray-300`}),t(`libraryPurge.includeNeverPrinted`)]}),(0,z.jsxs)(`div`,{className:`rounded border border-gray-200 dark:border-gray-700 bg-gray-50 dark:bg-gray-800/30 p-3`,children:[(0,z.jsx)(`div`,{className:`text-xs font-semibold uppercase tracking-wide text-gray-600 dark:text-gray-300 mb-2`,children:t(`libraryPurge.effectsTitle`)}),(0,z.jsxs)(`ul`,{className:`text-xs text-gray-700 dark:text-gray-300 space-y-1 list-disc pl-4`,children:[(0,z.jsx)(`li`,{children:t(`libraryPurge.effect1`)}),(0,z.jsx)(`li`,{children:t(`libraryPurge.effect2`)}),(0,z.jsx)(`li`,{children:t(`libraryPurge.effect3`)}),(0,z.jsx)(`li`,{children:t(`libraryPurge.effect4`)})]})]}),(0,z.jsx)(`div`,{className:`rounded border border-gray-200 dark:border-gray-700 bg-gray-50 dark:bg-gray-800/50 p-3`,children:h.isLoading||h.isFetching?(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-gray-500 dark:text-gray-400`,children:[(0,z.jsx)(j,{className:`w-4 h-4 animate-spin`}),` `,t(`libraryPurge.previewLoading`)]}):h.isError?(0,z.jsx)(`div`,{className:`text-sm text-red-600 dark:text-red-400`,children:h.error?.message??t(`libraryPurge.previewFailed`)}):(0,z.jsxs)(`div`,{className:`text-sm text-gray-900 dark:text-gray-100`,children:[(0,z.jsx)(`div`,{className:`font-medium`,children:t(`libraryPurge.previewSummary`,{count:y,size:oe(b)})}),_?.sample_filenames&&_.sample_filenames.length>0&&(0,z.jsxs)(`ul`,{className:`mt-2 text-xs text-gray-600 dark:text-gray-400 space-y-0.5 list-disc pl-4`,children:[_.sample_filenames.map(e=>(0,z.jsx)(`li`,{className:`truncate`,children:e},e)),y>_.sample_filenames.length&&(0,z.jsx)(`li`,{className:`list-none italic text-gray-500`,children:t(`libraryPurge.andMore`,{count:y-_.sample_filenames.length})})]})]})}),(0,z.jsxs)(`div`,{className:`flex gap-2 items-start text-xs text-amber-700 dark:text-amber-400 bg-amber-50 dark:bg-amber-900/20 rounded px-3 py-2`,children:[(0,z.jsx)(re,{className:`w-4 h-4 mt-0.5 shrink-0`}),(0,z.jsx)(`span`,{children:t(`libraryPurge.warning`)})]})]}),(0,z.jsxs)(`div`,{className:`flex justify-end gap-2 p-4 border-t border-gray-200 dark:border-gray-700`,children:[(0,z.jsx)(P,{variant:`secondary`,onClick:e,disabled:g.isPending,children:t(`common.cancel`)}),(0,z.jsx)(P,{variant:`danger`,disabled:!x,onClick:()=>g.mutate(),children:g.isPending?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(j,{className:`w-4 h-4 animate-spin mr-1`}),t(`libraryPurge.purging`)]}):t(`libraryPurge.confirmCta`,{count:y})})]})]})})}var qc=(0,R.lazy)(()=>I(()=>import(`./PdfPreviewModal-Con0pW4P.js`).then(e=>({default:e.PdfPreviewModal})),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28]))),Jc=(0,R.lazy)(()=>I(()=>import(`./SpreadsheetPreviewModal-CVALSyS0.js`).then(e=>({default:e.SpreadsheetPreviewModal})),__vite__mapDeps([29,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,30,26,27,28]))),Yc=(0,R.lazy)(()=>I(()=>import(`./ImagePreviewModal-VVWd1NOq.js`).then(e=>({default:e.ImagePreviewModal})),__vite__mapDeps([31,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28])));function Xc(e){return e===`csv`||e===`xlsx`||e===`ods`}function Zc(e){return e===`step`||e===`stp`}var Qc=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`bmp`,`tiff`,`tif`]),$c=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`bmp`]);function el(e){return Qc.has(e.toLowerCase())}function tl(e){return $c.has(e.toLowerCase())}function nl({fileType:e,className:t}){return(0,z.jsx)(e===`pdf`?Re:Xc(e)?C:el(e)?Fe:S,{className:t})}function rl(e){return{results:e,files:e.flatMap(e=>e.data??[])}}function il(e){let t=e.file_type;return Ze(e)||t===`3mf`||t===`stl`||Zc(t)||t===`pdf`||Xc(t)||tl(t)}var al={onClick:e=>e.stopPropagation(),onDoubleClick:e=>e.stopPropagation()};function ol(e){return Ze(e)||e.file_type===`3mf`||e.file_type===`stl`||Zc(e.file_type)}function sl(e){return e===`pdf`?(0,z.jsx)(Re,{className:`w-4 h-4`}):Xc(e)?(0,z.jsx)(C,{className:`w-4 h-4`}):(0,z.jsx)(Fe,{className:`w-4 h-4`})}function cl(e){return e===`stl`||e===`pdf`}function ll(e){return e===`3mf`?`bg-bambu-green/20 text-bambu-green`:e===`gcode`||e===`gcode.3mf`?`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`:e===`stl`?`bg-purple-100 dark:bg-purple-500/20 text-purple-700 dark:text-purple-400`:Zc(e)?`bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400`:e===`pdf`?`bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400`:Xc(e)?`bg-teal-100 dark:bg-teal-500/20 text-teal-700 dark:text-teal-400`:`bg-bambu-gray/20 text-bambu-gray`}function ul(e,t){let n=[...e],r=t.query?.trim().toLowerCase();r&&(n=n.filter(e=>e.filename.toLowerCase().includes(r)||e.print_name&&e.print_name.toLowerCase().includes(r))),t.filterType!==`all`&&(n=n.filter(e=>e.file_type===t.filterType));let i=t.filterUsername.trim().toLowerCase();return i&&(n=n.filter(e=>e.created_by_username&&e.created_by_username.toLowerCase().includes(i))),n.sort((e,n)=>{let r=0;switch(t.sortField){case`name`:r=(e.print_name||e.filename).localeCompare(n.print_name||n.filename);break;case`date`:r=(le(e.fs_modified_at??e.created_at)?.getTime()??0)-(le(n.fs_modified_at??n.created_at)?.getTime()??0);break;case`size`:r=e.file_size-n.file_size;break;case`type`:r=e.file_type.localeCompare(n.file_type);break;case`prints`:r=e.print_count-n.print_count;break}return t.sortDirection===`asc`?r:-r}),n}var dl=e=>e?`grid-cols-[24px_minmax(240px,1fr)_120px_100px_100px_100px_minmax(96px,200px)_220px]`:`grid-cols-[24px_minmax(240px,1fr)_100px_100px_100px_minmax(96px,200px)_220px]`,fl=`min-w-min`;function pl({parentId:e,onClose:t,onSave:n,isLoading:r,t:i}){let[a,o]=(0,R.useState)(``);return(0,z.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,z.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-sm border border-bambu-dark-tertiary`,children:[(0,z.jsx)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary`,children:(0,z.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`fileManager.newFolder`)})}),(0,z.jsxs)(`form`,{onSubmit:t=>{t.preventDefault(),n({name:a.trim(),parent_id:e})},className:`p-4 space-y-4`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:i(`fileManager.folderName`)}),(0,z.jsx)(`input`,{type:`text`,value:a,onChange:e=>o(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:i(`fileManager.folderNamePlaceholder`),autoFocus:!0,required:!0})]}),(0,z.jsxs)(`div`,{className:`flex justify-end gap-2 pt-2`,children:[(0,z.jsx)(P,{type:`button`,variant:`secondary`,onClick:t,children:i(`common.cancel`)}),(0,z.jsx)(P,{type:`submit`,disabled:!a.trim()||r,children:r?(0,z.jsx)(j,{className:`w-4 h-4 animate-spin`}):i(`common.create`)})]})]})]})})}function ml({onClose:e,onSave:t,isLoading:n,t:r}){let[i,a]=(0,R.useState)(``),[o,s]=(0,R.useState)(``),[c,l]=(0,R.useState)(!0),[u,d]=(0,R.useState)(!1);return(0,z.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,z.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-md border border-bambu-dark-tertiary`,children:[(0,z.jsxs)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary`,children:[(0,z.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,z.jsx)(it,{className:`w-5 h-5 text-bambu-green`}),r(`fileManager.linkExternalFolder`)]}),(0,z.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:r(`fileManager.linkExternalFolderDescription`)})]}),(0,z.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),t({name:i.trim(),external_path:o.trim(),readonly:c,show_hidden:u})},className:`p-4 space-y-4`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:r(`fileManager.folderName`)}),(0,z.jsx)(`input`,{type:`text`,value:i,onChange:e=>a(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:r(`fileManager.externalFolderNamePlaceholder`),autoFocus:!0,required:!0})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:r(`fileManager.externalPath`)}),(0,z.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 font-mono text-sm`,placeholder:`/mnt/nas/3d-prints`,required:!0}),(0,z.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:r(`fileManager.externalPathHelp`)})]}),(0,z.jsxs)(`div`,{className:`space-y-2`,children:[(0,z.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,z.jsx)(`input`,{type:`checkbox`,checked:c,onChange:e=>l(e.target.checked),className:`rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,z.jsx)(`span`,{className:`text-sm text-white`,children:r(`fileManager.readOnly`)}),(0,z.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[`(`,r(`fileManager.readOnlyHelp`),`)`]})]}),(0,z.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,z.jsx)(`input`,{type:`checkbox`,checked:u,onChange:e=>d(e.target.checked),className:`rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,z.jsx)(`span`,{className:`text-sm text-white`,children:r(`fileManager.showHiddenFiles`)})]})]}),(0,z.jsxs)(`div`,{className:`flex justify-end gap-2 pt-2`,children:[(0,z.jsx)(P,{type:`button`,variant:`secondary`,onClick:e,children:r(`common.cancel`)}),(0,z.jsx)(P,{type:`submit`,disabled:!i.trim()||!o.trim()||n,children:n?(0,z.jsx)(j,{className:`w-4 h-4 animate-spin`}):r(`fileManager.linkFolder`)})]})]})]})})}var hl=`<>:"/\\|?*`;function gl(e){for(let t of e)if(hl.includes(t)||t.charCodeAt(0)<32)return t;return null}function _l({type:e,currentName:t,onClose:n,onSave:r,isLoading:i,t:a}){let o=e===`file`?t.match(/(\.gcode\.3mf|\.3mf|\.gcode)$/i)?.[1]??``:``,s=e===`file`&&o?t.slice(0,-o.length):t,[c,l]=(0,R.useState)(s),u=e===`file`?gl(c):null,d=u?a(`fileManager.invalidFilenameChar`,{char:u}):null;return(0,z.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,z.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-sm border border-bambu-dark-tertiary`,children:[(0,z.jsx)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary`,children:(0,z.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:a(e===`file`?`fileManager.renameFile`:`fileManager.renameFolder`)})}),(0,z.jsxs)(`form`,{onSubmit:n=>{if(n.preventDefault(),d)return;let i=e===`file`?c.trim()+o:c.trim();c.trim()&&i!==t&&r(i)},className:`p-4 space-y-4`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`common.name`)}),(0,z.jsxs)(`div`,{className:`flex items-center bg-bambu-dark border rounded focus-within:border-bambu-green ${d?`border-red-500`:`border-bambu-dark-tertiary`}`,children:[(0,z.jsx)(`input`,{type:`text`,value:c,onChange:e=>l(e.target.value),className:`flex-1 bg-transparent px-3 py-2 text-white placeholder-bambu-gray focus:outline-none min-w-0`,autoFocus:!0,required:!0}),o&&(0,z.jsx)(`span`,{className:`pr-3 text-bambu-gray text-sm select-none whitespace-nowrap`,children:o})]}),d&&(0,z.jsx)(`p`,{className:`mt-1 text-xs text-red-700 dark:text-red-400`,children:d})]}),(0,z.jsxs)(`div`,{className:`flex justify-end gap-2 pt-2`,children:[(0,z.jsx)(P,{type:`button`,variant:`secondary`,onClick:n,children:a(`common.cancel`)}),(0,z.jsx)(P,{type:`submit`,disabled:!c.trim()||c.trim()===s||!!d||i,children:i?(0,z.jsx)(j,{className:`w-4 h-4 animate-spin`}):a(`common.rename`)})]})]})]})})}function vl({folders:e,selectedFiles:t,currentFolderId:n,onClose:r,onMove:i,isLoading:a,t:o}){let[s,c]=(0,R.useState)(null),l=(e,t=0)=>{let n=[];for(let r of e)n.push({id:r.id,name:r.name,depth:t,canWrite:r.can_write!==!1}),r.children.length>0&&n.push(...l(r.children,t+1));return n},u=[{id:null,name:o(`fileManager.rootNoFolder`),depth:0,canWrite:!0},...l(e)];return(0,z.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,z.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-sm border border-bambu-dark-tertiary`,children:[(0,z.jsx)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary`,children:(0,z.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:o(`fileManager.moveFiles`,{count:t.length})})}),(0,z.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,z.jsx)(`div`,{className:`max-h-64 overflow-y-auto space-y-1`,children:u.map(e=>(0,z.jsxs)(`button`,{onClick:()=>c(e.id),disabled:e.id===n||!e.canWrite,title:e.canWrite?void 0:o(`fileManager.folderNotWritable`),className:`w-full text-left px-3 py-2 rounded transition-colors flex items-center gap-2 ${s===e.id?`bg-bambu-green/20 text-bambu-green`:e.id===n||!e.canWrite?`opacity-50 cursor-not-allowed text-bambu-gray`:`hover:bg-bambu-dark text-white`}`,style:{paddingLeft:`${12+e.depth*16}px`},children:[(0,z.jsx)(Ie,{className:`w-4 h-4`}),e.name,e.id===n&&(0,z.jsxs)(`span`,{className:`text-xs text-bambu-gray ml-auto`,children:[`(`,o(`fileManager.current`),`)`]})]},e.id??`root`))}),(0,z.jsxs)(`div`,{className:`flex justify-end gap-2 pt-2`,children:[(0,z.jsx)(P,{type:`button`,variant:`secondary`,onClick:r,children:o(`common.cancel`)}),(0,z.jsx)(P,{onClick:()=>i(s),disabled:a,children:a?(0,z.jsx)(j,{className:`w-4 h-4 animate-spin`}):o(`common.move`)})]})]})]})})}function yl({folder:e,onClose:t,onLink:n,isLoading:r,t:i}){let[o,s]=(0,R.useState)(`project`),[c,u]=(0,R.useState)(e.project_id||e.archive_id||null);(0,R.useState)(()=>{e.archive_id&&s(`archive`)});let{data:d}=l({queryKey:[`projects`],queryFn:()=>a.getProjects(),select:t=>F([...t].sort((e,t)=>e.name.localeCompare(t.name)),e.project_id)}),{data:f}=l({queryKey:[`archives-for-link`],queryFn:()=>a.getArchives(void 0,void 0,100)}),p=()=>{n(o===`project`?{project_id:c,archive_id:0}:{project_id:0,archive_id:c})},h=()=>{n({project_id:0,archive_id:0})},g=e.project_id||e.archive_id;return(0,z.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,z.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-md border border-bambu-dark-tertiary`,children:[(0,z.jsxs)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary flex items-center justify-between`,children:[(0,z.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,z.jsx)(A,{className:`w-5 h-5 text-bambu-green`}),i(`fileManager.linkFolder`)]}),(0,z.jsx)(`button`,{onClick:t,className:`p-1 hover:bg-bambu-dark rounded`,children:(0,z.jsx)(ae,{className:`w-5 h-5 text-bambu-gray`})})]}),(0,z.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,z.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`fileManager.linkFolderDescription`,{name:e.name})}),(0,z.jsxs)(`div`,{className:`flex gap-2`,children:[(0,z.jsxs)(`button`,{onClick:()=>{s(`project`),u(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg border transition-colors ${o===`project`?`border-bambu-green bg-bambu-green/10 text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:text-white`}`,children:[(0,z.jsx)(m,{className:`w-4 h-4`}),i(`fileManager.project`)]}),(0,z.jsxs)(`button`,{onClick:()=>{s(`archive`),u(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg border transition-colors ${o===`archive`?`border-bambu-green bg-bambu-green/10 text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:text-white`}`,children:[(0,z.jsx)(he,{className:`w-4 h-4`}),i(`fileManager.archive`)]})]}),(0,z.jsx)(`div`,{className:`max-h-64 overflow-y-auto space-y-1 bg-bambu-dark rounded-lg p-2`,children:o===`project`?d&&d.length>0?d.map(e=>(0,z.jsxs)(`button`,{onClick:()=>u(e.id),className:`w-full text-left px-3 py-2 rounded transition-colors flex items-center gap-2 ${c===e.id?`bg-bambu-green/20 text-bambu-green`:`hover:bg-bambu-dark-tertiary text-white`}`,children:[(0,z.jsx)(`div`,{className:`w-3 h-3 rounded-full flex-shrink-0`,style:{backgroundColor:e.color||`#00ae42`}}),(0,z.jsx)(`span`,{className:`truncate`,children:e.name})]},e.id)):(0,z.jsx)(`p`,{className:`text-sm text-bambu-gray text-center py-4`,children:i(`fileManager.noProjectsFound`)}):f&&f.length>0?f.map(e=>(0,z.jsxs)(`button`,{onClick:()=>u(e.id),className:`w-full text-left px-3 py-2 rounded transition-colors flex items-center gap-2 ${c===e.id?`bg-bambu-green/20 text-bambu-green`:`hover:bg-bambu-dark-tertiary text-white`}`,children:[(0,z.jsx)(S,{className:`w-4 h-4 text-bambu-gray flex-shrink-0`}),(0,z.jsx)(`span`,{className:`truncate`,children:e.print_name||e.filename})]},e.id)):(0,z.jsx)(`p`,{className:`text-sm text-bambu-gray text-center py-4`,children:i(`fileManager.noArchivesFound`)})})]}),(0,z.jsxs)(`div`,{className:`p-4 border-t border-bambu-dark-tertiary flex justify-between`,children:[g&&(0,z.jsxs)(P,{variant:`danger`,onClick:h,disabled:r,children:[(0,z.jsx)(ie,{className:`w-4 h-4 mr-2`}),i(`fileManager.unlink`)]}),(0,z.jsxs)(`div`,{className:`flex gap-2 ${g?``:`ml-auto`}`,children:[(0,z.jsx)(P,{variant:`secondary`,onClick:t,children:i(`common.cancel`)}),(0,z.jsx)(P,{onClick:p,disabled:!c||r,children:r?(0,z.jsx)(j,{className:`w-4 h-4 animate-spin`}):i(`fileManager.link`)})]})]})]})})}function bl({folder:e,onDelete:t,onLink:n,onRename:r,onToggleShared:i,hasPermission:a,revealOnHover:o=!1,tabIndex:s,t:c}){let[l,u]=(0,R.useState)(null),d=(0,R.useRef)(null),f=(0,R.useRef)(null),p=()=>{u(null),d.current?.contains(document.activeElement)&&f.current?.focus()},m=e.children.length>0,h=e.project_id||e.archive_id,g=e.is_external,_=e.can_delete??(a(`library:delete_all`)||a(`library:delete_own`)&&e.file_count===0&&!m&&!g&&!h),v=_?void 0:a(`library:delete_own`)&&!g&&!h?c(`fileManager.onlyOwnFoldersDeletable`):c(`fileManager.noPermissionDeleteFolder`),y=e.can_rename??a(`library:update_all`),b=a(`library:update_all`),S=[{label:c(`common.rename`),icon:(0,z.jsx)(ue,{className:`w-3.5 h-3.5`}),onClick:()=>r(e),disabled:!y,title:y?void 0:c(`fileManager.noPermissionRenameFolder`)},{label:c(h?`fileManager.changeLink`:`fileManager.linkTo`),icon:(0,z.jsx)(A,{className:`w-3.5 h-3.5`}),onClick:()=>n(e),disabled:!b,title:b?void 0:c(`fileManager.noPermissionLinkFolder`)},...i&&b?[{label:e.shared?c(`fileManager.unshareFolder`):c(`fileManager.shareFolder`),icon:(0,z.jsx)(pe,{className:`w-3.5 h-3.5`}),onClick:()=>i(e),title:c(`fileManager.shareFolderHint`)}]:[],{label:c(`common.delete`),icon:(0,z.jsx)(de,{className:`w-3.5 h-3.5`}),onClick:()=>t(e.id),danger:!0,disabled:!_,title:v}];return(0,z.jsxs)(`div`,{ref:d,className:`relative flex-shrink-0 flex items-center transition-opacity ${o&&!l?`can-hover:opacity-0 group-hover:opacity-100 group-focus-within:opacity-100`:``}`,"data-folder-actions":!0,onClick:e=>e.stopPropagation(),onKeyDown:e=>{l&&(e.key===`ArrowUp`||e.key===`ArrowDown`)&&p()},children:[(0,z.jsx)(`button`,{ref:f,type:`button`,tabIndex:s,onClick:e=>{if(l){p();return}let t=e.currentTarget.getBoundingClientRect();u({x:t.left,y:t.bottom+4})},className:`p-1 rounded hover:bg-bambu-dark-tertiary`,title:c(`common.actions`),children:(0,z.jsx)(x,{className:`w-3.5 h-3.5 text-bambu-gray`})}),l&&(0,z.jsx)(T,{x:l.x,y:l.y,items:S,onClose:p,anchorRef:f})]})}function xl({folder:e,selectedFolderId:t,onSelect:n,onDelete:r,onLink:i,onRename:a,onToggleShared:o,depth:s=0,wrapNames:c=!1,defaultExpanded:l=!0,showModified:u=!1,hasPermission:d,t:f}){let[p,h]=(0,R.useState)(l),g=e.children.length>0,_=e.project_id||e.archive_id,v=e.is_external;return(0,z.jsxs)(`div`,{children:[(0,z.jsxs)(`div`,{className:`group flex items-center gap-1 px-2 py-1.5 rounded cursor-pointer transition-colors ${t===e.id?`bg-bambu-green/20 text-bambu-green`:`hover:bg-bambu-dark text-white`}`,style:{paddingLeft:`${8+s*12}px`},onClick:()=>n(e.id),children:[g?(0,z.jsx)(`button`,{onClick:e=>{e.stopPropagation(),h(!p)},className:`p-0.5 hover:bg-bambu-dark-tertiary rounded`,children:(0,z.jsx)(_e,{className:`w-3.5 h-3.5 transition-transform ${p?`rotate-90`:``}`})}):(0,z.jsx)(`div`,{className:`w-4.5`}),v?(0,z.jsx)(it,{className:`w-4 h-4 text-purple-600 dark:text-purple-400 flex-shrink-0`}):(0,z.jsx)(Ie,{className:`w-4 h-4 text-bambu-green flex-shrink-0`}),(0,z.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,z.jsx)(`span`,{className:`block text-sm ${c?`break-all`:`truncate`}`,title:e.name,children:e.name}),u&&e.latest_activity_at&&(0,z.jsxs)(`span`,{className:`mt-0.5 flex items-center gap-1 text-xs text-bambu-gray`,title:f(`fileManager.lastActivity`),children:[(0,z.jsx)(tt,{className:`w-3 h-3 flex-shrink-0`}),(0,z.jsx)(`span`,{className:`truncate`,children:se(e.latest_activity_at)})]})]}),_&&(0,z.jsxs)(`button`,{onClick:t=>{t.stopPropagation(),i(e)},className:`flex-shrink-0 flex items-center gap-1 text-xs px-1.5 py-0.5 rounded bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400 hover:bg-blue-200 dark:hover:bg-blue-500/30 transition-colors`,title:`${e.project_name?`Project: ${e.project_name}`:`Archive: ${e.archive_name}`} (click to change)`,children:[(0,z.jsx)(A,{className:`w-3 h-3`}),e.project_name?(0,z.jsx)(m,{className:`w-3 h-3`}):(0,z.jsx)(he,{className:`w-3 h-3`})]}),e.shared&&(0,z.jsx)(`span`,{title:f(`fileManager.sharedFolder`),children:(0,z.jsx)(pe,{className:`w-3 h-3 text-bambu-gray flex-shrink-0`})}),v&&e.external_readonly&&(0,z.jsx)(`span`,{title:f(`fileManager.readOnly`),children:(0,z.jsx)(M,{className:`w-3 h-3 text-amber-600 dark:text-amber-400 flex-shrink-0`})}),e.file_count>0&&(0,z.jsx)(`span`,{className:`flex-shrink-0 text-xs text-bambu-gray`,children:e.file_count}),!_&&!v&&(0,z.jsx)(`button`,{onClick:t=>{t.stopPropagation(),i(e)},className:`flex-shrink-0 p-1 rounded hover:bg-bambu-dark-tertiary`,title:f(`fileManager.linkToProjectOrArchive`),children:(0,z.jsx)(A,{className:`w-3.5 h-3.5 text-bambu-gray hover:text-bambu-green`})}),(0,z.jsx)(bl,{folder:e,onDelete:r,onLink:i,onRename:a,onToggleShared:o,hasPermission:d,revealOnHover:!c,t:f})]}),g&&p&&(0,z.jsx)(`div`,{children:e.children.map(e=>(0,z.jsx)(xl,{folder:e,selectedFolderId:t,onSelect:n,onDelete:r,onLink:i,onRename:a,onToggleShared:o,depth:s+1,wrapNames:c,defaultExpanded:l,showModified:u,hasPermission:d,t:f},e.id))})]})}function Sl({file:e,isSelected:t,onSelect:n,onDelete:r,onDownload:i,onPrint:o,onSlice:s,onOpenInSlicer:c,onRunPipeline:l,useSlicerApi:u,desktopSlicer:d,canSlice:f,onPreview:m,onRename:h,onDetails:g,onGenerateThumbnail:v,onTagClick:b,thumbnailVersion:S,hasPermission:C,canModify:w,authEnabled:E,showModified:D,t:O}){let[k,A]=(0,R.useState)(null),ee=C(`library:read`),j=w(`library`,`update`,e.created_by_id),M=w(`library`,`delete`,e.created_by_id),N=[];if(o&&Ze(e)&&N.push({label:O(`common.print`),icon:(0,z.jsx)(me,{className:`w-4 h-4 text-bambu-green`}),onClick:()=>o(e),disabled:!C(`queue:create`),title:C(`queue:create`)?void 0:O(`fileManager.noPermissionAddToQueue`)}),Qe(e,!!u,d)&&(u?s:c)&&N.push({label:O(`slice.action`),icon:u?(0,z.jsx)(y,{className:`w-4 h-4`}):(0,z.jsx)(fe,{className:`w-4 h-4`}),onClick:()=>{u?s?.(e):c?.(e)},disabled:!f,title:f?void 0:O(u?`fileManager.noPermissionSlice`:`fileManager.noPermissionDownload`)}),l&&u&&Qe(e,!0,d)&&N.push({label:O(`library.runWithPipeline.actionLabel`),icon:(0,z.jsx)(te,{className:`w-4 h-4`}),onClick:()=>l(e),disabled:!C(`pipelines:run`),title:C(`pipelines:run`)?void 0:O(`library.runWithPipeline.noPermission`)}),m&&il(e)){let t=ol(e);N.push({label:O(t?`fileManager.preview3d`:`fileManager.preview.open`),icon:t?(0,z.jsx)(p,{className:`w-4 h-4`}):sl(e.file_type),onClick:()=>m(e),disabled:!ee,title:ee?void 0:O(`fileManager.noPermissionPreview`)})}return N.push({label:O(`common.download`),icon:(0,z.jsx)(Le,{className:`w-4 h-4`}),onClick:()=>i(e.id),disabled:!C(`library:read`),title:C(`library:read`)?void 0:O(`fileManager.noPermissionDownload`)}),h&&N.push({label:O(`common.rename`),icon:(0,z.jsx)(ue,{className:`w-4 h-4`}),onClick:()=>h(e),disabled:!j,title:j?void 0:O(`fileManager.noPermissionRenameFile`)}),g&&N.push({label:O(`fileManager.details.title`),icon:(0,z.jsx)(_,{className:`w-4 h-4`}),onClick:()=>g(e),disabled:!ee,title:ee?void 0:O(`fileManager.noPermissionPreview`)}),e.external_url&&N.push({label:O(`fileManager.details.openLink`),icon:(0,z.jsx)(Me,{className:`w-4 h-4`}),onClick:()=>window.open(e.external_url,`_blank`,`noopener,noreferrer`)}),v&&cl(e.file_type)&&N.push({label:O(`fileManager.generateThumbnail`),icon:(0,z.jsx)(Fe,{className:`w-4 h-4`}),onClick:()=>v(e),disabled:!j,title:j?void 0:O(`fileManager.noPermissionGenerateThumbnail`)}),N.push({label:O(`common.delete`),icon:(0,z.jsx)(de,{className:`w-4 h-4`}),onClick:()=>r(e.id),danger:!0,disabled:!M,title:M?void 0:O(`fileManager.noPermissionDeleteFile`)}),(0,z.jsxs)(`div`,{className:`group relative bg-bambu-dark-secondary rounded-lg border transition-all cursor-pointer ${t?`border-bambu-green ring-1 ring-bambu-green`:`border-bambu-dark-tertiary hover:border-bambu-green/50`}`,onClick:()=>n(e.id),onDoubleClick:()=>m?.(e),children:[(0,z.jsxs)(`div`,{className:`aspect-square bg-bambu-dark flex items-center justify-center overflow-hidden rounded-t-lg`,children:[e.thumbnail_path?(0,z.jsx)(`img`,{src:`${a.getLibraryFileThumbnailUrl(e.id)}${S?(a.getLibraryFileThumbnailUrl(e.id).includes(`?`)?`&`:`?`)+`v=${S}`:``}`,loading:`lazy`,alt:e.filename,className:`w-full h-full object-cover`}):(0,z.jsx)(nl,{fileType:e.file_type,className:`w-12 h-12 text-bambu-gray/30`}),(0,z.jsx)(`div`,{className:`absolute top-2 right-2 text-xs px-1.5 py-0.5 rounded font-medium ${e.file_type===`3mf`?`bg-bambu-green/90 text-white`:e.file_type===`gcode`||e.file_type===`gcode.3mf`?`bg-blue-500/90 text-white`:e.file_type===`stl`?`bg-purple-500/90 text-white`:Zc(e.file_type)?`bg-amber-500/90 text-white`:e.file_type===`pdf`?`bg-red-500/90 text-white`:Xc(e.file_type)?`bg-teal-500/90 text-white`:`bg-bambu-gray/90 text-white`}`,children:e.file_type.toUpperCase()})]}),(0,z.jsxs)(`div`,{className:`p-3`,children:[(0,z.jsx)(`h3`,{className:`text-sm font-medium text-white truncate`,title:e.print_name||e.filename,children:e.print_name||e.filename}),(0,z.jsxs)(`div`,{className:`flex items-center gap-3 mt-1 text-xs text-bambu-gray`,children:[(0,z.jsx)(`span`,{children:oe(e.file_size)}),e.print_time_seconds&&(0,z.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,z.jsx)(ve,{className:`w-3 h-3`}),ce(e.print_time_seconds)]})]}),e.sliced_for_model&&(0,z.jsxs)(`div`,{className:`mt-1 text-xs text-bambu-gray flex items-center gap-1`,children:[(0,z.jsx)(me,{className:`w-3 h-3`}),e.sliced_for_model]}),(e.variant_count??0)>1&&(0,z.jsxs)(`div`,{className:`mt-1 text-xs text-bambu-green flex items-center gap-1`,children:[(0,z.jsx)(je,{className:`w-3 h-3`}),O(`fileManager.variants.badge`,{count:e.variant_count})]}),e.print_count>0&&(0,z.jsx)(`div`,{className:`mt-1 text-xs text-bambu-green`,children:O(`fileManager.printedCount`,{count:e.print_count})}),(e.external_url||e.has_notes||(e.photo_count??0)>0)&&(0,z.jsxs)(`div`,{className:`mt-1 flex items-center gap-2 text-xs text-bambu-gray`,...al,children:[e.external_url&&(0,z.jsx)(`a`,{href:e.external_url,target:`_blank`,rel:`noopener noreferrer`,className:`p-0.5 rounded hover:text-bambu-green`,title:O(`fileManager.details.openLink`),"aria-label":O(`fileManager.details.openLink`),children:(0,z.jsx)(Me,{className:`w-3.5 h-3.5`})}),e.has_notes&&(0,z.jsx)(`button`,{type:`button`,onClick:()=>g?.(e),className:`p-0.5 rounded hover:text-bambu-green`,title:O(`fileManager.details.hasNotes`),"aria-label":O(`fileManager.details.hasNotes`),children:(0,z.jsx)(ne,{className:`w-3.5 h-3.5`})}),(e.photo_count??0)>0&&(0,z.jsxs)(`button`,{type:`button`,onClick:()=>g?.(e),className:`flex items-center gap-0.5 p-0.5 rounded hover:text-bambu-green`,title:O(`fileManager.details.photoCount`,{count:e.photo_count}),"aria-label":O(`fileManager.details.photoCount`,{count:e.photo_count}),children:[(0,z.jsx)(be,{className:`w-3.5 h-3.5`}),(0,z.jsx)(`span`,{children:e.photo_count})]})]}),E&&e.created_by_username&&(0,z.jsxs)(`div`,{className:`mt-1 text-xs text-bambu-gray flex items-center gap-1`,children:[(0,z.jsx)(ye,{className:`w-3 h-3`}),e.created_by_username]}),D&&(0,z.jsxs)(`div`,{className:`mt-1 text-xs text-bambu-gray flex items-center gap-1`,title:O(`fileManager.lastModified`),children:[(0,z.jsx)(tt,{className:`w-3 h-3`}),se(e.fs_modified_at??e.created_at)]}),(e.tags?.length??0)>0&&(0,z.jsx)(`div`,{className:`mt-2 flex flex-wrap gap-1`,...al,children:e.tags.map(e=>(0,z.jsxs)(`button`,{type:`button`,onClick:()=>b?.(e.id),className:`inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded-full text-[10px] bg-bambu-green/10 text-bambu-green hover:bg-bambu-green/20 transition-colors max-w-full`,title:e.name,children:[(0,z.jsx)(xe,{className:`w-2.5 h-2.5 flex-shrink-0`}),(0,z.jsx)(`span`,{className:`truncate`,children:e.name})]},e.id))})]}),(0,z.jsxs)(`div`,{className:`absolute bottom-2 right-2 transition-opacity can-hover:opacity-0 group-hover:opacity-100 group-focus-within:opacity-100`,...al,children:[(0,z.jsx)(`button`,{onClick:e=>{let t=e.currentTarget.getBoundingClientRect();A({x:t.left,y:t.bottom+4})},className:`p-1.5 rounded bg-bambu-dark-secondary/90 hover:bg-bambu-dark-tertiary`,children:(0,z.jsx)(x,{className:`w-4 h-4 text-bambu-gray`})}),k&&(0,z.jsx)(T,{x:k.x,y:k.y,items:N,onClose:()=>A(null)})]}),(0,z.jsx)(`div`,{className:`absolute top-2 left-2 w-5 h-5 rounded border-2 flex items-center justify-center transition-all ${t?`bg-bambu-green border-bambu-green`:`border-white/30 bg-black/30 can-hover:opacity-0 group-hover:opacity-100 group-focus-within:opacity-100`}`,children:t&&(0,z.jsx)(`div`,{className:`w-2 h-2 bg-white rounded-sm`})})]})}function Cl({file:e,onPrint:t,onSlice:n,onOpenInSlicer:r,onRunPipeline:i,useSlicerApi:a,desktopSlicer:o,canSlice:s,onPreview:c,onDetails:l,onDownload:u,onRename:d,onGenerateThumbnail:f,thumbnailPending:m,onDelete:h,hasPermission:g,canModify:v,tabIndex:b,t:x}){let S=v(`library`,`update`,e.created_by_id),C=v(`library`,`delete`,e.created_by_id);return(0,z.jsxs)(`div`,{className:`flex items-center gap-1`,"data-file-actions":!0,...al,children:[Ze(e)&&(0,z.jsx)(`button`,{tabIndex:b,onClick:()=>g(`queue:create`)&&t(e),className:`p-1.5 rounded transition-colors ${g(`queue:create`)?`hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green`:`text-bambu-gray/50 cursor-not-allowed`}`,title:g(`queue:create`)?x(`common.print`):x(`fileManager.noPermissionAddToQueue`),disabled:!g(`queue:create`),children:(0,z.jsx)(me,{className:`w-4 h-4`})}),Qe(e,a,o)&&(0,z.jsx)(`button`,{tabIndex:b,onClick:()=>{s&&(a?n:r)(e)},className:`p-1.5 rounded transition-colors ${s?`hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green`:`text-bambu-gray/50 cursor-not-allowed`}`,title:x(s?`slice.action`:a?`fileManager.noPermissionSlice`:`fileManager.noPermissionDownload`),disabled:!s,children:a?(0,z.jsx)(y,{className:`w-4 h-4`}):(0,z.jsx)(fe,{className:`w-4 h-4`})}),a&&Qe(e,!0,o)&&(0,z.jsx)(`button`,{tabIndex:b,onClick:()=>g(`pipelines:run`)&&i(e),className:`p-1.5 rounded transition-colors ${g(`pipelines:run`)?`hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green`:`text-bambu-gray/50 cursor-not-allowed`}`,title:g(`pipelines:run`)?x(`library.runWithPipeline.actionLabel`):x(`library.runWithPipeline.noPermission`),disabled:!g(`pipelines:run`),children:(0,z.jsx)(te,{className:`w-4 h-4`})}),ol(e)&&(0,z.jsx)(`button`,{tabIndex:b,onClick:()=>g(`library:read`)&&c(e),className:`p-1.5 rounded transition-colors ${g(`library:read`)?`hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green`:`text-bambu-gray/50 cursor-not-allowed`}`,title:g(`library:read`)?x(`fileManager.preview3d`):x(`fileManager.noPermissionPreview`),disabled:!g(`library:read`),children:(0,z.jsx)(p,{className:`w-4 h-4`})}),!ol(e)&&il(e)&&(0,z.jsx)(`button`,{tabIndex:b,onClick:()=>g(`library:read`)&&c(e),className:`p-1.5 rounded transition-colors ${g(`library:read`)?`hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green`:`text-bambu-gray/50 cursor-not-allowed`}`,title:g(`library:read`)?x(`fileManager.preview.open`):x(`fileManager.noPermissionPreview`),disabled:!g(`library:read`),children:sl(e.file_type)}),(0,z.jsx)(`button`,{tabIndex:b,onClick:()=>g(`library:read`)&&u(e.id),className:`p-1.5 rounded transition-colors ${g(`library:read`)?`hover:bg-bambu-dark text-bambu-gray hover:text-white`:`text-bambu-gray/50 cursor-not-allowed`}`,title:g(`library:read`)?x(`common.download`):x(`fileManager.noPermissionDownload`),disabled:!g(`library:read`),children:(0,z.jsx)(Le,{className:`w-4 h-4`})}),(0,z.jsx)(`button`,{tabIndex:b,onClick:()=>g(`library:read`)&&l(e),className:`p-1.5 rounded transition-colors ${g(`library:read`)?`hover:bg-bambu-dark text-bambu-gray hover:text-white`:`text-bambu-gray/50 cursor-not-allowed`}`,title:g(`library:read`)?x(`fileManager.details.title`):x(`fileManager.noPermissionPreview`),disabled:!g(`library:read`),children:(0,z.jsx)(_,{className:`w-4 h-4`})}),(0,z.jsx)(`button`,{tabIndex:b,onClick:()=>S&&d(e),className:`p-1.5 rounded transition-colors ${S?`hover:bg-bambu-dark text-bambu-gray hover:text-white`:`text-bambu-gray/50 cursor-not-allowed`}`,title:x(S?`common.rename`:`fileManager.noPermissionRenameFile`),disabled:!S,children:(0,z.jsx)(ue,{className:`w-4 h-4`})}),cl(e.file_type)&&(0,z.jsx)(`button`,{tabIndex:b,onClick:()=>S&&f(e),className:`p-1.5 rounded transition-colors ${S?`hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green`:`text-bambu-gray/50 cursor-not-allowed`}`,title:x(S?`fileManager.generateThumbnail`:`fileManager.noPermissionGenerateThumbnail`),disabled:m||!S,children:(0,z.jsx)(Fe,{className:`w-4 h-4`})}),(0,z.jsx)(`button`,{tabIndex:b,onClick:()=>C&&h(e.id),className:`p-1.5 rounded transition-colors ${C?`hover:bg-bambu-dark text-bambu-gray hover:text-red-700 dark:hover:text-red-400`:`text-bambu-gray/50 cursor-not-allowed`}`,title:x(C?`common.delete`:`fileManager.noPermissionDeleteFile`),disabled:!C,children:(0,z.jsx)(de,{className:`w-4 h-4`})})]})}function wl({file:e,isSelected:t,isFocused:n,showModified:r,thumbnailVersion:i,onSelect:o,onOpen:s,actionProps:c,t:l}){let u=a.getLibraryFileThumbnailUrl(e.id);return(0,z.jsxs)(`div`,{"data-file-id":e.id,onClick:()=>o(e),onDoubleClick:()=>s(e),className:`group flex items-center gap-3 px-3 py-2 cursor-pointer transition-colors ${t?`bg-bambu-green/10`:`hover:bg-bambu-dark`} ${n?`ring-1 ring-inset ring-bambu-green/60`:``}`,title:e.print_name||e.filename,children:[(0,z.jsx)(`div`,{className:`w-4 h-4 rounded border-2 flex-shrink-0 flex items-center justify-center ${t?`bg-bambu-green border-bambu-green`:`border-bambu-gray/50`}`,children:t&&(0,z.jsx)(`div`,{className:`w-1.5 h-1.5 bg-white rounded-sm`})}),(0,z.jsx)(`div`,{className:`w-10 h-10 rounded bg-bambu-dark flex-shrink-0 overflow-hidden flex items-center justify-center`,children:e.thumbnail_path?(0,z.jsx)(`img`,{src:`${u}${i?(u.includes(`?`)?`&`:`?`)+`v=${i}`:``}`,loading:`lazy`,alt:``,className:`w-full h-full object-cover`}):(0,z.jsx)(nl,{fileType:e.file_type,className:`w-5 h-5 text-bambu-gray/50`})}),(0,z.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,z.jsx)(`div`,{className:`text-sm text-white truncate`,children:e.print_name||e.filename}),(0,z.jsxs)(`div`,{className:`mt-0.5 flex items-center gap-2 text-xs text-bambu-gray`,children:[(0,z.jsx)(`span`,{className:`px-1.5 py-px rounded font-medium ${ll(e.file_type)}`,children:e.file_type.toUpperCase()}),(0,z.jsx)(`span`,{children:oe(e.file_size)}),e.print_count>0&&(0,z.jsxs)(`span`,{children:[e.print_count,`x`]}),r&&(0,z.jsxs)(`span`,{className:`flex items-center gap-1 truncate`,title:l(`fileManager.lastModified`),children:[(0,z.jsx)(tt,{className:`w-3 h-3 flex-shrink-0`}),se(e.fs_modified_at??e.created_at)]})]})]}),(0,z.jsx)(`div`,{className:`flex-shrink-0 transition-opacity ${n||t?``:`can-hover:opacity-0 group-hover:opacity-100 group-focus-within:opacity-100`}`,children:(0,z.jsx)(Cl,{file:e,...c,tabIndex:n?0:-1})})]})}function Tl(){let{t:e}=o(),t=c(),{showToast:n}=v(),{hasPermission:r,hasAnyPermission:i,canModify:s,authEnabled:f}=ze(),[p]=De(),m=Ee(),h=p.get(`folder`),[g,_]=(0,R.useState)(h?parseInt(h,10):null),[y,x]=(0,R.useState)(`internal`),[C,T]=(0,R.useState)([]),[te,ie]=(0,R.useState)(!1),[ce,le]=(0,R.useState)(!1),[ue,fe]=(0,R.useState)(!1),[F,I]=(0,R.useState)(!1),[he,ve]=(0,R.useState)([]),[Te,Pe]=(0,R.useState)(!1),[Le,Re]=(0,R.useState)(!1),[Be,Ve]=(0,R.useState)(!1),[We,qe]=(0,R.useState)([]),[Je,Ye]=(0,R.useState)(null),[ot,st]=(0,R.useState)(null),[ct,ut]=(0,R.useState)(null),[dt,pt]=(0,R.useState)(null),[ht,gt]=(0,R.useState)(!1),[_t,vt]=(0,R.useState)(null),[yt,bt]=(0,R.useState)(null),[xt,St]=(0,R.useState)(null),[Ct,wt]=(0,R.useState)({}),[Tt,B]=(0,R.useState)(null),[Et,Dt]=(0,R.useState)(null),[V,H]=(0,R.useState)(null),[Ot,U]=(0,R.useState)(null),[W,kt]=(0,R.useState)(null),[G,At]=(0,R.useState)(()=>localStorage.getItem(`library-view-mode`)||`grid`),jt=(0,R.useRef)(null),[K,Mt]=(0,R.useState)(null),[Nt,Pt]=(0,R.useState)(()=>localStorage.getItem(`library-wrap-folders`)===`true`),[Ft,It]=(0,R.useState)(()=>localStorage.getItem(`library-collapse-folders`)===`true`),[Lt,Rt]=(0,R.useState)(()=>localStorage.getItem(`library-folder-sort-field`)===`activity`?`activity`:`name`),[zt,Bt]=(0,R.useState)(()=>localStorage.getItem(`library-folder-sort-direction`)===`desc`?`desc`:`asc`),[Vt,Ht]=(0,R.useState)(()=>{let e=localStorage.getItem(`library-sidebar-width`);return e?parseInt(e,10):256}),[Ut,Wt]=(0,R.useState)(!1),Gt=(0,R.useRef)(null);(0,R.useEffect)(()=>{if(!Ut)return;document.body.style.userSelect=`none`,document.body.style.cursor=`col-resize`;let e=e=>{if(!Gt.current)return;let t=Gt.current.parentElement?.getBoundingClientRect();if(!t)return;let n=e.clientX-t.left;Ht(Math.min(500,Math.max(200,n)))},t=()=>{Wt(!1),document.body.style.userSelect=``,document.body.style.cursor=``,localStorage.setItem(`library-sidebar-width`,String(Vt))};return document.addEventListener(`mousemove`,e),document.addEventListener(`mouseup`,t),()=>{document.removeEventListener(`mousemove`,e),document.removeEventListener(`mouseup`,t),document.body.style.userSelect=``,document.body.style.cursor=``}},[Ut,Vt]);let[Kt,qt]=(0,R.useState)(``),[Jt,Yt]=(0,R.useState)(`all`),[Xt,Zt]=(0,R.useState)(``),[Qt,$t]=(0,R.useState)(()=>localStorage.getItem(`library-sort-field`)||`name`),[en,tn]=(0,R.useState)(()=>localStorage.getItem(`library-sort-direction`)||`asc`),[nn,rn]=(0,R.useState)(()=>localStorage.getItem(`library-show-modified`)===`true`);(0,R.useEffect)(()=>{let e=p.get(`folder`);e&&_(parseInt(e,10))},[p]);let{data:an}=l({queryKey:[`settings`],queryFn:()=>a.getSettings()}),on=Ke(an?.open_in_slicer,an?.preferred_slicer),sn=(0,R.useCallback)(async t=>{try{let{token:e}=await a.createLibrarySlicerToken(t.id),n=a.getLibrarySlicerDownloadUrl(t.id,e,t.filename);Ge(`${window.location.origin}${n}`,on)}catch{n(e(`fileManager.toast.openInSlicerFailed`),`error`);let r=a.getLibraryFileDownloadUrl(t.id);Ge(`${window.location.origin}${r}`,on)}},[on,n,e]),cn=(0,R.useCallback)(()=>an?.use_slicer_api?r(`library:upload`):i(`library:read_all`,`library:read_own`),[an?.use_slicer_api,r,i]),{data:ln,isLoading:un}=l({queryKey:[`library-folders`],queryFn:()=>a.getLibraryFolders()}),q=(0,R.useMemo)(()=>{if(!ln)return ln;let e=t=>[...t].sort((e,t)=>{let n=0;if(Lt===`name`)n=e.name.localeCompare(t.name);else{let r=e.latest_activity_at?new Date(e.latest_activity_at).getTime():null,i=t.latest_activity_at?new Date(t.latest_activity_at).getTime():null;if(r===null&&i===null)n=e.name.localeCompare(t.name);else if(r===null)return 1;else if(i===null)return-1;else n=r-i}return zt===`asc`?n:-n}).map(t=>({...t,children:e(t.children)}));return e(ln)},[ln,Lt,zt]),{data:dn}=l({queryKey:[`library-trash-count`],queryFn:async()=>{try{return(await a.listLibraryTrash(1,0)).total}catch{return 0}},staleTime:3e4}),fn=g!==null&&Kt.trim().length>0,pn=(0,R.useMemo)(()=>[...We].sort((e,t)=>e-t),[We]),{data:mn=[]}=l({queryKey:[`library-tags`],queryFn:a.getLibraryTags}),hn=(0,R.useMemo)(()=>{let e=new Map;for(let t of mn)e.set(t.id,t.name);return e},[mn]);(0,R.useEffect)(()=>{mn.length!==0&&qe(e=>{let t=e.filter(e=>hn.has(e));return t.length===e.length?e:t})},[mn.length,hn]);let gn=(0,R.useCallback)(e=>{qe(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},[]),_n=Kt.trim().length>0||We.length>0,vn=G===`columns`&&g===null&&!_n,{data:yn,isLoading:bn}=l({queryKey:[`library-files`,g,y,fn,pn,vn],queryFn:()=>a.getLibraryFiles(g,vn,void 0,g===null?y:void 0,fn,pn)}),{data:xn}=l({queryKey:[`library-stats`],queryFn:()=>a.getLibraryStats()}),{data:Sn}=l({queryKey:[`users`,`slim`],queryFn:()=>a.getUsersSlim()}),Cn=(0,R.useMemo)(()=>{if(!yn)return[];let e=new Set(yn.map(e=>e.file_type));return Array.from(e).sort()},[yn]),J=(0,R.useMemo)(()=>ul(yn??[],{query:Kt,filterType:Jt,filterUsername:Xt,sortField:Qt,sortDirection:en}),[yn,Kt,Jt,Xt,Qt,en]),wn=(0,R.useMemo)(()=>{if(!xn||!an)return!1;let e=(an.library_disk_warning_gb||5)*1024*1024*1024;return xn.disk_free_bytesa.createLibraryFolder(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-folders`]}),ie(!1),n(e(`fileManager.toast.folderCreated`),`success`)},onError:e=>n(e.message,`error`)}),En=u({mutationFn:async e=>{let t=await a.createExternalFolder(e);return await a.scanExternalFolder(t.id),t},onSuccess:r=>{t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-stats`]}),le(!1),_(r.id),n(e(`fileManager.toast.externalFolderLinked`),`success`)},onError:e=>n(e.message,`error`)}),Dn=u({mutationFn:e=>a.scanExternalFolder(e),onSuccess:r=>{t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-stats`]}),n(e(`fileManager.toast.folderScanned`,{added:r.added,removed:r.removed}),`success`)},onError:e=>n(e.message,`error`)}),On=u({mutationFn:e=>a.deleteLibraryFolder(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-stats`]}),g===ot?.id&&_(null),st(null),n(e(`fileManager.toast.folderDeleted`),`success`)},onError:e=>{st(null),n(e.message,`error`)}}),kn=u({mutationFn:e=>a.deleteLibraryFile(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-stats`]}),t.invalidateQueries({queryKey:[`library-trash-count`]}),T(e=>e.filter(e=>e!==ot?.id)),st(null),n(e(`fileManager.toast.fileDeleted`),`success`)},onError:e=>{st(null),n(e.message,`error`)}}),An=u({mutationFn:e=>a.createVariantGroup(e.map(e=>({library_file_id:e}))),onSuccess:r=>{t.invalidateQueries({queryKey:[`library-files`]}),n(e(`fileManager.variants.grouped`,{count:r.members.length}),`success`),T([])},onError:e=>n(e.message,`error`)}),jn=u({mutationFn:e=>a.bulkDeleteLibrary(e,[]),onSuccess:(r,i)=>{t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-stats`]}),t.invalidateQueries({queryKey:[`library-trash-count`]}),n(e(`fileManager.toast.filesDeleted`,{count:i.length}),`success`),T([]),st(null)},onError:e=>{st(null),n(e.message,`error`)}}),Mn=u({mutationFn:({fileIds:e,folderId:t})=>a.moveLibraryFiles(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-folders`]}),T([]),fe(!1),n(e(`fileManager.toast.filesMoved`),`success`)},onError:e=>n(e.message,`error`)}),Nn=u({mutationFn:({id:e,data:t})=>a.updateLibraryFolder(e,t),onSuccess:(r,i)=>{t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`project-folders`]}),t.invalidateQueries({queryKey:[`archive-folders`]}),Ye(null),n(i.data.project_id===0&&i.data.archive_id===0?e(`fileManager.toast.folderUnlinked`):e(`fileManager.toast.folderLinked`),`success`)},onError:e=>n(e.message,`error`)}),Pn=u({mutationFn:({id:e,filename:t})=>a.updateLibraryFile(e,{filename:t}),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-files`]}),St(null),n(e(`fileManager.toast.fileRenamed`),`success`)},onError:e=>{St(null),n(e.message,`error`)}}),Fn=u({mutationFn:({id:e,name:t})=>a.updateLibraryFolder(e,{name:t}),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-files`]}),St(null),n(e(`fileManager.toast.folderRenamed`),`success`)},onError:e=>{St(null),n(e.message,`error`)}}),In=u({mutationFn:({id:e,shared:t})=>a.updateLibraryFolder(e,{shared:t}),onSuccess:(r,i)=>{t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`project-folders`]}),t.invalidateQueries({queryKey:[`archive-folders`]}),n(i.shared?e(`fileManager.toast.folderShared`):e(`fileManager.toast.folderUnshared`),`success`)},onError:e=>n(e.message,`error`)}),Ln=e=>In.mutate({id:e.id,shared:!e.shared}),Rn=u({mutationFn:()=>a.batchGenerateStlThumbnails({all_missing:!0}),onSuccess:r=>{if(t.invalidateQueries({queryKey:[`library-files`]}),r.succeeded>0){let e=Date.now(),t={};r.results.forEach(n=>{n.success&&(t[n.file_id]=e)}),wt(e=>({...e,...t}))}r.succeeded>0&&r.failed===0?n(e(`fileManager.toast.thumbnailsGenerated`,{count:r.succeeded}),`success`):r.succeeded>0&&r.failed>0?n(e(`fileManager.toast.thumbnailsGeneratedPartial`,{succeeded:r.succeeded,failed:r.failed}),`success`):r.processed===0?n(e(`fileManager.toast.noStlMissingThumbnails`),`info`):n(e(`fileManager.toast.failedToGenerateThumbnails`,{error:r.results[0]?.error||`Unknown error`}),`error`)},onError:e=>n(e.message,`error`)}),zn=u({mutationFn:e=>a.batchGenerateStlThumbnails({file_ids:[e]}),onSuccess:r=>{if(t.invalidateQueries({queryKey:[`library-files`]}),r.succeeded>0){let t=r.results[0]?.file_id;t&&wt(e=>({...e,[t]:Date.now()})),n(e(`fileManager.toast.thumbnailGenerated`),`success`)}else n(e(`fileManager.toast.failedToGenerateThumbnail`,{error:r.results[0]?.error||`Unknown error`}),`error`)},onError:e=>n(e.message,`error`)}),Bn=(0,R.useCallback)(e=>{r(`library:read`)&&(Ze(e)?m(`/gcode-viewer?library_file=${e.id}`):e.file_type===`3mf`||e.file_type===`stl`||Zc(e.file_type)?B(e):e.file_type===`pdf`?Dt(e):Xc(e.file_type)?H(e):tl(e.file_type)&&kt(e))},[r,m]),Vn=(0,R.useCallback)(e=>{T(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},[]),Hn=(0,R.useCallback)(()=>{if(J.length>0){let e=J.map(e=>e.id);T(t=>G===`columns`?[...new Set([...t,...e])]:e)}},[J,G]),Un=J.length>0&&J.every(e=>C.includes(e.id)),Wn=(0,R.useCallback)(()=>{T([])},[]),Gn=()=>{t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-stats`]})},Y=(0,R.useMemo)(()=>{if(!g||!ln)return null;let e=t=>{for(let n of t){if(n.id===g)return n;let t=e(n.children);if(t)return t}return null};return e(ln)},[g,ln]),Kn=Y?.can_write!==!1,qn=r(`library:upload`)&&Kn,Jn=r(`library:upload`)?Kn?void 0:e(`fileManager.folderNotWritable`):void 0,{isDraggingOver:Yn,dragHandlers:Xn}=He({disabled:!qn||F,onFiles:e=>{ve(e),I(!0)}}),Zn=(0,R.useCallback)(e=>{if(!e.thumbnail_path&&s(`library`,`update`,e.created_by_id))return n=>{a.uploadLibraryPreviewThumbnail(e.id,n).then(n=>{n.updated&&(wt(t=>({...t,[e.id]:(t[e.id]||0)+1})),t.invalidateQueries({queryKey:[`library-files`]}))}).catch(()=>{})}},[s,t]),Qn=e=>{a.downloadLibraryFile(e).catch(e=>{console.error(`Library file download failed:`,e)})},$n=()=>{ot&&(ot.type===`file`?kn.mutate(ot.id):ot.type===`folder`?On.mutate(ot.id):ot.type===`bulk`&&jn.mutate(C))},er=On.isPending||kn.isPending||jn.isPending,tr=e=>{At(e),localStorage.setItem(`library-view-mode`,e)},nr={onPrint:ut,onSlice:pt,onOpenInSlicer:sn,onRunPipeline:bt,useSlicerApi:an?.use_slicer_api??!1,desktopSlicer:on,canSlice:cn(),onPreview:Bn,onDetails:U,onDownload:Qn,onRename:e=>St({type:`file`,id:e.id,name:e.filename}),onGenerateThumbnail:e=>zn.mutate(e.id),thumbnailPending:zn.isPending,onDelete:e=>st({type:`file`,id:e}),hasPermission:r,canModify:s,t:e},rr=un||bn,ir=(0,R.useMemo)(()=>{if(!q||g===null)return[];let e=[],t=n=>{for(let r of n){if(e.push(r),r.id===g||t(r.children))return!0;e.pop()}return!1};return t(q),e},[q,g]),ar=ir.length>0?!!ir[0].is_external:y===`external`,X=(0,R.useMemo)(()=>{let e=[{key:`root`,folderId:null,items:(q??[]).filter(e=>!!e.is_external===ar),activeId:ir[0]?.id??null}];return ir.forEach((t,n)=>{t.children.length>0&&e.push({key:`folder-${t.id}`,folderId:t.id,items:t.children,activeId:ir[n+1]?.id??null})}),e},[q,ir,ar]),Z=(0,R.useMemo)(()=>G!==`columns`||_n?[]:X.filter(e=>e.folderId!==g).map(e=>({key:e.key,folderId:e.folderId,scope:e.folderId===null?ar?`external`:`internal`:void 0})),[G,_n,X,g,ar]),Q=d({combine:rl,queries:Z.map(e=>({queryKey:[`library-files`,`column`,e.folderId,e.scope??null],queryFn:()=>a.getLibraryFiles(e.folderId,e.folderId===null,void 0,e.scope,!1,[])}))}),or=new Map;Z.forEach((e,t)=>{let n=Q.results[t];or.set(e.key,{files:ul(n?.data??[],{filterType:Jt,filterUsername:Xt,sortField:Qt,sortDirection:en}),loading:!!n?.isPending})});let sr=(0,R.useMemo)(()=>{let e=new Map;for(let t of[...yn??[],...Q.files])e.set(t.id,t);return e},[yn,Q.files]),cr=(0,R.useMemo)(()=>{if(C.length!==1)return null;let e=sr.get(C[0]);return e&&il(e)?e:null},[sr,C]),lr=(0,R.useMemo)(()=>C.map(e=>sr.get(e)).filter(e=>!!e&&Ze(e)),[sr,C]),$=(0,R.useMemo)(()=>{let e=C.map(e=>sr.get(e)).filter(e=>!!e&&e.filename.toLowerCase().endsWith(`.stl`));return e.length===C.length?e:[]},[sr,C]),{data:ur}=l({queryKey:[`variant-group`,ct?.variant_group_id],queryFn:()=>a.getVariantGroup(ct.variant_group_id),enabled:!!ct?.variant_group_id}),dr=(0,R.useMemo)(()=>{if(ct){if(lr.length>1)return lr.map(e=>({id:e.id,filename:e.filename,sliced_for_model:e.sliced_for_model}));if(ur&&ur.members.length>1)return ur.members.map(e=>({id:e.library_file_id,filename:e.filename,sliced_for_model:e.target_model}))}},[ct,lr,ur]),fr=K===null?void 0:Z.map(e=>or.get(e.key)?.files).find(e=>e?.some(e=>e.id===K)),pr=fr??J;(0,R.useEffect)(()=>{G===`columns`&&jt.current?.focus({preventScroll:!0})},[G]),(0,R.useEffect)(()=>{Mt(null)},[g,G]),(0,R.useEffect)(()=>{T([])},[g]),(0,R.useEffect)(()=>{G!==`columns`||g===null||jt.current?.querySelector(`[data-folder-id="${g}"]`)?.scrollIntoView?.({block:`nearest`})},[g,G]),(0,R.useEffect)(()=>{G!==`columns`||K===null||jt.current?.querySelector(`[data-file-id="${K}"]`)?.scrollIntoView?.({block:`nearest`})},[K,G]);let mr=()=>{let e=jt.current;if(e){if(K!==null)e.querySelector(`[data-file-id="${K}"] [data-file-actions] button:not([disabled])`)?.focus();else if(g!==null){let t=e.querySelector(`[data-folder-id="${g}"] [data-folder-actions] button`);t?.focus(),t?.click()}}},hr=e=>{if(e.ctrlKey||e.metaKey||e.altKey)return;let t=e.target;if(t.tagName===`INPUT`||t.tagName===`TEXTAREA`||t.tagName===`SELECT`||t.isContentEditable)return;if(t.closest(`[data-folder-actions]`)){if(e.key===`Escape`){e.preventDefault(),jt.current?.focus({preventScroll:!0});return}if(e.key!==`ArrowUp`&&e.key!==`ArrowDown`)return;jt.current?.focus({preventScroll:!0})}let n=t.closest(`[data-file-actions]`);if(n){if(e.key===`Enter`||e.key===` `)return;if(e.key===`ArrowLeft`||e.key===`ArrowRight`){e.preventDefault();let r=Array.from(n.querySelectorAll(`button:not([disabled])`));r[r.indexOf(t)+(e.key===`ArrowRight`?1:-1)]?.focus();return}if(e.key===`Escape`){e.preventDefault(),jt.current?.focus({preventScroll:!0});return}(e.key===`ArrowUp`||e.key===`ArrowDown`)&&jt.current?.focus({preventScroll:!0})}if(e.key===`ContextMenu`||e.key===`F10`&&e.shiftKey){e.preventDefault(),mr();return}let r=K!==null,i=ir[ir.length-1];switch(e.key){case`ArrowDown`:case`ArrowUp`:{e.preventDefault();let t=e.key===`ArrowDown`?1:-1;if(r||_n){let e=pr.findIndex(e=>e.id===K),n=pr[e+t];n?Mt(n.id):t===-1&&e===0&&fr&&Mt(null)}else if(g===null)t===1&&X[0].items.length>0&&_(X[0].items[0].id);else{let e=X[ir.length-1],n=e?e.items.findIndex(e=>e.id===g):-1,r=n===-1?void 0:e.items[n+t];if(r)_(r.id);else if(t===1&&n!==-1){let t=e?or.get(e.key)?.files:void 0;t?.length&&Mt(t[0].id)}}break}case`ArrowRight`:if(e.preventDefault(),r)break;!_n&&i&&i.children.length>0?_(i.children[0].id):J.length>0&&Mt(J[0].id);break;case`ArrowLeft`:if(e.preventDefault(),r){Mt(null);break}if(_n)break;ir.length>1?_(ir[ir.length-2].id):ir.length===1?(x(ir[0].is_external?`external`:`internal`),_(null)):g!==null&&_(null);break;case`Enter`:{if(e.preventDefault(),!r){!_n&&i&&i.children.length>0?_(i.children[0].id):J.length>0&&Mt(J[0].id);break}let t=pr.find(e=>e.id===K);t&&Bn(t);break}case` `:if(e.preventDefault(),!r)break;K!==null&&Vn(K);break}};return(0,z.jsxs)(`div`,{className:`p-4 md:p-8 min-h-[calc(100vh-64px)] lg:h-screen flex flex-col relative`,...Xn,children:[Yn&&(0,z.jsx)(`div`,{className:`fixed inset-0 z-50 bg-bambu-dark/90 flex items-center justify-center pointer-events-none`,children:(0,z.jsxs)(`div`,{className:`border-4 border-dashed border-bambu-green rounded-xl p-12 text-center`,children:[(0,z.jsx)(Ne,{className:`w-16 h-16 mx-auto mb-4 text-bambu-green`}),(0,z.jsx)(`p`,{className:`text-2xl font-semibold text-white mb-2`,children:e(`fileManager.dropFilesHere`)}),(0,z.jsx)(`p`,{className:`text-bambu-gray`,children:e(`fileManager.releaseToUpload`)})]})}),(0,z.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-4 mb-6`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,z.jsx)(Ie,{className:`w-7 h-7 text-bambu-green`}),e(`fileManager.title`)]}),(0,z.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:e(`fileManager.subtitle`)})]}),(0,z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,z.jsxs)(`div`,{className:`flex items-center bg-bambu-dark rounded-lg p-1`,children:[(0,z.jsx)(`button`,{onClick:()=>tr(`grid`),className:`p-1.5 rounded transition-colors ${G===`grid`?`bg-bambu-dark-secondary text-white`:`text-bambu-gray hover:text-white`}`,title:e(`fileManager.gridView`),children:(0,z.jsx)(k,{className:`w-4 h-4`})}),(0,z.jsx)(`button`,{onClick:()=>tr(`list`),className:`p-1.5 rounded transition-colors ${G===`list`?`bg-bambu-dark-secondary text-white`:`text-bambu-gray hover:text-white`}`,title:e(`fileManager.listView`),children:(0,z.jsx)(ee,{className:`w-4 h-4`})}),(0,z.jsx)(`button`,{onClick:()=>tr(`columns`),className:`p-1.5 rounded transition-colors ${G===`columns`?`bg-bambu-dark-secondary text-white`:`text-bambu-gray hover:text-white`}`,title:e(`fileManager.columnsView`),children:(0,z.jsx)(b,{className:`w-4 h-4`})})]}),(0,z.jsxs)(P,{variant:`secondary`,onClick:()=>Rn.mutate(),disabled:Rn.isPending||!i(`library:update_own`,`library:update_all`),title:i(`library:update_own`,`library:update_all`)?e(`fileManager.generateThumbnailsForMissing`):e(`fileManager.noPermissionGenerateThumbnail`),children:[Rn.isPending?(0,z.jsx)(j,{className:`w-4 h-4 mr-2 animate-spin`}):(0,z.jsx)(Fe,{className:`w-4 h-4 mr-2`}),e(`fileManager.generateThumbnails`)]}),(0,z.jsxs)(P,{variant:`secondary`,onClick:()=>le(!0),disabled:!r(`library:upload`),title:r(`library:upload`)?e(`fileManager.linkExternalFolder`):e(`fileManager.noPermissionCreateFolder`),children:[(0,z.jsx)(it,{className:`w-4 h-4 mr-2`}),e(`fileManager.linkExternal`)]}),(0,z.jsxs)(P,{variant:`secondary`,onClick:()=>ie(!0),disabled:!qn,title:r(`library:upload`)?Jn:e(`fileManager.noPermissionCreateFolder`),children:[(0,z.jsx)(rt,{className:`w-4 h-4 mr-2`}),e(`fileManager.newFolder`)]}),(0,z.jsxs)(P,{variant:`secondary`,onClick:()=>Re(!0),title:e(`fileManager.tags.manageTitle`),children:[(0,z.jsx)(xe,{className:`w-4 h-4 mr-2`}),e(`fileManager.tags.manage`)]}),r(`library:purge`)&&(0,z.jsxs)(P,{variant:`secondary`,onClick:()=>Pe(!0),title:e(`libraryPurge.headerTooltip`),children:[(0,z.jsx)(de,{className:`w-4 h-4 mr-2`}),e(`libraryPurge.headerButton`)]}),i(`library:delete_own`,`library:delete_all`)&&(0,z.jsxs)(Se,{to:`/files/trash`,className:`inline-flex items-center px-3 py-1.5 text-sm rounded bg-bambu-dark-secondary text-bambu-gray hover:text-white hover:bg-bambu-dark transition-colors`,title:e(`libraryTrash.headerTooltip`),children:[(0,z.jsx)(de,{className:`w-4 h-4 mr-2`}),e(`libraryTrash.headerButton`),typeof dn==`number`&&dn>0&&(0,z.jsx)(`span`,{className:`ml-1.5 px-1.5 py-0.5 text-xs rounded-full bg-bambu-green/20 text-bambu-green`,children:dn})]}),(0,z.jsxs)(P,{onClick:()=>I(!0),disabled:!qn,title:r(`library:upload`)?Jn:e(`fileManager.noPermissionUpload`),children:[(0,z.jsx)(Ne,{className:`w-4 h-4 mr-2`}),e(`common.upload`)]})]})]}),wn&&xn&&an&&(0,z.jsxs)(`div`,{className:`flex items-center gap-3 mb-4 p-3 bg-amber-500/10 border border-amber-500/30 rounded-lg`,children:[(0,z.jsx)(re,{className:`w-5 h-5 text-amber-500 flex-shrink-0`}),(0,z.jsxs)(`div`,{className:`flex-1`,children:[(0,z.jsx)(`p`,{className:`text-sm text-amber-500 font-medium`,children:e(`fileManager.lowDiskSpaceWarning`)}),(0,z.jsx)(`p`,{className:`text-xs text-amber-500/80`,children:e(`fileManager.lowDiskSpaceDetails`,{free:oe(xn.disk_free_bytes),total:oe(xn.disk_total_bytes),threshold:an.library_disk_warning_gb})})]})]}),xn&&(0,z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 sm:gap-6 mb-6 p-3 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,z.jsx)(w,{className:`w-4 h-4 text-bambu-green`}),(0,z.jsxs)(`span`,{className:`text-bambu-gray`,children:[e(`fileManager.files`),`:`]}),(0,z.jsx)(`span`,{className:`text-white font-medium`,children:xn.total_files})]}),(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,z.jsx)(Ie,{className:`w-4 h-4 text-blue-600 dark:text-blue-400`}),(0,z.jsxs)(`span`,{className:`text-bambu-gray`,children:[e(`fileManager.folders`),`:`]}),(0,z.jsx)(`span`,{className:`text-white font-medium`,children:xn.total_folders})]}),(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,z.jsx)(O,{className:`w-4 h-4 text-amber-600 dark:text-amber-400`}),(0,z.jsxs)(`span`,{className:`text-bambu-gray`,children:[e(`fileManager.size`),`:`]}),(0,z.jsx)(`span`,{className:`text-white font-medium`,children:oe(xn.total_size_bytes)})]}),(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-sm sm:ml-auto`,children:[(0,z.jsxs)(`span`,{className:`text-bambu-gray`,children:[e(`fileManager.free`),`:`]}),(0,z.jsx)(`span`,{className:`font-medium ${wn?`text-amber-500`:`text-white`}`,children:oe(xn.disk_free_bytes)})]})]}),(0,z.jsxs)(`div`,{className:`flex-1 flex flex-col lg:flex-row gap-4 lg:gap-6 min-h-0`,children:[(0,z.jsx)(`div`,{className:`lg:hidden`,children:(0,z.jsxs)(`select`,{value:g===null?`__top:${y}`:String(g),onChange:e=>{let t=e.target.value;t.startsWith(`__top:`)?(_(null),x(t.slice(6))):_(parseInt(t,10))},className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg px-3 py-2.5 text-white focus:outline-none focus:border-bambu-green`,children:[(0,z.jsxs)(`option`,{value:`__top:internal`,children:[`📁 `,e(`fileManager.allFiles`)]}),ln?.some(e=>e.is_external)&&(0,z.jsxs)(`option`,{value:`__top:external`,children:[`🔗 `,e(`fileManager.allExternal`)]}),q&&(()=>{let e=(t,n=0)=>{let r=[];for(let i of t)r.push({id:i.id,name:i.name,fileCount:i.file_count,depth:n}),i.children.length>0&&r.push(...e(i.children,n+1));return r};return e(q).map(e=>(0,z.jsxs)(`option`,{value:e.id,children:[`│ `.repeat(e.depth),`📂 `,e.name,` `,e.fileCount>0?`(${e.fileCount})`:``]},e.id))})()]})}),(0,z.jsxs)(`div`,{ref:Gt,"data-testid":`folder-sidebar`,className:`hidden lg:flex flex-shrink-0 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary overflow-hidden flex-col relative`,style:{width:`${Vt}px`},children:[(0,z.jsx)(`div`,{className:`absolute right-0 top-0 bottom-0 w-1.5 cursor-col-resize z-10 group/resize flex items-center justify-center transition-colors ${Ut?`bg-bambu-green`:`hover:bg-bambu-green/50`}`,onMouseDown:e=>{e.preventDefault(),Wt(!0)},onDoubleClick:()=>{Ht(256),localStorage.setItem(`library-sidebar-width`,`256`)},title:e(`fileManager.dragToResizeTooltip`),children:(0,z.jsxs)(`div`,{className:`flex flex-col gap-1 opacity-0 group-hover/resize:opacity-100 transition-opacity ${Ut?`opacity-100`:``}`,children:[(0,z.jsx)(`div`,{className:`w-0.5 h-0.5 rounded-full bg-white/70`}),(0,z.jsx)(`div`,{className:`w-0.5 h-0.5 rounded-full bg-white/70`}),(0,z.jsx)(`div`,{className:`w-0.5 h-0.5 rounded-full bg-white/70`})]})}),(0,z.jsxs)(`div`,{className:`p-3 border-b border-bambu-dark-tertiary flex items-center justify-between`,children:[(0,z.jsx)(`h2`,{className:`text-sm font-medium text-white`,children:e(`fileManager.folders`)}),(0,z.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,z.jsxs)(`select`,{value:Lt,onChange:e=>{let t=e.target.value===`activity`?`activity`:`name`;Rt(t),localStorage.setItem(`library-folder-sort-field`,t)},className:`text-xs px-1 py-0.5 rounded bg-bambu-dark border border-bambu-dark-tertiary text-bambu-gray focus:outline-none focus:border-bambu-green`,title:e(`fileManager.folderSort`),"aria-label":e(`fileManager.folderSort`),children:[(0,z.jsx)(`option`,{value:`name`,children:e(`fileManager.folderSortByName`)}),(0,z.jsx)(`option`,{value:`activity`,children:e(`fileManager.folderSortByActivity`)})]}),(0,z.jsx)(`button`,{onClick:()=>{let e=zt===`asc`?`desc`:`asc`;Bt(e),localStorage.setItem(`library-folder-sort-direction`,e)},className:`text-bambu-gray hover:text-white hover:bg-bambu-dark p-1 rounded transition-colors`,title:e(zt===`asc`?`fileManager.ascending`:`fileManager.descending`),"aria-label":e(zt===`asc`?`fileManager.ascending`:`fileManager.descending`),children:zt===`asc`?(0,z.jsx)(et,{className:`w-3.5 h-3.5`}):(0,z.jsx)($e,{className:`w-3.5 h-3.5`})}),(0,z.jsx)(`button`,{onClick:()=>{let e=!Ft;It(e),localStorage.setItem(`library-collapse-folders`,String(e))},className:`text-xs px-1.5 py-0.5 rounded transition-colors ${Ft?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:text-white hover:bg-bambu-dark`}`,title:e(Ft?`fileManager.expandFoldersByDefault`:`fileManager.collapseFoldersByDefault`),children:e(`fileManager.collapse`)}),(0,z.jsx)(`button`,{onClick:()=>{let e=!Nt;Pt(e),localStorage.setItem(`library-wrap-folders`,String(e))},className:`text-xs px-1.5 py-0.5 rounded transition-colors ${Nt?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:text-white hover:bg-bambu-dark`}`,title:e(Nt?`fileManager.disableTextWrapping`:`fileManager.enableTextWrapping`),children:e(`fileManager.wrap`)})]})]}),(0,z.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-2`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-1.5 rounded cursor-pointer transition-colors ${g===null&&y===`internal`?`bg-bambu-green/20 text-bambu-green`:`hover:bg-bambu-dark text-white`}`,onClick:()=>{_(null),x(`internal`)},children:[(0,z.jsx)(S,{className:`w-4 h-4`}),(0,z.jsx)(`span`,{className:`text-sm`,children:e(`fileManager.allFiles`)})]}),ln?.some(e=>e.is_external)&&(0,z.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-1.5 rounded cursor-pointer transition-colors ${g===null&&y===`external`?`bg-bambu-green/20 text-bambu-green`:`hover:bg-bambu-dark text-white`}`,onClick:()=>{_(null),x(`external`)},children:[(0,z.jsx)(it,{className:`w-4 h-4 text-purple-600 dark:text-purple-400`}),(0,z.jsx)(`span`,{className:`text-sm`,children:e(`fileManager.allExternal`)})]}),q?.map(t=>(0,z.jsx)(xl,{folder:t,selectedFolderId:g,onSelect:_,onDelete:e=>st({type:`folder`,id:e}),onLink:Ye,onRename:e=>St({type:`folder`,id:e.id,name:e.name}),onToggleShared:Ln,wrapNames:Nt,defaultExpanded:!Ft,showModified:nn,hasPermission:r,t:e},`${t.id}-${Ft?`c`:`e`}`))]})]}),(0,z.jsxs)(`div`,{className:`flex-1 flex flex-col lg:flex-row min-w-0 min-h-0 gap-4 lg:gap-6`,children:[(0,z.jsxs)(`div`,{className:`flex-1 flex flex-col min-w-0 min-h-0`,children:[mn.length>0&&(0,z.jsxs)(`div`,{className:`mb-3 flex flex-wrap items-center gap-2 p-2 sm:p-3 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary`,children:[(0,z.jsx)(`span`,{className:`text-xs text-bambu-gray font-medium shrink-0`,children:e(`fileManager.tags.filterLabel`)}),mn.map(e=>{let t=We.includes(e.id);return(0,z.jsxs)(`button`,{type:`button`,onClick:()=>gn(e.id),className:t?`inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs bg-bambu-green/20 text-bambu-green border border-bambu-green/40 hover:bg-bambu-green/30 transition-colors`:`inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs bg-bambu-dark text-bambu-gray border border-bambu-dark-tertiary hover:text-white hover:border-bambu-green/40 transition-colors`,title:e.name,children:[(0,z.jsx)(xe,{className:`w-3 h-3`}),(0,z.jsx)(`span`,{children:e.name}),t&&(0,z.jsx)(ae,{className:`w-3 h-3`})]},e.id)}),We.length>0&&(0,z.jsx)(`button`,{type:`button`,onClick:()=>qe([]),className:`ml-auto text-xs text-bambu-gray hover:text-white shrink-0`,children:e(`fileManager.tags.clearAll`)})]}),Y?.is_external&&(0,z.jsxs)(`div`,{className:`flex items-center gap-3 mb-4 p-3 bg-purple-50 dark:bg-purple-500/10 border border-purple-300 dark:border-purple-500/30 rounded-lg`,children:[(0,z.jsx)(it,{className:`w-5 h-5 text-purple-600 dark:text-purple-400 flex-shrink-0`}),(0,z.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,z.jsx)(`span`,{className:`text-sm font-medium text-purple-700 dark:text-purple-300`,children:e(`fileManager.externalFolder`)}),Y.external_readonly&&(0,z.jsxs)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400 flex items-center gap-1`,children:[(0,z.jsx)(M,{className:`w-3 h-3`}),e(`fileManager.readOnly`)]})]}),(0,z.jsx)(`p`,{className:`text-xs text-bambu-gray truncate font-mono`,title:Y.external_path||``,children:Y.external_path})]}),(0,z.jsxs)(P,{variant:`secondary`,size:`sm`,onClick:()=>g&&Dn.mutate(g),disabled:Dn.isPending,title:e(`fileManager.scanFolder`),children:[Dn.isPending?(0,z.jsx)(j,{className:`w-4 h-4 animate-spin`}):(0,z.jsx)(L,{className:`w-4 h-4`}),(0,z.jsx)(`span`,{className:`ml-1.5`,children:e(`fileManager.scanFolder`)})]})]}),yn&&yn.length>0&&(0,z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 sm:gap-3 mb-4 p-2 sm:p-3 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary sticky top-0 z-10 lg:static`,children:[(0,z.jsxs)(`div`,{className:`relative w-full sm:w-auto sm:flex-1 sm:max-w-xs`,children:[(0,z.jsx)(N,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,z.jsx)(`input`,{type:`text`,placeholder:e(`fileManager.searchFiles`),value:Kt,onChange:e=>qt(e.target.value),className:`w-full pl-9 pr-3 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`}),fn&&(0,z.jsx)(`span`,{className:`absolute -bottom-4 left-0 text-[10px] text-bambu-gray whitespace-nowrap`,title:e(`fileManager.searchSubfoldersHint`),children:e(`fileManager.searchSubfoldersHint`)})]}),(0,z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,z.jsx)(E,{className:`w-4 h-4 text-bambu-gray hidden sm:block`}),(0,z.jsxs)(`select`,{value:Jt,onChange:e=>Yt(e.target.value),className:`bg-bambu-dark border border-bambu-dark-tertiary rounded px-2 py-1.5 text-sm text-white focus:outline-none focus:border-bambu-green`,children:[(0,z.jsx)(`option`,{value:`all`,children:e(`fileManager.allTypes`)}),Cn.map(e=>(0,z.jsx)(`option`,{value:e,children:e.toUpperCase()},e))]})]}),f&&(0,z.jsxs)(`div`,{className:`relative`,children:[(0,z.jsx)(`input`,{type:`text`,placeholder:e(`fileManager.filterByUser`,{defaultValue:`Filter by user`}),value:Xt,onChange:e=>Zt(e.target.value),list:`usernames-list`,className:`w-32 sm:w-40 px-2 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green ${Xt?`pr-7`:``}`,style:Xt?{WebkitAppearance:`none`,MozAppearance:`textfield`}:void 0}),Xt&&(0,z.jsx)(`button`,{onClick:()=>Zt(``),className:`absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white z-10`,children:(0,z.jsx)(ae,{className:`w-3 h-3`})}),(0,z.jsx)(`datalist`,{id:`usernames-list`,children:Sn?.map(e=>(0,z.jsx)(`option`,{value:e.username},e.id))})]}),(0,z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,z.jsxs)(`select`,{value:Qt,onChange:e=>{let t=e.target.value;$t(t),localStorage.setItem(`library-sort-field`,t)},className:`bg-bambu-dark border border-bambu-dark-tertiary rounded px-2 py-1.5 text-sm text-white focus:outline-none focus:border-bambu-green`,children:[(0,z.jsx)(`option`,{value:`name`,children:e(`common.name`)}),(0,z.jsx)(`option`,{value:`date`,children:e(`common.date`)}),(0,z.jsx)(`option`,{value:`size`,children:e(`fileManager.size`)}),(0,z.jsx)(`option`,{value:`type`,children:e(`common.type`)}),(0,z.jsx)(`option`,{value:`prints`,children:e(`fileManager.prints`)})]}),(0,z.jsx)(`button`,{onClick:()=>tn(e=>{let t=e===`asc`?`desc`:`asc`;return localStorage.setItem(`library-sort-direction`,t),t}),className:`p-1.5 rounded bg-bambu-dark border border-bambu-dark-tertiary hover:border-bambu-green transition-colors`,title:e(en===`asc`?`fileManager.ascending`:`fileManager.descending`),children:en===`asc`?(0,z.jsx)(et,{className:`w-4 h-4 text-white`}):(0,z.jsx)($e,{className:`w-4 h-4 text-white`})}),(0,z.jsx)(`button`,{onClick:()=>rn(e=>{let t=!e;return localStorage.setItem(`library-show-modified`,String(t)),t}),className:`p-1.5 rounded bg-bambu-dark border transition-colors ${nn?`border-bambu-green text-bambu-green`:`border-bambu-dark-tertiary text-white hover:border-bambu-green`}`,title:e(nn?`fileManager.hideModified`:`fileManager.showModified`),"aria-pressed":nn,children:(0,z.jsx)(tt,{className:`w-4 h-4`})})]}),(Kt||Jt!==`all`||Xt)&&(0,z.jsx)(`span`,{className:`text-sm text-bambu-gray hidden sm:inline`,children:e(`fileManager.resultsCount`,{showing:J.length,total:yn.length})})]}),(J.length>0||C.length>0)&&(0,z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 mb-4 p-2 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary sticky top-[52px] z-10 lg:static`,children:[Un?(0,z.jsxs)(P,{variant:`secondary`,size:`sm`,onClick:Wn,children:[(0,z.jsx)(ge,{className:`w-4 h-4 sm:mr-1`}),(0,z.jsx)(`span`,{className:`hidden sm:inline`,children:e(`fileManager.deselectAll`)})]}):(0,z.jsxs)(P,{variant:`secondary`,size:`sm`,onClick:Hn,children:[(0,z.jsx)(Ce,{className:`w-4 h-4 sm:mr-1`}),(0,z.jsx)(`span`,{className:`hidden sm:inline`,children:e(`fileManager.selectAll`)})]}),C.length>0&&(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`span`,{className:`text-sm text-bambu-gray ml-2`,children:e(`fileManager.selected`,{count:C.length})}),(0,z.jsx)(`div`,{className:`hidden sm:block flex-1`}),(0,z.jsxs)(`div`,{className:`w-full sm:w-auto flex flex-wrap items-center gap-2 mt-2 sm:mt-0`,children:[cr&&(0,z.jsxs)(P,{variant:`secondary`,size:`sm`,onClick:()=>Bn(cr),disabled:!r(`library:read`),title:r(`library:read`)?void 0:e(`fileManager.noPermissionPreview`),children:[(0,z.jsx)(we,{className:`w-4 h-4 sm:mr-1`}),(0,z.jsx)(`span`,{className:`hidden sm:inline`,children:e(`fileManager.preview.open`)})]}),lr.length>=1&&(0,z.jsxs)(P,{variant:`primary`,size:`sm`,onClick:()=>ut(lr[0]),disabled:!r(`queue:create`),title:r(`queue:create`)?void 0:e(`fileManager.noPermissionAddToQueue`),children:[(0,z.jsx)(me,{className:`w-4 h-4 sm:mr-1`}),(0,z.jsx)(`span`,{className:`hidden sm:inline`,children:lr.length>1?e(`fileManager.variants.printAlternatives`,{count:lr.length}):e(`common.print`)})]}),lr.length>=2&&!lr.some(e=>e.variant_group_id)&&(0,z.jsxs)(P,{variant:`secondary`,size:`sm`,onClick:()=>An.mutate(lr.map(e=>e.id)),disabled:An.isPending||!i(`library:update_own`,`library:update_all`),title:e(`fileManager.variants.groupTooltip`),children:[(0,z.jsx)(je,{className:`w-4 h-4 sm:mr-1`}),(0,z.jsx)(`span`,{className:`hidden sm:inline`,children:e(`fileManager.variants.groupAction`)})]}),$.length>=1&&(0,z.jsxs)(P,{variant:`secondary`,size:`sm`,onClick:()=>gt(!0),disabled:!r(`library:upload`),title:e(`fileManager.combine.tooltip`),children:[(0,z.jsx)(nt,{className:`w-4 h-4 sm:mr-1`}),(0,z.jsx)(`span`,{className:`hidden sm:inline`,children:e(`fileManager.combine.action`)})]}),(0,z.jsxs)(P,{variant:`secondary`,size:`sm`,onClick:()=>fe(!0),disabled:!i(`library:update_own`,`library:update_all`),title:i(`library:update_own`,`library:update_all`)?void 0:e(`fileManager.noPermissionMoveFiles`),children:[(0,z.jsx)(at,{className:`w-4 h-4 sm:mr-1`}),(0,z.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.move`)})]}),(0,z.jsxs)(P,{variant:`secondary`,size:`sm`,onClick:()=>Ve(!0),disabled:!i(`library:update_own`,`library:update_all`),title:i(`library:update_own`,`library:update_all`)?e(`fileManager.tags.bulkTooltip`):e(`fileManager.tags.noPermission`),children:[(0,z.jsx)(xe,{className:`w-4 h-4 sm:mr-1`}),(0,z.jsx)(`span`,{className:`hidden sm:inline`,children:e(`fileManager.tags.tagAction`)})]}),(0,z.jsxs)(P,{variant:`danger`,size:`sm`,onClick:()=>{C.length===1?st({type:`file`,id:C[0]}):st({type:`bulk`,id:0,count:C.length})},disabled:!i(`library:delete_own`,`library:delete_all`),title:i(`library:delete_own`,`library:delete_all`)?void 0:e(`fileManager.noPermissionDeleteFiles`),children:[(0,z.jsx)(de,{className:`w-4 h-4 sm:mr-1`}),(0,z.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.delete`)})]}),(0,z.jsxs)(P,{variant:`secondary`,size:`sm`,onClick:Wn,children:[(0,z.jsx)(ae,{className:`w-4 h-4 sm:mr-1`}),(0,z.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.clear`)})]})]})]})]}),rr&&G!==`columns`?(0,z.jsx)(`div`,{className:`flex-1 flex items-center justify-center`,children:(0,z.jsxs)(`div`,{className:`flex flex-col items-center gap-3`,children:[(0,z.jsx)(j,{className:`w-8 h-8 animate-spin text-bambu-green`}),(0,z.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`fileManager.loadingFiles`)})]})}):G===`columns`?(0,z.jsx)(`div`,{ref:jt,tabIndex:0,"aria-label":e(`fileManager.columnsView`),onKeyDown:hr,className:`flex-1 min-h-0 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary overflow-x-auto outline-none focus-visible:ring-1 focus-visible:ring-bambu-green/50`,"data-testid":`columns-view`,children:(0,z.jsxs)(`div`,{className:`h-full min-h-[16rem] flex divide-x divide-bambu-dark-tertiary`,children:[!_n&&X.map(t=>{let n=or.get(t.key),i=!!(n&&(n.loading||n.files.length>0));return(0,z.jsxs)(`div`,{"data-testid":`columns-level-${t.key}`,className:`${i?`w-[26rem]`:`w-64`} flex-shrink-0 overflow-y-auto py-1`,children:[t.items.map(n=>{let i=g===n.id;return(0,z.jsxs)(`div`,{"data-folder-id":n.id,className:`group flex items-center pr-1.5 transition-colors ${t.activeId===n.id?`bg-bambu-green/20 text-bambu-green`:i?`bg-bambu-green/10 text-white`:`text-white hover:bg-bambu-dark`}`,children:[(0,z.jsxs)(`button`,{type:`button`,tabIndex:-1,onClick:()=>{Mt(null),_(n.id)},className:`flex-1 min-w-0 flex items-center gap-2 pl-3 pr-1 py-2.5 text-left text-sm`,title:n.name,children:[n.is_external?(0,z.jsx)(it,{className:`w-5 h-5 flex-shrink-0 text-purple-600 dark:text-purple-400`}):(0,z.jsx)(Ie,{className:`w-5 h-5 flex-shrink-0 text-bambu-green`}),(0,z.jsx)(`span`,{className:`flex-1 truncate`,children:n.name}),(n.project_id||n.archive_id)&&(0,z.jsx)(A,{className:`w-3.5 h-3.5 flex-shrink-0 text-blue-700 dark:text-blue-400`}),n.shared&&(0,z.jsx)(`span`,{title:e(`fileManager.sharedFolder`),children:(0,z.jsx)(pe,{className:`w-3.5 h-3.5 flex-shrink-0 text-bambu-gray`})}),n.is_external&&n.external_readonly&&(0,z.jsx)(M,{className:`w-3.5 h-3.5 flex-shrink-0 text-amber-600 dark:text-amber-400`}),n.file_count>0&&(0,z.jsx)(`span`,{className:`text-xs text-bambu-gray flex-shrink-0`,children:n.file_count}),n.children.length>0&&(0,z.jsx)(_e,{className:`w-4 h-4 flex-shrink-0 text-bambu-gray`})]}),(0,z.jsx)(bl,{folder:n,onDelete:e=>st({type:`folder`,id:e}),onLink:Ye,onRename:e=>St({type:`folder`,id:e.id,name:e.name}),onToggleShared:Ln,hasPermission:r,revealOnHover:!i,tabIndex:i?0:-1,t:e})]},n.id)}),n?.loading&&(0,z.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,"aria-hidden":`true`,children:`…`}),n&&!n.loading&&n.files.map(t=>(0,z.jsx)(wl,{file:t,isSelected:C.includes(t.id),isFocused:K===t.id,showModified:nn,thumbnailVersion:Ct[t.id],onSelect:e=>{Mt(e.id),Vn(e.id)},onOpen:Bn,actionProps:nr,t:e},t.id))]},t.key)}),(0,z.jsx)(`div`,{className:`flex-1 min-w-[28rem] overflow-y-auto py-1`,"data-testid":`columns-files-pane`,children:bn?(0,z.jsx)(`div`,{className:`h-full flex items-center justify-center`,children:(0,z.jsx)(j,{className:`w-5 h-5 animate-spin text-bambu-green`})}):J.length===0?(0,z.jsx)(`div`,{className:`h-full flex items-center justify-center px-4 text-sm text-bambu-gray text-center`,children:(yn?.length??0)>0?e(`fileManager.noMatchingFiles`):g===null?vn&&X[0].items.length>0?e(`fileManager.noFilesOutsideFolders`):e(y===`external`?`fileManager.externalIsEmpty`:`fileManager.noFilesYet`):e(`fileManager.folderIsEmpty`)}):J.map(t=>(0,z.jsx)(wl,{file:t,isSelected:C.includes(t.id),isFocused:K===t.id,showModified:nn,thumbnailVersion:Ct[t.id],onSelect:e=>{Mt(e.id),Vn(e.id)},onOpen:Bn,actionProps:nr,t:e},t.id))})]})}):yn?.length===0?(0,z.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center`,children:[(0,z.jsx)(`div`,{className:`p-4 bg-bambu-dark rounded-2xl mb-4`,children:(0,z.jsx)(S,{className:`w-12 h-12 text-bambu-gray/50`})}),(0,z.jsx)(`h3`,{className:`text-lg font-medium text-white mb-2`,children:e(g===null?y===`external`?`fileManager.externalIsEmpty`:`fileManager.noFilesYet`:`fileManager.folderIsEmpty`)}),(0,z.jsx)(`p`,{className:`text-bambu-gray text-center max-w-md mb-6`,children:e(g===null?y===`external`?`fileManager.externalEmptyDescription`:`fileManager.noFilesDescription`:`fileManager.folderEmptyDescription`)}),(0,z.jsxs)(P,{onClick:()=>I(!0),disabled:!qn,title:r(`library:upload`)?Jn:e(`fileManager.noPermissionUpload`),children:[(0,z.jsx)(Oe,{className:`w-4 h-4 mr-2`}),e(`fileManager.uploadFiles`)]})]}):J.length===0?(0,z.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center`,children:[(0,z.jsx)(`div`,{className:`p-4 bg-bambu-dark rounded-2xl mb-4`,children:(0,z.jsx)(N,{className:`w-12 h-12 text-bambu-gray/50`})}),(0,z.jsx)(`h3`,{className:`text-lg font-medium text-white mb-2`,children:e(`fileManager.noMatchingFiles`)}),(0,z.jsx)(`p`,{className:`text-bambu-gray text-center max-w-md mb-6`,children:e(`fileManager.noMatchingFilesDescription`)}),(0,z.jsx)(P,{variant:`secondary`,onClick:()=>{qt(``),Yt(`all`)},children:e(`fileManager.clearFilters`)})]}):G===`grid`?(0,z.jsx)(`div`,{className:`flex-1 lg:overflow-y-auto`,children:(0,z.jsx)(`div`,{className:`grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 2xl:grid-cols-6 gap-4`,children:J.map(t=>(0,z.jsx)(Sl,{file:t,isSelected:C.includes(t.id),t:e,onSelect:Vn,onDelete:e=>st({type:`file`,id:e}),onDownload:Qn,onPrint:ut,onSlice:pt,onOpenInSlicer:sn,desktopSlicer:on,onRunPipeline:bt,useSlicerApi:an?.use_slicer_api??!1,canSlice:cn(),onPreview:Bn,onRename:e=>St({type:`file`,id:e.id,name:e.filename}),onDetails:U,onGenerateThumbnail:e=>zn.mutate(e.id),onTagClick:gn,thumbnailVersion:Ct[t.id],hasPermission:r,canModify:s,authEnabled:f,showModified:nn},t.id))})}):(0,z.jsx)(`div`,{className:`flex-1 lg:overflow-y-auto`,children:(0,z.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary overflow-x-auto`,children:[(0,z.jsxs)(`div`,{"data-testid":`file-list-grid-header`,className:`hidden sm:grid ${dl(f)} ${fl} gap-4 px-4 py-2 bg-bambu-dark-secondary border-b border-bambu-dark-tertiary text-xs text-bambu-gray font-medium`,children:[(0,z.jsx)(`div`,{className:`w-6`}),(0,z.jsx)(`div`,{children:e(`common.name`)}),f&&(0,z.jsx)(`div`,{children:e(`fileManager.uploadedBy`,{defaultValue:`Uploaded By`})}),(0,z.jsx)(`div`,{children:e(`common.type`)}),(0,z.jsx)(`div`,{children:e(`fileManager.size`)}),(0,z.jsx)(`div`,{children:e(`fileManager.prints`)}),(0,z.jsx)(`div`,{children:e(`fileManager.tags.title`)}),(0,z.jsx)(`div`,{})]}),J.map(t=>(0,z.jsxs)(`div`,{"data-testid":`file-list-grid-row`,className:`grid ${dl(f)} ${fl} gap-4 px-4 py-3 items-center border-b border-bambu-dark-tertiary last:border-b-0 cursor-pointer hover:bg-bambu-dark/50 transition-colors ${C.includes(t.id)?`bg-bambu-green/10`:``}`,onClick:()=>Vn(t.id),onDoubleClick:()=>Bn(t),children:[(0,z.jsx)(`div`,{className:`w-5 h-5 rounded border-2 flex items-center justify-center ${C.includes(t.id)?`bg-bambu-green border-bambu-green`:`border-bambu-gray/50`}`,children:C.includes(t.id)&&(0,z.jsx)(`div`,{className:`w-2 h-2 bg-white rounded-sm`})}),(0,z.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0`,children:[(0,z.jsxs)(`div`,{className:`relative group/thumb`,children:[(0,z.jsx)(`div`,{className:`w-10 h-10 rounded bg-bambu-dark flex-shrink-0 overflow-hidden`,children:t.thumbnail_path?(0,z.jsx)(`img`,{src:`${a.getLibraryFileThumbnailUrl(t.id)}${Ct[t.id]?(a.getLibraryFileThumbnailUrl(t.id).includes(`?`)?`&`:`?`)+`v=${Ct[t.id]}`:``}`,loading:`lazy`,alt:``,className:`w-full h-full object-cover`}):(0,z.jsx)(`div`,{className:`w-full h-full flex items-center justify-center`,children:(0,z.jsx)(nl,{fileType:t.file_type,className:`w-5 h-5 text-bambu-gray/50`})})}),t.thumbnail_path&&(0,z.jsx)(`div`,{className:`absolute left-0 top-full mt-2 z-50 hidden group-hover/thumb:block`,children:(0,z.jsx)(`div`,{className:`w-48 h-48 rounded-lg bg-bambu-dark-secondary border border-bambu-dark-tertiary shadow-xl overflow-hidden`,children:(0,z.jsx)(`img`,{src:`${a.getLibraryFileThumbnailUrl(t.id)}${Ct[t.id]?(a.getLibraryFileThumbnailUrl(t.id).includes(`?`)?`&`:`?`)+`v=${Ct[t.id]}`:``}`,loading:`lazy`,alt:t.filename,className:`w-full h-full object-contain`})})})]}),(0,z.jsxs)(`div`,{className:`min-w-0`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[(0,z.jsx)(`span`,{className:`text-sm text-white truncate`,children:t.print_name||t.filename}),t.external_url&&(0,z.jsx)(`a`,{href:t.external_url,target:`_blank`,rel:`noopener noreferrer`,...al,className:`flex-shrink-0 text-bambu-gray hover:text-bambu-green`,title:e(`fileManager.details.openLink`),"aria-label":e(`fileManager.details.openLink`),children:(0,z.jsx)(Me,{className:`w-3.5 h-3.5`})}),t.has_notes&&(0,z.jsx)(`span`,{className:`flex-shrink-0 text-bambu-gray`,title:e(`fileManager.details.hasNotes`),"aria-label":e(`fileManager.details.hasNotes`),children:(0,z.jsx)(ne,{className:`w-3.5 h-3.5`})}),(t.photo_count??0)>0&&(0,z.jsxs)(`span`,{className:`flex-shrink-0 flex items-center gap-0.5 text-xs text-bambu-gray`,title:e(`fileManager.details.photoCount`,{count:t.photo_count}),children:[(0,z.jsx)(be,{className:`w-3.5 h-3.5`}),t.photo_count]})]}),nn&&(0,z.jsxs)(`div`,{className:`text-xs text-bambu-gray flex items-center gap-1 mt-0.5`,title:e(`fileManager.lastModified`),children:[(0,z.jsx)(tt,{className:`w-3 h-3 flex-shrink-0`}),(0,z.jsx)(`span`,{className:`truncate`,children:se(t.fs_modified_at??t.created_at)})]})]})]}),f&&(0,z.jsx)(`div`,{className:`text-sm text-bambu-gray flex items-center gap-1`,children:t.created_by_username?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(ye,{className:`w-3 h-3`}),(0,z.jsx)(`span`,{className:`truncate`,children:t.created_by_username})]}):`-`}),(0,z.jsx)(`div`,{children:(0,z.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded font-medium ${ll(t.file_type)}`,children:t.file_type.toUpperCase()})}),(0,z.jsx)(`div`,{className:`text-sm text-bambu-gray`,children:oe(t.file_size)}),(0,z.jsx)(`div`,{className:`text-sm text-bambu-gray`,children:t.print_count>0?`${t.print_count}x`:`-`}),(0,z.jsx)(`div`,{className:`min-w-0`,...al,children:!t.tags||t.tags.length===0?(0,z.jsx)(`span`,{className:`text-xs text-bambu-gray/50`,children:`-`}):(0,z.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:t.tags.map(e=>(0,z.jsxs)(`button`,{type:`button`,onClick:()=>gn(e.id),className:`inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded-full text-[10px] bg-bambu-green/10 text-bambu-green hover:bg-bambu-green/20 transition-colors max-w-full`,title:e.name,children:[(0,z.jsx)(xe,{className:`w-2.5 h-2.5 flex-shrink-0`}),(0,z.jsx)(`span`,{className:`truncate`,children:e.name})]},e.id))})}),(0,z.jsx)(Cl,{file:t,...nr})]},t.id))]})})]}),g!==null&&(0,z.jsx)(Hc,{folderId:g})]})]}),te&&(0,z.jsx)(pl,{parentId:g,onClose:()=>ie(!1),onSave:e=>Tn.mutate(e),isLoading:Tn.isPending,t:e}),ce&&(0,z.jsx)(ml,{onClose:()=>le(!1),onSave:e=>En.mutate(e),isLoading:En.isPending,t:e}),ue&&ln&&(0,z.jsx)(vl,{folders:ln,selectedFiles:C,currentFolderId:g,onClose:()=>fe(!1),onMove:e=>Mn.mutate({fileIds:C,folderId:e}),isLoading:Mn.isPending,t:e}),F&&(0,z.jsx)(Xe,{folderId:g,onClose:()=>{I(!1),ve([])},onUploadComplete:Gn,initialFiles:he.length>0?he:void 0}),Te&&(0,z.jsx)(Kc,{onClose:()=>Pe(!1)}),(0,z.jsx)(Uc,{open:Le,onClose:()=>Re(!1),onPickTag:e=>{We.includes(e)||qe(t=>[...t,e])}}),(0,z.jsx)(mt,{open:Be,fileIds:C,onClose:()=>Ve(!1)}),Je&&(0,z.jsx)(yl,{folder:Je,onClose:()=>Ye(null),onLink:e=>Nn.mutate({id:Je.id,data:e}),isLoading:Nn.isPending,t:e}),ot&&(0,z.jsx)(ke,{title:ot.type===`folder`?e(`fileManager.deleteFolder`):ot.type===`bulk`?e(`fileManager.deleteFilesCount`,{count:ot.count}):e(`fileManager.deleteFile`),message:ot.type===`folder`?e(`fileManager.deleteFolderConfirm`):ot.type===`bulk`?e(`fileManager.deleteFilesConfirm`,{count:ot.count}):e(`fileManager.deleteFileConfirm`),confirmText:e(`common.delete`),variant:`danger`,isLoading:er,loadingText:e(`fileManager.deleting`),onConfirm:$n,onCancel:()=>st(null)}),ct&&(!ct.variant_group_id||ur!==void 0)&&(0,z.jsx)(Ae,{mode:`create`,libraryFileId:dr?.[0]?.id??ct.id,variantFiles:dr,archiveName:dr&&dr.length>1?`${dr[0].filename} ${e(`common.plusNMore`,{count:dr.length-1})}`:ct.print_name||ct.filename,onClose:()=>ut(null),onSuccess:()=>{ut(null),T([]),t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`queue`]}),t.invalidateQueries({queryKey:[`archives`]})}}),dt&&(0,z.jsx)(D,{source:{kind:`libraryFile`,id:dt.id,filename:dt.filename},onClose:()=>pt(null)}),ht&&$.length>0&&(0,z.jsx)(ft,{files:$,folderId:g,canSlice:!!an?.use_slicer_api&&cn(),onClose:()=>gt(!1),onCombined:(e,t)=>{gt(!1),T([]),t&&vt({id:e.id,filename:e.filename})}}),_t&&(0,z.jsx)(D,{source:{kind:`libraryFile`,id:_t.id,filename:_t.filename},onClose:()=>vt(null),defaultAutoArrange:!0}),yt&&(0,z.jsx)(Ue,{source:{kind:`libraryFile`,id:yt.id,filename:yt.filename},onClose:()=>bt(null)}),Tt&&(0,z.jsx)(lt,{libraryFileId:Tt.id,title:Tt.print_name||Tt.filename,fileType:Tt.file_type,onClose:()=>B(null),onSnapshot:Zc(Tt.file_type)?Zn(Tt):void 0,onSliceWithBambuddy:Qe(Tt,!0,on)&&r(`library:upload`)?()=>{let e=Tt;B(null),pt(e)}:void 0}),(Et||V||W)&&(0,z.jsxs)(R.Suspense,{fallback:null,children:[Et&&(0,z.jsx)(qc,{libraryFileId:Et.id,filename:Et.print_name||Et.filename,fileSize:Et.file_size,onClose:()=>Dt(null),onSnapshot:Zn(Et)}),V&&(0,z.jsx)(Jc,{libraryFileId:V.id,filename:V.print_name||V.filename,fileType:V.file_type,fileSize:V.file_size,onClose:()=>H(null),onSnapshot:Zn(V)}),W&&(0,z.jsx)(Yc,{libraryFileId:W.id,filename:W.print_name||W.filename,fileSize:W.file_size,onClose:()=>kt(null)})]}),Ot&&(0,z.jsx)(Wc,{file:Ot,canEdit:s(`library`,`update`,Ot.created_by_id),onClose:()=>U(null)}),xt&&(0,z.jsx)(_l,{type:xt.type,currentName:xt.name,onClose:()=>St(null),onSave:e=>{xt.type===`file`?Pn.mutate({id:xt.id,filename:e}):Fn.mutate({id:xt.id,name:e})},isLoading:Pn.isPending||Fn.isPending,t:e})]})}export{Tl as FileManagerPage}; \ No newline at end of file +`},i)),a}function Zo(e,t){return e&&`run`in e?async function(n,r){let i=Xo(n,{file:r,...t});await e.run(i,r)}:function(n,r){return Xo(n,{file:r,...e||t})}}function Qo(e){if(e)throw e}var $o=n(((e,t)=>{var n=Object.prototype.hasOwnProperty,r=Object.prototype.toString,i=Object.defineProperty,a=Object.getOwnPropertyDescriptor,o=function(e){return typeof Array.isArray==`function`?Array.isArray(e):r.call(e)===`[object Array]`},s=function(e){if(!e||r.call(e)!==`[object Object]`)return!1;var t=n.call(e,`constructor`),i=e.constructor&&e.constructor.prototype&&n.call(e.constructor.prototype,`isPrototypeOf`);if(e.constructor&&!t&&!i)return!1;for(var a in e);return a===void 0||n.call(e,a)},c=function(e,t){i&&t.name===`__proto__`?i(e,t.name,{enumerable:!0,configurable:!0,value:t.newValue,writable:!0}):e[t.name]=t.newValue},l=function(e,t){if(t===`__proto__`){if(!n.call(e,t))return;if(a)return a(e,t).value}return e[t]};t.exports=function e(){var t,n,r,i,a,u,d=arguments[0],f=1,p=arguments.length,m=!1;for(typeof d==`boolean`&&(m=d,d=arguments[1]||{},f=2),(d==null||typeof d!=`object`&&typeof d!=`function`)&&(d={});ft.length,o;r&&t.push(i);try{o=e.apply(this,t)}catch(e){let t=e;if(r&&n)throw t;return i(t)}r||(o&&o.then&&typeof o.then==`function`?o.then(a,i):o instanceof Error?i(o):a(o))}function i(e,...r){n||(n=!0,t(e,...r))}function a(e){i(null,e)}}var rs={basename:is,dirname:as,extname:os,join:ss,sep:`/`};function is(e,t){if(t!==void 0&&typeof t!=`string`)throw TypeError(`"ext" argument must be a string`);us(e);let n=0,r=-1,i=e.length,a;if(t===void 0||t.length===0||t.length>e.length){for(;i--;)if(e.codePointAt(i)===47){if(a){n=i+1;break}}else r<0&&(a=!0,r=i+1);return r<0?``:e.slice(n,r)}if(t===e)return``;let o=-1,s=t.length-1;for(;i--;)if(e.codePointAt(i)===47){if(a){n=i+1;break}}else o<0&&(a=!0,o=i+1),s>-1&&(e.codePointAt(i)===t.codePointAt(s--)?s<0&&(r=i):(s=-1,r=o));return n===r?r=o:r<0&&(r=e.length),e.slice(n,r)}function as(e){if(us(e),e.length===0)return`.`;let t=-1,n=e.length,r;for(;--n;)if(e.codePointAt(n)===47){if(r){t=n;break}}else r||=!0;return t<0?e.codePointAt(0)===47?`/`:`.`:t===1&&e.codePointAt(0)===47?`//`:e.slice(0,t)}function os(e){us(e);let t=e.length,n=-1,r=0,i=-1,a=0,o;for(;t--;){let s=e.codePointAt(t);if(s===47){if(o){r=t+1;break}continue}n<0&&(o=!0,n=t+1),s===46?i<0?i=t:a!==1&&(a=1):i>-1&&(a=-1)}return i<0||n<0||a===0||a===1&&i===n-1&&i===r+1?``:e.slice(i,n)}function ss(...e){let t=-1,n;for(;++t0&&e.codePointAt(e.length-1)===47&&(n+=`/`),t?`/`+n:n}function ls(e,t){let n=``,r=0,i=-1,a=0,o=-1,s,c;for(;++o<=e.length;){if(o2){if(c=n.lastIndexOf(`/`),c!==n.length-1){c<0?(n=``,r=0):(n=n.slice(0,c),r=n.length-1-n.lastIndexOf(`/`)),i=o,a=0;continue}}else if(n.length>0){n=``,r=0,i=o,a=0;continue}}t&&(n=n.length>0?n+`/..`:`..`,r=2)}else n.length>0?n+=`/`+e.slice(i+1,o):n=e.slice(i+1,o),r=o-i-1;i=o,a=0}else s===46&&a>-1?a++:a=-1}return n}function us(e){if(typeof e!=`string`)throw TypeError(`Path must be a string. Received `+JSON.stringify(e))}var ds={cwd:fs};function fs(){return`/`}function ps(e){return!!(typeof e==`object`&&e&&`href`in e&&e.href&&`protocol`in e&&e.protocol&&e.auth===void 0)}function ms(e){if(typeof e==`string`)e=new URL(e);else if(!ps(e)){let t=TypeError('The "path" argument must be of type string or an instance of URL. Received `'+e+"`");throw t.code=`ERR_INVALID_ARG_TYPE`,t}if(e.protocol!==`file:`){let e=TypeError(`The URL must be of scheme file`);throw e.code=`ERR_INVALID_URL_SCHEME`,e}return hs(e)}function hs(e){if(e.hostname!==``){let e=TypeError(`File URL host must be "localhost" or empty on darwin`);throw e.code=`ERR_INVALID_FILE_URL_HOST`,e}let t=e.pathname,n=-1;for(;++n0){let[r,...a]=t,o=n[i][1];es(o)&&es(r)&&(r=(0,Cs.default)(!0,o,r)),n[i]=[e,r,...a]}}}}().freeze();function Es(e,t){if(typeof t!=`function`)throw TypeError("Cannot `"+e+"` without `parser`")}function Ds(e,t){if(typeof t!=`function`)throw TypeError("Cannot `"+e+"` without `compiler`")}function Os(e,t){if(t)throw Error("Cannot call `"+e+"` on a frozen processor.\nCreate a new processor first, by calling it: use `processor()` instead of `processor`.")}function ks(e){if(!es(e)||typeof e.type!=`string`)throw TypeError("Expected node, got `"+e+"`")}function As(e,t,n){if(!n)throw Error("`"+e+"` finished async. Use `"+t+"` instead")}function js(e){return Ms(e)?e:new _s(e)}function Ms(e){return!!(e&&typeof e==`object`&&`message`in e&&`messages`in e)}function Ns(e){return typeof e==`string`||Ps(e)}function Ps(e){return!!(e&&typeof e==`object`&&`byteLength`in e&&`byteOffset`in e)}var Fs=[],Is={allowDangerousHtml:!0},Ls=/^(https?|ircs?|mailto|xmpp)$/i,Rs=[{from:`astPlugins`,id:`remove-buggy-html-in-markdown-parser`},{from:`allowDangerousHtml`,id:`remove-buggy-html-in-markdown-parser`},{from:`allowNode`,id:`replace-allownode-allowedtypes-and-disallowedtypes`,to:`allowElement`},{from:`allowedTypes`,id:`replace-allownode-allowedtypes-and-disallowedtypes`,to:`allowedElements`},{from:`disallowedTypes`,id:`replace-allownode-allowedtypes-and-disallowedtypes`,to:`disallowedElements`},{from:`escapeHtml`,id:`remove-buggy-html-in-markdown-parser`},{from:`includeElementIndex`,id:`#remove-includeelementindex`},{from:`includeNodeIndex`,id:`change-includenodeindex-to-includeelementindex`},{from:`linkTarget`,id:`remove-linktarget`},{from:`plugins`,id:`change-plugins-to-remarkplugins`,to:`remarkPlugins`},{from:`rawSourcePos`,id:`#remove-rawsourcepos`},{from:`renderers`,id:`change-renderers-to-components`,to:`components`},{from:`source`,id:`change-source-to-children`,to:`children`},{from:`sourcePos`,id:`#remove-sourcepos`},{from:`transformImageUri`,id:`#add-urltransform`,to:`urlTransform`},{from:`transformLinkUri`,id:`#add-urltransform`,to:`urlTransform`}];function zs(e){let t=Bs(e),n=Vs(e);return Hs(t.runSync(t.parse(n),n),e)}function Bs(e){let t=e.rehypePlugins||Fs,n=e.remarkPlugins||Fs,r=e.remarkRehypeOptions?{...e.remarkRehypeOptions,...Is}:Is;return Ts().use(Fa).use(n).use(Zo,r).use(t)}function Vs(e){let t=e.children||``,n=new _s;return typeof t==`string`?n.value=t:``+t,n}function Hs(e,t){let n=t.allowedElements,r=t.allowElement,i=t.components,a=t.disallowedElements,o=t.skipHtml,s=t.unwrapDisallowed,c=t.urlTransform||Us;for(let e of Rs)Object.hasOwn(t,e.from)&&``+e.from+(e.to?"use `"+e.to+"` instead":`remove it`)+e.id;return t.className&&(e={type:`element`,tagName:`div`,properties:{className:t.className},children:e.type===`root`?e.children:[e]}),Vo(e,l),_n(e,{Fragment:z.Fragment,components:i,ignoreInvalidStyle:!0,jsx:z.jsx,jsxs:z.jsxs,passKeys:!0,passNode:!0});function l(e,t,i){if(e.type===`raw`&&i&&typeof t==`number`)return o?i.children.splice(t,1):i.children[t]={type:`text`,value:e.value},t;if(e.type===`element`){let t;for(t in Rn)if(Object.hasOwn(Rn,t)&&Object.hasOwn(e.properties,t)){let n=e.properties[t],r=Rn[t];(r===null||r.includes(e.tagName))&&(e.properties[t]=c(String(n||``),t,e))}}if(e.type===`element`){let o=n?!n.includes(e.tagName):a?a.includes(e.tagName):!1;if(!o&&r&&typeof t==`number`&&(o=!r(e,t,i)),o&&i&&typeof t==`number`)return s&&e.children?i.children.splice(t,1,...e.children):i.children.splice(t,1),t}}}function Us(e){let t=e.indexOf(`:`),n=e.indexOf(`?`),r=e.indexOf(`#`),i=e.indexOf(`/`);return t===-1||i!==-1&&t>i||n!==-1&&t>n||r!==-1&&t>r||Ls.test(e.slice(0,t))?e:``}$s.peek=Qs;function Ws(){this.buffer()}function Gs(e){this.enter({type:`footnoteReference`,identifier:``,label:``},e)}function Ks(){this.buffer()}function qs(e){this.enter({type:`footnoteDefinition`,identifier:``,label:``,children:[]},e)}function Js(e){let t=this.resume(),n=this.stack[this.stack.length-1];n.type,n.identifier=Qn(this.sliceSerialize(e)).toLowerCase(),n.label=t}function Ys(e){this.exit(e)}function Xs(e){let t=this.resume(),n=this.stack[this.stack.length-1];n.type,n.identifier=Qn(this.sliceSerialize(e)).toLowerCase(),n.label=t}function Zs(e){this.exit(e)}function Qs(){return`[`}function $s(e,t,n,r){let i=n.createTracker(r),a=i.move(`[^`),o=n.enter(`footnoteReference`),s=n.enter(`reference`);return a+=i.move(n.safe(n.associationId(e),{after:`]`,before:a})),s(),o(),a+=i.move(`]`),a}function ec(){return{enter:{gfmFootnoteCallString:Ws,gfmFootnoteCall:Gs,gfmFootnoteDefinitionLabelString:Ks,gfmFootnoteDefinition:qs},exit:{gfmFootnoteCallString:Js,gfmFootnoteCall:Ys,gfmFootnoteDefinitionLabelString:Xs,gfmFootnoteDefinition:Zs}}}ic.peek=ac;function tc(){return{canContainEols:[`delete`],enter:{strikethrough:nc},exit:{strikethrough:rc}}}function nc(e){this.enter({type:`delete`,children:[]},e)}function rc(e){this.exit(e)}function ic(e,t,n,r){let i=n.createTracker(r),a=n.enter(`strikethrough`),o=i.move(`~~`);return o+=n.containerPhrasing(e,{...i.current(),before:o,after:`~`}),o+=i.move(`~~`),a(),o}function ac(){return`~`}function oc(){return{enter:{table:sc,tableData:dc,tableHeader:dc,tableRow:lc},exit:{codeText:fc,table:cc,tableData:uc,tableHeader:uc,tableRow:uc}}}function sc(e){let t=e._align;this.enter({type:`table`,align:t.map(function(e){return e===`none`?null:e}),children:[]},e),this.data.inTable=!0}function cc(e){this.exit(e),this.data.inTable=void 0}function lc(e){this.enter({type:`tableRow`,children:[]},e)}function uc(e){this.exit(e)}function dc(e){this.enter({type:`tableCell`,children:[]},e)}function fc(e){let t=this.resume();this.data.inTable&&(t=t.replace(/\\([\\|])/g,pc));let n=this.stack[this.stack.length-1];n.type,n.value=t,this.exit(e)}function pc(e,t){return t===`|`?t:e}function mc(){return{exit:{taskListCheckValueChecked:hc,taskListCheckValueUnchecked:hc,paragraph:gc}}}function hc(e){let t=this.stack[this.stack.length-2];t.type,t.checked=e.type===`taskListCheckValueChecked`}function gc(e){let t=this.stack[this.stack.length-2];if(t&&t.type===`listItem`&&typeof t.checked==`boolean`){let e=this.stack[this.stack.length-1];e.type;let n=e.children[0];if(n&&n.type===`text`){let r=t.children,i=-1,a;for(;++i999||s===93&&!o||s===null||s===91||Z(s))return n(s);if(s===93){e.exit(`chunkString`);let a=e.exit(`gfmFootnoteCallString`);return i.includes(Qn(r.sliceSerialize(a)))?(e.enter(`gfmFootnoteCallLabelMarker`),e.consume(s),e.exit(`gfmFootnoteCallLabelMarker`),e.exit(`gfmFootnoteCall`),t):n(s)}return Z(s)||(o=!0),a++,e.consume(s),s===92?u:l}function u(t){return t===91||t===92||t===93?(e.consume(t),a++,l):l(t)}}function Sc(e,t,n){let r=this,i=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]),a,o=0,s;return c;function c(t){return e.enter(`gfmFootnoteDefinition`)._container=!0,e.enter(`gfmFootnoteDefinitionLabel`),e.enter(`gfmFootnoteDefinitionLabelMarker`),e.consume(t),e.exit(`gfmFootnoteDefinitionLabelMarker`),l}function l(t){return t===94?(e.enter(`gfmFootnoteDefinitionMarker`),e.consume(t),e.exit(`gfmFootnoteDefinitionMarker`),e.enter(`gfmFootnoteDefinitionLabelString`),e.enter(`chunkString`).contentType=`string`,u):n(t)}function u(t){if(o>999||t===93&&!s||t===null||t===91||Z(t))return n(t);if(t===93){e.exit(`chunkString`);let n=e.exit(`gfmFootnoteDefinitionLabelString`);return a=Qn(r.sliceSerialize(n)),e.enter(`gfmFootnoteDefinitionLabelMarker`),e.consume(t),e.exit(`gfmFootnoteDefinitionLabelMarker`),e.exit(`gfmFootnoteDefinitionLabel`),f}return Z(t)||(s=!0),o++,e.consume(t),t===92?d:u}function d(t){return t===91||t===92||t===93?(e.consume(t),o++,u):u(t)}function f(t){return t===58?(e.enter(`definitionMarker`),e.consume(t),e.exit(`definitionMarker`),i.includes(a)||i.push(a),$(e,p,`gfmFootnoteDefinitionWhitespace`)):n(t)}function p(e){return t(e)}}function Cc(e,t,n){return e.check(wr,t,e.attempt(_c,t,n))}function wc(e){e.exit(`gfmFootnoteDefinition`)}function Tc(e,t,n){let r=this;return $(e,i,`gfmFootnoteDefinitionIndent`,5);function i(e){let i=r.events[r.events.length-1];return i&&i[1].type===`gfmFootnoteDefinitionIndent`&&i[2].sliceSerialize(i[1],!0).length===4?t(e):n(e)}}function Ec(e){let t=(e||{}).singleTilde,n={name:`strikethrough`,tokenize:i,resolveAll:r};return t??=!0,{text:{126:n},insideSpan:{null:[n]},attentionMarkers:{null:[126]}};function r(e,t){let n=-1;for(;++n1?r(a):(e.consume(a),o++,c);if(o<2&&!t)return r(a);let l=e.exit(`strikethroughSequenceTemporary`),u=gr(a);return l._open=!u||u===2&&!!s,l._close=!s||s===2&&!!u,n(a)}}}var Dc=class{constructor(){this.map=[]}add(e,t,n){Oc(this,e,t,n)}consume(e){if(this.map.sort(function(e,t){return e[0]-t[0]}),this.map.length===0)return;let t=this.map.length,n=[];for(;t>0;)--t,n.push(e.slice(this.map[t][0]+this.map[t][1]),this.map[t][2]),e.length=this.map[t][0];n.push(e.slice()),e.length=0;let r=n.pop();for(;r;){for(let t of r)e.push(t);r=n.pop()}this.map.length=0}};function Oc(e,t,n,r){let i=0;if(!(n===0&&r.length===0)){for(;i-1;){let e=r.events[t][1].type;if(e===`lineEnding`||e===`linePrefix`)t--;else break}let i=t>-1?r.events[t][1].type:null,a=i===`tableHead`||i===`tableRow`?S:c;return a===S&&r.parser.lazy[r.now().line]?n(e):a(e)}function c(t){return e.enter(`tableHead`),e.enter(`tableRow`),l(t)}function l(e){return e===124?u(e):(o=!0,a+=1,u(e))}function u(t){return t===null?n(t):X(t)?a>1?(a=0,r.interrupt=!0,e.exit(`tableRow`),e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),p):n(t):Q(t)?$(e,u,`whitespace`)(t):(a+=1,o&&(o=!1,i+=1),t===124?(e.enter(`tableCellDivider`),e.consume(t),e.exit(`tableCellDivider`),o=!0,u):(e.enter(`data`),d(t)))}function d(t){return t===null||t===124||Z(t)?(e.exit(`data`),u(t)):(e.consume(t),t===92?f:d)}function f(t){return t===92||t===124?(e.consume(t),d):d(t)}function p(t){return r.interrupt=!1,r.parser.lazy[r.now().line]?n(t):(e.enter(`tableDelimiterRow`),o=!1,Q(t)?$(e,m,`linePrefix`,r.parser.constructs.disable.null.includes(`codeIndented`)?void 0:4)(t):m(t))}function m(t){return t===45||t===58?g(t):t===124?(o=!0,e.enter(`tableCellDivider`),e.consume(t),e.exit(`tableCellDivider`),h):x(t)}function h(t){return Q(t)?$(e,g,`whitespace`)(t):g(t)}function g(t){return t===58?(a+=1,o=!0,e.enter(`tableDelimiterMarker`),e.consume(t),e.exit(`tableDelimiterMarker`),_):t===45?(a+=1,_(t)):t===null||X(t)?b(t):x(t)}function _(t){return t===45?(e.enter(`tableDelimiterFiller`),v(t)):x(t)}function v(t){return t===45?(e.consume(t),v):t===58?(o=!0,e.exit(`tableDelimiterFiller`),e.enter(`tableDelimiterMarker`),e.consume(t),e.exit(`tableDelimiterMarker`),y):(e.exit(`tableDelimiterFiller`),y(t))}function y(t){return Q(t)?$(e,b,`whitespace`)(t):b(t)}function b(n){return n===124?m(n):n===null||X(n)?!o||i!==a?x(n):(e.exit(`tableDelimiterRow`),e.exit(`tableHead`),t(n)):x(n)}function x(e){return n(e)}function S(t){return e.enter(`tableRow`),C(t)}function C(n){return n===124?(e.enter(`tableCellDivider`),e.consume(n),e.exit(`tableCellDivider`),C):n===null||X(n)?(e.exit(`tableRow`),t(n)):Q(n)?$(e,C,`whitespace`)(n):(e.enter(`data`),w(n))}function w(t){return t===null||t===124||Z(t)?(e.exit(`data`),C(t)):(e.consume(t),t===92?T:w)}function T(t){return t===92||t===124?(e.consume(t),w):w(t)}}function Mc(e,t){let n=-1,r=!0,i=0,a=[0,0,0,0],o=[0,0,0,0],s=!1,c=0,l,u,d,f=new Dc;for(;++nn[2]+1){let t=n[2]+1,r=n[3]-n[2]-1;e.add(t,r,[])}}e.add(n[3]+1,0,[[`exit`,o,t]])}return i!==void 0&&(a.end=Object.assign({},Fc(t.events,i)),e.add(i,0,[[`exit`,a,t]]),a=void 0),a}function Pc(e,t,n,r,i){let a=[],o=Fc(t.events,n);i&&(i.end=Object.assign({},o),a.push([`exit`,i,t])),r.end=Object.assign({},o),a.push([`exit`,r,t]),e.add(n+1,0,a)}function Fc(e,t){let n=e[t],r=n[0]===`enter`?`start`:`end`;return n[1][r]}var Ic={name:`tasklistCheck`,tokenize:Rc};function Lc(){return{text:{91:Ic}}}function Rc(e,t,n){let r=this;return i;function i(t){return r.previous!==null||!r._gfmTasklistFirstContentOfListItem?n(t):(e.enter(`taskListCheck`),e.enter(`taskListCheckMarker`),e.consume(t),e.exit(`taskListCheckMarker`),a)}function a(t){return Z(t)?(e.enter(`taskListCheckValueUnchecked`),e.consume(t),e.exit(`taskListCheckValueUnchecked`),o):t===88||t===120?(e.enter(`taskListCheckValueChecked`),e.consume(t),e.exit(`taskListCheckValueChecked`),o):n(t)}function o(t){return t===93?(e.enter(`taskListCheckMarker`),e.consume(t),e.exit(`taskListCheckMarker`),e.exit(`taskListCheck`),s):n(t)}function s(r){return X(r)?t(r):Q(r)?e.check({tokenize:zc},t,n)(r):n(r)}}function zc(e,t,n){return $(e,r,`whitespace`);function r(e){return e===null?n(e):t(e)}}function Bc(){let e=this.data(),t=e.micromarkExtensions||=[],n=e.fromMarkdownExtensions||=[];t.push(vc(),Ec(),Ac(),Lc()),n.push(ec(),tc(),oc(),mc())}var Vc=`fileManager.readmeCollapsed`;function Hc({folderId:e}){let{t}=o(),[n,r]=(0,R.useState)(()=>localStorage.getItem(Vc)===`1`);(0,R.useEffect)(()=>{localStorage.setItem(Vc,n?`1`:`0`)},[n]);let{data:i,isLoading:s,error:c}=l({queryKey:[`folder-readme`,e],queryFn:()=>a.getLibraryFolderReadme(e),retry:!1,staleTime:3e4});return s||c||!i?null:n?(0,z.jsxs)(`div`,{className:`mb-2 lg:mb-0 order-first lg:order-none lg:w-10 lg:flex-shrink-0 lg:h-full`,children:[(0,z.jsxs)(`button`,{type:`button`,onClick:()=>r(!1),title:t(`fileManager.readme.show`),"aria-label":t(`fileManager.readme.show`),className:`flex lg:hidden w-full items-center gap-2 px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg hover:bg-bambu-dark/40 transition-colors`,children:[(0,z.jsx)(Re,{className:`w-4 h-4 text-bambu-green flex-shrink-0`}),(0,z.jsx)(`span`,{className:`text-sm font-medium text-white truncate`,children:i.filename}),(0,z.jsx)(st,{className:`w-4 h-4 text-bambu-gray flex-shrink-0 ml-auto`})]}),(0,z.jsxs)(`button`,{type:`button`,onClick:()=>r(!1),title:t(`fileManager.readme.show`),"aria-label":t(`fileManager.readme.show`),className:`hidden lg:flex h-full w-10 flex-col items-center gap-2 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg hover:bg-bambu-dark/40 transition-colors`,children:[(0,z.jsx)(st,{className:`w-4 h-4 text-bambu-green flex-shrink-0`}),(0,z.jsx)(`span`,{className:`text-xs font-medium text-bambu-gray [writing-mode:vertical-rl] rotate-180 select-none`,children:t(`fileManager.readme.label`)})]})]}):(0,z.jsxs)(`div`,{className:`mb-4 lg:mb-0 order-first lg:order-none lg:w-80 xl:w-96 lg:flex-shrink-0 lg:h-full flex flex-col bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg overflow-hidden`,children:[(0,z.jsxs)(`div`,{className:`flex items-center justify-between gap-2 px-3 py-2`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,z.jsx)(Re,{className:`w-4 h-4 text-bambu-green flex-shrink-0`}),(0,z.jsx)(`span`,{className:`text-sm font-medium text-white truncate`,title:i.filename,children:i.filename}),i.truncated&&(0,z.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400 flex-shrink-0`,children:t(`fileManager.readme.truncated`)})]}),(0,z.jsx)(`button`,{type:`button`,onClick:()=>r(!0),title:t(`fileManager.readme.hide`),"aria-label":t(`fileManager.readme.hide`),className:`p-1 rounded text-bambu-gray hover:text-white hover:bg-bambu-dark/40 transition-colors flex-shrink-0`,children:(0,z.jsx)(ot,{className:`w-4 h-4`})})]}),(0,z.jsx)(`div`,{className:`px-4 py-3 border-t border-bambu-dark-tertiary flex-1 overflow-y-auto max-h-96 lg:max-h-none text-sm text-bambu-gray-light leading-relaxed space-y-2`,children:(0,z.jsx)(zs,{remarkPlugins:[Bc],components:{h1:({children:e})=>(0,z.jsx)(`h1`,{className:`text-lg font-semibold text-white mt-2 mb-1`,children:e}),h2:({children:e})=>(0,z.jsx)(`h2`,{className:`text-base font-semibold text-white mt-2 mb-1`,children:e}),h3:({children:e})=>(0,z.jsx)(`h3`,{className:`text-sm font-semibold text-white mt-2 mb-1`,children:e}),p:({children:e})=>(0,z.jsx)(`p`,{className:`my-1`,children:e}),ul:({children:e})=>(0,z.jsx)(`ul`,{className:`list-disc list-inside space-y-0.5 ml-2`,children:e}),ol:({children:e})=>(0,z.jsx)(`ol`,{className:`list-decimal list-inside space-y-0.5 ml-2`,children:e}),li:({children:e})=>(0,z.jsx)(`li`,{children:e}),code:({children:e,...t})=>t.className?(0,z.jsx)(`code`,{className:`block p-2 bg-bambu-dark rounded text-xs font-mono text-bambu-gray-light overflow-x-auto`,children:e}):(0,z.jsx)(`code`,{className:`px-1 py-0.5 bg-bambu-dark rounded text-xs font-mono text-bambu-green`,children:e}),pre:({children:e})=>(0,z.jsx)(`pre`,{className:`my-2`,children:e}),blockquote:({children:e})=>(0,z.jsx)(`blockquote`,{className:`border-l-2 border-bambu-dark-tertiary pl-3 text-bambu-gray italic`,children:e}),a:({children:e,href:t})=>(0,z.jsx)(`a`,{href:t,target:`_blank`,rel:`noopener noreferrer`,className:`text-bambu-green hover:underline`,children:e}),table:({children:e})=>(0,z.jsx)(`div`,{className:`overflow-x-auto`,children:(0,z.jsx)(`table`,{className:`min-w-full text-xs border-collapse`,children:e})}),th:({children:e})=>(0,z.jsx)(`th`,{className:`border border-bambu-dark-tertiary px-2 py-1 text-left font-semibold text-white`,children:e}),td:({children:e})=>(0,z.jsx)(`td`,{className:`border border-bambu-dark-tertiary px-2 py-1`,children:e}),hr:()=>(0,z.jsx)(`hr`,{className:`border-bambu-dark-tertiary my-2`})},children:i.content})})]})}function Uc({open:e,onClose:t,onPickTag:n}){let{t:r}=o(),i=c(),{showToast:s}=v(),[d,f]=(0,R.useState)(!1),[p,m]=(0,R.useState)(null),[h,g]=(0,R.useState)(``),[_,y]=(0,R.useState)(null),{data:b=[],isLoading:x}=l({queryKey:pt,queryFn:a.getLibraryTags,enabled:e}),S=()=>{i.invalidateQueries({queryKey:pt}),i.invalidateQueries({queryKey:[`library-files`]})},C=u({mutationFn:async()=>{let e=h.trim();if(!e)throw Error(r(`fileManager.tags.nameRequired`));return p?a.updateLibraryTag(p.id,e):a.createLibraryTag(e)},onSuccess:()=>{s(r(p?`fileManager.tags.updated`:`fileManager.tags.created`),`success`),f(!1),m(null),g(``),S()},onError:e=>{s(e.message||r(`fileManager.tags.saveFailed`),`error`)}}),w=u({mutationFn:e=>a.deleteLibraryTag(e),onSuccess:()=>{s(r(`fileManager.tags.deleted`),`success`),y(null),S()},onError:e=>{s(e.message||r(`fileManager.tags.deleteFailed`),`error`)}}),T=()=>{m(null),g(``),f(!0)},E=e=>{m(e),g(e.name),f(!0)},D=(0,R.useCallback)(()=>{C.isPending||(f(!1),m(null),g(``))},[C.isPending]);(0,R.useEffect)(()=>{if(!e)return;let n=e=>{e.key===`Escape`&&(C.isPending||w.isPending||(d?D():_||t()))};return document.addEventListener(`keydown`,n),()=>document.removeEventListener(`keydown`,n)},[e,d,_,C.isPending,w.isPending,D,t]);let O=e=>{e.preventDefault(),C.mutate()};if(!e)return null;let k=`library-tags-modal-title`,A=`library-tag-editor-title`;return(0,z.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[(0,z.jsx)(`div`,{className:`absolute inset-0 bg-black/60`,onClick:()=>{C.isPending||w.isPending||t()}}),(0,z.jsxs)(`div`,{className:`relative w-full max-w-4xl 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":k,children:[(0,z.jsxs)(`div`,{className:`flex items-center justify-between gap-4 px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,z.jsxs)(`h2`,{id:k,className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,z.jsx)(xe,{className:`w-5 h-5 text-bambu-green`}),r(`fileManager.tags.title`)]}),(0,z.jsx)(`p`,{className:`text-bambu-gray text-sm mt-0.5`,children:r(`fileManager.tags.subtitle`)})]}),(0,z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,z.jsxs)(P,{onClick:T,children:[(0,z.jsx)(Oe,{className:`w-4 h-4`}),r(`fileManager.tags.add`)]}),(0,z.jsx)(`button`,{type:`button`,className:`p-1.5 text-bambu-gray hover:text-white rounded`,onClick:t,"aria-label":r(`common.close`),children:(0,z.jsx)(ae,{className:`w-5 h-5`})})]})]}),(0,z.jsx)(`div`,{className:`overflow-y-auto`,children:x?(0,z.jsxs)(`div`,{className:`flex items-center justify-center py-16 text-bambu-gray`,children:[(0,z.jsx)(j,{className:`w-6 h-6 animate-spin mr-2`}),r(`common.loading`)]}):b.length===0?(0,z.jsx)(`div`,{className:`py-16 text-center text-bambu-gray`,children:r(`fileManager.tags.empty`)}):(0,z.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,z.jsx)(`thead`,{children:(0,z.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary text-left text-bambu-gray`,children:[(0,z.jsx)(`th`,{className:`px-4 py-3 font-medium`,children:r(`fileManager.tags.name`)}),(0,z.jsx)(`th`,{className:`px-4 py-3 font-medium text-right`,children:r(`fileManager.tags.fileCount`)}),(0,z.jsx)(`th`,{className:`px-4 py-3 font-medium text-right w-32`,children:r(`common.actions`)})]})}),(0,z.jsx)(`tbody`,{children:b.map(e=>(0,z.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/60 hover:bg-bambu-dark-tertiary/30 ${n?`cursor-pointer`:``}`,onClick:()=>{n&&(n(e.id),t())},children:[(0,z.jsx)(`td`,{className:`px-4 py-3 text-white font-medium`,children:e.name}),(0,z.jsx)(`td`,{className:`px-4 py-3 text-right text-bambu-gray`,children:e.file_count}),(0,z.jsx)(`td`,{className:`px-4 py-3 text-right`,onClick:e=>e.stopPropagation(),children:(0,z.jsxs)(`div`,{className:`flex items-center justify-end gap-1`,children:[(0,z.jsx)(`button`,{type:`button`,className:`p-1.5 text-bambu-gray hover:text-bambu-green rounded`,onClick:()=>E(e),title:r(`common.edit`),"aria-label":r(`fileManager.tags.editAria`,{name:e.name}),children:(0,z.jsx)(ue,{className:`w-4 h-4`})}),(0,z.jsx)(`button`,{type:`button`,className:`p-1.5 text-bambu-gray hover:text-red-600 dark:hover:text-red-400 rounded`,onClick:()=>y(e),title:r(`common.delete`),"aria-label":r(`fileManager.tags.deleteAria`,{name:e.name}),children:(0,z.jsx)(de,{className:`w-4 h-4`})})]})})]},e.id))})]})})]}),d&&(0,z.jsxs)(`div`,{className:`fixed inset-0 z-[60] flex items-center justify-center`,children:[(0,z.jsx)(`div`,{className:`absolute inset-0 bg-black/60`,onClick:D}),(0,z.jsxs)(`div`,{className:`relative w-full max-w-md mx-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl p-6 shadow-2xl`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":A,children:[(0,z.jsx)(`h3`,{id:A,className:`text-lg font-semibold text-white mb-4`,children:r(p?`fileManager.tags.edit`:`fileManager.tags.add`)}),(0,z.jsxs)(`form`,{onSubmit:O,children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,htmlFor:`library-tag-name`,children:r(`fileManager.tags.name`)}),(0,z.jsx)(`input`,{id:`library-tag-name`,type:`text`,maxLength:64,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green mb-4`,placeholder:r(`fileManager.tags.createPlaceholder`),value:h,onChange:e=>g(e.target.value),autoFocus:!0}),(0,z.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,z.jsx)(P,{type:`button`,variant:`secondary`,onClick:D,children:r(`common.cancel`)}),(0,z.jsxs)(P,{type:`submit`,disabled:C.isPending||!h.trim(),children:[C.isPending&&(0,z.jsx)(j,{className:`w-4 h-4 animate-spin`}),r(`common.save`)]})]})]})]})]}),_&&(0,z.jsx)(ke,{title:r(`fileManager.tags.confirmDelete`,{name:_.name}),message:_.file_count>0?r(`fileManager.tags.confirmDeleteInUseMessage`,{count:_.file_count}):r(`fileManager.tags.confirmDeleteMessage`),confirmText:r(`common.delete`),variant:`danger`,isLoading:w.isPending,onConfirm:()=>w.mutate(_.id),onCancel:()=>y(null)})]})}function Wc({file:e,canEdit:t,onClose:n}){let{t:r}=o(),{showToast:i}=v(),s=c(),{data:d}=l({queryKey:[`library-file`,e.id],queryFn:()=>a.getLibraryFile(e.id)}),[f,p]=(0,R.useState)(``),[m,h]=(0,R.useState)(``),[g,_]=(0,R.useState)([]),[y,b]=(0,R.useState)(!1),[x,S]=(0,R.useState)(null),C=(0,R.useRef)(null),w=(0,R.useRef)(null);(0,R.useEffect)(()=>{!d||w.current===d.id||(w.current=d.id,p(d.notes??``),h(d.external_url??``),_(d.photos??[]))},[d]),(0,R.useEffect)(()=>{if(x!==null)return;let e=e=>{e.key===`Escape`&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[x,n]);let T=()=>{s.invalidateQueries({queryKey:[`library-files`]}),s.invalidateQueries({queryKey:[`library-file`,e.id]})},E=u({mutationFn:()=>a.updateLibraryFile(e.id,{notes:f,external_url:m.trim()}),onSuccess:()=>{T(),i(r(`fileManager.details.saved`),`success`),n()},onError:()=>{i(r(`fileManager.details.saveFailed`),`error`)}}),D=!!d&&(f!==(d.notes??``)||m.trim()!==(d.external_url??``)),O=async t=>{let n=t.target.files?.[0];if(n){b(!0);try{_((await a.uploadLibraryFilePhoto(e.id,n)).photos),T()}catch{i(r(`fileManager.details.uploadFailed`),`error`)}finally{b(!1),C.current&&(C.current.value=``)}}},k=async t=>{try{let n=(await a.deleteLibraryFilePhoto(e.id,t)).photos??[];_(n),n.length===0&&S(null),T()}catch{i(r(`fileManager.details.deleteFailed`),`error`)}},A=e=>{e.preventDefault(),!(!t||!D)&&E.mutate()},ee=m.trim(),M=[{label:r(`fileManager.details.size`),value:oe(e.file_size)},{label:r(`fileManager.details.type`),value:e.file_type.toUpperCase()}];if(d?.print_name&&M.push({label:r(`fileManager.details.printName`),value:d.print_name}),d?.print_time_seconds&&M.push({label:r(`fileManager.details.printTime`),value:ce(d.print_time_seconds)}),d?.filament_used_grams&&M.push({label:r(`fileManager.details.filament`),value:`${d.filament_used_grams.toFixed(1)} g`}),d?.sliced_for_model&&M.push({label:r(`fileManager.details.slicedFor`),value:d.sliced_for_model}),d?.source_url){let e=/^https?:\/\//i.test(d.source_url);M.push({label:r(`fileManager.details.source`),value:e?(0,z.jsxs)(`a`,{href:d.source_url,target:`_blank`,rel:`noopener noreferrer`,className:`text-bambu-green hover:underline inline-flex items-center gap-1 min-w-0`,children:[(0,z.jsx)(`span`,{className:`truncate`,children:d.source_url}),(0,z.jsx)(fe,{className:`w-3 h-3 flex-shrink-0`})]}):(0,z.jsx)(`span`,{className:`truncate`,children:d.source_url})})}return M.push({label:r(`fileManager.details.created`),value:se(e.created_at)}),M.push({label:r(`fileManager.details.modified`),value:se(e.fs_modified_at??d?.updated_at??e.created_at)}),(0,z.jsxs)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:n,children:[(0,z.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-lg max-h-[90vh] flex flex-col`,onClick:e=>e.stopPropagation(),children:[(0,z.jsxs)(`div`,{className:`flex items-center justify-between gap-3 px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,z.jsxs)(`div`,{className:`min-w-0`,children:[(0,z.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:r(`fileManager.details.title`)}),(0,z.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,z.jsx)(`h2`,{className:`text-lg font-semibold text-white truncate`,title:e.filename,children:e.filename}),(0,z.jsx)(`span`,{className:`flex-shrink-0 text-xs px-1.5 py-0.5 rounded font-medium bg-bambu-dark-tertiary text-bambu-gray`,children:e.file_type.toUpperCase()})]})]}),(0,z.jsx)(`button`,{type:`button`,onClick:n,className:`text-bambu-gray hover:text-white transition-colors flex-shrink-0`,"aria-label":r(`common.close`),children:(0,z.jsx)(ae,{className:`w-5 h-5`})})]}),(0,z.jsxs)(`form`,{onSubmit:A,className:`p-6 space-y-4 overflow-y-auto flex-1`,children:[(0,z.jsx)(`dl`,{className:`grid grid-cols-[auto_1fr] gap-x-4 gap-y-1 text-sm`,children:M.map(e=>(0,z.jsxs)(`div`,{className:`contents`,children:[(0,z.jsx)(`dt`,{className:`text-bambu-gray whitespace-nowrap`,children:e.label}),(0,z.jsx)(`dd`,{className:`text-white min-w-0 truncate`,children:e.value})]},e.label))}),(0,z.jsxs)(`div`,{children:[(0,z.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[(0,z.jsx)(ne,{className:`w-4 h-4 inline mr-1`}),r(`fileManager.details.notes`)]}),(0,z.jsx)(`textarea`,{value:f,onChange:e=>p(e.target.value),rows:3,disabled:!t,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none resize-none disabled:opacity-60`,placeholder:r(`fileManager.details.notesPlaceholder`)})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[(0,z.jsx)(Pe,{className:`w-4 h-4 inline mr-1`}),r(`fileManager.details.externalLink`)]}),(0,z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,z.jsx)(`input`,{type:`url`,value:m,onChange:e=>h(e.target.value),disabled:!t,className:`flex-1 min-w-0 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none disabled:opacity-60`,placeholder:r(`fileManager.details.externalLinkPlaceholder`)}),ee&&(0,z.jsx)(`a`,{href:ee,target:`_blank`,rel:`noopener noreferrer`,className:`p-2 rounded-lg text-bambu-gray hover:text-bambu-green hover:bg-bambu-dark transition-colors`,title:r(`fileManager.details.openLink`),"aria-label":r(`fileManager.details.openLink`),children:(0,z.jsx)(fe,{className:`w-4 h-4`})})]})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[(0,z.jsx)(be,{className:`w-4 h-4 inline mr-1`}),r(`fileManager.details.photos`)]}),(0,z.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[g.map((n,i)=>(0,z.jsxs)(`div`,{className:`relative group`,children:[(0,z.jsx)(`button`,{type:`button`,onClick:()=>S(i),className:`block w-20 h-20 rounded-lg overflow-hidden border border-bambu-dark-tertiary hover:border-bambu-green transition-colors`,children:(0,z.jsx)(`img`,{src:a.getLibraryFilePhotoUrl(e.id,n),alt:r(`fileManager.details.photos`),className:`w-full h-full object-cover`})}),t&&(0,z.jsx)(`button`,{type:`button`,onClick:()=>k(n),className:`absolute -top-1 -right-1 p-1 bg-red-500 rounded-full can-hover:opacity-0 group-hover:opacity-100 focus-visible:opacity-100 transition-opacity`,title:r(`fileManager.details.deletePhoto`),"aria-label":r(`fileManager.details.deletePhoto`),children:(0,z.jsx)(de,{className:`w-3 h-3 text-white`})})]},n)),t&&(0,z.jsxs)(`label`,{className:`w-20 h-20 flex items-center justify-center border-2 border-dashed border-bambu-dark-tertiary rounded-lg cursor-pointer hover:border-bambu-green transition-colors`,title:r(`fileManager.details.addPhoto`),children:[(0,z.jsx)(`input`,{ref:C,type:`file`,accept:`image/jpeg,image/png,image/webp`,onChange:O,className:`hidden`,disabled:y,"aria-label":r(`fileManager.details.addPhoto`)}),y?(0,z.jsx)(j,{className:`w-6 h-6 text-bambu-gray animate-spin`}):(0,z.jsx)(Oe,{className:`w-6 h-6 text-bambu-gray`})]}),g.length===0&&!t&&(0,z.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:r(`fileManager.details.noPhotos`)})]})]}),(0,z.jsxs)(`div`,{className:`flex gap-3 pt-2`,children:[(0,z.jsx)(P,{type:`button`,variant:`secondary`,onClick:n,className:`flex-1`,children:r(`common.close`)}),t&&(0,z.jsxs)(P,{type:`submit`,variant:`primary`,className:`flex-1`,disabled:!D||E.isPending,children:[E.isPending?(0,z.jsx)(j,{className:`w-4 h-4 animate-spin`}):(0,z.jsx)(Te,{className:`w-4 h-4`}),r(`fileManager.details.save`)]})]})]})]}),x!==null&&g.length>0&&(0,z.jsx)(We,{archiveName:e.filename,photos:g,initialIndex:x,getPhotoUrl:t=>a.getLibraryFilePhotoUrl(e.id,t),onClose:()=>S(null),onDelete:t?k:void 0})]})}var Gc=90;function Kc({onClose:e}){let{t}=o(),n=c(),{showToast:r}=v(),[i,s]=(0,R.useState)(Gc),[d,f]=(0,R.useState)(!0),[p,m]=(0,R.useState)(i);(0,R.useEffect)(()=>{let e=window.setTimeout(()=>m(i),300);return()=>window.clearTimeout(e)},[i]);let h=l({queryKey:[`library-purge-preview`,p,d],queryFn:()=>a.previewLibraryPurge(p,d),enabled:p>=1}),g=u({mutationFn:()=>a.executeLibraryPurge(i,d),onSuccess:i=>{r(t(`libraryPurge.toast.success`,{count:i.moved_to_trash}),`success`),n.invalidateQueries({queryKey:[`library-files`]}),n.invalidateQueries({queryKey:[`library-folders`]}),n.invalidateQueries({queryKey:[`library-trash`]}),n.invalidateQueries({queryKey:[`library-trash-count`]}),e()},onError:e=>r(e.message||t(`libraryPurge.toast.failed`),`error`)});(0,R.useEffect)(()=>{let t=t=>{t.key===`Escape`&&!g.isPending&&e()};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e,g.isPending]);let _=h.data,y=_?.count??0,b=_?.total_bytes??0,x=y>0&&!g.isPending;return(0,z.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4`,children:(0,z.jsxs)(`div`,{className:`bg-white dark:bg-gray-900 rounded-lg shadow-xl max-w-lg w-full`,children:[(0,z.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-gray-200 dark:border-gray-700`,children:[(0,z.jsxs)(`h2`,{className:`text-lg font-semibold text-gray-900 dark:text-gray-100 flex items-center gap-2`,children:[(0,z.jsx)(de,{className:`w-5 h-5`}),t(`libraryPurge.title`)]}),(0,z.jsx)(`button`,{onClick:e,className:`text-gray-400 hover:text-gray-600 dark:hover:text-gray-200`,"aria-label":t(`common.close`),disabled:g.isPending,children:(0,z.jsx)(ae,{className:`w-5 h-5`})})]}),(0,z.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,z.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400`,children:t(`libraryPurge.description`)}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{htmlFor:`purge-days`,className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:t(`libraryPurge.ageLabel`)}),(0,z.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,z.jsx)(`input`,{id:`purge-days`,type:`number`,min:1,max:3650,value:i,onChange:e=>s(Math.max(1,Math.min(3650,parseInt(e.target.value||`0`,10)||0))),className:`w-24 rounded border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-800 text-sm px-2 py-1 text-gray-900 dark:text-gray-100`}),(0,z.jsx)(`span`,{className:`text-sm text-gray-600 dark:text-gray-400`,children:t(`libraryPurge.days`)})]})]}),(0,z.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-gray-700 dark:text-gray-300`,children:[(0,z.jsx)(`input`,{type:`checkbox`,checked:d,onChange:e=>f(e.target.checked),className:`rounded border-gray-300`}),t(`libraryPurge.includeNeverPrinted`)]}),(0,z.jsxs)(`div`,{className:`rounded border border-gray-200 dark:border-gray-700 bg-gray-50 dark:bg-gray-800/30 p-3`,children:[(0,z.jsx)(`div`,{className:`text-xs font-semibold uppercase tracking-wide text-gray-600 dark:text-gray-300 mb-2`,children:t(`libraryPurge.effectsTitle`)}),(0,z.jsxs)(`ul`,{className:`text-xs text-gray-700 dark:text-gray-300 space-y-1 list-disc pl-4`,children:[(0,z.jsx)(`li`,{children:t(`libraryPurge.effect1`)}),(0,z.jsx)(`li`,{children:t(`libraryPurge.effect2`)}),(0,z.jsx)(`li`,{children:t(`libraryPurge.effect3`)}),(0,z.jsx)(`li`,{children:t(`libraryPurge.effect4`)})]})]}),(0,z.jsx)(`div`,{className:`rounded border border-gray-200 dark:border-gray-700 bg-gray-50 dark:bg-gray-800/50 p-3`,children:h.isLoading||h.isFetching?(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-gray-500 dark:text-gray-400`,children:[(0,z.jsx)(j,{className:`w-4 h-4 animate-spin`}),` `,t(`libraryPurge.previewLoading`)]}):h.isError?(0,z.jsx)(`div`,{className:`text-sm text-red-600 dark:text-red-400`,children:h.error?.message??t(`libraryPurge.previewFailed`)}):(0,z.jsxs)(`div`,{className:`text-sm text-gray-900 dark:text-gray-100`,children:[(0,z.jsx)(`div`,{className:`font-medium`,children:t(`libraryPurge.previewSummary`,{count:y,size:oe(b)})}),_?.sample_filenames&&_.sample_filenames.length>0&&(0,z.jsxs)(`ul`,{className:`mt-2 text-xs text-gray-600 dark:text-gray-400 space-y-0.5 list-disc pl-4`,children:[_.sample_filenames.map(e=>(0,z.jsx)(`li`,{className:`truncate`,children:e},e)),y>_.sample_filenames.length&&(0,z.jsx)(`li`,{className:`list-none italic text-gray-500`,children:t(`libraryPurge.andMore`,{count:y-_.sample_filenames.length})})]})]})}),(0,z.jsxs)(`div`,{className:`flex gap-2 items-start text-xs text-amber-700 dark:text-amber-400 bg-amber-50 dark:bg-amber-900/20 rounded px-3 py-2`,children:[(0,z.jsx)(re,{className:`w-4 h-4 mt-0.5 shrink-0`}),(0,z.jsx)(`span`,{children:t(`libraryPurge.warning`)})]})]}),(0,z.jsxs)(`div`,{className:`flex justify-end gap-2 p-4 border-t border-gray-200 dark:border-gray-700`,children:[(0,z.jsx)(P,{variant:`secondary`,onClick:e,disabled:g.isPending,children:t(`common.cancel`)}),(0,z.jsx)(P,{variant:`danger`,disabled:!x,onClick:()=>g.mutate(),children:g.isPending?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(j,{className:`w-4 h-4 animate-spin mr-1`}),t(`libraryPurge.purging`)]}):t(`libraryPurge.confirmCta`,{count:y})})]})]})})}var qc=(0,R.lazy)(()=>I(()=>import(`./PdfPreviewModal-gJCfcyUW.js`).then(e=>({default:e.PdfPreviewModal})),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28]))),Jc=(0,R.lazy)(()=>I(()=>import(`./SpreadsheetPreviewModal-KGR-XjV_.js`).then(e=>({default:e.SpreadsheetPreviewModal})),__vite__mapDeps([29,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,30,26,27,28]))),Yc=(0,R.lazy)(()=>I(()=>import(`./ImagePreviewModal-NAGAMcx7.js`).then(e=>({default:e.ImagePreviewModal})),__vite__mapDeps([31,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28])));function Xc(e){return e===`csv`||e===`xlsx`||e===`ods`}function Zc(e){return e===`step`||e===`stp`}var Qc=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`bmp`,`tiff`,`tif`]),$c=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`bmp`]);function el(e){return Qc.has(e.toLowerCase())}function tl(e){return $c.has(e.toLowerCase())}function nl({fileType:e,className:t}){return(0,z.jsx)(e===`pdf`?Re:Xc(e)?C:el(e)?Fe:S,{className:t})}function rl(e){return{results:e,files:e.flatMap(e=>e.data??[])}}function il(e){let t=e.file_type;return Ze(e)||t===`3mf`||t===`stl`||Zc(t)||t===`pdf`||Xc(t)||tl(t)}var al={onClick:e=>e.stopPropagation(),onDoubleClick:e=>e.stopPropagation()};function ol(e){return Ze(e)||e.file_type===`3mf`||e.file_type===`stl`||Zc(e.file_type)}function sl(e){return e===`pdf`?(0,z.jsx)(Re,{className:`w-4 h-4`}):Xc(e)?(0,z.jsx)(C,{className:`w-4 h-4`}):(0,z.jsx)(Fe,{className:`w-4 h-4`})}function cl(e){return e===`stl`||e===`pdf`}function ll(e){return e===`3mf`?`bg-bambu-green/20 text-bambu-green`:e===`gcode`||e===`gcode.3mf`?`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`:e===`stl`?`bg-purple-100 dark:bg-purple-500/20 text-purple-700 dark:text-purple-400`:Zc(e)?`bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400`:e===`pdf`?`bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400`:Xc(e)?`bg-teal-100 dark:bg-teal-500/20 text-teal-700 dark:text-teal-400`:`bg-bambu-gray/20 text-bambu-gray`}function ul(e,t){let n=[...e],r=t.query?.trim().toLowerCase();r&&(n=n.filter(e=>e.filename.toLowerCase().includes(r)||e.print_name&&e.print_name.toLowerCase().includes(r))),t.filterType!==`all`&&(n=n.filter(e=>e.file_type===t.filterType));let i=t.filterUsername.trim().toLowerCase();return i&&(n=n.filter(e=>e.created_by_username&&e.created_by_username.toLowerCase().includes(i))),n.sort((e,n)=>{let r=0;switch(t.sortField){case`name`:r=(e.print_name||e.filename).localeCompare(n.print_name||n.filename);break;case`date`:r=(le(e.fs_modified_at??e.created_at)?.getTime()??0)-(le(n.fs_modified_at??n.created_at)?.getTime()??0);break;case`size`:r=e.file_size-n.file_size;break;case`type`:r=e.file_type.localeCompare(n.file_type);break;case`prints`:r=e.print_count-n.print_count;break}return t.sortDirection===`asc`?r:-r}),n}var dl=e=>e?`grid-cols-[24px_minmax(240px,1fr)_120px_100px_100px_100px_minmax(96px,200px)_220px]`:`grid-cols-[24px_minmax(240px,1fr)_100px_100px_100px_minmax(96px,200px)_220px]`,fl=`min-w-min`;function pl({parentId:e,onClose:t,onSave:n,isLoading:r,t:i}){let[a,o]=(0,R.useState)(``);return(0,z.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,z.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-sm border border-bambu-dark-tertiary`,children:[(0,z.jsx)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary`,children:(0,z.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`fileManager.newFolder`)})}),(0,z.jsxs)(`form`,{onSubmit:t=>{t.preventDefault(),n({name:a.trim(),parent_id:e})},className:`p-4 space-y-4`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:i(`fileManager.folderName`)}),(0,z.jsx)(`input`,{type:`text`,value:a,onChange:e=>o(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:i(`fileManager.folderNamePlaceholder`),autoFocus:!0,required:!0})]}),(0,z.jsxs)(`div`,{className:`flex justify-end gap-2 pt-2`,children:[(0,z.jsx)(P,{type:`button`,variant:`secondary`,onClick:t,children:i(`common.cancel`)}),(0,z.jsx)(P,{type:`submit`,disabled:!a.trim()||r,children:r?(0,z.jsx)(j,{className:`w-4 h-4 animate-spin`}):i(`common.create`)})]})]})]})})}function ml({onClose:e,onSave:t,isLoading:n,t:r}){let[i,a]=(0,R.useState)(``),[o,s]=(0,R.useState)(``),[c,l]=(0,R.useState)(!0),[u,d]=(0,R.useState)(!1);return(0,z.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,z.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-md border border-bambu-dark-tertiary`,children:[(0,z.jsxs)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary`,children:[(0,z.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,z.jsx)(it,{className:`w-5 h-5 text-bambu-green`}),r(`fileManager.linkExternalFolder`)]}),(0,z.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:r(`fileManager.linkExternalFolderDescription`)})]}),(0,z.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),t({name:i.trim(),external_path:o.trim(),readonly:c,show_hidden:u})},className:`p-4 space-y-4`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:r(`fileManager.folderName`)}),(0,z.jsx)(`input`,{type:`text`,value:i,onChange:e=>a(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:r(`fileManager.externalFolderNamePlaceholder`),autoFocus:!0,required:!0})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:r(`fileManager.externalPath`)}),(0,z.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 font-mono text-sm`,placeholder:`/mnt/nas/3d-prints`,required:!0}),(0,z.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:r(`fileManager.externalPathHelp`)})]}),(0,z.jsxs)(`div`,{className:`space-y-2`,children:[(0,z.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,z.jsx)(`input`,{type:`checkbox`,checked:c,onChange:e=>l(e.target.checked),className:`rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,z.jsx)(`span`,{className:`text-sm text-white`,children:r(`fileManager.readOnly`)}),(0,z.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[`(`,r(`fileManager.readOnlyHelp`),`)`]})]}),(0,z.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,z.jsx)(`input`,{type:`checkbox`,checked:u,onChange:e=>d(e.target.checked),className:`rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,z.jsx)(`span`,{className:`text-sm text-white`,children:r(`fileManager.showHiddenFiles`)})]})]}),(0,z.jsxs)(`div`,{className:`flex justify-end gap-2 pt-2`,children:[(0,z.jsx)(P,{type:`button`,variant:`secondary`,onClick:e,children:r(`common.cancel`)}),(0,z.jsx)(P,{type:`submit`,disabled:!i.trim()||!o.trim()||n,children:n?(0,z.jsx)(j,{className:`w-4 h-4 animate-spin`}):r(`fileManager.linkFolder`)})]})]})]})})}var hl=`<>:"/\\|?*`;function gl(e){for(let t of e)if(hl.includes(t)||t.charCodeAt(0)<32)return t;return null}function _l({type:e,currentName:t,onClose:n,onSave:r,isLoading:i,t:a}){let o=e===`file`?t.match(/(\.gcode\.3mf|\.3mf|\.gcode)$/i)?.[1]??``:``,s=e===`file`&&o?t.slice(0,-o.length):t,[c,l]=(0,R.useState)(s),u=e===`file`?gl(c):null,d=u?a(`fileManager.invalidFilenameChar`,{char:u}):null;return(0,z.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,z.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-sm border border-bambu-dark-tertiary`,children:[(0,z.jsx)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary`,children:(0,z.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:a(e===`file`?`fileManager.renameFile`:`fileManager.renameFolder`)})}),(0,z.jsxs)(`form`,{onSubmit:n=>{if(n.preventDefault(),d)return;let i=e===`file`?c.trim()+o:c.trim();c.trim()&&i!==t&&r(i)},className:`p-4 space-y-4`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`common.name`)}),(0,z.jsxs)(`div`,{className:`flex items-center bg-bambu-dark border rounded focus-within:border-bambu-green ${d?`border-red-500`:`border-bambu-dark-tertiary`}`,children:[(0,z.jsx)(`input`,{type:`text`,value:c,onChange:e=>l(e.target.value),className:`flex-1 bg-transparent px-3 py-2 text-white placeholder-bambu-gray focus:outline-none min-w-0`,autoFocus:!0,required:!0}),o&&(0,z.jsx)(`span`,{className:`pr-3 text-bambu-gray text-sm select-none whitespace-nowrap`,children:o})]}),d&&(0,z.jsx)(`p`,{className:`mt-1 text-xs text-red-700 dark:text-red-400`,children:d})]}),(0,z.jsxs)(`div`,{className:`flex justify-end gap-2 pt-2`,children:[(0,z.jsx)(P,{type:`button`,variant:`secondary`,onClick:n,children:a(`common.cancel`)}),(0,z.jsx)(P,{type:`submit`,disabled:!c.trim()||c.trim()===s||!!d||i,children:i?(0,z.jsx)(j,{className:`w-4 h-4 animate-spin`}):a(`common.rename`)})]})]})]})})}function vl({folders:e,selectedFiles:t,currentFolderId:n,onClose:r,onMove:i,isLoading:a,t:o}){let[s,c]=(0,R.useState)(null),l=(e,t=0)=>{let n=[];for(let r of e)n.push({id:r.id,name:r.name,depth:t,canWrite:r.can_write!==!1}),r.children.length>0&&n.push(...l(r.children,t+1));return n},u=[{id:null,name:o(`fileManager.rootNoFolder`),depth:0,canWrite:!0},...l(e)];return(0,z.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,z.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-sm border border-bambu-dark-tertiary`,children:[(0,z.jsx)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary`,children:(0,z.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:o(`fileManager.moveFiles`,{count:t.length})})}),(0,z.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,z.jsx)(`div`,{className:`max-h-64 overflow-y-auto space-y-1`,children:u.map(e=>(0,z.jsxs)(`button`,{onClick:()=>c(e.id),disabled:e.id===n||!e.canWrite,title:e.canWrite?void 0:o(`fileManager.folderNotWritable`),className:`w-full text-left px-3 py-2 rounded transition-colors flex items-center gap-2 ${s===e.id?`bg-bambu-green/20 text-bambu-green`:e.id===n||!e.canWrite?`opacity-50 cursor-not-allowed text-bambu-gray`:`hover:bg-bambu-dark text-white`}`,style:{paddingLeft:`${12+e.depth*16}px`},children:[(0,z.jsx)(Ie,{className:`w-4 h-4`}),e.name,e.id===n&&(0,z.jsxs)(`span`,{className:`text-xs text-bambu-gray ml-auto`,children:[`(`,o(`fileManager.current`),`)`]})]},e.id??`root`))}),(0,z.jsxs)(`div`,{className:`flex justify-end gap-2 pt-2`,children:[(0,z.jsx)(P,{type:`button`,variant:`secondary`,onClick:r,children:o(`common.cancel`)}),(0,z.jsx)(P,{onClick:()=>i(s),disabled:a,children:a?(0,z.jsx)(j,{className:`w-4 h-4 animate-spin`}):o(`common.move`)})]})]})]})})}function yl({folder:e,onClose:t,onLink:n,isLoading:r,t:i}){let[o,s]=(0,R.useState)(`project`),[c,u]=(0,R.useState)(e.project_id||e.archive_id||null);(0,R.useState)(()=>{e.archive_id&&s(`archive`)});let{data:d}=l({queryKey:[`projects`],queryFn:()=>a.getProjects(),select:t=>F([...t].sort((e,t)=>e.name.localeCompare(t.name)),e.project_id)}),{data:f}=l({queryKey:[`archives-for-link`],queryFn:()=>a.getArchives(void 0,void 0,100)}),p=()=>{n(o===`project`?{project_id:c,archive_id:0}:{project_id:0,archive_id:c})},h=()=>{n({project_id:0,archive_id:0})},g=e.project_id||e.archive_id;return(0,z.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,z.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-md border border-bambu-dark-tertiary`,children:[(0,z.jsxs)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary flex items-center justify-between`,children:[(0,z.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,z.jsx)(A,{className:`w-5 h-5 text-bambu-green`}),i(`fileManager.linkFolder`)]}),(0,z.jsx)(`button`,{onClick:t,className:`p-1 hover:bg-bambu-dark rounded`,children:(0,z.jsx)(ae,{className:`w-5 h-5 text-bambu-gray`})})]}),(0,z.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,z.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`fileManager.linkFolderDescription`,{name:e.name})}),(0,z.jsxs)(`div`,{className:`flex gap-2`,children:[(0,z.jsxs)(`button`,{onClick:()=>{s(`project`),u(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg border transition-colors ${o===`project`?`border-bambu-green bg-bambu-green/10 text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:text-white`}`,children:[(0,z.jsx)(m,{className:`w-4 h-4`}),i(`fileManager.project`)]}),(0,z.jsxs)(`button`,{onClick:()=>{s(`archive`),u(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg border transition-colors ${o===`archive`?`border-bambu-green bg-bambu-green/10 text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:text-white`}`,children:[(0,z.jsx)(he,{className:`w-4 h-4`}),i(`fileManager.archive`)]})]}),(0,z.jsx)(`div`,{className:`max-h-64 overflow-y-auto space-y-1 bg-bambu-dark rounded-lg p-2`,children:o===`project`?d&&d.length>0?d.map(e=>(0,z.jsxs)(`button`,{onClick:()=>u(e.id),className:`w-full text-left px-3 py-2 rounded transition-colors flex items-center gap-2 ${c===e.id?`bg-bambu-green/20 text-bambu-green`:`hover:bg-bambu-dark-tertiary text-white`}`,children:[(0,z.jsx)(`div`,{className:`w-3 h-3 rounded-full flex-shrink-0`,style:{backgroundColor:e.color||`#00ae42`}}),(0,z.jsx)(`span`,{className:`truncate`,children:e.name})]},e.id)):(0,z.jsx)(`p`,{className:`text-sm text-bambu-gray text-center py-4`,children:i(`fileManager.noProjectsFound`)}):f&&f.length>0?f.map(e=>(0,z.jsxs)(`button`,{onClick:()=>u(e.id),className:`w-full text-left px-3 py-2 rounded transition-colors flex items-center gap-2 ${c===e.id?`bg-bambu-green/20 text-bambu-green`:`hover:bg-bambu-dark-tertiary text-white`}`,children:[(0,z.jsx)(S,{className:`w-4 h-4 text-bambu-gray flex-shrink-0`}),(0,z.jsx)(`span`,{className:`truncate`,children:e.print_name||e.filename})]},e.id)):(0,z.jsx)(`p`,{className:`text-sm text-bambu-gray text-center py-4`,children:i(`fileManager.noArchivesFound`)})})]}),(0,z.jsxs)(`div`,{className:`p-4 border-t border-bambu-dark-tertiary flex justify-between`,children:[g&&(0,z.jsxs)(P,{variant:`danger`,onClick:h,disabled:r,children:[(0,z.jsx)(ie,{className:`w-4 h-4 mr-2`}),i(`fileManager.unlink`)]}),(0,z.jsxs)(`div`,{className:`flex gap-2 ${g?``:`ml-auto`}`,children:[(0,z.jsx)(P,{variant:`secondary`,onClick:t,children:i(`common.cancel`)}),(0,z.jsx)(P,{onClick:p,disabled:!c||r,children:r?(0,z.jsx)(j,{className:`w-4 h-4 animate-spin`}):i(`fileManager.link`)})]})]})]})})}function bl({folder:e,onDelete:t,onLink:n,onRename:r,onToggleShared:i,hasPermission:a,revealOnHover:o=!1,tabIndex:s,t:c}){let[l,u]=(0,R.useState)(null),d=(0,R.useRef)(null),f=(0,R.useRef)(null),p=()=>{u(null),d.current?.contains(document.activeElement)&&f.current?.focus()},m=e.children.length>0,h=e.project_id||e.archive_id,g=e.is_external,_=e.can_delete??(a(`library:delete_all`)||a(`library:delete_own`)&&e.file_count===0&&!m&&!g&&!h),v=_?void 0:a(`library:delete_own`)&&!g&&!h?c(`fileManager.onlyOwnFoldersDeletable`):c(`fileManager.noPermissionDeleteFolder`),y=e.can_rename??a(`library:update_all`),b=a(`library:update_all`),S=[{label:c(`common.rename`),icon:(0,z.jsx)(ue,{className:`w-3.5 h-3.5`}),onClick:()=>r(e),disabled:!y,title:y?void 0:c(`fileManager.noPermissionRenameFolder`)},{label:c(h?`fileManager.changeLink`:`fileManager.linkTo`),icon:(0,z.jsx)(A,{className:`w-3.5 h-3.5`}),onClick:()=>n(e),disabled:!b,title:b?void 0:c(`fileManager.noPermissionLinkFolder`)},...i&&b?[{label:e.shared?c(`fileManager.unshareFolder`):c(`fileManager.shareFolder`),icon:(0,z.jsx)(pe,{className:`w-3.5 h-3.5`}),onClick:()=>i(e),title:c(`fileManager.shareFolderHint`)}]:[],{label:c(`common.delete`),icon:(0,z.jsx)(de,{className:`w-3.5 h-3.5`}),onClick:()=>t(e.id),danger:!0,disabled:!_,title:v}];return(0,z.jsxs)(`div`,{ref:d,className:`relative flex-shrink-0 flex items-center transition-opacity ${o&&!l?`can-hover:opacity-0 group-hover:opacity-100 group-focus-within:opacity-100`:``}`,"data-folder-actions":!0,onClick:e=>e.stopPropagation(),onKeyDown:e=>{l&&(e.key===`ArrowUp`||e.key===`ArrowDown`)&&p()},children:[(0,z.jsx)(`button`,{ref:f,type:`button`,tabIndex:s,onClick:e=>{if(l){p();return}let t=e.currentTarget.getBoundingClientRect();u({x:t.left,y:t.bottom+4})},className:`p-1 rounded hover:bg-bambu-dark-tertiary`,title:c(`common.actions`),children:(0,z.jsx)(x,{className:`w-3.5 h-3.5 text-bambu-gray`})}),l&&(0,z.jsx)(T,{x:l.x,y:l.y,items:S,onClose:p,anchorRef:f})]})}function xl({folder:e,selectedFolderId:t,onSelect:n,onDelete:r,onLink:i,onRename:a,onToggleShared:o,depth:s=0,wrapNames:c=!1,defaultExpanded:l=!0,showModified:u=!1,hasPermission:d,t:f}){let[p,h]=(0,R.useState)(l),g=e.children.length>0,_=e.project_id||e.archive_id,v=e.is_external;return(0,z.jsxs)(`div`,{children:[(0,z.jsxs)(`div`,{className:`group flex items-center gap-1 px-2 py-1.5 rounded cursor-pointer transition-colors ${t===e.id?`bg-bambu-green/20 text-bambu-green`:`hover:bg-bambu-dark text-white`}`,style:{paddingLeft:`${8+s*12}px`},onClick:()=>n(e.id),children:[g?(0,z.jsx)(`button`,{onClick:e=>{e.stopPropagation(),h(!p)},className:`p-0.5 hover:bg-bambu-dark-tertiary rounded`,children:(0,z.jsx)(_e,{className:`w-3.5 h-3.5 transition-transform ${p?`rotate-90`:``}`})}):(0,z.jsx)(`div`,{className:`w-4.5`}),v?(0,z.jsx)(it,{className:`w-4 h-4 text-purple-600 dark:text-purple-400 flex-shrink-0`}):(0,z.jsx)(Ie,{className:`w-4 h-4 text-bambu-green flex-shrink-0`}),(0,z.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,z.jsx)(`span`,{className:`block text-sm ${c?`break-all`:`truncate`}`,title:e.name,children:e.name}),u&&e.latest_activity_at&&(0,z.jsxs)(`span`,{className:`mt-0.5 flex items-center gap-1 text-xs text-bambu-gray`,title:f(`fileManager.lastActivity`),children:[(0,z.jsx)(tt,{className:`w-3 h-3 flex-shrink-0`}),(0,z.jsx)(`span`,{className:`truncate`,children:se(e.latest_activity_at)})]})]}),_&&(0,z.jsxs)(`button`,{onClick:t=>{t.stopPropagation(),i(e)},className:`flex-shrink-0 flex items-center gap-1 text-xs px-1.5 py-0.5 rounded bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400 hover:bg-blue-200 dark:hover:bg-blue-500/30 transition-colors`,title:`${e.project_name?`Project: ${e.project_name}`:`Archive: ${e.archive_name}`} (click to change)`,children:[(0,z.jsx)(A,{className:`w-3 h-3`}),e.project_name?(0,z.jsx)(m,{className:`w-3 h-3`}):(0,z.jsx)(he,{className:`w-3 h-3`})]}),e.shared&&(0,z.jsx)(`span`,{title:f(`fileManager.sharedFolder`),children:(0,z.jsx)(pe,{className:`w-3 h-3 text-bambu-gray flex-shrink-0`})}),v&&e.external_readonly&&(0,z.jsx)(`span`,{title:f(`fileManager.readOnly`),children:(0,z.jsx)(M,{className:`w-3 h-3 text-amber-600 dark:text-amber-400 flex-shrink-0`})}),e.file_count>0&&(0,z.jsx)(`span`,{className:`flex-shrink-0 text-xs text-bambu-gray`,children:e.file_count}),!_&&!v&&(0,z.jsx)(`button`,{onClick:t=>{t.stopPropagation(),i(e)},className:`flex-shrink-0 p-1 rounded hover:bg-bambu-dark-tertiary`,title:f(`fileManager.linkToProjectOrArchive`),children:(0,z.jsx)(A,{className:`w-3.5 h-3.5 text-bambu-gray hover:text-bambu-green`})}),(0,z.jsx)(bl,{folder:e,onDelete:r,onLink:i,onRename:a,onToggleShared:o,hasPermission:d,revealOnHover:!c,t:f})]}),g&&p&&(0,z.jsx)(`div`,{children:e.children.map(e=>(0,z.jsx)(xl,{folder:e,selectedFolderId:t,onSelect:n,onDelete:r,onLink:i,onRename:a,onToggleShared:o,depth:s+1,wrapNames:c,defaultExpanded:l,showModified:u,hasPermission:d,t:f},e.id))})]})}function Sl({file:e,isSelected:t,onSelect:n,onDelete:r,onDownload:i,onPrint:o,onSlice:s,onOpenInSlicer:c,onRunPipeline:l,useSlicerApi:u,desktopSlicer:d,canSlice:f,onPreview:m,onRename:h,onDetails:g,onGenerateThumbnail:v,onTagClick:b,thumbnailVersion:S,hasPermission:C,canModify:w,authEnabled:E,showModified:D,t:O}){let[k,A]=(0,R.useState)(null),ee=C(`library:read`),j=w(`library`,`update`,e.created_by_id),M=w(`library`,`delete`,e.created_by_id),N=[];if(o&&Ze(e)&&N.push({label:O(`common.print`),icon:(0,z.jsx)(me,{className:`w-4 h-4 text-bambu-green`}),onClick:()=>o(e),disabled:!C(`queue:create`),title:C(`queue:create`)?void 0:O(`fileManager.noPermissionAddToQueue`)}),Qe(e,!!u,d)&&(u?s:c)&&N.push({label:O(`slice.action`),icon:u?(0,z.jsx)(y,{className:`w-4 h-4`}):(0,z.jsx)(fe,{className:`w-4 h-4`}),onClick:()=>{u?s?.(e):c?.(e)},disabled:!f,title:f?void 0:O(u?`fileManager.noPermissionSlice`:`fileManager.noPermissionDownload`)}),l&&u&&Qe(e,!0,d)&&N.push({label:O(`library.runWithPipeline.actionLabel`),icon:(0,z.jsx)(te,{className:`w-4 h-4`}),onClick:()=>l(e),disabled:!C(`pipelines:run`),title:C(`pipelines:run`)?void 0:O(`library.runWithPipeline.noPermission`)}),m&&il(e)){let t=ol(e);N.push({label:O(t?`fileManager.preview3d`:`fileManager.preview.open`),icon:t?(0,z.jsx)(p,{className:`w-4 h-4`}):sl(e.file_type),onClick:()=>m(e),disabled:!ee,title:ee?void 0:O(`fileManager.noPermissionPreview`)})}return N.push({label:O(`common.download`),icon:(0,z.jsx)(Le,{className:`w-4 h-4`}),onClick:()=>i(e.id),disabled:!C(`library:read`),title:C(`library:read`)?void 0:O(`fileManager.noPermissionDownload`)}),h&&N.push({label:O(`common.rename`),icon:(0,z.jsx)(ue,{className:`w-4 h-4`}),onClick:()=>h(e),disabled:!j,title:j?void 0:O(`fileManager.noPermissionRenameFile`)}),g&&N.push({label:O(`fileManager.details.title`),icon:(0,z.jsx)(_,{className:`w-4 h-4`}),onClick:()=>g(e),disabled:!ee,title:ee?void 0:O(`fileManager.noPermissionPreview`)}),e.external_url&&N.push({label:O(`fileManager.details.openLink`),icon:(0,z.jsx)(Me,{className:`w-4 h-4`}),onClick:()=>window.open(e.external_url,`_blank`,`noopener,noreferrer`)}),v&&cl(e.file_type)&&N.push({label:O(`fileManager.generateThumbnail`),icon:(0,z.jsx)(Fe,{className:`w-4 h-4`}),onClick:()=>v(e),disabled:!j,title:j?void 0:O(`fileManager.noPermissionGenerateThumbnail`)}),N.push({label:O(`common.delete`),icon:(0,z.jsx)(de,{className:`w-4 h-4`}),onClick:()=>r(e.id),danger:!0,disabled:!M,title:M?void 0:O(`fileManager.noPermissionDeleteFile`)}),(0,z.jsxs)(`div`,{className:`group relative bg-bambu-dark-secondary rounded-lg border transition-all cursor-pointer ${t?`border-bambu-green ring-1 ring-bambu-green`:`border-bambu-dark-tertiary hover:border-bambu-green/50`}`,onClick:()=>n(e.id),onDoubleClick:()=>m?.(e),children:[(0,z.jsxs)(`div`,{className:`aspect-square bg-bambu-dark flex items-center justify-center overflow-hidden rounded-t-lg`,children:[e.thumbnail_path?(0,z.jsx)(`img`,{src:`${a.getLibraryFileThumbnailUrl(e.id)}${S?(a.getLibraryFileThumbnailUrl(e.id).includes(`?`)?`&`:`?`)+`v=${S}`:``}`,loading:`lazy`,alt:e.filename,className:`w-full h-full object-cover`}):(0,z.jsx)(nl,{fileType:e.file_type,className:`w-12 h-12 text-bambu-gray/30`}),(0,z.jsx)(`div`,{className:`absolute top-2 right-2 text-xs px-1.5 py-0.5 rounded font-medium ${e.file_type===`3mf`?`bg-bambu-green/90 text-white`:e.file_type===`gcode`||e.file_type===`gcode.3mf`?`bg-blue-500/90 text-white`:e.file_type===`stl`?`bg-purple-500/90 text-white`:Zc(e.file_type)?`bg-amber-500/90 text-white`:e.file_type===`pdf`?`bg-red-500/90 text-white`:Xc(e.file_type)?`bg-teal-500/90 text-white`:`bg-bambu-gray/90 text-white`}`,children:e.file_type.toUpperCase()})]}),(0,z.jsxs)(`div`,{className:`p-3`,children:[(0,z.jsx)(`h3`,{className:`text-sm font-medium text-white truncate`,title:e.print_name||e.filename,children:e.print_name||e.filename}),(0,z.jsxs)(`div`,{className:`flex items-center gap-3 mt-1 text-xs text-bambu-gray`,children:[(0,z.jsx)(`span`,{children:oe(e.file_size)}),e.print_time_seconds&&(0,z.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,z.jsx)(ve,{className:`w-3 h-3`}),ce(e.print_time_seconds)]})]}),e.sliced_for_model&&(0,z.jsxs)(`div`,{className:`mt-1 text-xs text-bambu-gray flex items-center gap-1`,children:[(0,z.jsx)(me,{className:`w-3 h-3`}),e.sliced_for_model]}),(e.variant_count??0)>1&&(0,z.jsxs)(`div`,{className:`mt-1 text-xs text-bambu-green flex items-center gap-1`,children:[(0,z.jsx)(je,{className:`w-3 h-3`}),O(`fileManager.variants.badge`,{count:e.variant_count})]}),e.print_count>0&&(0,z.jsx)(`div`,{className:`mt-1 text-xs text-bambu-green`,children:O(`fileManager.printedCount`,{count:e.print_count})}),(e.external_url||e.has_notes||(e.photo_count??0)>0)&&(0,z.jsxs)(`div`,{className:`mt-1 flex items-center gap-2 text-xs text-bambu-gray`,...al,children:[e.external_url&&(0,z.jsx)(`a`,{href:e.external_url,target:`_blank`,rel:`noopener noreferrer`,className:`p-0.5 rounded hover:text-bambu-green`,title:O(`fileManager.details.openLink`),"aria-label":O(`fileManager.details.openLink`),children:(0,z.jsx)(Me,{className:`w-3.5 h-3.5`})}),e.has_notes&&(0,z.jsx)(`button`,{type:`button`,onClick:()=>g?.(e),className:`p-0.5 rounded hover:text-bambu-green`,title:O(`fileManager.details.hasNotes`),"aria-label":O(`fileManager.details.hasNotes`),children:(0,z.jsx)(ne,{className:`w-3.5 h-3.5`})}),(e.photo_count??0)>0&&(0,z.jsxs)(`button`,{type:`button`,onClick:()=>g?.(e),className:`flex items-center gap-0.5 p-0.5 rounded hover:text-bambu-green`,title:O(`fileManager.details.photoCount`,{count:e.photo_count}),"aria-label":O(`fileManager.details.photoCount`,{count:e.photo_count}),children:[(0,z.jsx)(be,{className:`w-3.5 h-3.5`}),(0,z.jsx)(`span`,{children:e.photo_count})]})]}),E&&e.created_by_username&&(0,z.jsxs)(`div`,{className:`mt-1 text-xs text-bambu-gray flex items-center gap-1`,children:[(0,z.jsx)(ye,{className:`w-3 h-3`}),e.created_by_username]}),D&&(0,z.jsxs)(`div`,{className:`mt-1 text-xs text-bambu-gray flex items-center gap-1`,title:O(`fileManager.lastModified`),children:[(0,z.jsx)(tt,{className:`w-3 h-3`}),se(e.fs_modified_at??e.created_at)]}),(e.tags?.length??0)>0&&(0,z.jsx)(`div`,{className:`mt-2 flex flex-wrap gap-1`,...al,children:e.tags.map(e=>(0,z.jsxs)(`button`,{type:`button`,onClick:()=>b?.(e.id),className:`inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded-full text-[10px] bg-bambu-green/10 text-bambu-green hover:bg-bambu-green/20 transition-colors max-w-full`,title:e.name,children:[(0,z.jsx)(xe,{className:`w-2.5 h-2.5 flex-shrink-0`}),(0,z.jsx)(`span`,{className:`truncate`,children:e.name})]},e.id))})]}),(0,z.jsxs)(`div`,{className:`absolute bottom-2 right-2 transition-opacity can-hover:opacity-0 group-hover:opacity-100 group-focus-within:opacity-100`,...al,children:[(0,z.jsx)(`button`,{onClick:e=>{let t=e.currentTarget.getBoundingClientRect();A({x:t.left,y:t.bottom+4})},className:`p-1.5 rounded bg-bambu-dark-secondary/90 hover:bg-bambu-dark-tertiary`,children:(0,z.jsx)(x,{className:`w-4 h-4 text-bambu-gray`})}),k&&(0,z.jsx)(T,{x:k.x,y:k.y,items:N,onClose:()=>A(null)})]}),(0,z.jsx)(`div`,{className:`absolute top-2 left-2 w-5 h-5 rounded border-2 flex items-center justify-center transition-all ${t?`bg-bambu-green border-bambu-green`:`border-white/30 bg-black/30 can-hover:opacity-0 group-hover:opacity-100 group-focus-within:opacity-100`}`,children:t&&(0,z.jsx)(`div`,{className:`w-2 h-2 bg-white rounded-sm`})})]})}function Cl({file:e,onPrint:t,onSlice:n,onOpenInSlicer:r,onRunPipeline:i,useSlicerApi:a,desktopSlicer:o,canSlice:s,onPreview:c,onDetails:l,onDownload:u,onRename:d,onGenerateThumbnail:f,thumbnailPending:m,onDelete:h,hasPermission:g,canModify:v,tabIndex:b,t:x}){let S=v(`library`,`update`,e.created_by_id),C=v(`library`,`delete`,e.created_by_id);return(0,z.jsxs)(`div`,{className:`flex items-center gap-1`,"data-file-actions":!0,...al,children:[Ze(e)&&(0,z.jsx)(`button`,{tabIndex:b,onClick:()=>g(`queue:create`)&&t(e),className:`p-1.5 rounded transition-colors ${g(`queue:create`)?`hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green`:`text-bambu-gray/50 cursor-not-allowed`}`,title:g(`queue:create`)?x(`common.print`):x(`fileManager.noPermissionAddToQueue`),disabled:!g(`queue:create`),children:(0,z.jsx)(me,{className:`w-4 h-4`})}),Qe(e,a,o)&&(0,z.jsx)(`button`,{tabIndex:b,onClick:()=>{s&&(a?n:r)(e)},className:`p-1.5 rounded transition-colors ${s?`hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green`:`text-bambu-gray/50 cursor-not-allowed`}`,title:x(s?`slice.action`:a?`fileManager.noPermissionSlice`:`fileManager.noPermissionDownload`),disabled:!s,children:a?(0,z.jsx)(y,{className:`w-4 h-4`}):(0,z.jsx)(fe,{className:`w-4 h-4`})}),a&&Qe(e,!0,o)&&(0,z.jsx)(`button`,{tabIndex:b,onClick:()=>g(`pipelines:run`)&&i(e),className:`p-1.5 rounded transition-colors ${g(`pipelines:run`)?`hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green`:`text-bambu-gray/50 cursor-not-allowed`}`,title:g(`pipelines:run`)?x(`library.runWithPipeline.actionLabel`):x(`library.runWithPipeline.noPermission`),disabled:!g(`pipelines:run`),children:(0,z.jsx)(te,{className:`w-4 h-4`})}),ol(e)&&(0,z.jsx)(`button`,{tabIndex:b,onClick:()=>g(`library:read`)&&c(e),className:`p-1.5 rounded transition-colors ${g(`library:read`)?`hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green`:`text-bambu-gray/50 cursor-not-allowed`}`,title:g(`library:read`)?x(`fileManager.preview3d`):x(`fileManager.noPermissionPreview`),disabled:!g(`library:read`),children:(0,z.jsx)(p,{className:`w-4 h-4`})}),!ol(e)&&il(e)&&(0,z.jsx)(`button`,{tabIndex:b,onClick:()=>g(`library:read`)&&c(e),className:`p-1.5 rounded transition-colors ${g(`library:read`)?`hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green`:`text-bambu-gray/50 cursor-not-allowed`}`,title:g(`library:read`)?x(`fileManager.preview.open`):x(`fileManager.noPermissionPreview`),disabled:!g(`library:read`),children:sl(e.file_type)}),(0,z.jsx)(`button`,{tabIndex:b,onClick:()=>g(`library:read`)&&u(e.id),className:`p-1.5 rounded transition-colors ${g(`library:read`)?`hover:bg-bambu-dark text-bambu-gray hover:text-white`:`text-bambu-gray/50 cursor-not-allowed`}`,title:g(`library:read`)?x(`common.download`):x(`fileManager.noPermissionDownload`),disabled:!g(`library:read`),children:(0,z.jsx)(Le,{className:`w-4 h-4`})}),(0,z.jsx)(`button`,{tabIndex:b,onClick:()=>g(`library:read`)&&l(e),className:`p-1.5 rounded transition-colors ${g(`library:read`)?`hover:bg-bambu-dark text-bambu-gray hover:text-white`:`text-bambu-gray/50 cursor-not-allowed`}`,title:g(`library:read`)?x(`fileManager.details.title`):x(`fileManager.noPermissionPreview`),disabled:!g(`library:read`),children:(0,z.jsx)(_,{className:`w-4 h-4`})}),(0,z.jsx)(`button`,{tabIndex:b,onClick:()=>S&&d(e),className:`p-1.5 rounded transition-colors ${S?`hover:bg-bambu-dark text-bambu-gray hover:text-white`:`text-bambu-gray/50 cursor-not-allowed`}`,title:x(S?`common.rename`:`fileManager.noPermissionRenameFile`),disabled:!S,children:(0,z.jsx)(ue,{className:`w-4 h-4`})}),cl(e.file_type)&&(0,z.jsx)(`button`,{tabIndex:b,onClick:()=>S&&f(e),className:`p-1.5 rounded transition-colors ${S?`hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green`:`text-bambu-gray/50 cursor-not-allowed`}`,title:x(S?`fileManager.generateThumbnail`:`fileManager.noPermissionGenerateThumbnail`),disabled:m||!S,children:(0,z.jsx)(Fe,{className:`w-4 h-4`})}),(0,z.jsx)(`button`,{tabIndex:b,onClick:()=>C&&h(e.id),className:`p-1.5 rounded transition-colors ${C?`hover:bg-bambu-dark text-bambu-gray hover:text-red-700 dark:hover:text-red-400`:`text-bambu-gray/50 cursor-not-allowed`}`,title:x(C?`common.delete`:`fileManager.noPermissionDeleteFile`),disabled:!C,children:(0,z.jsx)(de,{className:`w-4 h-4`})})]})}function wl({file:e,isSelected:t,isFocused:n,showModified:r,thumbnailVersion:i,onSelect:o,onOpen:s,actionProps:c,t:l}){let u=a.getLibraryFileThumbnailUrl(e.id);return(0,z.jsxs)(`div`,{"data-file-id":e.id,onClick:()=>o(e),onDoubleClick:()=>s(e),className:`group flex items-center gap-3 px-3 py-2 cursor-pointer transition-colors ${t?`bg-bambu-green/10`:`hover:bg-bambu-dark`} ${n?`ring-1 ring-inset ring-bambu-green/60`:``}`,title:e.print_name||e.filename,children:[(0,z.jsx)(`div`,{className:`w-4 h-4 rounded border-2 flex-shrink-0 flex items-center justify-center ${t?`bg-bambu-green border-bambu-green`:`border-bambu-gray/50`}`,children:t&&(0,z.jsx)(`div`,{className:`w-1.5 h-1.5 bg-white rounded-sm`})}),(0,z.jsx)(`div`,{className:`w-10 h-10 rounded bg-bambu-dark flex-shrink-0 overflow-hidden flex items-center justify-center`,children:e.thumbnail_path?(0,z.jsx)(`img`,{src:`${u}${i?(u.includes(`?`)?`&`:`?`)+`v=${i}`:``}`,loading:`lazy`,alt:``,className:`w-full h-full object-cover`}):(0,z.jsx)(nl,{fileType:e.file_type,className:`w-5 h-5 text-bambu-gray/50`})}),(0,z.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,z.jsx)(`div`,{className:`text-sm text-white truncate`,children:e.print_name||e.filename}),(0,z.jsxs)(`div`,{className:`mt-0.5 flex items-center gap-2 text-xs text-bambu-gray`,children:[(0,z.jsx)(`span`,{className:`px-1.5 py-px rounded font-medium ${ll(e.file_type)}`,children:e.file_type.toUpperCase()}),(0,z.jsx)(`span`,{children:oe(e.file_size)}),e.print_count>0&&(0,z.jsxs)(`span`,{children:[e.print_count,`x`]}),r&&(0,z.jsxs)(`span`,{className:`flex items-center gap-1 truncate`,title:l(`fileManager.lastModified`),children:[(0,z.jsx)(tt,{className:`w-3 h-3 flex-shrink-0`}),se(e.fs_modified_at??e.created_at)]})]})]}),(0,z.jsx)(`div`,{className:`flex-shrink-0 transition-opacity ${n||t?``:`can-hover:opacity-0 group-hover:opacity-100 group-focus-within:opacity-100`}`,children:(0,z.jsx)(Cl,{file:e,...c,tabIndex:n?0:-1})})]})}function Tl(){let{t:e}=o(),t=c(),{showToast:n}=v(),{hasPermission:r,hasAnyPermission:i,canModify:s,authEnabled:f}=ze(),[p]=De(),m=Ee(),h=p.get(`folder`),[g,_]=(0,R.useState)(h?parseInt(h,10):null),[y,x]=(0,R.useState)(`internal`),[C,T]=(0,R.useState)([]),[te,ie]=(0,R.useState)(!1),[ce,le]=(0,R.useState)(!1),[ue,fe]=(0,R.useState)(!1),[F,I]=(0,R.useState)(!1),[he,ve]=(0,R.useState)([]),[Te,Pe]=(0,R.useState)(!1),[Le,Re]=(0,R.useState)(!1),[Be,Ve]=(0,R.useState)(!1),[We,qe]=(0,R.useState)([]),[Je,Ye]=(0,R.useState)(null),[ot,st]=(0,R.useState)(null),[ct,ut]=(0,R.useState)(null),[dt,pt]=(0,R.useState)(null),[ht,gt]=(0,R.useState)(!1),[_t,vt]=(0,R.useState)(null),[yt,bt]=(0,R.useState)(null),[xt,St]=(0,R.useState)(null),[Ct,wt]=(0,R.useState)({}),[Tt,B]=(0,R.useState)(null),[Et,Dt]=(0,R.useState)(null),[V,H]=(0,R.useState)(null),[Ot,U]=(0,R.useState)(null),[W,kt]=(0,R.useState)(null),[G,At]=(0,R.useState)(()=>localStorage.getItem(`library-view-mode`)||`grid`),jt=(0,R.useRef)(null),[K,Mt]=(0,R.useState)(null),[Nt,Pt]=(0,R.useState)(()=>localStorage.getItem(`library-wrap-folders`)===`true`),[Ft,It]=(0,R.useState)(()=>localStorage.getItem(`library-collapse-folders`)===`true`),[Lt,Rt]=(0,R.useState)(()=>localStorage.getItem(`library-folder-sort-field`)===`activity`?`activity`:`name`),[zt,Bt]=(0,R.useState)(()=>localStorage.getItem(`library-folder-sort-direction`)===`desc`?`desc`:`asc`),[Vt,Ht]=(0,R.useState)(()=>{let e=localStorage.getItem(`library-sidebar-width`);return e?parseInt(e,10):256}),[Ut,Wt]=(0,R.useState)(!1),Gt=(0,R.useRef)(null);(0,R.useEffect)(()=>{if(!Ut)return;document.body.style.userSelect=`none`,document.body.style.cursor=`col-resize`;let e=e=>{if(!Gt.current)return;let t=Gt.current.parentElement?.getBoundingClientRect();if(!t)return;let n=e.clientX-t.left;Ht(Math.min(500,Math.max(200,n)))},t=()=>{Wt(!1),document.body.style.userSelect=``,document.body.style.cursor=``,localStorage.setItem(`library-sidebar-width`,String(Vt))};return document.addEventListener(`mousemove`,e),document.addEventListener(`mouseup`,t),()=>{document.removeEventListener(`mousemove`,e),document.removeEventListener(`mouseup`,t),document.body.style.userSelect=``,document.body.style.cursor=``}},[Ut,Vt]);let[Kt,qt]=(0,R.useState)(``),[Jt,Yt]=(0,R.useState)(`all`),[Xt,Zt]=(0,R.useState)(``),[Qt,$t]=(0,R.useState)(()=>localStorage.getItem(`library-sort-field`)||`name`),[en,tn]=(0,R.useState)(()=>localStorage.getItem(`library-sort-direction`)||`asc`),[nn,rn]=(0,R.useState)(()=>localStorage.getItem(`library-show-modified`)===`true`);(0,R.useEffect)(()=>{let e=p.get(`folder`);e&&_(parseInt(e,10))},[p]);let{data:an}=l({queryKey:[`settings`],queryFn:()=>a.getSettings()}),on=Ke(an?.open_in_slicer,an?.preferred_slicer),sn=(0,R.useCallback)(async t=>{try{let{token:e}=await a.createLibrarySlicerToken(t.id),n=a.getLibrarySlicerDownloadUrl(t.id,e,t.filename);Ge(`${window.location.origin}${n}`,on)}catch{n(e(`fileManager.toast.openInSlicerFailed`),`error`);let r=a.getLibraryFileDownloadUrl(t.id);Ge(`${window.location.origin}${r}`,on)}},[on,n,e]),cn=(0,R.useCallback)(()=>an?.use_slicer_api?r(`library:upload`):i(`library:read_all`,`library:read_own`),[an?.use_slicer_api,r,i]),{data:ln,isLoading:un}=l({queryKey:[`library-folders`],queryFn:()=>a.getLibraryFolders()}),q=(0,R.useMemo)(()=>{if(!ln)return ln;let e=t=>[...t].sort((e,t)=>{let n=0;if(Lt===`name`)n=e.name.localeCompare(t.name);else{let r=e.latest_activity_at?new Date(e.latest_activity_at).getTime():null,i=t.latest_activity_at?new Date(t.latest_activity_at).getTime():null;if(r===null&&i===null)n=e.name.localeCompare(t.name);else if(r===null)return 1;else if(i===null)return-1;else n=r-i}return zt===`asc`?n:-n}).map(t=>({...t,children:e(t.children)}));return e(ln)},[ln,Lt,zt]),{data:dn}=l({queryKey:[`library-trash-count`],queryFn:async()=>{try{return(await a.listLibraryTrash(1,0)).total}catch{return 0}},staleTime:3e4}),fn=g!==null&&Kt.trim().length>0,pn=(0,R.useMemo)(()=>[...We].sort((e,t)=>e-t),[We]),{data:mn=[]}=l({queryKey:[`library-tags`],queryFn:a.getLibraryTags}),hn=(0,R.useMemo)(()=>{let e=new Map;for(let t of mn)e.set(t.id,t.name);return e},[mn]);(0,R.useEffect)(()=>{mn.length!==0&&qe(e=>{let t=e.filter(e=>hn.has(e));return t.length===e.length?e:t})},[mn.length,hn]);let gn=(0,R.useCallback)(e=>{qe(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},[]),_n=Kt.trim().length>0||We.length>0,vn=G===`columns`&&g===null&&!_n,{data:yn,isLoading:bn}=l({queryKey:[`library-files`,g,y,fn,pn,vn],queryFn:()=>a.getLibraryFiles(g,vn,void 0,g===null?y:void 0,fn,pn)}),{data:xn}=l({queryKey:[`library-stats`],queryFn:()=>a.getLibraryStats()}),{data:Sn}=l({queryKey:[`users`,`slim`],queryFn:()=>a.getUsersSlim()}),Cn=(0,R.useMemo)(()=>{if(!yn)return[];let e=new Set(yn.map(e=>e.file_type));return Array.from(e).sort()},[yn]),J=(0,R.useMemo)(()=>ul(yn??[],{query:Kt,filterType:Jt,filterUsername:Xt,sortField:Qt,sortDirection:en}),[yn,Kt,Jt,Xt,Qt,en]),wn=(0,R.useMemo)(()=>{if(!xn||!an)return!1;let e=(an.library_disk_warning_gb||5)*1024*1024*1024;return xn.disk_free_bytesa.createLibraryFolder(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-folders`]}),ie(!1),n(e(`fileManager.toast.folderCreated`),`success`)},onError:e=>n(e.message,`error`)}),En=u({mutationFn:async e=>{let t=await a.createExternalFolder(e);return await a.scanExternalFolder(t.id),t},onSuccess:r=>{t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-stats`]}),le(!1),_(r.id),n(e(`fileManager.toast.externalFolderLinked`),`success`)},onError:e=>n(e.message,`error`)}),Dn=u({mutationFn:e=>a.scanExternalFolder(e),onSuccess:r=>{t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-stats`]}),n(e(`fileManager.toast.folderScanned`,{added:r.added,removed:r.removed}),`success`)},onError:e=>n(e.message,`error`)}),On=u({mutationFn:e=>a.deleteLibraryFolder(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-stats`]}),g===ot?.id&&_(null),st(null),n(e(`fileManager.toast.folderDeleted`),`success`)},onError:e=>{st(null),n(e.message,`error`)}}),kn=u({mutationFn:e=>a.deleteLibraryFile(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-stats`]}),t.invalidateQueries({queryKey:[`library-trash-count`]}),T(e=>e.filter(e=>e!==ot?.id)),st(null),n(e(`fileManager.toast.fileDeleted`),`success`)},onError:e=>{st(null),n(e.message,`error`)}}),An=u({mutationFn:e=>a.createVariantGroup(e.map(e=>({library_file_id:e}))),onSuccess:r=>{t.invalidateQueries({queryKey:[`library-files`]}),n(e(`fileManager.variants.grouped`,{count:r.members.length}),`success`),T([])},onError:e=>n(e.message,`error`)}),jn=u({mutationFn:e=>a.bulkDeleteLibrary(e,[]),onSuccess:(r,i)=>{t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-stats`]}),t.invalidateQueries({queryKey:[`library-trash-count`]}),n(e(`fileManager.toast.filesDeleted`,{count:i.length}),`success`),T([]),st(null)},onError:e=>{st(null),n(e.message,`error`)}}),Mn=u({mutationFn:({fileIds:e,folderId:t})=>a.moveLibraryFiles(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-folders`]}),T([]),fe(!1),n(e(`fileManager.toast.filesMoved`),`success`)},onError:e=>n(e.message,`error`)}),Nn=u({mutationFn:({id:e,data:t})=>a.updateLibraryFolder(e,t),onSuccess:(r,i)=>{t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`project-folders`]}),t.invalidateQueries({queryKey:[`archive-folders`]}),Ye(null),n(i.data.project_id===0&&i.data.archive_id===0?e(`fileManager.toast.folderUnlinked`):e(`fileManager.toast.folderLinked`),`success`)},onError:e=>n(e.message,`error`)}),Pn=u({mutationFn:({id:e,filename:t})=>a.updateLibraryFile(e,{filename:t}),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-files`]}),St(null),n(e(`fileManager.toast.fileRenamed`),`success`)},onError:e=>{St(null),n(e.message,`error`)}}),Fn=u({mutationFn:({id:e,name:t})=>a.updateLibraryFolder(e,{name:t}),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-files`]}),St(null),n(e(`fileManager.toast.folderRenamed`),`success`)},onError:e=>{St(null),n(e.message,`error`)}}),In=u({mutationFn:({id:e,shared:t})=>a.updateLibraryFolder(e,{shared:t}),onSuccess:(r,i)=>{t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`project-folders`]}),t.invalidateQueries({queryKey:[`archive-folders`]}),n(i.shared?e(`fileManager.toast.folderShared`):e(`fileManager.toast.folderUnshared`),`success`)},onError:e=>n(e.message,`error`)}),Ln=e=>In.mutate({id:e.id,shared:!e.shared}),Rn=u({mutationFn:()=>a.batchGenerateStlThumbnails({all_missing:!0}),onSuccess:r=>{if(t.invalidateQueries({queryKey:[`library-files`]}),r.succeeded>0){let e=Date.now(),t={};r.results.forEach(n=>{n.success&&(t[n.file_id]=e)}),wt(e=>({...e,...t}))}r.succeeded>0&&r.failed===0?n(e(`fileManager.toast.thumbnailsGenerated`,{count:r.succeeded}),`success`):r.succeeded>0&&r.failed>0?n(e(`fileManager.toast.thumbnailsGeneratedPartial`,{succeeded:r.succeeded,failed:r.failed}),`success`):r.processed===0?n(e(`fileManager.toast.noStlMissingThumbnails`),`info`):n(e(`fileManager.toast.failedToGenerateThumbnails`,{error:r.results[0]?.error||`Unknown error`}),`error`)},onError:e=>n(e.message,`error`)}),zn=u({mutationFn:e=>a.batchGenerateStlThumbnails({file_ids:[e]}),onSuccess:r=>{if(t.invalidateQueries({queryKey:[`library-files`]}),r.succeeded>0){let t=r.results[0]?.file_id;t&&wt(e=>({...e,[t]:Date.now()})),n(e(`fileManager.toast.thumbnailGenerated`),`success`)}else n(e(`fileManager.toast.failedToGenerateThumbnail`,{error:r.results[0]?.error||`Unknown error`}),`error`)},onError:e=>n(e.message,`error`)}),Bn=(0,R.useCallback)(e=>{r(`library:read`)&&(Ze(e)?m(`/gcode-viewer?library_file=${e.id}`):e.file_type===`3mf`||e.file_type===`stl`||Zc(e.file_type)?B(e):e.file_type===`pdf`?Dt(e):Xc(e.file_type)?H(e):tl(e.file_type)&&kt(e))},[r,m]),Vn=(0,R.useCallback)(e=>{T(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},[]),Hn=(0,R.useCallback)(()=>{if(J.length>0){let e=J.map(e=>e.id);T(t=>G===`columns`?[...new Set([...t,...e])]:e)}},[J,G]),Un=J.length>0&&J.every(e=>C.includes(e.id)),Wn=(0,R.useCallback)(()=>{T([])},[]),Gn=()=>{t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-stats`]})},Y=(0,R.useMemo)(()=>{if(!g||!ln)return null;let e=t=>{for(let n of t){if(n.id===g)return n;let t=e(n.children);if(t)return t}return null};return e(ln)},[g,ln]),Kn=Y?.can_write!==!1,qn=r(`library:upload`)&&Kn,Jn=r(`library:upload`)?Kn?void 0:e(`fileManager.folderNotWritable`):void 0,{isDraggingOver:Yn,dragHandlers:Xn}=He({disabled:!qn||F,onFiles:e=>{ve(e),I(!0)}}),Zn=(0,R.useCallback)(e=>{if(!e.thumbnail_path&&s(`library`,`update`,e.created_by_id))return n=>{a.uploadLibraryPreviewThumbnail(e.id,n).then(n=>{n.updated&&(wt(t=>({...t,[e.id]:(t[e.id]||0)+1})),t.invalidateQueries({queryKey:[`library-files`]}))}).catch(()=>{})}},[s,t]),Qn=e=>{a.downloadLibraryFile(e).catch(e=>{console.error(`Library file download failed:`,e)})},$n=()=>{ot&&(ot.type===`file`?kn.mutate(ot.id):ot.type===`folder`?On.mutate(ot.id):ot.type===`bulk`&&jn.mutate(C))},er=On.isPending||kn.isPending||jn.isPending,tr=e=>{At(e),localStorage.setItem(`library-view-mode`,e)},nr={onPrint:ut,onSlice:pt,onOpenInSlicer:sn,onRunPipeline:bt,useSlicerApi:an?.use_slicer_api??!1,desktopSlicer:on,canSlice:cn(),onPreview:Bn,onDetails:U,onDownload:Qn,onRename:e=>St({type:`file`,id:e.id,name:e.filename}),onGenerateThumbnail:e=>zn.mutate(e.id),thumbnailPending:zn.isPending,onDelete:e=>st({type:`file`,id:e}),hasPermission:r,canModify:s,t:e},rr=un||bn,ir=(0,R.useMemo)(()=>{if(!q||g===null)return[];let e=[],t=n=>{for(let r of n){if(e.push(r),r.id===g||t(r.children))return!0;e.pop()}return!1};return t(q),e},[q,g]),ar=ir.length>0?!!ir[0].is_external:y===`external`,X=(0,R.useMemo)(()=>{let e=[{key:`root`,folderId:null,items:(q??[]).filter(e=>!!e.is_external===ar),activeId:ir[0]?.id??null}];return ir.forEach((t,n)=>{t.children.length>0&&e.push({key:`folder-${t.id}`,folderId:t.id,items:t.children,activeId:ir[n+1]?.id??null})}),e},[q,ir,ar]),Z=(0,R.useMemo)(()=>G!==`columns`||_n?[]:X.filter(e=>e.folderId!==g).map(e=>({key:e.key,folderId:e.folderId,scope:e.folderId===null?ar?`external`:`internal`:void 0})),[G,_n,X,g,ar]),Q=d({combine:rl,queries:Z.map(e=>({queryKey:[`library-files`,`column`,e.folderId,e.scope??null],queryFn:()=>a.getLibraryFiles(e.folderId,e.folderId===null,void 0,e.scope,!1,[])}))}),or=new Map;Z.forEach((e,t)=>{let n=Q.results[t];or.set(e.key,{files:ul(n?.data??[],{filterType:Jt,filterUsername:Xt,sortField:Qt,sortDirection:en}),loading:!!n?.isPending})});let sr=(0,R.useMemo)(()=>{let e=new Map;for(let t of[...yn??[],...Q.files])e.set(t.id,t);return e},[yn,Q.files]),cr=(0,R.useMemo)(()=>{if(C.length!==1)return null;let e=sr.get(C[0]);return e&&il(e)?e:null},[sr,C]),lr=(0,R.useMemo)(()=>C.map(e=>sr.get(e)).filter(e=>!!e&&Ze(e)),[sr,C]),$=(0,R.useMemo)(()=>{let e=C.map(e=>sr.get(e)).filter(e=>!!e&&e.filename.toLowerCase().endsWith(`.stl`));return e.length===C.length?e:[]},[sr,C]),{data:ur}=l({queryKey:[`variant-group`,ct?.variant_group_id],queryFn:()=>a.getVariantGroup(ct.variant_group_id),enabled:!!ct?.variant_group_id}),dr=(0,R.useMemo)(()=>{if(ct){if(lr.length>1)return lr.map(e=>({id:e.id,filename:e.filename,sliced_for_model:e.sliced_for_model}));if(ur&&ur.members.length>1)return ur.members.map(e=>({id:e.library_file_id,filename:e.filename,sliced_for_model:e.target_model}))}},[ct,lr,ur]),fr=K===null?void 0:Z.map(e=>or.get(e.key)?.files).find(e=>e?.some(e=>e.id===K)),pr=fr??J;(0,R.useEffect)(()=>{G===`columns`&&jt.current?.focus({preventScroll:!0})},[G]),(0,R.useEffect)(()=>{Mt(null)},[g,G]),(0,R.useEffect)(()=>{T([])},[g]),(0,R.useEffect)(()=>{G!==`columns`||g===null||jt.current?.querySelector(`[data-folder-id="${g}"]`)?.scrollIntoView?.({block:`nearest`})},[g,G]),(0,R.useEffect)(()=>{G!==`columns`||K===null||jt.current?.querySelector(`[data-file-id="${K}"]`)?.scrollIntoView?.({block:`nearest`})},[K,G]);let mr=()=>{let e=jt.current;if(e){if(K!==null)e.querySelector(`[data-file-id="${K}"] [data-file-actions] button:not([disabled])`)?.focus();else if(g!==null){let t=e.querySelector(`[data-folder-id="${g}"] [data-folder-actions] button`);t?.focus(),t?.click()}}},hr=e=>{if(e.ctrlKey||e.metaKey||e.altKey)return;let t=e.target;if(t.tagName===`INPUT`||t.tagName===`TEXTAREA`||t.tagName===`SELECT`||t.isContentEditable)return;if(t.closest(`[data-folder-actions]`)){if(e.key===`Escape`){e.preventDefault(),jt.current?.focus({preventScroll:!0});return}if(e.key!==`ArrowUp`&&e.key!==`ArrowDown`)return;jt.current?.focus({preventScroll:!0})}let n=t.closest(`[data-file-actions]`);if(n){if(e.key===`Enter`||e.key===` `)return;if(e.key===`ArrowLeft`||e.key===`ArrowRight`){e.preventDefault();let r=Array.from(n.querySelectorAll(`button:not([disabled])`));r[r.indexOf(t)+(e.key===`ArrowRight`?1:-1)]?.focus();return}if(e.key===`Escape`){e.preventDefault(),jt.current?.focus({preventScroll:!0});return}(e.key===`ArrowUp`||e.key===`ArrowDown`)&&jt.current?.focus({preventScroll:!0})}if(e.key===`ContextMenu`||e.key===`F10`&&e.shiftKey){e.preventDefault(),mr();return}let r=K!==null,i=ir[ir.length-1];switch(e.key){case`ArrowDown`:case`ArrowUp`:{e.preventDefault();let t=e.key===`ArrowDown`?1:-1;if(r||_n){let e=pr.findIndex(e=>e.id===K),n=pr[e+t];n?Mt(n.id):t===-1&&e===0&&fr&&Mt(null)}else if(g===null)t===1&&X[0].items.length>0&&_(X[0].items[0].id);else{let e=X[ir.length-1],n=e?e.items.findIndex(e=>e.id===g):-1,r=n===-1?void 0:e.items[n+t];if(r)_(r.id);else if(t===1&&n!==-1){let t=e?or.get(e.key)?.files:void 0;t?.length&&Mt(t[0].id)}}break}case`ArrowRight`:if(e.preventDefault(),r)break;!_n&&i&&i.children.length>0?_(i.children[0].id):J.length>0&&Mt(J[0].id);break;case`ArrowLeft`:if(e.preventDefault(),r){Mt(null);break}if(_n)break;ir.length>1?_(ir[ir.length-2].id):ir.length===1?(x(ir[0].is_external?`external`:`internal`),_(null)):g!==null&&_(null);break;case`Enter`:{if(e.preventDefault(),!r){!_n&&i&&i.children.length>0?_(i.children[0].id):J.length>0&&Mt(J[0].id);break}let t=pr.find(e=>e.id===K);t&&Bn(t);break}case` `:if(e.preventDefault(),!r)break;K!==null&&Vn(K);break}};return(0,z.jsxs)(`div`,{className:`p-4 md:p-8 min-h-[calc(100vh-64px)] lg:h-screen flex flex-col relative`,...Xn,children:[Yn&&(0,z.jsx)(`div`,{className:`fixed inset-0 z-50 bg-bambu-dark/90 flex items-center justify-center pointer-events-none`,children:(0,z.jsxs)(`div`,{className:`border-4 border-dashed border-bambu-green rounded-xl p-12 text-center`,children:[(0,z.jsx)(Ne,{className:`w-16 h-16 mx-auto mb-4 text-bambu-green`}),(0,z.jsx)(`p`,{className:`text-2xl font-semibold text-white mb-2`,children:e(`fileManager.dropFilesHere`)}),(0,z.jsx)(`p`,{className:`text-bambu-gray`,children:e(`fileManager.releaseToUpload`)})]})}),(0,z.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-4 mb-6`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,z.jsx)(Ie,{className:`w-7 h-7 text-bambu-green`}),e(`fileManager.title`)]}),(0,z.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:e(`fileManager.subtitle`)})]}),(0,z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,z.jsxs)(`div`,{className:`flex items-center bg-bambu-dark rounded-lg p-1`,children:[(0,z.jsx)(`button`,{onClick:()=>tr(`grid`),className:`p-1.5 rounded transition-colors ${G===`grid`?`bg-bambu-dark-secondary text-white`:`text-bambu-gray hover:text-white`}`,title:e(`fileManager.gridView`),children:(0,z.jsx)(k,{className:`w-4 h-4`})}),(0,z.jsx)(`button`,{onClick:()=>tr(`list`),className:`p-1.5 rounded transition-colors ${G===`list`?`bg-bambu-dark-secondary text-white`:`text-bambu-gray hover:text-white`}`,title:e(`fileManager.listView`),children:(0,z.jsx)(ee,{className:`w-4 h-4`})}),(0,z.jsx)(`button`,{onClick:()=>tr(`columns`),className:`p-1.5 rounded transition-colors ${G===`columns`?`bg-bambu-dark-secondary text-white`:`text-bambu-gray hover:text-white`}`,title:e(`fileManager.columnsView`),children:(0,z.jsx)(b,{className:`w-4 h-4`})})]}),(0,z.jsxs)(P,{variant:`secondary`,onClick:()=>Rn.mutate(),disabled:Rn.isPending||!i(`library:update_own`,`library:update_all`),title:i(`library:update_own`,`library:update_all`)?e(`fileManager.generateThumbnailsForMissing`):e(`fileManager.noPermissionGenerateThumbnail`),children:[Rn.isPending?(0,z.jsx)(j,{className:`w-4 h-4 mr-2 animate-spin`}):(0,z.jsx)(Fe,{className:`w-4 h-4 mr-2`}),e(`fileManager.generateThumbnails`)]}),(0,z.jsxs)(P,{variant:`secondary`,onClick:()=>le(!0),disabled:!r(`library:upload`),title:r(`library:upload`)?e(`fileManager.linkExternalFolder`):e(`fileManager.noPermissionCreateFolder`),children:[(0,z.jsx)(it,{className:`w-4 h-4 mr-2`}),e(`fileManager.linkExternal`)]}),(0,z.jsxs)(P,{variant:`secondary`,onClick:()=>ie(!0),disabled:!qn,title:r(`library:upload`)?Jn:e(`fileManager.noPermissionCreateFolder`),children:[(0,z.jsx)(rt,{className:`w-4 h-4 mr-2`}),e(`fileManager.newFolder`)]}),(0,z.jsxs)(P,{variant:`secondary`,onClick:()=>Re(!0),title:e(`fileManager.tags.manageTitle`),children:[(0,z.jsx)(xe,{className:`w-4 h-4 mr-2`}),e(`fileManager.tags.manage`)]}),r(`library:purge`)&&(0,z.jsxs)(P,{variant:`secondary`,onClick:()=>Pe(!0),title:e(`libraryPurge.headerTooltip`),children:[(0,z.jsx)(de,{className:`w-4 h-4 mr-2`}),e(`libraryPurge.headerButton`)]}),i(`library:delete_own`,`library:delete_all`)&&(0,z.jsxs)(Se,{to:`/files/trash`,className:`inline-flex items-center px-3 py-1.5 text-sm rounded bg-bambu-dark-secondary text-bambu-gray hover:text-white hover:bg-bambu-dark transition-colors`,title:e(`libraryTrash.headerTooltip`),children:[(0,z.jsx)(de,{className:`w-4 h-4 mr-2`}),e(`libraryTrash.headerButton`),typeof dn==`number`&&dn>0&&(0,z.jsx)(`span`,{className:`ml-1.5 px-1.5 py-0.5 text-xs rounded-full bg-bambu-green/20 text-bambu-green`,children:dn})]}),(0,z.jsxs)(P,{onClick:()=>I(!0),disabled:!qn,title:r(`library:upload`)?Jn:e(`fileManager.noPermissionUpload`),children:[(0,z.jsx)(Ne,{className:`w-4 h-4 mr-2`}),e(`common.upload`)]})]})]}),wn&&xn&&an&&(0,z.jsxs)(`div`,{className:`flex items-center gap-3 mb-4 p-3 bg-amber-500/10 border border-amber-500/30 rounded-lg`,children:[(0,z.jsx)(re,{className:`w-5 h-5 text-amber-500 flex-shrink-0`}),(0,z.jsxs)(`div`,{className:`flex-1`,children:[(0,z.jsx)(`p`,{className:`text-sm text-amber-500 font-medium`,children:e(`fileManager.lowDiskSpaceWarning`)}),(0,z.jsx)(`p`,{className:`text-xs text-amber-500/80`,children:e(`fileManager.lowDiskSpaceDetails`,{free:oe(xn.disk_free_bytes),total:oe(xn.disk_total_bytes),threshold:an.library_disk_warning_gb})})]})]}),xn&&(0,z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 sm:gap-6 mb-6 p-3 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,z.jsx)(w,{className:`w-4 h-4 text-bambu-green`}),(0,z.jsxs)(`span`,{className:`text-bambu-gray`,children:[e(`fileManager.files`),`:`]}),(0,z.jsx)(`span`,{className:`text-white font-medium`,children:xn.total_files})]}),(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,z.jsx)(Ie,{className:`w-4 h-4 text-blue-600 dark:text-blue-400`}),(0,z.jsxs)(`span`,{className:`text-bambu-gray`,children:[e(`fileManager.folders`),`:`]}),(0,z.jsx)(`span`,{className:`text-white font-medium`,children:xn.total_folders})]}),(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,z.jsx)(O,{className:`w-4 h-4 text-amber-600 dark:text-amber-400`}),(0,z.jsxs)(`span`,{className:`text-bambu-gray`,children:[e(`fileManager.size`),`:`]}),(0,z.jsx)(`span`,{className:`text-white font-medium`,children:oe(xn.total_size_bytes)})]}),(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-sm sm:ml-auto`,children:[(0,z.jsxs)(`span`,{className:`text-bambu-gray`,children:[e(`fileManager.free`),`:`]}),(0,z.jsx)(`span`,{className:`font-medium ${wn?`text-amber-500`:`text-white`}`,children:oe(xn.disk_free_bytes)})]})]}),(0,z.jsxs)(`div`,{className:`flex-1 flex flex-col lg:flex-row gap-4 lg:gap-6 min-h-0`,children:[(0,z.jsx)(`div`,{className:`lg:hidden`,children:(0,z.jsxs)(`select`,{value:g===null?`__top:${y}`:String(g),onChange:e=>{let t=e.target.value;t.startsWith(`__top:`)?(_(null),x(t.slice(6))):_(parseInt(t,10))},className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg px-3 py-2.5 text-white focus:outline-none focus:border-bambu-green`,children:[(0,z.jsxs)(`option`,{value:`__top:internal`,children:[`📁 `,e(`fileManager.allFiles`)]}),ln?.some(e=>e.is_external)&&(0,z.jsxs)(`option`,{value:`__top:external`,children:[`🔗 `,e(`fileManager.allExternal`)]}),q&&(()=>{let e=(t,n=0)=>{let r=[];for(let i of t)r.push({id:i.id,name:i.name,fileCount:i.file_count,depth:n}),i.children.length>0&&r.push(...e(i.children,n+1));return r};return e(q).map(e=>(0,z.jsxs)(`option`,{value:e.id,children:[`│ `.repeat(e.depth),`📂 `,e.name,` `,e.fileCount>0?`(${e.fileCount})`:``]},e.id))})()]})}),(0,z.jsxs)(`div`,{ref:Gt,"data-testid":`folder-sidebar`,className:`hidden lg:flex flex-shrink-0 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary overflow-hidden flex-col relative`,style:{width:`${Vt}px`},children:[(0,z.jsx)(`div`,{className:`absolute right-0 top-0 bottom-0 w-1.5 cursor-col-resize z-10 group/resize flex items-center justify-center transition-colors ${Ut?`bg-bambu-green`:`hover:bg-bambu-green/50`}`,onMouseDown:e=>{e.preventDefault(),Wt(!0)},onDoubleClick:()=>{Ht(256),localStorage.setItem(`library-sidebar-width`,`256`)},title:e(`fileManager.dragToResizeTooltip`),children:(0,z.jsxs)(`div`,{className:`flex flex-col gap-1 opacity-0 group-hover/resize:opacity-100 transition-opacity ${Ut?`opacity-100`:``}`,children:[(0,z.jsx)(`div`,{className:`w-0.5 h-0.5 rounded-full bg-white/70`}),(0,z.jsx)(`div`,{className:`w-0.5 h-0.5 rounded-full bg-white/70`}),(0,z.jsx)(`div`,{className:`w-0.5 h-0.5 rounded-full bg-white/70`})]})}),(0,z.jsxs)(`div`,{className:`p-3 border-b border-bambu-dark-tertiary flex items-center justify-between`,children:[(0,z.jsx)(`h2`,{className:`text-sm font-medium text-white`,children:e(`fileManager.folders`)}),(0,z.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,z.jsxs)(`select`,{value:Lt,onChange:e=>{let t=e.target.value===`activity`?`activity`:`name`;Rt(t),localStorage.setItem(`library-folder-sort-field`,t)},className:`text-xs px-1 py-0.5 rounded bg-bambu-dark border border-bambu-dark-tertiary text-bambu-gray focus:outline-none focus:border-bambu-green`,title:e(`fileManager.folderSort`),"aria-label":e(`fileManager.folderSort`),children:[(0,z.jsx)(`option`,{value:`name`,children:e(`fileManager.folderSortByName`)}),(0,z.jsx)(`option`,{value:`activity`,children:e(`fileManager.folderSortByActivity`)})]}),(0,z.jsx)(`button`,{onClick:()=>{let e=zt===`asc`?`desc`:`asc`;Bt(e),localStorage.setItem(`library-folder-sort-direction`,e)},className:`text-bambu-gray hover:text-white hover:bg-bambu-dark p-1 rounded transition-colors`,title:e(zt===`asc`?`fileManager.ascending`:`fileManager.descending`),"aria-label":e(zt===`asc`?`fileManager.ascending`:`fileManager.descending`),children:zt===`asc`?(0,z.jsx)(et,{className:`w-3.5 h-3.5`}):(0,z.jsx)($e,{className:`w-3.5 h-3.5`})}),(0,z.jsx)(`button`,{onClick:()=>{let e=!Ft;It(e),localStorage.setItem(`library-collapse-folders`,String(e))},className:`text-xs px-1.5 py-0.5 rounded transition-colors ${Ft?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:text-white hover:bg-bambu-dark`}`,title:e(Ft?`fileManager.expandFoldersByDefault`:`fileManager.collapseFoldersByDefault`),children:e(`fileManager.collapse`)}),(0,z.jsx)(`button`,{onClick:()=>{let e=!Nt;Pt(e),localStorage.setItem(`library-wrap-folders`,String(e))},className:`text-xs px-1.5 py-0.5 rounded transition-colors ${Nt?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:text-white hover:bg-bambu-dark`}`,title:e(Nt?`fileManager.disableTextWrapping`:`fileManager.enableTextWrapping`),children:e(`fileManager.wrap`)})]})]}),(0,z.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-2`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-1.5 rounded cursor-pointer transition-colors ${g===null&&y===`internal`?`bg-bambu-green/20 text-bambu-green`:`hover:bg-bambu-dark text-white`}`,onClick:()=>{_(null),x(`internal`)},children:[(0,z.jsx)(S,{className:`w-4 h-4`}),(0,z.jsx)(`span`,{className:`text-sm`,children:e(`fileManager.allFiles`)})]}),ln?.some(e=>e.is_external)&&(0,z.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-1.5 rounded cursor-pointer transition-colors ${g===null&&y===`external`?`bg-bambu-green/20 text-bambu-green`:`hover:bg-bambu-dark text-white`}`,onClick:()=>{_(null),x(`external`)},children:[(0,z.jsx)(it,{className:`w-4 h-4 text-purple-600 dark:text-purple-400`}),(0,z.jsx)(`span`,{className:`text-sm`,children:e(`fileManager.allExternal`)})]}),q?.map(t=>(0,z.jsx)(xl,{folder:t,selectedFolderId:g,onSelect:_,onDelete:e=>st({type:`folder`,id:e}),onLink:Ye,onRename:e=>St({type:`folder`,id:e.id,name:e.name}),onToggleShared:Ln,wrapNames:Nt,defaultExpanded:!Ft,showModified:nn,hasPermission:r,t:e},`${t.id}-${Ft?`c`:`e`}`))]})]}),(0,z.jsxs)(`div`,{className:`flex-1 flex flex-col lg:flex-row min-w-0 min-h-0 gap-4 lg:gap-6`,children:[(0,z.jsxs)(`div`,{className:`flex-1 flex flex-col min-w-0 min-h-0`,children:[mn.length>0&&(0,z.jsxs)(`div`,{className:`mb-3 flex flex-wrap items-center gap-2 p-2 sm:p-3 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary`,children:[(0,z.jsx)(`span`,{className:`text-xs text-bambu-gray font-medium shrink-0`,children:e(`fileManager.tags.filterLabel`)}),mn.map(e=>{let t=We.includes(e.id);return(0,z.jsxs)(`button`,{type:`button`,onClick:()=>gn(e.id),className:t?`inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs bg-bambu-green/20 text-bambu-green border border-bambu-green/40 hover:bg-bambu-green/30 transition-colors`:`inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs bg-bambu-dark text-bambu-gray border border-bambu-dark-tertiary hover:text-white hover:border-bambu-green/40 transition-colors`,title:e.name,children:[(0,z.jsx)(xe,{className:`w-3 h-3`}),(0,z.jsx)(`span`,{children:e.name}),t&&(0,z.jsx)(ae,{className:`w-3 h-3`})]},e.id)}),We.length>0&&(0,z.jsx)(`button`,{type:`button`,onClick:()=>qe([]),className:`ml-auto text-xs text-bambu-gray hover:text-white shrink-0`,children:e(`fileManager.tags.clearAll`)})]}),Y?.is_external&&(0,z.jsxs)(`div`,{className:`flex items-center gap-3 mb-4 p-3 bg-purple-50 dark:bg-purple-500/10 border border-purple-300 dark:border-purple-500/30 rounded-lg`,children:[(0,z.jsx)(it,{className:`w-5 h-5 text-purple-600 dark:text-purple-400 flex-shrink-0`}),(0,z.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,z.jsx)(`span`,{className:`text-sm font-medium text-purple-700 dark:text-purple-300`,children:e(`fileManager.externalFolder`)}),Y.external_readonly&&(0,z.jsxs)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400 flex items-center gap-1`,children:[(0,z.jsx)(M,{className:`w-3 h-3`}),e(`fileManager.readOnly`)]})]}),(0,z.jsx)(`p`,{className:`text-xs text-bambu-gray truncate font-mono`,title:Y.external_path||``,children:Y.external_path})]}),(0,z.jsxs)(P,{variant:`secondary`,size:`sm`,onClick:()=>g&&Dn.mutate(g),disabled:Dn.isPending,title:e(`fileManager.scanFolder`),children:[Dn.isPending?(0,z.jsx)(j,{className:`w-4 h-4 animate-spin`}):(0,z.jsx)(L,{className:`w-4 h-4`}),(0,z.jsx)(`span`,{className:`ml-1.5`,children:e(`fileManager.scanFolder`)})]})]}),yn&&yn.length>0&&(0,z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 sm:gap-3 mb-4 p-2 sm:p-3 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary sticky top-0 z-10 lg:static`,children:[(0,z.jsxs)(`div`,{className:`relative w-full sm:w-auto sm:flex-1 sm:max-w-xs`,children:[(0,z.jsx)(N,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,z.jsx)(`input`,{type:`text`,placeholder:e(`fileManager.searchFiles`),value:Kt,onChange:e=>qt(e.target.value),className:`w-full pl-9 pr-3 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`}),fn&&(0,z.jsx)(`span`,{className:`absolute -bottom-4 left-0 text-[10px] text-bambu-gray whitespace-nowrap`,title:e(`fileManager.searchSubfoldersHint`),children:e(`fileManager.searchSubfoldersHint`)})]}),(0,z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,z.jsx)(E,{className:`w-4 h-4 text-bambu-gray hidden sm:block`}),(0,z.jsxs)(`select`,{value:Jt,onChange:e=>Yt(e.target.value),className:`bg-bambu-dark border border-bambu-dark-tertiary rounded px-2 py-1.5 text-sm text-white focus:outline-none focus:border-bambu-green`,children:[(0,z.jsx)(`option`,{value:`all`,children:e(`fileManager.allTypes`)}),Cn.map(e=>(0,z.jsx)(`option`,{value:e,children:e.toUpperCase()},e))]})]}),f&&(0,z.jsxs)(`div`,{className:`relative`,children:[(0,z.jsx)(`input`,{type:`text`,placeholder:e(`fileManager.filterByUser`,{defaultValue:`Filter by user`}),value:Xt,onChange:e=>Zt(e.target.value),list:`usernames-list`,className:`w-32 sm:w-40 px-2 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green ${Xt?`pr-7`:``}`,style:Xt?{WebkitAppearance:`none`,MozAppearance:`textfield`}:void 0}),Xt&&(0,z.jsx)(`button`,{onClick:()=>Zt(``),className:`absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white z-10`,children:(0,z.jsx)(ae,{className:`w-3 h-3`})}),(0,z.jsx)(`datalist`,{id:`usernames-list`,children:Sn?.map(e=>(0,z.jsx)(`option`,{value:e.username},e.id))})]}),(0,z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,z.jsxs)(`select`,{value:Qt,onChange:e=>{let t=e.target.value;$t(t),localStorage.setItem(`library-sort-field`,t)},className:`bg-bambu-dark border border-bambu-dark-tertiary rounded px-2 py-1.5 text-sm text-white focus:outline-none focus:border-bambu-green`,children:[(0,z.jsx)(`option`,{value:`name`,children:e(`common.name`)}),(0,z.jsx)(`option`,{value:`date`,children:e(`common.date`)}),(0,z.jsx)(`option`,{value:`size`,children:e(`fileManager.size`)}),(0,z.jsx)(`option`,{value:`type`,children:e(`common.type`)}),(0,z.jsx)(`option`,{value:`prints`,children:e(`fileManager.prints`)})]}),(0,z.jsx)(`button`,{onClick:()=>tn(e=>{let t=e===`asc`?`desc`:`asc`;return localStorage.setItem(`library-sort-direction`,t),t}),className:`p-1.5 rounded bg-bambu-dark border border-bambu-dark-tertiary hover:border-bambu-green transition-colors`,title:e(en===`asc`?`fileManager.ascending`:`fileManager.descending`),children:en===`asc`?(0,z.jsx)(et,{className:`w-4 h-4 text-white`}):(0,z.jsx)($e,{className:`w-4 h-4 text-white`})}),(0,z.jsx)(`button`,{onClick:()=>rn(e=>{let t=!e;return localStorage.setItem(`library-show-modified`,String(t)),t}),className:`p-1.5 rounded bg-bambu-dark border transition-colors ${nn?`border-bambu-green text-bambu-green`:`border-bambu-dark-tertiary text-white hover:border-bambu-green`}`,title:e(nn?`fileManager.hideModified`:`fileManager.showModified`),"aria-pressed":nn,children:(0,z.jsx)(tt,{className:`w-4 h-4`})})]}),(Kt||Jt!==`all`||Xt)&&(0,z.jsx)(`span`,{className:`text-sm text-bambu-gray hidden sm:inline`,children:e(`fileManager.resultsCount`,{showing:J.length,total:yn.length})})]}),(J.length>0||C.length>0)&&(0,z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 mb-4 p-2 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary sticky top-[52px] z-10 lg:static`,children:[Un?(0,z.jsxs)(P,{variant:`secondary`,size:`sm`,onClick:Wn,children:[(0,z.jsx)(ge,{className:`w-4 h-4 sm:mr-1`}),(0,z.jsx)(`span`,{className:`hidden sm:inline`,children:e(`fileManager.deselectAll`)})]}):(0,z.jsxs)(P,{variant:`secondary`,size:`sm`,onClick:Hn,children:[(0,z.jsx)(Ce,{className:`w-4 h-4 sm:mr-1`}),(0,z.jsx)(`span`,{className:`hidden sm:inline`,children:e(`fileManager.selectAll`)})]}),C.length>0&&(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`span`,{className:`text-sm text-bambu-gray ml-2`,children:e(`fileManager.selected`,{count:C.length})}),(0,z.jsx)(`div`,{className:`hidden sm:block flex-1`}),(0,z.jsxs)(`div`,{className:`w-full sm:w-auto flex flex-wrap items-center gap-2 mt-2 sm:mt-0`,children:[cr&&(0,z.jsxs)(P,{variant:`secondary`,size:`sm`,onClick:()=>Bn(cr),disabled:!r(`library:read`),title:r(`library:read`)?void 0:e(`fileManager.noPermissionPreview`),children:[(0,z.jsx)(we,{className:`w-4 h-4 sm:mr-1`}),(0,z.jsx)(`span`,{className:`hidden sm:inline`,children:e(`fileManager.preview.open`)})]}),lr.length>=1&&(0,z.jsxs)(P,{variant:`primary`,size:`sm`,onClick:()=>ut(lr[0]),disabled:!r(`queue:create`),title:r(`queue:create`)?void 0:e(`fileManager.noPermissionAddToQueue`),children:[(0,z.jsx)(me,{className:`w-4 h-4 sm:mr-1`}),(0,z.jsx)(`span`,{className:`hidden sm:inline`,children:lr.length>1?e(`fileManager.variants.printAlternatives`,{count:lr.length}):e(`common.print`)})]}),lr.length>=2&&!lr.some(e=>e.variant_group_id)&&(0,z.jsxs)(P,{variant:`secondary`,size:`sm`,onClick:()=>An.mutate(lr.map(e=>e.id)),disabled:An.isPending||!i(`library:update_own`,`library:update_all`),title:e(`fileManager.variants.groupTooltip`),children:[(0,z.jsx)(je,{className:`w-4 h-4 sm:mr-1`}),(0,z.jsx)(`span`,{className:`hidden sm:inline`,children:e(`fileManager.variants.groupAction`)})]}),$.length>=1&&(0,z.jsxs)(P,{variant:`secondary`,size:`sm`,onClick:()=>gt(!0),disabled:!r(`library:upload`),title:e(`fileManager.combine.tooltip`),children:[(0,z.jsx)(nt,{className:`w-4 h-4 sm:mr-1`}),(0,z.jsx)(`span`,{className:`hidden sm:inline`,children:e(`fileManager.combine.action`)})]}),(0,z.jsxs)(P,{variant:`secondary`,size:`sm`,onClick:()=>fe(!0),disabled:!i(`library:update_own`,`library:update_all`),title:i(`library:update_own`,`library:update_all`)?void 0:e(`fileManager.noPermissionMoveFiles`),children:[(0,z.jsx)(at,{className:`w-4 h-4 sm:mr-1`}),(0,z.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.move`)})]}),(0,z.jsxs)(P,{variant:`secondary`,size:`sm`,onClick:()=>Ve(!0),disabled:!i(`library:update_own`,`library:update_all`),title:i(`library:update_own`,`library:update_all`)?e(`fileManager.tags.bulkTooltip`):e(`fileManager.tags.noPermission`),children:[(0,z.jsx)(xe,{className:`w-4 h-4 sm:mr-1`}),(0,z.jsx)(`span`,{className:`hidden sm:inline`,children:e(`fileManager.tags.tagAction`)})]}),(0,z.jsxs)(P,{variant:`danger`,size:`sm`,onClick:()=>{C.length===1?st({type:`file`,id:C[0]}):st({type:`bulk`,id:0,count:C.length})},disabled:!i(`library:delete_own`,`library:delete_all`),title:i(`library:delete_own`,`library:delete_all`)?void 0:e(`fileManager.noPermissionDeleteFiles`),children:[(0,z.jsx)(de,{className:`w-4 h-4 sm:mr-1`}),(0,z.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.delete`)})]}),(0,z.jsxs)(P,{variant:`secondary`,size:`sm`,onClick:Wn,children:[(0,z.jsx)(ae,{className:`w-4 h-4 sm:mr-1`}),(0,z.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.clear`)})]})]})]})]}),rr&&G!==`columns`?(0,z.jsx)(`div`,{className:`flex-1 flex items-center justify-center`,children:(0,z.jsxs)(`div`,{className:`flex flex-col items-center gap-3`,children:[(0,z.jsx)(j,{className:`w-8 h-8 animate-spin text-bambu-green`}),(0,z.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`fileManager.loadingFiles`)})]})}):G===`columns`?(0,z.jsx)(`div`,{ref:jt,tabIndex:0,"aria-label":e(`fileManager.columnsView`),onKeyDown:hr,className:`flex-1 min-h-0 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary overflow-x-auto outline-none focus-visible:ring-1 focus-visible:ring-bambu-green/50`,"data-testid":`columns-view`,children:(0,z.jsxs)(`div`,{className:`h-full min-h-[16rem] flex divide-x divide-bambu-dark-tertiary`,children:[!_n&&X.map(t=>{let n=or.get(t.key),i=!!(n&&(n.loading||n.files.length>0));return(0,z.jsxs)(`div`,{"data-testid":`columns-level-${t.key}`,className:`${i?`w-[26rem]`:`w-64`} flex-shrink-0 overflow-y-auto py-1`,children:[t.items.map(n=>{let i=g===n.id;return(0,z.jsxs)(`div`,{"data-folder-id":n.id,className:`group flex items-center pr-1.5 transition-colors ${t.activeId===n.id?`bg-bambu-green/20 text-bambu-green`:i?`bg-bambu-green/10 text-white`:`text-white hover:bg-bambu-dark`}`,children:[(0,z.jsxs)(`button`,{type:`button`,tabIndex:-1,onClick:()=>{Mt(null),_(n.id)},className:`flex-1 min-w-0 flex items-center gap-2 pl-3 pr-1 py-2.5 text-left text-sm`,title:n.name,children:[n.is_external?(0,z.jsx)(it,{className:`w-5 h-5 flex-shrink-0 text-purple-600 dark:text-purple-400`}):(0,z.jsx)(Ie,{className:`w-5 h-5 flex-shrink-0 text-bambu-green`}),(0,z.jsx)(`span`,{className:`flex-1 truncate`,children:n.name}),(n.project_id||n.archive_id)&&(0,z.jsx)(A,{className:`w-3.5 h-3.5 flex-shrink-0 text-blue-700 dark:text-blue-400`}),n.shared&&(0,z.jsx)(`span`,{title:e(`fileManager.sharedFolder`),children:(0,z.jsx)(pe,{className:`w-3.5 h-3.5 flex-shrink-0 text-bambu-gray`})}),n.is_external&&n.external_readonly&&(0,z.jsx)(M,{className:`w-3.5 h-3.5 flex-shrink-0 text-amber-600 dark:text-amber-400`}),n.file_count>0&&(0,z.jsx)(`span`,{className:`text-xs text-bambu-gray flex-shrink-0`,children:n.file_count}),n.children.length>0&&(0,z.jsx)(_e,{className:`w-4 h-4 flex-shrink-0 text-bambu-gray`})]}),(0,z.jsx)(bl,{folder:n,onDelete:e=>st({type:`folder`,id:e}),onLink:Ye,onRename:e=>St({type:`folder`,id:e.id,name:e.name}),onToggleShared:Ln,hasPermission:r,revealOnHover:!i,tabIndex:i?0:-1,t:e})]},n.id)}),n?.loading&&(0,z.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,"aria-hidden":`true`,children:`…`}),n&&!n.loading&&n.files.map(t=>(0,z.jsx)(wl,{file:t,isSelected:C.includes(t.id),isFocused:K===t.id,showModified:nn,thumbnailVersion:Ct[t.id],onSelect:e=>{Mt(e.id),Vn(e.id)},onOpen:Bn,actionProps:nr,t:e},t.id))]},t.key)}),(0,z.jsx)(`div`,{className:`flex-1 min-w-[28rem] overflow-y-auto py-1`,"data-testid":`columns-files-pane`,children:bn?(0,z.jsx)(`div`,{className:`h-full flex items-center justify-center`,children:(0,z.jsx)(j,{className:`w-5 h-5 animate-spin text-bambu-green`})}):J.length===0?(0,z.jsx)(`div`,{className:`h-full flex items-center justify-center px-4 text-sm text-bambu-gray text-center`,children:(yn?.length??0)>0?e(`fileManager.noMatchingFiles`):g===null?vn&&X[0].items.length>0?e(`fileManager.noFilesOutsideFolders`):e(y===`external`?`fileManager.externalIsEmpty`:`fileManager.noFilesYet`):e(`fileManager.folderIsEmpty`)}):J.map(t=>(0,z.jsx)(wl,{file:t,isSelected:C.includes(t.id),isFocused:K===t.id,showModified:nn,thumbnailVersion:Ct[t.id],onSelect:e=>{Mt(e.id),Vn(e.id)},onOpen:Bn,actionProps:nr,t:e},t.id))})]})}):yn?.length===0?(0,z.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center`,children:[(0,z.jsx)(`div`,{className:`p-4 bg-bambu-dark rounded-2xl mb-4`,children:(0,z.jsx)(S,{className:`w-12 h-12 text-bambu-gray/50`})}),(0,z.jsx)(`h3`,{className:`text-lg font-medium text-white mb-2`,children:e(g===null?y===`external`?`fileManager.externalIsEmpty`:`fileManager.noFilesYet`:`fileManager.folderIsEmpty`)}),(0,z.jsx)(`p`,{className:`text-bambu-gray text-center max-w-md mb-6`,children:e(g===null?y===`external`?`fileManager.externalEmptyDescription`:`fileManager.noFilesDescription`:`fileManager.folderEmptyDescription`)}),(0,z.jsxs)(P,{onClick:()=>I(!0),disabled:!qn,title:r(`library:upload`)?Jn:e(`fileManager.noPermissionUpload`),children:[(0,z.jsx)(Oe,{className:`w-4 h-4 mr-2`}),e(`fileManager.uploadFiles`)]})]}):J.length===0?(0,z.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center`,children:[(0,z.jsx)(`div`,{className:`p-4 bg-bambu-dark rounded-2xl mb-4`,children:(0,z.jsx)(N,{className:`w-12 h-12 text-bambu-gray/50`})}),(0,z.jsx)(`h3`,{className:`text-lg font-medium text-white mb-2`,children:e(`fileManager.noMatchingFiles`)}),(0,z.jsx)(`p`,{className:`text-bambu-gray text-center max-w-md mb-6`,children:e(`fileManager.noMatchingFilesDescription`)}),(0,z.jsx)(P,{variant:`secondary`,onClick:()=>{qt(``),Yt(`all`)},children:e(`fileManager.clearFilters`)})]}):G===`grid`?(0,z.jsx)(`div`,{className:`flex-1 lg:overflow-y-auto`,children:(0,z.jsx)(`div`,{className:`grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 2xl:grid-cols-6 gap-4`,children:J.map(t=>(0,z.jsx)(Sl,{file:t,isSelected:C.includes(t.id),t:e,onSelect:Vn,onDelete:e=>st({type:`file`,id:e}),onDownload:Qn,onPrint:ut,onSlice:pt,onOpenInSlicer:sn,desktopSlicer:on,onRunPipeline:bt,useSlicerApi:an?.use_slicer_api??!1,canSlice:cn(),onPreview:Bn,onRename:e=>St({type:`file`,id:e.id,name:e.filename}),onDetails:U,onGenerateThumbnail:e=>zn.mutate(e.id),onTagClick:gn,thumbnailVersion:Ct[t.id],hasPermission:r,canModify:s,authEnabled:f,showModified:nn},t.id))})}):(0,z.jsx)(`div`,{className:`flex-1 lg:overflow-y-auto`,children:(0,z.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary overflow-x-auto`,children:[(0,z.jsxs)(`div`,{"data-testid":`file-list-grid-header`,className:`hidden sm:grid ${dl(f)} ${fl} gap-4 px-4 py-2 bg-bambu-dark-secondary border-b border-bambu-dark-tertiary text-xs text-bambu-gray font-medium`,children:[(0,z.jsx)(`div`,{className:`w-6`}),(0,z.jsx)(`div`,{children:e(`common.name`)}),f&&(0,z.jsx)(`div`,{children:e(`fileManager.uploadedBy`,{defaultValue:`Uploaded By`})}),(0,z.jsx)(`div`,{children:e(`common.type`)}),(0,z.jsx)(`div`,{children:e(`fileManager.size`)}),(0,z.jsx)(`div`,{children:e(`fileManager.prints`)}),(0,z.jsx)(`div`,{children:e(`fileManager.tags.title`)}),(0,z.jsx)(`div`,{})]}),J.map(t=>(0,z.jsxs)(`div`,{"data-testid":`file-list-grid-row`,className:`grid ${dl(f)} ${fl} gap-4 px-4 py-3 items-center border-b border-bambu-dark-tertiary last:border-b-0 cursor-pointer hover:bg-bambu-dark/50 transition-colors ${C.includes(t.id)?`bg-bambu-green/10`:``}`,onClick:()=>Vn(t.id),onDoubleClick:()=>Bn(t),children:[(0,z.jsx)(`div`,{className:`w-5 h-5 rounded border-2 flex items-center justify-center ${C.includes(t.id)?`bg-bambu-green border-bambu-green`:`border-bambu-gray/50`}`,children:C.includes(t.id)&&(0,z.jsx)(`div`,{className:`w-2 h-2 bg-white rounded-sm`})}),(0,z.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0`,children:[(0,z.jsxs)(`div`,{className:`relative group/thumb`,children:[(0,z.jsx)(`div`,{className:`w-10 h-10 rounded bg-bambu-dark flex-shrink-0 overflow-hidden`,children:t.thumbnail_path?(0,z.jsx)(`img`,{src:`${a.getLibraryFileThumbnailUrl(t.id)}${Ct[t.id]?(a.getLibraryFileThumbnailUrl(t.id).includes(`?`)?`&`:`?`)+`v=${Ct[t.id]}`:``}`,loading:`lazy`,alt:``,className:`w-full h-full object-cover`}):(0,z.jsx)(`div`,{className:`w-full h-full flex items-center justify-center`,children:(0,z.jsx)(nl,{fileType:t.file_type,className:`w-5 h-5 text-bambu-gray/50`})})}),t.thumbnail_path&&(0,z.jsx)(`div`,{className:`absolute left-0 top-full mt-2 z-50 hidden group-hover/thumb:block`,children:(0,z.jsx)(`div`,{className:`w-48 h-48 rounded-lg bg-bambu-dark-secondary border border-bambu-dark-tertiary shadow-xl overflow-hidden`,children:(0,z.jsx)(`img`,{src:`${a.getLibraryFileThumbnailUrl(t.id)}${Ct[t.id]?(a.getLibraryFileThumbnailUrl(t.id).includes(`?`)?`&`:`?`)+`v=${Ct[t.id]}`:``}`,loading:`lazy`,alt:t.filename,className:`w-full h-full object-contain`})})})]}),(0,z.jsxs)(`div`,{className:`min-w-0`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[(0,z.jsx)(`span`,{className:`text-sm text-white truncate`,children:t.print_name||t.filename}),t.external_url&&(0,z.jsx)(`a`,{href:t.external_url,target:`_blank`,rel:`noopener noreferrer`,...al,className:`flex-shrink-0 text-bambu-gray hover:text-bambu-green`,title:e(`fileManager.details.openLink`),"aria-label":e(`fileManager.details.openLink`),children:(0,z.jsx)(Me,{className:`w-3.5 h-3.5`})}),t.has_notes&&(0,z.jsx)(`span`,{className:`flex-shrink-0 text-bambu-gray`,title:e(`fileManager.details.hasNotes`),"aria-label":e(`fileManager.details.hasNotes`),children:(0,z.jsx)(ne,{className:`w-3.5 h-3.5`})}),(t.photo_count??0)>0&&(0,z.jsxs)(`span`,{className:`flex-shrink-0 flex items-center gap-0.5 text-xs text-bambu-gray`,title:e(`fileManager.details.photoCount`,{count:t.photo_count}),children:[(0,z.jsx)(be,{className:`w-3.5 h-3.5`}),t.photo_count]})]}),nn&&(0,z.jsxs)(`div`,{className:`text-xs text-bambu-gray flex items-center gap-1 mt-0.5`,title:e(`fileManager.lastModified`),children:[(0,z.jsx)(tt,{className:`w-3 h-3 flex-shrink-0`}),(0,z.jsx)(`span`,{className:`truncate`,children:se(t.fs_modified_at??t.created_at)})]})]})]}),f&&(0,z.jsx)(`div`,{className:`text-sm text-bambu-gray flex items-center gap-1`,children:t.created_by_username?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(ye,{className:`w-3 h-3`}),(0,z.jsx)(`span`,{className:`truncate`,children:t.created_by_username})]}):`-`}),(0,z.jsx)(`div`,{children:(0,z.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded font-medium ${ll(t.file_type)}`,children:t.file_type.toUpperCase()})}),(0,z.jsx)(`div`,{className:`text-sm text-bambu-gray`,children:oe(t.file_size)}),(0,z.jsx)(`div`,{className:`text-sm text-bambu-gray`,children:t.print_count>0?`${t.print_count}x`:`-`}),(0,z.jsx)(`div`,{className:`min-w-0`,...al,children:!t.tags||t.tags.length===0?(0,z.jsx)(`span`,{className:`text-xs text-bambu-gray/50`,children:`-`}):(0,z.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:t.tags.map(e=>(0,z.jsxs)(`button`,{type:`button`,onClick:()=>gn(e.id),className:`inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded-full text-[10px] bg-bambu-green/10 text-bambu-green hover:bg-bambu-green/20 transition-colors max-w-full`,title:e.name,children:[(0,z.jsx)(xe,{className:`w-2.5 h-2.5 flex-shrink-0`}),(0,z.jsx)(`span`,{className:`truncate`,children:e.name})]},e.id))})}),(0,z.jsx)(Cl,{file:t,...nr})]},t.id))]})})]}),g!==null&&(0,z.jsx)(Hc,{folderId:g})]})]}),te&&(0,z.jsx)(pl,{parentId:g,onClose:()=>ie(!1),onSave:e=>Tn.mutate(e),isLoading:Tn.isPending,t:e}),ce&&(0,z.jsx)(ml,{onClose:()=>le(!1),onSave:e=>En.mutate(e),isLoading:En.isPending,t:e}),ue&&ln&&(0,z.jsx)(vl,{folders:ln,selectedFiles:C,currentFolderId:g,onClose:()=>fe(!1),onMove:e=>Mn.mutate({fileIds:C,folderId:e}),isLoading:Mn.isPending,t:e}),F&&(0,z.jsx)(Xe,{folderId:g,onClose:()=>{I(!1),ve([])},onUploadComplete:Gn,initialFiles:he.length>0?he:void 0}),Te&&(0,z.jsx)(Kc,{onClose:()=>Pe(!1)}),(0,z.jsx)(Uc,{open:Le,onClose:()=>Re(!1),onPickTag:e=>{We.includes(e)||qe(t=>[...t,e])}}),(0,z.jsx)(mt,{open:Be,fileIds:C,onClose:()=>Ve(!1)}),Je&&(0,z.jsx)(yl,{folder:Je,onClose:()=>Ye(null),onLink:e=>Nn.mutate({id:Je.id,data:e}),isLoading:Nn.isPending,t:e}),ot&&(0,z.jsx)(ke,{title:ot.type===`folder`?e(`fileManager.deleteFolder`):ot.type===`bulk`?e(`fileManager.deleteFilesCount`,{count:ot.count}):e(`fileManager.deleteFile`),message:ot.type===`folder`?e(`fileManager.deleteFolderConfirm`):ot.type===`bulk`?e(`fileManager.deleteFilesConfirm`,{count:ot.count}):e(`fileManager.deleteFileConfirm`),confirmText:e(`common.delete`),variant:`danger`,isLoading:er,loadingText:e(`fileManager.deleting`),onConfirm:$n,onCancel:()=>st(null)}),ct&&(!ct.variant_group_id||ur!==void 0)&&(0,z.jsx)(Ae,{mode:`create`,libraryFileId:dr?.[0]?.id??ct.id,variantFiles:dr,archiveName:dr&&dr.length>1?`${dr[0].filename} ${e(`common.plusNMore`,{count:dr.length-1})}`:ct.print_name||ct.filename,onClose:()=>ut(null),onSuccess:()=>{ut(null),T([]),t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`queue`]}),t.invalidateQueries({queryKey:[`archives`]})}}),dt&&(0,z.jsx)(D,{source:{kind:`libraryFile`,id:dt.id,filename:dt.filename},onClose:()=>pt(null)}),ht&&$.length>0&&(0,z.jsx)(ft,{files:$,folderId:g,canSlice:!!an?.use_slicer_api&&cn(),onClose:()=>gt(!1),onCombined:(e,t)=>{gt(!1),T([]),t&&vt({id:e.id,filename:e.filename})}}),_t&&(0,z.jsx)(D,{source:{kind:`libraryFile`,id:_t.id,filename:_t.filename},onClose:()=>vt(null),defaultAutoArrange:!0}),yt&&(0,z.jsx)(Ue,{source:{kind:`libraryFile`,id:yt.id,filename:yt.filename},onClose:()=>bt(null)}),Tt&&(0,z.jsx)(lt,{libraryFileId:Tt.id,title:Tt.print_name||Tt.filename,fileType:Tt.file_type,onClose:()=>B(null),onSnapshot:Zc(Tt.file_type)?Zn(Tt):void 0,onSliceWithBambuddy:Qe(Tt,!0,on)&&r(`library:upload`)?()=>{let e=Tt;B(null),pt(e)}:void 0}),(Et||V||W)&&(0,z.jsxs)(R.Suspense,{fallback:null,children:[Et&&(0,z.jsx)(qc,{libraryFileId:Et.id,filename:Et.print_name||Et.filename,fileSize:Et.file_size,onClose:()=>Dt(null),onSnapshot:Zn(Et)}),V&&(0,z.jsx)(Jc,{libraryFileId:V.id,filename:V.print_name||V.filename,fileType:V.file_type,fileSize:V.file_size,onClose:()=>H(null),onSnapshot:Zn(V)}),W&&(0,z.jsx)(Yc,{libraryFileId:W.id,filename:W.print_name||W.filename,fileSize:W.file_size,onClose:()=>kt(null)})]}),Ot&&(0,z.jsx)(Wc,{file:Ot,canEdit:s(`library`,`update`,Ot.created_by_id),onClose:()=>U(null)}),xt&&(0,z.jsx)(_l,{type:xt.type,currentName:xt.name,onClose:()=>St(null),onSave:e=>{xt.type===`file`?Pn.mutate({id:xt.id,filename:e}):Fn.mutate({id:xt.id,name:e})},isLoading:Pn.isPending||Fn.isPending,t:e})]})}export{Tl as FileManagerPage}; \ No newline at end of file diff --git a/static/assets/FileUploadModal-CpDg524n.js b/static/assets/FileUploadModal-Dee1GxH_.js similarity index 99% rename from static/assets/FileUploadModal-CpDg524n.js rename to static/assets/FileUploadModal-Dee1GxH_.js index 90f94f200..0868e1443 100644 --- a/static/assets/FileUploadModal-CpDg524n.js +++ b/static/assets/FileUploadModal-Dee1GxH_.js @@ -1,2 +1,2 @@ -import{i as e,r as t,t as n}from"./chunk-aKtaBQYM.js";import{C as r,D as i,a,l as o,w as s}from"./client-DnySrlFv.js";import{n as c}from"./info-ROUoQhJR.js";import{r as l}from"./ToastContext-BRX0SW3C.js";import{n as u}from"./ContextMenu-BOFgRmSk.js";import{t as d}from"./loader-circle-BEmFtawu.js";import{t as f}from"./x-DR-Trv6U.js";import{n as p,t as m}from"./zoom-out-DNNe6DMN.js";import{t as h}from"./Button-DDr6eAFy.js";import{Gt as g,Jt as _,Ln as v,kt as y,un as b}from"./index-0t--Yqoi.js";import{A as x,C as S,D as C,E as w,O as T,S as E,T as D,_ as O,a as k,b as A,c as j,d as M,f as N,g as P,h as F,k as I,l as L,m as R,n as z,o as B,p as V,r as H,s as U,t as ee,u as W,v as G,w as K,x as q,y as J}from"./OrbitControls-Bbqf07B-.js";var Y=e(i(),1);function X(e,t=!1){let n=e[0].index!==null,r=new Set(Object.keys(e[0].attributes)),i=new Set(Object.keys(e[0].morphAttributes)),a={},o={},s=e[0].morphTargetsRelative,c=new j,l=0;for(let u=0;u>5&31)/31,a=(e>>10&31)/31)}for(let c=1;c<=3;c++){let l=n+c*12,u=e*3*3+(c-1)*3;p[u]=t.getFloat32(l,!0),p[u+1]=t.getFloat32(l+4,!0),p[u+2]=t.getFloat32(l+8,!0),m[u]=d,m[u+1]=f,m[u+2]=g,o&&(h.setRGB(r,i,a,C),s[u]=h.r,s[u+1]=h.g,s[u+2]=h.b)}}return f.setAttribute(`position`,new U(p,3)),f.setAttribute(`normal`,new U(m,3)),o&&(f.setAttribute(`color`,new U(s,3)),f.hasColors=!0,f.alpha=d),f}function i(e){let t=new j,n=/solid([\s\S]*?)endsolid/g,r=/facet([\s\S]*?)endfacet/g,i=/solid\s(.+)/,a=0,o=RegExp(`vertex[\\s]+([+-]?(?:\\d*)(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)[\\s]+([+-]?(?:\\d*)(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)[\\s]+([+-]?(?:\\d*)(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)`,`g`),s=RegExp(`normal[\\s]+([+-]?(?:\\d*)(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)[\\s]+([+-]?(?:\\d*)(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)[\\s]+([+-]?(?:\\d*)(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)`,`g`),c=[],l=[],u=[],d=new x,f,p=0,m=0,h=0;for(;(f=n.exec(e))!==null;){m=h;let e=f[0],n=(f=i.exec(e))===null?``:f[1];for(u.push(n);(f=r.exec(e))!==null;){let e=0,t=0,n=f[0];for(;(f=s.exec(n))!==null;)d.x=parseFloat(f[1]),d.y=parseFloat(f[2]),d.z=parseFloat(f[3]),t++;for(;(f=o.exec(n))!==null;)c.push(parseFloat(f[1]),parseFloat(f[2]),parseFloat(f[3])),l.push(d.x,d.y,d.z),e++,h++;t!==1&&console.error(`THREE.STLLoader: Something isn't right with the normal of face number `+a),e!==3&&console.error(`THREE.STLLoader: Something isn't right with the vertices of face number `+a),a++}let g=m,_=h-m;t.userData.groupNames=u,t.addGroup(g,_,p),p++}return t.setAttribute(`position`,new N(c,3)),t.setAttribute(`normal`,new N(l,3)),t}function a(e){return typeof e==`string`?e:new TextDecoder().decode(e)}function o(e){if(typeof e==`string`){let t=new Uint8Array(e.length);for(let n=0;n{t.isMesh&&(e.add(t.geometry),e.add(t.material))});for(let t of e)t.dispose()}};function Z(e){return new q({color:0,emissive:16777215,emissiveIntensity:e})}var ie=e(n(((e,n)=>{(function(t){typeof e==`object`&&n!==void 0?n.exports=t():typeof define==`function`&&define.amd?define([],t):(typeof window<`u`?window:typeof global<`u`?global:typeof self<`u`?self:this).JSZip=t()})(function(){return function e(n,r,i){function a(s,c){if(!r[s]){if(!n[s]){var l=typeof t==`function`&&t;if(!c&&l)return l(s,!0);if(o)return o(s,!0);var u=Error(`Cannot find module '`+s+`'`);throw u.code=`MODULE_NOT_FOUND`,u}var d=r[s]={exports:{}};n[s][0].call(d.exports,function(e){var t=n[s][1][e];return a(t||e)},d,d.exports,e,n,r,i)}return r[s].exports}for(var o=typeof t==`function`&&t,s=0;s>2,s=(3&t)<<4|n>>4,c=1>6:64,l=2>4,n=(15&o)<<4|(s=a.indexOf(e.charAt(l++)))>>2,r=(3&s)<<6|(c=a.indexOf(e.charAt(l++))),f[u++]=t,s!==64&&(f[u++]=n),c!==64&&(f[u++]=r);return f}},{"./support":30,"./utils":32}],2:[function(e,t,n){var r=e(`./external`),i=e(`./stream/DataWorker`),a=e(`./stream/Crc32Probe`),o=e(`./stream/DataLengthProbe`);function s(e,t,n,r,i){this.compressedSize=e,this.uncompressedSize=t,this.crc32=n,this.compression=r,this.compressedContent=i}s.prototype={getContentWorker:function(){var e=new i(r.Promise.resolve(this.compressedContent)).pipe(this.compression.uncompressWorker()).pipe(new o(`data_length`)),t=this;return e.on(`end`,function(){if(this.streamInfo.data_length!==t.uncompressedSize)throw Error(`Bug : uncompressed data size mismatch`)}),e},getCompressedWorker:function(){return new i(r.Promise.resolve(this.compressedContent)).withStreamInfo(`compressedSize`,this.compressedSize).withStreamInfo(`uncompressedSize`,this.uncompressedSize).withStreamInfo(`crc32`,this.crc32).withStreamInfo(`compression`,this.compression)}},s.createWorkerFrom=function(e,t,n){return e.pipe(new a).pipe(new o(`uncompressedSize`)).pipe(t.compressWorker(n)).pipe(new o(`compressedSize`)).withStreamInfo(`compression`,t)},t.exports=s},{"./external":6,"./stream/Crc32Probe":25,"./stream/DataLengthProbe":26,"./stream/DataWorker":27}],3:[function(e,t,n){var r=e(`./stream/GenericWorker`);n.STORE={magic:`\0\0`,compressWorker:function(){return new r(`STORE compression`)},uncompressWorker:function(){return new r(`STORE decompression`)}},n.DEFLATE=e(`./flate`)},{"./flate":7,"./stream/GenericWorker":28}],4:[function(e,t,n){var r=e(`./utils`),i=function(){for(var e,t=[],n=0;n<256;n++){e=n;for(var r=0;r<8;r++)e=1&e?3988292384^e>>>1:e>>>1;t[n]=e}return t}();t.exports=function(e,t){return e!==void 0&&e.length?r.getTypeOf(e)===`string`?function(e,t,n,r){var a=i,o=r+n;e^=-1;for(var s=r;s>>8^a[255&(e^t.charCodeAt(s))];return-1^e}(0|t,e,e.length,0):function(e,t,n,r){var a=i,o=r+n;e^=-1;for(var s=r;s>>8^a[255&(e^t[s])];return-1^e}(0|t,e,e.length,0):0}},{"./utils":32}],5:[function(e,t,n){n.base64=!1,n.binary=!1,n.dir=!1,n.createFolders=!0,n.date=null,n.compression=null,n.compressionOptions=null,n.comment=null,n.unixPermissions=null,n.dosPermissions=null},{}],6:[function(e,t,n){var r=null;r=typeof Promise<`u`?Promise:e(`lie`),t.exports={Promise:r}},{lie:37}],7:[function(e,t,n){var r=typeof Uint8Array<`u`&&typeof Uint16Array<`u`&&typeof Uint32Array<`u`,i=e(`pako`),a=e(`./utils`),o=e(`./stream/GenericWorker`),s=r?`uint8array`:`array`;function c(e,t){o.call(this,`FlateWorker/`+e),this._pako=null,this._pakoAction=e,this._pakoOptions=t,this.meta={}}n.magic=`\b\0`,a.inherits(c,o),c.prototype.processChunk=function(e){this.meta=e.meta,this._pako===null&&this._createPako(),this._pako.push(a.transformTo(s,e.data),!1)},c.prototype.flush=function(){o.prototype.flush.call(this),this._pako===null&&this._createPako(),this._pako.push([],!0)},c.prototype.cleanUp=function(){o.prototype.cleanUp.call(this),this._pako=null},c.prototype._createPako=function(){this._pako=new i[this._pakoAction]({raw:!0,level:this._pakoOptions.level||-1});var e=this;this._pako.onData=function(t){e.push({data:t,meta:e.meta})}},n.compressWorker=function(e){return new c(`Deflate`,e)},n.uncompressWorker=function(){return new c(`Inflate`,{})}},{"./stream/GenericWorker":28,"./utils":32,pako:38}],8:[function(e,t,n){function r(e,t){var n,r=``;for(n=0;n>>=8;return r}function i(e,t,n,i,o,u){var d,f,p=e.file,m=e.compression,h=u!==s.utf8encode,g=a.transformTo(`string`,u(p.name)),_=a.transformTo(`string`,s.utf8encode(p.name)),v=p.comment,y=a.transformTo(`string`,u(v)),b=a.transformTo(`string`,s.utf8encode(v)),x=_.length!==p.name.length,S=b.length!==v.length,C=``,w=``,T=``,E=p.dir,D=p.date,O={crc32:0,compressedSize:0,uncompressedSize:0};t&&!n||(O.crc32=e.crc32,O.compressedSize=e.compressedSize,O.uncompressedSize=e.uncompressedSize);var k=0;t&&(k|=8),h||!x&&!S||(k|=2048);var A=0,j=0;E&&(A|=16),o===`UNIX`?(j=798,A|=function(e,t){var n=e;return e||(n=t?16893:33204),(65535&n)<<16}(p.unixPermissions,E)):(j=20,A|=function(e){return 63&(e||0)}(p.dosPermissions)),d=D.getUTCHours(),d<<=6,d|=D.getUTCMinutes(),d<<=5,d|=D.getUTCSeconds()/2,f=D.getUTCFullYear()-1980,f<<=4,f|=D.getUTCMonth()+1,f<<=5,f|=D.getUTCDate(),x&&(w=r(1,1)+r(c(g),4)+_,C+=`up`+r(w.length,2)+w),S&&(T=r(1,1)+r(c(y),4)+b,C+=`uc`+r(T.length,2)+T);var M=``;return M+=` +import{i as e,r as t,t as n}from"./chunk-aKtaBQYM.js";import{C as r,D as i,a,l as o,w as s}from"./client-DnySrlFv.js";import{n as c}from"./info-ROUoQhJR.js";import{r as l}from"./ToastContext-BRX0SW3C.js";import{n as u}from"./ContextMenu-CwroFwVJ.js";import{t as d}from"./loader-circle-BEmFtawu.js";import{t as f}from"./x-DR-Trv6U.js";import{n as p,t as m}from"./zoom-out-DNNe6DMN.js";import{t as h}from"./Button-DDr6eAFy.js";import{Gt as g,Jt as _,Ln as v,kt as y,un as b}from"./index-Cxa-KVmA.js";import{A as x,C as S,D as C,E as w,O as T,S as E,T as D,_ as O,a as k,b as A,c as j,d as M,f as N,g as P,h as F,k as I,l as L,m as R,n as z,o as B,p as V,r as H,s as U,t as ee,u as W,v as G,w as K,x as q,y as J}from"./OrbitControls-Bbqf07B-.js";var Y=e(i(),1);function X(e,t=!1){let n=e[0].index!==null,r=new Set(Object.keys(e[0].attributes)),i=new Set(Object.keys(e[0].morphAttributes)),a={},o={},s=e[0].morphTargetsRelative,c=new j,l=0;for(let u=0;u>5&31)/31,a=(e>>10&31)/31)}for(let c=1;c<=3;c++){let l=n+c*12,u=e*3*3+(c-1)*3;p[u]=t.getFloat32(l,!0),p[u+1]=t.getFloat32(l+4,!0),p[u+2]=t.getFloat32(l+8,!0),m[u]=d,m[u+1]=f,m[u+2]=g,o&&(h.setRGB(r,i,a,C),s[u]=h.r,s[u+1]=h.g,s[u+2]=h.b)}}return f.setAttribute(`position`,new U(p,3)),f.setAttribute(`normal`,new U(m,3)),o&&(f.setAttribute(`color`,new U(s,3)),f.hasColors=!0,f.alpha=d),f}function i(e){let t=new j,n=/solid([\s\S]*?)endsolid/g,r=/facet([\s\S]*?)endfacet/g,i=/solid\s(.+)/,a=0,o=RegExp(`vertex[\\s]+([+-]?(?:\\d*)(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)[\\s]+([+-]?(?:\\d*)(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)[\\s]+([+-]?(?:\\d*)(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)`,`g`),s=RegExp(`normal[\\s]+([+-]?(?:\\d*)(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)[\\s]+([+-]?(?:\\d*)(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)[\\s]+([+-]?(?:\\d*)(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)`,`g`),c=[],l=[],u=[],d=new x,f,p=0,m=0,h=0;for(;(f=n.exec(e))!==null;){m=h;let e=f[0],n=(f=i.exec(e))===null?``:f[1];for(u.push(n);(f=r.exec(e))!==null;){let e=0,t=0,n=f[0];for(;(f=s.exec(n))!==null;)d.x=parseFloat(f[1]),d.y=parseFloat(f[2]),d.z=parseFloat(f[3]),t++;for(;(f=o.exec(n))!==null;)c.push(parseFloat(f[1]),parseFloat(f[2]),parseFloat(f[3])),l.push(d.x,d.y,d.z),e++,h++;t!==1&&console.error(`THREE.STLLoader: Something isn't right with the normal of face number `+a),e!==3&&console.error(`THREE.STLLoader: Something isn't right with the vertices of face number `+a),a++}let g=m,_=h-m;t.userData.groupNames=u,t.addGroup(g,_,p),p++}return t.setAttribute(`position`,new N(c,3)),t.setAttribute(`normal`,new N(l,3)),t}function a(e){return typeof e==`string`?e:new TextDecoder().decode(e)}function o(e){if(typeof e==`string`){let t=new Uint8Array(e.length);for(let n=0;n{t.isMesh&&(e.add(t.geometry),e.add(t.material))});for(let t of e)t.dispose()}};function Z(e){return new q({color:0,emissive:16777215,emissiveIntensity:e})}var ie=e(n(((e,n)=>{(function(t){typeof e==`object`&&n!==void 0?n.exports=t():typeof define==`function`&&define.amd?define([],t):(typeof window<`u`?window:typeof global<`u`?global:typeof self<`u`?self:this).JSZip=t()})(function(){return function e(n,r,i){function a(s,c){if(!r[s]){if(!n[s]){var l=typeof t==`function`&&t;if(!c&&l)return l(s,!0);if(o)return o(s,!0);var u=Error(`Cannot find module '`+s+`'`);throw u.code=`MODULE_NOT_FOUND`,u}var d=r[s]={exports:{}};n[s][0].call(d.exports,function(e){var t=n[s][1][e];return a(t||e)},d,d.exports,e,n,r,i)}return r[s].exports}for(var o=typeof t==`function`&&t,s=0;s>2,s=(3&t)<<4|n>>4,c=1>6:64,l=2>4,n=(15&o)<<4|(s=a.indexOf(e.charAt(l++)))>>2,r=(3&s)<<6|(c=a.indexOf(e.charAt(l++))),f[u++]=t,s!==64&&(f[u++]=n),c!==64&&(f[u++]=r);return f}},{"./support":30,"./utils":32}],2:[function(e,t,n){var r=e(`./external`),i=e(`./stream/DataWorker`),a=e(`./stream/Crc32Probe`),o=e(`./stream/DataLengthProbe`);function s(e,t,n,r,i){this.compressedSize=e,this.uncompressedSize=t,this.crc32=n,this.compression=r,this.compressedContent=i}s.prototype={getContentWorker:function(){var e=new i(r.Promise.resolve(this.compressedContent)).pipe(this.compression.uncompressWorker()).pipe(new o(`data_length`)),t=this;return e.on(`end`,function(){if(this.streamInfo.data_length!==t.uncompressedSize)throw Error(`Bug : uncompressed data size mismatch`)}),e},getCompressedWorker:function(){return new i(r.Promise.resolve(this.compressedContent)).withStreamInfo(`compressedSize`,this.compressedSize).withStreamInfo(`uncompressedSize`,this.uncompressedSize).withStreamInfo(`crc32`,this.crc32).withStreamInfo(`compression`,this.compression)}},s.createWorkerFrom=function(e,t,n){return e.pipe(new a).pipe(new o(`uncompressedSize`)).pipe(t.compressWorker(n)).pipe(new o(`compressedSize`)).withStreamInfo(`compression`,t)},t.exports=s},{"./external":6,"./stream/Crc32Probe":25,"./stream/DataLengthProbe":26,"./stream/DataWorker":27}],3:[function(e,t,n){var r=e(`./stream/GenericWorker`);n.STORE={magic:`\0\0`,compressWorker:function(){return new r(`STORE compression`)},uncompressWorker:function(){return new r(`STORE decompression`)}},n.DEFLATE=e(`./flate`)},{"./flate":7,"./stream/GenericWorker":28}],4:[function(e,t,n){var r=e(`./utils`),i=function(){for(var e,t=[],n=0;n<256;n++){e=n;for(var r=0;r<8;r++)e=1&e?3988292384^e>>>1:e>>>1;t[n]=e}return t}();t.exports=function(e,t){return e!==void 0&&e.length?r.getTypeOf(e)===`string`?function(e,t,n,r){var a=i,o=r+n;e^=-1;for(var s=r;s>>8^a[255&(e^t.charCodeAt(s))];return-1^e}(0|t,e,e.length,0):function(e,t,n,r){var a=i,o=r+n;e^=-1;for(var s=r;s>>8^a[255&(e^t[s])];return-1^e}(0|t,e,e.length,0):0}},{"./utils":32}],5:[function(e,t,n){n.base64=!1,n.binary=!1,n.dir=!1,n.createFolders=!0,n.date=null,n.compression=null,n.compressionOptions=null,n.comment=null,n.unixPermissions=null,n.dosPermissions=null},{}],6:[function(e,t,n){var r=null;r=typeof Promise<`u`?Promise:e(`lie`),t.exports={Promise:r}},{lie:37}],7:[function(e,t,n){var r=typeof Uint8Array<`u`&&typeof Uint16Array<`u`&&typeof Uint32Array<`u`,i=e(`pako`),a=e(`./utils`),o=e(`./stream/GenericWorker`),s=r?`uint8array`:`array`;function c(e,t){o.call(this,`FlateWorker/`+e),this._pako=null,this._pakoAction=e,this._pakoOptions=t,this.meta={}}n.magic=`\b\0`,a.inherits(c,o),c.prototype.processChunk=function(e){this.meta=e.meta,this._pako===null&&this._createPako(),this._pako.push(a.transformTo(s,e.data),!1)},c.prototype.flush=function(){o.prototype.flush.call(this),this._pako===null&&this._createPako(),this._pako.push([],!0)},c.prototype.cleanUp=function(){o.prototype.cleanUp.call(this),this._pako=null},c.prototype._createPako=function(){this._pako=new i[this._pakoAction]({raw:!0,level:this._pakoOptions.level||-1});var e=this;this._pako.onData=function(t){e.push({data:t,meta:e.meta})}},n.compressWorker=function(e){return new c(`Deflate`,e)},n.uncompressWorker=function(){return new c(`Inflate`,{})}},{"./stream/GenericWorker":28,"./utils":32,pako:38}],8:[function(e,t,n){function r(e,t){var n,r=``;for(n=0;n>>=8;return r}function i(e,t,n,i,o,u){var d,f,p=e.file,m=e.compression,h=u!==s.utf8encode,g=a.transformTo(`string`,u(p.name)),_=a.transformTo(`string`,s.utf8encode(p.name)),v=p.comment,y=a.transformTo(`string`,u(v)),b=a.transformTo(`string`,s.utf8encode(v)),x=_.length!==p.name.length,S=b.length!==v.length,C=``,w=``,T=``,E=p.dir,D=p.date,O={crc32:0,compressedSize:0,uncompressedSize:0};t&&!n||(O.crc32=e.crc32,O.compressedSize=e.compressedSize,O.uncompressedSize=e.uncompressedSize);var k=0;t&&(k|=8),h||!x&&!S||(k|=2048);var A=0,j=0;E&&(A|=16),o===`UNIX`?(j=798,A|=function(e,t){var n=e;return e||(n=t?16893:33204),(65535&n)<<16}(p.unixPermissions,E)):(j=20,A|=function(e){return 63&(e||0)}(p.dosPermissions)),d=D.getUTCHours(),d<<=6,d|=D.getUTCMinutes(),d<<=5,d|=D.getUTCSeconds()/2,f=D.getUTCFullYear()-1980,f<<=4,f|=D.getUTCMonth()+1,f<<=5,f|=D.getUTCDate(),x&&(w=r(1,1)+r(c(g),4)+_,C+=`up`+r(w.length,2)+w),S&&(T=r(1,1)+r(c(y),4)+b,C+=`uc`+r(T.length,2)+T);var M=``;return M+=` \0`,M+=r(k,2),M+=m.magic,M+=r(d,2),M+=r(f,2),M+=r(O.crc32,4),M+=r(O.compressedSize,4),M+=r(O.uncompressedSize,4),M+=r(g.length,2),M+=r(C.length,2),{fileRecord:l.LOCAL_FILE_HEADER+M+g+C,dirRecord:l.CENTRAL_FILE_HEADER+r(j,2)+M+r(y.length,2)+`\0\0\0\0`+r(A,4)+r(i,4)+g+C+y}}var a=e(`../utils`),o=e(`../stream/GenericWorker`),s=e(`../utf8`),c=e(`../crc32`),l=e(`../signature`);function u(e,t,n,r){o.call(this,`ZipFileWorker`),this.bytesWritten=0,this.zipComment=t,this.zipPlatform=n,this.encodeFileName=r,this.streamFiles=e,this.accumulate=!1,this.contentBuffer=[],this.dirRecords=[],this.currentSourceOffset=0,this.entriesCount=0,this.currentFile=null,this._sources=[]}a.inherits(u,o),u.prototype.push=function(e){var t=e.meta.percent||0,n=this.entriesCount,r=this._sources.length;this.accumulate?this.contentBuffer.push(e):(this.bytesWritten+=e.data.length,o.prototype.push.call(this,{data:e.data,meta:{currentFile:this.currentFile,percent:n?(t+100*(n-r-1))/n:100}}))},u.prototype.openedSource=function(e){this.currentSourceOffset=this.bytesWritten,this.currentFile=e.file.name;var t=this.streamFiles&&!e.file.dir;if(t){var n=i(e,t,!1,this.currentSourceOffset,this.zipPlatform,this.encodeFileName);this.push({data:n.fileRecord,meta:{percent:0}})}else this.accumulate=!0},u.prototype.closedSource=function(e){this.accumulate=!1;var t=this.streamFiles&&!e.file.dir,n=i(e,t,!0,this.currentSourceOffset,this.zipPlatform,this.encodeFileName);if(this.dirRecords.push(n.dirRecord),t)this.push({data:function(e){return l.DATA_DESCRIPTOR+r(e.crc32,4)+r(e.compressedSize,4)+r(e.uncompressedSize,4)}(e),meta:{percent:100}});else for(this.push({data:n.fileRecord,meta:{percent:0}});this.contentBuffer.length;)this.push(this.contentBuffer.shift());this.currentFile=null},u.prototype.flush=function(){for(var e=this.bytesWritten,t=0;t=this.index;t--)n=(n<<8)+this.byteAt(t);return this.index+=e,n},readString:function(e){return r.transformTo(`string`,this.readData(e))},readData:function(){},lastIndexOfSignature:function(){},readAndCheckSignature:function(){},readDate:function(){var e=this.readInt(4);return new Date(Date.UTC(1980+(e>>25&127),(e>>21&15)-1,e>>16&31,e>>11&31,e>>5&63,(31&e)<<1))}},t.exports=i},{"../utils":32}],19:[function(e,t,n){var r=e(`./Uint8ArrayReader`);function i(e){r.call(this,e)}e(`../utils`).inherits(i,r),i.prototype.readData=function(e){this.checkOffset(e);var t=this.data.slice(this.zero+this.index,this.zero+this.index+e);return this.index+=e,t},t.exports=i},{"../utils":32,"./Uint8ArrayReader":21}],20:[function(e,t,n){var r=e(`./DataReader`);function i(e){r.call(this,e)}e(`../utils`).inherits(i,r),i.prototype.byteAt=function(e){return this.data.charCodeAt(this.zero+e)},i.prototype.lastIndexOfSignature=function(e){return this.data.lastIndexOf(e)-this.zero},i.prototype.readAndCheckSignature=function(e){return e===this.readData(4)},i.prototype.readData=function(e){this.checkOffset(e);var t=this.data.slice(this.zero+this.index,this.zero+this.index+e);return this.index+=e,t},t.exports=i},{"../utils":32,"./DataReader":18}],21:[function(e,t,n){var r=e(`./ArrayReader`);function i(e){r.call(this,e)}e(`../utils`).inherits(i,r),i.prototype.readData=function(e){if(this.checkOffset(e),e===0)return new Uint8Array;var t=this.data.subarray(this.zero+this.index,this.zero+this.index+e);return this.index+=e,t},t.exports=i},{"../utils":32,"./ArrayReader":17}],22:[function(e,t,n){var r=e(`../utils`),i=e(`../support`),a=e(`./ArrayReader`),o=e(`./StringReader`),s=e(`./NodeBufferReader`),c=e(`./Uint8ArrayReader`);t.exports=function(e){var t=r.getTypeOf(e);return r.checkSupport(t),t!==`string`||i.uint8array?t===`nodebuffer`?new s(e):i.uint8array?new c(r.transformTo(`uint8array`,e)):new a(r.transformTo(`array`,e)):new o(e)}},{"../support":30,"../utils":32,"./ArrayReader":17,"./NodeBufferReader":19,"./StringReader":20,"./Uint8ArrayReader":21}],23:[function(e,t,n){n.LOCAL_FILE_HEADER=`PK`,n.CENTRAL_FILE_HEADER=`PK`,n.CENTRAL_DIRECTORY_END=`PK`,n.ZIP64_CENTRAL_DIRECTORY_LOCATOR=`PK\x07`,n.ZIP64_CENTRAL_DIRECTORY_END=`PK`,n.DATA_DESCRIPTOR=`PK\x07\b`},{}],24:[function(e,t,n){var r=e(`./GenericWorker`),i=e(`../utils`);function a(e){r.call(this,`ConvertWorker to `+e),this.destType=e}i.inherits(a,r),a.prototype.processChunk=function(e){this.push({data:i.transformTo(this.destType,e.data),meta:e.meta})},t.exports=a},{"../utils":32,"./GenericWorker":28}],25:[function(e,t,n){var r=e(`./GenericWorker`),i=e(`../crc32`);function a(){r.call(this,`Crc32Probe`),this.withStreamInfo(`crc32`,0)}e(`../utils`).inherits(a,r),a.prototype.processChunk=function(e){this.streamInfo.crc32=i(e.data,this.streamInfo.crc32||0),this.push(e)},t.exports=a},{"../crc32":4,"../utils":32,"./GenericWorker":28}],26:[function(e,t,n){var r=e(`../utils`),i=e(`./GenericWorker`);function a(e){i.call(this,`DataLengthProbe for `+e),this.propName=e,this.withStreamInfo(e,0)}r.inherits(a,i),a.prototype.processChunk=function(e){if(e){var t=this.streamInfo[this.propName]||0;this.streamInfo[this.propName]=t+e.data.length}i.prototype.processChunk.call(this,e)},t.exports=a},{"../utils":32,"./GenericWorker":28}],27:[function(e,t,n){var r=e(`../utils`),i=e(`./GenericWorker`);function a(e){i.call(this,`DataWorker`);var t=this;this.dataIsReady=!1,this.index=0,this.max=0,this.data=null,this.type=``,this._tickScheduled=!1,e.then(function(e){t.dataIsReady=!0,t.data=e,t.max=e&&e.length||0,t.type=r.getTypeOf(e),t.isPaused||t._tickAndRepeat()},function(e){t.error(e)})}r.inherits(a,i),a.prototype.cleanUp=function(){i.prototype.cleanUp.call(this),this.data=null},a.prototype.resume=function(){return!!i.prototype.resume.call(this)&&(!this._tickScheduled&&this.dataIsReady&&(this._tickScheduled=!0,r.delay(this._tickAndRepeat,[],this)),!0)},a.prototype._tickAndRepeat=function(){this._tickScheduled=!1,this.isPaused||this.isFinished||(this._tick(),this.isFinished||(r.delay(this._tickAndRepeat,[],this),this._tickScheduled=!0))},a.prototype._tick=function(){if(this.isPaused||this.isFinished)return!1;var e=null,t=Math.min(this.max,this.index+16384);if(this.index>=this.max)return this.end();switch(this.type){case`string`:e=this.data.substring(this.index,t);break;case`uint8array`:e=this.data.subarray(this.index,t);break;case`array`:case`nodebuffer`:e=this.data.slice(this.index,t)}return this.index=t,this.push({data:e,meta:{percent:this.max?this.index/this.max*100:0}})},t.exports=a},{"../utils":32,"./GenericWorker":28}],28:[function(e,t,n){function r(e){this.name=e||`default`,this.streamInfo={},this.generatedError=null,this.extraStreamInfo={},this.isPaused=!0,this.isFinished=!1,this.isLocked=!1,this._listeners={data:[],end:[],error:[]},this.previous=null}r.prototype={push:function(e){this.emit(`data`,e)},end:function(){if(this.isFinished)return!1;this.flush();try{this.emit(`end`),this.cleanUp(),this.isFinished=!0}catch(e){this.emit(`error`,e)}return!0},error:function(e){return!this.isFinished&&(this.isPaused?this.generatedError=e:(this.isFinished=!0,this.emit(`error`,e),this.previous&&this.previous.error(e),this.cleanUp()),!0)},on:function(e,t){return this._listeners[e].push(t),this},cleanUp:function(){this.streamInfo=this.generatedError=this.extraStreamInfo=null,this._listeners=[]},emit:function(e,t){if(this._listeners[e])for(var n=0;n `+e:e}},t.exports=r},{}],29:[function(e,t,n){var r=e(`../utils`),i=e(`./ConvertWorker`),a=e(`./GenericWorker`),o=e(`../base64`),s=e(`../support`),c=e(`../external`),l=null;if(s.nodestream)try{l=e(`../nodejs/NodejsStreamOutputAdapter`)}catch{}function u(e,t){return new c.Promise(function(n,i){var a=[],s=e._internalType,c=e._outputType,l=e._mimeType;e.on(`data`,function(e,n){a.push(e),t&&t(n)}).on(`error`,function(e){a=[],i(e)}).on(`end`,function(){try{n(function(e,t,n){switch(e){case`blob`:return r.newBlob(r.transformTo(`arraybuffer`,t),n);case`base64`:return o.encode(t);default:return r.transformTo(e,t)}}(c,function(e,t){var n,r=0,i=null,a=0;for(n=0;n`u`)n.blob=!1;else{var r=new ArrayBuffer(0);try{n.blob=new Blob([r],{type:`application/zip`}).size===0}catch{try{var i=new(self.BlobBuilder||self.WebKitBlobBuilder||self.MozBlobBuilder||self.MSBlobBuilder);i.append(r),n.blob=i.getBlob(`application/zip`).size===0}catch{n.blob=!1}}}try{n.nodestream=!!e(`readable-stream`).Readable}catch{n.nodestream=!1}},{"readable-stream":16}],31:[function(e,t,n){for(var r=e(`./utils`),i=e(`./support`),a=e(`./nodejsUtils`),o=e(`./stream/GenericWorker`),s=Array(256),c=0;c<256;c++)s[c]=252<=c?6:248<=c?5:240<=c?4:224<=c?3:192<=c?2:1;s[254]=s[254]=1;function l(){o.call(this,`utf-8 decode`),this.leftOver=null}function u(){o.call(this,`utf-8 encode`)}n.utf8encode=function(e){return i.nodebuffer?a.newBufferFrom(e,`utf-8`):function(e){var t,n,r,a,o,s=e.length,c=0;for(a=0;a>>6:(n<65536?t[o++]=224|n>>>12:(t[o++]=240|n>>>18,t[o++]=128|n>>>12&63),t[o++]=128|n>>>6&63),t[o++]=128|63&n);return t}(e)},n.utf8decode=function(e){return i.nodebuffer?r.transformTo(`nodebuffer`,e).toString(`utf-8`):function(e){var t,n,i,a,o=e.length,c=Array(2*o);for(t=n=0;t>10&1023,c[n++]=56320|1023&i)}return c.length!==n&&(c.subarray?c=c.subarray(0,n):c.length=n),r.applyFromCharCode(c)}(e=r.transformTo(i.uint8array?`uint8array`:`array`,e))},r.inherits(l,o),l.prototype.processChunk=function(e){var t=r.transformTo(i.uint8array?`uint8array`:`array`,e.data);if(this.leftOver&&this.leftOver.length){if(i.uint8array){var a=t;(t=new Uint8Array(a.length+this.leftOver.length)).set(this.leftOver,0),t.set(a,this.leftOver.length)}else t=this.leftOver.concat(t);this.leftOver=null}var o=function(e,t){var n;for((t||=e.length)>e.length&&(t=e.length),n=t-1;0<=n&&(192&e[n])==128;)n--;return n<0||n===0?t:n+s[e[n]]>t?n:t}(t),c=t;o!==t.length&&(i.uint8array?(c=t.subarray(0,o),this.leftOver=t.subarray(o,t.length)):(c=t.slice(0,o),this.leftOver=t.slice(o,t.length))),this.push({data:n.utf8decode(c),meta:e.meta})},l.prototype.flush=function(){this.leftOver&&this.leftOver.length&&(this.push({data:n.utf8decode(this.leftOver),meta:{}}),this.leftOver=null)},n.Utf8DecodeWorker=l,r.inherits(u,o),u.prototype.processChunk=function(e){this.push({data:n.utf8encode(e.data),meta:e.meta})},n.Utf8EncodeWorker=u},{"./nodejsUtils":14,"./stream/GenericWorker":28,"./support":30,"./utils":32}],32:[function(e,t,n){var r=e(`./support`),i=e(`./base64`),a=e(`./nodejsUtils`),o=e(`./external`);function s(e){return e}function c(e,t){for(var n=0;n>8;this.dir=!!(16&this.externalFileAttributes),e==0&&(this.dosPermissions=63&this.externalFileAttributes),e==3&&(this.unixPermissions=this.externalFileAttributes>>16&65535),this.dir||this.fileNameStr.slice(-1)!==`/`||(this.dir=!0)},parseZIP64ExtraField:function(){if(this.extraFields[1]){var e=r(this.extraFields[1].value);this.uncompressedSize===i.MAX_VALUE_32BITS&&(this.uncompressedSize=e.readInt(8)),this.compressedSize===i.MAX_VALUE_32BITS&&(this.compressedSize=e.readInt(8)),this.localHeaderOffset===i.MAX_VALUE_32BITS&&(this.localHeaderOffset=e.readInt(8)),this.diskNumberStart===i.MAX_VALUE_32BITS&&(this.diskNumberStart=e.readInt(4))}},readExtraFields:function(e){var t,n,r,i=e.index+this.extraFieldsLength;for(this.extraFields||={};e.index+4>>6:(n<65536?t[o++]=224|n>>>12:(t[o++]=240|n>>>18,t[o++]=128|n>>>12&63),t[o++]=128|n>>>6&63),t[o++]=128|63&n);return t},n.buf2binstring=function(e){return c(e,e.length)},n.binstring2buf=function(e){for(var t=new r.Buf8(e.length),n=0,i=t.length;n>10&1023,l[r++]=56320|1023&i)}return c(l,r)},n.utf8border=function(e,t){var n;for((t||=e.length)>e.length&&(t=e.length),n=t-1;0<=n&&(192&e[n])==128;)n--;return n<0||n===0?t:n+o[e[n]]>t?n:t}},{"./common":41}],43:[function(e,t,n){t.exports=function(e,t,n,r){for(var i=65535&e|0,a=e>>>16&65535|0,o=0;n!==0;){for(n-=o=2e3>>1:e>>>1;t[n]=e}return t}();t.exports=function(e,t,n,i){var a=r,o=i+n;e^=-1;for(var s=i;s>>8^a[255&(e^t[s])];return-1^e}},{}],46:[function(e,t,n){var r,i=e(`../utils/common`),a=e(`./trees`),o=e(`./adler32`),s=e(`./crc32`),c=e(`./messages`),l=0,u=4,d=0,f=-2,p=-1,m=4,h=2,g=8,_=9,v=286,y=30,b=19,x=2*v+1,S=15,C=3,w=258,T=w+C+1,E=42,D=113,O=1,k=2,A=3,j=4;function M(e,t){return e.msg=c[t],t}function N(e){return(e<<1)-(4e.avail_out&&(n=e.avail_out),n!==0&&(i.arraySet(e.output,t.pending_buf,t.pending_out,n,e.next_out),e.next_out+=n,t.pending_out+=n,e.total_out+=n,e.avail_out-=n,t.pending-=n,t.pending===0&&(t.pending_out=0))}function I(e,t){a._tr_flush_block(e,0<=e.block_start?e.block_start:-1,e.strstart-e.block_start,t),e.block_start=e.strstart,F(e.strm)}function L(e,t){e.pending_buf[e.pending++]=t}function R(e,t){e.pending_buf[e.pending++]=t>>>8&255,e.pending_buf[e.pending++]=255&t}function z(e,t){var n,r,i=e.max_chain_length,a=e.strstart,o=e.prev_length,s=e.nice_match,c=e.strstart>e.w_size-T?e.strstart-(e.w_size-T):0,l=e.window,u=e.w_mask,d=e.prev,f=e.strstart+w,p=l[a+o-1],m=l[a+o];e.prev_length>=e.good_match&&(i>>=2),s>e.lookahead&&(s=e.lookahead);do if(l[(n=t)+o]===m&&l[n+o-1]===p&&l[n]===l[a]&&l[++n]===l[a+1]){a+=2,n++;do;while(l[++a]===l[++n]&&l[++a]===l[++n]&&l[++a]===l[++n]&&l[++a]===l[++n]&&l[++a]===l[++n]&&l[++a]===l[++n]&&l[++a]===l[++n]&&l[++a]===l[++n]&&ac&&--i!=0);return o<=e.lookahead?o:e.lookahead}function B(e){var t,n,r,a,c,l,u,d,f,p,m=e.w_size;do{if(a=e.window_size-e.lookahead-e.strstart,e.strstart>=m+(m-T)){for(i.arraySet(e.window,e.window,m,m,0),e.match_start-=m,e.strstart-=m,e.block_start-=m,t=n=e.hash_size;r=e.head[--t],e.head[t]=m<=r?r-m:0,--n;);for(t=n=m;r=e.prev[--t],e.prev[t]=m<=r?r-m:0,--n;);a+=m}if(e.strm.avail_in===0)break;if(l=e.strm,u=e.window,d=e.strstart+e.lookahead,f=a,p=void 0,p=l.avail_in,f=C)for(c=e.strstart-e.insert,e.ins_h=e.window[c],e.ins_h=(e.ins_h<=C&&(e.ins_h=(e.ins_h<=C)if(r=a._tr_tally(e,e.strstart-e.match_start,e.match_length-C),e.lookahead-=e.match_length,e.match_length<=e.max_lazy_match&&e.lookahead>=C){for(e.match_length--;e.strstart++,e.ins_h=(e.ins_h<=C&&(e.ins_h=(e.ins_h<=C&&e.match_length<=e.prev_length){for(i=e.strstart+e.lookahead-C,r=a._tr_tally(e,e.strstart-1-e.prev_match,e.prev_length-C),e.lookahead-=e.prev_length-1,e.prev_length-=2;++e.strstart<=i&&(e.ins_h=(e.ins_h<e.pending_buf_size-5&&(n=e.pending_buf_size-5);;){if(e.lookahead<=1){if(B(e),e.lookahead===0&&t===l)return O;if(e.lookahead===0)break}e.strstart+=e.lookahead,e.lookahead=0;var r=e.block_start+n;if((e.strstart===0||e.strstart>=r)&&(e.lookahead=e.strstart-r,e.strstart=r,I(e,!1),e.strm.avail_out===0)||e.strstart-e.block_start>=e.w_size-T&&(I(e,!1),e.strm.avail_out===0))return O}return e.insert=0,t===u?(I(e,!0),e.strm.avail_out===0?A:j):(e.strstart>e.block_start&&(I(e,!1),e.strm.avail_out),O)}),new U(4,4,8,4,V),new U(4,5,16,8,V),new U(4,6,32,32,V),new U(4,4,16,16,H),new U(8,16,32,32,H),new U(8,16,128,128,H),new U(8,32,128,256,H),new U(32,128,258,1024,H),new U(32,258,258,4096,H)],n.deflateInit=function(e,t){return K(e,t,g,15,8,0)},n.deflateInit2=K,n.deflateReset=G,n.deflateResetKeep=W,n.deflateSetHeader=function(e,t){return e&&e.state&&e.state.wrap===2?(e.state.gzhead=t,d):f},n.deflate=function(e,t){var n,i,o,c;if(!e||!e.state||5>8&255),L(i,i.gzhead.time>>16&255),L(i,i.gzhead.time>>24&255),L(i,i.level===9?2:2<=i.strategy||i.level<2?4:0),L(i,255&i.gzhead.os),i.gzhead.extra&&i.gzhead.extra.length&&(L(i,255&i.gzhead.extra.length),L(i,i.gzhead.extra.length>>8&255)),i.gzhead.hcrc&&(e.adler=s(e.adler,i.pending_buf,i.pending,0)),i.gzindex=0,i.status=69):(L(i,0),L(i,0),L(i,0),L(i,0),L(i,0),L(i,i.level===9?2:2<=i.strategy||i.level<2?4:0),L(i,3),i.status=D);else{var p=g+(i.w_bits-8<<4)<<8;p|=(2<=i.strategy||i.level<2?0:i.level<6?1:i.level===6?2:3)<<6,i.strstart!==0&&(p|=32),p+=31-p%31,i.status=D,R(i,p),i.strstart!==0&&(R(i,e.adler>>>16),R(i,65535&e.adler)),e.adler=1}if(i.status===69)if(i.gzhead.extra){for(o=i.pending;i.gzindex<(65535&i.gzhead.extra.length)&&(i.pending!==i.pending_buf_size||(i.gzhead.hcrc&&i.pending>o&&(e.adler=s(e.adler,i.pending_buf,i.pending-o,o)),F(e),o=i.pending,i.pending!==i.pending_buf_size));)L(i,255&i.gzhead.extra[i.gzindex]),i.gzindex++;i.gzhead.hcrc&&i.pending>o&&(e.adler=s(e.adler,i.pending_buf,i.pending-o,o)),i.gzindex===i.gzhead.extra.length&&(i.gzindex=0,i.status=73)}else i.status=73;if(i.status===73)if(i.gzhead.name){o=i.pending;do{if(i.pending===i.pending_buf_size&&(i.gzhead.hcrc&&i.pending>o&&(e.adler=s(e.adler,i.pending_buf,i.pending-o,o)),F(e),o=i.pending,i.pending===i.pending_buf_size)){c=1;break}c=i.gzindexo&&(e.adler=s(e.adler,i.pending_buf,i.pending-o,o)),c===0&&(i.gzindex=0,i.status=91)}else i.status=91;if(i.status===91)if(i.gzhead.comment){o=i.pending;do{if(i.pending===i.pending_buf_size&&(i.gzhead.hcrc&&i.pending>o&&(e.adler=s(e.adler,i.pending_buf,i.pending-o,o)),F(e),o=i.pending,i.pending===i.pending_buf_size)){c=1;break}c=i.gzindexo&&(e.adler=s(e.adler,i.pending_buf,i.pending-o,o)),c===0&&(i.status=103)}else i.status=103;if(i.status===103&&(i.gzhead.hcrc?(i.pending+2>i.pending_buf_size&&F(e),i.pending+2<=i.pending_buf_size&&(L(i,255&e.adler),L(i,e.adler>>8&255),e.adler=0,i.status=D)):i.status=D),i.pending!==0){if(F(e),e.avail_out===0)return i.last_flush=-1,d}else if(e.avail_in===0&&N(t)<=N(n)&&t!==u)return M(e,-5);if(i.status===666&&e.avail_in!==0)return M(e,-5);if(e.avail_in!==0||i.lookahead!==0||t!==l&&i.status!==666){var m=i.strategy===2?function(e,t){for(var n;;){if(e.lookahead===0&&(B(e),e.lookahead===0)){if(t===l)return O;break}if(e.match_length=0,n=a._tr_tally(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++,n&&(I(e,!1),e.strm.avail_out===0))return O}return e.insert=0,t===u?(I(e,!0),e.strm.avail_out===0?A:j):e.last_lit&&(I(e,!1),e.strm.avail_out===0)?O:k}(i,t):i.strategy===3?function(e,t){for(var n,r,i,o,s=e.window;;){if(e.lookahead<=w){if(B(e),e.lookahead<=w&&t===l)return O;if(e.lookahead===0)break}if(e.match_length=0,e.lookahead>=C&&0e.lookahead&&(e.match_length=e.lookahead)}if(e.match_length>=C?(n=a._tr_tally(e,1,e.match_length-C),e.lookahead-=e.match_length,e.strstart+=e.match_length,e.match_length=0):(n=a._tr_tally(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++),n&&(I(e,!1),e.strm.avail_out===0))return O}return e.insert=0,t===u?(I(e,!0),e.strm.avail_out===0?A:j):e.last_lit&&(I(e,!1),e.strm.avail_out===0)?O:k}(i,t):r[i.level].func(i,t);if(m!==A&&m!==j||(i.status=666),m===O||m===A)return e.avail_out===0&&(i.last_flush=-1),d;if(m===k&&(t===1?a._tr_align(i):t!==5&&(a._tr_stored_block(i,0,0,!1),t===3&&(P(i.head),i.lookahead===0&&(i.strstart=0,i.block_start=0,i.insert=0))),F(e),e.avail_out===0))return i.last_flush=-1,d}return t===u?i.wrap<=0?1:(i.wrap===2?(L(i,255&e.adler),L(i,e.adler>>8&255),L(i,e.adler>>16&255),L(i,e.adler>>24&255),L(i,255&e.total_in),L(i,e.total_in>>8&255),L(i,e.total_in>>16&255),L(i,e.total_in>>24&255)):(R(i,e.adler>>>16),R(i,65535&e.adler)),F(e),0=n.w_size&&(s===0&&(P(n.head),n.strstart=0,n.block_start=0,n.insert=0),p=new i.Buf8(n.w_size),i.arraySet(p,t,m-n.w_size,n.w_size,0),t=p,m=n.w_size),c=e.avail_in,l=e.next_in,u=e.input,e.avail_in=m,e.next_in=0,e.input=t,B(n);n.lookahead>=C;){for(r=n.strstart,a=n.lookahead-(C-1);n.ins_h=(n.ins_h<>>=b=y>>>24,m-=b,(b=y>>>16&255)==0)E[a++]=65535&y;else{if(!(16&b)){if(!(64&b)){y=h[(65535&y)+(p&(1<>>=b,m-=b),m<15&&(p+=T[r++]<>>=b=y>>>24,m-=b,!(16&(b=y>>>16&255))){if(!(64&b)){y=g[(65535&y)+(p&(1<>>=b,m-=b,(b=a-o)>3,p&=(1<<(m-=x<<3))-1,e.next_in=r,e.next_out=a,e.avail_in=r>>24&255)+(e>>>8&65280)+((65280&e)<<8)+((255&e)<<24)}function g(){this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new r.Buf16(320),this.work=new r.Buf16(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}function _(e){var t;return e&&e.state?(t=e.state,e.total_in=e.total_out=t.total=0,e.msg=``,t.wrap&&(e.adler=1&t.wrap),t.mode=f,t.last=0,t.havedict=0,t.dmax=32768,t.head=null,t.hold=0,t.bits=0,t.lencode=t.lendyn=new r.Buf32(p),t.distcode=t.distdyn=new r.Buf32(m),t.sane=1,t.back=-1,u):d}function v(e){var t;return e&&e.state?((t=e.state).wsize=0,t.whave=0,t.wnext=0,_(e)):d}function y(e,t){var n,r;return e&&e.state?(r=e.state,t<0?(n=0,t=-t):(n=1+(t>>4),t<48&&(t&=15)),t&&(t<8||15=o.wsize?(r.arraySet(o.window,t,n-o.wsize,o.wsize,0),o.wnext=0,o.whave=o.wsize):(i<(a=o.wsize-o.wnext)&&(a=i),r.arraySet(o.window,t,n-i,a,o.wnext),(i-=a)?(r.arraySet(o.window,t,n-i,i,0),o.wnext=i,o.whave=o.wsize):(o.wnext+=a,o.wnext===o.wsize&&(o.wnext=0),o.whave>>8&255,n.check=a(n.check,B,2,0),x=b=0,n.mode=2;break}if(n.flags=0,n.head&&(n.head.done=!1),!(1&n.wrap)||(((255&b)<<8)+(b>>8))%31){e.msg=`incorrect header check`,n.mode=30;break}if((15&b)!=8){e.msg=`unknown compression method`,n.mode=30;break}if(x-=4,F=8+(15&(b>>>=4)),n.wbits===0)n.wbits=F;else if(F>n.wbits){e.msg=`invalid window size`,n.mode=30;break}n.dmax=1<>8&1),512&n.flags&&(B[0]=255&b,B[1]=b>>>8&255,n.check=a(n.check,B,2,0)),x=b=0,n.mode=3;case 3:for(;x<32;){if(v===0)break e;v--,b+=p[g++]<>>8&255,B[2]=b>>>16&255,B[3]=b>>>24&255,n.check=a(n.check,B,4,0)),x=b=0,n.mode=4;case 4:for(;x<16;){if(v===0)break e;v--,b+=p[g++]<>8),512&n.flags&&(B[0]=255&b,B[1]=b>>>8&255,n.check=a(n.check,B,2,0)),x=b=0,n.mode=5;case 5:if(1024&n.flags){for(;x<16;){if(v===0)break e;v--,b+=p[g++]<>>8&255,n.check=a(n.check,B,2,0)),x=b=0}else n.head&&(n.head.extra=null);n.mode=6;case 6:if(1024&n.flags&&(v<(E=n.length)&&(E=v),E&&(n.head&&(F=n.head.extra_len-n.length,n.head.extra||(n.head.extra=Array(n.head.extra_len)),r.arraySet(n.head.extra,p,g,E,F)),512&n.flags&&(n.check=a(n.check,p,E,g)),v-=E,g+=E,n.length-=E),n.length))break e;n.length=0,n.mode=7;case 7:if(2048&n.flags){if(v===0)break e;for(E=0;F=p[g+ E++],n.head&&F&&n.length<65536&&(n.head.name+=String.fromCharCode(F)),F&&E>9&1,n.head.done=!0),e.adler=n.check=0,n.mode=12;break;case 10:for(;x<32;){if(v===0)break e;v--,b+=p[g++]<>>=7&x,x-=7&x,n.mode=27;break}for(;x<3;){if(v===0)break e;v--,b+=p[g++]<>>=1)){case 0:n.mode=14;break;case 1:if(w(n),n.mode=20,t!==6)break;b>>>=2,x-=2;break e;case 2:n.mode=17;break;case 3:e.msg=`invalid block type`,n.mode=30}b>>>=2,x-=2;break;case 14:for(b>>>=7&x,x-=7&x;x<32;){if(v===0)break e;v--,b+=p[g++]<>>16^65535)){e.msg=`invalid stored block lengths`,n.mode=30;break}if(n.length=65535&b,x=b=0,n.mode=15,t===6)break e;case 15:n.mode=16;case 16:if(E=n.length){if(v>>=5,x-=5,n.ndist=1+(31&b),b>>>=5,x-=5,n.ncode=4+(15&b),b>>>=4,x-=4,286>>=3,x-=3}for(;n.have<19;)n.lens[V[n.have++]]=0;if(n.lencode=n.lendyn,n.lenbits=7,L={bits:n.lenbits},I=s(0,n.lens,0,19,n.lencode,0,n.work,L),n.lenbits=L.bits,I){e.msg=`invalid code lengths set`,n.mode=30;break}n.have=0,n.mode=19;case 19:for(;n.have>>16&255,j=65535&z,!((k=z>>>24)<=x);){if(v===0)break e;v--,b+=p[g++]<>>=k,x-=k,n.lens[n.have++]=j;else{if(j===16){for(R=k+2;x>>=k,x-=k,n.have===0){e.msg=`invalid bit length repeat`,n.mode=30;break}F=n.lens[n.have-1],E=3+(3&b),b>>>=2,x-=2}else if(j===17){for(R=k+3;x>>=k)),b>>>=3,x-=3}else{for(R=k+7;x>>=k)),b>>>=7,x-=7}if(n.have+E>n.nlen+n.ndist){e.msg=`invalid bit length repeat`,n.mode=30;break}for(;E--;)n.lens[n.have++]=F}}if(n.mode===30)break;if(n.lens[256]===0){e.msg=`invalid code -- missing end-of-block`,n.mode=30;break}if(n.lenbits=9,L={bits:n.lenbits},I=s(c,n.lens,0,n.nlen,n.lencode,0,n.work,L),n.lenbits=L.bits,I){e.msg=`invalid literal/lengths set`,n.mode=30;break}if(n.distbits=6,n.distcode=n.distdyn,L={bits:n.distbits},I=s(l,n.lens,n.nlen,n.ndist,n.distcode,0,n.work,L),n.distbits=L.bits,I){e.msg=`invalid distances set`,n.mode=30;break}if(n.mode=20,t===6)break e;case 20:n.mode=21;case 21:if(6<=v&&258<=y){e.next_out=_,e.avail_out=y,e.next_in=g,e.avail_in=v,n.hold=b,n.bits=x,o(e,C),_=e.next_out,m=e.output,y=e.avail_out,g=e.next_in,p=e.input,v=e.avail_in,b=n.hold,x=n.bits,n.mode===12&&(n.back=-1);break}for(n.back=0;A=(z=n.lencode[b&(1<>>16&255,j=65535&z,!((k=z>>>24)<=x);){if(v===0)break e;v--,b+=p[g++]<>M)])>>>16&255,j=65535&z,!(M+(k=z>>>24)<=x);){if(v===0)break e;v--,b+=p[g++]<>>=M,x-=M,n.back+=M}if(b>>>=k,x-=k,n.back+=k,n.length=j,A===0){n.mode=26;break}if(32&A){n.back=-1,n.mode=12;break}if(64&A){e.msg=`invalid literal/length code`,n.mode=30;break}n.extra=15&A,n.mode=22;case 22:if(n.extra){for(R=n.extra;x>>=n.extra,x-=n.extra,n.back+=n.extra}n.was=n.length,n.mode=23;case 23:for(;A=(z=n.distcode[b&(1<>>16&255,j=65535&z,!((k=z>>>24)<=x);){if(v===0)break e;v--,b+=p[g++]<>M)])>>>16&255,j=65535&z,!(M+(k=z>>>24)<=x);){if(v===0)break e;v--,b+=p[g++]<>>=M,x-=M,n.back+=M}if(b>>>=k,x-=k,n.back+=k,64&A){e.msg=`invalid distance code`,n.mode=30;break}n.offset=j,n.extra=15&A,n.mode=24;case 24:if(n.extra){for(R=n.extra;x>>=n.extra,x-=n.extra,n.back+=n.extra}if(n.offset>n.dmax){e.msg=`invalid distance too far back`,n.mode=30;break}n.mode=25;case 25:if(y===0)break e;if(E=C-y,n.offset>E){if((E=n.offset-E)>n.whave&&n.sane){e.msg=`invalid distance too far back`,n.mode=30;break}D=E>n.wnext?(E-=n.wnext,n.wsize-E):n.wnext-E,E>n.length&&(E=n.length),O=n.window}else O=m,D=_-n.offset,E=n.length;for(yv?(b=L[R+d[w]],N[P+d[w]]):(b=96,0),p=1<>k)+(m-=p)]=y<<24|b<<16|x|0,m!==0;);for(p=1<>=1;if(p===0?M=0:(M&=p-1,M+=p),w++,--F[C]==0){if(C===E)break;C=t[n+d[w]]}if(D>>7)]}function L(e,t){e.pending_buf[e.pending++]=255&t,e.pending_buf[e.pending++]=t>>>8&255}function R(e,t,n){e.bi_valid>h-n?(e.bi_buf|=t<>h-e.bi_valid,e.bi_valid+=n-h):(e.bi_buf|=t<>>=1,n<<=1,0<--t;);return n>>>1}function V(e,t,n){var r,i,a=Array(m+1),o=0;for(r=1;r<=m;r++)a[r]=o=o+n[r-1]<<1;for(i=0;i<=t;i++){var s=e[2*i+1];s!==0&&(e[2*i]=B(a[s]++,s))}}function H(e){var t;for(t=0;t>1;1<=n;n--)W(e,a,n);for(i=c;n=e.heap[1],e.heap[1]=e.heap[e.heap_len--],W(e,a,1),r=e.heap[1],e.heap[--e.heap_max]=n,e.heap[--e.heap_max]=r,a[2*i]=a[2*n]+a[2*r],e.depth[i]=(e.depth[n]>=e.depth[r]?e.depth[n]:e.depth[r])+1,a[2*n+1]=a[2*r+1]=i,e.heap[1]=i++,W(e,a,1),2<=e.heap_len;);e.heap[--e.heap_max]=e.heap[1],function(e,t){var n,r,i,a,o,s,c=t.dyn_tree,l=t.max_code,u=t.stat_desc.static_tree,d=t.stat_desc.has_stree,f=t.stat_desc.extra_bits,h=t.stat_desc.extra_base,g=t.stat_desc.max_length,_=0;for(a=0;a<=m;a++)e.bl_count[a]=0;for(c[2*e.heap[e.heap_max]+1]=0,n=e.heap_max+1;n>=7;r>>=1)if(1&n&&e.dyn_ltree[2*t]!==0)return i;if(e.dyn_ltree[18]!==0||e.dyn_ltree[20]!==0||e.dyn_ltree[26]!==0)return a;for(t=32;t>>3,(s=e.static_len+3+7>>>3)<=o&&(o=s)):o=s=n+5,n+4<=o&&t!==-1?X(e,t,n,r):e.strategy===4||s===o?(R(e,2+ +!!r,3),G(e,T,E)):(R(e,4+ +!!r,3),function(e,t,n,r){var i;for(R(e,t-257,5),R(e,n-1,5),R(e,r-4,4),i=0;i>>8&255,e.pending_buf[e.d_buf+2*e.last_lit+1]=255&t,e.pending_buf[e.l_buf+e.last_lit]=255&n,e.last_lit++,t===0?e.dyn_ltree[2*n]++:(e.matches++,t--,e.dyn_ltree[2*(O[n]+l+1)]++,e.dyn_dtree[2*I(t)]++),e.last_lit===e.lit_bufsize-1},n._tr_align=function(e){R(e,2,3),z(e,_,T),function(e){e.bi_valid===16?(L(e,e.bi_buf),e.bi_buf=0,e.bi_valid=0):8<=e.bi_valid&&(e.pending_buf[e.pending++]=255&e.bi_buf,e.bi_buf>>=8,e.bi_valid-=8)}(e)}},{"../utils/common":41}],53:[function(e,t,n){t.exports=function(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg=``,this.state=null,this.data_type=2,this.adler=0}},{}],54:[function(e,t,n){(function(e){(function(e,t){if(!e.setImmediate){var n,r,i,a,o=1,s={},c=!1,l=e.document,u=Object.getPrototypeOf&&Object.getPrototypeOf(e);u=u&&u.setTimeout?u:e,n={}.toString.call(e.process)===`[object process]`?function(e){process.nextTick(function(){f(e)})}:function(){if(e.postMessage&&!e.importScripts){var t=!0,n=e.onmessage;return e.onmessage=function(){t=!1},e.postMessage(``,`*`),e.onmessage=n,t}}()?(a=`setImmediate$`+Math.random()+`$`,e.addEventListener?e.addEventListener(`message`,p,!1):e.attachEvent(`onmessage`,p),function(t){e.postMessage(a+t,`*`)}):e.MessageChannel?((i=new MessageChannel).port1.onmessage=function(e){f(e.data)},function(e){i.port2.postMessage(e)}):l&&`onreadystatechange`in l.createElement(`script`)?(r=l.documentElement,function(e){var t=l.createElement(`script`);t.onreadystatechange=function(){f(e),t.onreadystatechange=null,r.removeChild(t),t=null},r.appendChild(t)}):function(e){setTimeout(f,0,e)},u.setImmediate=function(e){typeof e!=`function`&&(e=Function(``+e));for(var t=Array(arguments.length-1),r=0;r`u`?e===void 0?this:e:self)}).call(this,typeof global<`u`?global:typeof self<`u`?self:typeof window<`u`?window:{})},{}]},{},[10])(10)})}))(),1),Q=r(),ae=null,oe=0,$=new Map;function se(e){for(let t of $.values())t.reject(Error(e));$.clear()}function ce(){if(!ae){let e=new Worker(new URL(`/assets/stepPreview.worker-QYcQPnWg.js`,``+import.meta.url),{type:`module`});e.onmessage=e=>{let t=$.get(e.data.id);t&&($.delete(e.data.id),e.data.ok?t.resolve(e.data.meshes):t.reject(Error(e.data.reason)))},e.onerror=()=>{se(`error`),e.terminate(),ae===e&&(ae=null)},ae=e}return ae}function le(e){return new Promise((t,n)=>{let r=++oe;$.set(r,{resolve:t,reject:n}),ce().postMessage({id:r,buffer:e},[e])})}var ue=8;function de(e,t,n,r,i=1.15){let a=n.getSize(new x),o=n.getCenter(new x),s=Math.max(a.length()/2,.001),c=O.degToRad(e.fov),l=2*Math.atan(Math.tan(c/2)*e.aspect),u=i*Math.max(s/Math.sin(c/2),s/Math.sin(l/2)),d=new x(.7,.5,.7).normalize();e.position.copy(o).addScaledVector(d,u),t.minDistance=Math.max(s*.05,.05),t.maxDistance=u*ue,e.near=Math.max(u/1e3,.01),e.far=t.maxDistance+s*4+r,e.updateProjectionMatrix(),t.target.copy(o),t.update()}var fe={x:256,y:256,z:256};function pe(){return new Promise(e=>setTimeout(e,0))}var me=2e4,he=2e4;function ge(e){let t=new G;if(!e)return t;let n=e.trim().split(/\s+/).map(parseFloat);return n.length>=12&&t.set(n[0],n[1],n[2],n[9],n[3],n[4],n[5],n[10],n[6],n[7],n[8],n[11],0,0,0,1),t}var _e=ge;async function ve(e,t=0){let n=[],r=e.getElementsByTagName(`mesh`);for(let e=0;e0&&e%me===0&&await pe()}let c=i.getElementsByTagName(`triangle`);for(let e=0;e0&&e%he===0&&await pe()}a.length>0&&o.length>0&&n.push({vertices:a,triangles:o,extruder:t})}return n}function ye(e){let t=Array.from(e.attributes).find(e=>{let t=e.name.toLowerCase();return t===`plate_id`||t===`plater_id`||t===`plateid`||t===`platerid`||t.endsWith(`:plate_id`)||t.endsWith(`:plater_id`)});if(!t?.value)return null;let n=Number.parseInt(t.value,10);return Number.isFinite(n)?n:null}async function be(e){let t;try{t=await ie.default.loadAsync(e)}catch{throw Error(`Unsupported file format`)}let n=new Map,r=[],i=new Map,a=new Map,o=new DOMParser;async function s(e){let n=e.startsWith(`/`)?e.slice(1):e,r=t.files[n];if(!r)return null;let i=await r.async(`string`);return o.parseFromString(i,`application/xml`)}let c=new Map,l=new Map,u=new Map,d=new Map,f=t.files[`Metadata/model_settings.config`];if(f)try{let e=await f.async(`string`),t=o.parseFromString(e,`application/xml`),n=t.getElementsByTagName(`object`);for(let e=0;ee.tagName===`metadata`&&e.getAttribute(`key`)===`extruder`);if(i.length>0){let e=i[0].getAttribute(`value`);e&&c.set(r,Math.max(0,parseInt(e,10)-1))}let a=Array.from(t.children).find(e=>e.tagName===`metadata`&&e.getAttribute(`key`)===`name`)?.getAttribute(`value`);a&&u.set(r,a);let o=t.getElementsByTagName(`part`);for(let e=0;ee.tagName===`metadata`&&e.getAttribute(`key`)===`extruder`);if(i.length>0){let e=i[0].getAttribute(`value`);e&&l.set(`${r}:${n}`,Math.max(0,parseInt(e,10)-1))}}}let r=t.getElementsByTagName(`plate`);for(let e=0;ee.startsWith(`Metadata/plate_`)&&e.endsWith(`.json`));for(let e of m){let n=e.match(/^Metadata\/plate_(\d+)\.json$/);if(!n)continue;let r=Number.parseInt(n[1],10);if(Number.isFinite(r))try{let n=await t.files[e].async(`string`),a=JSON.parse(n),o=a.bbox_objects??[];for(let e of o)e?.name&&p.set(e.name,r);if(Array.isArray(a.bbox_all)&&a.bbox_all.length>=4){let[e,t,n,o]=a.bbox_all;[e,t,n,o].every(e=>Number.isFinite(e))&&i.set(r,{minX:e,minY:t,maxX:n,maxY:o})}}catch{}}let h=Object.keys(t.files).find(e=>e===`3D/3dmodel.model`||e.endsWith(`/3dmodel.model`));if(!h){let e=Object.keys(t.files).find(e=>e.endsWith(`.model`));if(e){let t=await s(e);if(t){let e=await ve(t,0);e.length>0&&n.set(`1`,{id:`1`,meshes:e,defaultExtruder:0})}}return{objects:n,buildItems:r,plateBounds:i,plateOffsets:a}}let g=await s(h);if(!g)return{objects:n,buildItems:r,plateBounds:i,plateOffsets:a};let _=g.getElementsByTagName(`object`);for(let e=0;e<_.length;e++){e>0&&await pe();let t=_[e],r=t.getAttribute(`id`);if(!r)continue;let i=ye(t)??d.get(r)??null,a=c.get(r)??-1;if(a<0){let e=t.getAttribute(`p:extruder`)||t.getAttributeNS(`http://schemas.microsoft.com/3dmanufacturing/production/2015/06`,`extruder`)||`1`;a=Math.max(0,parseInt(e,10)-1)}let o=[],u=t.getElementsByTagName(`mesh`);for(let e=0;e0&&e%me===0&&await pe()}let s=t.getElementsByTagName(`triangle`);for(let e=0;e0&&e%he===0&&await pe()}n.length>0&&r.length>0&&o.push({vertices:n,triangles:r,extruder:a})}let f=t.getElementsByTagName(`component`);for(let e=0;e0&&n.set(r,{id:r,meshes:o,defaultExtruder:a,plateId:i})}let v=g.getElementsByTagName(`build`);if(v.length>0){let e=v[0].getElementsByTagName(`item`);for(let t=0;t{if(e instanceof J)if(e.geometry.dispose(),Array.isArray(e.material))for(let t of e.material)t.dispose();else e.material.dispose()})}function Ce(e,t,n){let{objects:r,buildItems:i}=e,a=new R,o=e=>new E({color:new L(n?.[e]||`#00ae42`),roughness:.62,metalness:0,envMapIntensity:.55,flatShading:!1}),s=new Map,c=i.some(e=>e.plateId!=null),l=t==null||!c?i:i.filter(e=>e.plateId===t),u=l.length>0?l:i;if(u.length>0)for(let e of u){let t=r.get(e.objectId);if(t)for(let n of t.meshes){let t=e.extruder??n.extruder,r=[];for(let t=0;t1)for(let e of t)e.dispose()}return a}function we(e,t){let n=new R,r=t?.[0]||`#00ae42`;for(let t of e){let e=new j;e.setAttribute(`position`,new U(t.positions,3)),t.normals&&e.setAttribute(`normal`,new U(t.normals,3)),t.indices&&e.setIndex(new U(t.indices,1)),t.normals||e.computeVertexNormals(),e.rotateX(-Math.PI/2);let i=new J(e,new E({color:t.color?new L(t.color[0],t.color[1],t.color[2]):new L(r),roughness:.62,metalness:0,envMapIntensity:.55}));i.castShadow=!0,n.add(i)}return n}function Te({url:e,fileType:t,buildVolume:n=fe,filamentColors:r,selectedPlateId:i=null,className:a=``,onSnapshot:c}){let{t:l}=s(),u=(0,Y.useRef)(null),f=(0,Y.useRef)(null),_=(0,Y.useRef)(null),v=(0,Y.useRef)(null),y=(0,Y.useRef)(null),b=(0,Y.useRef)(null),S=(0,Y.useRef)(null),C=(0,Y.useRef)(null),w=(0,Y.useRef)(null),O=(0,Y.useRef)(null),j=(0,Y.useRef)(null),M=(0,Y.useRef)(null),N=(0,Y.useRef)(null),[P,F]=(0,Y.useState)(!0),[B,U]=(0,Y.useState)(null),[G,q]=(0,Y.useState)(null),[X,te]=(0,Y.useState)(null),[Z,ie]=(0,Y.useState)(null),[ae,oe]=(0,Y.useState)(0),$=(t||e.split(`?`)[0].split(`.`).pop()||``).toLowerCase(),se=$===`step`||$===`stp`;(0,Y.useEffect)(()=>{if(!P||!se)return;oe(0);let e=Date.now(),t=window.setInterval(()=>{oe(Math.floor((Date.now()-e)/1e3))},1e3);return()=>window.clearInterval(t)},[P,se]);let ce=(0,Y.useRef)(!1),ue=(0,Y.useRef)(c);(0,Y.useEffect)(()=>{ue.current=c}),(0,Y.useEffect)(()=>{if(!u.current)return;let r=u.current,i=r.clientWidth,a=r.clientHeight,s=new T;s.background=new L(1710618),_.current=s;let c=new K(45,i/a,.1,1e4);c.position.set(150,150,150),v.current=c;let d=new H({antialias:!0});d.setSize(i,a),d.setPixelRatio(Math.min(window.devicePixelRatio,2)),d.toneMapping=4,d.toneMappingExposure=.85,d.shadowMap.enabled=!0,d.shadowMap.type=2,r.appendChild(d.domElement),f.current=d;let p=new ee(c,d.domElement);p.enableDamping=!0,p.dampingFactor=.05,w.current=p;let m=new z(d),h=m.fromScene(new re,.04);s.environment=h.texture,y.current=m,b.current=h.texture;let g=new W(16777215,.75);g.position.set(60,260,90),g.castShadow=!0,g.shadow.mapSize.set(2048,2048),g.shadow.bias=-5e-4,g.shadow.normalBias=.02;let x=Math.max(n.x,n.y)*.75;g.shadow.camera.left=-x,g.shadow.camera.right=x,g.shadow.camera.top=x,g.shadow.camera.bottom=-x,g.shadow.camera.near=1,g.shadow.camera.far=x*6,g.shadow.camera.updateProjectionMatrix(),s.add(g),S.current=g;let E=Math.max(n.x,n.y),k=new V(E,Math.ceil(E/16),4473924,3355443);s.add(k),M.current=k;let N=new J(new D(n.x,n.y),new A({color:44610,transparent:!0,opacity:.15,side:2}));N.rotation.x=-Math.PI/2,N.position.y=-.5,s.add(N),j.current=N;let P=new J(new D(n.x,n.y),new I({opacity:.22}));P.rotation.x=-Math.PI/2,P.position.y=-.49,P.receiveShadow=!0,s.add(P),C.current=P;let R,B=()=>{R=requestAnimationFrame(B),p.update(),d.render(s,c)};B(),F(!0),U(null),q(null),te(null),ie(null),ce.current=!1;let G=(t||e.split(`?`)[0].split(`.`).pop()||``).toLowerCase(),Y={},X=o();X&&(Y.Authorization=`Bearer ${X}`),G===`stl`?fetch(e,{headers:Y}).then(e=>{if(!e.ok)throw Error(l(`modelViewer.errors.failedToLoad`));return e.arrayBuffer()}).then(e=>{let t=new ne().parse(e);t.computeVertexNormals(),t.rotateX(-Math.PI/2),te(t)}).catch(e=>{U(e.message),F(!1)}):G===`3mf`?fetch(e,{headers:Y}).then(e=>{if(!e.ok)throw Error(l(`modelViewer.errors.failedToLoad`));return e.arrayBuffer()}).then(be).then(e=>{if(e.objects.size===0)throw Error(l(`modelViewer.errors.noMeshes`));q(e)}).catch(e=>{U(e.message),F(!1)}):G===`step`||G===`stp`?fetch(e,{headers:Y}).then(e=>{if(!e.ok)throw Error(l(`modelViewer.errors.failedToLoad`));return e.arrayBuffer()}).then(le).then(ie).catch(e=>{U(e.message===`no-meshes`?l(`modelViewer.errors.noMeshes`):e.message===`error`?l(`modelViewer.errors.failedToLoad`):e.message),F(!1)}):(U(l(`modelViewer.errors.unsupportedFormat`)),F(!1));let Z=()=>{if(!r)return;let e=r.clientWidth,t=r.clientHeight;e===0||t===0||(c.aspect=e/t,c.updateProjectionMatrix(),d.setSize(e,t))};window.addEventListener(`resize`,Z),document.addEventListener(`fullscreenchange`,Z);let Q=new ResizeObserver(()=>{Z()});return Q.observe(r),()=>{window.removeEventListener(`resize`,Z),document.removeEventListener(`fullscreenchange`,Z),Q.disconnect(),cancelAnimationFrame(R),p.dispose(),b.current?.dispose(),b.current=null,y.current?.dispose(),y.current=null,s.environment=null,d.dispose(),r.removeChild(d.domElement),O.current=null,j.current=null,M.current=null,S.current=null,C.current=null}},[e,n,t,l]),(0,Y.useEffect)(()=>{if(!_.current||!v.current||!w.current||!G&&!X&&!Z)return;O.current&&(_.current.remove(O.current),Se(O.current));let e=!!X||!!Z,t=X?(()=>{let e=new J(X,new E({color:new L(r?.[0]||`#00ae42`),roughness:.62,metalness:0,envMapIntensity:.55}));e.castShadow=!0;let t=new R;return t.add(e),t})():Z?we(Z,r):Ce(G,i??null,r);O.current=t,_.current.add(t);let a=new k().setFromObject(t),o=a.getCenter(new x);t.position.y=-a.min.y;let s=!e&&i!=null&&G.buildItems.length>0?G.plateBounds.get(i):void 0,c=!e&&i!=null?G.plateOffsets.get(i):void 0,l=e||G.buildItems.length===0||i!=null&&!s&&!c,u=l?-o.x:0,d=l?-o.z:0,p=0,m=0;if(!e&&i!=null&&G.buildItems.length>0&&s){let e=new k().setFromObject(t);p=e.min.x-s.minX,m=e.min.z-s.minY}let h=n.x/2,g=n.y/2;!e&&i!=null&&G.buildItems.length>0&&s?(t.position.x=u-p,t.position.z=d-m):!e&&i!=null&&c?(t.position.x=u+(h-c.offsetX),t.position.z=d+(g-c.offsetY)):l?(t.position.x=u+h,t.position.z=d+g):(t.position.x=u,t.position.z=d),j.current&&(j.current.position.x=h,j.current.position.z=g),M.current&&(M.current.position.x=h,M.current.position.z=g),C.current&&(C.current.position.x=h,C.current.position.z=g);let y=new k().setFromObject(t);N.current=y,de(v.current,w.current,y,Math.hypot(n.x,n.y)),F(!1),ue.current&&!ce.current&&(ce.current=!0,requestAnimationFrame(()=>{let e=f.current,t=_.current,n=v.current;if(!(!e||!t||!n))try{e.render(t,n);let r=e.domElement,i=Math.min(r.width,r.height),a=document.createElement(`canvas`);a.width=256,a.height=256;let o=a.getContext(`2d`);if(!o)return;o.drawImage(r,(r.width-i)/2,(r.height-i)/2,i,i,0,0,256,256),a.toBlob(e=>{e&&ue.current?.(e)},`image/png`)}catch{}}))},[G,X,Z,i,r,n]);let pe=()=>{let e=v.current,t=w.current;!e||!t||(N.current?de(e,t,N.current,Math.hypot(n.x,n.y)):(e.position.set(150,150,150),t.target.set(0,50,0),t.update()))},me=e=>{let t=v.current,n=w.current;if(!t||!n)return;let r=t.position.clone().sub(n.target),i=Math.min(n.maxDistance,Math.max(n.minDistance,r.length()*e));t.position.copy(n.target).addScaledVector(r.normalize(),i),n.update()};return(0,Q.jsxs)(`div`,{className:`relative ${a}`,children:[(0,Q.jsx)(`div`,{ref:u,className:`w-full h-full min-h-[400px]`}),P&&(0,Q.jsxs)(`div`,{className:`absolute inset-0 flex flex-col items-center justify-center gap-3 bg-bambu-dark/80 px-6 text-center`,children:[(0,Q.jsx)(d,{className:`w-8 h-8 text-bambu-green animate-spin`}),se&&(0,Q.jsxs)(`div`,{role:`status`,className:`space-y-1`,children:[(0,Q.jsx)(`p`,{className:`text-sm text-white tabular-nums`,children:l(`modelViewer.stepConverting`,{seconds:ae})}),(0,Q.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:l(`modelViewer.stepSlowHint`)})]})]}),B&&(0,Q.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-bambu-dark/80`,children:(0,Q.jsx)(`p`,{className:`text-red-400`,children:B})}),!P&&!B&&(0,Q.jsxs)(`div`,{className:`absolute bottom-4 right-4 flex gap-2`,children:[(0,Q.jsx)(h,{variant:`secondary`,size:`sm`,onClick:()=>me(.8),children:(0,Q.jsx)(p,{className:`w-4 h-4`})}),(0,Q.jsx)(h,{variant:`secondary`,size:`sm`,onClick:()=>me(1.25),children:(0,Q.jsx)(m,{className:`w-4 h-4`})}),(0,Q.jsx)(h,{variant:`secondary`,size:`sm`,onClick:pe,children:(0,Q.jsx)(g,{className:`w-4 h-4`})})]})]})}function Ee({folderId:e,onClose:t,onUploadComplete:n,onFileUploaded:r,autoUpload:i,validateFile:o,accept:p,initialFiles:m}){let{t:g}=s(),[x,S]=(0,Y.useState)([]),[C,w]=(0,Y.useState)(!1),[T,E]=(0,Y.useState)(!1),[D,O]=(0,Y.useState)(!0),[k,A]=(0,Y.useState)(!1),[j,M]=(0,Y.useState)(!0),[N,P]=(0,Y.useState)(null),F=(0,Y.useRef)(null),I=e=>{e.preventDefault(),w(!0)},L=e=>{e.preventDefault(),w(!1)},R=e=>{e.preventDefault(),w(!1),H(Array.from(e.dataTransfer.files))},z=e=>{e.target.files&&H(Array.from(e.target.files))},B=(e,t)=>{S(n=>n.map(n=>n.file===e?{...n,...t}:n))},V=async i=>{E(!0);for(let t of i)if(t.status===`pending`){B(t.file,{status:`uploading`});try{if(t.isZip){let n=await a.extractZipFile(t.file,e,D,k,j);B(t.file,{status:n.errors.length>0&&n.extracted===0?`error`:`success`,extractedCount:n.extracted,error:n.errors.length>0?g(`fileManager.zipFilesFailed`,`{{count}} files failed`,{count:n.errors.length}):void 0})}else{let n=await a.uploadLibraryFile(t.file,e,j);B(t.file,{status:`success`});let i=r?.(n);if(i){P(i),S([]),E(!1);return}}}catch(e){B(t.file,{status:`error`,error:e instanceof Error?e.message:g(`fileManager.uploadFailed`,`Upload failed`)})}}E(!1),n(),S(e=>(e.some(e=>e.status===`error`)||t(),e))},H=e=>{if(P(null),o)for(let t of e){let e=o(t);if(e){P(e);return}}let t=e.map(e=>({file:e,status:`pending`,isZip:e.name.toLowerCase().endsWith(`.zip`),is3mf:e.name.toLowerCase().endsWith(`.3mf`)}));S(e=>[...e,...t]),i&&e.length>0&&V(t)},U=e=>{S(t=>t.filter((t,n)=>n!==e))},ee=(0,Y.useRef)(!1);(0,Y.useEffect)(()=>{ee.current||!m||m.length===0||(ee.current=!0,H(m))},[]);let W=x.some(e=>e.isZip&&e.status===`pending`),G=x.some(e=>e.file.name.toLowerCase().endsWith(`.stl`)&&e.status===`pending`),K=x.some(e=>e.is3mf&&e.status===`pending`),q=x.filter(e=>e.status===`pending`).length,J=x.length>0&&q===0&&!T;return(0,Q.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,Q.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-lg border border-bambu-dark-tertiary`,children:[(0,Q.jsxs)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary flex items-center justify-between`,children:[(0,Q.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:g(`fileManager.uploadFiles`)}),(0,Q.jsx)(`button`,{onClick:t,className:`p-1 hover:bg-bambu-dark rounded`,children:(0,Q.jsx)(f,{className:`w-5 h-5 text-bambu-gray`})})]}),(0,Q.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,Q.jsxs)(`div`,{onDragOver:I,onDragLeave:L,onDrop:R,onClick:()=>F.current?.click(),className:`border-2 border-dashed rounded-lg p-8 text-center cursor-pointer transition-colors ${C?`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary hover:border-bambu-green/50`}`,children:[(0,Q.jsx)(y,{className:`w-10 h-10 mx-auto mb-3 ${C?`text-bambu-green`:`text-bambu-gray`}`}),(0,Q.jsx)(`p`,{className:`text-white font-medium`,children:g(C?`fileManager.dropFilesHere`:`fileManager.dragDropFiles`)}),(0,Q.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:g(`fileManager.orClickToBrowse`)}),(0,Q.jsx)(`p`,{className:`text-xs text-bambu-gray/70 mt-2`,children:g(`fileManager.allFileTypesSupported`)})]}),(0,Q.jsx)(`input`,{ref:F,type:`file`,multiple:!0,accept:p,className:`hidden`,onChange:z}),W&&(0,Q.jsx)(`div`,{className:`p-3 bg-blue-50 dark:bg-blue-500/10 border border-blue-300 dark:border-blue-500/30 rounded-lg`,children:(0,Q.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,Q.jsx)(v,{className:`w-5 h-5 text-blue-600 dark:text-blue-400 mt-0.5 flex-shrink-0`}),(0,Q.jsxs)(`div`,{className:`flex-1`,children:[(0,Q.jsx)(`p`,{className:`text-sm text-blue-700 dark:text-blue-300 font-medium`,children:g(`fileManager.zipFilesDetected`)}),(0,Q.jsx)(`p`,{className:`text-xs text-blue-700/80 dark:text-blue-300/70 mt-1`,children:g(`fileManager.zipExtractOptions`)}),(0,Q.jsxs)(`label`,{className:`flex items-center gap-2 mt-2 cursor-pointer`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,checked:D,onChange:e=>O(e.target.checked),className:`w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,Q.jsx)(`span`,{className:`text-sm text-white`,children:g(`fileManager.preserveZipStructure`)})]}),(0,Q.jsxs)(`label`,{className:`flex items-center gap-2 mt-2 cursor-pointer`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,checked:k,onChange:e=>A(e.target.checked),className:`w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,Q.jsx)(`span`,{className:`text-sm text-white`,children:g(`fileManager.createFolderFromZip`)})]})]})]})}),K&&(0,Q.jsx)(`div`,{className:`p-3 bg-purple-50 dark:bg-purple-500/10 border border-purple-300 dark:border-purple-500/30 rounded-lg`,children:(0,Q.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,Q.jsx)(_,{className:`w-5 h-5 text-purple-600 dark:text-purple-400 mt-0.5 flex-shrink-0`}),(0,Q.jsxs)(`div`,{className:`flex-1`,children:[(0,Q.jsx)(`p`,{className:`text-sm text-purple-700 dark:text-purple-300 font-medium`,children:g(`fileManager.threemfDetected`)}),(0,Q.jsx)(`p`,{className:`text-xs text-purple-700/80 dark:text-purple-300/70 mt-1`,children:g(`fileManager.threemfExtractionInfo`)})]})]})}),(G||W)&&(0,Q.jsx)(`div`,{className:`p-3 bg-bambu-green/10 border border-bambu-green/30 rounded-lg`,children:(0,Q.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,Q.jsx)(b,{className:`w-5 h-5 text-bambu-green mt-0.5 flex-shrink-0`}),(0,Q.jsxs)(`div`,{className:`flex-1`,children:[(0,Q.jsx)(`p`,{className:`text-sm text-bambu-green font-medium`,children:g(`fileManager.stlThumbnailGeneration`)}),(0,Q.jsx)(`p`,{className:`text-xs text-bambu-green/70 mt-1`,children:g(W&&!G?`fileManager.zipMayContainStl`:`fileManager.thumbnailsCanBeGenerated`)}),(0,Q.jsxs)(`label`,{className:`flex items-center gap-2 mt-2 cursor-pointer`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,checked:j,onChange:e=>M(e.target.checked),className:`w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,Q.jsx)(`span`,{className:`text-sm text-white`,children:g(`fileManager.generateThumbnailsForStl`)})]})]})]})}),x.length>0&&(0,Q.jsx)(`div`,{className:`max-h-48 overflow-y-auto space-y-2`,children:x.map((e,t)=>(0,Q.jsxs)(`div`,{className:`flex items-center gap-3 p-2 bg-bambu-dark rounded-lg`,children:[e.isZip?(0,Q.jsx)(v,{className:`w-4 h-4 text-blue-600 dark:text-blue-400 flex-shrink-0`}):(0,Q.jsx)(u,{className:`w-4 h-4 text-bambu-gray flex-shrink-0`}),(0,Q.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Q.jsx)(`p`,{className:`text-sm text-white truncate`,children:e.file.name}),(0,Q.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[(e.file.size/1024/1024).toFixed(2),` MB`,e.isZip&&e.status===`pending`&&(0,Q.jsxs)(`span`,{className:`text-blue-700 dark:text-blue-400 ml-2`,children:[`• `,g(`fileManager.willBeExtracted`)]}),e.extractedCount!==void 0&&(0,Q.jsxs)(`span`,{className:`text-green-700 dark:text-green-400 ml-2`,children:[`• `,g(`fileManager.filesExtracted`,{count:e.extractedCount})]})]}),e.status===`error`&&e.error&&(0,Q.jsx)(`p`,{className:`text-xs text-red-700 dark:text-red-400 mt-1 break-words`,children:e.error})]}),e.status===`pending`&&(0,Q.jsx)(`button`,{onClick:()=>U(t),className:`p-1 hover:bg-bambu-dark-tertiary rounded`,children:(0,Q.jsx)(f,{className:`w-4 h-4 text-bambu-gray`})}),e.status===`uploading`&&(0,Q.jsx)(d,{className:`w-4 h-4 text-bambu-green animate-spin`}),e.status===`success`&&(0,Q.jsx)(l,{className:`w-4 h-4 text-green-500`}),e.status===`error`&&(0,Q.jsx)(`span`,{title:e.error,children:(0,Q.jsx)(c,{className:`w-4 h-4 text-red-500`})})]},t))}),N&&(0,Q.jsx)(`div`,{className:`p-3 bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30 rounded-lg`,children:(0,Q.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,Q.jsx)(c,{className:`w-5 h-5 text-red-600 dark:text-red-400 mt-0.5 flex-shrink-0`}),(0,Q.jsx)(`p`,{className:`text-sm text-red-700 dark:text-red-300`,children:N})]})})]}),(0,Q.jsxs)(`div`,{className:`p-4 border-t border-bambu-dark-tertiary flex justify-end gap-2`,children:[(0,Q.jsx)(h,{variant:`secondary`,onClick:t,children:g(`common.cancel`)}),!J&&(0,Q.jsx)(h,{onClick:()=>V(x),disabled:q===0||T,children:T?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(d,{className:`w-4 h-4 mr-2 animate-spin`}),g(`fileManager.uploading`)]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(y,{className:`w-4 h-4 mr-2`}),g(`common.upload`),` `,q>0?`(${q})`:``]})})]})]})})}export{Te as n,Ee as t}; \ No newline at end of file diff --git a/static/assets/FinancePage-WsLEQ1fC.js b/static/assets/FinancePage-D-k9CqTS.js similarity index 99% rename from static/assets/FinancePage-WsLEQ1fC.js rename to static/assets/FinancePage-D-k9CqTS.js index f64845a9e..7f292cbe9 100644 --- a/static/assets/FinancePage-WsLEQ1fC.js +++ b/static/assets/FinancePage-D-k9CqTS.js @@ -1 +1 @@ -import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,w as ee}from"./client-DnySrlFv.js";import{n as te}from"./QueryClientProvider-Ce8_sN3w.js";import{t as i}from"./useQuery-BBCjCezC.js";import{t as a}from"./useMutation-B-Tr2hIP.js";import{t as o}from"./createLucideIcon-DvBYJlWL.js";import{n as ne,t as re}from"./chevrons-right-DTJgqnxZ.js";import{n as ie}from"./ToastContext-BRX0SW3C.js";import{i as s,n as c,t as l}from"./Card-Bzc64K35.js";import{t as u}from"./Button-DDr6eAFy.js";import{v as d}from"./date-G9KUauqz.js";import{$t as ae,At as oe,Mn as se,_t as ce,at as le,jn as ue,yt as de}from"./index-0t--Yqoi.js";var fe=o(`building-2`,[[`path`,{d:`M10 12h4`,key:`a56b0p`}],[`path`,{d:`M10 8h4`,key:`1sr2af`}],[`path`,{d:`M14 21v-3a2 2 0 0 0-4 0v3`,key:`1rgiei`}],[`path`,{d:`M6 10H4a2 2 0 0 0-2 2v7a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V9a2 2 0 0 0-2-2h-2`,key:`secmi2`}],[`path`,{d:`M6 21V5a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v16`,key:`16ra0t`}]]),pe=o(`clock-3`,[[`path`,{d:`M12 6v6h4`,key:`135r8i`}],[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}]]),me=o(`wallet`,[[`path`,{d:`M19 7V4a1 1 0 0 0-1-1H5a2 2 0 0 0 0 4h15a1 1 0 0 1 1 1v4h-3a2 2 0 0 0 0 4h3a1 1 0 0 0 1-1v-2a1 1 0 0 0-1-1`,key:`18etb6`}],[`path`,{d:`M3 5v14a2 2 0 0 0 2 2h15a1 1 0 0 0 1-1v-4`,key:`xoc0q4`}]]),f=e(n(),1),p=t(),m=/\[(aborted|failed|cancelled):\s*([^\]]*)\]/i;function he(e){if(!e)return{isPartial:!1,partialType:null,cleanedDescription:null};let t=e.match(m);if(!t)return{isPartial:!1,partialType:null,cleanedDescription:e};let n=e.replace(t[0],``).trim();return{isPartial:!0,partialType:t[1].toLowerCase(),cleanedDescription:n||null}}function ge(e,t){if(!e)return`-`;let n=d(e);return n?n.toLocaleString(t):e}function h(e){let t=e.trim();if(!t)return null;let n=Number.parseFloat(t);return Number.isFinite(n)?n:null}function _e(e){return`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,`0`)}-${String(e.getDate()).padStart(2,`0`)}T${String(e.getHours()).padStart(2,`0`)}:${String(e.getMinutes()).padStart(2,`0`)}`}var g=`w-full px-3 py-2 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded text-white placeholder-bambu-gray focus:outline-none focus:ring-1 focus:ring-bambu-green`,_=`block text-sm font-medium text-white mb-1`,v=`px-4 py-3 text-left text-bambu-gray font-medium`,y=`px-4 py-3 align-top text-white`;function b({title:e,onClose:t,children:n,size:r=`md`}){let{t:te}=ee();return(0,p.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/70 p-4`,children:(0,p.jsxs)(`div`,{className:`w-full ${r===`sm`?`max-w-xl`:r===`lg`?`max-w-6xl`:`max-w-4xl`} overflow-hidden rounded-lg border border-bambu-dark-tertiary bg-bambu-dark-secondary`,children:[(0,p.jsxs)(`div`,{className:`flex items-center justify-between border-b border-bambu-dark-tertiary px-4 py-3`,children:[(0,p.jsx)(`h3`,{className:`text-lg font-semibold text-white`,children:e}),(0,p.jsx)(u,{size:`sm`,variant:`secondary`,onClick:t,children:te(`common.close`,`Close`)})]}),(0,p.jsx)(`div`,{className:`max-h-[75vh] overflow-auto p-4`,children:n})]})})}function x(){let{t:e,i18n:t}=ee(),{hasPermission:n,user:o}=de(),{showToast:d}=ie(),m=te(),x=n(`cost_centers:read_own`),S=n(`cost_centers:read_all`),C=n(`cost_centers:create`),w=n(`cost_centers:modify`),T=n(`cost_centers:modify`),E=n(`cost_centers:modify`),D=n(`cost_centers:modify`),O=n(`users:read_slim`)||n(`users:read`),ve=S||C||w||T||E||D,ye=x||ve,be=ye,[xe,Se]=(0,f.useState)(``),[k,Ce]=(0,f.useState)(`monthly`),[we,Te]=(0,f.useState)(``),[A,Ee]=(0,f.useState)(null),[De,Oe]=(0,f.useState)(`deposit`),[ke,Ae]=(0,f.useState)(``),[je,Me]=(0,f.useState)(``),[Ne,Pe]=(0,f.useState)(null),[j,M]=(0,f.useState)(null),[Fe,Ie]=(0,f.useState)(null),[Le,Re]=(0,f.useState)(!0),[N,P]=(0,f.useState)(0),[F,ze]=(0,f.useState)(`all`),[I,Be]=(0,f.useState)(`all`),[Ve,He]=(0,f.useState)(!1),[Ue,We]=(0,f.useState)(!1),[Ge,Ke]=(0,f.useState)(!1),[L,qe]=(0,f.useState)(!1),[R,Je]=(0,f.useState)(`personal`),[z,Ye]=(0,f.useState)(null),[Xe,Ze]=(0,f.useState)(``),[Qe,B]=(0,f.useState)(`monthly`),[$e,V]=(0,f.useState)(``),[et,tt]=(0,f.useState)(!1),[nt,rt]=(0,f.useState)(null),[it,at]=(0,f.useState)(null),[ot,st]=(0,f.useState)(null),[ct,lt]=(0,f.useState)(``),[ut,dt]=(0,f.useState)(``),[ft,H]=(0,f.useState)(!1),[pt,mt]=(0,f.useState)(null),[ht,gt]=(0,f.useState)(null),[_t,vt]=(0,f.useState)(``),[yt,bt]=(0,f.useState)(``),[xt,St]=(0,f.useState)(_e(new Date)),[U,Ct]=(0,f.useState)(null),[wt,Tt]=(0,f.useState)(null),W=S||C||w||T||D&&O||E&&O;(0,f.useEffect)(()=>{W||Je(`personal`)},[W]);let{data:Et,isLoading:Dt}=i({queryKey:[`finance`,`me`,`balance`],queryFn:r.getMyBalance,enabled:x}),{data:Ot}=i({queryKey:[`ui-flags`],queryFn:r.getUiFlags}),{data:kt,isLoading:At}=i({queryKey:[`finance`,`me`,`transactions`,50,N],queryFn:()=>r.getMyTransactions(50,N),enabled:x}),{data:jt,isLoading:Mt}=i({queryKey:[`finance`,`transactions`,50,N],queryFn:()=>r.getAllTransactions(50,N),enabled:R===`admin`&&S}),{data:G,isLoading:K}=i({queryKey:[`finance`,`cost-centers`,R],queryFn:()=>R===`admin`&&ve?r.listCostCenters(!0):r.getMyCostCenters(),enabled:be}),{data:q}=i({queryKey:[`users`,`slim`],queryFn:r.getUsersSlim,enabled:O&&(be||D||E)}),{data:J}=i({queryKey:[`finance`,`cost-center`,j],queryFn:()=>r.getCostCenter(j),enabled:E&&j!=null});(0,f.useEffect)(()=>{!q||q.length===0||A!=null&&q.some(e=>e.id===A)||Ee(q[0].id)},[q,A]),(0,f.useEffect)(()=>{if(!E)return;let e=(G||[]).filter(e=>!e.is_private);if(e.length===0){M(null);return}j!=null&&e.some(e=>e.id===j)||M(e[0].id)},[E,G,j]),(0,f.useEffect)(()=>{if(!E||!q||q.length===0)return;let e=new Set((J?.members||[]).map(e=>e.user_id)),t=q.find(t=>!e.has(t.id));Ie(t?t.id:null)},[E,q,J]),(0,f.useEffect)(()=>{if(!L)return;let e=G||[];if(e.length===0){Ye(null);return}z!=null&&e.some(e=>e.id===z)||Ye(e[0].id)},[L,z,G]),(0,f.useEffect)(()=>{if(!L||z==null)return;let e=(G||[]).find(e=>e.id===z);if(e){if(Ze(e.name),e.budget_mode===`total`){B(`total`),V(e.total_budget==null?``:String(e.total_budget));return}B(`monthly`),V(e.monthly_budget==null?``:String(e.monthly_budget))}},[L,z,G]);let Nt=a({mutationFn:()=>r.createCostCenter({name:xe.trim(),total_budget:k===`total`?h(we):null,monthly_budget:k===`monthly`?h(we):null,is_active:!0}),onSuccess:()=>{m.invalidateQueries({queryKey:[`finance`]}),Se(``),Te(``),d(e(`finance.createdCostCenter`,`Cost center created`))},onError:t=>{d(t.message||e(`finance.createCostCenterFailed`,`Failed to create cost center`),`error`)}}),Pt=a({mutationFn:({costCenterId:e,value:t,mode:n})=>r.updateCostCenterBudgets(e,{total_budget:n===`total`?h(t):null,monthly_budget:n===`monthly`?h(t):null})}),Ft=a({mutationFn:({costCenterId:e,name:t})=>r.updateCostCenter(e,{name:t})}),It=a({mutationFn:e=>r.deleteCostCenter(e)}),Lt=a({mutationFn:e=>r.deleteTransaction(e),onSuccess:()=>{m.invalidateQueries({queryKey:[`finance`]}),d(e(`finance.transactionDeleted`,`Transaction deleted`))},onError:t=>{d(t.message||e(`finance.deleteTransactionFailed`,`Failed to delete transaction`),`error`)}}),Rt=a({mutationFn:e=>r.editTransaction(e.transactionId,e.data),onSuccess:()=>{m.invalidateQueries({queryKey:[`finance`]}),d(e(`finance.transactionEdited`,`Transaction updated and ledger recalculated`)),tt(!1)},onError:t=>{d(t.message||e(`finance.editTransactionFailed`,`Failed to edit transaction`),`error`)}}),zt=a({mutationFn:e=>r.createManualPrint(e),onSuccess:()=>{m.invalidateQueries({queryKey:[`finance`]}),d(e(`finance.manualPrintCreated`,`Manual print charge added and ledger recalculated`)),H(!1),mt(null),gt(null),vt(``),bt(``),St(_e(new Date))},onError:t=>{d(t.message||e(`finance.manualPrintFailed`,`Failed to create manual print`),`error`)}}),Bt=a({mutationFn:e=>r.depositUserBalance(e.userId,{amount:e.amount,description:e.description,cost_center_id:e.costCenterId??null})}),Vt=a({mutationFn:e=>r.withdrawUserBalance(e.userId,{amount:e.amount,description:e.description,cost_center_id:e.costCenterId??null})}),Ht=a({mutationFn:e=>r.upsertCostCenterMember(e.costCenterId,{user_id:e.userId,can_print:e.canPrint}),onSuccess:()=>{m.invalidateQueries({queryKey:[`finance`]}),d(e(`finance.memberSaved`,`Member saved`))},onError:t=>{d(t.message||e(`finance.memberSaveFailed`,`Failed to save member`),`error`)}}),Ut=a({mutationFn:e=>r.removeCostCenterMember(e.costCenterId,e.userId),onSuccess:()=>{m.invalidateQueries({queryKey:[`finance`]}),d(e(`finance.memberRemoved`,`Member removed`))},onError:t=>{d(t.message||e(`finance.memberRemoveFailed`,`Failed to remove member`),`error`)}}),Wt=Bt.isPending||Vt.isPending,Gt=()=>{if(!xe.trim()){d(e(`finance.costCenterNameRequired`,`Cost center name is required`),`error`);return}Nt.mutate()},Kt=async()=>{if(z==null){d(e(`finance.selectCostCenter`,`Please select a cost center`),`error`);return}let t=Xe.trim();if(!t){d(e(`finance.costCenterNameRequired`,`Cost center name is required`),`error`);return}try{w&&await Ft.mutateAsync({costCenterId:z,name:t}),T&&await Pt.mutateAsync({costCenterId:z,mode:Qe,value:$e}),m.invalidateQueries({queryKey:[`finance`]}),d(e(`finance.costCenterUpdated`,`Cost center updated`)),qe(!1)}catch(t){d(t.message||e(`finance.costCenterUpdateFailed`,`Failed to update cost center`),`error`)}},qt=e=>{let t=(G||[]).find(t=>t.id===e);t&&(Ye(t.id),Ze(t.name),t.budget_mode===`total`?(B(`total`),V(t.total_budget==null?``:String(t.total_budget))):(B(`monthly`),V(t.monthly_budget==null?``:String(t.monthly_budget))),qe(!0))},Jt=async()=>{if(U)try{await It.mutateAsync(U.id),m.invalidateQueries({queryKey:[`finance`]}),j===U.id&&M(null),d(e(`finance.costCenterDeleted`,`Cost center deleted`))}catch(t){d(t.message||e(`finance.costCenterDeleteFailed`,`Failed to delete cost center`),`error`)}finally{Ct(null)}},Yt=()=>{wt!=null&&Lt.mutate(wt,{onSettled:()=>Tt(null)})},Xt=e=>{rt(e.id),at(e.user_id),st(e.cost_center_id),lt(String(e.amount)),dt(e.description||``),tt(!0)},Zt=async()=>{if(nt==null)return;let t=ct?Number.parseFloat(ct):null;if(t!==null&&!Number.isFinite(t)){d(e(`finance.amountInvalid`,`Amount must be a valid number`),`error`);return}Rt.mutate({transactionId:nt,data:{user_id:it||void 0,cost_center_id:ot||void 0,amount:t??void 0,description:ut||void 0}})},Qt=async()=>{if(pt==null){d(e(`finance.userRequired`,`Please select a user`),`error`);return}if(ht==null){d(e(`finance.costCenterRequired`,`Please select a cost center`),`error`);return}let t=_t?Number.parseFloat(_t):null;if(t===null||!Number.isFinite(t)){d(e(`finance.amountInvalid`,`Amount must be a valid number`),`error`);return}t=Math.abs(t),zt.mutate({user_id:pt,cost_center_id:ht,amount:t,description:yt||void 0,created_at:xt?new Date(xt).toISOString():void 0})},$t=async()=>{if(A==null){d(e(`finance.userRequired`,`Please select a user`),`error`);return}let t=Number.parseFloat(ke);if(!Number.isFinite(t)||t<=0){d(e(`finance.amountMustBePositive`,`Amount must be greater than zero`),`error`);return}let n={userId:A,amount:t,description:je.trim()||void 0,costCenterId:Ne};try{De===`deposit`?await Bt.mutateAsync(n):await Vt.mutateAsync(n),m.invalidateQueries({queryKey:[`finance`]}),Ae(``),Me(``),d(De===`deposit`?e(`finance.depositSuccess`,`Deposit successful`):e(`finance.withdrawSuccess`,`Withdrawal successful`))}catch(t){d(t.message||e(`finance.adjustmentFailed`,`Wallet adjustment failed`),`error`)}},en=()=>{if(j==null){d(e(`finance.selectCostCenter`,`Please select a cost center`),`error`);return}if(Fe==null){d(e(`finance.noEligibleUsers`,`No eligible users available`),`error`);return}Ht.mutate({costCenterId:j,userId:Fe,canPrint:Le})},tn=e=>{j!=null&&Ut.mutate({costCenterId:j,userId:e})},Y=le(Ot?.currency||`USD`),X=(0,f.useMemo)(()=>[...q||[]].sort((e,t)=>e.username.localeCompare(t.username)),[q]),nn=(0,f.useMemo)(()=>{let e=new Map;for(let t of X)e.set(t.id,t.username);return e},[X]),rn=(0,f.useMemo)(()=>{let e=new Set((J?.members||[]).map(e=>e.user_id));return X.filter(t=>!e.has(t.id))},[X,J]),an=R===`admin`&&S?jt:kt,Z=R===`admin`&&S?Mt:At,Q=(0,f.useMemo)(()=>an?.items??[],[an?.items]),on=an?.total??0,sn=Math.max(1,Math.ceil(on/50)),cn=(0,f.useMemo)(()=>Q.filter(e=>!(F!==`all`&&e.transaction_type!==F||I!==`all`&&e.cost_center_id!==I)),[Q,F,I]),ln=Math.floor(N/50)+1,$=R===`admin`,un=t=>t===`deposit`?e(`finance.deposit`):t===`withdraw`?e(`finance.withdraw`):t===`print_charge`?e(`finance.printCharge`):t,dn=t=>t==null?e(`finance.personal`,`Personal`):nn.get(t)||(o?.id===t&&o.username?o.username:e(`finance.userWithId`,`User #{{id}}`,{id:t})),fn=t=>t.budget_limit==null||t.budget_available==null?e(`finance.unlimited`,`Unlimited`):`${Y}${t.budget_available.toFixed(2)}/${Y}${t.budget_limit.toFixed(2)}`;return ye?(0,p.jsxs)(`div`,{className:`p-4 md:p-8 space-y-8`,children:[(0,p.jsxs)(`div`,{className:`flex flex-col gap-4 lg:flex-row lg:items-start lg:justify-between`,children:[(0,p.jsxs)(`div`,{children:[(0,p.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,p.jsx)(me,{className:`h-6 w-6 text-bambu-green`}),(0,p.jsx)(`h1`,{className:`text-2xl font-bold text-white`,children:e(`finance.title`,`Finance`)})]}),(0,p.jsx)(`p`,{className:`text-bambu-gray mt-2 max-w-2xl`,children:e(`finance.subtitle`,`Wallet, personal transactions, and cost centers`)}),(0,p.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1 max-w-2xl`,children:e(`finance.budgetPolicyHint`,`Account balances track costs. Printing is limited only by the selected cost center budget; without a budget, printing is unlimited.`)})]}),(0,p.jsxs)(`div`,{className:`flex flex-col gap-2 lg:items-end`,children:[W&&(0,p.jsxs)(`div`,{className:`inline-flex overflow-hidden rounded border border-bambu-dark-tertiary`,children:[(0,p.jsx)(`button`,{type:`button`,onClick:()=>Je(`personal`),className:`px-3 py-1.5 text-sm ${R===`personal`?`bg-bambu-green text-black font-medium`:`bg-bambu-dark text-bambu-gray`}`,children:e(`finance.personalView`,`Personal view`)}),(0,p.jsx)(`button`,{type:`button`,onClick:()=>Je(`admin`),className:`px-3 py-1.5 text-sm ${R===`admin`?`bg-bambu-green text-black font-medium`:`bg-bambu-dark text-bambu-gray`}`,children:e(`finance.adminView`,`Admin view`)})]}),R===`admin`&&W&&(0,p.jsxs)(`div`,{className:`flex flex-wrap gap-2 lg:justify-end`,children:[C&&(0,p.jsx)(u,{size:`sm`,variant:`secondary`,onClick:()=>He(!0),children:e(`finance.createCostCenter`,`Create cost center`)}),D&&O&&(0,p.jsx)(u,{size:`sm`,variant:`secondary`,onClick:()=>We(!0),children:e(`finance.adjustWallet`,`Adjust wallet`)}),D&&O&&(0,p.jsx)(u,{size:`sm`,variant:`secondary`,onClick:()=>H(!0),children:e(`finance.addManualPrint`,`Add manual print`)}),E&&O&&(0,p.jsx)(u,{size:`sm`,variant:`secondary`,onClick:()=>Ke(!0),children:e(`finance.manageMembers`,`Manage cost center members`)})]})]})]}),(0,p.jsxs)(`div`,{className:`grid gap-5 md:grid-cols-2 xl:grid-cols-3`,children:[(0,p.jsxs)(l,{children:[(0,p.jsxs)(s,{className:`flex flex-row items-center justify-between pb-2`,children:[(0,p.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e(`finance.currentBalance`,`Personal account balance`)}),(0,p.jsx)(me,{className:`w-4 h-4 text-bambu-green/90`})]}),(0,p.jsx)(c,{className:`pt-1`,children:(0,p.jsx)(`p`,{className:`text-3xl font-semibold text-white leading-tight`,children:Dt?e(`common.loading`,`Loading...`):`${Y}${(Et?.balance??0).toFixed(2)}`})})]}),(0,p.jsxs)(l,{children:[(0,p.jsxs)(s,{className:`flex flex-row items-center justify-between pb-2`,children:[(0,p.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:R===`admin`?e(`finance.transactions`,`Transactions`):e(`finance.personalTransactions`,`Personal transactions`)}),(0,p.jsx)(pe,{className:`w-4 h-4 text-blue-400`})]}),(0,p.jsx)(c,{className:`pt-1`,children:(0,p.jsx)(`p`,{className:`text-3xl font-semibold text-white leading-tight`,children:Z?`-`:on})})]}),(0,p.jsxs)(l,{children:[(0,p.jsxs)(s,{className:`flex flex-row items-center justify-between pb-2`,children:[(0,p.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e(`finance.costCenters`,`Cost centers`)}),(0,p.jsx)(fe,{className:`w-4 h-4 text-orange-400`})]}),(0,p.jsx)(c,{className:`pt-1`,children:(0,p.jsx)(`p`,{className:`text-3xl font-semibold text-white leading-tight`,children:K?`-`:G?.length??0})})]})]}),Ve&&C&&(0,p.jsx)(b,{title:e(`finance.createCostCenter`,`Create cost center`),size:`md`,onClose:()=>He(!1),children:(0,p.jsxs)(`div`,{className:`space-y-4`,children:[(0,p.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-3`,children:[(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`finance.costCenterName`,`Name`)}),(0,p.jsx)(`input`,{type:`text`,value:xe,onChange:e=>Se(e.target.value),placeholder:e(`finance.costCenterName`,`Name`),className:g})]}),(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`finance.budgetType`,`Budget type`)}),(0,p.jsxs)(`select`,{value:k,onChange:e=>Ce(e.target.value),className:g,children:[(0,p.jsx)(`option`,{value:`monthly`,children:e(`finance.monthlyBudget`,`Monthly budget`)}),(0,p.jsx)(`option`,{value:`total`,children:e(`finance.totalBudget`,`Total budget`)})]})]}),(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:k===`monthly`?e(`finance.monthlyBudget`,`Monthly budget`):e(`finance.totalBudget`,`Total budget`)}),(0,p.jsx)(`input`,{type:`number`,step:`0.01`,value:we,onChange:e=>Te(e.target.value),placeholder:`0.00`,className:g})]})]}),(0,p.jsx)(u,{className:`min-w-[180px]`,onClick:Gt,disabled:Nt.isPending,children:Nt.isPending?e(`common.saving`,`Saving...`):e(`finance.create`,`Create`)})]})}),Ue&&D&&O&&(0,p.jsx)(b,{title:e(`finance.adjustWallet`,`Adjust wallet`),size:`md`,onClose:()=>We(!1),children:(0,p.jsxs)(`div`,{className:`space-y-4`,children:[(0,p.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`finance.selectUser`,`Select user`)}),(0,p.jsx)(`select`,{value:A??``,onChange:e=>Ee(e.target.value?Number(e.target.value):null),className:g,children:(X||[]).map(e=>(0,p.jsx)(`option`,{value:e.id,children:e.username},e.id))})]}),(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`finance.transactionType`,`Type`)}),(0,p.jsxs)(`select`,{value:De,onChange:e=>Oe(e.target.value),className:g,children:[(0,p.jsx)(`option`,{value:`deposit`,children:e(`finance.deposit`,`Deposit`)}),(0,p.jsx)(`option`,{value:`withdraw`,children:e(`finance.withdraw`,`Withdraw`)})]})]}),(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`finance.amount`,`Amount`)}),(0,p.jsx)(`input`,{type:`number`,step:`0.01`,min:`0`,value:ke,onChange:e=>Ae(e.target.value),placeholder:`0.00`,className:g})]}),(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`finance.costCenters`,`Cost centers`)}),(0,p.jsxs)(`select`,{value:Ne??``,onChange:e=>Pe(e.target.value?Number(e.target.value):null),className:g,children:[(0,p.jsx)(`option`,{value:``,children:e(`finance.noCostCenter`,`No cost center`)}),(G||[]).map(e=>(0,p.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]})]}),(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`common.description`,`Description`)}),(0,p.jsx)(`input`,{type:`text`,value:je,onChange:e=>Me(e.target.value),placeholder:e(`finance.descriptionOptional`,`Description (optional)`),className:g})]}),(0,p.jsx)(u,{className:`min-w-[180px]`,onClick:$t,disabled:Wt,children:Wt?e(`common.saving`,`Saving...`):e(`finance.applyAdjustment`,`Apply adjustment`)})]})}),Ge&&E&&O&&(0,p.jsx)(b,{title:e(`finance.manageMembers`,`Manage cost center members`),size:`lg`,onClose:()=>Ke(!1),children:(0,p.jsxs)(`div`,{className:`space-y-5`,children:[(0,p.jsxs)(`div`,{className:`grid gap-5 md:grid-cols-2`,children:[(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`finance.costCenters`,`Cost centers`)}),(0,p.jsx)(`select`,{value:j??``,onChange:e=>M(e.target.value?Number(e.target.value):null),className:g,children:(G||[]).filter(e=>!e.is_private).map(e=>(0,p.jsx)(`option`,{value:e.id,children:e.name},e.id))})]}),(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`finance.selectUser`,`Select user`)}),(0,p.jsxs)(`select`,{value:Fe??``,onChange:e=>Ie(e.target.value?Number(e.target.value):null),className:g,children:[(0,p.jsx)(`option`,{value:``,children:e(`finance.selectUser`,`Select user`)}),rn.map(e=>(0,p.jsx)(`option`,{value:e.id,children:e.username},e.id))]})]}),(0,p.jsxs)(`div`,{className:`flex items-center gap-2 rounded border border-bambu-dark-tertiary bg-bambu-dark-secondary px-3 py-2`,children:[(0,p.jsx)(`input`,{id:`memberCanPrint`,type:`checkbox`,checked:Le,onChange:e=>Re(e.target.checked),className:`rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,p.jsx)(`label`,{htmlFor:`memberCanPrint`,className:`text-sm text-bambu-gray`,children:e(`finance.memberCanPrint`,`Member can print`)})]}),(0,p.jsx)(`div`,{className:`flex items-end`,children:(0,p.jsx)(u,{className:`min-w-[180px]`,onClick:en,disabled:Ht.isPending||Fe==null,children:Ht.isPending?e(`common.saving`,`Saving...`):e(`finance.addMember`,`Add member`)})})]}),(0,p.jsx)(`div`,{className:`overflow-auto rounded-lg border border-bambu-dark-tertiary`,children:(0,p.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,p.jsx)(`thead`,{children:(0,p.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary bg-bambu-dark text-bambu-gray`,children:[(0,p.jsx)(`th`,{className:v,children:e(`common.name`,`Name`)}),(0,p.jsx)(`th`,{className:v,children:e(`finance.canPrint`,`Can print`)}),(0,p.jsx)(`th`,{className:v,children:e(`common.actions`,`Actions`)})]})}),(0,p.jsxs)(`tbody`,{children:[(J?.members||[]).map(t=>(0,p.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/60 text-white`,children:[(0,p.jsx)(`td`,{className:y,children:X.find(e=>e.id===t.user_id)?.username||`User ${t.user_id}`}),(0,p.jsx)(`td`,{className:y,children:t.can_print?e(`common.yes`,`Yes`):e(`common.no`,`No`)}),(0,p.jsx)(`td`,{className:y,children:(0,p.jsx)(u,{size:`sm`,variant:`danger`,onClick:()=>tn(t.user_id),disabled:Ut.isPending,children:e(`common.remove`,`Remove`)})})]},t.id)),(J?.members||[]).length===0&&(0,p.jsx)(`tr`,{children:(0,p.jsx)(`td`,{colSpan:3,className:`py-3 text-bambu-gray`,children:e(`finance.noMembers`,`No members assigned.`)})})]})]})})]})}),L&&(w||T)&&(0,p.jsx)(b,{title:e(`finance.editCostCenter`,`Edit cost center`),size:`md`,onClose:()=>qe(!1),children:(0,p.jsxs)(`div`,{className:`space-y-4`,children:[(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`finance.costCenterName`,`Name`)}),(0,p.jsx)(`input`,{type:`text`,value:Xe,onChange:e=>Ze(e.target.value),placeholder:e(`finance.costCenterName`,`Name`),className:g,disabled:!w})]}),(0,p.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`finance.budgetType`,`Budget type`)}),(0,p.jsxs)(`select`,{value:Qe,onChange:e=>B(e.target.value),className:g,disabled:!T,children:[(0,p.jsx)(`option`,{value:`monthly`,children:e(`finance.monthlyBudget`,`Monthly budget`)}),(0,p.jsx)(`option`,{value:`total`,children:e(`finance.totalBudget`,`Total budget`)})]})]}),(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:Qe===`monthly`?e(`finance.monthlyBudget`,`Monthly budget`):e(`finance.totalBudget`,`Total budget`)}),(0,p.jsx)(`input`,{type:`number`,step:`0.01`,value:$e,onChange:e=>V(e.target.value),placeholder:`0.00`,className:g,disabled:!T})]})]}),(0,p.jsx)(u,{className:`min-w-[180px]`,onClick:Kt,disabled:Ft.isPending||Pt.isPending||z==null,children:Ft.isPending||Pt.isPending?e(`common.saving`,`Saving...`):e(`common.save`,`Save`)})]})}),(0,p.jsxs)(`div`,{className:`grid gap-6 ${be&&x?`xl:grid-cols-2`:``}`,children:[be&&(0,p.jsxs)(l,{children:[(0,p.jsxs)(s,{children:[(0,p.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`finance.myCostCenters`,`My cost centers`)}),(0,p.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:e(`finance.costCentersHint`,`Review budget limits and keep costs under control`)})]}),(0,p.jsxs)(c,{className:`space-y-3`,children:[K&&(0,p.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`common.loading`,`Loading...`)}),!K&&(!G||G.length===0)&&(0,p.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`finance.noCostCenters`,`No cost centers found.`)}),!K&&G&&G.length>0&&(0,p.jsx)(`div`,{className:`overflow-auto rounded-lg border border-bambu-dark-tertiary`,children:(0,p.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,p.jsx)(`thead`,{children:(0,p.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary bg-bambu-dark text-bambu-gray`,children:[(0,p.jsx)(`th`,{className:v,children:e(`common.name`,`Name`)}),$&&(0,p.jsx)(`th`,{className:v,children:e(`finance.owner`,`Owner`)}),(0,p.jsx)(`th`,{className:v,children:e(`finance.balance`,`Account balance`)}),(0,p.jsx)(`th`,{className:v,children:e(`finance.budget`,`Budget`)}),$&&(0,p.jsx)(`th`,{className:v,children:e(`common.actions`,`Actions`)})]})}),(0,p.jsx)(`tbody`,{children:G.map(t=>{let n=w||T,r=!t.is_private&&w;return(0,p.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/60 text-white`,children:[(0,p.jsx)(`td`,{className:y,children:t.name}),$&&(0,p.jsx)(`td`,{className:y,children:t.is_private?dn(t.owner_user_id):e(`finance.shared`,`Shared`)}),(0,p.jsxs)(`td`,{className:y,children:[Y,t.total_balance.toFixed(2)]}),(0,p.jsx)(`td`,{className:y,children:(0,p.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[(0,p.jsx)(`span`,{children:fn(t)}),(0,p.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:t.budget_mode===`monthly`?e(`finance.monthlyBudget`,`Monthly budget`):t.budget_mode===`total`?e(`finance.totalBudget`,`Total budget`):e(`finance.noBudget`,`No budget`)})]})}),$&&(0,p.jsx)(`td`,{className:y,children:(0,p.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,p.jsx)(u,{size:`sm`,variant:`ghost`,onClick:()=>qt(t.id),disabled:!n,title:n?e(`common.edit`,`Edit`):e(`finance.cannotEditPrivateCostCenter`,`Private cost centers cannot be edited here`),className:`p-1.5 sm:p-2`,children:(0,p.jsx)(ae,{className:`w-4 h-4`})}),r&&(0,p.jsx)(u,{size:`sm`,variant:`ghost`,onClick:()=>Ct({id:t.id,name:t.name}),disabled:It.isPending,title:e(`common.delete`,`Delete`),className:`text-red-400 hover:text-red-300 hover:bg-red-500/10 p-1.5 sm:p-2`,children:(0,p.jsx)(oe,{className:`w-4 h-4`})})]})})]},t.id)})})]})})]})]}),x&&(0,p.jsxs)(l,{children:[(0,p.jsxs)(s,{children:[(0,p.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`finance.recentTransactions`,`Recent transactions`)}),(0,p.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:e(`finance.transactionsHint`,`Filter by type and cost center, then navigate pages`)})]}),(0,p.jsxs)(c,{className:`space-y-4`,children:[(0,p.jsxs)(`div`,{className:`grid gap-4 lg:grid-cols-[minmax(0,1fr)_minmax(0,1fr)_auto] xl:grid-cols-[minmax(0,1fr)_minmax(0,1fr)_minmax(0,1fr)_auto] items-end`,children:[(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`finance.transactionType`,`Type`)}),(0,p.jsxs)(`select`,{value:F,onChange:e=>ze(e.target.value),className:g,children:[(0,p.jsx)(`option`,{value:`all`,children:e(`finance.allTypes`)}),(0,p.jsx)(`option`,{value:`deposit`,children:e(`finance.deposit`)}),(0,p.jsx)(`option`,{value:`withdraw`,children:e(`finance.withdraw`)}),(0,p.jsx)(`option`,{value:`print_charge`,children:e(`finance.printCharge`)})]})]}),(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`finance.costCenters`,`Cost centers`)}),(0,p.jsxs)(`select`,{value:I,onChange:e=>Be(e.target.value===`all`?`all`:Number(e.target.value)),className:g,children:[(0,p.jsx)(`option`,{value:`all`,children:e(`finance.allCostCenters`)}),(G||[]).map(e=>(0,p.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]})]}),Z&&(0,p.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`common.loading`,`Loading...`)}),!Z&&(!Q||Q.length===0)&&(0,p.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`finance.noTransactions`,`No transactions available.`)}),!Z&&Q.length>0&&cn.length===0&&(0,p.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`finance.noTransactionsForFilter`,`No transactions match the selected filters.`)}),!Z&&cn.length>0&&(0,p.jsx)(`div`,{className:`overflow-auto rounded-lg border border-bambu-dark-tertiary`,children:(0,p.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,p.jsx)(`thead`,{children:(0,p.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary bg-bambu-dark text-bambu-gray`,children:[(0,p.jsx)(`th`,{className:v,children:e(`common.date`,`Date`)}),$&&(0,p.jsx)(`th`,{className:v,children:e(`common.user`,`User`)}),(0,p.jsx)(`th`,{className:v,children:e(`finance.costCenter`,`Cost center`)}),(0,p.jsx)(`th`,{className:v,children:e(`finance.transactionType`,`Type`)}),(0,p.jsx)(`th`,{className:v,children:e(`common.description`,`Description`)}),(0,p.jsx)(`th`,{className:v,children:e(`finance.amount`,`Amount`)}),(0,p.jsx)(`th`,{className:v,children:e(`finance.balanceAfter`,`Balance after`)}),$&&(0,p.jsx)(`th`,{className:v,children:e(`common.actions`,`Actions`)})]})}),(0,p.jsx)(`tbody`,{children:cn.map(n=>{let r=n.amount>=0,ee=n.cost_center_id==null?null:(G||[]).find(e=>e.id===n.cost_center_id),te=nn.get(n.user_id),i=n.transaction_type===`print_charge`?he(n.description??null):null,a=i?.isPartial??!1;return(0,p.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/60 text-white`,children:[(0,p.jsx)(`td`,{className:y,children:ge(n.created_at,t.language)}),$&&(0,p.jsx)(`td`,{className:y,children:te||e(`finance.userWithId`,`User #{{id}}`,{id:n.user_id})}),(0,p.jsx)(`td`,{className:y,children:ee?.name||`-`}),(0,p.jsx)(`td`,{className:y,children:(0,p.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,p.jsx)(`span`,{children:un(n.transaction_type)}),a&&(0,p.jsx)(`span`,{className:`rounded border border-yellow-500/40 bg-yellow-500/10 px-2 py-0.5 text-[11px] text-yellow-300`,children:i&&i.partialType?e(`finance.partialStatus.${i.partialType}`,i.partialType):e(`finance.partial`,`Partial`)})]})}),(0,p.jsx)(`td`,{className:y,children:(i?.cleanedDescription??n.description)||`-`}),(0,p.jsxs)(`td`,{className:`${y} ${r?`text-green-400`:`text-red-400`}`,children:[r?`+`:`-`,Y,Math.abs(n.amount).toFixed(2)]}),(0,p.jsx)(`td`,{className:y,children:n.balance_after==null?`-`:`${n.balance_after<0?`-`:``}${Y}${Math.abs(n.balance_after).toFixed(2)}`}),$&&(0,p.jsx)(`td`,{className:y,children:(0,p.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,p.jsx)(u,{size:`sm`,variant:`secondary`,onClick:()=>Xt(n),disabled:Rt.isPending,children:(0,p.jsx)(ae,{className:`w-4 h-4`})}),(0,p.jsx)(u,{size:`sm`,variant:`danger`,onClick:()=>Tt(n.id),disabled:Lt.isPending,children:(0,p.jsx)(oe,{className:`w-4 h-4`})})]})})]},n.id)})})]})}),!Z&&cn.length>0&&(0,p.jsx)(`div`,{className:`flex justify-end pt-2 lg:pt-0`,children:(0,p.jsxs)(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[(0,p.jsx)(`button`,{type:`button`,onClick:()=>P(0),disabled:N===0||Z,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,"aria-label":e(`finance.first`,`First`),children:(0,p.jsx)(ne,{className:`w-4 h-4`})}),(0,p.jsx)(`button`,{type:`button`,onClick:()=>P(e=>Math.max(0,e-50)),disabled:N===0||Z,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,"aria-label":e(`finance.prev`,`Previous`),children:(0,p.jsx)(ue,{className:`w-4 h-4`})}),(0,p.jsx)(`span`,{className:`text-bambu-gray px-1 whitespace-nowrap`,children:e(`finance.pageNumberOf`,`Page {{page}} of {{total}}`,{page:ln,total:sn})}),(0,p.jsx)(`button`,{type:`button`,onClick:()=>P(e=>e+50),disabled:Z||ln>=sn,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,"aria-label":e(`finance.next`,`Next`),children:(0,p.jsx)(se,{className:`w-4 h-4`})}),(0,p.jsx)(`button`,{type:`button`,onClick:()=>P(Math.max(0,(sn-1)*50)),disabled:Z||ln>=sn,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,"aria-label":e(`finance.last`,`Last`),children:(0,p.jsx)(re,{className:`w-4 h-4`})})]})})]})]}),et&&nt!==null&&(0,p.jsx)(b,{title:e(`finance.editTransaction`,`Edit Transaction`),onClose:()=>tt(!1),size:`md`,children:(0,p.jsxs)(`div`,{className:`space-y-4`,children:[(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`common.user`,`User`)}),(0,p.jsxs)(`select`,{className:g,value:it||``,onChange:e=>at(e.target.value?Number(e.target.value):null),children:[(0,p.jsx)(`option`,{value:``,children:e(`finance.selectUser`,`Select user...`)}),X.map(e=>(0,p.jsx)(`option`,{value:e.id,children:e.username},e.id))]})]}),(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`finance.costCenter`,`Cost center (optional)`)}),(0,p.jsxs)(`select`,{className:g,value:ot||``,onChange:e=>st(e.target.value?Number(e.target.value):null),children:[(0,p.jsx)(`option`,{value:``,children:e(`finance.noCostCenter`,`Personal (no cost center)`)}),(G||[]).map(e=>(0,p.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`finance.amount`,`Amount`)}),(0,p.jsx)(`input`,{type:`number`,step:`0.01`,className:g,value:ct,onChange:e=>lt(e.target.value),placeholder:e(`finance.amountExample`,`e.g., 10.50`)})]}),(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`common.description`,`Description`)}),(0,p.jsx)(`textarea`,{className:`${g} resize-none`,rows:3,value:ut,onChange:e=>dt(e.target.value),placeholder:e(`finance.manualAdjustmentExample`,`e.g., Manual adjustment`)})]}),(0,p.jsxs)(`div`,{className:`flex justify-end gap-2 pt-4`,children:[(0,p.jsx)(u,{variant:`secondary`,onClick:()=>tt(!1),children:e(`common.cancel`,`Cancel`)}),(0,p.jsx)(u,{onClick:Zt,disabled:Rt.isPending,children:e(`common.save`,`Save`)})]})]})}),ft&&(0,p.jsx)(b,{title:e(`finance.addManualPrint`,`Add manual print`),onClose:()=>H(!1),size:`md`,children:(0,p.jsxs)(`div`,{className:`space-y-4`,children:[(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`common.user`,`User`)}),(0,p.jsxs)(`select`,{className:g,value:pt||``,onChange:e=>mt(e.target.value?Number(e.target.value):null),children:[(0,p.jsx)(`option`,{value:``,children:e(`finance.selectUser`,`Select user...`)}),X.map(e=>(0,p.jsx)(`option`,{value:e.id,children:e.username},e.id))]})]}),(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`finance.costCenter`,`Cost center`)}),(0,p.jsxs)(`select`,{className:g,value:ht||``,onChange:e=>gt(e.target.value?Number(e.target.value):null),children:[(0,p.jsx)(`option`,{value:``,children:e(`finance.selectCostCenter`,`Select cost center...`)}),(G||[]).map(e=>(0,p.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`finance.amount`,`Amount`)}),(0,p.jsx)(`input`,{type:`number`,step:`0.01`,className:g,value:_t,onChange:e=>vt(e.target.value),placeholder:e(`finance.amountExample`,`e.g., 4.00`)})]}),(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`common.description`,`Description`)}),(0,p.jsx)(`input`,{type:`text`,value:yt,onChange:e=>bt(e.target.value),placeholder:e(`finance.descriptionOptional`,`Description (optional)`),className:g})]}),(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`common.date`,`Date`)}),(0,p.jsx)(`input`,{type:`datetime-local`,value:xt,onChange:e=>St(e.target.value),className:g})]}),(0,p.jsxs)(`div`,{className:`flex justify-end gap-2 pt-4`,children:[(0,p.jsx)(u,{variant:`secondary`,onClick:()=>H(!1),children:e(`common.cancel`,`Cancel`)}),(0,p.jsx)(u,{onClick:Qt,disabled:zt.isPending,children:zt.isPending?e(`common.saving`,`Saving...`):e(`finance.addManualPrint`,`Add manual print`)})]})]})}),U&&(0,p.jsx)(ce,{title:e(`common.delete`,`Delete`),message:e(`finance.confirmDeleteCostCenter`,`Delete cost center "{{name}}"?`,{name:U.name}),confirmText:e(`common.delete`,`Delete`),variant:`danger`,isLoading:It.isPending,onConfirm:Jt,onCancel:()=>Ct(null)}),wt!=null&&(0,p.jsx)(ce,{title:e(`finance.deleteTransaction`,`Delete transaction`),message:e(`finance.deleteTransactionConfirm`,`Delete this transaction? Balances will be recalculated automatically.`),confirmText:e(`common.delete`,`Delete`),variant:`danger`,isLoading:Lt.isPending,onConfirm:Yt,onCancel:()=>Tt(null)})]})]}):(0,p.jsxs)(`div`,{className:`p-4 md:p-8 space-y-6`,children:[(0,p.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,p.jsx)(me,{className:`h-6 w-6 text-bambu-green`}),(0,p.jsx)(`h1`,{className:`text-2xl font-bold text-white`,children:e(`finance.title`,`Finance`)})]}),(0,p.jsx)(`div`,{children:(0,p.jsx)(`p`,{className:`text-bambu-gray mt-2 max-w-2xl`,children:e(`finance.subtitle`,`Wallet, personal transactions, and cost centers`)})}),(0,p.jsx)(l,{children:(0,p.jsx)(c,{className:`py-8 text-center text-bambu-gray`,children:e(`finance.noAccess`,`You do not have permission to view finance data.`)})})]})}export{x as FinancePage}; \ No newline at end of file +import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,w as ee}from"./client-DnySrlFv.js";import{n as te}from"./QueryClientProvider-Ce8_sN3w.js";import{t as i}from"./useQuery-BBCjCezC.js";import{t as a}from"./useMutation-B-Tr2hIP.js";import{t as o}from"./createLucideIcon-DvBYJlWL.js";import{n as ne,t as re}from"./chevrons-right-DTJgqnxZ.js";import{n as ie}from"./ToastContext-BRX0SW3C.js";import{i as s,n as c,t as l}from"./Card-Bzc64K35.js";import{t as u}from"./Button-DDr6eAFy.js";import{v as d}from"./date-G9KUauqz.js";import{$t as ae,At as oe,Mn as se,_t as ce,at as le,jn as ue,yt as de}from"./index-Cxa-KVmA.js";var fe=o(`building-2`,[[`path`,{d:`M10 12h4`,key:`a56b0p`}],[`path`,{d:`M10 8h4`,key:`1sr2af`}],[`path`,{d:`M14 21v-3a2 2 0 0 0-4 0v3`,key:`1rgiei`}],[`path`,{d:`M6 10H4a2 2 0 0 0-2 2v7a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V9a2 2 0 0 0-2-2h-2`,key:`secmi2`}],[`path`,{d:`M6 21V5a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v16`,key:`16ra0t`}]]),pe=o(`clock-3`,[[`path`,{d:`M12 6v6h4`,key:`135r8i`}],[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}]]),me=o(`wallet`,[[`path`,{d:`M19 7V4a1 1 0 0 0-1-1H5a2 2 0 0 0 0 4h15a1 1 0 0 1 1 1v4h-3a2 2 0 0 0 0 4h3a1 1 0 0 0 1-1v-2a1 1 0 0 0-1-1`,key:`18etb6`}],[`path`,{d:`M3 5v14a2 2 0 0 0 2 2h15a1 1 0 0 0 1-1v-4`,key:`xoc0q4`}]]),f=e(n(),1),p=t(),m=/\[(aborted|failed|cancelled):\s*([^\]]*)\]/i;function he(e){if(!e)return{isPartial:!1,partialType:null,cleanedDescription:null};let t=e.match(m);if(!t)return{isPartial:!1,partialType:null,cleanedDescription:e};let n=e.replace(t[0],``).trim();return{isPartial:!0,partialType:t[1].toLowerCase(),cleanedDescription:n||null}}function ge(e,t){if(!e)return`-`;let n=d(e);return n?n.toLocaleString(t):e}function h(e){let t=e.trim();if(!t)return null;let n=Number.parseFloat(t);return Number.isFinite(n)?n:null}function _e(e){return`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,`0`)}-${String(e.getDate()).padStart(2,`0`)}T${String(e.getHours()).padStart(2,`0`)}:${String(e.getMinutes()).padStart(2,`0`)}`}var g=`w-full px-3 py-2 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded text-white placeholder-bambu-gray focus:outline-none focus:ring-1 focus:ring-bambu-green`,_=`block text-sm font-medium text-white mb-1`,v=`px-4 py-3 text-left text-bambu-gray font-medium`,y=`px-4 py-3 align-top text-white`;function b({title:e,onClose:t,children:n,size:r=`md`}){let{t:te}=ee();return(0,p.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/70 p-4`,children:(0,p.jsxs)(`div`,{className:`w-full ${r===`sm`?`max-w-xl`:r===`lg`?`max-w-6xl`:`max-w-4xl`} overflow-hidden rounded-lg border border-bambu-dark-tertiary bg-bambu-dark-secondary`,children:[(0,p.jsxs)(`div`,{className:`flex items-center justify-between border-b border-bambu-dark-tertiary px-4 py-3`,children:[(0,p.jsx)(`h3`,{className:`text-lg font-semibold text-white`,children:e}),(0,p.jsx)(u,{size:`sm`,variant:`secondary`,onClick:t,children:te(`common.close`,`Close`)})]}),(0,p.jsx)(`div`,{className:`max-h-[75vh] overflow-auto p-4`,children:n})]})})}function x(){let{t:e,i18n:t}=ee(),{hasPermission:n,user:o}=de(),{showToast:d}=ie(),m=te(),x=n(`cost_centers:read_own`),S=n(`cost_centers:read_all`),C=n(`cost_centers:create`),w=n(`cost_centers:modify`),T=n(`cost_centers:modify`),E=n(`cost_centers:modify`),D=n(`cost_centers:modify`),O=n(`users:read_slim`)||n(`users:read`),ve=S||C||w||T||E||D,ye=x||ve,be=ye,[xe,Se]=(0,f.useState)(``),[k,Ce]=(0,f.useState)(`monthly`),[we,Te]=(0,f.useState)(``),[A,Ee]=(0,f.useState)(null),[De,Oe]=(0,f.useState)(`deposit`),[ke,Ae]=(0,f.useState)(``),[je,Me]=(0,f.useState)(``),[Ne,Pe]=(0,f.useState)(null),[j,M]=(0,f.useState)(null),[Fe,Ie]=(0,f.useState)(null),[Le,Re]=(0,f.useState)(!0),[N,P]=(0,f.useState)(0),[F,ze]=(0,f.useState)(`all`),[I,Be]=(0,f.useState)(`all`),[Ve,He]=(0,f.useState)(!1),[Ue,We]=(0,f.useState)(!1),[Ge,Ke]=(0,f.useState)(!1),[L,qe]=(0,f.useState)(!1),[R,Je]=(0,f.useState)(`personal`),[z,Ye]=(0,f.useState)(null),[Xe,Ze]=(0,f.useState)(``),[Qe,B]=(0,f.useState)(`monthly`),[$e,V]=(0,f.useState)(``),[et,tt]=(0,f.useState)(!1),[nt,rt]=(0,f.useState)(null),[it,at]=(0,f.useState)(null),[ot,st]=(0,f.useState)(null),[ct,lt]=(0,f.useState)(``),[ut,dt]=(0,f.useState)(``),[ft,H]=(0,f.useState)(!1),[pt,mt]=(0,f.useState)(null),[ht,gt]=(0,f.useState)(null),[_t,vt]=(0,f.useState)(``),[yt,bt]=(0,f.useState)(``),[xt,St]=(0,f.useState)(_e(new Date)),[U,Ct]=(0,f.useState)(null),[wt,Tt]=(0,f.useState)(null),W=S||C||w||T||D&&O||E&&O;(0,f.useEffect)(()=>{W||Je(`personal`)},[W]);let{data:Et,isLoading:Dt}=i({queryKey:[`finance`,`me`,`balance`],queryFn:r.getMyBalance,enabled:x}),{data:Ot}=i({queryKey:[`ui-flags`],queryFn:r.getUiFlags}),{data:kt,isLoading:At}=i({queryKey:[`finance`,`me`,`transactions`,50,N],queryFn:()=>r.getMyTransactions(50,N),enabled:x}),{data:jt,isLoading:Mt}=i({queryKey:[`finance`,`transactions`,50,N],queryFn:()=>r.getAllTransactions(50,N),enabled:R===`admin`&&S}),{data:G,isLoading:K}=i({queryKey:[`finance`,`cost-centers`,R],queryFn:()=>R===`admin`&&ve?r.listCostCenters(!0):r.getMyCostCenters(),enabled:be}),{data:q}=i({queryKey:[`users`,`slim`],queryFn:r.getUsersSlim,enabled:O&&(be||D||E)}),{data:J}=i({queryKey:[`finance`,`cost-center`,j],queryFn:()=>r.getCostCenter(j),enabled:E&&j!=null});(0,f.useEffect)(()=>{!q||q.length===0||A!=null&&q.some(e=>e.id===A)||Ee(q[0].id)},[q,A]),(0,f.useEffect)(()=>{if(!E)return;let e=(G||[]).filter(e=>!e.is_private);if(e.length===0){M(null);return}j!=null&&e.some(e=>e.id===j)||M(e[0].id)},[E,G,j]),(0,f.useEffect)(()=>{if(!E||!q||q.length===0)return;let e=new Set((J?.members||[]).map(e=>e.user_id)),t=q.find(t=>!e.has(t.id));Ie(t?t.id:null)},[E,q,J]),(0,f.useEffect)(()=>{if(!L)return;let e=G||[];if(e.length===0){Ye(null);return}z!=null&&e.some(e=>e.id===z)||Ye(e[0].id)},[L,z,G]),(0,f.useEffect)(()=>{if(!L||z==null)return;let e=(G||[]).find(e=>e.id===z);if(e){if(Ze(e.name),e.budget_mode===`total`){B(`total`),V(e.total_budget==null?``:String(e.total_budget));return}B(`monthly`),V(e.monthly_budget==null?``:String(e.monthly_budget))}},[L,z,G]);let Nt=a({mutationFn:()=>r.createCostCenter({name:xe.trim(),total_budget:k===`total`?h(we):null,monthly_budget:k===`monthly`?h(we):null,is_active:!0}),onSuccess:()=>{m.invalidateQueries({queryKey:[`finance`]}),Se(``),Te(``),d(e(`finance.createdCostCenter`,`Cost center created`))},onError:t=>{d(t.message||e(`finance.createCostCenterFailed`,`Failed to create cost center`),`error`)}}),Pt=a({mutationFn:({costCenterId:e,value:t,mode:n})=>r.updateCostCenterBudgets(e,{total_budget:n===`total`?h(t):null,monthly_budget:n===`monthly`?h(t):null})}),Ft=a({mutationFn:({costCenterId:e,name:t})=>r.updateCostCenter(e,{name:t})}),It=a({mutationFn:e=>r.deleteCostCenter(e)}),Lt=a({mutationFn:e=>r.deleteTransaction(e),onSuccess:()=>{m.invalidateQueries({queryKey:[`finance`]}),d(e(`finance.transactionDeleted`,`Transaction deleted`))},onError:t=>{d(t.message||e(`finance.deleteTransactionFailed`,`Failed to delete transaction`),`error`)}}),Rt=a({mutationFn:e=>r.editTransaction(e.transactionId,e.data),onSuccess:()=>{m.invalidateQueries({queryKey:[`finance`]}),d(e(`finance.transactionEdited`,`Transaction updated and ledger recalculated`)),tt(!1)},onError:t=>{d(t.message||e(`finance.editTransactionFailed`,`Failed to edit transaction`),`error`)}}),zt=a({mutationFn:e=>r.createManualPrint(e),onSuccess:()=>{m.invalidateQueries({queryKey:[`finance`]}),d(e(`finance.manualPrintCreated`,`Manual print charge added and ledger recalculated`)),H(!1),mt(null),gt(null),vt(``),bt(``),St(_e(new Date))},onError:t=>{d(t.message||e(`finance.manualPrintFailed`,`Failed to create manual print`),`error`)}}),Bt=a({mutationFn:e=>r.depositUserBalance(e.userId,{amount:e.amount,description:e.description,cost_center_id:e.costCenterId??null})}),Vt=a({mutationFn:e=>r.withdrawUserBalance(e.userId,{amount:e.amount,description:e.description,cost_center_id:e.costCenterId??null})}),Ht=a({mutationFn:e=>r.upsertCostCenterMember(e.costCenterId,{user_id:e.userId,can_print:e.canPrint}),onSuccess:()=>{m.invalidateQueries({queryKey:[`finance`]}),d(e(`finance.memberSaved`,`Member saved`))},onError:t=>{d(t.message||e(`finance.memberSaveFailed`,`Failed to save member`),`error`)}}),Ut=a({mutationFn:e=>r.removeCostCenterMember(e.costCenterId,e.userId),onSuccess:()=>{m.invalidateQueries({queryKey:[`finance`]}),d(e(`finance.memberRemoved`,`Member removed`))},onError:t=>{d(t.message||e(`finance.memberRemoveFailed`,`Failed to remove member`),`error`)}}),Wt=Bt.isPending||Vt.isPending,Gt=()=>{if(!xe.trim()){d(e(`finance.costCenterNameRequired`,`Cost center name is required`),`error`);return}Nt.mutate()},Kt=async()=>{if(z==null){d(e(`finance.selectCostCenter`,`Please select a cost center`),`error`);return}let t=Xe.trim();if(!t){d(e(`finance.costCenterNameRequired`,`Cost center name is required`),`error`);return}try{w&&await Ft.mutateAsync({costCenterId:z,name:t}),T&&await Pt.mutateAsync({costCenterId:z,mode:Qe,value:$e}),m.invalidateQueries({queryKey:[`finance`]}),d(e(`finance.costCenterUpdated`,`Cost center updated`)),qe(!1)}catch(t){d(t.message||e(`finance.costCenterUpdateFailed`,`Failed to update cost center`),`error`)}},qt=e=>{let t=(G||[]).find(t=>t.id===e);t&&(Ye(t.id),Ze(t.name),t.budget_mode===`total`?(B(`total`),V(t.total_budget==null?``:String(t.total_budget))):(B(`monthly`),V(t.monthly_budget==null?``:String(t.monthly_budget))),qe(!0))},Jt=async()=>{if(U)try{await It.mutateAsync(U.id),m.invalidateQueries({queryKey:[`finance`]}),j===U.id&&M(null),d(e(`finance.costCenterDeleted`,`Cost center deleted`))}catch(t){d(t.message||e(`finance.costCenterDeleteFailed`,`Failed to delete cost center`),`error`)}finally{Ct(null)}},Yt=()=>{wt!=null&&Lt.mutate(wt,{onSettled:()=>Tt(null)})},Xt=e=>{rt(e.id),at(e.user_id),st(e.cost_center_id),lt(String(e.amount)),dt(e.description||``),tt(!0)},Zt=async()=>{if(nt==null)return;let t=ct?Number.parseFloat(ct):null;if(t!==null&&!Number.isFinite(t)){d(e(`finance.amountInvalid`,`Amount must be a valid number`),`error`);return}Rt.mutate({transactionId:nt,data:{user_id:it||void 0,cost_center_id:ot||void 0,amount:t??void 0,description:ut||void 0}})},Qt=async()=>{if(pt==null){d(e(`finance.userRequired`,`Please select a user`),`error`);return}if(ht==null){d(e(`finance.costCenterRequired`,`Please select a cost center`),`error`);return}let t=_t?Number.parseFloat(_t):null;if(t===null||!Number.isFinite(t)){d(e(`finance.amountInvalid`,`Amount must be a valid number`),`error`);return}t=Math.abs(t),zt.mutate({user_id:pt,cost_center_id:ht,amount:t,description:yt||void 0,created_at:xt?new Date(xt).toISOString():void 0})},$t=async()=>{if(A==null){d(e(`finance.userRequired`,`Please select a user`),`error`);return}let t=Number.parseFloat(ke);if(!Number.isFinite(t)||t<=0){d(e(`finance.amountMustBePositive`,`Amount must be greater than zero`),`error`);return}let n={userId:A,amount:t,description:je.trim()||void 0,costCenterId:Ne};try{De===`deposit`?await Bt.mutateAsync(n):await Vt.mutateAsync(n),m.invalidateQueries({queryKey:[`finance`]}),Ae(``),Me(``),d(De===`deposit`?e(`finance.depositSuccess`,`Deposit successful`):e(`finance.withdrawSuccess`,`Withdrawal successful`))}catch(t){d(t.message||e(`finance.adjustmentFailed`,`Wallet adjustment failed`),`error`)}},en=()=>{if(j==null){d(e(`finance.selectCostCenter`,`Please select a cost center`),`error`);return}if(Fe==null){d(e(`finance.noEligibleUsers`,`No eligible users available`),`error`);return}Ht.mutate({costCenterId:j,userId:Fe,canPrint:Le})},tn=e=>{j!=null&&Ut.mutate({costCenterId:j,userId:e})},Y=le(Ot?.currency||`USD`),X=(0,f.useMemo)(()=>[...q||[]].sort((e,t)=>e.username.localeCompare(t.username)),[q]),nn=(0,f.useMemo)(()=>{let e=new Map;for(let t of X)e.set(t.id,t.username);return e},[X]),rn=(0,f.useMemo)(()=>{let e=new Set((J?.members||[]).map(e=>e.user_id));return X.filter(t=>!e.has(t.id))},[X,J]),an=R===`admin`&&S?jt:kt,Z=R===`admin`&&S?Mt:At,Q=(0,f.useMemo)(()=>an?.items??[],[an?.items]),on=an?.total??0,sn=Math.max(1,Math.ceil(on/50)),cn=(0,f.useMemo)(()=>Q.filter(e=>!(F!==`all`&&e.transaction_type!==F||I!==`all`&&e.cost_center_id!==I)),[Q,F,I]),ln=Math.floor(N/50)+1,$=R===`admin`,un=t=>t===`deposit`?e(`finance.deposit`):t===`withdraw`?e(`finance.withdraw`):t===`print_charge`?e(`finance.printCharge`):t,dn=t=>t==null?e(`finance.personal`,`Personal`):nn.get(t)||(o?.id===t&&o.username?o.username:e(`finance.userWithId`,`User #{{id}}`,{id:t})),fn=t=>t.budget_limit==null||t.budget_available==null?e(`finance.unlimited`,`Unlimited`):`${Y}${t.budget_available.toFixed(2)}/${Y}${t.budget_limit.toFixed(2)}`;return ye?(0,p.jsxs)(`div`,{className:`p-4 md:p-8 space-y-8`,children:[(0,p.jsxs)(`div`,{className:`flex flex-col gap-4 lg:flex-row lg:items-start lg:justify-between`,children:[(0,p.jsxs)(`div`,{children:[(0,p.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,p.jsx)(me,{className:`h-6 w-6 text-bambu-green`}),(0,p.jsx)(`h1`,{className:`text-2xl font-bold text-white`,children:e(`finance.title`,`Finance`)})]}),(0,p.jsx)(`p`,{className:`text-bambu-gray mt-2 max-w-2xl`,children:e(`finance.subtitle`,`Wallet, personal transactions, and cost centers`)}),(0,p.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1 max-w-2xl`,children:e(`finance.budgetPolicyHint`,`Account balances track costs. Printing is limited only by the selected cost center budget; without a budget, printing is unlimited.`)})]}),(0,p.jsxs)(`div`,{className:`flex flex-col gap-2 lg:items-end`,children:[W&&(0,p.jsxs)(`div`,{className:`inline-flex overflow-hidden rounded border border-bambu-dark-tertiary`,children:[(0,p.jsx)(`button`,{type:`button`,onClick:()=>Je(`personal`),className:`px-3 py-1.5 text-sm ${R===`personal`?`bg-bambu-green text-black font-medium`:`bg-bambu-dark text-bambu-gray`}`,children:e(`finance.personalView`,`Personal view`)}),(0,p.jsx)(`button`,{type:`button`,onClick:()=>Je(`admin`),className:`px-3 py-1.5 text-sm ${R===`admin`?`bg-bambu-green text-black font-medium`:`bg-bambu-dark text-bambu-gray`}`,children:e(`finance.adminView`,`Admin view`)})]}),R===`admin`&&W&&(0,p.jsxs)(`div`,{className:`flex flex-wrap gap-2 lg:justify-end`,children:[C&&(0,p.jsx)(u,{size:`sm`,variant:`secondary`,onClick:()=>He(!0),children:e(`finance.createCostCenter`,`Create cost center`)}),D&&O&&(0,p.jsx)(u,{size:`sm`,variant:`secondary`,onClick:()=>We(!0),children:e(`finance.adjustWallet`,`Adjust wallet`)}),D&&O&&(0,p.jsx)(u,{size:`sm`,variant:`secondary`,onClick:()=>H(!0),children:e(`finance.addManualPrint`,`Add manual print`)}),E&&O&&(0,p.jsx)(u,{size:`sm`,variant:`secondary`,onClick:()=>Ke(!0),children:e(`finance.manageMembers`,`Manage cost center members`)})]})]})]}),(0,p.jsxs)(`div`,{className:`grid gap-5 md:grid-cols-2 xl:grid-cols-3`,children:[(0,p.jsxs)(l,{children:[(0,p.jsxs)(s,{className:`flex flex-row items-center justify-between pb-2`,children:[(0,p.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e(`finance.currentBalance`,`Personal account balance`)}),(0,p.jsx)(me,{className:`w-4 h-4 text-bambu-green/90`})]}),(0,p.jsx)(c,{className:`pt-1`,children:(0,p.jsx)(`p`,{className:`text-3xl font-semibold text-white leading-tight`,children:Dt?e(`common.loading`,`Loading...`):`${Y}${(Et?.balance??0).toFixed(2)}`})})]}),(0,p.jsxs)(l,{children:[(0,p.jsxs)(s,{className:`flex flex-row items-center justify-between pb-2`,children:[(0,p.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:R===`admin`?e(`finance.transactions`,`Transactions`):e(`finance.personalTransactions`,`Personal transactions`)}),(0,p.jsx)(pe,{className:`w-4 h-4 text-blue-400`})]}),(0,p.jsx)(c,{className:`pt-1`,children:(0,p.jsx)(`p`,{className:`text-3xl font-semibold text-white leading-tight`,children:Z?`-`:on})})]}),(0,p.jsxs)(l,{children:[(0,p.jsxs)(s,{className:`flex flex-row items-center justify-between pb-2`,children:[(0,p.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e(`finance.costCenters`,`Cost centers`)}),(0,p.jsx)(fe,{className:`w-4 h-4 text-orange-400`})]}),(0,p.jsx)(c,{className:`pt-1`,children:(0,p.jsx)(`p`,{className:`text-3xl font-semibold text-white leading-tight`,children:K?`-`:G?.length??0})})]})]}),Ve&&C&&(0,p.jsx)(b,{title:e(`finance.createCostCenter`,`Create cost center`),size:`md`,onClose:()=>He(!1),children:(0,p.jsxs)(`div`,{className:`space-y-4`,children:[(0,p.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-3`,children:[(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`finance.costCenterName`,`Name`)}),(0,p.jsx)(`input`,{type:`text`,value:xe,onChange:e=>Se(e.target.value),placeholder:e(`finance.costCenterName`,`Name`),className:g})]}),(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`finance.budgetType`,`Budget type`)}),(0,p.jsxs)(`select`,{value:k,onChange:e=>Ce(e.target.value),className:g,children:[(0,p.jsx)(`option`,{value:`monthly`,children:e(`finance.monthlyBudget`,`Monthly budget`)}),(0,p.jsx)(`option`,{value:`total`,children:e(`finance.totalBudget`,`Total budget`)})]})]}),(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:k===`monthly`?e(`finance.monthlyBudget`,`Monthly budget`):e(`finance.totalBudget`,`Total budget`)}),(0,p.jsx)(`input`,{type:`number`,step:`0.01`,value:we,onChange:e=>Te(e.target.value),placeholder:`0.00`,className:g})]})]}),(0,p.jsx)(u,{className:`min-w-[180px]`,onClick:Gt,disabled:Nt.isPending,children:Nt.isPending?e(`common.saving`,`Saving...`):e(`finance.create`,`Create`)})]})}),Ue&&D&&O&&(0,p.jsx)(b,{title:e(`finance.adjustWallet`,`Adjust wallet`),size:`md`,onClose:()=>We(!1),children:(0,p.jsxs)(`div`,{className:`space-y-4`,children:[(0,p.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`finance.selectUser`,`Select user`)}),(0,p.jsx)(`select`,{value:A??``,onChange:e=>Ee(e.target.value?Number(e.target.value):null),className:g,children:(X||[]).map(e=>(0,p.jsx)(`option`,{value:e.id,children:e.username},e.id))})]}),(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`finance.transactionType`,`Type`)}),(0,p.jsxs)(`select`,{value:De,onChange:e=>Oe(e.target.value),className:g,children:[(0,p.jsx)(`option`,{value:`deposit`,children:e(`finance.deposit`,`Deposit`)}),(0,p.jsx)(`option`,{value:`withdraw`,children:e(`finance.withdraw`,`Withdraw`)})]})]}),(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`finance.amount`,`Amount`)}),(0,p.jsx)(`input`,{type:`number`,step:`0.01`,min:`0`,value:ke,onChange:e=>Ae(e.target.value),placeholder:`0.00`,className:g})]}),(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`finance.costCenters`,`Cost centers`)}),(0,p.jsxs)(`select`,{value:Ne??``,onChange:e=>Pe(e.target.value?Number(e.target.value):null),className:g,children:[(0,p.jsx)(`option`,{value:``,children:e(`finance.noCostCenter`,`No cost center`)}),(G||[]).map(e=>(0,p.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]})]}),(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`common.description`,`Description`)}),(0,p.jsx)(`input`,{type:`text`,value:je,onChange:e=>Me(e.target.value),placeholder:e(`finance.descriptionOptional`,`Description (optional)`),className:g})]}),(0,p.jsx)(u,{className:`min-w-[180px]`,onClick:$t,disabled:Wt,children:Wt?e(`common.saving`,`Saving...`):e(`finance.applyAdjustment`,`Apply adjustment`)})]})}),Ge&&E&&O&&(0,p.jsx)(b,{title:e(`finance.manageMembers`,`Manage cost center members`),size:`lg`,onClose:()=>Ke(!1),children:(0,p.jsxs)(`div`,{className:`space-y-5`,children:[(0,p.jsxs)(`div`,{className:`grid gap-5 md:grid-cols-2`,children:[(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`finance.costCenters`,`Cost centers`)}),(0,p.jsx)(`select`,{value:j??``,onChange:e=>M(e.target.value?Number(e.target.value):null),className:g,children:(G||[]).filter(e=>!e.is_private).map(e=>(0,p.jsx)(`option`,{value:e.id,children:e.name},e.id))})]}),(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`finance.selectUser`,`Select user`)}),(0,p.jsxs)(`select`,{value:Fe??``,onChange:e=>Ie(e.target.value?Number(e.target.value):null),className:g,children:[(0,p.jsx)(`option`,{value:``,children:e(`finance.selectUser`,`Select user`)}),rn.map(e=>(0,p.jsx)(`option`,{value:e.id,children:e.username},e.id))]})]}),(0,p.jsxs)(`div`,{className:`flex items-center gap-2 rounded border border-bambu-dark-tertiary bg-bambu-dark-secondary px-3 py-2`,children:[(0,p.jsx)(`input`,{id:`memberCanPrint`,type:`checkbox`,checked:Le,onChange:e=>Re(e.target.checked),className:`rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,p.jsx)(`label`,{htmlFor:`memberCanPrint`,className:`text-sm text-bambu-gray`,children:e(`finance.memberCanPrint`,`Member can print`)})]}),(0,p.jsx)(`div`,{className:`flex items-end`,children:(0,p.jsx)(u,{className:`min-w-[180px]`,onClick:en,disabled:Ht.isPending||Fe==null,children:Ht.isPending?e(`common.saving`,`Saving...`):e(`finance.addMember`,`Add member`)})})]}),(0,p.jsx)(`div`,{className:`overflow-auto rounded-lg border border-bambu-dark-tertiary`,children:(0,p.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,p.jsx)(`thead`,{children:(0,p.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary bg-bambu-dark text-bambu-gray`,children:[(0,p.jsx)(`th`,{className:v,children:e(`common.name`,`Name`)}),(0,p.jsx)(`th`,{className:v,children:e(`finance.canPrint`,`Can print`)}),(0,p.jsx)(`th`,{className:v,children:e(`common.actions`,`Actions`)})]})}),(0,p.jsxs)(`tbody`,{children:[(J?.members||[]).map(t=>(0,p.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/60 text-white`,children:[(0,p.jsx)(`td`,{className:y,children:X.find(e=>e.id===t.user_id)?.username||`User ${t.user_id}`}),(0,p.jsx)(`td`,{className:y,children:t.can_print?e(`common.yes`,`Yes`):e(`common.no`,`No`)}),(0,p.jsx)(`td`,{className:y,children:(0,p.jsx)(u,{size:`sm`,variant:`danger`,onClick:()=>tn(t.user_id),disabled:Ut.isPending,children:e(`common.remove`,`Remove`)})})]},t.id)),(J?.members||[]).length===0&&(0,p.jsx)(`tr`,{children:(0,p.jsx)(`td`,{colSpan:3,className:`py-3 text-bambu-gray`,children:e(`finance.noMembers`,`No members assigned.`)})})]})]})})]})}),L&&(w||T)&&(0,p.jsx)(b,{title:e(`finance.editCostCenter`,`Edit cost center`),size:`md`,onClose:()=>qe(!1),children:(0,p.jsxs)(`div`,{className:`space-y-4`,children:[(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`finance.costCenterName`,`Name`)}),(0,p.jsx)(`input`,{type:`text`,value:Xe,onChange:e=>Ze(e.target.value),placeholder:e(`finance.costCenterName`,`Name`),className:g,disabled:!w})]}),(0,p.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`finance.budgetType`,`Budget type`)}),(0,p.jsxs)(`select`,{value:Qe,onChange:e=>B(e.target.value),className:g,disabled:!T,children:[(0,p.jsx)(`option`,{value:`monthly`,children:e(`finance.monthlyBudget`,`Monthly budget`)}),(0,p.jsx)(`option`,{value:`total`,children:e(`finance.totalBudget`,`Total budget`)})]})]}),(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:Qe===`monthly`?e(`finance.monthlyBudget`,`Monthly budget`):e(`finance.totalBudget`,`Total budget`)}),(0,p.jsx)(`input`,{type:`number`,step:`0.01`,value:$e,onChange:e=>V(e.target.value),placeholder:`0.00`,className:g,disabled:!T})]})]}),(0,p.jsx)(u,{className:`min-w-[180px]`,onClick:Kt,disabled:Ft.isPending||Pt.isPending||z==null,children:Ft.isPending||Pt.isPending?e(`common.saving`,`Saving...`):e(`common.save`,`Save`)})]})}),(0,p.jsxs)(`div`,{className:`grid gap-6 ${be&&x?`xl:grid-cols-2`:``}`,children:[be&&(0,p.jsxs)(l,{children:[(0,p.jsxs)(s,{children:[(0,p.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`finance.myCostCenters`,`My cost centers`)}),(0,p.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:e(`finance.costCentersHint`,`Review budget limits and keep costs under control`)})]}),(0,p.jsxs)(c,{className:`space-y-3`,children:[K&&(0,p.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`common.loading`,`Loading...`)}),!K&&(!G||G.length===0)&&(0,p.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`finance.noCostCenters`,`No cost centers found.`)}),!K&&G&&G.length>0&&(0,p.jsx)(`div`,{className:`overflow-auto rounded-lg border border-bambu-dark-tertiary`,children:(0,p.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,p.jsx)(`thead`,{children:(0,p.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary bg-bambu-dark text-bambu-gray`,children:[(0,p.jsx)(`th`,{className:v,children:e(`common.name`,`Name`)}),$&&(0,p.jsx)(`th`,{className:v,children:e(`finance.owner`,`Owner`)}),(0,p.jsx)(`th`,{className:v,children:e(`finance.balance`,`Account balance`)}),(0,p.jsx)(`th`,{className:v,children:e(`finance.budget`,`Budget`)}),$&&(0,p.jsx)(`th`,{className:v,children:e(`common.actions`,`Actions`)})]})}),(0,p.jsx)(`tbody`,{children:G.map(t=>{let n=w||T,r=!t.is_private&&w;return(0,p.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/60 text-white`,children:[(0,p.jsx)(`td`,{className:y,children:t.name}),$&&(0,p.jsx)(`td`,{className:y,children:t.is_private?dn(t.owner_user_id):e(`finance.shared`,`Shared`)}),(0,p.jsxs)(`td`,{className:y,children:[Y,t.total_balance.toFixed(2)]}),(0,p.jsx)(`td`,{className:y,children:(0,p.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[(0,p.jsx)(`span`,{children:fn(t)}),(0,p.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:t.budget_mode===`monthly`?e(`finance.monthlyBudget`,`Monthly budget`):t.budget_mode===`total`?e(`finance.totalBudget`,`Total budget`):e(`finance.noBudget`,`No budget`)})]})}),$&&(0,p.jsx)(`td`,{className:y,children:(0,p.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,p.jsx)(u,{size:`sm`,variant:`ghost`,onClick:()=>qt(t.id),disabled:!n,title:n?e(`common.edit`,`Edit`):e(`finance.cannotEditPrivateCostCenter`,`Private cost centers cannot be edited here`),className:`p-1.5 sm:p-2`,children:(0,p.jsx)(ae,{className:`w-4 h-4`})}),r&&(0,p.jsx)(u,{size:`sm`,variant:`ghost`,onClick:()=>Ct({id:t.id,name:t.name}),disabled:It.isPending,title:e(`common.delete`,`Delete`),className:`text-red-400 hover:text-red-300 hover:bg-red-500/10 p-1.5 sm:p-2`,children:(0,p.jsx)(oe,{className:`w-4 h-4`})})]})})]},t.id)})})]})})]})]}),x&&(0,p.jsxs)(l,{children:[(0,p.jsxs)(s,{children:[(0,p.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`finance.recentTransactions`,`Recent transactions`)}),(0,p.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:e(`finance.transactionsHint`,`Filter by type and cost center, then navigate pages`)})]}),(0,p.jsxs)(c,{className:`space-y-4`,children:[(0,p.jsxs)(`div`,{className:`grid gap-4 lg:grid-cols-[minmax(0,1fr)_minmax(0,1fr)_auto] xl:grid-cols-[minmax(0,1fr)_minmax(0,1fr)_minmax(0,1fr)_auto] items-end`,children:[(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`finance.transactionType`,`Type`)}),(0,p.jsxs)(`select`,{value:F,onChange:e=>ze(e.target.value),className:g,children:[(0,p.jsx)(`option`,{value:`all`,children:e(`finance.allTypes`)}),(0,p.jsx)(`option`,{value:`deposit`,children:e(`finance.deposit`)}),(0,p.jsx)(`option`,{value:`withdraw`,children:e(`finance.withdraw`)}),(0,p.jsx)(`option`,{value:`print_charge`,children:e(`finance.printCharge`)})]})]}),(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`finance.costCenters`,`Cost centers`)}),(0,p.jsxs)(`select`,{value:I,onChange:e=>Be(e.target.value===`all`?`all`:Number(e.target.value)),className:g,children:[(0,p.jsx)(`option`,{value:`all`,children:e(`finance.allCostCenters`)}),(G||[]).map(e=>(0,p.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]})]}),Z&&(0,p.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`common.loading`,`Loading...`)}),!Z&&(!Q||Q.length===0)&&(0,p.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`finance.noTransactions`,`No transactions available.`)}),!Z&&Q.length>0&&cn.length===0&&(0,p.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`finance.noTransactionsForFilter`,`No transactions match the selected filters.`)}),!Z&&cn.length>0&&(0,p.jsx)(`div`,{className:`overflow-auto rounded-lg border border-bambu-dark-tertiary`,children:(0,p.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,p.jsx)(`thead`,{children:(0,p.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary bg-bambu-dark text-bambu-gray`,children:[(0,p.jsx)(`th`,{className:v,children:e(`common.date`,`Date`)}),$&&(0,p.jsx)(`th`,{className:v,children:e(`common.user`,`User`)}),(0,p.jsx)(`th`,{className:v,children:e(`finance.costCenter`,`Cost center`)}),(0,p.jsx)(`th`,{className:v,children:e(`finance.transactionType`,`Type`)}),(0,p.jsx)(`th`,{className:v,children:e(`common.description`,`Description`)}),(0,p.jsx)(`th`,{className:v,children:e(`finance.amount`,`Amount`)}),(0,p.jsx)(`th`,{className:v,children:e(`finance.balanceAfter`,`Balance after`)}),$&&(0,p.jsx)(`th`,{className:v,children:e(`common.actions`,`Actions`)})]})}),(0,p.jsx)(`tbody`,{children:cn.map(n=>{let r=n.amount>=0,ee=n.cost_center_id==null?null:(G||[]).find(e=>e.id===n.cost_center_id),te=nn.get(n.user_id),i=n.transaction_type===`print_charge`?he(n.description??null):null,a=i?.isPartial??!1;return(0,p.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/60 text-white`,children:[(0,p.jsx)(`td`,{className:y,children:ge(n.created_at,t.language)}),$&&(0,p.jsx)(`td`,{className:y,children:te||e(`finance.userWithId`,`User #{{id}}`,{id:n.user_id})}),(0,p.jsx)(`td`,{className:y,children:ee?.name||`-`}),(0,p.jsx)(`td`,{className:y,children:(0,p.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,p.jsx)(`span`,{children:un(n.transaction_type)}),a&&(0,p.jsx)(`span`,{className:`rounded border border-yellow-500/40 bg-yellow-500/10 px-2 py-0.5 text-[11px] text-yellow-300`,children:i&&i.partialType?e(`finance.partialStatus.${i.partialType}`,i.partialType):e(`finance.partial`,`Partial`)})]})}),(0,p.jsx)(`td`,{className:y,children:(i?.cleanedDescription??n.description)||`-`}),(0,p.jsxs)(`td`,{className:`${y} ${r?`text-green-400`:`text-red-400`}`,children:[r?`+`:`-`,Y,Math.abs(n.amount).toFixed(2)]}),(0,p.jsx)(`td`,{className:y,children:n.balance_after==null?`-`:`${n.balance_after<0?`-`:``}${Y}${Math.abs(n.balance_after).toFixed(2)}`}),$&&(0,p.jsx)(`td`,{className:y,children:(0,p.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,p.jsx)(u,{size:`sm`,variant:`secondary`,onClick:()=>Xt(n),disabled:Rt.isPending,children:(0,p.jsx)(ae,{className:`w-4 h-4`})}),(0,p.jsx)(u,{size:`sm`,variant:`danger`,onClick:()=>Tt(n.id),disabled:Lt.isPending,children:(0,p.jsx)(oe,{className:`w-4 h-4`})})]})})]},n.id)})})]})}),!Z&&cn.length>0&&(0,p.jsx)(`div`,{className:`flex justify-end pt-2 lg:pt-0`,children:(0,p.jsxs)(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[(0,p.jsx)(`button`,{type:`button`,onClick:()=>P(0),disabled:N===0||Z,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,"aria-label":e(`finance.first`,`First`),children:(0,p.jsx)(ne,{className:`w-4 h-4`})}),(0,p.jsx)(`button`,{type:`button`,onClick:()=>P(e=>Math.max(0,e-50)),disabled:N===0||Z,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,"aria-label":e(`finance.prev`,`Previous`),children:(0,p.jsx)(ue,{className:`w-4 h-4`})}),(0,p.jsx)(`span`,{className:`text-bambu-gray px-1 whitespace-nowrap`,children:e(`finance.pageNumberOf`,`Page {{page}} of {{total}}`,{page:ln,total:sn})}),(0,p.jsx)(`button`,{type:`button`,onClick:()=>P(e=>e+50),disabled:Z||ln>=sn,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,"aria-label":e(`finance.next`,`Next`),children:(0,p.jsx)(se,{className:`w-4 h-4`})}),(0,p.jsx)(`button`,{type:`button`,onClick:()=>P(Math.max(0,(sn-1)*50)),disabled:Z||ln>=sn,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,"aria-label":e(`finance.last`,`Last`),children:(0,p.jsx)(re,{className:`w-4 h-4`})})]})})]})]}),et&&nt!==null&&(0,p.jsx)(b,{title:e(`finance.editTransaction`,`Edit Transaction`),onClose:()=>tt(!1),size:`md`,children:(0,p.jsxs)(`div`,{className:`space-y-4`,children:[(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`common.user`,`User`)}),(0,p.jsxs)(`select`,{className:g,value:it||``,onChange:e=>at(e.target.value?Number(e.target.value):null),children:[(0,p.jsx)(`option`,{value:``,children:e(`finance.selectUser`,`Select user...`)}),X.map(e=>(0,p.jsx)(`option`,{value:e.id,children:e.username},e.id))]})]}),(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`finance.costCenter`,`Cost center (optional)`)}),(0,p.jsxs)(`select`,{className:g,value:ot||``,onChange:e=>st(e.target.value?Number(e.target.value):null),children:[(0,p.jsx)(`option`,{value:``,children:e(`finance.noCostCenter`,`Personal (no cost center)`)}),(G||[]).map(e=>(0,p.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`finance.amount`,`Amount`)}),(0,p.jsx)(`input`,{type:`number`,step:`0.01`,className:g,value:ct,onChange:e=>lt(e.target.value),placeholder:e(`finance.amountExample`,`e.g., 10.50`)})]}),(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`common.description`,`Description`)}),(0,p.jsx)(`textarea`,{className:`${g} resize-none`,rows:3,value:ut,onChange:e=>dt(e.target.value),placeholder:e(`finance.manualAdjustmentExample`,`e.g., Manual adjustment`)})]}),(0,p.jsxs)(`div`,{className:`flex justify-end gap-2 pt-4`,children:[(0,p.jsx)(u,{variant:`secondary`,onClick:()=>tt(!1),children:e(`common.cancel`,`Cancel`)}),(0,p.jsx)(u,{onClick:Zt,disabled:Rt.isPending,children:e(`common.save`,`Save`)})]})]})}),ft&&(0,p.jsx)(b,{title:e(`finance.addManualPrint`,`Add manual print`),onClose:()=>H(!1),size:`md`,children:(0,p.jsxs)(`div`,{className:`space-y-4`,children:[(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`common.user`,`User`)}),(0,p.jsxs)(`select`,{className:g,value:pt||``,onChange:e=>mt(e.target.value?Number(e.target.value):null),children:[(0,p.jsx)(`option`,{value:``,children:e(`finance.selectUser`,`Select user...`)}),X.map(e=>(0,p.jsx)(`option`,{value:e.id,children:e.username},e.id))]})]}),(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`finance.costCenter`,`Cost center`)}),(0,p.jsxs)(`select`,{className:g,value:ht||``,onChange:e=>gt(e.target.value?Number(e.target.value):null),children:[(0,p.jsx)(`option`,{value:``,children:e(`finance.selectCostCenter`,`Select cost center...`)}),(G||[]).map(e=>(0,p.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`finance.amount`,`Amount`)}),(0,p.jsx)(`input`,{type:`number`,step:`0.01`,className:g,value:_t,onChange:e=>vt(e.target.value),placeholder:e(`finance.amountExample`,`e.g., 4.00`)})]}),(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`common.description`,`Description`)}),(0,p.jsx)(`input`,{type:`text`,value:yt,onChange:e=>bt(e.target.value),placeholder:e(`finance.descriptionOptional`,`Description (optional)`),className:g})]}),(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{className:_,children:e(`common.date`,`Date`)}),(0,p.jsx)(`input`,{type:`datetime-local`,value:xt,onChange:e=>St(e.target.value),className:g})]}),(0,p.jsxs)(`div`,{className:`flex justify-end gap-2 pt-4`,children:[(0,p.jsx)(u,{variant:`secondary`,onClick:()=>H(!1),children:e(`common.cancel`,`Cancel`)}),(0,p.jsx)(u,{onClick:Qt,disabled:zt.isPending,children:zt.isPending?e(`common.saving`,`Saving...`):e(`finance.addManualPrint`,`Add manual print`)})]})]})}),U&&(0,p.jsx)(ce,{title:e(`common.delete`,`Delete`),message:e(`finance.confirmDeleteCostCenter`,`Delete cost center "{{name}}"?`,{name:U.name}),confirmText:e(`common.delete`,`Delete`),variant:`danger`,isLoading:It.isPending,onConfirm:Jt,onCancel:()=>Ct(null)}),wt!=null&&(0,p.jsx)(ce,{title:e(`finance.deleteTransaction`,`Delete transaction`),message:e(`finance.deleteTransactionConfirm`,`Delete this transaction? Balances will be recalculated automatically.`),confirmText:e(`common.delete`,`Delete`),variant:`danger`,isLoading:Lt.isPending,onConfirm:Yt,onCancel:()=>Tt(null)})]})]}):(0,p.jsxs)(`div`,{className:`p-4 md:p-8 space-y-6`,children:[(0,p.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,p.jsx)(me,{className:`h-6 w-6 text-bambu-green`}),(0,p.jsx)(`h1`,{className:`text-2xl font-bold text-white`,children:e(`finance.title`,`Finance`)})]}),(0,p.jsx)(`div`,{children:(0,p.jsx)(`p`,{className:`text-bambu-gray mt-2 max-w-2xl`,children:e(`finance.subtitle`,`Wallet, personal transactions, and cost centers`)})}),(0,p.jsx)(l,{children:(0,p.jsx)(c,{className:`py-8 text-center text-bambu-gray`,children:e(`finance.noAccess`,`You do not have permission to view finance data.`)})})]})}export{x as FinancePage}; \ No newline at end of file diff --git a/static/assets/GCodeViewerPage-CAOZmPME.js b/static/assets/GCodeViewerPage-BZpj3rht.js similarity index 97% rename from static/assets/GCodeViewerPage-CAOZmPME.js rename to static/assets/GCodeViewerPage-BZpj3rht.js index 0403981d4..5d5a91f3e 100644 --- a/static/assets/GCodeViewerPage-CAOZmPME.js +++ b/static/assets/GCodeViewerPage-BZpj3rht.js @@ -1 +1 @@ -import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,w as i}from"./client-DnySrlFv.js";import{t as a}from"./useQuery-BBCjCezC.js";import{t as o}from"./arrow-left-0Q6F2rjC.js";import{t as s}from"./GcodeToolpathViewer-Cg6UnTDw.js";import{Vn as c,Wn as l}from"./index-0t--Yqoi.js";var u=e(n(),1),d=t();function f(){let e=c(),[t,n]=l(),{t:f}=i(),p=t.get(`archive`),m=t.get(`library_file`),h=t.get(`plate`),g=a({queryKey:[`gcode-viewer-archive-colors`,p],queryFn:()=>r.getArchiveCapabilities(Number(p)),enabled:!!p,staleTime:5*6e4,retry:!1}),_=a({queryKey:[`gcode-viewer-library-colors`,m],queryFn:()=>r.getLibraryFilePlates(Number(m)),enabled:!!m,staleTime:5*6e4,retry:!1}),v=a({queryKey:[`gcode-viewer-archive-plates`,p],queryFn:()=>r.getArchivePlates(Number(p)),enabled:!!p,staleTime:5*6e4,retry:!1}),y=(0,u.useMemo)(()=>(p?v.data?.plates:_.data?.plates)??[],[p,v.data,_.data]),b=(0,u.useMemo)(()=>h?Number(h):y.length===0?null:Math.min(...y.map(e=>e.index)),[h,y]),x=e=>{if(e===b)return;let r=new URLSearchParams(t);r.set(`plate`,String(e)),n(r,{replace:!0})},S=(0,u.useMemo)(()=>{if(p)return g.data?.filament_colors;let e=y.find(e=>e.index===b)||y[0];if(!e?.filaments?.length)return;let t=[];for(let n of e.filaments){let e=Math.max(0,(n.slot_id??1)-1);n.color&&(t[e]=n.color)}return t.length>0?t:void 0},[p,g.data,y,b]),C=(0,u.useMemo)(()=>{let e=e=>h?`${e}?plate=${encodeURIComponent(h)}`:e;return p?e(r.getArchiveGcode(Number(p))):m?e(r.getLibraryFileGcodeUrl(Number(m))):null},[p,m,h]),w=()=>{window.history.length>1?e(-1):e(p?`/archives`:`/files`)},T=p?f(`gcodeViewer.backToArchives`,`Back to Archives`):f(`gcodeViewer.backToFiles`,`Back to File Manager`);return(0,d.jsxs)(`div`,{className:`flex flex-col min-h-[calc(100vh-64px)] lg:h-screen`,children:[(0,d.jsxs)(`div`,{className:`flex-shrink-0 px-4 py-2 border-b border-bambu-dark-tertiary flex flex-wrap items-center gap-x-4 gap-y-2`,children:[(0,d.jsxs)(`button`,{type:`button`,onClick:w,className:`inline-flex items-center gap-1.5 text-sm text-gray-700 dark:text-gray-300 hover:text-gray-900 dark:hover:text-white transition-colors`,children:[(0,d.jsx)(o,{className:`w-4 h-4`}),T]}),y.length>1&&(0,d.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,d.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:f(`gcodeViewer.plates`,`Plates`)}),y.map(e=>(0,d.jsx)(`button`,{type:`button`,onClick:()=>x(e.index),"aria-pressed":e.index===b,title:e.name??void 0,className:`px-2 py-0.5 rounded text-xs transition-colors ${e.index===b?`bg-bambu-green text-white`:`bg-bambu-dark-tertiary text-gray-700 dark:text-gray-300 hover:text-gray-900 dark:hover:text-white`}`,children:f(`gcodeViewer.plateN`,`Plate {{n}}`,{n:e.index})},e.index))]})]}),C?(0,d.jsx)(s,{gcodeUrl:C,filamentColors:S,className:`flex-1 min-h-0`}):(0,d.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-sm text-bambu-gray`,children:f(`gcodeViewer.noSource`,`No file was given to preview.`)})]})}export{f as GCodeViewerPage}; \ No newline at end of file +import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,w as i}from"./client-DnySrlFv.js";import{t as a}from"./useQuery-BBCjCezC.js";import{t as o}from"./arrow-left-0Q6F2rjC.js";import{t as s}from"./GcodeToolpathViewer-Cg6UnTDw.js";import{Vn as c,Wn as l}from"./index-Cxa-KVmA.js";var u=e(n(),1),d=t();function f(){let e=c(),[t,n]=l(),{t:f}=i(),p=t.get(`archive`),m=t.get(`library_file`),h=t.get(`plate`),g=a({queryKey:[`gcode-viewer-archive-colors`,p],queryFn:()=>r.getArchiveCapabilities(Number(p)),enabled:!!p,staleTime:5*6e4,retry:!1}),_=a({queryKey:[`gcode-viewer-library-colors`,m],queryFn:()=>r.getLibraryFilePlates(Number(m)),enabled:!!m,staleTime:5*6e4,retry:!1}),v=a({queryKey:[`gcode-viewer-archive-plates`,p],queryFn:()=>r.getArchivePlates(Number(p)),enabled:!!p,staleTime:5*6e4,retry:!1}),y=(0,u.useMemo)(()=>(p?v.data?.plates:_.data?.plates)??[],[p,v.data,_.data]),b=(0,u.useMemo)(()=>h?Number(h):y.length===0?null:Math.min(...y.map(e=>e.index)),[h,y]),x=e=>{if(e===b)return;let r=new URLSearchParams(t);r.set(`plate`,String(e)),n(r,{replace:!0})},S=(0,u.useMemo)(()=>{if(p)return g.data?.filament_colors;let e=y.find(e=>e.index===b)||y[0];if(!e?.filaments?.length)return;let t=[];for(let n of e.filaments){let e=Math.max(0,(n.slot_id??1)-1);n.color&&(t[e]=n.color)}return t.length>0?t:void 0},[p,g.data,y,b]),C=(0,u.useMemo)(()=>{let e=e=>h?`${e}?plate=${encodeURIComponent(h)}`:e;return p?e(r.getArchiveGcode(Number(p))):m?e(r.getLibraryFileGcodeUrl(Number(m))):null},[p,m,h]),w=()=>{window.history.length>1?e(-1):e(p?`/archives`:`/files`)},T=p?f(`gcodeViewer.backToArchives`,`Back to Archives`):f(`gcodeViewer.backToFiles`,`Back to File Manager`);return(0,d.jsxs)(`div`,{className:`flex flex-col min-h-[calc(100vh-64px)] lg:h-screen`,children:[(0,d.jsxs)(`div`,{className:`flex-shrink-0 px-4 py-2 border-b border-bambu-dark-tertiary flex flex-wrap items-center gap-x-4 gap-y-2`,children:[(0,d.jsxs)(`button`,{type:`button`,onClick:w,className:`inline-flex items-center gap-1.5 text-sm text-gray-700 dark:text-gray-300 hover:text-gray-900 dark:hover:text-white transition-colors`,children:[(0,d.jsx)(o,{className:`w-4 h-4`}),T]}),y.length>1&&(0,d.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,d.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:f(`gcodeViewer.plates`,`Plates`)}),y.map(e=>(0,d.jsx)(`button`,{type:`button`,onClick:()=>x(e.index),"aria-pressed":e.index===b,title:e.name??void 0,className:`px-2 py-0.5 rounded text-xs transition-colors ${e.index===b?`bg-bambu-green text-white`:`bg-bambu-dark-tertiary text-gray-700 dark:text-gray-300 hover:text-gray-900 dark:hover:text-white`}`,children:f(`gcodeViewer.plateN`,`Plate {{n}}`,{n:e.index})},e.index))]})]}),C?(0,d.jsx)(s,{gcodeUrl:C,filamentColors:S,className:`flex-1 min-h-0`}):(0,d.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-sm text-bambu-gray`,children:f(`gcodeViewer.noSource`,`No file was given to preview.`)})]})}export{f as GCodeViewerPage}; \ No newline at end of file diff --git a/static/assets/GroupEditPage-BfkGtN0q.js b/static/assets/GroupEditPage-CMQ5Sk5q.js similarity index 99% rename from static/assets/GroupEditPage-BfkGtN0q.js rename to static/assets/GroupEditPage-CMQ5Sk5q.js index a113dccb2..4956dbb23 100644 --- a/static/assets/GroupEditPage-BfkGtN0q.js +++ b/static/assets/GroupEditPage-CMQ5Sk5q.js @@ -1 +1 @@ -import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,w as i}from"./client-DnySrlFv.js";import{n as a}from"./QueryClientProvider-Ce8_sN3w.js";import{t as o}from"./useQuery-BBCjCezC.js";import{t as s}from"./useMutation-B-Tr2hIP.js";import{t as ee}from"./arrow-left-0Q6F2rjC.js";import{t as c}from"./check-Ck0cMLU4.js";import{n as l}from"./ToastContext-BRX0SW3C.js";import{t as u}from"./loader-circle-BEmFtawu.js";import{t as d}from"./minus-DypeGjGR.js";import{t as f}from"./search-0n0CBc74.js";import{t as p}from"./shield-bODVqOJd.js";import{t as m}from"./triangle-alert-Dt_1FcBy.js";import{t as h}from"./Card-Bzc64K35.js";import{t as g}from"./Button-DDr6eAFy.js";import{Jt as _,Rn as v,Un as y,Ut as b,Vn as x}from"./index-0t--Yqoi.js";var S=e(n(),1),C=t();function w(){let{id:e}=y(),t=x(),n=a(),{t:w}=i(),{showToast:T}=l(),E=!!e,[D,O]=(0,S.useState)(``),[k,A]=(0,S.useState)(``),[j,M]=(0,S.useState)([]),[N,P]=(0,S.useState)(``),[F,I]=(0,S.useState)(!1),{data:L,isLoading:R}=o({queryKey:[`group`,e],queryFn:()=>r.getGroup(Number(e)),enabled:E}),{data:z,isLoading:B}=o({queryKey:[`permissions`],queryFn:()=>r.getPermissions()});E&&L&&!F&&(O(L.name),A(L.description||``),M(L.permissions),I(!0));let V=s({mutationFn:e=>r.createGroup(e),onSuccess:()=>{n.invalidateQueries({queryKey:[`groups`]}),n.invalidateQueries({queryKey:[`group`]}),T(w(`groups.toast.created`)),t(`/settings?tab=users`)},onError:e=>{T(e.message,`error`)}}),H=s({mutationFn:t=>r.updateGroup(Number(e),t),onSuccess:r=>{n.invalidateQueries({queryKey:[`groups`]}),r&&n.setQueryData([`group`,e],r),T(w(`groups.toast.updated`)),t(`/settings?tab=users`)},onError:e=>{T(e.message,`error`)}}),U=V.isPending||H.isPending,W=E&&L?.is_system===!0&&L.name===`Administrators`,G=()=>{if(!D.trim()){T(w(`groups.toast.enterGroupName`),`error`);return}if(E){let e=!L||j.length!==L.permissions.length||j.some(e=>!L.permissions.includes(e));H.mutate({name:D===L?.name?void 0:D,description:k,permissions:L?.is_system&&!e?void 0:j})}else V.mutate({name:D,description:k||void 0,permissions:j})},K=e=>{M(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},q=(e,t)=>{let n=e.permissions.map(e=>e.value);M(e=>{let r=e.filter(e=>!n.includes(e));return t?[...r,...n]:r})},J=e=>e.permissions.every(e=>j.includes(e.value)),Y=e=>{let t=e.permissions.filter(e=>j.includes(e.value)).length;return t>0&&t{z&&M(z.all_permissions)},Z=()=>{M([])},Q=N.toLowerCase(),$=(0,S.useMemo)(()=>z?Q?z.categories.map(e=>({...e,permissions:e.permissions.filter(e=>e.label.toLowerCase().includes(Q))})).filter(e=>e.permissions.length>0):z.categories:[],[z,Q]),te=z?.all_permissions.length??0;return R||B?(0,C.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,C.jsx)(u,{className:`w-8 h-8 text-bambu-green animate-spin`})}):(0,C.jsxs)(`div`,{className:`space-y-6 max-w-5xl mx-auto`,children:[(0,C.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,C.jsx)(`button`,{onClick:()=>t(`/settings?tab=users`),className:`p-2 rounded-lg hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white transition-colors`,children:(0,C.jsx)(ee,{className:`w-5 h-5`})}),(0,C.jsx)(`h1`,{className:`text-xl font-bold text-white`,children:w(E?`groups.editor.title`:`groups.editor.createTitle`)})]}),E&&L?.is_system&&(0,C.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-3 rounded-lg bg-yellow-50 dark:bg-yellow-500/10 border border-yellow-300 dark:border-yellow-500/20 text-yellow-700 dark:text-yellow-400 text-sm`,children:[(0,C.jsx)(m,{className:`w-4 h-4 shrink-0`}),w(`groups.form.systemGroupWarning`)]}),(0,C.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:[(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:w(`groups.form.groupName`)}),(0,C.jsx)(`input`,{type:`text`,value:D,onChange:e=>O(e.target.value),disabled:E&&L?.is_system,className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors disabled:opacity-50`,placeholder:w(`groups.form.groupNamePlaceholder`)})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:w(`groups.form.description`)}),(0,C.jsx)(`input`,{type:`text`,value:k,onChange:e=>A(e.target.value),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:w(`groups.form.descriptionPlaceholder`)})]})]}),(0,C.jsx)(h,{children:(0,C.jsxs)(`div`,{className:`p-4 flex flex-wrap items-center justify-between gap-3`,children:[(0,C.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,C.jsx)(_,{className:`w-4 h-4 text-bambu-gray shrink-0`}),(0,C.jsx)(`span`,{className:`text-white font-medium text-sm`,children:w(`groups.editor.printerAccess`)}),(0,C.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:W?w(`groups.editor.adminsSeeAllPrinters`):E?L?.restrict_printers?w(`groups.editor.printerAccessLimited`,{printers:L.printer_ids.length,locations:L.locations?.length??0}):w(`groups.editor.printerAccessOpen`):w(`groups.editor.printerAccessAfterCreate`)})]}),E&&!W&&(0,C.jsx)(v,{to:`/settings?tab=users&sub=printer-access&group=${e}`,className:`text-sm text-bambu-green hover:underline shrink-0`,children:w(`groups.editor.managePrinterAccess`)})]})}),(0,C.jsxs)(`div`,{className:`flex items-center justify-between flex-wrap gap-3`,children:[(0,C.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,C.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[w(`groups.editor.permissionsSelected`,{count:j.length}),` / `,te]}),(0,C.jsx)(g,{size:`sm`,variant:`ghost`,onClick:X,children:w(`groups.editor.selectAll`)}),(0,C.jsx)(g,{size:`sm`,variant:`ghost`,onClick:Z,children:w(`groups.editor.clearAll`)})]}),(0,C.jsxs)(`div`,{className:`relative`,children:[(0,C.jsx)(f,{className:`w-4 h-4 absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray`}),(0,C.jsx)(`input`,{type:`text`,value:N,onChange:e=>P(e.target.value),placeholder:w(`groups.editor.search`),className:`pl-9 pr-4 py-2 text-sm bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors w-64`})]})]}),$.length===0?(0,C.jsx)(`div`,{className:`text-center py-12 text-bambu-gray`,children:w(`groups.editor.noResults`)}):(0,C.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:$.map(e=>{let t=z.categories.find(t=>t.name===e.name),n=t.permissions.filter(e=>j.includes(e.value)).length,r=t.permissions.length,i=J(t),a=Y(t);return(0,C.jsxs)(h,{children:[(0,C.jsxs)(`div`,{className:`sticky top-0 z-10 flex items-center justify-between px-4 py-3 bg-bambu-dark-secondary border-b border-bambu-dark-tertiary rounded-t-xl`,children:[(0,C.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,C.jsxs)(`button`,{type:`button`,onClick:()=>q(t,!i),className:`w-5 h-5 rounded border flex items-center justify-center transition-colors shrink-0 ${i?`bg-bambu-green border-bambu-green`:a?`bg-bambu-green/50 border-bambu-green`:`border-bambu-gray hover:border-white`}`,children:[i&&(0,C.jsx)(c,{className:`w-3 h-3 text-white`}),a&&!i&&(0,C.jsx)(d,{className:`w-3 h-3 text-white`})]}),(0,C.jsx)(p,{className:`w-4 h-4 text-bambu-gray shrink-0`}),(0,C.jsx)(`span`,{className:`text-white font-medium text-sm`,children:e.name})]}),(0,C.jsxs)(`span`,{className:`text-xs text-bambu-gray tabular-nums`,children:[n,`/`,r]})]}),(0,C.jsx)(`div`,{className:`p-3 space-y-1`,children:e.permissions.map(e=>(0,C.jsxs)(`label`,{className:`flex items-center gap-3 px-2 py-1.5 rounded hover:bg-bambu-dark-secondary cursor-pointer`,children:[(0,C.jsx)(`input`,{type:`checkbox`,checked:j.includes(e.value),onChange:()=>K(e.value),className:`w-4 h-4 shrink-0 rounded border-bambu-gray text-bambu-green focus:ring-bambu-green focus:ring-offset-0 bg-bambu-dark-secondary`}),(0,C.jsxs)(`span`,{className:`flex flex-col`,children:[(0,C.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.label}),e.value===`websocket:connect`&&(0,C.jsx)(`span`,{className:`text-xs text-bambu-gray/60`,children:w(`groups.editor.websocketHint`)})]})]},e.value))})]},e.name)})}),(0,C.jsx)(`div`,{className:`h-16`}),(0,C.jsxs)(`div`,{className:`fixed bottom-0 left-0 right-0 z-20 px-6 py-3 bg-bambu-dark-secondary border-t border-bambu-dark-tertiary flex items-center justify-center gap-3`,children:[(0,C.jsx)(g,{variant:`secondary`,onClick:()=>t(`/settings?tab=users`),children:w(`common.cancel`)}),(0,C.jsx)(g,{onClick:G,disabled:U||!D.trim(),children:U?(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)(u,{className:`w-4 h-4 animate-spin`}),w(`common.saving`)]}):(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)(b,{className:`w-4 h-4`}),w(`common.save`)]})})]})]})}export{w as GroupEditPage}; \ No newline at end of file +import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,w as i}from"./client-DnySrlFv.js";import{n as a}from"./QueryClientProvider-Ce8_sN3w.js";import{t as o}from"./useQuery-BBCjCezC.js";import{t as s}from"./useMutation-B-Tr2hIP.js";import{t as ee}from"./arrow-left-0Q6F2rjC.js";import{t as c}from"./check-Ck0cMLU4.js";import{n as l}from"./ToastContext-BRX0SW3C.js";import{t as u}from"./loader-circle-BEmFtawu.js";import{t as d}from"./minus-DypeGjGR.js";import{t as f}from"./search-0n0CBc74.js";import{t as p}from"./shield-bODVqOJd.js";import{t as m}from"./triangle-alert-Dt_1FcBy.js";import{t as h}from"./Card-Bzc64K35.js";import{t as g}from"./Button-DDr6eAFy.js";import{Jt as _,Rn as v,Un as y,Ut as b,Vn as x}from"./index-Cxa-KVmA.js";var S=e(n(),1),C=t();function w(){let{id:e}=y(),t=x(),n=a(),{t:w}=i(),{showToast:T}=l(),E=!!e,[D,O]=(0,S.useState)(``),[k,A]=(0,S.useState)(``),[j,M]=(0,S.useState)([]),[N,P]=(0,S.useState)(``),[F,I]=(0,S.useState)(!1),{data:L,isLoading:R}=o({queryKey:[`group`,e],queryFn:()=>r.getGroup(Number(e)),enabled:E}),{data:z,isLoading:B}=o({queryKey:[`permissions`],queryFn:()=>r.getPermissions()});E&&L&&!F&&(O(L.name),A(L.description||``),M(L.permissions),I(!0));let V=s({mutationFn:e=>r.createGroup(e),onSuccess:()=>{n.invalidateQueries({queryKey:[`groups`]}),n.invalidateQueries({queryKey:[`group`]}),T(w(`groups.toast.created`)),t(`/settings?tab=users`)},onError:e=>{T(e.message,`error`)}}),H=s({mutationFn:t=>r.updateGroup(Number(e),t),onSuccess:r=>{n.invalidateQueries({queryKey:[`groups`]}),r&&n.setQueryData([`group`,e],r),T(w(`groups.toast.updated`)),t(`/settings?tab=users`)},onError:e=>{T(e.message,`error`)}}),U=V.isPending||H.isPending,W=E&&L?.is_system===!0&&L.name===`Administrators`,G=()=>{if(!D.trim()){T(w(`groups.toast.enterGroupName`),`error`);return}if(E){let e=!L||j.length!==L.permissions.length||j.some(e=>!L.permissions.includes(e));H.mutate({name:D===L?.name?void 0:D,description:k,permissions:L?.is_system&&!e?void 0:j})}else V.mutate({name:D,description:k||void 0,permissions:j})},K=e=>{M(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},q=(e,t)=>{let n=e.permissions.map(e=>e.value);M(e=>{let r=e.filter(e=>!n.includes(e));return t?[...r,...n]:r})},J=e=>e.permissions.every(e=>j.includes(e.value)),Y=e=>{let t=e.permissions.filter(e=>j.includes(e.value)).length;return t>0&&t{z&&M(z.all_permissions)},Z=()=>{M([])},Q=N.toLowerCase(),$=(0,S.useMemo)(()=>z?Q?z.categories.map(e=>({...e,permissions:e.permissions.filter(e=>e.label.toLowerCase().includes(Q))})).filter(e=>e.permissions.length>0):z.categories:[],[z,Q]),te=z?.all_permissions.length??0;return R||B?(0,C.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,C.jsx)(u,{className:`w-8 h-8 text-bambu-green animate-spin`})}):(0,C.jsxs)(`div`,{className:`space-y-6 max-w-5xl mx-auto`,children:[(0,C.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,C.jsx)(`button`,{onClick:()=>t(`/settings?tab=users`),className:`p-2 rounded-lg hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white transition-colors`,children:(0,C.jsx)(ee,{className:`w-5 h-5`})}),(0,C.jsx)(`h1`,{className:`text-xl font-bold text-white`,children:w(E?`groups.editor.title`:`groups.editor.createTitle`)})]}),E&&L?.is_system&&(0,C.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-3 rounded-lg bg-yellow-50 dark:bg-yellow-500/10 border border-yellow-300 dark:border-yellow-500/20 text-yellow-700 dark:text-yellow-400 text-sm`,children:[(0,C.jsx)(m,{className:`w-4 h-4 shrink-0`}),w(`groups.form.systemGroupWarning`)]}),(0,C.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:[(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:w(`groups.form.groupName`)}),(0,C.jsx)(`input`,{type:`text`,value:D,onChange:e=>O(e.target.value),disabled:E&&L?.is_system,className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors disabled:opacity-50`,placeholder:w(`groups.form.groupNamePlaceholder`)})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:w(`groups.form.description`)}),(0,C.jsx)(`input`,{type:`text`,value:k,onChange:e=>A(e.target.value),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:w(`groups.form.descriptionPlaceholder`)})]})]}),(0,C.jsx)(h,{children:(0,C.jsxs)(`div`,{className:`p-4 flex flex-wrap items-center justify-between gap-3`,children:[(0,C.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,C.jsx)(_,{className:`w-4 h-4 text-bambu-gray shrink-0`}),(0,C.jsx)(`span`,{className:`text-white font-medium text-sm`,children:w(`groups.editor.printerAccess`)}),(0,C.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:W?w(`groups.editor.adminsSeeAllPrinters`):E?L?.restrict_printers?w(`groups.editor.printerAccessLimited`,{printers:L.printer_ids.length,locations:L.locations?.length??0}):w(`groups.editor.printerAccessOpen`):w(`groups.editor.printerAccessAfterCreate`)})]}),E&&!W&&(0,C.jsx)(v,{to:`/settings?tab=users&sub=printer-access&group=${e}`,className:`text-sm text-bambu-green hover:underline shrink-0`,children:w(`groups.editor.managePrinterAccess`)})]})}),(0,C.jsxs)(`div`,{className:`flex items-center justify-between flex-wrap gap-3`,children:[(0,C.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,C.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[w(`groups.editor.permissionsSelected`,{count:j.length}),` / `,te]}),(0,C.jsx)(g,{size:`sm`,variant:`ghost`,onClick:X,children:w(`groups.editor.selectAll`)}),(0,C.jsx)(g,{size:`sm`,variant:`ghost`,onClick:Z,children:w(`groups.editor.clearAll`)})]}),(0,C.jsxs)(`div`,{className:`relative`,children:[(0,C.jsx)(f,{className:`w-4 h-4 absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray`}),(0,C.jsx)(`input`,{type:`text`,value:N,onChange:e=>P(e.target.value),placeholder:w(`groups.editor.search`),className:`pl-9 pr-4 py-2 text-sm bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors w-64`})]})]}),$.length===0?(0,C.jsx)(`div`,{className:`text-center py-12 text-bambu-gray`,children:w(`groups.editor.noResults`)}):(0,C.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:$.map(e=>{let t=z.categories.find(t=>t.name===e.name),n=t.permissions.filter(e=>j.includes(e.value)).length,r=t.permissions.length,i=J(t),a=Y(t);return(0,C.jsxs)(h,{children:[(0,C.jsxs)(`div`,{className:`sticky top-0 z-10 flex items-center justify-between px-4 py-3 bg-bambu-dark-secondary border-b border-bambu-dark-tertiary rounded-t-xl`,children:[(0,C.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,C.jsxs)(`button`,{type:`button`,onClick:()=>q(t,!i),className:`w-5 h-5 rounded border flex items-center justify-center transition-colors shrink-0 ${i?`bg-bambu-green border-bambu-green`:a?`bg-bambu-green/50 border-bambu-green`:`border-bambu-gray hover:border-white`}`,children:[i&&(0,C.jsx)(c,{className:`w-3 h-3 text-white`}),a&&!i&&(0,C.jsx)(d,{className:`w-3 h-3 text-white`})]}),(0,C.jsx)(p,{className:`w-4 h-4 text-bambu-gray shrink-0`}),(0,C.jsx)(`span`,{className:`text-white font-medium text-sm`,children:e.name})]}),(0,C.jsxs)(`span`,{className:`text-xs text-bambu-gray tabular-nums`,children:[n,`/`,r]})]}),(0,C.jsx)(`div`,{className:`p-3 space-y-1`,children:e.permissions.map(e=>(0,C.jsxs)(`label`,{className:`flex items-center gap-3 px-2 py-1.5 rounded hover:bg-bambu-dark-secondary cursor-pointer`,children:[(0,C.jsx)(`input`,{type:`checkbox`,checked:j.includes(e.value),onChange:()=>K(e.value),className:`w-4 h-4 shrink-0 rounded border-bambu-gray text-bambu-green focus:ring-bambu-green focus:ring-offset-0 bg-bambu-dark-secondary`}),(0,C.jsxs)(`span`,{className:`flex flex-col`,children:[(0,C.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.label}),e.value===`websocket:connect`&&(0,C.jsx)(`span`,{className:`text-xs text-bambu-gray/60`,children:w(`groups.editor.websocketHint`)})]})]},e.value))})]},e.name)})}),(0,C.jsx)(`div`,{className:`h-16`}),(0,C.jsxs)(`div`,{className:`fixed bottom-0 left-0 right-0 z-20 px-6 py-3 bg-bambu-dark-secondary border-t border-bambu-dark-tertiary flex items-center justify-center gap-3`,children:[(0,C.jsx)(g,{variant:`secondary`,onClick:()=>t(`/settings?tab=users`),children:w(`common.cancel`)}),(0,C.jsx)(g,{onClick:G,disabled:U||!D.trim(),children:U?(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)(u,{className:`w-4 h-4 animate-spin`}),w(`common.saving`)]}):(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)(b,{className:`w-4 h-4`}),w(`common.save`)]})})]})]})}export{w as GroupEditPage}; \ No newline at end of file diff --git a/static/assets/ImagePreviewModal-VVWd1NOq.js b/static/assets/ImagePreviewModal-NAGAMcx7.js similarity index 98% rename from static/assets/ImagePreviewModal-VVWd1NOq.js rename to static/assets/ImagePreviewModal-NAGAMcx7.js index 7694ad4bb..15f805bc0 100644 --- a/static/assets/ImagePreviewModal-VVWd1NOq.js +++ b/static/assets/ImagePreviewModal-NAGAMcx7.js @@ -1 +1 @@ -import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,l as i,w as a}from"./client-DnySrlFv.js";import{t as o}from"./loader-circle-BEmFtawu.js";import{n as s,t as c}from"./zoom-out-DNNe6DMN.js";import{t as l}from"./file-DDkFXH-b.js";import{Gt as u,un as d}from"./index-0t--Yqoi.js";import{n as f,r as p,t as m}from"./usePreviewFullscreen-ButueZqN.js";var h=e(n(),1),g=t(),_=.4,v=8,y=1.25,b=30,x=Math.log(y)/b,S=e=>Math.min(v,Math.max(_,e)),C={x:0,y:0};function w(e){return e.deltaMode===1?e.deltaY*16:e.deltaMode===2?e.deltaY*100:e.deltaY}function T({libraryFileId:e,filename:t,fileSize:n,onClose:_}){let{t:v}=a(),T=m(),{isFullscreen:E,toggleFullscreen:D}=T,O=(0,h.useRef)(null),k=(0,h.useRef)(null),[A,j]=(0,h.useState)(null),[M,N]=(0,h.useState)(!1),[P,F]=(0,h.useState)(null),[I,L]=(0,h.useState)(1),[R,z]=(0,h.useState)(C),[B,V]=(0,h.useState)(!1),H=(0,h.useRef)(1),U=(0,h.useRef)(C),W=(0,h.useRef)(new Map),G=(0,h.useRef)(null),K=(0,h.useCallback)((e,t)=>{let n=O.current,r=k.current;if(!n||!r)return e;let i=Math.max(0,(r.offsetWidth*t-n.clientWidth)/2),a=Math.max(0,(r.offsetHeight*t-n.clientHeight)/2);return{x:Math.min(i,Math.max(-i,e.x)),y:Math.min(a,Math.max(-a,e.y))}},[]),q=(0,h.useCallback)((e,t)=>{H.current=e,U.current=t,L(e),z(t)},[]),J=(0,h.useCallback)((e,t,n)=>{let r=H.current,i=S(r*e);if(i===r)return;let a=O.current,o=U.current,s={x:o.x*(i/r),y:o.y*(i/r)};if(a){let e=a.getBoundingClientRect(),c=(t??e.left+e.width/2)-(e.left+e.width/2),l=(n??e.top+e.height/2)-(e.top+e.height/2),u=i/r;s={x:c-(c-o.x)*u,y:l-(l-o.y)*u}}q(i,K(s,i))},[K,q]),Y=(0,h.useCallback)(()=>q(1,C),[q]);(0,h.useEffect)(()=>{let t=!1,a=null;if(j(null),N(!1),F(null),q(1,C),n>52428800){F(v(`fileManager.preview.tooLarge`,{size:l(n)}));return}let o={},s=i();return s&&(o.Authorization=`Bearer ${s}`),(async()=>{let n=await fetch(r.getLibraryFileDownloadUrl(e),{headers:o});if(!n.ok)throw Error(`HTTP ${n.status}`);let i=await n.blob();t||(a=URL.createObjectURL(i),j(a))})().catch(e=>{console.error(`[image-preview] load failed`,e),t||F(v(`fileManager.preview.error`))}),()=>{t=!0,a&&URL.revokeObjectURL(a)}},[e,n,v,q]),(0,h.useEffect)(()=>{let e=e=>{e.ctrlKey||e.metaKey||e.altKey||(e.key===`+`||e.key===`=`?(e.preventDefault(),J(y)):e.key===`-`?(e.preventDefault(),J(1/y)):e.key===`0`&&(e.preventDefault(),Y()))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[Y,J]),(0,h.useEffect)(()=>{let e=O.current;if(!e)return;let t=e=>{e.preventDefault();let t=Math.max(-30,Math.min(b,w(e)));J(Math.exp(-t*x),e.clientX,e.clientY)};return e.addEventListener(`wheel`,t,{passive:!1}),()=>e.removeEventListener(`wheel`,t)},[J,A]);let X=e=>{W.current.set(e.pointerId,{x:e.clientX,y:e.clientY}),G.current=null,W.current.size===1&&H.current>1&&(e.currentTarget.setPointerCapture(e.pointerId),V(!0))},Z=e=>{W.current.delete(e.pointerId),G.current=null,W.current.size===0&&V(!1)},Q=e=>{let t=W.current,n=t.get(e.pointerId);if(!n)return;if(e.pointerType===`mouse`&&e.buttons===0){Z(e);return}if(t.set(e.pointerId,{x:e.clientX,y:e.clientY}),t.size===1){if(H.current<=1)return;let t={x:U.current.x+(e.clientX-n.x),y:U.current.y+(e.clientY-n.y)};q(H.current,K(t,H.current));return}if(t.size!==2)return;let[r,i]=Array.from(t.values()),a=Math.hypot(r.x-i.x,r.y-i.y),o=G.current;G.current=a,o!=null&&o>0&&a>0&&J(a/o,(r.x+i.x)/2,(r.y+i.y)/2)},$=I>1;return(0,g.jsx)(f,{title:t,fullscreen:T,onClose:_,icon:(0,g.jsx)(d,{className:`w-5 h-5 text-bambu-green flex-shrink-0`}),actions:A?(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(`button`,{onClick:()=>J(1/y),className:p,"aria-label":v(`fileManager.preview.zoomOut`),children:(0,g.jsx)(c,{className:`w-4 h-4`})}),(0,g.jsx)(`button`,{onClick:()=>J(y),className:p,"aria-label":v(`fileManager.preview.zoomIn`),children:(0,g.jsx)(s,{className:`w-4 h-4`})}),(0,g.jsx)(`button`,{onClick:Y,className:p,"aria-label":v(`fileManager.preview.resetZoom`),children:(0,g.jsx)(u,{className:`w-4 h-4`})})]}):void 0,children:(0,g.jsx)(`div`,{ref:O,"data-testid":`image-preview-content`,className:`relative flex-1 min-h-0 overflow-hidden bg-bambu-dark flex items-center justify-center touch-none ${E?``:`rounded-b-lg`} ${$?B?`cursor-grabbing`:`cursor-grab`:``}`,onDoubleClick:D,onPointerDown:X,onPointerMove:Q,onPointerUp:Z,onPointerCancel:Z,onPointerLeave:Z,children:P?(0,g.jsx)(`p`,{className:`text-bambu-gray text-center p-6`,children:P}):(0,g.jsxs)(g.Fragment,{children:[A&&(0,g.jsx)(`img`,{ref:k,src:A,alt:t,draggable:!1,onLoad:()=>N(!0),onError:()=>F(v(`fileManager.preview.error`)),style:{transform:`translate(${R.x}px, ${R.y}px) scale(${I})`},className:`max-w-full max-h-full object-contain select-none`}),!M&&(0,g.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center pointer-events-none`,children:(0,g.jsx)(o,{className:`w-8 h-8 text-bambu-green animate-spin`})})]})})})}export{T as ImagePreviewModal}; \ No newline at end of file +import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,l as i,w as a}from"./client-DnySrlFv.js";import{t as o}from"./loader-circle-BEmFtawu.js";import{n as s,t as c}from"./zoom-out-DNNe6DMN.js";import{t as l}from"./file-DDkFXH-b.js";import{Gt as u,un as d}from"./index-Cxa-KVmA.js";import{n as f,r as p,t as m}from"./usePreviewFullscreen-ButueZqN.js";var h=e(n(),1),g=t(),_=.4,v=8,y=1.25,b=30,x=Math.log(y)/b,S=e=>Math.min(v,Math.max(_,e)),C={x:0,y:0};function w(e){return e.deltaMode===1?e.deltaY*16:e.deltaMode===2?e.deltaY*100:e.deltaY}function T({libraryFileId:e,filename:t,fileSize:n,onClose:_}){let{t:v}=a(),T=m(),{isFullscreen:E,toggleFullscreen:D}=T,O=(0,h.useRef)(null),k=(0,h.useRef)(null),[A,j]=(0,h.useState)(null),[M,N]=(0,h.useState)(!1),[P,F]=(0,h.useState)(null),[I,L]=(0,h.useState)(1),[R,z]=(0,h.useState)(C),[B,V]=(0,h.useState)(!1),H=(0,h.useRef)(1),U=(0,h.useRef)(C),W=(0,h.useRef)(new Map),G=(0,h.useRef)(null),K=(0,h.useCallback)((e,t)=>{let n=O.current,r=k.current;if(!n||!r)return e;let i=Math.max(0,(r.offsetWidth*t-n.clientWidth)/2),a=Math.max(0,(r.offsetHeight*t-n.clientHeight)/2);return{x:Math.min(i,Math.max(-i,e.x)),y:Math.min(a,Math.max(-a,e.y))}},[]),q=(0,h.useCallback)((e,t)=>{H.current=e,U.current=t,L(e),z(t)},[]),J=(0,h.useCallback)((e,t,n)=>{let r=H.current,i=S(r*e);if(i===r)return;let a=O.current,o=U.current,s={x:o.x*(i/r),y:o.y*(i/r)};if(a){let e=a.getBoundingClientRect(),c=(t??e.left+e.width/2)-(e.left+e.width/2),l=(n??e.top+e.height/2)-(e.top+e.height/2),u=i/r;s={x:c-(c-o.x)*u,y:l-(l-o.y)*u}}q(i,K(s,i))},[K,q]),Y=(0,h.useCallback)(()=>q(1,C),[q]);(0,h.useEffect)(()=>{let t=!1,a=null;if(j(null),N(!1),F(null),q(1,C),n>52428800){F(v(`fileManager.preview.tooLarge`,{size:l(n)}));return}let o={},s=i();return s&&(o.Authorization=`Bearer ${s}`),(async()=>{let n=await fetch(r.getLibraryFileDownloadUrl(e),{headers:o});if(!n.ok)throw Error(`HTTP ${n.status}`);let i=await n.blob();t||(a=URL.createObjectURL(i),j(a))})().catch(e=>{console.error(`[image-preview] load failed`,e),t||F(v(`fileManager.preview.error`))}),()=>{t=!0,a&&URL.revokeObjectURL(a)}},[e,n,v,q]),(0,h.useEffect)(()=>{let e=e=>{e.ctrlKey||e.metaKey||e.altKey||(e.key===`+`||e.key===`=`?(e.preventDefault(),J(y)):e.key===`-`?(e.preventDefault(),J(1/y)):e.key===`0`&&(e.preventDefault(),Y()))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[Y,J]),(0,h.useEffect)(()=>{let e=O.current;if(!e)return;let t=e=>{e.preventDefault();let t=Math.max(-30,Math.min(b,w(e)));J(Math.exp(-t*x),e.clientX,e.clientY)};return e.addEventListener(`wheel`,t,{passive:!1}),()=>e.removeEventListener(`wheel`,t)},[J,A]);let X=e=>{W.current.set(e.pointerId,{x:e.clientX,y:e.clientY}),G.current=null,W.current.size===1&&H.current>1&&(e.currentTarget.setPointerCapture(e.pointerId),V(!0))},Z=e=>{W.current.delete(e.pointerId),G.current=null,W.current.size===0&&V(!1)},Q=e=>{let t=W.current,n=t.get(e.pointerId);if(!n)return;if(e.pointerType===`mouse`&&e.buttons===0){Z(e);return}if(t.set(e.pointerId,{x:e.clientX,y:e.clientY}),t.size===1){if(H.current<=1)return;let t={x:U.current.x+(e.clientX-n.x),y:U.current.y+(e.clientY-n.y)};q(H.current,K(t,H.current));return}if(t.size!==2)return;let[r,i]=Array.from(t.values()),a=Math.hypot(r.x-i.x,r.y-i.y),o=G.current;G.current=a,o!=null&&o>0&&a>0&&J(a/o,(r.x+i.x)/2,(r.y+i.y)/2)},$=I>1;return(0,g.jsx)(f,{title:t,fullscreen:T,onClose:_,icon:(0,g.jsx)(d,{className:`w-5 h-5 text-bambu-green flex-shrink-0`}),actions:A?(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(`button`,{onClick:()=>J(1/y),className:p,"aria-label":v(`fileManager.preview.zoomOut`),children:(0,g.jsx)(c,{className:`w-4 h-4`})}),(0,g.jsx)(`button`,{onClick:()=>J(y),className:p,"aria-label":v(`fileManager.preview.zoomIn`),children:(0,g.jsx)(s,{className:`w-4 h-4`})}),(0,g.jsx)(`button`,{onClick:Y,className:p,"aria-label":v(`fileManager.preview.resetZoom`),children:(0,g.jsx)(u,{className:`w-4 h-4`})})]}):void 0,children:(0,g.jsx)(`div`,{ref:O,"data-testid":`image-preview-content`,className:`relative flex-1 min-h-0 overflow-hidden bg-bambu-dark flex items-center justify-center touch-none ${E?``:`rounded-b-lg`} ${$?B?`cursor-grabbing`:`cursor-grab`:``}`,onDoubleClick:D,onPointerDown:X,onPointerMove:Q,onPointerUp:Z,onPointerCancel:Z,onPointerLeave:Z,children:P?(0,g.jsx)(`p`,{className:`text-bambu-gray text-center p-6`,children:P}):(0,g.jsxs)(g.Fragment,{children:[A&&(0,g.jsx)(`img`,{ref:k,src:A,alt:t,draggable:!1,onLoad:()=>N(!0),onError:()=>F(v(`fileManager.preview.error`)),style:{transform:`translate(${R.x}px, ${R.y}px) scale(${I})`},className:`max-w-full max-h-full object-contain select-none`}),!M&&(0,g.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center pointer-events-none`,children:(0,g.jsx)(o,{className:`w-8 h-8 text-bambu-green animate-spin`})})]})})})}export{T as ImagePreviewModal}; \ No newline at end of file diff --git a/static/assets/InventoryPage-CPx98yw-.js b/static/assets/InventoryPage-o24Ni0S2.js similarity index 99% rename from static/assets/InventoryPage-CPx98yw-.js rename to static/assets/InventoryPage-o24Ni0S2.js index f09e20278..061eb42e4 100644 --- a/static/assets/InventoryPage-CPx98yw-.js +++ b/static/assets/InventoryPage-o24Ni0S2.js @@ -1,2 +1,2 @@ -import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,n as i,r as a,t as o,v as s,w as c}from"./client-DnySrlFv.js";import{n as l}from"./QueryClientProvider-Ce8_sN3w.js";import{t as u}from"./useQuery-BBCjCezC.js";import{t as d}from"./useMutation-B-Tr2hIP.js";import{t as f}from"./useQueries-Be6PMvSC.js";import{t as p}from"./createLucideIcon-DvBYJlWL.js";import{i as m,n as h,r as g}from"./haSensorDisplay-lPbcOxD8.js";import{t as _}from"./arrow-down-Cj0DZhNf.js";import{t as v}from"./arrow-up-down-BdyOV_2F.js";import{t as y}from"./arrow-up-D-pfJ3WZ.js";import{i as b,n as x,r as S,t as C}from"./ReferenceLine-clJprXoH.js";import{t as w}from"./check-Ck0cMLU4.js";import{a as T,i as E,n as D,t as O}from"./info-ROUoQhJR.js";import{n as ee,t as k}from"./chevrons-right-DTJgqnxZ.js";import{n as te,r as A}from"./ToastContext-BRX0SW3C.js";import{t as j}from"./columns-2-DVEObeDC.js";import{t as M}from"./copy-Cu_0GKCU.js";import{t as N}from"./layout-grid-DkD3u6wa.js";import{t as P}from"./link-2-MI-QCMh8.js";import{t as F}from"./loader-circle-BEmFtawu.js";import{t as ne}from"./lock-MLqgWH4Q.js";import{_ as I,c as L,g as re,h as R,s as ie,v as ae}from"./locationSensorDefaults-Bb4u9P8m.js";import{t as oe}from"./package-BGUevlqS.js";import{t as se}from"./search-0n0CBc74.js";import{t as z}from"./sparkles-DRqKNlhr.js";import{L as ce,Rn as le,Xt as ue,c as de,p as fe,s as pe}from"./CartesianChart-BAcHzPFb.js";import{t as B}from"./triangle-alert-Dt_1FcBy.js";import{t as me}from"./unlink-C098nwOf.js";import{t as he}from"./x-DR-Trv6U.js";import{t as V}from"./Button-DDr6eAFy.js";import{r as ge,v as H,y as _e}from"./date-G9KUauqz.js";import{n as ve}from"./filamentSwatchHelpers-D3oXQSGk.js";import{$t as ye,At as be,Cn as xe,Gt as Se,H as Ce,Jt as U,Kt as we,Ln as Te,Lt as Ee,Mn as De,On as Oe,Pt as ke,Rt as Ae,Tt as je,Ut as Me,Wn as Ne,Zt as Pe,_t as Fe,a as Ie,at as Le,bt as Re,cn as ze,en as Be,ft as Ve,i as He,jn as Ue,kn as We,kt as Ge,lt as Ke,o as qe,ot as Je,r as Ye,s as Xe,st as W,w as Ze,wn as Qe,xn as $e,yt as et,zt as tt}from"./index-0t--Yqoi.js";import{i as nt,r as rt}from"./slicerPrinterMatch-CUdoNag2.js";import{t as it}from"./ColumnConfigModal-DrIkn1Rf.js";import{n as at,t as ot}from"./AreaChart-DJpIJXxF.js";import{a as st,i as ct,n as lt,o as ut,r as G,s as dt,t as ft}from"./AdditionalSection-BgleEt_Y.js";import{_ as pt,a as K,b as mt,c as ht,d as gt,f as _t,g as vt,i as yt,l as bt,m as xt,n as St,o as Ct,r as wt,s as Tt,t as Et,u as Dt,v as Ot}from"./utils-DVekehs6.js";import{t as kt}from"./AssignToAmsModal-CcnpBCWY.js";import{t as At}from"./inventorySearch-C_D57LMP.js";var q=p(`beaker`,[[`path`,{d:`M4.5 3h15`,key:`c7n0jr`}],[`path`,{d:`M6 3v16a2 2 0 0 0 2 2h8a2 2 0 0 0 2-2V3`,key:`m1uhx7`}],[`path`,{d:`M6 14h12`,key:`4cwo0f`}]]),jt=p(`chart-no-axes-column`,[[`path`,{d:`M5 21v-6`,key:`1hz6c0`}],[`path`,{d:`M12 21V3`,key:`1lcnhd`}],[`path`,{d:`M19 21V9`,key:`unv183`}]]),Mt=p(`credit-card`,[[`rect`,{width:`20`,height:`14`,x:`2`,y:`5`,rx:`2`,key:`ynyp8z`}],[`line`,{x1:`2`,x2:`22`,y1:`10`,y2:`10`,key:`1b3vmo`}]]),Nt=p(`group`,[[`path`,{d:`M3 7V5c0-1.1.9-2 2-2h2`,key:`adw53z`}],[`path`,{d:`M17 3h2c1.1 0 2 .9 2 2v2`,key:`an4l38`}],[`path`,{d:`M21 17v2c0 1.1-.9 2-2 2h-2`,key:`144t0e`}],[`path`,{d:`M7 21H5c-1.1 0-2-.9-2-2v-2`,key:`rtnfgi`}],[`rect`,{width:`7`,height:`5`,x:`7`,y:`7`,rx:`1`,key:`1eyiv7`}],[`rect`,{width:`7`,height:`5`,x:`10`,y:`12`,rx:`1`,key:`1qlmkx`}]]),Pt=p(`package-check`,[[`path`,{d:`m16 16 2 2 4-4`,key:`gfu2re`}],[`path`,{d:`M21 10V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l2-1.14`,key:`e7tb2h`}],[`path`,{d:`m7.5 4.27 9 5.15`,key:`1c824w`}],[`polyline`,{points:`3.29 7 12 12 20.71 7`,key:`ousv84`}],[`line`,{x1:`12`,x2:`12`,y1:`22`,y2:`12`,key:`a4e8g8`}]]),Ft=p(`store`,[[`path`,{d:`M15 21v-5a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v5`,key:`slp6dd`}],[`path`,{d:`M17.774 10.31a1.12 1.12 0 0 0-1.549 0 2.5 2.5 0 0 1-3.451 0 1.12 1.12 0 0 0-1.548 0 2.5 2.5 0 0 1-3.452 0 1.12 1.12 0 0 0-1.549 0 2.5 2.5 0 0 1-3.77-3.248l2.889-4.184A2 2 0 0 1 7 2h10a2 2 0 0 1 1.653.873l2.895 4.192a2.5 2.5 0 0 1-3.774 3.244`,key:`o0xfot`}],[`path`,{d:`M4 10.95V19a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-8.05`,key:`wn3emo`}]]),It=p(`table-properties`,[[`path`,{d:`M15 3v18`,key:`14nvp0`}],[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M21 9H3`,key:`1338ky`}],[`path`,{d:`M21 15H3`,key:`9uk58r`}]]),J=e(n(),1),Y=t(),Lt=1.65,Rt=[`#1DB954`,`#3B82F6`,`#F59E0B`,`#EF4444`,`#8B5CF6`];function X(e,t,n,r){return`${e}||${t??``}||${n??``}||${r??``}`}function Z(e,t){let n=new Date(e);return n.setDate(n.getDate()+Math.round(t)),n}function zt(e){return e.toLocaleDateString(void 0,{month:`short`,day:`numeric`,year:`numeric`})}function Bt(e){return e.toLocaleDateString(void 0,{month:`short`,day:`numeric`})}function Vt(e){if(e.length<2)return null;let t=new Map;for(let n of e){let e=n.created_at.slice(0,10);t.set(e,(t.get(e)??0)+n.weight_used)}if(t.size<2)return null;let n=[...t.entries()].map(([e,t])=>({ms:new Date(e).getTime(),totalG:t})).sort((e,t)=>e.ms-t.ms),r=Date.now(),i=Math.LN2/30,a=[];for(let e=1;ee+t.weight,0);if(o===0)return null;let s=a.reduce((e,t)=>e+t.rate*t.weight,0)/o,c=a.reduce((e,t)=>e+t.weight*(t.rate-s)**2,0)/o;return{rate:s,stdDev:Math.sqrt(c)}}function Ht(e){let t=e.reduce((e,t)=>e+Math.max(0,t.weight_used-(t.weight_used_baseline??0)),0);if(t===0)return null;let n=Date.now(),r=(n-e.reduce((e,t)=>{let n=new Date(t.created_at).getTime();return nr.getAllUsageHistory(5e3),staleTime:6e4,enabled:s}),{data:M=[]}=u({queryKey:[`shopping-list`],queryFn:r.getShoppingList,staleTime:3e4,enabled:s}),N=k?.forecast_global_lead_time_days??0,P=(0,J.useMemo)(()=>{let e=new Map;for(let t of A)e.set(X(t.material,t.subtype,t.brand,t.color_name),t);return e},[A]),F=(0,J.useMemo)(()=>{let e=new Map;for(let t of j){let n=e.get(t.spool_id)??[];n.push(t),e.set(t.spool_id,n)}return e},[j]),I=(0,J.useMemo)(()=>{let t=new Map;for(let n of e){if(n.archived_at)continue;let e=X(n.material,n.subtype,n.brand,n.color_name),r=t.get(e)??{key:e,material:n.material,subtype:n.subtype,brand:n.brand,colorName:n.color_name,spools:[]};r.spools.push(n),t.set(e,r)}return[...t.values()]},[e]),L=(0,J.useMemo)(()=>{let e=new Date;return e.setHours(0,0,0,0),I.map(t=>{let n=P.get(t.key)??(t.colorName===null?null:P.get(X(t.material,t.subtype,t.brand,null))??null),r=n?.lead_time_days??0,i=Math.max(N,r),a=n?.safety_margin_value??14,o=n?.safety_margin_unit??`days`,s=t.spools.reduce((e,t)=>e+Math.max(0,t.label_weight-t.weight_used),0),c=t.spools.reduce((e,t)=>e+t.label_weight,0),l=t.spools.reduce((e,t)=>e+Math.max(0,t.weight_used-(t.weight_used_baseline??0)),0),u=[];for(let e of t.spools)(e.weight_used_baseline??0)===0&&u.push(...F.get(e.id)??[]);let d=null,f=null,p=`none`,m=Vt(u);if(m!==null)d=m.rate,f=m.stdDev,p=`history`;else{let e=Ht(t.spools);e!==null&&(d=e,p=`delta`)}let h=Lt*(f??(d===null?0:d*.2))*Math.sqrt(i)+(o===`g`?a:d===null?a*5:d*a),g=d===null?0:d*i+h,_=d&&d>0?Math.floor(s/d):null,v=_===null?null:Z(e,_),y=d&&d>0?Math.floor((s-g)/d):null,b=y===null?null:Z(e,Math.max(0,y)),x=_!==null&&i>0&&_<=i,S=!x&&y!==null&&y<=0;return{group:t,settings:n,totalRemainingG:s,totalLabelG:c,totalSpools:t.spools.length,totalUsedG:l,dailyRateG:d,dailyRateStdDev:f,rateTier:p,effectiveLeadTimeDays:i,safetyStockG:h,reorderPointG:g,daysRemaining:_,daysUntilROP:y,projectedEmptyDate:v,reorderTriggerDate:b,reorderAlert:S,stockBreakAlert:x}})},[I,P,F,N]),re=(0,J.useMemo)(()=>[...new Set(I.map(e=>e.material))].sort(),[I]),R=(0,J.useMemo)(()=>[...new Set(I.map(e=>e.brand).filter(Boolean))].sort(),[I]),ie=(0,J.useMemo)(()=>{let e=[...L];return v&&(e=e.filter(e=>e.group.material===v)),b&&(e=e.filter(e=>e.group.brand===b)),e.sort((e,t)=>{let n=0,r=0;switch(m){case`material`:n=[e.group.material,e.group.subtype??``,e.group.brand??``].join(` `).toLowerCase(),r=[t.group.material,t.group.subtype??``,t.group.brand??``].join(` `).toLowerCase();break;case`used`:n=e.totalUsedG,r=t.totalUsedG;break;case`days_left`:n=e.daysRemaining??999999,r=t.daysRemaining??999999;break;case`stock`:n=e.totalRemainingG,r=t.totalRemainingG;break}let i=nr);return g===`asc`?i:-i}),e},[L,m,g,v,b]),ae=(0,J.useMemo)(()=>L.filter(e=>!e.settings?.alerts_snoozed&&(e.stockBreakAlert||e.reorderAlert)),[L]),oe=(0,J.useMemo)(()=>[...L].filter(e=>e.dailyRateG!==null).sort((e,t)=>t.totalUsedG-e.totalUsedG).slice(0,5),[L]);if(!s)return(0,Y.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-16 text-bambu-gray gap-3`,children:[(0,Y.jsx)(ne,{className:`w-8 h-8 opacity-40`}),(0,Y.jsx)(`p`,{className:`text-sm`,children:i(`forecast.noReadAccess`)})]});function se(e){m===e?_(e=>e===`asc`?`desc`:`asc`):(h(e),_(e===`days_left`?`asc`:`desc`))}let z=M.length>0?M.length:null;return(0,Y.jsxs)(`div`,{className:`space-y-5`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[ae.length>0&&(0,Y.jsxs)(`button`,{onClick:()=>p(e=>!e),className:`flex items-center gap-2 px-3 py-1.5 rounded-lg border text-sm font-medium transition-colors ${ae.some(e=>e.stockBreakAlert)?`bg-red-100 dark:bg-red-500/15 border-red-300 dark:border-red-500/30 text-red-700 dark:text-red-300 hover:bg-red-200 dark:hover:bg-red-500/25`:`bg-yellow-100 dark:bg-yellow-500/15 border-yellow-300 dark:border-yellow-500/30 text-yellow-700 dark:text-yellow-300 hover:bg-yellow-200 dark:hover:bg-yellow-500/25`}`,children:[(0,Y.jsx)(B,{className:`w-4 h-4`}),i(`forecast.alertCount`,{count:ae.length}),f?(0,Y.jsx)(E,{className:`w-3.5 h-3.5`}):(0,Y.jsx)(T,{className:`w-3.5 h-3.5`})]}),d&&(0,Y.jsx)(Yt,{value:N,onSave:e=>{r.updateSettings({forecast_global_lead_time_days:e}).then(()=>{t.invalidateQueries({queryKey:[`settings`]}),n(i(`forecast.globalLeadTimeSaved`),`success`)})}}),(0,Y.jsxs)(`select`,{value:v,onChange:e=>y(e.target.value),className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${v?`bg-bambu-green/20 text-bambu-green border-bambu-green/30`:`bg-transparent text-bambu-gray border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary`}`,children:[(0,Y.jsx)(`option`,{value:``,children:i(`inventory.material`)}),re.map(e=>(0,Y.jsx)(`option`,{value:e,children:e},e))]}),(0,Y.jsxs)(`select`,{value:b,onChange:e=>x(e.target.value),className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${b?`bg-bambu-green/20 text-bambu-green border-bambu-green/30`:`bg-transparent text-bambu-gray border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary`}`,children:[(0,Y.jsx)(`option`,{value:``,children:i(`inventory.brand`)}),R.map(e=>(0,Y.jsx)(`option`,{value:e,children:e},e))]}),(0,Y.jsxs)(`button`,{onClick:()=>D(e=>!e),className:`relative flex items-center gap-2 px-3 py-1.5 rounded-lg border border-bambu-dark-tertiary text-bambu-gray hover:bg-bambu-dark-tertiary text-sm transition-colors ml-auto`,children:[(0,Y.jsx)(tt,{className:`w-4 h-4`}),(0,Y.jsx)(`span`,{className:`hidden sm:inline`,children:i(`forecast.shoppingList`)}),z&&(0,Y.jsx)(`span`,{className:`absolute -top-1.5 -right-1.5 w-4 h-4 rounded-full bg-bambu-green text-white text-[10px] font-bold flex items-center justify-center`,children:z})]})]}),f&&ae.length>0&&(0,Y.jsx)(`div`,{className:`space-y-2`,children:ae.map(e=>(0,Y.jsx)(Kt,{forecast:e,onCart:()=>C(e)},e.group.key))}),w&&(0,Y.jsx)(en,{items:M,forecasts:L,globalLeadTime:N,canWrite:d,onClose:()=>D(!1),onRemove:e=>{r.removeFromShoppingList(e).then(()=>t.invalidateQueries({queryKey:[`shopping-list`]})).catch(()=>n(i(`forecast.failedSaveSettings`),`error`))},onClear:()=>{r.clearShoppingList().then(()=>t.invalidateQueries({queryKey:[`shopping-list`]})).catch(()=>n(i(`forecast.failedSaveSettings`),`error`))}}),oe.length>0&&(0,Y.jsx)(Jt,{forecasts:oe,days:O,onDaysChange:ee}),L.length===0?(0,Y.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-16 text-bambu-gray`,children:[(0,Y.jsx)(le,{className:`w-10 h-10 mb-3 opacity-40`}),(0,Y.jsx)(`p`,{className:`text-sm`,children:i(`forecast.noSpools`)})]}):(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-dark-tertiary`,children:[(0,Y.jsx)(`div`,{className:`overflow-x-auto`,children:(0,Y.jsxs)(`table`,{className:`w-full`,children:[(0,Y.jsx)(`thead`,{children:(0,Y.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary bg-bambu-dark-tertiary/30`,children:[(0,Y.jsx)(`th`,{className:`w-8 px-4 py-3`}),(0,Y.jsx)(Gt,{col:`material`,active:m,dir:g,onSort:se,children:i(`forecast.sku`)}),(0,Y.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:i(`locations.spools`)}),(0,Y.jsx)(Gt,{col:`stock`,active:m,dir:g,onSort:se,children:i(`forecast.stock`)}),(0,Y.jsx)(Gt,{col:`used`,active:m,dir:g,onSort:se,children:i(`forecast.dailyRate`)}),(0,Y.jsx)(Gt,{col:`days_left`,active:m,dir:g,onSort:se,children:i(`forecast.daysLeft`)}),(0,Y.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:i(`forecast.emptyBy`)}),(0,Y.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:i(`forecast.reorderBy`)}),(0,Y.jsx)(`th`,{className:`w-24 px-4 py-3`})]})}),(0,Y.jsx)(`tbody`,{className:`divide-y divide-bambu-dark-tertiary`,children:ie.map(e=>(0,Y.jsx)(Xt,{forecast:e,globalLeadTime:N,canWrite:d,onSaved:()=>t.invalidateQueries({queryKey:[`sku-settings`]}),onCart:()=>C(e),showToast:n},e.group.key))})]})}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4 px-4 py-3 text-xs text-bambu-gray border-t border-bambu-dark-tertiary bg-bambu-dark-tertiary/20`,children:[(0,Y.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-bambu-green inline-block`}),i(`forecast.trendLegend`)]}),(0,Y.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-blue-400 inline-block`}),i(`forecast.estimatedLegend`)]}),(0,Y.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-bambu-gray/40 inline-block`}),i(`forecast.noDataLegend`)]})]})]}),S&&(0,Y.jsx)(nn,{forecast:S,onClose:()=>C(null),onAdd:e=>{r.addToShoppingList(e).then(()=>{t.invalidateQueries({queryKey:[`shopping-list`]}),n(i(`forecast.addedToCart`),`success`),C(null),D(!0)}).catch(()=>n(i(`forecast.failedAddItem`),`error`))}})]})}function Gt({col:e,active:t,dir:n,onSort:r,children:i}){return(0,Y.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide cursor-pointer select-none hover:text-white transition-colors`,onClick:()=>r(e),children:(0,Y.jsxs)(`span`,{className:`inline-flex items-center`,children:[i,t===e?n===`asc`?(0,Y.jsx)(y,{className:`w-3 h-3 ml-1 text-bambu-green`}):(0,Y.jsx)(_,{className:`w-3 h-3 ml-1 text-bambu-green`}):(0,Y.jsx)(v,{className:`w-3 h-3 ml-1 opacity-40`})]})})}function Kt({forecast:e,onCart:t}){let{t:n}=c(),r=[e.group.brand,e.group.material,e.group.subtype,e.group.colorName].filter(Boolean).join(` `),i=e.stockBreakAlert;return(0,Y.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-3 rounded-lg border text-sm ${i?`bg-red-50 dark:bg-red-500/10 border-red-300 dark:border-red-500/30 text-red-700 dark:text-red-300`:`bg-yellow-50 dark:bg-yellow-500/10 border-yellow-300 dark:border-yellow-500/30 text-yellow-700 dark:text-yellow-300`}`,children:[(0,Y.jsx)(B,{className:`w-4 h-4 flex-shrink-0`}),(0,Y.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Y.jsx)(`span`,{className:`font-medium`,children:r}),i?(0,Y.jsxs)(`span`,{className:`ml-2 text-xs opacity-80`,children:[n(`forecast.stockBreakRisk`),` — `,n(`forecast.stockBreakDetail`,{days:e.daysRemaining,lt:e.effectiveLeadTimeDays})]}):(0,Y.jsxs)(`span`,{className:`ml-2 text-xs opacity-80`,children:[n(`forecast.reorderNow`),` — `,n(`forecast.reorderTriggerPassed`,{date:e.reorderTriggerDate?zt(e.reorderTriggerDate):`—`})]})]}),(0,Y.jsxs)(`button`,{onClick:t,className:`flex items-center gap-1.5 px-2.5 py-1 rounded border border-current text-xs opacity-70 hover:opacity-100 transition-opacity`,children:[(0,Y.jsx)(tt,{className:`w-3 h-3`}),` `,n(`forecast.order`)]})]})}var qt=[{label:`1W`,value:7},{label:`1M`,value:30},{label:`6M`,value:180}];function Jt({forecasts:e,days:t,onDaysChange:n}){let{t:r}=c(),i=Array.from({length:t+1},(e,t)=>t),a=e.map((e,n)=>({key:e.group.key,label:[e.group.brand,e.group.material,e.group.subtype,e.group.colorName].filter(Boolean).join(` `),color:Rt[n%Rt.length],rop:e.reorderPointG,points:Ut(e,t)})),o=i.map(e=>{let t={day:e,label:Bt(Z(new Date,e))};for(let n of a){let r=n.points.find(t=>t.day===e);t[n.key]=r?.stock??0}return t}),s=(()=>{for(let e=t;e>=0;e--)if(a.some(t=>o[e]?.[t.key]>0))return e;return t})(),l=o.slice(0,s+1),u=a.filter(e=>e.rop>0);return(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-dark-tertiary p-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 mb-4`,children:[(0,Y.jsx)(le,{className:`w-4 h-4 text-bambu-green`}),(0,Y.jsx)(`h3`,{className:`text-sm font-semibold text-white`,children:r(`forecast.chartTitle`)}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1 hidden sm:inline`,children:r(`forecast.dashedLinesROP`)}),(0,Y.jsx)(`div`,{className:`ml-auto flex items-center bg-bambu-dark-tertiary rounded-lg p-0.5`,children:qt.map(e=>(0,Y.jsx)(`button`,{onClick:()=>n(e.value),className:`px-2.5 py-1 text-xs font-medium rounded-md transition-colors ${t===e.value?`bg-bambu-dark-secondary text-white shadow`:`text-bambu-gray hover:text-white`}`,children:e.label},e.value))})]}),(0,Y.jsx)(ue,{width:`100%`,height:220,children:(0,Y.jsxs)(ot,{data:l,margin:{top:4,right:8,bottom:0,left:0},children:[(0,Y.jsx)(`defs`,{children:a.map(e=>(0,Y.jsxs)(`linearGradient`,{id:`grad-${e.key}`,x1:`0`,y1:`0`,x2:`0`,y2:`1`,children:[(0,Y.jsx)(`stop`,{offset:`5%`,stopColor:e.color,stopOpacity:.25}),(0,Y.jsx)(`stop`,{offset:`95%`,stopColor:e.color,stopOpacity:.02})]},e.key))}),(0,Y.jsx)(fe,{strokeDasharray:`3 3`,stroke:`#374151`,strokeOpacity:.5}),(0,Y.jsx)(de,{dataKey:`label`,tick:{fill:`#6B7280`,fontSize:10},interval:Math.max(0,Math.ceil(s/8)-1),axisLine:!1,tickLine:!1}),(0,Y.jsx)(pe,{tick:{fill:`#6B7280`,fontSize:10},axisLine:!1,tickLine:!1,tickFormatter:e=>e>=1e3?`${(e/1e3).toFixed(1)}kg`:`${e}g`,width:48}),(0,Y.jsx)(ce,{content:({label:e,payload:t})=>t?.length?(0,Y.jsxs)(`div`,{style:{background:`#1a1a2e`,border:`1px solid #374151`,borderRadius:8,fontSize:12,padding:`8px 12px`},children:[(0,Y.jsx)(`div`,{style:{color:`#9CA3AF`,marginBottom:6},children:e}),t.map(e=>{let t=a.find(t=>t.key===String(e.dataKey));return typeof e.value==`number`?(0,Y.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:6,color:`#E5E7EB`,marginBottom:2},children:[(0,Y.jsx)(`span`,{style:{color:t?.color??`#9CA3AF`,fontSize:10},children:`●`}),(0,Y.jsx)(`span`,{children:t?.label??String(e.dataKey)}),(0,Y.jsxs)(`span`,{style:{color:`#9CA3AF`,marginLeft:4},children:[e.value,`g`]})]},String(e.dataKey)):null})]}):null}),(0,Y.jsx)(x,{formatter:e=>(0,Y.jsx)(`span`,{style:{color:`#9CA3AF`,fontSize:11},children:a.find(t=>t.key===e)?.label??e})}),a.map(e=>(0,Y.jsx)(at,{type:`monotone`,dataKey:e.key,stroke:e.color,strokeWidth:2,fill:`url(#grad-${e.key})`,dot:!1,activeDot:{r:3}},e.key)),u.map(e=>(0,Y.jsx)(C,{y:e.rop,stroke:e.color,strokeDasharray:`4 3`,strokeOpacity:.6},`rop-${e.key}`))]})})]})}function Yt({value:e,onSave:t}){let{t:n}=c(),[r,i]=(0,J.useState)(!1),[a,o]=(0,J.useState)(String(e));function s(){let e=parseInt(a,10);isNaN(e)||e<0||(t(e),i(!1))}return(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-1.5 bg-bambu-dark-tertiary/40 rounded-lg border border-bambu-dark-tertiary text-xs text-bambu-gray`,children:[(0,Y.jsx)(O,{className:`w-3.5 h-3.5 flex-shrink-0`,"aria-label":n(`forecast.globalLeadTimeHint`)}),(0,Y.jsxs)(`span`,{className:`hidden sm:inline`,children:[n(`forecast.globalLeadTime`),`:`]}),r?(0,Y.jsxs)(`form`,{className:`flex items-center gap-1.5`,onSubmit:e=>{e.preventDefault(),s()},children:[(0,Y.jsx)(`input`,{type:`number`,min:0,max:365,value:a,onChange:e=>o(e.target.value),className:`w-14 px-1.5 py-0.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-sm text-white focus:outline-none focus:border-bambu-green`,autoFocus:!0}),(0,Y.jsx)(`span`,{className:`text-bambu-gray`,children:`d`}),(0,Y.jsx)(`button`,{type:`submit`,className:`px-2 py-0.5 bg-bambu-green text-white text-xs rounded hover:bg-bambu-green/80`,children:n(`forecast.save`)}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>i(!1),className:`text-xs text-bambu-gray hover:text-white`,children:`✕`})]}):(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsxs)(`span`,{className:`font-semibold text-white`,children:[e,`d`]}),(0,Y.jsx)(`button`,{onClick:()=>{o(String(e)),i(!0)},className:`p-0.5 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,Y.jsx)(I,{className:`w-3 h-3`})})]})]})}function Xt({forecast:e,globalLeadTime:t,canWrite:n,onSaved:i,onCart:a,showToast:o}){let{t:s}=c(),[l,u]=(0,J.useState)(!1),[f,p]=(0,J.useState)(!1),[m,h]=(0,J.useState)(!1),[g,_]=(0,J.useState)(String(e.settings?.lead_time_days??0)),[v,y]=(0,J.useState)(String(e.settings?.safety_margin_value??14)),[x,S]=(0,J.useState)(e.settings?.safety_margin_unit??`days`);(0,J.useEffect)(()=>{f||_(String(e.settings?.lead_time_days??0))},[e.settings?.lead_time_days,f]),(0,J.useEffect)(()=>{m||(y(String(e.settings?.safety_margin_value??14)),S(e.settings?.safety_margin_unit??`days`))},[e.settings?.safety_margin_value,e.settings?.safety_margin_unit,m]);let C=d({mutationFn:r.upsertSkuSettings,onSuccess:()=>{i(),o(s(`forecast.settingsSaved`),`success`)},onError:()=>o(s(`forecast.failedSaveSettings`),`error`)}),D=e.settings?.alerts_snoozed??!1,O=[e.group.brand,e.group.material,e.group.subtype,e.group.colorName].filter(Boolean).join(` `),ee=e.group.spools[0]?.rgba?Ke(e.group.spools[0].rgba):{backgroundColor:`#4B5563`},k=e.totalLabelG>0?Math.round(e.totalRemainingG/e.totalLabelG*100):0,te=D||e.daysRemaining===null?`text-bambu-gray`:e.stockBreakAlert?`text-red-700 dark:text-red-400`:e.reorderAlert||e.daysRemaining<30?`text-yellow-700 dark:text-yellow-400`:`text-green-700 dark:text-green-400`;function A(t,n,r,i=D){C.mutate({material:e.group.material,subtype:e.group.subtype,brand:e.group.brand,color_name:e.group.colorName,lead_time_days:t,safety_margin_value:n,safety_margin_unit:r,alerts_snoozed:i})}function j(t){t.stopPropagation(),A(e.settings?.lead_time_days??0,e.settings?.safety_margin_value??14,e.settings?.safety_margin_unit??`days`,!D)}let M=e.rateTier===`history`?(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-xs px-1.5 py-0.5 rounded bg-bambu-green/15 text-bambu-green`,children:[(0,Y.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-bambu-green`}),s(`forecast.trend`)]}):e.rateTier===`delta`?(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-xs px-1.5 py-0.5 rounded bg-blue-100 dark:bg-blue-400/15 text-blue-700 dark:text-blue-400`,children:[(0,Y.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-blue-400`}),s(`forecast.estimated`)]}):(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-xs px-1.5 py-0.5 rounded bg-bambu-dark-tertiary text-bambu-gray/60`,children:[(0,Y.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-bambu-gray/40`}),s(`forecast.noData`)]});return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/50 cursor-pointer hover:bg-bambu-dark-tertiary/30 transition-colors ${D?``:e.stockBreakAlert?`bg-red-500/5`:e.reorderAlert?`bg-yellow-500/5`:``} ${D?`opacity-50`:``}`,onClick:()=>u(e=>!e),children:[(0,Y.jsx)(`td`,{className:`px-4 py-3`,children:(0,Y.jsx)(`span`,{className:`block w-5 h-5 rounded-full border border-black/20`,style:ee})}),(0,Y.jsx)(`td`,{className:`px-4 py-3`,children:(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:O})}),(0,Y.jsx)(`td`,{className:`px-4 py-3`,children:(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.totalSpools})}),(0,Y.jsx)(`td`,{className:`px-4 py-3 min-w-[140px]`,children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`div`,{className:`flex-1 h-2 bg-bambu-dark-tertiary rounded-full overflow-hidden`,children:(0,Y.jsx)(`div`,{className:`h-full rounded-full ${k>50?`bg-bambu-green`:k>20?`bg-yellow-500`:`bg-red-500`}`,style:{width:`${Math.min(k,100)}%`}})}),(0,Y.jsxs)(`span`,{className:`text-xs text-bambu-gray min-w-[40px] text-right`,children:[Math.round(e.totalRemainingG),`g`]})]})}),(0,Y.jsx)(`td`,{className:`px-4 py-3`,children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 flex-wrap`,children:[(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:e.dailyRateG===null?`—`:`${e.dailyRateG.toFixed(1)}g/d`}),M]})}),(0,Y.jsx)(`td`,{className:`px-4 py-3`,children:(0,Y.jsx)(`span`,{className:`text-sm font-semibold ${te}`,children:e.daysRemaining===null?(0,Y.jsx)(`span`,{className:`text-bambu-gray font-normal`,children:`—`}):`${e.daysRemaining}d`})}),(0,Y.jsx)(`td`,{className:`px-4 py-3`,children:(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.projectedEmptyDate?zt(e.projectedEmptyDate):`—`})}),(0,Y.jsx)(`td`,{className:`px-4 py-3`,children:(0,Y.jsx)(`span`,{className:`text-sm ${!D&&e.reorderAlert?`text-yellow-700 dark:text-yellow-400`:`text-bambu-gray`}`,children:e.reorderTriggerDate?zt(e.reorderTriggerDate):`—`})}),(0,Y.jsx)(`td`,{className:`px-4 py-3`,onClick:e=>e.stopPropagation(),children:(0,Y.jsxs)(`div`,{className:`flex items-center justify-end gap-1`,children:[n&&(0,Y.jsx)(`button`,{onClick:a,className:`p-1.5 text-bambu-gray hover:text-bambu-green rounded transition-colors`,title:s(`forecast.addToCart`),children:(0,Y.jsx)(tt,{className:`w-4 h-4`})}),!D&&(e.stockBreakAlert?(0,Y.jsx)(B,{className:`w-4 h-4 text-red-600 dark:text-red-400`,"aria-label":s(`forecast.stockBreakRisk`)}):e.reorderAlert?(0,Y.jsx)(B,{className:`w-4 h-4 text-yellow-600 dark:text-yellow-400`,"aria-label":s(`forecast.reorderNow`)}):e.daysRemaining===null?null:(0,Y.jsx)(w,{className:`w-4 h-4 text-bambu-green/50`})),n&&(0,Y.jsx)(`button`,{onClick:j,className:`p-1 rounded transition-colors ${D?`text-amber-600/80 dark:text-amber-400/80 hover:text-amber-700 dark:hover:text-amber-300`:`text-slate-400 hover:text-white`}`,title:s(D?`forecast.alertsEnabled`:`forecast.alertsSnoozed`),children:(0,Y.jsx)(b,{className:`w-3.5 h-3.5`})}),(0,Y.jsx)(`button`,{onClick:e=>{e.stopPropagation(),u(e=>!e)},className:`p-1.5 text-bambu-gray hover:text-white rounded transition-colors`,children:l?(0,Y.jsx)(E,{className:`w-4 h-4`}):(0,Y.jsx)(T,{className:`w-4 h-4`})})]})})]}),l&&(0,Y.jsx)(`tr`,{className:`bg-bambu-dark-tertiary/10`,children:(0,Y.jsx)(`td`,{colSpan:9,className:`px-6 py-4`,children:(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`grid gap-2 ${n?`grid-cols-2 sm:grid-cols-4`:`grid-cols-2`}`,children:[(0,Y.jsx)(Zt,{label:s(`forecast.effectiveLeadTime`),value:`${e.effectiveLeadTimeDays}d`,hint:s(`forecast.effectiveLeadTimeHint`,{global:t,sku:e.settings?.lead_time_days??0})}),(0,Y.jsx)(Zt,{label:s(`forecast.reorderPoint`),value:`${Math.round(e.reorderPointG)}g`,hint:s(`forecast.reorderPointHint`)}),n&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(Qt,{label:s(`forecast.skuLeadTimeOverride`),hint:s(`forecast.skuLeadTimeHint`),unit:s(`forecast.leadTime`),editing:f,value:e.settings?.lead_time_days??0,inputValue:g,onInputChange:_,onEdit:()=>{_(String(e.settings?.lead_time_days??0)),p(!0)},onSave:()=>{let t=parseInt(g,10);!isNaN(t)&&t>=0&&(A(t,e.settings?.safety_margin_value??14,x),p(!1))},onCancel:()=>p(!1),isPending:C.isPending,saveLabel:s(`forecast.save`),cancelLabel:s(`forecast.cancel`)}),(0,Y.jsx)($t,{value:e.settings?.safety_margin_value??14,unit:x,editing:m,inputValue:v,dailyRateG:e.dailyRateG,onInputChange:y,onUnitChange:e=>S(e),onEdit:()=>{y(String(e.settings?.safety_margin_value??14)),S(e.settings?.safety_margin_unit??`days`),h(!0)},onSave:()=>{let t=parseInt(v,10);!isNaN(t)&&t>=0&&(A(e.settings?.lead_time_days??0,t,x),h(!1))},onCancel:()=>h(!1),isPending:C.isPending,saveLabel:s(`forecast.save`),cancelLabel:s(`forecast.cancel`),safetyMarginLabel:s(`forecast.safetyMarginLabel`)})]})]}),e.group.spools.length>1&&(0,Y.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary pt-3`,children:[(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:s(`forecast.individualSpools`)}),(0,Y.jsx)(`div`,{className:`bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-dark-tertiary`,children:(0,Y.jsxs)(`table`,{className:`w-full`,children:[(0,Y.jsx)(`thead`,{children:(0,Y.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary bg-bambu-dark-tertiary/30`,children:[(0,Y.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:`#`}),(0,Y.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:s(`inventory.remaining`)}),(0,Y.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:s(`inventory.used`)}),(0,Y.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:s(`forecast.labelWeight`)})]})}),(0,Y.jsx)(`tbody`,{className:`divide-y divide-bambu-dark-tertiary`,children:e.group.spools.map(e=>{let t=Math.max(0,e.label_weight-e.weight_used),n=e.label_weight>0?t/e.label_weight*100:0;return(0,Y.jsxs)(`tr`,{className:`hover:bg-bambu-dark-tertiary/30 transition-colors`,children:[(0,Y.jsx)(`td`,{className:`px-4 py-2`,children:(0,Y.jsxs)(`span`,{className:`text-xs font-mono text-bambu-gray/70`,children:[`#`,e.id]})}),(0,Y.jsx)(`td`,{className:`px-4 py-2`,children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Y.jsx)(`div`,{className:`w-24 h-1.5 bg-bambu-dark-tertiary rounded-full overflow-hidden flex-shrink-0`,children:(0,Y.jsx)(`div`,{className:`h-full rounded-full ${n>50?`bg-bambu-green`:n>20?`bg-yellow-500`:`bg-red-500`}`,style:{width:`${Math.min(n,100)}%`}})}),(0,Y.jsxs)(`span`,{className:`text-sm text-white`,children:[Math.round(t),`g`]})]})}),(0,Y.jsx)(`td`,{className:`px-4 py-2`,children:(0,Y.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[Math.round(Math.max(0,e.weight_used-(e.weight_used_baseline??0))),`g`]})}),(0,Y.jsx)(`td`,{className:`px-4 py-2`,children:(0,Y.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[e.label_weight,`g`]})})]},e.id)})})]})})]})]})})})]})}function Zt({label:e,value:t,hint:n}){return(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-tertiary/40 rounded-lg p-3`,title:n,children:[(0,Y.jsx)(`div`,{className:`text-xs font-medium text-white mb-1`,children:e}),(0,Y.jsx)(`div`,{className:`text-lg font-semibold text-white`,children:t})]})}function Qt({label:e,hint:t,unit:n,editing:r,value:i,inputValue:a,onInputChange:o,onEdit:s,onSave:c,onCancel:l,isPending:u,saveLabel:d=`Save`,cancelLabel:f=`Cancel`}){return(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-tertiary/40 rounded-lg p-3 space-y-1`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(`span`,{className:`text-xs font-medium text-white`,children:e}),(0,Y.jsx)(`span`,{title:t,children:(0,Y.jsx)(O,{className:`w-3 h-3 text-bambu-gray/50`})})]}),r?(0,Y.jsxs)(`form`,{className:`flex items-center gap-2`,onSubmit:e=>{e.preventDefault(),c()},children:[(0,Y.jsx)(`input`,{type:`number`,min:0,max:365,value:a,onChange:e=>o(e.target.value),className:`w-20 px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-sm text-white focus:outline-none focus:border-bambu-green`,autoFocus:!0,disabled:u}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:n}),(0,Y.jsx)(`button`,{type:`submit`,disabled:u,className:`px-2 py-1 bg-bambu-green text-white text-xs rounded hover:bg-bambu-green/80 disabled:opacity-50`,children:d}),(0,Y.jsx)(`button`,{type:`button`,onClick:l,disabled:u,className:`px-2 py-1 text-xs text-bambu-gray hover:text-white`,children:f})]}):(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{className:`text-lg font-semibold text-white`,children:i}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:n}),(0,Y.jsx)(`button`,{onClick:s,className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,Y.jsx)(I,{className:`w-3 h-3`})})]})]})}function $t({value:e,unit:t,editing:n,inputValue:r,dailyRateG:i,onInputChange:a,onUnitChange:o,onEdit:s,onSave:l,onCancel:u,isPending:d,saveLabel:f=`Save`,cancelLabel:p=`Cancel`,safetyMarginLabel:m=`Safety Margin`}){let{t:h}=c(),g=t===`g`?e:i===null?null:Math.round(i*e),_=t===`days`?h(`forecast.safetyMarginHintDays`,{approx:g===null?``:h(`forecast.safetyMarginHintDaysApprox`,{g})}):h(`forecast.safetyMarginHintG`,{approx:i===null?``:h(`forecast.safetyMarginHintGApprox`,{days:Math.round(e/i)})});return(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-tertiary/40 rounded-lg p-3 space-y-1`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(`span`,{className:`text-xs font-medium text-white`,children:m}),(0,Y.jsx)(`span`,{title:_,children:(0,Y.jsx)(O,{className:`w-3 h-3 text-bambu-gray/50`})})]}),n?(0,Y.jsxs)(`form`,{className:`flex items-center gap-2 flex-wrap`,onSubmit:e=>{e.preventDefault(),l()},children:[(0,Y.jsx)(`input`,{type:`number`,min:0,max:t===`g`?1e4:365,value:r,onChange:e=>a(e.target.value),className:`w-20 px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-sm text-white focus:outline-none focus:border-bambu-green`,autoFocus:!0,disabled:d}),(0,Y.jsxs)(`div`,{className:`flex bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded overflow-hidden text-xs`,children:[(0,Y.jsx)(`button`,{type:`button`,onClick:()=>o(`days`),className:`px-2 py-1 transition-colors ${t===`days`?`bg-bambu-green text-white`:`text-bambu-gray hover:text-white`}`,children:`days`}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>o(`g`),className:`px-2 py-1 transition-colors ${t===`g`?`bg-bambu-green text-white`:`text-bambu-gray hover:text-white`}`,children:`g`})]}),(0,Y.jsx)(`button`,{type:`submit`,disabled:d,className:`px-2 py-1 bg-bambu-green text-white text-xs rounded hover:bg-bambu-green/80 disabled:opacity-50`,children:f}),(0,Y.jsx)(`button`,{type:`button`,onClick:u,disabled:d,className:`px-2 py-1 text-xs text-bambu-gray hover:text-white`,children:p})]}):(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{className:`text-lg font-semibold text-white`,children:e}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:t}),g!==null&&t===`days`&&(0,Y.jsxs)(`span`,{className:`text-lg font-semibold text-white`,children:[`≈ `,g,`g`]}),t===`g`&&i!==null&&(0,Y.jsxs)(`span`,{className:`text-lg font-semibold text-white`,children:[`≈ `,Math.round(e/i),`d`]}),(0,Y.jsx)(`button`,{onClick:s,className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,Y.jsx)(I,{className:`w-3 h-3`})})]})]})}function en({items:e,forecasts:t,globalLeadTime:n,canWrite:i,onClose:a,onRemove:o,onClear:s}){let{t:u}=c(),f=l(),[p,m]=(0,J.useState)(`list`),h=d({mutationFn:async({id:e,status:t,item:n,avgSpoolG:i})=>{if(await r.updateShoppingListStatus(e,t),t===`received`&&n){let t=i??1e3,a={material:n.material,subtype:n.subtype,brand:n.brand,label_weight:t,core_weight:0,core_weight_catalog_id:null,color_name:n.color_name,rgba:null,extra_colors:null,effect_type:null,nozzle_temp_min:null,nozzle_temp_max:null,note:n.note??null,tag_uid:null,tray_uuid:null,data_origin:`manual`,tag_type:null,cost_per_kg:null,last_scale_weight:null,last_weighed_at:null,weight_used:0,slicer_filament:null,slicer_filament_name:null,added_full:null,last_used:null,encode_time:null,category:`Stock`,low_stock_threshold_pct:null,material_number:null};await r.bulkCreateSpools(a,n.quantity_spools),await r.removeFromShoppingList(e)}},onSuccess:()=>{f.invalidateQueries({queryKey:[`shopping-list`]}),f.invalidateQueries({queryKey:[`spools`]})}}),g=(0,J.useMemo)(()=>{let e=new Map;for(let n of t)e.set(n.group.key,n);return e},[t]),_=(0,J.useMemo)(()=>e.map(e=>({item:e,forecast:g.get(X(e.material,e.subtype,e.brand,e.color_name))??null})),[e,g]),v=(0,J.useMemo)(()=>_.filter(({forecast:e})=>!e||e.dailyRateG===null?!1:e.stockBreakAlert||e.daysRemaining!==null&&e.daysRemaining<=e.effectiveLeadTimeDays),[_]);function y(){let t=[u(`forecast.qty`),u(`forecast.material`),u(`inventory.brand`),u(`inventory.subtype`),u(`inventory.color`),`${u(`forecast.weight`)} (g)`,`${u(`forecast.leadTime`)} (d)`,u(`forecast.expectedRestock`),u(`forecast.status`),u(`forecast.note`)],r=e.map(e=>{let t=g.get(X(e.material,e.subtype,e.brand,e.color_name))??null,r=t&&t.totalSpools>0?t.totalLabelG/t.totalSpools:1e3,i=Math.round(e.quantity_spools*r),a=t?.effectiveLeadTimeDays??n??0,o=a>0?zt(Z(new Date,a)):``;return[e.quantity_spools,e.material,e.brand??``,e.subtype??``,e.color_name??``,i,a||``,o,e.status,e.note??``].map(e=>`"${String(e).replace(/"/g,`""`)}"`).join(`,`)}),i=[t.join(`,`),...r].join(` +import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,n as i,r as a,t as o,v as s,w as c}from"./client-DnySrlFv.js";import{n as l}from"./QueryClientProvider-Ce8_sN3w.js";import{t as u}from"./useQuery-BBCjCezC.js";import{t as d}from"./useMutation-B-Tr2hIP.js";import{t as f}from"./useQueries-Be6PMvSC.js";import{t as p}from"./createLucideIcon-DvBYJlWL.js";import{i as m,n as h,r as g}from"./haSensorDisplay-lPbcOxD8.js";import{t as _}from"./arrow-down-Cj0DZhNf.js";import{t as v}from"./arrow-up-down-BdyOV_2F.js";import{t as y}from"./arrow-up-D-pfJ3WZ.js";import{i as b,n as x,r as S,t as C}from"./ReferenceLine-clJprXoH.js";import{t as w}from"./check-Ck0cMLU4.js";import{a as T,i as E,n as D,t as O}from"./info-ROUoQhJR.js";import{n as ee,t as k}from"./chevrons-right-DTJgqnxZ.js";import{n as te,r as A}from"./ToastContext-BRX0SW3C.js";import{t as j}from"./columns-2-DVEObeDC.js";import{t as M}from"./copy-Cu_0GKCU.js";import{t as N}from"./layout-grid-DkD3u6wa.js";import{t as P}from"./link-2-MI-QCMh8.js";import{t as F}from"./loader-circle-BEmFtawu.js";import{t as ne}from"./lock-MLqgWH4Q.js";import{_ as I,c as L,g as re,h as R,s as ie,v as ae}from"./locationSensorDefaults-DcLWzMwe.js";import{t as oe}from"./package-BGUevlqS.js";import{t as se}from"./search-0n0CBc74.js";import{t as z}from"./sparkles-DRqKNlhr.js";import{L as ce,Rn as le,Xt as ue,c as de,p as fe,s as pe}from"./CartesianChart-BAcHzPFb.js";import{t as B}from"./triangle-alert-Dt_1FcBy.js";import{t as me}from"./unlink-C098nwOf.js";import{t as he}from"./x-DR-Trv6U.js";import{t as V}from"./Button-DDr6eAFy.js";import{r as ge,v as H,y as _e}from"./date-G9KUauqz.js";import{n as ve}from"./filamentSwatchHelpers-D3oXQSGk.js";import{$t as ye,At as be,Cn as xe,Gt as Se,H as Ce,Jt as U,Kt as we,Ln as Te,Lt as Ee,Mn as De,On as Oe,Pt as ke,Rt as Ae,Tt as je,Ut as Me,Wn as Ne,Zt as Pe,_t as Fe,a as Ie,at as Le,bt as Re,cn as ze,en as Be,ft as Ve,i as He,jn as Ue,kn as We,kt as Ge,lt as Ke,o as qe,ot as Je,r as Ye,s as Xe,st as W,w as Ze,wn as Qe,xn as $e,yt as et,zt as tt}from"./index-Cxa-KVmA.js";import{i as nt,r as rt}from"./slicerPrinterMatch-CUdoNag2.js";import{t as it}from"./ColumnConfigModal-BBpKz9m6.js";import{n as at,t as ot}from"./AreaChart-DJpIJXxF.js";import{a as st,i as ct,n as lt,o as ut,r as G,s as dt,t as ft}from"./AdditionalSection-9uxxm13d.js";import{_ as pt,a as K,b as mt,c as ht,d as gt,f as _t,g as vt,i as yt,l as bt,m as xt,n as St,o as Ct,r as wt,s as Tt,t as Et,u as Dt,v as Ot}from"./utils-subfXwl6.js";import{t as kt}from"./AssignToAmsModal-dWQ_DHhy.js";import{t as At}from"./inventorySearch-TJiB5tGt.js";var q=p(`beaker`,[[`path`,{d:`M4.5 3h15`,key:`c7n0jr`}],[`path`,{d:`M6 3v16a2 2 0 0 0 2 2h8a2 2 0 0 0 2-2V3`,key:`m1uhx7`}],[`path`,{d:`M6 14h12`,key:`4cwo0f`}]]),jt=p(`chart-no-axes-column`,[[`path`,{d:`M5 21v-6`,key:`1hz6c0`}],[`path`,{d:`M12 21V3`,key:`1lcnhd`}],[`path`,{d:`M19 21V9`,key:`unv183`}]]),Mt=p(`credit-card`,[[`rect`,{width:`20`,height:`14`,x:`2`,y:`5`,rx:`2`,key:`ynyp8z`}],[`line`,{x1:`2`,x2:`22`,y1:`10`,y2:`10`,key:`1b3vmo`}]]),Nt=p(`group`,[[`path`,{d:`M3 7V5c0-1.1.9-2 2-2h2`,key:`adw53z`}],[`path`,{d:`M17 3h2c1.1 0 2 .9 2 2v2`,key:`an4l38`}],[`path`,{d:`M21 17v2c0 1.1-.9 2-2 2h-2`,key:`144t0e`}],[`path`,{d:`M7 21H5c-1.1 0-2-.9-2-2v-2`,key:`rtnfgi`}],[`rect`,{width:`7`,height:`5`,x:`7`,y:`7`,rx:`1`,key:`1eyiv7`}],[`rect`,{width:`7`,height:`5`,x:`10`,y:`12`,rx:`1`,key:`1qlmkx`}]]),Pt=p(`package-check`,[[`path`,{d:`m16 16 2 2 4-4`,key:`gfu2re`}],[`path`,{d:`M21 10V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l2-1.14`,key:`e7tb2h`}],[`path`,{d:`m7.5 4.27 9 5.15`,key:`1c824w`}],[`polyline`,{points:`3.29 7 12 12 20.71 7`,key:`ousv84`}],[`line`,{x1:`12`,x2:`12`,y1:`22`,y2:`12`,key:`a4e8g8`}]]),Ft=p(`store`,[[`path`,{d:`M15 21v-5a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v5`,key:`slp6dd`}],[`path`,{d:`M17.774 10.31a1.12 1.12 0 0 0-1.549 0 2.5 2.5 0 0 1-3.451 0 1.12 1.12 0 0 0-1.548 0 2.5 2.5 0 0 1-3.452 0 1.12 1.12 0 0 0-1.549 0 2.5 2.5 0 0 1-3.77-3.248l2.889-4.184A2 2 0 0 1 7 2h10a2 2 0 0 1 1.653.873l2.895 4.192a2.5 2.5 0 0 1-3.774 3.244`,key:`o0xfot`}],[`path`,{d:`M4 10.95V19a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-8.05`,key:`wn3emo`}]]),It=p(`table-properties`,[[`path`,{d:`M15 3v18`,key:`14nvp0`}],[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M21 9H3`,key:`1338ky`}],[`path`,{d:`M21 15H3`,key:`9uk58r`}]]),J=e(n(),1),Y=t(),Lt=1.65,Rt=[`#1DB954`,`#3B82F6`,`#F59E0B`,`#EF4444`,`#8B5CF6`];function X(e,t,n,r){return`${e}||${t??``}||${n??``}||${r??``}`}function Z(e,t){let n=new Date(e);return n.setDate(n.getDate()+Math.round(t)),n}function zt(e){return e.toLocaleDateString(void 0,{month:`short`,day:`numeric`,year:`numeric`})}function Bt(e){return e.toLocaleDateString(void 0,{month:`short`,day:`numeric`})}function Vt(e){if(e.length<2)return null;let t=new Map;for(let n of e){let e=n.created_at.slice(0,10);t.set(e,(t.get(e)??0)+n.weight_used)}if(t.size<2)return null;let n=[...t.entries()].map(([e,t])=>({ms:new Date(e).getTime(),totalG:t})).sort((e,t)=>e.ms-t.ms),r=Date.now(),i=Math.LN2/30,a=[];for(let e=1;ee+t.weight,0);if(o===0)return null;let s=a.reduce((e,t)=>e+t.rate*t.weight,0)/o,c=a.reduce((e,t)=>e+t.weight*(t.rate-s)**2,0)/o;return{rate:s,stdDev:Math.sqrt(c)}}function Ht(e){let t=e.reduce((e,t)=>e+Math.max(0,t.weight_used-(t.weight_used_baseline??0)),0);if(t===0)return null;let n=Date.now(),r=(n-e.reduce((e,t)=>{let n=new Date(t.created_at).getTime();return nr.getAllUsageHistory(5e3),staleTime:6e4,enabled:s}),{data:M=[]}=u({queryKey:[`shopping-list`],queryFn:r.getShoppingList,staleTime:3e4,enabled:s}),N=k?.forecast_global_lead_time_days??0,P=(0,J.useMemo)(()=>{let e=new Map;for(let t of A)e.set(X(t.material,t.subtype,t.brand,t.color_name),t);return e},[A]),F=(0,J.useMemo)(()=>{let e=new Map;for(let t of j){let n=e.get(t.spool_id)??[];n.push(t),e.set(t.spool_id,n)}return e},[j]),I=(0,J.useMemo)(()=>{let t=new Map;for(let n of e){if(n.archived_at)continue;let e=X(n.material,n.subtype,n.brand,n.color_name),r=t.get(e)??{key:e,material:n.material,subtype:n.subtype,brand:n.brand,colorName:n.color_name,spools:[]};r.spools.push(n),t.set(e,r)}return[...t.values()]},[e]),L=(0,J.useMemo)(()=>{let e=new Date;return e.setHours(0,0,0,0),I.map(t=>{let n=P.get(t.key)??(t.colorName===null?null:P.get(X(t.material,t.subtype,t.brand,null))??null),r=n?.lead_time_days??0,i=Math.max(N,r),a=n?.safety_margin_value??14,o=n?.safety_margin_unit??`days`,s=t.spools.reduce((e,t)=>e+Math.max(0,t.label_weight-t.weight_used),0),c=t.spools.reduce((e,t)=>e+t.label_weight,0),l=t.spools.reduce((e,t)=>e+Math.max(0,t.weight_used-(t.weight_used_baseline??0)),0),u=[];for(let e of t.spools)(e.weight_used_baseline??0)===0&&u.push(...F.get(e.id)??[]);let d=null,f=null,p=`none`,m=Vt(u);if(m!==null)d=m.rate,f=m.stdDev,p=`history`;else{let e=Ht(t.spools);e!==null&&(d=e,p=`delta`)}let h=Lt*(f??(d===null?0:d*.2))*Math.sqrt(i)+(o===`g`?a:d===null?a*5:d*a),g=d===null?0:d*i+h,_=d&&d>0?Math.floor(s/d):null,v=_===null?null:Z(e,_),y=d&&d>0?Math.floor((s-g)/d):null,b=y===null?null:Z(e,Math.max(0,y)),x=_!==null&&i>0&&_<=i,S=!x&&y!==null&&y<=0;return{group:t,settings:n,totalRemainingG:s,totalLabelG:c,totalSpools:t.spools.length,totalUsedG:l,dailyRateG:d,dailyRateStdDev:f,rateTier:p,effectiveLeadTimeDays:i,safetyStockG:h,reorderPointG:g,daysRemaining:_,daysUntilROP:y,projectedEmptyDate:v,reorderTriggerDate:b,reorderAlert:S,stockBreakAlert:x}})},[I,P,F,N]),re=(0,J.useMemo)(()=>[...new Set(I.map(e=>e.material))].sort(),[I]),R=(0,J.useMemo)(()=>[...new Set(I.map(e=>e.brand).filter(Boolean))].sort(),[I]),ie=(0,J.useMemo)(()=>{let e=[...L];return v&&(e=e.filter(e=>e.group.material===v)),b&&(e=e.filter(e=>e.group.brand===b)),e.sort((e,t)=>{let n=0,r=0;switch(m){case`material`:n=[e.group.material,e.group.subtype??``,e.group.brand??``].join(` `).toLowerCase(),r=[t.group.material,t.group.subtype??``,t.group.brand??``].join(` `).toLowerCase();break;case`used`:n=e.totalUsedG,r=t.totalUsedG;break;case`days_left`:n=e.daysRemaining??999999,r=t.daysRemaining??999999;break;case`stock`:n=e.totalRemainingG,r=t.totalRemainingG;break}let i=nr);return g===`asc`?i:-i}),e},[L,m,g,v,b]),ae=(0,J.useMemo)(()=>L.filter(e=>!e.settings?.alerts_snoozed&&(e.stockBreakAlert||e.reorderAlert)),[L]),oe=(0,J.useMemo)(()=>[...L].filter(e=>e.dailyRateG!==null).sort((e,t)=>t.totalUsedG-e.totalUsedG).slice(0,5),[L]);if(!s)return(0,Y.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-16 text-bambu-gray gap-3`,children:[(0,Y.jsx)(ne,{className:`w-8 h-8 opacity-40`}),(0,Y.jsx)(`p`,{className:`text-sm`,children:i(`forecast.noReadAccess`)})]});function se(e){m===e?_(e=>e===`asc`?`desc`:`asc`):(h(e),_(e===`days_left`?`asc`:`desc`))}let z=M.length>0?M.length:null;return(0,Y.jsxs)(`div`,{className:`space-y-5`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[ae.length>0&&(0,Y.jsxs)(`button`,{onClick:()=>p(e=>!e),className:`flex items-center gap-2 px-3 py-1.5 rounded-lg border text-sm font-medium transition-colors ${ae.some(e=>e.stockBreakAlert)?`bg-red-100 dark:bg-red-500/15 border-red-300 dark:border-red-500/30 text-red-700 dark:text-red-300 hover:bg-red-200 dark:hover:bg-red-500/25`:`bg-yellow-100 dark:bg-yellow-500/15 border-yellow-300 dark:border-yellow-500/30 text-yellow-700 dark:text-yellow-300 hover:bg-yellow-200 dark:hover:bg-yellow-500/25`}`,children:[(0,Y.jsx)(B,{className:`w-4 h-4`}),i(`forecast.alertCount`,{count:ae.length}),f?(0,Y.jsx)(E,{className:`w-3.5 h-3.5`}):(0,Y.jsx)(T,{className:`w-3.5 h-3.5`})]}),d&&(0,Y.jsx)(Yt,{value:N,onSave:e=>{r.updateSettings({forecast_global_lead_time_days:e}).then(()=>{t.invalidateQueries({queryKey:[`settings`]}),n(i(`forecast.globalLeadTimeSaved`),`success`)})}}),(0,Y.jsxs)(`select`,{value:v,onChange:e=>y(e.target.value),className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${v?`bg-bambu-green/20 text-bambu-green border-bambu-green/30`:`bg-transparent text-bambu-gray border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary`}`,children:[(0,Y.jsx)(`option`,{value:``,children:i(`inventory.material`)}),re.map(e=>(0,Y.jsx)(`option`,{value:e,children:e},e))]}),(0,Y.jsxs)(`select`,{value:b,onChange:e=>x(e.target.value),className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${b?`bg-bambu-green/20 text-bambu-green border-bambu-green/30`:`bg-transparent text-bambu-gray border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary`}`,children:[(0,Y.jsx)(`option`,{value:``,children:i(`inventory.brand`)}),R.map(e=>(0,Y.jsx)(`option`,{value:e,children:e},e))]}),(0,Y.jsxs)(`button`,{onClick:()=>D(e=>!e),className:`relative flex items-center gap-2 px-3 py-1.5 rounded-lg border border-bambu-dark-tertiary text-bambu-gray hover:bg-bambu-dark-tertiary text-sm transition-colors ml-auto`,children:[(0,Y.jsx)(tt,{className:`w-4 h-4`}),(0,Y.jsx)(`span`,{className:`hidden sm:inline`,children:i(`forecast.shoppingList`)}),z&&(0,Y.jsx)(`span`,{className:`absolute -top-1.5 -right-1.5 w-4 h-4 rounded-full bg-bambu-green text-white text-[10px] font-bold flex items-center justify-center`,children:z})]})]}),f&&ae.length>0&&(0,Y.jsx)(`div`,{className:`space-y-2`,children:ae.map(e=>(0,Y.jsx)(Kt,{forecast:e,onCart:()=>C(e)},e.group.key))}),w&&(0,Y.jsx)(en,{items:M,forecasts:L,globalLeadTime:N,canWrite:d,onClose:()=>D(!1),onRemove:e=>{r.removeFromShoppingList(e).then(()=>t.invalidateQueries({queryKey:[`shopping-list`]})).catch(()=>n(i(`forecast.failedSaveSettings`),`error`))},onClear:()=>{r.clearShoppingList().then(()=>t.invalidateQueries({queryKey:[`shopping-list`]})).catch(()=>n(i(`forecast.failedSaveSettings`),`error`))}}),oe.length>0&&(0,Y.jsx)(Jt,{forecasts:oe,days:O,onDaysChange:ee}),L.length===0?(0,Y.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-16 text-bambu-gray`,children:[(0,Y.jsx)(le,{className:`w-10 h-10 mb-3 opacity-40`}),(0,Y.jsx)(`p`,{className:`text-sm`,children:i(`forecast.noSpools`)})]}):(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-dark-tertiary`,children:[(0,Y.jsx)(`div`,{className:`overflow-x-auto`,children:(0,Y.jsxs)(`table`,{className:`w-full`,children:[(0,Y.jsx)(`thead`,{children:(0,Y.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary bg-bambu-dark-tertiary/30`,children:[(0,Y.jsx)(`th`,{className:`w-8 px-4 py-3`}),(0,Y.jsx)(Gt,{col:`material`,active:m,dir:g,onSort:se,children:i(`forecast.sku`)}),(0,Y.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:i(`locations.spools`)}),(0,Y.jsx)(Gt,{col:`stock`,active:m,dir:g,onSort:se,children:i(`forecast.stock`)}),(0,Y.jsx)(Gt,{col:`used`,active:m,dir:g,onSort:se,children:i(`forecast.dailyRate`)}),(0,Y.jsx)(Gt,{col:`days_left`,active:m,dir:g,onSort:se,children:i(`forecast.daysLeft`)}),(0,Y.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:i(`forecast.emptyBy`)}),(0,Y.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:i(`forecast.reorderBy`)}),(0,Y.jsx)(`th`,{className:`w-24 px-4 py-3`})]})}),(0,Y.jsx)(`tbody`,{className:`divide-y divide-bambu-dark-tertiary`,children:ie.map(e=>(0,Y.jsx)(Xt,{forecast:e,globalLeadTime:N,canWrite:d,onSaved:()=>t.invalidateQueries({queryKey:[`sku-settings`]}),onCart:()=>C(e),showToast:n},e.group.key))})]})}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4 px-4 py-3 text-xs text-bambu-gray border-t border-bambu-dark-tertiary bg-bambu-dark-tertiary/20`,children:[(0,Y.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-bambu-green inline-block`}),i(`forecast.trendLegend`)]}),(0,Y.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-blue-400 inline-block`}),i(`forecast.estimatedLegend`)]}),(0,Y.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-bambu-gray/40 inline-block`}),i(`forecast.noDataLegend`)]})]})]}),S&&(0,Y.jsx)(nn,{forecast:S,onClose:()=>C(null),onAdd:e=>{r.addToShoppingList(e).then(()=>{t.invalidateQueries({queryKey:[`shopping-list`]}),n(i(`forecast.addedToCart`),`success`),C(null),D(!0)}).catch(()=>n(i(`forecast.failedAddItem`),`error`))}})]})}function Gt({col:e,active:t,dir:n,onSort:r,children:i}){return(0,Y.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide cursor-pointer select-none hover:text-white transition-colors`,onClick:()=>r(e),children:(0,Y.jsxs)(`span`,{className:`inline-flex items-center`,children:[i,t===e?n===`asc`?(0,Y.jsx)(y,{className:`w-3 h-3 ml-1 text-bambu-green`}):(0,Y.jsx)(_,{className:`w-3 h-3 ml-1 text-bambu-green`}):(0,Y.jsx)(v,{className:`w-3 h-3 ml-1 opacity-40`})]})})}function Kt({forecast:e,onCart:t}){let{t:n}=c(),r=[e.group.brand,e.group.material,e.group.subtype,e.group.colorName].filter(Boolean).join(` `),i=e.stockBreakAlert;return(0,Y.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-3 rounded-lg border text-sm ${i?`bg-red-50 dark:bg-red-500/10 border-red-300 dark:border-red-500/30 text-red-700 dark:text-red-300`:`bg-yellow-50 dark:bg-yellow-500/10 border-yellow-300 dark:border-yellow-500/30 text-yellow-700 dark:text-yellow-300`}`,children:[(0,Y.jsx)(B,{className:`w-4 h-4 flex-shrink-0`}),(0,Y.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Y.jsx)(`span`,{className:`font-medium`,children:r}),i?(0,Y.jsxs)(`span`,{className:`ml-2 text-xs opacity-80`,children:[n(`forecast.stockBreakRisk`),` — `,n(`forecast.stockBreakDetail`,{days:e.daysRemaining,lt:e.effectiveLeadTimeDays})]}):(0,Y.jsxs)(`span`,{className:`ml-2 text-xs opacity-80`,children:[n(`forecast.reorderNow`),` — `,n(`forecast.reorderTriggerPassed`,{date:e.reorderTriggerDate?zt(e.reorderTriggerDate):`—`})]})]}),(0,Y.jsxs)(`button`,{onClick:t,className:`flex items-center gap-1.5 px-2.5 py-1 rounded border border-current text-xs opacity-70 hover:opacity-100 transition-opacity`,children:[(0,Y.jsx)(tt,{className:`w-3 h-3`}),` `,n(`forecast.order`)]})]})}var qt=[{label:`1W`,value:7},{label:`1M`,value:30},{label:`6M`,value:180}];function Jt({forecasts:e,days:t,onDaysChange:n}){let{t:r}=c(),i=Array.from({length:t+1},(e,t)=>t),a=e.map((e,n)=>({key:e.group.key,label:[e.group.brand,e.group.material,e.group.subtype,e.group.colorName].filter(Boolean).join(` `),color:Rt[n%Rt.length],rop:e.reorderPointG,points:Ut(e,t)})),o=i.map(e=>{let t={day:e,label:Bt(Z(new Date,e))};for(let n of a){let r=n.points.find(t=>t.day===e);t[n.key]=r?.stock??0}return t}),s=(()=>{for(let e=t;e>=0;e--)if(a.some(t=>o[e]?.[t.key]>0))return e;return t})(),l=o.slice(0,s+1),u=a.filter(e=>e.rop>0);return(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-dark-tertiary p-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 mb-4`,children:[(0,Y.jsx)(le,{className:`w-4 h-4 text-bambu-green`}),(0,Y.jsx)(`h3`,{className:`text-sm font-semibold text-white`,children:r(`forecast.chartTitle`)}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1 hidden sm:inline`,children:r(`forecast.dashedLinesROP`)}),(0,Y.jsx)(`div`,{className:`ml-auto flex items-center bg-bambu-dark-tertiary rounded-lg p-0.5`,children:qt.map(e=>(0,Y.jsx)(`button`,{onClick:()=>n(e.value),className:`px-2.5 py-1 text-xs font-medium rounded-md transition-colors ${t===e.value?`bg-bambu-dark-secondary text-white shadow`:`text-bambu-gray hover:text-white`}`,children:e.label},e.value))})]}),(0,Y.jsx)(ue,{width:`100%`,height:220,children:(0,Y.jsxs)(ot,{data:l,margin:{top:4,right:8,bottom:0,left:0},children:[(0,Y.jsx)(`defs`,{children:a.map(e=>(0,Y.jsxs)(`linearGradient`,{id:`grad-${e.key}`,x1:`0`,y1:`0`,x2:`0`,y2:`1`,children:[(0,Y.jsx)(`stop`,{offset:`5%`,stopColor:e.color,stopOpacity:.25}),(0,Y.jsx)(`stop`,{offset:`95%`,stopColor:e.color,stopOpacity:.02})]},e.key))}),(0,Y.jsx)(fe,{strokeDasharray:`3 3`,stroke:`#374151`,strokeOpacity:.5}),(0,Y.jsx)(de,{dataKey:`label`,tick:{fill:`#6B7280`,fontSize:10},interval:Math.max(0,Math.ceil(s/8)-1),axisLine:!1,tickLine:!1}),(0,Y.jsx)(pe,{tick:{fill:`#6B7280`,fontSize:10},axisLine:!1,tickLine:!1,tickFormatter:e=>e>=1e3?`${(e/1e3).toFixed(1)}kg`:`${e}g`,width:48}),(0,Y.jsx)(ce,{content:({label:e,payload:t})=>t?.length?(0,Y.jsxs)(`div`,{style:{background:`#1a1a2e`,border:`1px solid #374151`,borderRadius:8,fontSize:12,padding:`8px 12px`},children:[(0,Y.jsx)(`div`,{style:{color:`#9CA3AF`,marginBottom:6},children:e}),t.map(e=>{let t=a.find(t=>t.key===String(e.dataKey));return typeof e.value==`number`?(0,Y.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:6,color:`#E5E7EB`,marginBottom:2},children:[(0,Y.jsx)(`span`,{style:{color:t?.color??`#9CA3AF`,fontSize:10},children:`●`}),(0,Y.jsx)(`span`,{children:t?.label??String(e.dataKey)}),(0,Y.jsxs)(`span`,{style:{color:`#9CA3AF`,marginLeft:4},children:[e.value,`g`]})]},String(e.dataKey)):null})]}):null}),(0,Y.jsx)(x,{formatter:e=>(0,Y.jsx)(`span`,{style:{color:`#9CA3AF`,fontSize:11},children:a.find(t=>t.key===e)?.label??e})}),a.map(e=>(0,Y.jsx)(at,{type:`monotone`,dataKey:e.key,stroke:e.color,strokeWidth:2,fill:`url(#grad-${e.key})`,dot:!1,activeDot:{r:3}},e.key)),u.map(e=>(0,Y.jsx)(C,{y:e.rop,stroke:e.color,strokeDasharray:`4 3`,strokeOpacity:.6},`rop-${e.key}`))]})})]})}function Yt({value:e,onSave:t}){let{t:n}=c(),[r,i]=(0,J.useState)(!1),[a,o]=(0,J.useState)(String(e));function s(){let e=parseInt(a,10);isNaN(e)||e<0||(t(e),i(!1))}return(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-1.5 bg-bambu-dark-tertiary/40 rounded-lg border border-bambu-dark-tertiary text-xs text-bambu-gray`,children:[(0,Y.jsx)(O,{className:`w-3.5 h-3.5 flex-shrink-0`,"aria-label":n(`forecast.globalLeadTimeHint`)}),(0,Y.jsxs)(`span`,{className:`hidden sm:inline`,children:[n(`forecast.globalLeadTime`),`:`]}),r?(0,Y.jsxs)(`form`,{className:`flex items-center gap-1.5`,onSubmit:e=>{e.preventDefault(),s()},children:[(0,Y.jsx)(`input`,{type:`number`,min:0,max:365,value:a,onChange:e=>o(e.target.value),className:`w-14 px-1.5 py-0.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-sm text-white focus:outline-none focus:border-bambu-green`,autoFocus:!0}),(0,Y.jsx)(`span`,{className:`text-bambu-gray`,children:`d`}),(0,Y.jsx)(`button`,{type:`submit`,className:`px-2 py-0.5 bg-bambu-green text-white text-xs rounded hover:bg-bambu-green/80`,children:n(`forecast.save`)}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>i(!1),className:`text-xs text-bambu-gray hover:text-white`,children:`✕`})]}):(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsxs)(`span`,{className:`font-semibold text-white`,children:[e,`d`]}),(0,Y.jsx)(`button`,{onClick:()=>{o(String(e)),i(!0)},className:`p-0.5 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,Y.jsx)(I,{className:`w-3 h-3`})})]})]})}function Xt({forecast:e,globalLeadTime:t,canWrite:n,onSaved:i,onCart:a,showToast:o}){let{t:s}=c(),[l,u]=(0,J.useState)(!1),[f,p]=(0,J.useState)(!1),[m,h]=(0,J.useState)(!1),[g,_]=(0,J.useState)(String(e.settings?.lead_time_days??0)),[v,y]=(0,J.useState)(String(e.settings?.safety_margin_value??14)),[x,S]=(0,J.useState)(e.settings?.safety_margin_unit??`days`);(0,J.useEffect)(()=>{f||_(String(e.settings?.lead_time_days??0))},[e.settings?.lead_time_days,f]),(0,J.useEffect)(()=>{m||(y(String(e.settings?.safety_margin_value??14)),S(e.settings?.safety_margin_unit??`days`))},[e.settings?.safety_margin_value,e.settings?.safety_margin_unit,m]);let C=d({mutationFn:r.upsertSkuSettings,onSuccess:()=>{i(),o(s(`forecast.settingsSaved`),`success`)},onError:()=>o(s(`forecast.failedSaveSettings`),`error`)}),D=e.settings?.alerts_snoozed??!1,O=[e.group.brand,e.group.material,e.group.subtype,e.group.colorName].filter(Boolean).join(` `),ee=e.group.spools[0]?.rgba?Ke(e.group.spools[0].rgba):{backgroundColor:`#4B5563`},k=e.totalLabelG>0?Math.round(e.totalRemainingG/e.totalLabelG*100):0,te=D||e.daysRemaining===null?`text-bambu-gray`:e.stockBreakAlert?`text-red-700 dark:text-red-400`:e.reorderAlert||e.daysRemaining<30?`text-yellow-700 dark:text-yellow-400`:`text-green-700 dark:text-green-400`;function A(t,n,r,i=D){C.mutate({material:e.group.material,subtype:e.group.subtype,brand:e.group.brand,color_name:e.group.colorName,lead_time_days:t,safety_margin_value:n,safety_margin_unit:r,alerts_snoozed:i})}function j(t){t.stopPropagation(),A(e.settings?.lead_time_days??0,e.settings?.safety_margin_value??14,e.settings?.safety_margin_unit??`days`,!D)}let M=e.rateTier===`history`?(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-xs px-1.5 py-0.5 rounded bg-bambu-green/15 text-bambu-green`,children:[(0,Y.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-bambu-green`}),s(`forecast.trend`)]}):e.rateTier===`delta`?(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-xs px-1.5 py-0.5 rounded bg-blue-100 dark:bg-blue-400/15 text-blue-700 dark:text-blue-400`,children:[(0,Y.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-blue-400`}),s(`forecast.estimated`)]}):(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-xs px-1.5 py-0.5 rounded bg-bambu-dark-tertiary text-bambu-gray/60`,children:[(0,Y.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-bambu-gray/40`}),s(`forecast.noData`)]});return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/50 cursor-pointer hover:bg-bambu-dark-tertiary/30 transition-colors ${D?``:e.stockBreakAlert?`bg-red-500/5`:e.reorderAlert?`bg-yellow-500/5`:``} ${D?`opacity-50`:``}`,onClick:()=>u(e=>!e),children:[(0,Y.jsx)(`td`,{className:`px-4 py-3`,children:(0,Y.jsx)(`span`,{className:`block w-5 h-5 rounded-full border border-black/20`,style:ee})}),(0,Y.jsx)(`td`,{className:`px-4 py-3`,children:(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:O})}),(0,Y.jsx)(`td`,{className:`px-4 py-3`,children:(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.totalSpools})}),(0,Y.jsx)(`td`,{className:`px-4 py-3 min-w-[140px]`,children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`div`,{className:`flex-1 h-2 bg-bambu-dark-tertiary rounded-full overflow-hidden`,children:(0,Y.jsx)(`div`,{className:`h-full rounded-full ${k>50?`bg-bambu-green`:k>20?`bg-yellow-500`:`bg-red-500`}`,style:{width:`${Math.min(k,100)}%`}})}),(0,Y.jsxs)(`span`,{className:`text-xs text-bambu-gray min-w-[40px] text-right`,children:[Math.round(e.totalRemainingG),`g`]})]})}),(0,Y.jsx)(`td`,{className:`px-4 py-3`,children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 flex-wrap`,children:[(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:e.dailyRateG===null?`—`:`${e.dailyRateG.toFixed(1)}g/d`}),M]})}),(0,Y.jsx)(`td`,{className:`px-4 py-3`,children:(0,Y.jsx)(`span`,{className:`text-sm font-semibold ${te}`,children:e.daysRemaining===null?(0,Y.jsx)(`span`,{className:`text-bambu-gray font-normal`,children:`—`}):`${e.daysRemaining}d`})}),(0,Y.jsx)(`td`,{className:`px-4 py-3`,children:(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.projectedEmptyDate?zt(e.projectedEmptyDate):`—`})}),(0,Y.jsx)(`td`,{className:`px-4 py-3`,children:(0,Y.jsx)(`span`,{className:`text-sm ${!D&&e.reorderAlert?`text-yellow-700 dark:text-yellow-400`:`text-bambu-gray`}`,children:e.reorderTriggerDate?zt(e.reorderTriggerDate):`—`})}),(0,Y.jsx)(`td`,{className:`px-4 py-3`,onClick:e=>e.stopPropagation(),children:(0,Y.jsxs)(`div`,{className:`flex items-center justify-end gap-1`,children:[n&&(0,Y.jsx)(`button`,{onClick:a,className:`p-1.5 text-bambu-gray hover:text-bambu-green rounded transition-colors`,title:s(`forecast.addToCart`),children:(0,Y.jsx)(tt,{className:`w-4 h-4`})}),!D&&(e.stockBreakAlert?(0,Y.jsx)(B,{className:`w-4 h-4 text-red-600 dark:text-red-400`,"aria-label":s(`forecast.stockBreakRisk`)}):e.reorderAlert?(0,Y.jsx)(B,{className:`w-4 h-4 text-yellow-600 dark:text-yellow-400`,"aria-label":s(`forecast.reorderNow`)}):e.daysRemaining===null?null:(0,Y.jsx)(w,{className:`w-4 h-4 text-bambu-green/50`})),n&&(0,Y.jsx)(`button`,{onClick:j,className:`p-1 rounded transition-colors ${D?`text-amber-600/80 dark:text-amber-400/80 hover:text-amber-700 dark:hover:text-amber-300`:`text-slate-400 hover:text-white`}`,title:s(D?`forecast.alertsEnabled`:`forecast.alertsSnoozed`),children:(0,Y.jsx)(b,{className:`w-3.5 h-3.5`})}),(0,Y.jsx)(`button`,{onClick:e=>{e.stopPropagation(),u(e=>!e)},className:`p-1.5 text-bambu-gray hover:text-white rounded transition-colors`,children:l?(0,Y.jsx)(E,{className:`w-4 h-4`}):(0,Y.jsx)(T,{className:`w-4 h-4`})})]})})]}),l&&(0,Y.jsx)(`tr`,{className:`bg-bambu-dark-tertiary/10`,children:(0,Y.jsx)(`td`,{colSpan:9,className:`px-6 py-4`,children:(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`grid gap-2 ${n?`grid-cols-2 sm:grid-cols-4`:`grid-cols-2`}`,children:[(0,Y.jsx)(Zt,{label:s(`forecast.effectiveLeadTime`),value:`${e.effectiveLeadTimeDays}d`,hint:s(`forecast.effectiveLeadTimeHint`,{global:t,sku:e.settings?.lead_time_days??0})}),(0,Y.jsx)(Zt,{label:s(`forecast.reorderPoint`),value:`${Math.round(e.reorderPointG)}g`,hint:s(`forecast.reorderPointHint`)}),n&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(Qt,{label:s(`forecast.skuLeadTimeOverride`),hint:s(`forecast.skuLeadTimeHint`),unit:s(`forecast.leadTime`),editing:f,value:e.settings?.lead_time_days??0,inputValue:g,onInputChange:_,onEdit:()=>{_(String(e.settings?.lead_time_days??0)),p(!0)},onSave:()=>{let t=parseInt(g,10);!isNaN(t)&&t>=0&&(A(t,e.settings?.safety_margin_value??14,x),p(!1))},onCancel:()=>p(!1),isPending:C.isPending,saveLabel:s(`forecast.save`),cancelLabel:s(`forecast.cancel`)}),(0,Y.jsx)($t,{value:e.settings?.safety_margin_value??14,unit:x,editing:m,inputValue:v,dailyRateG:e.dailyRateG,onInputChange:y,onUnitChange:e=>S(e),onEdit:()=>{y(String(e.settings?.safety_margin_value??14)),S(e.settings?.safety_margin_unit??`days`),h(!0)},onSave:()=>{let t=parseInt(v,10);!isNaN(t)&&t>=0&&(A(e.settings?.lead_time_days??0,t,x),h(!1))},onCancel:()=>h(!1),isPending:C.isPending,saveLabel:s(`forecast.save`),cancelLabel:s(`forecast.cancel`),safetyMarginLabel:s(`forecast.safetyMarginLabel`)})]})]}),e.group.spools.length>1&&(0,Y.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary pt-3`,children:[(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:s(`forecast.individualSpools`)}),(0,Y.jsx)(`div`,{className:`bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-dark-tertiary`,children:(0,Y.jsxs)(`table`,{className:`w-full`,children:[(0,Y.jsx)(`thead`,{children:(0,Y.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary bg-bambu-dark-tertiary/30`,children:[(0,Y.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:`#`}),(0,Y.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:s(`inventory.remaining`)}),(0,Y.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:s(`inventory.used`)}),(0,Y.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:s(`forecast.labelWeight`)})]})}),(0,Y.jsx)(`tbody`,{className:`divide-y divide-bambu-dark-tertiary`,children:e.group.spools.map(e=>{let t=Math.max(0,e.label_weight-e.weight_used),n=e.label_weight>0?t/e.label_weight*100:0;return(0,Y.jsxs)(`tr`,{className:`hover:bg-bambu-dark-tertiary/30 transition-colors`,children:[(0,Y.jsx)(`td`,{className:`px-4 py-2`,children:(0,Y.jsxs)(`span`,{className:`text-xs font-mono text-bambu-gray/70`,children:[`#`,e.id]})}),(0,Y.jsx)(`td`,{className:`px-4 py-2`,children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Y.jsx)(`div`,{className:`w-24 h-1.5 bg-bambu-dark-tertiary rounded-full overflow-hidden flex-shrink-0`,children:(0,Y.jsx)(`div`,{className:`h-full rounded-full ${n>50?`bg-bambu-green`:n>20?`bg-yellow-500`:`bg-red-500`}`,style:{width:`${Math.min(n,100)}%`}})}),(0,Y.jsxs)(`span`,{className:`text-sm text-white`,children:[Math.round(t),`g`]})]})}),(0,Y.jsx)(`td`,{className:`px-4 py-2`,children:(0,Y.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[Math.round(Math.max(0,e.weight_used-(e.weight_used_baseline??0))),`g`]})}),(0,Y.jsx)(`td`,{className:`px-4 py-2`,children:(0,Y.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[e.label_weight,`g`]})})]},e.id)})})]})})]})]})})})]})}function Zt({label:e,value:t,hint:n}){return(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-tertiary/40 rounded-lg p-3`,title:n,children:[(0,Y.jsx)(`div`,{className:`text-xs font-medium text-white mb-1`,children:e}),(0,Y.jsx)(`div`,{className:`text-lg font-semibold text-white`,children:t})]})}function Qt({label:e,hint:t,unit:n,editing:r,value:i,inputValue:a,onInputChange:o,onEdit:s,onSave:c,onCancel:l,isPending:u,saveLabel:d=`Save`,cancelLabel:f=`Cancel`}){return(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-tertiary/40 rounded-lg p-3 space-y-1`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(`span`,{className:`text-xs font-medium text-white`,children:e}),(0,Y.jsx)(`span`,{title:t,children:(0,Y.jsx)(O,{className:`w-3 h-3 text-bambu-gray/50`})})]}),r?(0,Y.jsxs)(`form`,{className:`flex items-center gap-2`,onSubmit:e=>{e.preventDefault(),c()},children:[(0,Y.jsx)(`input`,{type:`number`,min:0,max:365,value:a,onChange:e=>o(e.target.value),className:`w-20 px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-sm text-white focus:outline-none focus:border-bambu-green`,autoFocus:!0,disabled:u}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:n}),(0,Y.jsx)(`button`,{type:`submit`,disabled:u,className:`px-2 py-1 bg-bambu-green text-white text-xs rounded hover:bg-bambu-green/80 disabled:opacity-50`,children:d}),(0,Y.jsx)(`button`,{type:`button`,onClick:l,disabled:u,className:`px-2 py-1 text-xs text-bambu-gray hover:text-white`,children:f})]}):(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{className:`text-lg font-semibold text-white`,children:i}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:n}),(0,Y.jsx)(`button`,{onClick:s,className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,Y.jsx)(I,{className:`w-3 h-3`})})]})]})}function $t({value:e,unit:t,editing:n,inputValue:r,dailyRateG:i,onInputChange:a,onUnitChange:o,onEdit:s,onSave:l,onCancel:u,isPending:d,saveLabel:f=`Save`,cancelLabel:p=`Cancel`,safetyMarginLabel:m=`Safety Margin`}){let{t:h}=c(),g=t===`g`?e:i===null?null:Math.round(i*e),_=t===`days`?h(`forecast.safetyMarginHintDays`,{approx:g===null?``:h(`forecast.safetyMarginHintDaysApprox`,{g})}):h(`forecast.safetyMarginHintG`,{approx:i===null?``:h(`forecast.safetyMarginHintGApprox`,{days:Math.round(e/i)})});return(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-tertiary/40 rounded-lg p-3 space-y-1`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(`span`,{className:`text-xs font-medium text-white`,children:m}),(0,Y.jsx)(`span`,{title:_,children:(0,Y.jsx)(O,{className:`w-3 h-3 text-bambu-gray/50`})})]}),n?(0,Y.jsxs)(`form`,{className:`flex items-center gap-2 flex-wrap`,onSubmit:e=>{e.preventDefault(),l()},children:[(0,Y.jsx)(`input`,{type:`number`,min:0,max:t===`g`?1e4:365,value:r,onChange:e=>a(e.target.value),className:`w-20 px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-sm text-white focus:outline-none focus:border-bambu-green`,autoFocus:!0,disabled:d}),(0,Y.jsxs)(`div`,{className:`flex bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded overflow-hidden text-xs`,children:[(0,Y.jsx)(`button`,{type:`button`,onClick:()=>o(`days`),className:`px-2 py-1 transition-colors ${t===`days`?`bg-bambu-green text-white`:`text-bambu-gray hover:text-white`}`,children:`days`}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>o(`g`),className:`px-2 py-1 transition-colors ${t===`g`?`bg-bambu-green text-white`:`text-bambu-gray hover:text-white`}`,children:`g`})]}),(0,Y.jsx)(`button`,{type:`submit`,disabled:d,className:`px-2 py-1 bg-bambu-green text-white text-xs rounded hover:bg-bambu-green/80 disabled:opacity-50`,children:f}),(0,Y.jsx)(`button`,{type:`button`,onClick:u,disabled:d,className:`px-2 py-1 text-xs text-bambu-gray hover:text-white`,children:p})]}):(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{className:`text-lg font-semibold text-white`,children:e}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:t}),g!==null&&t===`days`&&(0,Y.jsxs)(`span`,{className:`text-lg font-semibold text-white`,children:[`≈ `,g,`g`]}),t===`g`&&i!==null&&(0,Y.jsxs)(`span`,{className:`text-lg font-semibold text-white`,children:[`≈ `,Math.round(e/i),`d`]}),(0,Y.jsx)(`button`,{onClick:s,className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,Y.jsx)(I,{className:`w-3 h-3`})})]})]})}function en({items:e,forecasts:t,globalLeadTime:n,canWrite:i,onClose:a,onRemove:o,onClear:s}){let{t:u}=c(),f=l(),[p,m]=(0,J.useState)(`list`),h=d({mutationFn:async({id:e,status:t,item:n,avgSpoolG:i})=>{if(await r.updateShoppingListStatus(e,t),t===`received`&&n){let t=i??1e3,a={material:n.material,subtype:n.subtype,brand:n.brand,label_weight:t,core_weight:0,core_weight_catalog_id:null,color_name:n.color_name,rgba:null,extra_colors:null,effect_type:null,nozzle_temp_min:null,nozzle_temp_max:null,note:n.note??null,tag_uid:null,tray_uuid:null,data_origin:`manual`,tag_type:null,cost_per_kg:null,last_scale_weight:null,last_weighed_at:null,weight_used:0,slicer_filament:null,slicer_filament_name:null,added_full:null,last_used:null,encode_time:null,category:`Stock`,low_stock_threshold_pct:null,material_number:null};await r.bulkCreateSpools(a,n.quantity_spools),await r.removeFromShoppingList(e)}},onSuccess:()=>{f.invalidateQueries({queryKey:[`shopping-list`]}),f.invalidateQueries({queryKey:[`spools`]})}}),g=(0,J.useMemo)(()=>{let e=new Map;for(let n of t)e.set(n.group.key,n);return e},[t]),_=(0,J.useMemo)(()=>e.map(e=>({item:e,forecast:g.get(X(e.material,e.subtype,e.brand,e.color_name))??null})),[e,g]),v=(0,J.useMemo)(()=>_.filter(({forecast:e})=>!e||e.dailyRateG===null?!1:e.stockBreakAlert||e.daysRemaining!==null&&e.daysRemaining<=e.effectiveLeadTimeDays),[_]);function y(){let t=[u(`forecast.qty`),u(`forecast.material`),u(`inventory.brand`),u(`inventory.subtype`),u(`inventory.color`),`${u(`forecast.weight`)} (g)`,`${u(`forecast.leadTime`)} (d)`,u(`forecast.expectedRestock`),u(`forecast.status`),u(`forecast.note`)],r=e.map(e=>{let t=g.get(X(e.material,e.subtype,e.brand,e.color_name))??null,r=t&&t.totalSpools>0?t.totalLabelG/t.totalSpools:1e3,i=Math.round(e.quantity_spools*r),a=t?.effectiveLeadTimeDays??n??0,o=a>0?zt(Z(new Date,a)):``;return[e.quantity_spools,e.material,e.brand??``,e.subtype??``,e.color_name??``,i,a||``,o,e.status,e.note??``].map(e=>`"${String(e).replace(/"/g,`""`)}"`).join(`,`)}),i=[t.join(`,`),...r].join(` `),a=new Blob([i],{type:`text/csv`}),o=URL.createObjectURL(a),s=document.createElement(`a`);s.href=o,s.download=`shopping-list-${new Date().toISOString().slice(0,10)}.csv`,s.click(),setTimeout(()=>URL.revokeObjectURL(o),100)}return(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 border-b border-bambu-dark-tertiary bg-bambu-dark-tertiary/30`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Y.jsx)(tt,{className:`w-4 h-4 text-bambu-green`}),(0,Y.jsx)(`h3`,{className:`text-sm font-semibold text-white`,children:u(`forecast.shoppingList`)}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:u(`forecast.shoppingListItems`,{count:e.length})}),e.length>0&&(0,Y.jsxs)(`div`,{className:`flex bg-bambu-dark-tertiary rounded-md p-0.5 ml-1`,children:[(0,Y.jsxs)(`button`,{onClick:()=>m(`list`),className:`flex items-center gap-1.5 px-2 py-0.5 text-xs font-medium rounded transition-colors ${p===`list`?`bg-bambu-dark-secondary text-white shadow`:`text-bambu-gray hover:text-white`}`,children:[(0,Y.jsx)(oe,{className:`w-3 h-3`}),u(`forecast.listView`)]}),(0,Y.jsxs)(`button`,{onClick:()=>m(`logistics`),className:`flex items-center gap-1.5 px-2 py-0.5 text-xs font-medium rounded transition-colors ${p===`logistics`?`bg-bambu-dark-secondary text-white shadow`:`text-bambu-gray hover:text-white`}`,children:[(0,Y.jsx)(jt,{className:`w-3 h-3`}),u(`forecast.logisticsView`),v.length>0&&(0,Y.jsx)(`span`,{className:`w-3.5 h-3.5 rounded-full bg-red-500 text-white text-[9px] font-bold flex items-center justify-center`,children:v.length})]})]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.length>0&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`button`,{onClick:y,className:`flex items-center gap-1.5 text-xs text-bambu-gray hover:text-white transition-colors px-2 py-1 rounded border border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary`,children:[(0,Y.jsx)(Qe,{className:`w-3 h-3`}),u(`forecast.downloadCsv`)]}),i&&(0,Y.jsx)(`button`,{onClick:s,className:`text-xs text-red-700 dark:text-red-400 hover:text-red-800 dark:hover:text-red-300 transition-colors px-2 py-1 rounded border border-red-200 dark:border-red-500/20 hover:bg-red-50 dark:hover:bg-red-500/10`,children:u(`forecast.clearAll`)})]}),(0,Y.jsx)(`button`,{onClick:a,className:`p-1 text-bambu-gray hover:text-white transition-colors`,children:(0,Y.jsx)(he,{className:`w-4 h-4`})})]})]}),e.length===0?(0,Y.jsxs)(`div`,{className:`flex flex-col items-center py-8 text-bambu-gray`,children:[(0,Y.jsx)(oe,{className:`w-8 h-8 mb-2 opacity-30`}),(0,Y.jsx)(`p`,{className:`text-sm`,children:u(`forecast.shoppingListEmpty`)})]}):p===`list`?(0,Y.jsx)(`div`,{className:`overflow-x-auto`,children:(0,Y.jsxs)(`table`,{className:`w-full`,children:[(0,Y.jsx)(`thead`,{children:(0,Y.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary bg-bambu-dark-tertiary/20`,children:[(0,Y.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:u(`forecast.qty`)}),(0,Y.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:u(`forecast.material`)}),(0,Y.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:u(`forecast.weight`)}),(0,Y.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:u(`forecast.leadTime`)}),(0,Y.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:u(`forecast.expectedRestock`)}),(0,Y.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:u(`forecast.status`)}),(0,Y.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:u(`forecast.note`)}),(0,Y.jsx)(`th`,{className:`px-4 py-2 text-right text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:u(`forecast.actions`)})]})}),(0,Y.jsx)(`tbody`,{className:`divide-y divide-bambu-dark-tertiary`,children:e.map(e=>{let t=[e.brand,e.material,e.subtype,e.color_name].filter(Boolean).join(` `),r=v.some(t=>t.item.id===e.id),a=g.get(X(e.material,e.subtype,e.brand,e.color_name))??null,s=a&&a.totalSpools>0?a.totalLabelG/a.totalSpools:1e3,c=Math.round(e.quantity_spools*s),l=a?.effectiveLeadTimeDays??n??0,d=l>0?Z(new Date,l):null,f=e.status===`purchased`||e.status===`received`,p=e.status===`received`,m=h.isPending;return(0,Y.jsxs)(`tr`,{className:`hover:bg-bambu-dark-tertiary/30 transition-colors ${r&&!f?`bg-red-500/5`:``}`,children:[(0,Y.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,Y.jsxs)(`span`,{className:`text-sm font-semibold text-bambu-green`,children:[e.quantity_spools,`×`]})}),(0,Y.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:t}),r&&!f&&(0,Y.jsx)(B,{className:`w-3.5 h-3.5 text-red-600 dark:text-red-400 flex-shrink-0`,"aria-label":u(`forecast.stockBreakBefore`)})]})}),(0,Y.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:c>=1e3?`${(c/1e3).toFixed(1)}kg`:`${c}g`})}),(0,Y.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:l>0?`${l}d`:`—`})}),(0,Y.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:d?zt(d):`—`})}),(0,Y.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,Y.jsx)(`span`,{className:`inline-flex items-center px-2 py-0.5 rounded text-xs font-medium ${p?`bg-bambu-green/20 text-bambu-green`:f?`bg-blue-100 dark:bg-blue-400/20 text-blue-700 dark:text-blue-400`:`bg-bambu-dark-tertiary text-bambu-gray`}`,children:u(p?`forecast.received`:f?`forecast.purchased`:`forecast.pending`)})}),(0,Y.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:e.note||`—`})}),(0,Y.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,Y.jsx)(`div`,{className:`flex items-center justify-end gap-1`,children:i&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`button`,{onClick:()=>h.mutate({id:e.id,status:f?`pending`:`purchased`}),disabled:m||p,title:u(f?`forecast.resetToPending`:`forecast.markPurchased`),className:`p-1.5 rounded transition-colors disabled:opacity-30 ${f?`text-blue-600 dark:text-blue-400 hover:text-blue-700 dark:hover:text-blue-300`:`text-blue-600/50 dark:text-blue-400/50 hover:text-blue-600 dark:hover:text-blue-400`}`,children:f?(0,Y.jsx)(Se,{className:`w-4 h-4`}):(0,Y.jsx)(Mt,{className:`w-4 h-4`})}),(0,Y.jsx)(`button`,{onClick:()=>h.mutate({id:e.id,status:`received`,item:e,avgSpoolG:s}),disabled:m||!f||p,title:u(`forecast.markReceived`),className:`p-1.5 rounded transition-colors text-bambu-green/50 hover:text-bambu-green disabled:opacity-30`,children:(0,Y.jsx)(Pt,{className:`w-4 h-4`})}),(0,Y.jsx)(`button`,{onClick:()=>o(e.id),className:`p-1 text-bambu-gray hover:text-red-600 dark:hover:text-red-400 transition-colors`,title:u(`forecast.remove`),children:(0,Y.jsx)(be,{className:`w-3.5 h-3.5`})})]})})})]},e.id)})})]})}):(0,Y.jsx)(`div`,{className:`divide-y divide-bambu-dark-tertiary`,children:_.filter(({item:e})=>e.status!==`received`).map(({item:e,forecast:t})=>(0,Y.jsx)(tn,{item:e,forecast:t,globalLeadTime:n,canWrite:i,onRemove:()=>o(e.id)},e.id))})]})}function tn({item:e,forecast:t,globalLeadTime:n,canWrite:r,onRemove:i}){let{t:a}=c(),o=[e.brand,e.material,e.subtype,e.color_name].filter(Boolean).join(` `),s=(0,J.useMemo)(()=>{if(!t||t.dailyRateG===null||t.dailyRateG<=0)return null;let n=t.dailyRateG,r=t.effectiveLeadTimeDays,i=t.totalSpools>0?t.totalLabelG/t.totalSpools:1e3,a=e.quantity_spools*i,o=Math.max(0,t.totalRemainingG-n*r),s=o+a,c=Math.ceil(s/n),l=Math.min(r+c+5,365),u=[];for(let e=0;e<=l;e++){let i=Bt(Z(new Date,e));if(e===r)u.push({day:e,label:i,stock:Math.round(o),rop:Math.round(t.reorderPointG),safetyStock:Math.round(t.safetyStockG)}),u.push({day:e,label:i,stock:Math.round(s),rop:Math.round(t.reorderPointG),safetyStock:Math.round(t.safetyStockG),arrival:!0});else{let a=e{if(!t||t.dailyRateG===null||t.dailyRateG<=0)return null;let e=Math.floor(t.totalRemainingG/t.dailyRateG);return ee>=1e3?`${(e/1e3).toFixed(1)}kg`:`${e}g`,width:44}),(0,Y.jsx)(ce,{contentStyle:{background:`#1a1a2e`,border:`1px solid #374151`,borderRadius:8,fontSize:11},labelStyle:{color:`#9CA3AF`},formatter:(e,t)=>typeof e==`number`?t===`stock`?`${e}g — ${a(`forecast.stock`)}`:t===`rop`?`${e}g — ${a(`forecast.reorderPoint`)}`:t===`safetyStock`?`${e}g — ${a(`forecast.safetyMarginLabel`)}`:`${e}`:``}),(0,Y.jsx)(at,{type:`linear`,dataKey:`stock`,stroke:`#1DB954`,strokeWidth:2,fill:`url(#cart-post-${e.id})`,dot:!1,activeDot:{r:3}}),t.reorderPointG>0&&(0,Y.jsx)(C,{y:t.reorderPointG,stroke:`#F59E0B`,strokeDasharray:`5 3`,strokeOpacity:.8,label:{value:`ROP`,position:`insideTopRight`,fill:`#F59E0B`,fontSize:9}}),t.safetyStockG>0&&(0,Y.jsx)(C,{y:t.safetyStockG,stroke:`#6B7280`,strokeDasharray:`3 3`,strokeOpacity:.6,label:{value:`SS`,position:`insideTopRight`,fill:`#6B7280`,fontSize:9}}),(0,Y.jsx)(C,{x:Bt(Z(new Date,s.lt)),stroke:`#3B82F6`,strokeWidth:1.5,strokeDasharray:`4 3`,strokeOpacity:.9,label:{value:`+${s.arrivalG>=1e3?`${(s.arrivalG/1e3).toFixed(1)}kg`:`${Math.round(s.arrivalG)}g`} arrives (d${s.lt})`,position:`insideTopLeft`,fill:`#3B82F6`,fontSize:9}}),l!==null&&(0,Y.jsx)(C,{x:Bt(Z(new Date,l)),stroke:`#EF4444`,strokeWidth:1.5,strokeOpacity:.9,label:{value:`OUT`,position:`insideTopLeft`,fill:`#EF4444`,fontSize:9}})]})}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 mt-2 text-[10px] text-bambu-gray`,children:[(0,Y.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,Y.jsx)(`span`,{className:`inline-block w-4 border-t-2 border-yellow-400 border-dashed`}),` `,a(`forecast.ropLabel`)]}),(0,Y.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,Y.jsx)(`span`,{className:`inline-block w-4 border-t border-bambu-gray border-dashed`}),` `,a(`forecast.safetyStockLegend`)]}),(0,Y.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,Y.jsx)(`span`,{className:`inline-block w-4 border-t-2 border-blue-400 border-dashed`}),` `,a(`forecast.stockArrivalLegend`)]}),u&&(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 text-red-700 dark:text-red-400`,children:[(0,Y.jsx)(`span`,{className:`inline-block w-4 border-t-2 border-red-400`}),` `,a(`forecast.stockoutLegend`)]})]})]}):null]})}function nn({forecast:e,onClose:t,onAdd:n}){let{t:r}=c(),i=[e.group.brand,e.group.material,e.group.subtype,e.group.colorName].filter(Boolean).join(` `),[a,o]=(0,J.useState)(`qty`),[s,l]=(0,J.useState)(`1`),[u,d]=(0,J.useState)(`30`),[f,p]=(0,J.useState)(``),m=(0,J.useMemo)(()=>{if(!e.dailyRateG||e.dailyRateG<=0)return null;let t=e.dailyRateG*Number(u),n=e.group.spools.length>0?e.group.spools.reduce((e,t)=>e+t.label_weight,0)/e.group.spools.length:1e3;return Math.ceil(t/n)},[e,u]),h=a===`qty`?parseInt(s,10)||1:m??1;function g(t){t.preventDefault(),n({material:e.group.material,subtype:e.group.subtype,brand:e.group.brand,color_name:e.group.colorName,quantity_spools:h,note:f||null})}return(0,Y.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm p-4`,children:(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-2xl border border-bambu-dark-tertiary w-full max-w-sm shadow-2xl`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between px-5 pt-5 pb-4 border-b border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(tt,{className:`w-5 h-5 text-bambu-green`}),(0,Y.jsx)(`h2`,{className:`text-base font-semibold text-white`,children:r(`forecast.addToCartTitle`)})]}),(0,Y.jsx)(`button`,{onClick:t,className:`p-1 text-bambu-gray hover:text-white transition-colors`,children:(0,Y.jsx)(he,{className:`w-5 h-5`})})]}),(0,Y.jsxs)(`form`,{onSubmit:g,className:`p-5 space-y-4`,children:[(0,Y.jsx)(`div`,{className:`text-sm text-bambu-gray`,children:i}),(0,Y.jsxs)(`div`,{className:`flex bg-bambu-dark-tertiary rounded-lg p-0.5`,children:[(0,Y.jsx)(`button`,{type:`button`,onClick:()=>o(`qty`),className:`flex-1 py-1.5 text-xs font-medium rounded-md transition-colors ${a===`qty`?`bg-bambu-dark-secondary text-white shadow`:`text-bambu-gray hover:text-white`}`,children:r(`forecast.byQuantity`)}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>o(`duration`),className:`flex-1 py-1.5 text-xs font-medium rounded-md transition-colors ${a===`duration`?`bg-bambu-dark-secondary text-white shadow`:`text-bambu-gray hover:text-white`}`,children:r(`forecast.byDuration`)})]}),a===`qty`?(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(`label`,{className:`text-xs text-bambu-gray`,children:r(`forecast.numberOfSpools`)}),(0,Y.jsx)(`input`,{type:`number`,min:1,max:99,value:s,onChange:e=>l(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`,autoFocus:!0})]}):(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(`label`,{className:`text-xs text-bambu-gray`,children:r(`forecast.lastHowManyDays`)}),(0,Y.jsx)(`input`,{type:`number`,min:1,max:365,value:u,onChange:e=>d(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`,autoFocus:!0})]}),e.dailyRateG===null?(0,Y.jsx)(`div`,{className:`text-xs text-yellow-700 dark:text-yellow-400 px-1`,children:r(`forecast.noUsageQty`)}):(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2 bg-bambu-dark-tertiary/50 rounded-lg`,children:[(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:`≈`}),(0,Y.jsx)(`span`,{className:`text-sm font-semibold text-bambu-green`,children:r(`forecast.spoolCount`,{count:m??0})}),(0,Y.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[`at `,e.dailyRateG.toFixed(1),`g/day`]})]})]}),(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(`label`,{className:`text-xs text-bambu-gray`,children:r(`forecast.noteOptional`)}),(0,Y.jsx)(`input`,{type:`text`,maxLength:200,value:f,onChange:e=>p(e.target.value),placeholder:r(`forecast.notePlaceholder`),className:`w-full px-3 py-2 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/40 focus:outline-none focus:border-bambu-green`})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-3 pt-1`,children:[(0,Y.jsx)(`button`,{type:`submit`,className:`flex-1 py-2 bg-bambu-green text-white text-sm font-medium rounded-lg hover:bg-bambu-green/80 transition-colors`,children:r(`forecast.addNSpools`,{count:h})}),(0,Y.jsx)(`button`,{type:`button`,onClick:t,className:`px-4 py-2 text-sm text-bambu-gray hover:text-white border border-bambu-dark-tertiary rounded-lg transition-colors`,children:r(`forecast.cancel`)})]})]})]})})}function rn({links:e,onChange:t,currencySymbol:n}){let{t:i}=c(),{showToast:a}=te(),s=l(),d=(0,J.useRef)(null),[f,p]=(0,J.useState)(!1),[m,h]=(0,J.useState)(``),[g,_]=(0,J.useState)(!1),{data:v=[],isLoading:y,isError:b}=u({queryKey:Xe,queryFn:r.getSuppliers});(0,J.useEffect)(()=>{if(!f)return;let e=e=>{d.current&&!d.current.contains(e.target)&&(p(!1),h(``))};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[f]);let x=(0,J.useMemo)(()=>new Set(e.map(e=>e.supplier_id)),[e]),S=(0,J.useMemo)(()=>v.filter(e=>!x.has(e.id)).filter(e=>e.name.toLowerCase().includes(m.trim().toLowerCase())),[v,x,m]),C=v.some(e=>e.name.toLowerCase()===m.trim().toLowerCase()),w=n=>{t([...e,{supplier_id:n.id,supplier_name:n.name,supplier_article_number:``,quoted_price_per_kg:null,is_purchase_source:!1}]),p(!1),h(``)},E=async()=>{let e=m.trim();if(e){_(!0);try{let t=await r.createSupplier({name:e});await He(s),w(t)}catch(e){console.error(`SupplierSection.createAndAdd failed:`,e),a(i(e instanceof o&&e.status===409?`inventory.suppliers.duplicateName`:`inventory.suppliers.createFailed`),`error`)}finally{_(!1)}}},D=(n,r)=>{t(e.map(e=>e.supplier_id===n?{...e,...r}:r.is_purchase_source?{...e,is_purchase_source:!1}:e))},O=n=>{t(e.filter(e=>e.supplier_id!==n))};return(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:i(`inventory.suppliers.label`)}),e.length>0&&(0,Y.jsx)(`div`,{className:`space-y-2 mb-2`,children:e.map(e=>(0,Y.jsxs)(`div`,{className:`p-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs bg-bambu-green/10 text-bambu-green`,children:[(0,Y.jsx)(Ft,{className:`w-3 h-3`}),e.supplier_name]}),(0,Y.jsxs)(`label`,{className:`ml-auto flex items-center gap-1.5 text-xs text-bambu-gray cursor-pointer`,title:i(`inventory.suppliers.purchaseSourceHelp`),children:[(0,Y.jsx)(`input`,{type:`checkbox`,className:`w-3.5 h-3.5 accent-bambu-green`,checked:e.is_purchase_source,onChange:t=>D(e.supplier_id,{is_purchase_source:t.target.checked})}),i(`inventory.suppliers.purchaseSource`)]}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>O(e.supplier_id),className:`p-1 rounded text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary`,"aria-label":i(`common.remove`),children:(0,Y.jsx)(he,{className:`w-3.5 h-3.5`})})]}),(0,Y.jsxs)(`div`,{className:`flex gap-2 mt-2`,children:[(0,Y.jsx)(`input`,{type:`text`,className:`flex-1 min-w-0 px-2 py-1.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-xs placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`,placeholder:i(`inventory.suppliers.articleNumberPlaceholder`),value:e.supplier_article_number,maxLength:100,onChange:t=>D(e.supplier_id,{supplier_article_number:t.target.value})}),(0,Y.jsxs)(`div`,{className:`relative w-28`,children:[(0,Y.jsx)(`span`,{className:`absolute left-2 top-1/2 -translate-y-1/2 text-xs text-bambu-gray pointer-events-none`,children:n}),(0,Y.jsx)(`input`,{type:`number`,className:`w-full pl-6 pr-2 py-1.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-xs text-right placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`,placeholder:i(`inventory.suppliers.pricePlaceholder`),title:i(`inventory.suppliers.priceHelp`),min:0,step:.01,value:e.quoted_price_per_kg??``,onChange:t=>D(e.supplier_id,{quoted_price_per_kg:t.target.value===``?null:parseFloat(t.target.value)})})]})]})]},e.supplier_id))}),(0,Y.jsxs)(`div`,{className:`relative`,ref:d,children:[(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>p(e=>!e),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-sm text-bambu-gray hover:text-white flex items-center justify-between transition-colors focus:outline-none focus:border-bambu-green`,children:[(0,Y.jsx)(`span`,{children:i(`inventory.suppliers.addSupplier`)}),(0,Y.jsx)(T,{className:`w-4 h-4 transition-transform ${f?`rotate-180`:``}`})]}),f&&(0,Y.jsxs)(`div`,{className:`absolute z-50 w-full mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg`,children:[(0,Y.jsx)(`div`,{className:`p-2 border-b border-bambu-dark-tertiary`,children:(0,Y.jsx)(`input`,{type:`text`,autoFocus:!0,className:`w-full px-2 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`,placeholder:i(`inventory.suppliers.searchPlaceholder`),value:m,onChange:e=>h(e.target.value)})}),(0,Y.jsx)(`div`,{className:`max-h-48 overflow-y-auto py-1`,children:y?(0,Y.jsxs)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray flex items-center gap-2`,children:[(0,Y.jsx)(F,{className:`w-4 h-4 animate-spin`}),i(`common.loading`)]}):b?(0,Y.jsxs)(`div`,{className:`px-3 py-2 text-sm text-red-400 flex items-center gap-2`,children:[(0,Y.jsx)(B,{className:`w-4 h-4`}),i(`inventory.suppliers.loadFailed`)]}):(0,Y.jsxs)(Y.Fragment,{children:[S.map(e=>(0,Y.jsx)(`button`,{type:`button`,onClick:()=>w(e),className:`w-full px-3 py-2 text-left text-sm text-white hover:bg-bambu-dark-tertiary`,children:e.name},e.id)),S.length===0&&!m.trim()&&(0,Y.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:i(`inventory.suppliers.noneLeft`)}),m.trim()&&!C&&(0,Y.jsxs)(`button`,{type:`button`,onClick:E,disabled:g,className:`w-full px-3 py-2 text-left text-sm text-bambu-green hover:bg-bambu-dark-tertiary flex items-center gap-1.5`,children:[g?(0,Y.jsx)(F,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(Pe,{className:`w-4 h-4`}),i(`inventory.suppliers.createNew`,{name:m.trim()})]})]})})]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`inventory.suppliers.help`)})]})}function an({filaments:e,isLoading:t,selectedId:n,onSelect:r}){let{t:i}=c(),[a,o]=(0,J.useState)(!1),[s,l]=(0,J.useState)(``),u=(0,J.useRef)(null),d=(0,J.useRef)(null),f=(0,J.useMemo)(()=>e.find(e=>e.id===n)??null,[e,n]);(0,J.useEffect)(()=>{let e=e=>{u.current&&!u.current.contains(e.target)&&(o(!1),l(``))};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[]);let p=(0,J.useMemo)(()=>{let t=s.toLowerCase().trim();return t?e.filter(e=>e.name.toLowerCase().includes(t)||(e.material?.toLowerCase().includes(t)??!1)||(e.vendor?.name.toLowerCase().includes(t)??!1)||(e.color_name?.toLowerCase().includes(t)??!1)):e},[e,s]);(0,J.useEffect)(()=>{a&&d.current?.focus()},[a]);let m=()=>{o(!0),l(``)},h=e=>{r(e),o(!1),l(``)};return(0,Y.jsxs)(`div`,{ref:u,className:`relative`,children:[(0,Y.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:i(`inventory.pickFromSpoolmanCatalog`)}),(0,Y.jsxs)(`button`,{type:`button`,onClick:m,className:`w-full flex items-center gap-2 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-left focus:outline-none focus:border-bambu-green hover:border-bambu-gray transition-colors`,children:[t?(0,Y.jsx)(F,{className:`w-4 h-4 text-bambu-gray animate-spin shrink-0`}):f?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`span`,{className:`w-4 h-4 rounded-full shrink-0 border border-white/20`,style:Ke(f.color_hex),"aria-label":i(`inventory.spoolmanFilamentColorSwatch`)}),(0,Y.jsxs)(`span`,{className:`text-white text-sm truncate flex-1`,children:[f.vendor?.name?`${f.vendor.name} — `:``,f.name]})]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(oe,{className:`w-4 h-4 text-bambu-gray shrink-0`}),(0,Y.jsx)(`span`,{className:`text-bambu-gray text-sm flex-1`,children:i(`inventory.spoolmanFilamentCatalog`)})]}),(0,Y.jsx)(T,{className:`w-4 h-4 text-bambu-gray shrink-0 ml-auto`})]}),a&&(0,Y.jsxs)(`div`,{className:`absolute z-50 w-full mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl`,children:[(0,Y.jsx)(`div`,{className:`p-2 border-b border-bambu-dark-tertiary`,children:(0,Y.jsx)(`input`,{ref:d,type:`text`,value:s,onChange:e=>l(e.target.value),placeholder:i(`inventory.pickFromSpoolmanCatalog`),className:`w-full px-2 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm placeholder-bambu-gray focus:outline-none focus:border-bambu-green`})}),(0,Y.jsx)(`ul`,{className:`max-h-56 overflow-y-auto py-1`,children:t?(0,Y.jsxs)(`li`,{className:`flex items-center justify-center gap-2 py-4 text-bambu-gray text-sm`,children:[(0,Y.jsx)(F,{className:`w-4 h-4 animate-spin`}),(0,Y.jsx)(`span`,{children:i(`common.loading`,`Loading…`)})]}):p.length===0?(0,Y.jsx)(`li`,{className:`py-4 text-center text-bambu-gray text-sm`,children:i(`inventory.noSpoolmanFilaments`)}):p.map(e=>(0,Y.jsx)(`li`,{children:(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>h(e),className:`w-full flex items-center gap-2 px-3 py-2 text-left hover:bg-bambu-dark-tertiary transition-colors ${e.id===n?`bg-bambu-dark-tertiary`:``}`,children:[(0,Y.jsx)(`span`,{className:`w-4 h-4 rounded-full shrink-0 border border-white/20`,style:Ke(e.color_hex),"aria-label":i(`inventory.spoolmanFilamentColorSwatch`)}),(0,Y.jsxs)(`span`,{className:`flex-1 min-w-0`,children:[(0,Y.jsxs)(`span`,{className:`block text-white text-sm truncate`,children:[e.vendor?.name?`${e.vendor.name} — `:``,e.name]}),(0,Y.jsxs)(`span`,{className:`block text-bambu-gray text-xs truncate`,children:[[e.material,e.color_name].filter(Boolean).join(` · `),e.weight?` · ${e.weight}g`:``]})]})]})},e.id))})]})]})}function on(e){let t=(e??``).trim().toUpperCase().slice(0,2);return t===`HH`||t===`HS`?t:null}function sn(e){return e?e===`HH`?`HF`:`S`:null}function cn(e,t){let n=e.nozzles??[];return on(n[(e.printer.nozzle_count??1)>1&&t>0?t:0]?.nozzle_type)??on(n[0]?.nozzle_type)}function ln(e){let t=new Set;for(let n of e.nozzles??[]){let e=(n?.nozzle_diameter??``).trim();e&&parseFloat(e)>0&&t.add(e)}for(let n of e.calibrations){let e=(n.nozzle_diameter??``).trim();e&&parseFloat(e)>0&&t.add(e)}return Array.from(t).sort((e,t)=>parseFloat(e)-parseFloat(t))}function un(e,t){return(e.printer.nozzle_count??1)>1?[{extruder:1,label:t.left},{extruder:0,label:t.right}]:[{extruder:0,label:t.single}]}function dn({formData:e,printersWithCalibrations:t,filamentOptions:n,modelPresets:r,setModelPresets:i,selectedProfiles:a,setSelectedProfiles:o,selectedGroupId:s,setSelectedGroupId:l,printerModels:u,isLoading:d=!1}){let{t:f}=c(),p=(0,J.useMemo)(()=>{let e=new Map,n=[];for(let r of t){let t=(r.printer.model||``).trim();if(!t){n.push(r);continue}let i=e.get(t);i?i.push(r):e.set(t,[r])}return[...Array.from(e.entries()).map(([e,t])=>({id:`m:${e}`,model:e,printers:t,diameters:Array.from(new Set([...mt,...t.flatMap(ln)])).sort((e,t)=>parseFloat(e)-parseFloat(t))})).sort((e,t)=>e.model.localeCompare(t.model)),...n.map(e=>({id:`p:${e.printer.id}`,model:``,printers:[e],diameters:Array.from(new Set([...mt,...ln(e)])).sort((e,t)=>parseFloat(e)-parseFloat(t))}))]},[t]),m=p.find(e=>e.id===s)??p[0],h=(0,J.useMemo)(()=>{let e=new Map;return(t,r)=>{if(!t)return n;let i=e.get(t);if(i||(i=n.filter(e=>{let n=rt(e.name,u??{});return!n||nt(n,t)}),e.set(t,i)),r&&!i.some(e=>e.code===r)){let e=n.find(e=>e.code===r);if(e)return[e,...i]}return i}},[n,u]),g=[e.brand,e.material,e.subtype].map(e=>e.trim()).filter(Boolean).join(` `),_=/^[0-9A-Fa-f]{6,8}$/.test(e.rgba)?`#${e.rgba.slice(0,6)}`:`var(--bambu-gray, #808080)`,v=e=>un(e,{left:f(`inventory.leftNozzle`),right:f(`inventory.rightNozzle`),single:f(`inventory.nozzle`)}),y=t=>t.printer.connected?t.calibrations.filter(t=>Ct(t,e)):[],b=e=>{let t=0;for(let n of e.printers){let r=y(n);for(let i of v(n))for(let o of e.diameters)r.some(e=>(e.extruder_id??0)===i.extruder&&((e.nozzle_diameter??``).trim()||`0.4`)===o)&&(a.get(K(n.printer.id,i.extruder,o))||t++)}return t},x=(e,t,n)=>{i(r=>{let i=new Map(r),a=gt(e,t);return n?i.set(a,{code:n.code,name:n.name}):i.delete(a),i})},S=(e,t,n,r)=>{o(i=>{let a=new Map(i),o=K(e,t,n);return r?a.set(o,r):a.delete(o),a})},C=()=>{let t=n.find(t=>t.code===e.slicer_filament);if(!t)return;let r=t.name.split(`@`)[0].trim().toLowerCase();r&&i(e=>{let t=new Map(e);for(let e of p){if(!e.model)continue;let n=h(e.model,void 0).filter(e=>e.name.toLowerCase().startsWith(r)&&rt(e.name,u??{})!==null);if(n.length!==0)for(let r of e.diameters){let i=n.find(e=>RegExp(`\\b${r.replace(`.`,`\\.`)}\\s*nozzle\\b`,`i`).test(e.name)),a=n.find(e=>!/\b[\d.]+\s*nozzle\b/i.test(e.name)),o=i??a;o&&t.set(gt(e.model,r),{code:o.code,name:o.name})}}return t})};if(t.length===0)return(0,Y.jsx)(`div`,{className:`p-6 bg-bambu-dark rounded-lg text-center`,children:(0,Y.jsxs)(`p`,{className:`text-bambu-gray flex items-center justify-center gap-2`,children:[d&&(0,Y.jsx)(F,{className:`w-4 h-4 animate-spin`}),f(d?`common.loading`:`inventory.noPrintersConfigured`)]})});let T=(e,t,n)=>{let i=gt(e,t),a=r.get(i),o=h(e,a?.code);return(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,Y.jsx)(ct,{ariaLabel:`${e} ${t}mm ${f(`inventory.filamentPreset`)}`,value:a?.code??``,options:o,inheritLabel:n,disabled:!e,onChange:n=>x(e,t,n)})}),(0,Y.jsx)(`span`,{className:`text-[10px] font-semibold uppercase tracking-wide px-2 py-1 rounded-full shrink-0 ${a?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark-tertiary text-bambu-gray`}`,children:f(a?`inventory.presetOverride`:`inventory.presetInherited`)})]})};return(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(g||e.color_name)&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-2.5 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg`,children:[(0,Y.jsx)(`span`,{className:`w-5 h-5 rounded-full border border-white/15 shrink-0`,style:{background:_},"aria-hidden":`true`}),g&&(0,Y.jsx)(`span`,{className:`text-sm text-white truncate`,children:g}),e.color_name&&(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray truncate`,children:e.color_name})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col md:flex-row gap-4`,children:[(0,Y.jsx)(`div`,{role:`tablist`,"aria-label":f(`inventory.printersTab`),"aria-orientation":`vertical`,className:`md:w-52 md:shrink-0 md:self-start md:sticky md:top-0 flex md:flex-col gap-1.5 overflow-x-auto md:overflow-x-visible`,children:p.map(e=>{let t=e===m,n=b(e);return(0,Y.jsxs)(`button`,{type:`button`,role:`tab`,onClick:()=>l(e.id),"aria-selected":t,className:`flex items-center gap-2 px-3 py-2 rounded-lg border text-left transition-colors shrink-0 md:shrink ${t?`bg-bambu-green/10 border-bambu-green/40 text-white`:`bg-transparent border-transparent text-bambu-gray hover:bg-bambu-dark hover:text-white`}`,children:[(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsx)(`div`,{className:`text-sm font-semibold truncate`,children:e.model||f(`inventory.unknownModel`)}),(0,Y.jsx)(`div`,{className:`text-[11px] text-bambu-gray`,children:e.printers.length===1?f(`inventory.onePrinter`):f(`inventory.nPrinters`,{n:e.printers.length})})]}),n>0?(0,Y.jsx)(`span`,{className:`text-[10px] font-mono px-1.5 py-0.5 rounded-full bg-bambu-dark-tertiary text-bambu-gray shrink-0`,children:n}):(0,Y.jsx)(w,{className:`w-3.5 h-3.5 text-bambu-green shrink-0`})]},e.id)})}),(0,Y.jsx)(`div`,{className:`flex-1 min-w-0`,children:m&&(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,Y.jsxs)(`div`,{className:`min-w-0`,children:[(0,Y.jsx)(`h4`,{className:`text-base font-semibold text-white truncate`,children:m.model||f(`inventory.unknownModel`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:m.printers.map(e=>e.printer.name).join(`, `)})]}),e.slicer_filament&&(0,Y.jsxs)(`button`,{type:`button`,onClick:C,title:f(`inventory.autoMatchPresetsHint`),className:`flex items-center gap-1.5 px-2 py-1 text-xs bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white hover:border-bambu-green transition-colors shrink-0`,children:[(0,Y.jsx)(z,{className:`w-3.5 h-3.5`}),f(`inventory.autoMatchPresets`)]})]}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(`p`,{className:`text-xs font-semibold text-bambu-gray uppercase tracking-wide`,children:f(`inventory.filamentPreset`)}),m.model?(0,Y.jsx)(`div`,{className:`space-y-2`,children:m.diameters.map(e=>(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Y.jsxs)(`span`,{className:`text-xs font-mono text-bambu-gray w-14 shrink-0`,children:[e,`mm`]}),(0,Y.jsx)(`div`,{className:`flex-1 min-w-0`,children:T(m.model,e,f(`inventory.presetUseSpoolDefault`))})]},e))}):(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray italic`,children:f(`inventory.presetNeedsModel`)})]}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(`p`,{className:`text-xs font-semibold text-bambu-gray uppercase tracking-wide`,children:f(`inventory.kProfilesPerPrinter`)}),e.material?m.printers.map(e=>{let t=y(e);return(0,Y.jsxs)(`div`,{className:`p-3 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,Y.jsx)(U,{className:`w-3.5 h-3.5 text-bambu-gray shrink-0`}),(0,Y.jsx)(`span`,{className:`text-sm font-semibold text-white truncate`,children:e.printer.name}),(0,Y.jsx)(`span`,{className:`text-[10px] font-semibold uppercase tracking-wide px-2 py-0.5 rounded-full shrink-0 ${e.printer.connected?`bg-green-500/20 text-green-500`:`bg-bambu-dark-tertiary text-bambu-gray`}`,children:e.printer.connected?f(`inventory.connected`):f(`inventory.offline`)})]}),e.printer.connected?t.length===0?(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray italic py-1`,children:f(`inventory.noKProfilesMatch`)}):(0,Y.jsxs)(`div`,{className:`grid gap-x-3 gap-y-1.5 items-center`,style:{gridTemplateColumns:`3.5rem repeat(${v(e).length}, minmax(0, 1fr))`},children:[(0,Y.jsx)(`span`,{}),v(e).map(e=>(0,Y.jsx)(`span`,{className:`text-[11px] font-semibold uppercase tracking-wide text-bambu-gray`,children:e.label},e.extruder)),m.diameters.map(n=>(0,Y.jsxs)(J.Fragment,{children:[(0,Y.jsxs)(`span`,{className:`text-xs font-mono text-bambu-gray`,children:[n,`mm`]}),v(e).map(r=>{let i=t.filter(e=>(e.extruder_id??0)===r.extruder&&((e.nozzle_diameter??``).trim()||`0.4`)===n),o=K(e.printer.id,r.extruder,n),s=a.get(o);if(i.length===0)return(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray/50 px-2 py-1.5`,title:f(`inventory.noKProfilesMatch`),children:`—`},o);let c=cn(e,r.extruder),l=on(s?.nozzle_id),u=!!(c&&l&&c!==l);return(0,Y.jsxs)(`select`,{title:u?f(`inventory.kProfileFlowMismatch`,{profile:sn(l),fitted:sn(c)}):void 0,"aria-label":`${e.printer.name} ${r.label} ${n}mm`,value:s?String(s.cali_idx):``,onChange:t=>{let a=i.find(e=>String(e.cali_idx)===t.target.value)??null;S(e.printer.id,r.extruder,n,a)},className:`min-w-0 px-2 py-1.5 bg-bambu-dark-secondary border rounded-lg text-sm text-white focus:outline-none focus:border-bambu-green ${u?`border-amber-500/60`:`border-bambu-dark-tertiary`}`,children:[(0,Y.jsx)(`option`,{value:``,children:f(`inventory.kProfileNotSet`)}),i.map(e=>{let t=sn(on(e.nozzle_id));return(0,Y.jsx)(`option`,{value:e.cali_idx,children:`${t?`[${t}] `:``}${e.name||e.filament_id} K=${e.k_value.toFixed(3)}`},e.cali_idx)})]},o)})]},n))]}):(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray italic py-1`,children:f(`inventory.printerOffline`)})]},e.printer.id)}):(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray italic`,children:f(`inventory.selectMaterialFirst`)})]})]})})]})]})}function fn(e){let t=H(e);return t?t.toLocaleDateString(`en-GB`,{day:`2-digit`,month:`2-digit`,year:`2-digit`})+` `+t.toLocaleTimeString(`en-GB`,{hour:`2-digit`,minute:`2-digit`}):``}var pn={completed:`text-bambu-green`,failed:`text-red-700 dark:text-red-400`,aborted:`text-yellow-700 dark:text-yellow-400`};function mn({spoolId:e}){let{t}=c(),n=l(),{showToast:i}=te(),{data:a,isLoading:o}=u({queryKey:[`spool-usage`,e],queryFn:()=>r.getSpoolUsageHistory(e)}),s=d({mutationFn:()=>r.clearSpoolUsageHistory(e),onSuccess:()=>{n.invalidateQueries({queryKey:[`spool-usage`,e]}),i(t(`inventory.historyCleared`),`success`)}});return o?(0,Y.jsx)(`div`,{className:`flex justify-center py-4`,children:(0,Y.jsx)(F,{className:`w-5 h-5 animate-spin text-bambu-green`})}):!a||a.length===0?(0,Y.jsxs)(`div`,{className:`text-center py-4 text-bambu-gray text-sm`,children:[(0,Y.jsx)(Oe,{className:`w-5 h-5 mx-auto mb-2 opacity-50`}),t(`inventory.noUsageHistory`)]}):(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`h4`,{className:`text-sm font-medium text-white`,children:t(`inventory.usageHistory`)}),(0,Y.jsxs)(V,{variant:`ghost`,size:`sm`,onClick:()=>s.mutate(),disabled:s.isPending,className:`text-xs text-bambu-gray hover:text-red-700 dark:hover:text-red-400`,children:[(0,Y.jsx)(be,{className:`w-3 h-3 mr-1`}),t(`inventory.clearHistory`)]})]}),(0,Y.jsx)(`div`,{className:`max-h-48 overflow-y-auto space-y-1`,children:a.map(e=>(0,Y.jsxs)(`div`,{className:`flex items-center justify-between p-2 rounded bg-bambu-dark/50 text-xs`,children:[(0,Y.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Y.jsx)(`span`,{className:`text-bambu-gray`,children:fn(e.created_at)}),e.print_name&&(0,Y.jsx)(`span`,{className:`text-white ml-2 truncate`,title:e.print_name,children:e.print_name})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0 ml-2`,children:[(0,Y.jsxs)(`span`,{className:`text-white font-medium`,children:[e.weight_used.toFixed(1),`g`]}),(0,Y.jsxs)(`span`,{className:`text-bambu-gray`,children:[`(`,e.percent_used,`%)`]}),(0,Y.jsx)(`span`,{className:pn[e.status]||`text-bambu-gray`,children:e.status})]})]},e.id))})]})}var hn={tag_uid:null,tray_uuid:null,tag_type:null,data_origin:null};function gn({isOpen:e,onClose:t,spool:n,mode:i,printersWithCalibrations:a=[],currencySymbol:s,onSpoolsCreated:f,spoolmanMode:p=!1,spoolsQueryKey:m=[`inventory-spools`]}){let{t:h}=c(),g=l(),{showToast:_}=te(),v=()=>Ie(g,m),y=i===`edit`,b=i===`copy`,[x,S]=(0,J.useState)(ut),[C,w]=(0,J.useState)({}),[T,E]=(0,J.useState)(`filament`),[D,O]=(0,J.useState)(!1),[ee,k]=(0,J.useState)(!1),[A,j]=(0,J.useState)(!1),[M,N]=(0,J.useState)(!1),[ne,I]=(0,J.useState)([]),[L,re]=(0,J.useState)(!1),[R,ie]=(0,J.useState)(!1),[ae,oe]=(0,J.useState)(1),[se,z]=(0,J.useState)(!1);(0,J.useEffect)(()=>{z(!1)},[e,n?.id]);let[ce,le]=(0,J.useState)(!1),[ue,de]=(0,J.useState)(!1),[fe,pe]=(0,J.useState)([]),[B,ge]=(0,J.useState)(new Set),[ve,ye]=(0,J.useState)(``),[be,xe]=(0,J.useState)([]),[Se,Ce]=(0,J.useState)([]),[U,we]=(0,J.useState)([]),[Te,Ee]=(0,J.useState)([]),[De,Oe]=(0,J.useState)([]),[Ae,je]=(0,J.useState)([]),[Ne,Pe]=(0,J.useState)([]),[Fe,Le]=(0,J.useState)(!1),[ze,Ve]=(0,J.useState)(new Map),[He,Ue]=(0,J.useState)(new Map),[We,Ge]=(0,J.useState)(``),Ke=a.length>0?a:Ne,qe=ze.size+He.size,{data:Je=[],isLoading:Xe,error:W}=u({queryKey:[`spoolman-inventory-filaments`],queryFn:()=>r.getSpoolmanInventoryFilaments(),enabled:p&&e,staleTime:6e4,retry:!1});(0,J.useEffect)(()=>{je(Tt())},[]),(0,J.useEffect)(()=>{let t=!1;return e&&((async()=>{de(!0);try{let[e,n]=await Promise.allSettled([(async()=>(await r.getCloudStatus()).is_authenticated?{connected:!0,presets:await r.getFilamentPresets()}:{connected:!1,presets:[]})(),(async()=>(await r.orcaCloudStatus()).connected?{connected:!0,presets:(await r.orcaCloudListProfiles()).filament}:{connected:!1,presets:[]})()]);if(t)return;let i=e.status===`fulfilled`&&e.value.connected,a=n.status===`fulfilled`&&n.value.connected,o=e.status===`fulfilled`?e.value.presets:[],s=n.status===`fulfilled`?n.value.presets:[];le(i||a),pe([...o,...s]),ge(new Set(s.map(e=>e.setting_id)))}catch(e){if(t)return;console.error(`Failed to fetch cloud presets:`,e),le(!1)}finally{t||de(!1)}})(),r.getSpoolCatalog().then(xe).catch(console.error),r.getColorCatalog().then(Oe).catch(console.error),r.getLocalPresets().then(e=>we(e.filament)).catch(console.error),r.getBuiltinFilaments().then(Ee).catch(console.error),r.getLocations().then(e=>Ce(e.map(e=>({id:e.id,name:e.name})))).catch(console.error),a.length===0&&(async()=>{Le(!0);try{let e=await r.getPrinters(),n=await Promise.all(e.map(e=>r.getPrinterStatus(e.id).catch(()=>null))),i=await Promise.all(e.map(async(e,t)=>{let r=n[t],i=r?.connected??!1,a=[];return i&&(a=await wt(e.id,r)),{printer:{...e,connected:i},calibrations:a,nozzles:r?.nozzles}}));t||Pe(i)}catch(e){console.error(`Failed to fetch printer calibrations:`,e)}finally{t||Le(!1)}})()),()=>{t=!0}},[e,a.length]);let Ze=(0,J.useMemo)(()=>Et(fe,new Set,U,Te,B),[fe,U,Te,B]),Qe=(0,J.useMemo)(()=>{let e=St(fe,U),t=De.map(e=>e.manufacturer?.trim()).filter(e=>!!e),n=new Set([...e,...t]);return Array.from(n).sort((e,t)=>e.localeCompare(t))},[fe,U,De]),$e=(0,J.useMemo)(()=>{let e=De.map(e=>e.material?.trim()).filter(e=>!!e),t=new Set([...Ot,...e]);return Array.from(t).sort((e,t)=>e.localeCompare(t))},[De]),et=(0,J.useMemo)(()=>{let e=[];for(let t of De){let n=t.manufacturer?.trim(),r=t.material?.trim();n&&r&&e.push({brand:n,material:r})}for(let t of fe){let n=Dt(t.name);n.brand&&n.material&&e.push({brand:n.brand,material:n.material})}for(let t of U){let n=Dt(t.name),r=t.filament_vendor?.trim()||n.brand,i=n.material;r&&i&&e.push({brand:r,material:i})}return e},[fe,De,U]),tt=(0,J.useMemo)(()=>{let e=new Map;for(let t of et){let n=t.brand.toLowerCase(),r=t.material.toLowerCase();e.has(n)||e.set(n,new Set),e.get(n).add(r)}return e},[et]),nt=(0,J.useMemo)(()=>{let e=new Map;for(let t of et){let n=t.brand.toLowerCase(),r=t.material.toLowerCase();e.has(r)||e.set(r,new Set),e.get(r).add(n)}return e},[et]),rt=(0,J.useMemo)(()=>xt(Qe,x.brand),[Qe,x.brand]),it=(0,J.useMemo)(()=>xt($e,x.material),[$e,x.material]),at=(0,J.useMemo)(()=>ht(rt,x.material,nt),[rt,x.material,nt]),ot=(0,J.useMemo)(()=>ht(it,x.brand,tt),[it,x.brand,tt]),ct=(0,J.useMemo)(()=>yt(x.slicer_filament,Ze),[x.slicer_filament,Ze]);(0,J.useEffect)(()=>{if(e){if(n){let e=n.rgba&&/^[0-9A-Fa-f]{8}$/.test(n.rgba)?n.rgba:`808080FF`;if(S({material:n.material||``,subtype:n.subtype||``,brand:n.brand||``,color_name:n.color_name_is_synthesized?``:n.color_name||``,rgba:e,extra_colors:n.extra_colors||``,effect_type:n.effect_type||``,label_weight:n.label_weight||1e3,core_weight:n.core_weight??250,core_weight_catalog_id:n.core_weight_catalog_id??null,weight_used:b?0:n.weight_used||0,slicer_filament:n.slicer_filament||``,note:n.note||``,cost_per_kg:n.cost_per_kg??null,category:n.category||``,low_stock_threshold_pct:n.low_stock_threshold_pct??null,material_number:n.material_number||``,location_id:n.location_id??null,last_dried_at:(()=>{let e=b?null:H(n.last_dried_at);return e?_e(e):``})(),spoolman_filament_id:null}),ye(n.slicer_filament_name||n.slicer_filament||``),n.k_profiles&&n.k_profiles.length>0){let e=new Map;for(let t of n.k_profiles){if(t.cali_idx===null||t.cali_idx===void 0)continue;let n=(t.nozzle_diameter||``).trim()||`0.4`,r=t.extruder??0;e.set(K(t.printer_id,r,n),{cali_idx:t.cali_idx,filament_id:``,setting_id:t.setting_id||``,name:t.name||``,k_value:t.k_value,n_coef:0,extruder_id:r,nozzle_diameter:n,nozzle_id:t.nozzle_type||``})}Ve(e)}else Ve(new Map);I((n.suppliers??[]).map(e=>({supplier_id:e.supplier_id,supplier_name:e.supplier_name,supplier_article_number:e.supplier_article_number??``,quoted_price_per_kg:e.quoted_price_per_kg,is_purchase_source:b?!1:e.is_purchase_source})))}else S(ut),ye(``),Ve(new Map),I([]);ie(!1),oe(1),w({}),E(`filament`),Ge(``),Ue(new Map),O(!1),N(!1),k(b&&n?.core_weight_is_inherited===!1),j(!1),re(!1)}},[e,n,i,b]),(0,J.useEffect)(()=>{if(!e||!n)return;let t=!1;return(p?r.getSpoolmanFilamentPresets:r.getSpoolFilamentPresets)(n.id).then(e=>{if(t)return;let n=new Map;for(let t of e)n.set(gt(t.printer_model,t.nozzle_diameter||``),{code:t.slicer_filament||``,name:t.slicer_filament_name||``});Ue(n)}).catch(e=>{t||(console.error(`Failed to load filament preset overrides:`,e),_(h(`inventory.filamentPresetsLoadFailed`),`warning`))}),()=>{t=!0}},[e,n?.id,p]),(0,J.useEffect)(()=>{if(!e||!n||A||x.location_id!=null)return;let t=n.storage_location?.trim();if(!t||Se.length===0)return;let r=Se.find(e=>e.name.toLowerCase()===t.toLowerCase());r&&S(e=>e.location_id===r.id?e:{...e,location_id:r.id})},[e,n,Se,x.location_id,A]);let pt=(e,t)=>{let n=st.has(e);p&&n&&x.spoolman_filament_id!==null&&_(h(`inventory.spoolmanFilamentUnlinked`),`info`),S(r=>({...r,[e]:t,...p&&n&&r.spoolman_filament_id!==null?{spoolman_filament_id:null}:{}})),e===`weight_used`&&O(!0),e===`core_weight`&&k(!0),e===`location_id`&&j(!0),e===`last_dried_at`&&N(!0),C[e]&&w(t=>({...t,[e]:void 0}))},mt=e=>{let t=e.material||``,n=e.name||``,r=t&&n.startsWith(t)?n.slice(t.length).trim():n,i=(e.color_hex??``).replace(`#`,``).toUpperCase(),a=/^[0-9A-F]{6}(?:[0-9A-F]{2})?$/.test(i)?i:`808080`,o=a.length===8?a:`${a}FF`;S(n=>({...n,spoolman_filament_id:e.id,material:t,subtype:r,brand:e.vendor?.name||``,rgba:o,color_name:e.color_name||``,label_weight:e.weight??n.label_weight})),_(h(`inventory.spoolmanFilamentSelected`),`success`)},vt=e=>{je(t=>_t(e,t))},Ct=d({mutationFn:e=>p?r.createSpoolmanInventorySpool(e):r.createSpool(e),onSuccess:async e=>{e?.id&&(!await Kt(e.id)||!await Gt(e.id))||(await v(),f&&f([e]),_(h(`inventory.spoolCreated`),`success`),t())},onError:e=>{e instanceof o&&e.status===503?_(h(`inventory.spoolmanUnreachable`),`error`):_(h(`inventory.saveFailed`),`error`)}}),At=d({mutationFn:({data:e,qty:t})=>p?r.bulkCreateSpoolmanInventorySpools(e,t):r.bulkCreateSpools(e,t),onSuccess:async e=>{let n=p&&`created`in e?e:null,r=n?n.created:e;if(ze.size>0||He.size>0)for(let e of r)await Kt(e.id);if(Wt)for(let e of r)await Gt(e.id);await v(),f&&f(r),n&&n.failed_count>0?_(h(`inventory.spoolsPartiallyCreated`,{created:r.length,total:n.requested_count}),`warning`):_(h(`inventory.spoolsCreated`,{count:r.length}),`success`),t()},onError:e=>{e instanceof o&&e.status===503?_(h(`inventory.spoolmanUnreachable`),`error`):_(h(`inventory.saveFailed`),`error`)}}),jt=d({mutationFn:e=>p?r.updateSpoolmanInventorySpool(n.id,e):r.updateSpool(n.id,e),onSuccess:async()=>{n?.id&&(!await Kt(n.id)||!await Gt(n.id))||(await v(),_(h(`inventory.spoolUpdated`),`success`),t())},onError:e=>{e instanceof o&&e.status===503?_(h(`inventory.spoolmanUnreachable`),`error`):_(h(`inventory.saveFailed`),`error`)}}),Mt=d({mutationFn:()=>p?r.updateSpoolmanInventorySpool(n.id,hn):r.updateSpool(n.id,hn),onSuccess:async()=>{await v(),_(h(`inventory.rfidCleared`,`RFID tag cleared`),`success`),t()},onError:e=>{e instanceof o&&e.status===503?_(h(`inventory.spoolmanUnreachable`),`error`):_(h(`inventory.tagClearFailed`),`error`)}}),{data:Nt,isLoading:Pt}=u({queryKey:[`spool-assignments`],queryFn:()=>r.getAssignments(),enabled:e&&y&&!p}),{data:Ft,isLoading:It}=u({queryKey:[`spoolman-slot-assignments-all`],queryFn:()=>r.getSpoolmanSlotAssignments(),enabled:e&&y&&p}),Lt=(()=>{if(n)return p?Ft?.find(e=>e.spoolman_spool_id===n.id):Nt?.find(e=>e.spool_id===n.id)})(),Rt=p?It:Pt,{data:X}=u({queryKey:[`inventory-spools`],queryFn:()=>r.getSpools(!0),enabled:e}),{data:Z}=u({queryKey:[`settings`],queryFn:r.getSettings,enabled:e}),{data:zt}=u({queryKey:[`slicerPrinterModels`],queryFn:r.getSlicerPrinterModels,enabled:e,staleTime:1/0}),Bt=(()=>{let e=new Set;for(let t of X??[]){let n=t.category?.trim();n&&e.add(n)}return Array.from(e).sort((e,t)=>e.localeCompare(t))})(),Vt=(()=>{let e=new Set;for(let t of X??[]){let n=t.material_number?.trim();n&&e.add(n)}return Array.from(e).sort((e,t)=>e.localeCompare(t,void 0,{numeric:!0}))})(),Ht=Z?.low_stock_threshold??20,Ut=d({mutationFn:async()=>{if(!Lt)throw Error(`No assignment`);if(p){if(!n)throw Error(`No spool`);await r.unassignSpoolmanSlot(n.id);return}await r.unassignSpool(Lt.printer_id,Lt.ams_id,Lt.tray_id)},onSuccess:async()=>{p?(await g.invalidateQueries({queryKey:[`spoolman-slot-assignments-all`]}),await g.invalidateQueries({queryKey:[`spoolman-slot-assignments`]})):await g.invalidateQueries({queryKey:[`spool-assignments`]}),_(h(`inventory.unassignSuccess`,`Spool unassigned`),`success`),t()},onError:e=>{_(e.message,`error`)}}),Wt=L||b,Gt=async e=>{if(!Wt)return!0;let t=p?r.setSpoolmanSpoolSuppliers:r.setSpoolSuppliers;try{return await t(e,ne.map(e=>({supplier_id:e.supplier_id,supplier_article_number:e.supplier_article_number.trim()||null,quoted_price_per_kg:e.quoted_price_per_kg,is_purchase_source:e.is_purchase_source}))),!0}catch(e){return console.error(`SpoolFormModal.saveSupplierLinks failed:`,e),_(h(`inventory.suppliers.saveFailed`),`error`),!1}},Kt=async e=>{let t=p?r.saveSpoolmanKProfiles:r.saveSpoolKProfiles,n=p?r.saveSpoolmanFilamentPresets:r.saveSpoolFilamentPresets,i=[];for(let[e,t]of ze){let[n,r,a]=e.split(`:`);i.push({printer_id:parseInt(n),extruder:parseInt(r),nozzle_diameter:a||`0.4`,nozzle_type:on(t.nozzle_id),k_value:t.k_value,name:t.name||null,cali_idx:t.cali_idx,setting_id:t.setting_id||null})}let a=[];for(let[e,t]of He){let{model:n,diameter:r}=bt(e);n&&a.push({printer_model:n,nozzle_diameter:r,slicer_filament:t.code||null,slicer_filament_name:t.name||null})}try{await t(e,i)}catch(e){return console.error(`Failed to save K-profiles:`,e),_(h(`inventory.kProfileSaveFailed`),`warning`),!1}try{await n(e,a)}catch(e){return console.error(`Failed to save filament preset overrides:`,e),_(h(`inventory.filamentPresetSaveFailed`),`warning`),!1}return!0};if((0,J.useEffect)(()=>{if(!e)return;let n=e=>{e.key===`Escape`&&!se&&t()};return document.addEventListener(`keydown`,n),()=>document.removeEventListener(`keydown`,n)},[e,t,se]),!e)return null;let qt=()=>{let e=dt(x,R,p,i);if(!e.isValid){w(e.errors),(e.errors.slicer_filament||e.errors.material||e.errors.brand||e.errors.subtype)&&E(`filament`);return}let t=ct?.displayName||ve||null,n={material:x.material||null,subtype:x.subtype||null,brand:x.brand||null,color_name:x.color_name||null,rgba:x.rgba||null,extra_colors:x.extra_colors||null,effect_type:x.effect_type||null,label_weight:x.label_weight,...p?ee?{core_weight:x.core_weight}:{}:{core_weight:x.core_weight,core_weight_catalog_id:x.core_weight_catalog_id},slicer_filament:x.slicer_filament||null,slicer_filament_name:t,nozzle_temp_min:null,nozzle_temp_max:null,note:x.note||null,cost_per_kg:x.cost_per_kg,category:x.category.trim()||null,low_stock_threshold_pct:x.low_stock_threshold_pct,material_number:x.material_number.trim()||null,...p?{spoolman_filament_id:x.spoolman_filament_id}:{}};(!y||D)&&(n.weight_used=x.weight_used),(!y||A)&&(n.location_id=x.location_id),y&&M&&(n.last_dried_at=x.last_dried_at?new Date(x.last_dried_at).toISOString():null),y?jt.mutate(n):ae>1?At.mutate({data:n,qty:ae}):Ct.mutate(n)},Jt=Ct.isPending||At.isPending||jt.isPending||Mt.isPending||Ut.isPending;return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[(0,Y.jsx)(`div`,{className:`absolute inset-0 bg-black/60 backdrop-blur-sm`,onClick:t}),(0,Y.jsxs)(`div`,{className:`relative w-full max-w-5xl mx-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl max-h-[90vh] flex flex-col`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary flex-shrink-0`,children:[(0,Y.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-baseline gap-2`,children:[h(y?`inventory.editSpool`:b?`inventory.copySpool`:`inventory.addSpool`),y&&n&&(0,Y.jsxs)(`span`,{className:`text-sm font-mono text-bambu-gray`,children:[`#`,n.id]})]}),(0,Y.jsx)(`button`,{onClick:t,className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,Y.jsx)(he,{className:`w-5 h-5`})})]}),i===`create`&&(0,Y.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2 border-b border-bambu-dark-tertiary flex-shrink-0`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(Re,{className:`w-4 h-4 text-amber-600 dark:text-amber-400`}),(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:h(`inventory.quickAdd`)})]}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>{ie(!R),R||E(`filament`)},className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors ${R?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,children:(0,Y.jsx)(`span`,{className:`inline-block h-3.5 w-3.5 rounded-full bg-white transition-transform ${R?`translate-x-4`:`translate-x-0.5`}`})})]}),(0,Y.jsxs)(`div`,{className:`flex border-b border-bambu-dark-tertiary flex-shrink-0`,children:[(0,Y.jsxs)(`button`,{onClick:()=>E(`filament`),className:`flex-1 px-4 py-2.5 text-sm font-medium flex items-center justify-center gap-2 transition-colors ${T===`filament`?`text-bambu-green border-b-2 border-bambu-green`:`text-bambu-gray hover:text-white`}`,children:[(0,Y.jsx)(q,{className:`w-4 h-4`}),h(`inventory.filamentInfoTab`)]}),!R&&(0,Y.jsxs)(`button`,{onClick:()=>E(`appearance`),className:`flex-1 px-4 py-2.5 text-sm font-medium flex items-center justify-center gap-2 transition-colors ${T===`appearance`?`text-bambu-green border-b-2 border-bambu-green`:`text-bambu-gray hover:text-white`}`,children:[(0,Y.jsx)(Be,{className:`w-4 h-4`}),h(`inventory.colorAndCostTab`)]}),!R&&(0,Y.jsxs)(`button`,{onClick:()=>E(`printers`),className:`flex-1 px-4 py-2.5 text-sm font-medium flex items-center justify-center gap-2 transition-colors ${T===`printers`?`text-bambu-green border-b-2 border-bambu-green`:`text-bambu-gray hover:text-white`}`,children:[(0,Y.jsx)(Re,{className:`w-4 h-4`}),h(`inventory.printersTab`),qe>0&&(0,Y.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded-full bg-bambu-green/20 text-bambu-green`,children:qe})]})]}),(0,Y.jsx)(`div`,{className:`p-4 overflow-y-auto flex-1`,style:{scrollbarGutter:`stable`},children:T===`filament`?(0,Y.jsxs)(`div`,{className:`space-y-6`,children:[p&&!y&&(0,Y.jsx)(`div`,{children:W?(0,Y.jsx)(`p`,{className:`text-sm text-red-700 dark:text-red-400 px-1`,children:h(`inventory.spoolmanCatalogLoadFailed`)}):(0,Y.jsx)(an,{filaments:Je,isLoading:Xe,selectedId:x.spoolman_filament_id,onSelect:mt})}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h3`,{className:`text-sm font-semibold text-bambu-gray uppercase tracking-wide mb-3`,children:h(`inventory.filamentInfo`)}),(0,Y.jsx)(G,{formData:x,updateField:pt,cloudAuthenticated:ce,loadingCloudPresets:ue,presetInputValue:ve,setPresetInputValue:ye,selectedPresetOption:ct,filamentOptions:Ze,availableBrands:rt,availableMaterials:it,suggestedBrands:at,suggestedMaterials:ot,quickAdd:R,detailsRequired:!R&&!p&&i===`create`,quantity:ae,onQuantityChange:oe,errors:C})]})]}):T===`appearance`?(0,Y.jsxs)(`div`,{className:`space-y-6`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h3`,{className:`text-sm font-semibold text-bambu-gray uppercase tracking-wide mb-3`,children:h(`inventory.color`)}),(0,Y.jsx)(lt,{formData:x,updateField:pt,recentColors:Ae,onColorUsed:vt,catalogColors:De})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h3`,{className:`text-sm font-semibold text-bambu-gray uppercase tracking-wide mb-3`,children:h(`inventory.additional`)}),(0,Y.jsx)(ft,{formData:x,updateField:pt,spoolCatalog:be,currencySymbol:s,availableCategories:Bt,availableMaterialNumbers:Vt,availableLocations:Se,showLastDried:y,onCreateLocation:async e=>{try{let t=await r.createLocation({name:e});return Ce(e=>[...e,{id:t.id,name:t.name}].sort((e,t)=>e.name.localeCompare(t.name))),await Ye(g),{id:t.id,name:t.name}}catch(e){return console.error(e),_((e instanceof Error?e.message:h(`locations.saveFailed`))||h(`locations.saveFailed`),`error`),null}},globalLowStockThreshold:Ht,spoolmanMode:p})]}),(0,Y.jsx)(`div`,{children:(0,Y.jsx)(rn,{links:ne,onChange:e=>{I(e),re(!0)},currencySymbol:s})}),y&&n&&!p&&(0,Y.jsx)(`div`,{children:(0,Y.jsx)(mn,{spoolId:n.id})})]}):(0,Y.jsx)(dn,{formData:x,printersWithCalibrations:Ke,filamentOptions:Ze,modelPresets:He,setModelPresets:Ue,selectedProfiles:ze,setSelectedProfiles:Ve,selectedGroupId:We,setSelectedGroupId:Ge,printerModels:zt,isLoading:Fe})}),(0,Y.jsxs)(`div`,{className:`flex gap-2 p-4 border-t border-bambu-dark-tertiary flex-shrink-0`,children:[y&&(0,Y.jsxs)(`div`,{className:`flex gap-2 mr-auto`,children:[(0,Y.jsxs)(V,{variant:`secondary`,onClick:()=>Mt.mutate(),disabled:Jt||!(n?.tag_uid||n?.tray_uuid),children:[(0,Y.jsx)(ke,{className:`w-4 h-4`}),h(`inventory.clearRfid`,`Clear RFID Tag`)]}),Lt?(0,Y.jsxs)(V,{variant:`secondary`,onClick:()=>Ut.mutate(),disabled:Jt||Rt,children:[(0,Y.jsx)(me,{className:`w-4 h-4`}),h(`inventory.unassignSpool`,`Unassign`)]}):(0,Y.jsxs)(V,{variant:`secondary`,onClick:()=>z(!0),disabled:Jt||Rt,children:[(0,Y.jsx)(P,{className:`w-4 h-4`}),h(`inventory.assignSpool`,`Assign Spool`)]})]}),(0,Y.jsxs)(`div`,{className:`flex gap-2 ml-auto`,children:[(0,Y.jsx)(V,{variant:`secondary`,onClick:t,children:h(`common.cancel`)}),(0,Y.jsx)(V,{onClick:qt,disabled:Jt,children:Jt?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(F,{className:`w-4 h-4 animate-spin`}),h(`common.saving`)]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(Me,{className:`w-4 h-4`}),h(y?`common.save`:b?`inventory.copySpool`:`inventory.addSpool`)]})})]})]})]})]}),y&&n&&(0,Y.jsx)(kt,{isOpen:se,onClose:()=>z(!1),spool:n,printerId:null,variant:`dialog`,spoolmanMode:p})]})}var Q=[{value:`ams_holder_74x33`,i18nKey:`amsHolderSmall`,fallbackLabel:`AMS holder — small (74 × 33 mm)`,fallbackHint:`Single label per page; matches the printable label from MakerWorld model 752566 (AMS Filament Label Holder).`},{value:`ams_holder_75x55`,i18nKey:`amsHolderLarge`,fallbackLabel:`AMS holder — large (75 × 55 mm)`,fallbackHint:`Single label per page; fits the cardstock-insert variant of the AMS Filament Label Holder. Roomy enough for swatch, brand, material, ID, and QR code.`},{value:`box_40x30`,i18nKey:`box40x30`,fallbackLabel:`Box label (40 × 30 mm)`,fallbackHint:`Single label per page; common DK/Brother roll size, good for filament-bag and storage-bin labels.`},{value:`box_62x29`,i18nKey:`box`,fallbackLabel:`Box label (62 × 29 mm)`,fallbackHint:`Single label per page; sized for Brother PT/QL and Dymo small labels.`},{value:`avery_l7160`,i18nKey:`averyL7160`,fallbackLabel:`Avery L7160 — A4 sheet (38.1 × 63.5 mm × 21)`,fallbackHint:`EU sheet stock; 21 labels per A4 page.`},{value:`avery_5160`,i18nKey:`avery5160`,fallbackLabel:`Avery 5160 — US Letter sheet (25.4 × 66.7 mm × 30)`,fallbackHint:`US sheet stock; 30 labels per Letter page.`}],_n={avery_l7160:21,avery_5160:30},vn=[203,300,600],yn={brand:{i18nKey:`brand`,fallback:`Brand`},material:{i18nKey:`material`,fallback:`Material and subtype`},hex:{i18nKey:`hex`,fallback:`Colour code`},name:{i18nKey:`name`,fallback:`Colour or filament name`},location:{i18nKey:`location`,fallback:`Storage location`},material_number:{i18nKey:`materialNumber`,fallback:`Material number`},temps:{i18nKey:`temps`,fallback:`Nozzle temperature`},weight:{i18nKey:`weight`,fallback:`Net weight`},note:{i18nKey:`note`,fallback:`Note`},added:{i18nKey:`added`,fallback:`Date added`},qr:{i18nKey:`qr`,fallback:`QR code`},spool_id:{i18nKey:`spoolId`,fallback:`Spool ID`}},bn=`bambuddy-label-print-options`,xn={template:Q[0].value,fields:{},monochrome:!1,format:`pdf`,dpi:300};function Sn(){let e;try{e=JSON.parse(localStorage.getItem(bn)??`null`)}catch{return xn}if(!e||typeof e!=`object`)return xn;let t=e,n=Q.map(e=>e.value),r={};if(t.fields&&typeof t.fields==`object`)for(let[e,i]of Object.entries(t.fields))!n.includes(e)||!Array.isArray(i)||(r[e]=i.filter(e=>a.includes(e)));return{template:n.includes(t.template)?t.template:xn.template,fields:r,monochrome:t.monochrome===!0,format:t.format===`png`?`png`:`pdf`,dpi:vn.includes(t.dpi)?t.dpi:xn.dpi}}function Cn(e){try{localStorage.setItem(bn,JSON.stringify(e))}catch{}}function wn(e,t){return e.fields[t]??i}function Tn(e){let t=window.URL.createObjectURL(e);if(!window.open(t,`_blank`)){let e=document.createElement(`a`);e.href=t,e.download=`bambuddy-labels.pdf`,document.body.appendChild(e),e.click(),document.body.removeChild(e)}setTimeout(()=>window.URL.revokeObjectURL(t),6e4)}function En(e,t){let n=window.URL.createObjectURL(e),r=document.createElement(`a`);r.href=n,r.download=`bambuddy-labels-${t}.${e.type===`application/zip`?`zip`:`png`}`,document.body.appendChild(r),r.click(),document.body.removeChild(r),setTimeout(()=>window.URL.revokeObjectURL(n),6e4)}function Dn(e){return Ke(e)}function On(e){return Ve(e.color_name,e.rgba,e.color_name_is_synthesized)}function $(e){return`${On(e)??`${e.material}${e.subtype?` ${e.subtype}`:``}`}${e.brand?` · ${e.brand}`:``}`}function kn(e){return[On(e),e.color_name,e.material,e.subtype,e.brand,`#${e.id}`].filter(Boolean).join(` `).toLowerCase()}function An(e){if(!e)return[1,0];let t=e.replace(/^#/,``).slice(0,6);if(t.length!==6)return[1,0];let n=parseInt(t.slice(0,2),16),r=parseInt(t.slice(2,4),16),i=parseInt(t.slice(4,6),16);if([n,r,i].some(Number.isNaN))return[1,0];let a=n/255,o=r/255,s=i/255,c=Math.max(a,o,s),l=Math.min(a,o,s),u=(c+l)/2,d=c-l;if((d===0?0:d/(1-Math.abs(2*u-1)))<.1)return[1,u];let f=0;return f=c===a?(o-s)/d%6:c===o?(s-a)/d+2:(a-o)/d+4,f*=60,f<0&&(f+=360),[0,f]}function jn({isOpen:e,onClose:t,availableSpools:n,initialSelectedIds:o,spoolmanMode:s}){let{t:l}=c(),u=Je(),{showToast:d}=te(),[f,p]=(0,J.useState)(!1),[m,h]=(0,J.useState)(new Set),[g,_]=(0,J.useState)(``),[v,y]=(0,J.useState)(``),[b,x]=(0,J.useState)(`id`),[S,C]=(0,J.useState)(xn),[w,T]=(0,J.useState)(`1`),[E,D]=(0,J.useState)(null),[O,ee]=(0,J.useState)(!1),[k,A]=(0,J.useState)(null),j=(0,J.useRef)(null);(0,J.useEffect)(()=>{if(e){let e=new Set(n.map(e=>e.id));h(new Set(o.filter(t=>e.has(t)))),_(``),y(``),x(`id`),C(Sn()),T(`1`),p(!1)}},[e]);let M=(0,J.useMemo)(()=>{let e=[...n];return b===`color`?(e.sort((e,t)=>{let n=An(e.rgba),r=An(t.rgba);return n[0]===r[0]?n[1]===r[1]?e.id-t.id:n[1]-r[1]:n[0]-r[0]}),e):(e.sort((e,t)=>e.id-t.id),e)},[n,b]),N=(0,J.useMemo)(()=>{let e=new Set;for(let t of M)t.material&&e.add(t.material.toUpperCase());return[...e].sort()},[M]),P=(0,J.useMemo)(()=>{let e=g.trim().toLowerCase();return M.filter(t=>!(v&&(t.material||``).toUpperCase()!==v||e&&!kn(t).includes(e)))},[M,g,v,u]),ne=P.length>0&&P.every(e=>m.has(e.id)),I=S.template,L=wn(S,I),re=L.join(`,`),R=M.find(e=>m.has(e.id))?.id??null;function ie(e){j.current&&window.URL.revokeObjectURL(j.current),j.current=e,D(e)}if((0,J.useEffect)(()=>{if(!e||R===null){ie(null),A(null),ee(!1);return}let t=new AbortController;ee(!0);let n=window.setTimeout(async()=>{let e={spool_id:R,template:I,monochrome:S.monochrome,fields:re?re.split(`,`):[]};try{let n=s?await r.previewSpoolmanSpoolLabel(e,t.signal):await r.previewSpoolLabel(e,t.signal);if(t.signal.aborted)return;ie(window.URL.createObjectURL(n)),A(null)}catch(e){if(t.signal.aborted)return;ie(null),A(e instanceof Error?e.message:String(e))}finally{t.signal.aborted||ee(!1)}},250);return()=>{window.clearTimeout(n),t.abort()}},[e,R,I,re,S.monochrome,s]),(0,J.useEffect)(()=>()=>{j.current&&window.URL.revokeObjectURL(j.current)},[]),!e)return null;let ae=m.size,oe=ae===0,z=_n[I],ce=Number(w),le=z===void 0||Number.isInteger(ce)&&ce>=1&&ce<=z,ue=Q.find(e=>e.value===I)??Q[0];function de(e){C(t=>{let n={...t,...e};return Cn(n),n})}function fe(e){let t=a.filter(t=>e.includes(t));de({fields:{...S.fields,[I]:t}})}function pe(e){fe(L.includes(e)?L.filter(t=>t!==e):[...L,e])}function B(e){h(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function me(){h(e=>{let t=new Set(e);for(let e of P)t.add(e.id);return t})}function ge(){h(e=>{let t=new Set(e);for(let e of P)t.delete(e.id);return t})}function H(){h(new Set)}async function _e(){if(oe||f||!le)return;let e={spool_ids:M.filter(e=>m.has(e.id)).map(e=>e.id),template:I,monochrome:S.monochrome,starting_position:z===void 0?1:ce,fields:L,format:S.format,dpi:S.dpi};p(!0);try{let n=s?await r.printSpoolmanSpoolLabels(e):await r.printSpoolLabels(e);S.format===`pdf`?Tn(n):En(n,I),t()}catch(e){d(l(`inventory.labels.error`,`Could not generate labels: {{msg}}`,{msg:e instanceof Error?e.message:String(e)}),`error`)}finally{p(!1)}}let ve=e=>`px-2 py-0.5 text-xs rounded-full border transition ${e?`bg-bambu-green text-bambu-dark border-bambu-green`:`bg-bambu-dark text-bambu-gray border-bambu-dark-tertiary hover:border-bambu-gray`}`;return(0,Y.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-start sm:items-center justify-center p-4 overflow-y-auto`,children:[(0,Y.jsx)(`div`,{className:`absolute inset-0 bg-black/60 backdrop-blur-sm`,onClick:t}),(0,Y.jsxs)(`div`,{"data-testid":`label-template-picker-panel`,className:`relative w-full max-w-5xl bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl max-h-[90vh] overflow-clip flex flex-col my-auto`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(U,{className:`w-5 h-5 text-bambu-green`}),(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:l(`inventory.labels.title`,`Print spool labels`)}),ae>0&&(0,Y.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[`(`,l(`inventory.labels.selectedCount`,`{{count}} selected`,{count:ae}),`)`]})]}),(0,Y.jsx)(`button`,{onClick:t,className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,"aria-label":l(`common.close`,`Close`),children:(0,Y.jsx)(he,{className:`w-5 h-5`})})]}),(0,Y.jsxs)(`div`,{className:`flex-1 min-h-0 overflow-y-auto md:overflow-hidden grid grid-cols-1 md:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-col min-h-0 md:border-r border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{className:`p-4 space-y-2 border-b border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsx)(se,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`}),(0,Y.jsx)(`input`,{type:`search`,value:g,onChange:e=>_(e.target.value),placeholder:l(`inventory.labels.searchPlaceholder`,`Search name, brand, or #ID`),className:`w-full pl-9 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray focus:outline-none focus:border-bambu-green`})]}),N.length>1&&(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray mr-1`,children:l(`inventory.labels.filterByMaterial`,`Material:`)}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>y(``),className:`px-2 py-0.5 text-xs rounded-full border transition ${v===``?`bg-bambu-green text-bambu-dark border-bambu-green`:`bg-bambu-dark text-bambu-gray border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:l(`inventory.labels.allMaterials`,`All`)}),N.map(e=>(0,Y.jsx)(`button`,{type:`button`,onClick:()=>y(e),className:`px-2 py-0.5 text-xs rounded-full border transition ${v===e?`bg-bambu-green text-bambu-dark border-bambu-green`:`bg-bambu-dark text-bambu-gray border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:e},e))]}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray mr-1`,children:l(`inventory.labels.sortBy.label`)}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>x(`id`),className:`px-2 py-0.5 text-xs rounded-full border transition ${b===`id`?`bg-bambu-green text-bambu-dark border-bambu-green`:`bg-bambu-dark text-bambu-gray border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:l(`inventory.labels.sortBy.id`)}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>x(`color`),className:`px-2 py-0.5 text-xs rounded-full border transition ${b===`color`?`bg-bambu-green text-bambu-dark border-bambu-green`:`bg-bambu-dark text-bambu-gray border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:l(`inventory.labels.sortBy.color`)})]})]}),(0,Y.jsxs)(`div`,{className:`px-4 pt-3 pb-2 flex items-center justify-between gap-3 flex-wrap`,children:[(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:l(`inventory.labels.pickSpools`,`Pick which spools to print labels for:`)}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-3 text-xs`,children:[(0,Y.jsx)(`button`,{type:`button`,onClick:ne?ge:me,disabled:P.length===0,className:`text-bambu-green hover:underline disabled:opacity-50 disabled:no-underline disabled:cursor-not-allowed`,children:ne?l(`inventory.labels.deselectVisible`,`Deselect visible`):l(`inventory.labels.selectVisible`,`Select all visible ({{count}})`,{count:P.length})}),(0,Y.jsx)(`button`,{type:`button`,onClick:H,disabled:ae===0,className:`text-bambu-gray hover:text-white hover:underline disabled:opacity-50 disabled:no-underline disabled:cursor-not-allowed`,children:l(`inventory.labels.clearAll`,`Clear all`)})]})]}),(0,Y.jsx)(`div`,{className:`flex-1 overflow-y-auto px-2 pb-2 min-h-0 max-h-72 md:max-h-none`,children:P.length===0?(0,Y.jsx)(`div`,{className:`text-center text-sm text-bambu-gray py-6`,children:M.length===0?l(`inventory.labels.noSpoolsToShow`,`No spools to show. Adjust your filter and try again.`):l(`inventory.labels.noMatches`,`No spools match the current search or filter.`)}):(0,Y.jsx)(`ul`,{className:`space-y-0.5`,children:P.map(e=>{let t=m.has(e.id);return(0,Y.jsx)(`li`,{children:(0,Y.jsxs)(`label`,{className:`flex items-center gap-3 px-2 py-1.5 rounded hover:bg-bambu-dark-tertiary/50 cursor-pointer`,children:[t?(0,Y.jsx)(Ae,{className:`w-4 h-4 text-bambu-green shrink-0`}):(0,Y.jsx)(Ee,{className:`w-4 h-4 text-bambu-gray shrink-0`}),(0,Y.jsx)(`input`,{type:`checkbox`,checked:t,onChange:()=>B(e.id),className:`sr-only`}),(0,Y.jsx)(`span`,{className:`w-4 h-4 rounded border border-black/20 shrink-0`,style:Dn(e.rgba)}),(0,Y.jsx)(`span`,{className:`flex-1 min-w-0 truncate text-sm text-white`,children:$(e)}),(0,Y.jsxs)(`span`,{className:`text-xs font-mono text-bambu-gray shrink-0`,children:[`#`,e.id]})]})},e.id)})})})]}),(0,Y.jsxs)(`div`,{className:`md:overflow-y-auto p-4 space-y-4 border-t md:border-t-0 border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(`label`,{htmlFor:`label-template`,className:`text-sm font-medium text-white`,children:l(`inventory.labels.template`,`Label size`)}),(0,Y.jsx)(`select`,{id:`label-template`,"data-testid":`label-template-select`,value:I,onChange:e=>de({template: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:outline-none focus:border-bambu-green`,children:Q.map(e=>(0,Y.jsx)(`option`,{value:e.value,children:l(`inventory.labels.templates.${e.i18nKey}.label`,e.fallbackLabel)},e.value))}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:l(`inventory.labels.templates.${ue.i18nKey}.hint`,ue.fallbackHint)})]}),(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium text-white`,children:R===null?l(`inventory.labels.preview`,`Preview`):l(`inventory.labels.previewOf`,`Preview of #{{id}}`,{id:R})}),(0,Y.jsxs)(`div`,{"data-testid":`label-preview`,className:`relative flex items-center justify-center min-h-40 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary`,children:[R===null?(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray text-center`,children:l(`inventory.labels.previewNoSelection`,`Select a spool to see its label.`)}):k?(0,Y.jsx)(`span`,{className:`text-sm text-red-400 text-center`,children:l(`inventory.labels.previewError`,`Could not render the preview: {{msg}}`,{msg:k})}):E?(0,Y.jsx)(`img`,{src:E,alt:l(`inventory.labels.previewAlt`,`Label preview`),className:`max-h-56 max-w-full object-contain bg-white shadow`}):null,O&&(0,Y.jsx)(F,{className:`absolute top-2 right-2 w-4 h-4 animate-spin text-bambu-green`})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:l(`inventory.labels.previewHint`,`Lines that don't fit on this label size are left out.`)})]}),(0,Y.jsxs)(`fieldset`,{className:`space-y-2`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Y.jsx)(`legend`,{className:`text-sm font-medium text-white`,children:l(`inventory.labels.content`,`Print on the label`)}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>fe(i),className:`text-xs text-bambu-green hover:underline`,children:l(`inventory.labels.resetFields`,`Reset to default`)})]}),(0,Y.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-x-3 gap-y-1`,children:a.map(e=>{let t=L.includes(e),{i18nKey:n,fallback:r}=yn[e];return(0,Y.jsxs)(`label`,{className:`flex items-center gap-2 py-0.5 cursor-pointer select-none`,children:[t?(0,Y.jsx)(Ae,{className:`w-4 h-4 text-bambu-green shrink-0`}):(0,Y.jsx)(Ee,{className:`w-4 h-4 text-bambu-gray shrink-0`}),(0,Y.jsx)(`input`,{type:`checkbox`,"data-testid":`label-field-${e}`,checked:t,onChange:()=>pe(e),className:`sr-only`}),(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:l(`inventory.labels.fields.${n}`,r)})]},e)})})]}),(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsxs)(`label`,{className:`inline-flex items-center gap-2 cursor-pointer select-none`,children:[S.monochrome?(0,Y.jsx)(Ae,{className:`w-4 h-4 text-bambu-green shrink-0`}):(0,Y.jsx)(Ee,{className:`w-4 h-4 text-bambu-gray shrink-0`}),(0,Y.jsx)(`input`,{type:`checkbox`,checked:S.monochrome,onChange:e=>de({monochrome:e.target.checked}),className:`sr-only`}),(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:l(`inventory.labels.monochrome`,`Monochrome (black & white printer)`)}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:l(`inventory.labels.monochromeHint`,`Drops the colour swatch and widens the text`)})]}),z!==void 0&&(0,Y.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,Y.jsx)(`label`,{htmlFor:`label-starting-position`,className:`text-sm text-white whitespace-nowrap pt-1.5`,children:l(`inventory.labels.startingPosition`,`Starting label position`)}),(0,Y.jsx)(`input`,{id:`label-starting-position`,"data-testid":`label-starting-position`,type:`number`,min:1,max:z,step:1,value:w,onChange:e=>T(e.target.value),"aria-describedby":`label-starting-position-help`,className:`w-20 px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:outline-none focus:border-bambu-green`}),(0,Y.jsx)(`div`,{id:`label-starting-position-help`,"data-testid":`label-starting-position-status`,className:`text-xs pt-1.5 ${le?`text-bambu-gray`:`text-red-400`}`,children:le?ce===1?l(`inventory.labels.startingPositionFirst`,`Printing starts at position 1.`):l(`inventory.labels.startingPositionSkipped`,`Positions 1 through {{lastPosition}} will be left blank on the first sheet.`,{lastPosition:ce-1}):l(`inventory.labels.startingPositionInvalid`,`Enter a whole number from 1 to {{capacity}}.`,{capacity:z})})]}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,Y.jsx)(`span`,{className:`text-sm text-white mr-1`,children:l(`inventory.labels.format`,`Output:`)}),(0,Y.jsx)(`button`,{type:`button`,"data-testid":`label-format-pdf`,"aria-pressed":S.format===`pdf`,onClick:()=>de({format:`pdf`}),className:ve(S.format===`pdf`),children:`PDF`}),(0,Y.jsx)(`button`,{type:`button`,"data-testid":`label-format-png`,"aria-pressed":S.format===`png`,onClick:()=>de({format:`png`}),className:ve(S.format===`png`),children:`PNG`}),S.format===`png`&&(0,Y.jsx)(`select`,{"data-testid":`label-dpi-select`,"aria-label":l(`inventory.labels.dpi`,`Resolution`),value:S.dpi,onChange:e=>de({dpi:Number(e.target.value)}),className:`ml-2 px-2 py-0.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-xs focus:outline-none focus:border-bambu-green`,children:vn.map(e=>(0,Y.jsxs)(`option`,{value:e,children:[e,` dpi`]},e))})]}),S.format===`png`&&(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:l(`inventory.labels.pngHint`,`For label printer software that takes images. Match your printer's resolution; several labels come as a ZIP.`)})]})]})]}),(0,Y.jsxs)(`div`,{className:`flex justify-end gap-2 px-5 py-3 border-t border-bambu-dark-tertiary`,children:[(0,Y.jsx)(V,{variant:`secondary`,onClick:t,disabled:f,children:l(`common.cancel`,`Cancel`)}),(0,Y.jsxs)(V,{"data-testid":`label-print-button`,onClick:_e,disabled:oe||f||!le,children:[f?(0,Y.jsx)(F,{className:`w-4 h-4 animate-spin`}):S.format===`pdf`?(0,Y.jsx)(U,{className:`w-4 h-4`}):(0,Y.jsx)(Qe,{className:`w-4 h-4`}),S.format===`pdf`?l(`inventory.labels.createPdf`,`Create PDF`):l(`inventory.labels.downloadPng`,`Download PNG`)]})]})]})]})}function Mn({onClose:e,onImported:t}){let{t:n}=c(),[i,a]=(0,J.useState)(null),[o,s]=(0,J.useState)(!1),[l,u]=(0,J.useState)(null),[d,f]=(0,J.useState)(!1),[p,m]=(0,J.useState)(!1),[h,g]=(0,J.useState)(null),_=(0,J.useRef)(null),v=async e=>{a(e),u(null),g(null),f(!0);try{u(await r.importSpoolsCsvPreview(e))}catch(e){g(e instanceof Error?e.message:n(`inventory.csv.previewError`,`Could not read the CSV file`))}finally{f(!1)}},y=e=>{let t=e.target.files?.[0];t&&v(t)},b=e=>{e.preventDefault(),s(!1);let t=e.dataTransfer.files?.[0];t&&v(t)},x=async()=>{if(i){m(!0),g(null);try{t((await r.importSpoolsCsv(i)).created)}catch(e){g(e instanceof Error?e.message:n(`inventory.csv.importError`,`Import failed`)),m(!1)}}},S=e=>e===`valid`?(0,Y.jsx)(A,{className:`w-4 h-4 text-green-500 flex-shrink-0`}):e===`error`?(0,Y.jsx)(D,{className:`w-4 h-4 text-red-500 flex-shrink-0`}):(0,Y.jsx)(We,{className:`w-4 h-4 text-bambu-gray flex-shrink-0`}),C=l?.valid_count??0;return(0,Y.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-3xl border border-bambu-dark-tertiary flex flex-col max-h-[90vh]`,children:[(0,Y.jsxs)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary flex items-center justify-between`,children:[(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:n(`inventory.csv.modalTitle`,`Import spools from CSV`)}),(0,Y.jsx)(`button`,{onClick:e,className:`p-1 hover:bg-bambu-dark rounded`,children:(0,Y.jsx)(he,{className:`w-5 h-5 text-bambu-gray`})})]}),(0,Y.jsxs)(`div`,{className:`p-4 space-y-4 overflow-y-auto flex-1`,children:[(0,Y.jsxs)(`div`,{onDragOver:e=>{e.preventDefault(),s(!0)},onDragLeave:e=>{e.preventDefault(),s(!1)},onDrop:b,onClick:()=>_.current?.click(),className:`border-2 border-dashed rounded-lg p-6 text-center cursor-pointer transition-colors ${o?`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary hover:border-bambu-green/50`}`,children:[(0,Y.jsx)(Ge,{className:`w-9 h-9 mx-auto mb-2 ${o?`text-bambu-green`:`text-bambu-gray`}`}),i?(0,Y.jsxs)(`p`,{className:`text-white font-medium flex items-center justify-center gap-2`,children:[(0,Y.jsx)($e,{className:`w-4 h-4`}),` `,i.name]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`p`,{className:`text-white font-medium`,children:n(`inventory.csv.selectFile`,`Choose a CSV file or drag it here`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray/70 mt-1`,children:n(`inventory.csv.dragHint`,`Header: material (required), brand, subtype, color_name, rgba, …`)})]})]}),(0,Y.jsx)(`input`,{ref:_,type:`file`,accept:`.csv,text/csv`,className:`hidden`,onChange:y}),d&&(0,Y.jsxs)(`div`,{className:`flex items-center justify-center gap-2 text-bambu-gray py-4`,children:[(0,Y.jsx)(F,{className:`w-4 h-4 animate-spin`}),n(`inventory.csv.parsing`,`Reading file…`)]}),h&&(0,Y.jsxs)(`div`,{className:`p-3 bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30 rounded-lg flex items-start gap-3`,children:[(0,Y.jsx)(D,{className:`w-5 h-5 text-red-600 dark:text-red-400 mt-0.5 flex-shrink-0`}),(0,Y.jsx)(`p`,{className:`text-sm text-red-700 dark:text-red-300 break-words`,children:h})]}),l&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap gap-3 text-sm`,children:[(0,Y.jsx)(`span`,{className:`px-2 py-1 rounded bg-green-50 dark:bg-green-500/10 text-green-700 dark:text-green-400`,children:n(`inventory.csv.validCount`,`{{count}} valid`,{count:l.valid_count})}),(0,Y.jsx)(`span`,{className:`px-2 py-1 rounded bg-red-50 dark:bg-red-500/10 text-red-700 dark:text-red-400`,children:n(`inventory.csv.errorCount`,`{{count}} error`,{count:l.error_count})}),(0,Y.jsx)(`span`,{className:`px-2 py-1 rounded bg-bambu-dark text-bambu-gray`,children:n(`inventory.csv.skippedCount`,`{{count}} skipped`,{count:l.skipped_count})})]}),l.warnings.length>0&&(0,Y.jsx)(`div`,{className:`p-3 bg-yellow-50 dark:bg-yellow-500/10 border border-yellow-300 dark:border-yellow-500/30 rounded-lg space-y-1`,children:l.warnings.map((e,t)=>(0,Y.jsx)(`p`,{className:`text-xs text-yellow-700 dark:text-yellow-300`,children:e},t))}),l.rows.length>0&&(0,Y.jsx)(`div`,{className:`border border-bambu-dark-tertiary rounded-lg overflow-hidden`,children:(0,Y.jsx)(`div`,{className:`max-h-72 overflow-y-auto`,children:(0,Y.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,Y.jsx)(`thead`,{className:`bg-bambu-dark sticky top-0`,children:(0,Y.jsxs)(`tr`,{className:`text-left text-bambu-gray`,children:[(0,Y.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:n(`inventory.csv.colRow`,`Row`)}),(0,Y.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:n(`inventory.csv.colStatus`,`Status`)}),(0,Y.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:n(`inventory.material`,`Material`)}),(0,Y.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:n(`inventory.brand`,`Brand`)}),(0,Y.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:n(`inventory.csv.colColor`,`Color`)})]})}),(0,Y.jsx)(`tbody`,{children:l.rows.map(e=>(0,Y.jsxs)(`tr`,{className:`border-t border-bambu-dark-tertiary`,children:[(0,Y.jsx)(`td`,{className:`px-3 py-2 text-bambu-gray`,children:e.row_number}),(0,Y.jsx)(`td`,{className:`px-3 py-2`,children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[S(e.status),e.status===`error`&&e.reason&&(0,Y.jsx)(`span`,{className:`text-xs text-red-700 dark:text-red-400 break-words`,children:e.reason})]})}),(0,Y.jsx)(`td`,{className:`px-3 py-2 text-white`,children:e.material||`—`}),(0,Y.jsx)(`td`,{className:`px-3 py-2 text-white`,children:e.brand||`—`}),(0,Y.jsx)(`td`,{className:`px-3 py-2`,children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.rgba&&(0,Y.jsx)(`span`,{className:`inline-block w-4 h-4 rounded-full border border-bambu-dark-tertiary flex-shrink-0`,style:Ke(e.rgba)}),(0,Y.jsx)(`span`,{className:`text-white`,children:e.color_name||`—`}),e.resolved_color&&!e.cross_material_color&&(0,Y.jsx)(`span`,{title:n(`inventory.csv.colorResolved`,`Color filled from catalog`),children:(0,Y.jsx)(je,{className:`w-3.5 h-3.5 text-bambu-green flex-shrink-0`})}),e.cross_material_color&&(0,Y.jsx)(`span`,{title:n(`inventory.csv.colorCrossMaterial`,`Color taken from a different material — no exact match in catalog`),children:(0,Y.jsx)(B,{className:`w-3.5 h-3.5 text-yellow-500 flex-shrink-0`})}),e.duplicate_of_existing&&(0,Y.jsx)(`span`,{title:n(`inventory.csv.duplicateExisting`,`A spool with this material, brand and color already exists — it will still be imported as a new spool`),children:(0,Y.jsx)(M,{className:`w-3.5 h-3.5 text-amber-600 dark:text-amber-400 flex-shrink-0`})})]})})]},e.row_number))})]})})})]})]}),(0,Y.jsxs)(`div`,{className:`p-4 border-t border-bambu-dark-tertiary flex justify-end gap-2`,children:[(0,Y.jsx)(V,{variant:`secondary`,onClick:e,disabled:p,children:n(`common.cancel`)}),(0,Y.jsx)(V,{onClick:x,disabled:!l||C===0||p,children:p?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(F,{className:`w-4 h-4 mr-2 animate-spin`}),n(`inventory.csv.importing`,`Importing…`)]}):C>0?n(`inventory.csv.importValidRows`,`Import {{count}} valid rows`,{count:C}):n(`inventory.csv.noValidRows`,`No valid rows`)})]})]})})}function Nn({open:e,onClose:t}){let{t:n}=c(),{showToast:i}=te(),a=l(),{data:s=[],isLoading:d,isError:f}=u({queryKey:Xe,queryFn:r.getSuppliers,enabled:e}),[p,m]=(0,J.useState)(``),[h,g]=(0,J.useState)(!1),[_,v]=(0,J.useState)(null),[y,b]=(0,J.useState)(``),[x,S]=(0,J.useState)(``),[C,T]=(0,J.useState)(``),[E,D]=(0,J.useState)(``),[O,ee]=(0,J.useState)(!1),[k,A]=(0,J.useState)(null);if((0,J.useEffect)(()=>{if(!e)return;let n=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,n),()=>window.removeEventListener(`keydown`,n)},[e,t]),!e)return null;let j=s.filter(e=>e.name.toLowerCase().includes(p.toLowerCase())),M=()=>{b(``),S(``),T(``),D(``)},N=()=>({name:y.trim(),website:x.trim()||null,customer_number:C.trim()||null,note:E.trim()||null}),P=async()=>{if(!y.trim()){i(n(`inventory.suppliers.nameRequired`),`error`);return}ee(!0);try{await r.createSupplier(N()),await He(a),g(!1),M(),i(n(`inventory.suppliers.added`),`success`)}catch(e){console.error(`SuppliersModal.handleAdd failed:`,e),i(n(e instanceof o&&e.status===409?`inventory.suppliers.duplicateName`:`inventory.suppliers.addFailed`),`error`)}finally{ee(!1)}},ne=e=>{v(e.id),b(e.name),S(e.website??``),T(e.customer_number??``),D(e.note??``)},I=()=>{v(null),M()},L=async e=>{if(!y.trim()){i(n(`inventory.suppliers.nameRequired`),`error`);return}ee(!0);try{await r.updateSupplier(e,N()),await He(a),I(),i(n(`inventory.suppliers.updated`),`success`)}catch(e){console.error(`SuppliersModal.handleUpdate failed:`,e),i(n(e instanceof o&&e.status===409?`inventory.suppliers.duplicateName`:`inventory.suppliers.updateFailed`),`error`)}finally{ee(!1)}},re=async()=>{if(k)try{await r.deleteSupplier(k.id),await He(a),i(n(`inventory.suppliers.deleted`),`success`)}catch(e){console.error(`SuppliersModal.handleDelete failed:`,e),e instanceof o&&e.status===409?i(n(`inventory.suppliers.deleteBlocked`,{count:k.spool_count}),`error`):i(n(`inventory.suppliers.deleteFailed`),`error`)}finally{A(null)}},R=(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(`input`,{type:`text`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`,placeholder:n(`inventory.suppliers.namePlaceholder`),value:y,maxLength:200,onChange:e=>b(e.target.value)}),(0,Y.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Y.jsx)(`input`,{type:`text`,className:`flex-1 min-w-0 px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`,placeholder:n(`inventory.suppliers.websitePlaceholder`),value:x,maxLength:500,onChange:e=>S(e.target.value)}),(0,Y.jsx)(`input`,{type:`text`,className:`w-40 px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`,placeholder:n(`inventory.suppliers.customerNumberPlaceholder`),value:C,maxLength:100,onChange:e=>T(e.target.value)})]}),(0,Y.jsx)(`input`,{type:`text`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`,placeholder:n(`inventory.suppliers.notePlaceholder`),value:E,maxLength:500,onChange:e=>D(e.target.value)})]});return(0,Y.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[(0,Y.jsx)(`div`,{className:`absolute inset-0 bg-black/60`,onClick:t}),(0,Y.jsxs)(`div`,{className:`relative w-full max-w-3xl 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":`suppliers-modal-title`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-4 px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(Ft,{className:`w-5 h-5 text-bambu-gray`}),(0,Y.jsx)(`h2`,{id:`suppliers-modal-title`,className:`text-lg font-semibold text-white`,children:n(`inventory.suppliers.title`)}),(0,Y.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[`(`,s.length,`)`]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsxs)(`button`,{onClick:()=>{g(!0),v(null),M()},className:`px-3 py-1.5 text-sm bg-bambu-green text-white rounded-lg hover:bg-bambu-green/80 transition-colors flex items-center gap-1.5`,children:[(0,Y.jsx)(Pe,{className:`w-4 h-4`}),(0,Y.jsx)(`span`,{className:`hidden sm:inline`,children:n(`common.add`)})]}),(0,Y.jsx)(`button`,{onClick:t,className:`p-1.5 rounded hover:bg-bambu-dark text-bambu-gray hover:text-white transition-colors`,"aria-label":n(`common.close`),children:(0,Y.jsx)(he,{className:`w-5 h-5`})})]})]}),(0,Y.jsxs)(`div`,{className:`flex-1 min-h-0 overflow-y-auto px-6 py-4 space-y-4`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`inventory.suppliers.description`)}),(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsx)(se,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,Y.jsx)(`input`,{type:`text`,className:`w-full pl-10 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`,placeholder:n(`inventory.suppliers.search`),value:p,onChange:e=>m(e.target.value)})]}),h&&(0,Y.jsxs)(`div`,{className:`p-4 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary space-y-3`,children:[(0,Y.jsx)(`h3`,{className:`text-sm font-medium text-white`,children:n(`inventory.suppliers.addNew`)}),R,(0,Y.jsxs)(`div`,{className:`flex gap-2 justify-end`,children:[(0,Y.jsx)(`button`,{onClick:()=>{g(!1),M()},className:`px-3 py-2 rounded-lg text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary`,children:n(`common.cancel`)}),(0,Y.jsxs)(`button`,{onClick:P,disabled:O,className:`px-3 py-2 bg-bambu-green text-white rounded-lg hover:bg-bambu-green/80 flex items-center gap-1`,children:[O?(0,Y.jsx)(F,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(w,{className:`w-4 h-4`}),n(`common.add`)]})]})]}),d?(0,Y.jsxs)(`div`,{className:`flex items-center justify-center py-8 text-bambu-gray`,children:[(0,Y.jsx)(F,{className:`w-5 h-5 animate-spin mr-2`}),n(`common.loading`)]}):f?(0,Y.jsxs)(`div`,{className:`flex items-center justify-center gap-2 py-8 text-sm text-red-400`,children:[(0,Y.jsx)(B,{className:`w-4 h-4`}),n(`inventory.suppliers.loadFailed`)]}):(0,Y.jsx)(`div`,{className:`border border-bambu-dark-tertiary rounded-lg`,children:(0,Y.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,Y.jsx)(`thead`,{className:`bg-bambu-dark sticky top-0`,children:(0,Y.jsxs)(`tr`,{children:[(0,Y.jsx)(`th`,{className:`px-4 py-2 text-left text-bambu-gray font-medium`,children:n(`common.name`)}),(0,Y.jsx)(`th`,{className:`px-4 py-2 text-left text-bambu-gray font-medium hidden sm:table-cell`,children:n(`inventory.suppliers.customerNumber`)}),(0,Y.jsx)(`th`,{className:`px-4 py-2 text-right text-bambu-gray font-medium w-20`,children:n(`inventory.suppliers.spools`)}),(0,Y.jsx)(`th`,{className:`px-4 py-2 w-24`})]})}),(0,Y.jsx)(`tbody`,{children:j.length===0?(0,Y.jsx)(`tr`,{children:(0,Y.jsx)(`td`,{colSpan:4,className:`px-4 py-8 text-center text-bambu-gray`,children:n(p?`inventory.suppliers.noMatch`:`inventory.suppliers.empty`)})}):j.map(e=>(0,Y.jsx)(`tr`,{className:`border-t border-bambu-dark-tertiary hover:bg-bambu-dark align-top`,children:_===e.id?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`td`,{className:`px-4 py-2`,colSpan:3,children:R}),(0,Y.jsx)(`td`,{className:`px-4 py-2`,children:(0,Y.jsxs)(`div`,{className:`flex justify-end gap-1`,children:[(0,Y.jsx)(`button`,{onClick:()=>L(e.id),disabled:O,className:`p-1.5 rounded hover:bg-green-500/20 text-green-500`,children:O?(0,Y.jsx)(F,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(w,{className:`w-4 h-4`})}),(0,Y.jsx)(`button`,{onClick:I,className:`p-1.5 rounded hover:bg-bambu-dark-tertiary text-bambu-gray`,children:(0,Y.jsx)(he,{className:`w-4 h-4`})})]})})]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`td`,{className:`px-4 py-2 text-white`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(`span`,{children:e.name}),e.website&&(0,Y.jsx)(`a`,{href:e.website,target:`_blank`,rel:`noopener noreferrer`,className:`text-bambu-gray hover:text-bambu-green`,title:e.website,children:(0,Y.jsx)(xe,{className:`w-3.5 h-3.5`})})]}),e.note&&(0,Y.jsx)(`div`,{className:`text-xs text-bambu-gray mt-0.5`,children:e.note})]}),(0,Y.jsx)(`td`,{className:`px-4 py-2 text-bambu-gray hidden sm:table-cell`,children:e.customer_number||`-`}),(0,Y.jsx)(`td`,{className:`px-4 py-2 text-right font-mono text-bambu-gray`,children:e.spool_count}),(0,Y.jsx)(`td`,{className:`px-4 py-2`,children:(0,Y.jsxs)(`div`,{className:`flex justify-end gap-1`,children:[(0,Y.jsx)(`button`,{onClick:()=>{ne(e),g(!1)},className:`p-1.5 rounded hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white`,children:(0,Y.jsx)(ye,{className:`w-4 h-4`})}),(0,Y.jsx)(`button`,{onClick:()=>A(e),className:`p-1.5 rounded bg-red-500/10 hover:bg-red-500/20 text-red-500`,children:(0,Y.jsx)(be,{className:`w-4 h-4`})})]})})]})},e.id))})]})})]})]}),k&&(0,Y.jsx)(Fe,{title:n(`inventory.suppliers.deleteTitle`),message:k.spool_count>0?n(`inventory.suppliers.deleteConfirmReferenced`,{name:k.name,count:k.spool_count}):n(`inventory.suppliers.deleteConfirm`,{name:k.name}),confirmText:n(`common.delete`),variant:`danger`,onConfirm:re,onCancel:()=>A(null)})]})}var Pn=[{id:`material`,type:`searchable`,labelKey:`inventory.material`},{id:`subtype`,type:`searchable`,labelKey:`inventory.subtype`},{id:`brand`,type:`searchable`,labelKey:`inventory.brand`},{id:`color_name`,type:`text`,labelKey:`inventory.colorName`},{id:`rgba`,type:`color`,labelKey:`inventory.color`,pattern:`^[0-9A-Fa-f]{6}([0-9A-Fa-f]{2})?$`},{id:`location_id`,type:`searchableClosed`,labelKey:`inventory.storageLocation`},{id:`slicer_filament_name`,type:`searchable`,labelKey:`inventory.slicerFilamentName`},{id:`slicer_filament`,type:`searchable`,labelKey:`inventory.slicerFilament`},{id:`cost_per_kg`,type:`number`,labelKey:`inventory.costPerKg`,min:0,step:.01},{id:`note`,type:`textarea`,labelKey:`inventory.note`},{id:`label_weight`,type:`number`,labelKey:`inventory.labelWeight`,min:1,step:1},{id:`core_weight`,type:`number`,labelKey:`inventory.coreWeight`,min:0,step:1},{id:`category`,type:`searchable`,labelKey:`inventory.category`,internalOnly:!0},{id:`low_stock_threshold_pct`,type:`number`,labelKey:`inventory.lowStockThresholdOverride`,min:1,max:99,step:1,internalOnly:!0},{id:`material_number`,type:`searchable`,labelKey:`inventory.materialNumber`,internalOnly:!0}];function Fn({value:e,onChange:t,options:n,allowCustom:r,placeholderKey:i,disabled:a}){let{t:o}=c(),s=(0,J.useRef)(null),[l,u]=(0,J.useState)(!1),[d,f]=(0,J.useState)(``);(0,J.useEffect)(()=>{if(!l)return;let e=e=>{s.current&&!s.current.contains(e.target)&&(u(!1),f(``))},t=e=>{e.key===`Escape`&&(u(!1),f(``))};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[l]);let p=l?d:n.find(t=>t.value===e)?.label??e,m=(0,J.useMemo)(()=>{if(!l)return n;let e=d.trim().toLowerCase();return e?n.filter(t=>t.label.toLowerCase().includes(e)||t.value.toLowerCase().includes(e)):n},[l,d,n]),h=l&&d.trim()&&!n.some(e=>e.value.toLowerCase()===d.trim().toLowerCase());return(0,Y.jsxs)(`div`,{className:`relative`,ref:s,children:[(0,Y.jsx)(`input`,{type:`text`,disabled:a,value:p,onChange:e=>{f(e.target.value),u(!0),r&&t(e.target.value)},onFocus:()=>{u(!0),f(``)},placeholder:i?o(i):void 0,className:`w-full px-3 py-2 pr-9 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray/50 focus:border-bambu-green focus:outline-none`}),(0,Y.jsx)(T,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50 pointer-events-none`}),l&&(0,Y.jsxs)(`div`,{className:`absolute z-50 left-0 right-0 mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-64 overflow-y-auto`,children:[m.length===0&&!r&&(0,Y.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:o(`inventory.noResults`)}),m.map(n=>(0,Y.jsx)(`button`,{type:`button`,className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${e===n.value?`bg-bambu-green/10 text-bambu-green`:`text-white`}`,onClick:()=>{t(n.value),u(!1),f(``)},children:n.label},n.value)),r&&h&&(0,Y.jsx)(`button`,{type:`button`,className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary text-bambu-green border-t border-bambu-dark-tertiary`,onClick:()=>{t(d.trim()),u(!1),f(``)},children:o(`inventory.bulk.useCustom`,{value:d.trim()})})]})]})}function In(...e){let t=new Set;for(let n of e)for(let e of n){let n=e?.trim();n&&t.add(n)}return Array.from(t).sort((e,t)=>e.localeCompare(t))}function Ln({isOpen:e,selectedCount:t,isPending:n,availableLocations:i,availableMaterials:a,availableSubtypes:o,availableBrands:s,availableCategories:l,availableMaterialNumbers:d,availableSlicerFilaments:f,availableSlicerFilamentNames:p,spoolmanMode:m=!1,onClose:h,onApply:g}){let{t:_}=c(),v=(0,J.useMemo)(()=>Pn.filter(e=>!(m&&e.internalOnly)),[m]),{data:y=[]}=u({queryKey:[`bulk-edit-cloud-presets`],enabled:e,staleTime:300*1e3,queryFn:async()=>{let e=[];try{if((await r.getCloudStatus()).is_authenticated){let t=await r.getFilamentPresets();e.push(...t)}}catch{}try{if((await r.orcaCloudStatus()).connected){let t=await r.orcaCloudListProfiles();e.push(...t.filament)}}catch{}return e}}),{data:b}=u({queryKey:[`bulk-edit-local-presets`],enabled:e,staleTime:300*1e3,queryFn:r.getLocalPresets}),{data:x=[]}=u({queryKey:[`builtin-filaments`],enabled:e,staleTime:300*1e3,queryFn:r.getBuiltinFilaments}),S=(0,J.useMemo)(()=>Et(y,new Set,b?.filament??[],x),[y,b,x]),[C,w]=(0,J.useState)({}),T=(0,J.useMemo)(()=>In(Ot,a).map(e=>({value:e,label:e})),[a]),E=(0,J.useMemo)(()=>In(pt,o).map(e=>({value:e,label:e})),[o]),D=(0,J.useMemo)(()=>In(vt,s).map(e=>({value:e,label:e})),[s]),O=(0,J.useMemo)(()=>In(l).map(e=>({value:e,label:e})),[l]),ee=(0,J.useMemo)(()=>In(d).map(e=>({value:e,label:e})),[d]),k=(0,J.useMemo)(()=>{let e=S.map(e=>({value:e.code,label:e.displayName})),t=f.filter(t=>!e.some(e=>e.value===t)).map(e=>({value:e,label:e}));return[...e,...t].sort((e,t)=>e.label.localeCompare(t.label))},[S,f]),te=(0,J.useMemo)(()=>{let e=S.map(e=>({value:e.displayName,label:e.displayName})),t=p.filter(t=>!e.some(e=>e.value===t)).map(e=>({value:e,label:e}));return[...e,...t].sort((e,t)=>e.label.localeCompare(t.label))},[S,p]),A=(0,J.useMemo)(()=>i.map(e=>({value:String(e.id),label:e.name})),[i]);if(!e)return null;let j=(e,t)=>{w(n=>({...n,[e]:t}))},M=e=>{w(t=>{let n={...t};return delete n[e],n})},N=(()=>{let e={};for(let t of v){let n=C[t.id];if(n===void 0)continue;let r=typeof n==`string`?n.trim():n;if(!(r===``||r===null))if(t.type===`number`){let n=Number(r);Number.isFinite(n)&&(e[t.id]=n)}else if(t.id===`location_id`){let n=Number(r);Number.isFinite(n)&&n>0&&(e[t.id]=n)}else if(t.id===`rgba`){let n=String(r).replace(/^#/,``),i=n.length===6?`${n}FF`:n;/^[0-9A-Fa-f]{8}$/.test(i)&&(e[t.id]=i.toUpperCase())}else e[t.id]=String(r)}return e})(),P=Object.keys(N).length>0,ne=v.some(e=>{let t=C[e.id];return t===void 0||t.trim()===``?!1:N[e.id]===void 0}),I=e=>e===`material`?T:e===`subtype`?E:e===`brand`?D:e===`category`?O:e===`material_number`?ee:e===`slicer_filament`?k:e===`slicer_filament_name`?te:e===`location_id`?A:[],L=e=>{let t=C[e.id]??``;if(e.type===`searchable`||e.type===`searchableClosed`)return(0,Y.jsx)(Fn,{value:t,onChange:t=>{t===``?M(e.id):j(e.id,t)},options:I(e.id),allowCustom:e.type===`searchable`,disabled:n});if(e.type===`textarea`)return(0,Y.jsx)(`textarea`,{disabled:n,value:t,onChange:t=>j(e.id,t.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray/50 focus:border-bambu-green focus:outline-none resize-none min-h-[60px]`});if(e.type===`color`){let r=t.trim().replace(/^#/,``),i=r.length===6?`${r}FF`:r,a=t.trim()!==``&&!/^[0-9A-Fa-f]{8}$/.test(i);return(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`input`,{type:`color`,disabled:n,value:`#${(t||`808080`).replace(/^#/,``).slice(0,6)}`,onChange:t=>j(e.id,t.target.value.replace(/^#/,``).toUpperCase()),className:`h-9 w-12 rounded cursor-pointer`}),(0,Y.jsx)(`input`,{type:`text`,disabled:n,value:t,onChange:t=>j(e.id,t.target.value.replace(/^#/,``).toUpperCase()),placeholder:`RRGGBB or RRGGBBAA`,className:`flex-1 px-3 py-2 bg-bambu-dark border rounded-lg text-white placeholder-bambu-gray/50 focus:outline-none ${a?`border-red-500 focus:border-red-500`:`border-bambu-dark-tertiary focus:border-bambu-green`}`,pattern:e.pattern})]}),a&&(0,Y.jsx)(`p`,{className:`mt-1 text-xs text-red-600 dark:text-red-400`,children:_(`inventory.bulk.invalidHex`)})]})}return(0,Y.jsx)(`input`,{type:e.type===`number`?`number`:`text`,disabled:n,value:t,onChange:t=>j(e.id,t.target.value),min:e.min,max:e.max,step:e.step,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray/50 focus:border-bambu-green focus:outline-none`})};return(0,Y.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center p-4 z-50`,onClick:n?void 0:h,children:(0,Y.jsxs)(`div`,{className:`w-full max-w-3xl bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg max-h-[90vh] flex flex-col`,onClick:e=>e.stopPropagation(),children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between p-5 border-b border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:_(`inventory.bulk.editTitle`)}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray mt-0.5`,children:_(`inventory.bulk.editSubtitle`,{count:t})})]}),(0,Y.jsx)(`button`,{onClick:h,disabled:n,className:`p-1 text-bambu-gray hover:text-white transition-colors`,"aria-label":_(`common.close`),children:(0,Y.jsx)(he,{className:`w-5 h-5`})})]}),(0,Y.jsx)(`p`,{className:`px-5 pt-4 text-xs text-bambu-gray`,children:_(`inventory.bulk.editHint`)}),(0,Y.jsx)(`div`,{className:`flex-1 overflow-y-auto p-5 space-y-3`,children:v.map(e=>{let t=C[e.id]!==void 0;return(0,Y.jsxs)(`div`,{className:`flex items-start gap-3 rounded-md p-2 transition-colors ${t?`bg-bambu-green/5 border border-bambu-green/30`:`border border-transparent`}`,children:[(0,Y.jsx)(`div`,{className:`pt-2`,children:(0,Y.jsx)(`input`,{type:`checkbox`,className:`h-4 w-4 cursor-pointer`,checked:t,onChange:t=>{t.target.checked?j(e.id,``):M(e.id)},"aria-label":_(`inventory.bulk.toggleField`)})}),(0,Y.jsxs)(`div`,{className:`flex-1`,children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:_(e.labelKey)}),L(e)]})]},e.id)})}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-3 p-5 border-t border-bambu-dark-tertiary`,children:[(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:_(`inventory.bulk.changeCount`,{count:Object.keys(N).length})}),(0,Y.jsxs)(`div`,{className:`ml-auto flex gap-2`,children:[(0,Y.jsx)(V,{variant:`secondary`,onClick:h,disabled:n,children:_(`common.cancel`)}),(0,Y.jsx)(V,{onClick:()=>g(N),disabled:!P||n||ne,children:n?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(F,{className:`w-4 h-4 mr-2 animate-spin`}),_(`inventory.bulk.applyPending`)]}):_(`inventory.bulk.applyButton`,{count:t})})]})]})]})})}function Rn(e){let t=e[0],n=0,r=0,i=0;for(let t of e)n+=t.label_weight,r+=t.weight_used,i+=t.core_weight;return{...t,label_weight:n,weight_used:r,core_weight:i}}function zn(e){let t=new Set;for(let n of e)if(typeof n==`string`){let e=n.trim();e&&t.add(e)}return Array.from(t).sort((e,t)=>e.localeCompare(t))}function Bn(e){return`${e.material}|${e.subtype||``}|${e.brand||``}|${e.color_name||``}|${e.rgba||``}|${e.extra_colors||``}|${e.effect_type||``}|${e.label_weight}|${e.last_dried_at||``}`}var Vn=`bambuddy-inventory-columns`,Hn=`none`.padStart(65,`_`);function Un(e){return(e||``).toLowerCase().replace(/\d+/g,e=>e.padStart(64,`0`))}var Wn=[{id:`id`,label:`#`,visible:!0},{id:`added_time`,label:`Added`,visible:!0},{id:`encode_time`,label:`Encoded`,visible:!1},{id:`last_used_time`,label:`Last Used`,visible:!1},{id:`rgba`,label:`Color`,visible:!0},{id:`material`,label:`Material`,visible:!0},{id:`subtype`,label:`Subtype`,visible:!0},{id:`color_name`,label:`Color Name`,visible:!1},{id:`brand`,label:`Brand`,visible:!0},{id:`slicer_filament`,label:`Slicer Filament`,visible:!1},{id:`location`,label:`Location`,visible:!0},{id:`storage_location`,label:`Storage Location`,visible:!1},{id:`temperature`,label:`Temperature`,visible:!1},{id:`humidity`,label:`Humidity`,visible:!1},{id:`last_dried`,label:`Last Dried`,visible:!0},{id:`battery`,label:`Battery`,visible:!1},{id:`label_weight`,label:`Label`,visible:!0},{id:`net`,label:`Net`,visible:!0},{id:`gross`,label:`Gross`,visible:!1},{id:`added_full`,label:`Full`,visible:!1},{id:`used`,label:`Used`,visible:!1},{id:`printed_total`,label:`Printed Total`,visible:!1},{id:`printed_since_weight`,label:`Printed Since Weight`,visible:!1},{id:`note`,label:`Note`,visible:!1},{id:`material_number`,label:`Material No.`,visible:!1},{id:`suppliers`,label:`Suppliers`,visible:!1},{id:`pa_k`,label:`PA(K)`,visible:!0},{id:`tag_id`,label:`Tag ID`,visible:!1},{id:`data_origin`,label:`Data Origin`,visible:!1},{id:`tag_type`,label:`Linked Tag Type`,visible:!1},{id:`stock`,label:`Stock`,visible:!1},{id:`remaining`,label:`Remaining`,visible:!0},{id:`spool_name`,label:`Spool`,visible:!1},{id:`cost_per_kg`,label:`Cost/kg`,visible:!1},{id:`weight_check`,label:`Weight Check`,visible:!1}];function Gn(){try{let e=localStorage.getItem(Vn);if(e){let t=JSON.parse(e),n=new Set(Wn.map(e=>e.id)),r=new Set(t.map(e=>e.id)),i=[...t.filter(e=>n.has(e.id))];for(let e of Wn){if(r.has(e.id))continue;let t=Wn.indexOf(e),n=i.length;for(let e=t-1;e>=0;e--){let t=i.findIndex(t=>t.id===Wn[e].id);if(t!==-1){n=t+1;break}}i.splice(n,0,e)}return i}}catch{}return Wn.map(e=>({...e}))}function Kn(e){try{localStorage.setItem(Vn,JSON.stringify(e))}catch{}}function qn(e,t=!1){return t&&e>=1e3?`${(e/1e3).toFixed(1)}kg`:`${Math.round(e)}g`}var Jn={PLA:`bg-green-100 dark:bg-green-500/20 text-green-700 dark:text-green-400`,ABS:`bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400`,PETG:`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`,TPU:`bg-purple-100 dark:bg-purple-500/20 text-purple-700 dark:text-purple-400`,ASA:`bg-orange-100 dark:bg-orange-500/20 text-orange-700 dark:text-orange-400`,PA:`bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400`,PC:`bg-cyan-100 dark:bg-cyan-500/20 text-cyan-700 dark:text-cyan-400`,PET:`bg-sky-100 dark:bg-sky-500/20 text-sky-700 dark:text-sky-400`};function Yn(e){let t=[];return e.last_dried_temp!=null&&t.push(`${e.last_dried_temp}°C`),e.last_dried_hours!=null&&t.push(`${Number(e.last_dried_hours.toFixed(1))}h`),t.join(` · `)}function Xn(e,t=`system`){if(!e)return`-`;let n=H(e);return n?ge(n,t):`-`}var Zn={id:()=>`#`,added_time:()=>`Added`,encode_time:()=>`Encoded`,last_used_time:()=>`Last Used`,rgba:e=>e(`inventory.color`),material:e=>e(`inventory.material`),subtype:e=>e(`inventory.subtype`),color_name:e=>e(`inventory.colorName`),brand:e=>e(`inventory.brand`),slicer_filament:e=>e(`inventory.slicerFilament`),location:()=>`Location`,storage_location:e=>e(`inventory.storageLocation`),temperature:e=>e(`inventory.temperature`),humidity:e=>e(`inventory.humidity`),last_dried:e=>e(`inventory.lastDried`),battery:e=>e(`inventory.battery`),label_weight:e=>e(`inventory.labelWeight`),net:e=>e(`inventory.net`),gross:()=>`Gross`,added_full:()=>`Full`,used:e=>e(`inventory.weightUsed`),printed_total:()=>`Printed Total`,printed_since_weight:()=>`Printed Since Weight`,note:e=>e(`inventory.note`),material_number:e=>e(`inventory.materialNumber`),suppliers:e=>e(`inventory.suppliers.label`),pa_k:()=>`PA(K)`,tag_id:()=>`Tag ID`,data_origin:()=>`Data Origin`,tag_type:()=>`Linked Tag Type`,stock:e=>e(`inventory.stock`),remaining:e=>e(`inventory.remaining`),spool_name:e=>e(`inventory.spoolName`),cost_per_kg:e=>e(`inventory.costPerKg`),weight_check:e=>e(`inventory.weightCheck`)},Qn={id:({spool:e})=>(0,Y.jsx)(`span`,{className:`text-sm font-medium text-white`,children:e.id}),added_time:({spool:e,dateFormat:t})=>(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:Xn(e.created_at,t)}),encode_time:({spool:e,dateFormat:t})=>(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:Xn(e.encode_time,t)}),last_used_time:({spool:e,dateFormat:t})=>(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.last_used?Xn(e.last_used,t):`Never`}),last_dried:({spool:e,dateFormat:t})=>{if(!e.last_dried_at)return(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:`-`});let n=Yn(e);return(0,Y.jsxs)(`div`,{className:`text-sm text-bambu-gray`,children:[(0,Y.jsx)(`div`,{children:Xn(e.last_dried_at,t)}),n&&(0,Y.jsx)(`div`,{className:`text-xs text-bambu-gray/60`,children:n})]})},rgba:({spool:e})=>(0,Y.jsx)(`div`,{className:`flex items-center justify-center`,children:(0,Y.jsx)(Ze,{rgba:e.rgba,extraColors:e.extra_colors,effectType:e.effect_type,effectSize:`table`,subtype:e.subtype})}),material:({spool:e})=>(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:e.material}),subtype:({spool:e})=>(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.subtype||`-`}),color_name:({spool:e})=>(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:Ve(e.color_name,e.rgba,e.color_name_is_synthesized)||`-`}),brand:({spool:e})=>(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.brand||`-`}),slicer_filament:({spool:e})=>(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,title:e.slicer_filament||void 0,children:e.slicer_filament_name||e.slicer_filament||`-`}),location:({spool:e,assignmentMap:t})=>{let n=t[e.id];if(!n)return(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:`-`});let r=n.printer_name||`Printer ${n.printer_id}`,i=n.ams_id===254||n.ams_id===255,a=!i&&n.ams_id>=128;return(0,Y.jsxs)(`span`,{className:`inline-flex items-center px-1.5 py-0.5 rounded text-xs font-medium bg-purple-100 dark:bg-purple-500/20 text-purple-700 dark:text-purple-400`,children:[r,` `,Ce(n.ams_id,n.tray_id,a,i),n.ams_label?` (${n.ams_label})`:``]})},storage_location:({spool:e})=>e.storage_location?(0,Y.jsx)(`span`,{className:`inline-flex items-center px-1.5 py-0.5 rounded text-xs font-medium bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`,children:e.storage_location}):(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:`-`}),temperature:({spool:e,locationReadingsMap:t,t:n,colorizeLocationSensors:r,locationSensorAboveColor:i,locationSensorBelowColor:a,locationSensorOptimalColor:o})=>{let s=e.location_id?t[e.location_id]?.find(e=>e.device_class===`temperature`):void 0;return s?(0,Y.jsx)(`span`,{title:s.name,className:`text-sm ${ur(s,r,i,a,o)}`,children:lr(s,n)}):(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray/50`,children:`-`})},humidity:({spool:e,locationReadingsMap:t,t:n,colorizeLocationSensors:r,locationSensorAboveColor:i,locationSensorBelowColor:a,locationSensorOptimalColor:o})=>{let s=e.location_id?t[e.location_id]?.find(e=>e.device_class===`humidity`):void 0;return s?(0,Y.jsx)(`span`,{title:s.name,className:`text-sm ${ur(s,r,i,a,o)}`,children:lr(s,n)}):(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray/50`,children:`-`})},battery:({spool:e,locationReadingsMap:t,t:n,colorizeLocationSensors:r,locationSensorAboveColor:i,locationSensorBelowColor:a,locationSensorOptimalColor:o})=>{let s=e.location_id?t[e.location_id]?.find(e=>e.device_class===`battery`):void 0;return s?(0,Y.jsx)(`span`,{title:s.name,className:`text-sm ${ur(s,r,i,a,o)}`,children:lr(s,n)}):(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray/50`,children:`-`})},label_weight:({spool:e})=>(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:qn(e.label_weight)}),net:({remaining:e})=>(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:qn(e)}),gross:({spool:e,remaining:t})=>(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:qn(t+e.core_weight)}),added_full:({spool:e})=>(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.added_full==null?`-`:e.added_full?`Yes`:`No`}),used:({spool:e})=>(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.weight_used>0?qn(e.weight_used):`-`}),printed_total:()=>(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray/50`,children:`-`}),printed_since_weight:()=>(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray/50`,children:`-`}),note:({spool:e})=>(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray max-w-[150px] truncate block`,title:e.note||void 0,children:e.note||`-`}),material_number:({spool:e})=>(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.material_number||`-`}),suppliers:({spool:e})=>{let t=e.suppliers??[];return t.length===0?(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:`-`}):(0,Y.jsx)(`div`,{className:`flex flex-wrap gap-1 max-w-[220px]`,children:[...t].sort((e,t)=>Number(t.is_purchase_source)-Number(e.is_purchase_source)).map(e=>(0,Y.jsx)(`span`,{title:e.supplier_article_number||void 0,className:`inline-flex items-center px-1.5 py-0.5 rounded-full text-[10px] font-medium ${e.is_purchase_source?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-gray/10 text-bambu-gray`}`,children:e.supplier_name},e.id))})},pa_k:({spool:e})=>(e.k_profiles?.length??0)===0?(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:`-`}):(0,Y.jsx)(`span`,{className:`inline-flex items-center px-1.5 py-0.5 rounded text-xs font-medium bg-bambu-green/20 text-bambu-green`,children:`K`}),tag_id:({spool:e})=>{let t=e.tag_uid||e.tray_uuid;return t?(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray font-mono`,title:t,children:t.length>12?`${t.slice(0,6)}...${t.slice(-4)}`:t}):(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray/50`,children:`-`})},data_origin:({spool:e})=>(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.data_origin||`-`}),tag_type:({spool:e})=>(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.tag_type||`-`}),stock:({spool:e,t})=>e.slicer_filament?(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:`-`}):(0,Y.jsx)(`span`,{className:`inline-flex items-center px-1.5 py-0.5 rounded text-xs font-medium bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400`,children:t(`inventory.stock`)}),remaining:({remaining:e,pct:t})=>(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`div`,{className:`flex-1 h-2 bg-bambu-dark-tertiary rounded-full overflow-hidden`,children:(0,Y.jsx)(`div`,{className:`h-full rounded-full ${t>50?`bg-bambu-green`:t>20?`bg-yellow-500`:`bg-red-500`}`,style:{width:`${Math.min(t,100)}%`}})}),(0,Y.jsxs)(`span`,{className:`text-xs text-bambu-gray min-w-[40px] text-right`,children:[Math.round(e),`g`]})]}),spool_name:({spool:e,catalogMap:t})=>(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:(e.core_weight_catalog_id==null?void 0:t[e.core_weight_catalog_id])?.name||`-`}),cost_per_kg:({spool:e,currencySymbol:t})=>(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.cost_per_kg==null?`-`:`${t}${e.cost_per_kg.toFixed(2)}`}),weight_check:({spool:e,onSyncWeight:t})=>{let n=e.last_scale_weight;if(n==null)return(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray/50`,title:`No scale measurement`,children:`-`});let r=e.core_weight||0,i=Math.max(0,e.label_weight-e.weight_used)+r,a,o;n0?`+${Math.round(a)}`:`${Math.round(a)}`,c=o?`Scale: ${Math.round(n)}g\nCalculated: ${Math.round(i)}g\nDifference: ${s}g (within tolerance)`:`Scale: ${Math.round(n)}g\nCalculated: ${Math.round(i)}g\nDifference: ${s}g (mismatch!)`;return(0,Y.jsxs)(`div`,{className:`flex items-center gap-1 text-sm font-medium ${o?`text-green-700 dark:text-green-400`:`text-yellow-700 dark:text-yellow-400`}`,title:c,children:[(0,Y.jsxs)(`span`,{children:[Math.round(n),`g`]}),o?(0,Y.jsx)(w,{className:`w-3 h-3`}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(B,{className:`w-3 h-3`}),t&&(0,Y.jsx)(`button`,{type:`button`,onClick:n=>{n.stopPropagation(),n.preventDefault(),t(e)},className:`p-1 hover:bg-bambu-green/20 rounded transition-colors text-bambu-green`,title:`Sync: trust scale weight and reset tracking`,children:(0,Y.jsx)(we,{className:`w-3.5 h-3.5`})})]})]})}},$n={id:e=>e.id,added_time:e=>e.created_at||``,encode_time:e=>e.encode_time||``,last_used_time:e=>e.last_used||``,last_dried:e=>e.last_dried_at||``,material:e=>(e.material||``).toLowerCase(),subtype:e=>(e.subtype||``).toLowerCase(),color_name:e=>(e.color_name||``).toLowerCase(),rgba:e=>W(e.rgba),brand:e=>(e.brand||``).toLowerCase(),slicer_filament:e=>(e.slicer_filament_name||e.slicer_filament||``).toLowerCase(),location:(e,t)=>{let n=t[e.id];if(!n)return``;let r=n.ams_id===254||n.ams_id===255,i=!r&&n.ams_id>=128,a=n.ams_label?` (${n.ams_label})`:``;return`${n.printer_name||``} ${Ce(n.ams_id,n.tray_id,i,r)}${a}`},storage_location:e=>(e.storage_location||``).toLowerCase(),label_weight:e=>e.label_weight,net:e=>Math.max(0,e.label_weight-e.weight_used),gross:e=>Math.max(0,e.label_weight-e.weight_used)+e.core_weight,used:e=>e.weight_used,remaining:e=>e.label_weight>0?Math.max(0,e.label_weight-e.weight_used)/e.label_weight:0,note:e=>(e.note||``).toLowerCase(),material_number:e=>Un(e.material_number),suppliers:e=>{let t=e.suppliers??[];return((t.find(e=>e.is_purchase_source)??t[0])?.supplier_name||``).toLowerCase()},data_origin:e=>(e.data_origin||``).toLowerCase(),tag_type:e=>(e.tag_type||``).toLowerCase(),stock:e=>+!!e.slicer_filament,spool_name:e=>e.core_weight_catalog_id??0,cost_per_kg:e=>e.cost_per_kg??0,weight_check:e=>{if(e.last_scale_weight==null)return-1;let t=Math.max(0,e.label_weight-e.weight_used)+e.core_weight;return Math.abs(e.last_scale_weight-t)},temperature:(e,t,n)=>(e.location_id?n[e.location_id]:void 0)?.find(e=>e.device_class===`temperature`)?.value??-1/0,humidity:(e,t,n)=>(e.location_id?n[e.location_id]:void 0)?.find(e=>e.device_class===`humidity`)?.value??-1/0,battery:(e,t,n)=>(e.location_id?n[e.location_id]:void 0)?.find(e=>e.device_class===`battery`)?.value??-1/0},er=`bambuddy-inventory-sort`;function tr(){try{let e=localStorage.getItem(er);if(e)return JSON.parse(e)}catch{}return null}function nr(e){try{e?localStorage.setItem(er,JSON.stringify(e)):localStorage.removeItem(er)}catch{}}function rr(){let{data:e}=u({queryKey:[`spoolman-settings`],queryFn:r.getSpoolmanSettings,staleTime:300*1e3}),t=e!==void 0;return(0,Y.jsx)(ir,{spoolmanMode:e?.spoolman_enabled===`true`&&!!e?.spoolman_url,spoolmanModeReady:t})}function ir({spoolmanMode:e=!1,spoolmanModeReady:t=!0}){let{t:n}=c(),i=Je(),a=l(),{showToast:p}=te(),{hasPermission:h,loading:g}=et(),b=!g&&h(`inventory:forecast_read`),[x,C]=Ne(),[w,E]=(0,J.useState)(null),D=(0,J.useRef)(!1),[O,A]=(0,J.useState)(null),[M,P]=(0,J.useState)(null),[L,ie]=(0,J.useState)(!1),[z,ce]=(0,J.useState)(!1),[ue,de]=(0,J.useState)(!1),[fe,pe]=(0,J.useState)(!1),[me,ge]=(0,J.useState)(`active`),[H,_e]=(0,J.useState)(`all`),[ye,xe]=(0,J.useState)(``),[Ce,we]=(0,J.useState)(``),[Ee,ke]=(0,J.useState)(``),[Ae,je]=(0,J.useState)(``),[Me,Re]=(0,J.useState)(``),[Be,He]=(0,J.useState)(``),[We,Ke]=(0,J.useState)(`all`),[Ye,Xe]=(0,J.useState)(``),[W,Ze]=(0,J.useState)(`table`),[$e,tt]=(0,J.useState)(tr),[nt,rt]=(0,J.useState)(Gn),[at,ot]=(0,J.useState)(!1),[st,ct]=(0,J.useState)(()=>{try{return localStorage.getItem(`bambuddy-inventory-group`)===`true`}catch{return!1}}),[lt,ut]=(0,J.useState)(new Set),[G,dt]=(0,J.useState)(new Set),[ft,pt]=(0,J.useState)(!1),[K,mt]=(0,J.useState)(null),ht=(0,J.useCallback)(e=>{dt(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),gt=(0,J.useCallback)(()=>dt(new Set),[]);(0,J.useEffect)(()=>{dt(new Set)},[me,H,ye,Ce,Ee,Ae,Me,Be,We,Ye]);let[_t,vt]=(0,J.useState)(0),[yt,bt]=(0,J.useState)(()=>{try{let e=localStorage.getItem(`bambuddy-inventory-pageSize`);if(e){let t=Number(e);if([15,30,50,100,-1].includes(t))return t}}catch{}return 15}),{data:xt}=u({queryKey:[`settings`],queryFn:r.getSettings}),St=xt?.date_format||`system`,Ct=(xt?.location_sensor_poll_interval||120)*1e3,{colorize:wt,aboveColor:Tt,belowColor:Et,optimalColor:Dt}=R(),Ot=e?[`spoolman-inventory-spools`]:[`inventory-spools`],kt=()=>Ie(a,Ot),{data:q,isLoading:jt}=u({queryKey:Ot,queryFn:()=>e?r.getSpoolmanInventorySpools(!0):r.getSpools(!0),refetchInterval:3e4}),Mt=(0,J.useCallback)(async()=>{ce(!0);try{await r.exportSpoolsCsv()}catch(e){p(e instanceof Error?e.message:n(`inventory.csv.exportError`,`Export failed`),`error`)}finally{ce(!1)}},[p,n]),Pt=e?n(`inventory.csv.spoolmanHint`,`In Spoolman mode, use Spoolman's built-in CSV import/export.`):void 0,{data:Lt=[]}=u({queryKey:qe,queryFn:r.getLocations}),Rt=x.get(`location_id`),X=Rt===`__none__`?`__none__`:Rt&&/^\d+$/.test(Rt)&&Number(Rt)>0?Rt:``,Z=x.get(`spool`),zt=Z&&/^\d+$/.test(Z)&&Number(Z)>0?Number(Z):null,Bt=q?.find(e=>e.id===zt)??null,Vt=(0,J.useCallback)(()=>{D.current=!0,C(e=>(e.delete(`spool`),e),{replace:!0})},[C]),{data:Ht,isError:Ut,error:Gt}=u({queryKey:e?[`spoolman-inventory-spool`,zt]:[`inventory-spool`,zt],queryFn:()=>e?r.getSpoolmanInventorySpool(zt):r.getSpool(zt),enabled:t&&zt!==null&&Bt===null,staleTime:1/0,retry:(e,t)=>e<2&&!(t instanceof o&&t.status===404)});(0,J.useEffect)(()=>{if(!D.current){if(t&&zt&&Bt){Vt(),E({spool:Bt,mode:`edit`});return}if(Ht){Vt(),E({spool:Ht,mode:`edit`});return}Ut&&(Vt(),p(n(Gt instanceof o&&Gt.status===404?`inventory.deepLinkSpoolNotFound`:`inventory.deepLinkFetchFailed`),`error`))}},[t,zt,Bt,Ht,Ut,Gt,Vt,p,n]);let{data:Kt}=u({queryKey:[`spool-assignments`],queryFn:()=>r.getAssignments(),refetchInterval:3e4}),{data:qt=[],isError:Jt}=u({queryKey:[`spoolman-slot-assignments-all`],queryFn:()=>r.getSpoolmanSlotAssignments(),enabled:e,refetchInterval:3e4,staleTime:1e4,retry:1}),Yt=(0,J.useRef)(!1);(0,J.useEffect)(()=>{Jt&&!Yt.current?(Yt.current=!0,p(n(`inventory.spoolmanUnreachable`),`error`)):Jt||(Yt.current=!1)},[Jt,p,n]);let{data:Xt}=u({queryKey:[`spool-catalog`],queryFn:()=>r.getSpoolCatalog()}),Zt=d({mutationFn:t=>e?r.deleteSpoolmanInventorySpool(t):r.deleteSpool(t),onSuccess:()=>{kt(),p(n(`inventory.spoolDeleted`),`success`)},onError:e=>{e instanceof o&&e.status===404?p(n(`inventory.deleteSpoolNotFound`),`error`):e instanceof o&&e.status===503?p(n(`inventory.spoolmanUnreachable`),`error`):p(n(`inventory.deleteFailed`),`error`)}}),Qt=d({mutationFn:t=>e?r.archiveSpoolmanInventorySpool(t):r.archiveSpool(t),onSuccess:()=>{kt(),p(n(`inventory.spoolArchived`),`success`)},onError:e=>{e instanceof o&&e.status===404?p(n(`inventory.archiveSpoolNotFound`),`error`):e instanceof o&&e.status===503?p(n(`inventory.spoolmanUnreachable`),`error`):p(n(`inventory.archiveFailed`),`error`)}}),$t=d({mutationFn:t=>e?r.restoreSpoolmanInventorySpool(t):r.restoreSpool(t),onSuccess:()=>{kt(),p(n(`inventory.spoolRestored`),`success`)},onError:e=>{e instanceof o&&e.status===404?p(n(`inventory.restoreSpoolNotFound`),`error`):e instanceof o&&e.status===503?p(n(`inventory.spoolmanUnreachable`),`error`):p(n(`inventory.restoreFailed`),`error`)}}),en=d({mutationFn:t=>e?r.resetSpoolmanInventorySpoolConsumedCounter(t):r.resetSpoolConsumedCounter(t),onSuccess:()=>{a.invalidateQueries({queryKey:Ot}),p(n(`inventory.consumedCounterReset`),`success`)},onError:()=>{p(n(`inventory.resetConsumedCounterFailed`),`error`)}}),tn=d({mutationFn:t=>e?r.bulkResetSpoolmanInventorySpoolConsumedCounter(t):r.bulkResetSpoolConsumedCounter(t),onSuccess:e=>{a.invalidateQueries({queryKey:Ot}),p(n(`inventory.allConsumedCountersReset`,{count:e.reset}),`success`),mt(null),gt()},onError:()=>{p(n(`inventory.resetConsumedCounterFailed`),`error`)}}),nn=e=>(e.not_found?.length??0)+(e.errors?.length??0),rn=d({mutationFn:async({ids:t,update:n})=>e?r.bulkUpdateSpoolmanInventorySpools(t,n):r.bulkUpdateSpools(t,n),onSuccess:e=>{kt();let t=nn(e);if(e.updated===0){p(n(`inventory.bulk.updateAllFailed`,{count:t}),`error`);return}t>0?p(n(`inventory.bulk.updatePartial`,{ok:e.updated,failed:t}),`warning`):p(n(`inventory.bulk.updateSuccess`,{count:e.updated}),`success`),pt(!1),gt()},onError:e=>{p(e.message||n(`inventory.bulk.updateFailed`),`error`)}}),an=d({mutationFn:async t=>e?r.bulkDeleteSpoolmanInventorySpools(t):r.bulkDeleteSpools(t),onSuccess:e=>{kt();let t=nn(e);if(e.deleted===0){p(n(`inventory.bulk.deleteAllFailed`,{count:t}),`error`);return}t>0?p(n(`inventory.bulk.deletePartial`,{ok:e.deleted,failed:t}),`warning`):p(n(`inventory.bulk.deleteSuccess`,{count:e.deleted}),`success`),mt(null),gt()},onError:e=>{p(e.message||n(`inventory.bulk.deleteFailed`),`error`)}}),on=d({mutationFn:async t=>e?r.bulkArchiveSpoolmanInventorySpools(t):r.bulkArchiveSpools(t),onSuccess:e=>{kt();let t=nn(e);if(e.archived===0&&t>0){p(n(`inventory.bulk.archiveAllFailed`,{count:t}),`error`);return}t>0?p(n(`inventory.bulk.archivePartial`,{ok:e.archived,failed:t}),`warning`):p(n(`inventory.bulk.archiveSuccess`,{count:e.archived}),`success`),mt(null),gt()},onError:e=>{p(e.message||n(`inventory.bulk.archiveFailed`),`error`)}}),sn=d({mutationFn:async t=>e?r.bulkRestoreSpoolmanInventorySpools(t):r.bulkRestoreSpools(t),onSuccess:e=>{kt();let t=nn(e);if(e.restored===0&&t>0){p(n(`inventory.bulk.restoreAllFailed`,{count:t}),`error`);return}t>0?p(n(`inventory.bulk.restorePartial`,{ok:e.restored,failed:t}),`warning`):p(n(`inventory.bulk.restoreSuccess`,{count:e.restored}),`success`),mt(null),gt()},onError:e=>{p(e.message||n(`inventory.bulk.restoreFailed`),`error`)}}),cn=(0,J.useMemo)(()=>(q??[]).map(e=>e.id),[q]),ln=async t=>{if(t.last_scale_weight!=null)try{e?await r.syncSpoolmanSpoolWeight(t.id,t.last_scale_weight):await s.updateSpoolWeight(t.id,t.last_scale_weight),a.invalidateQueries({queryKey:Ot}),p(`Synced "${[t.brand,t.material,Ve(t.color_name,t.rgba,t.color_name_is_synthesized)].filter(Boolean).join(` `)}" to scale weight`,`success`)}catch(e){let t=e instanceof o&&e.status===404,r=e instanceof o&&e.status===503;p(n(t?`inventory.syncWeightSpoolNotFound`:r?`inventory.syncWeightSpoolmanUnreachable`:`inventory.syncWeightFailed`),`error`)}},un=xt?.low_stock_threshold??20,[dn,fn]=(0,J.useState)(!1),[pn,mn]=(0,J.useState)(un.toString());(0,J.useEffect)(()=>{dn||mn(un.toString())},[un,dn]);let hn=d({mutationFn:e=>r.updateSettings({low_stock_threshold:e}),onSuccess:()=>{a.invalidateQueries({queryKey:[`settings`]}),p(n(`common.saved`),`success`),fn(!1)},onError:()=>{p(n(`inventory.lowStockThresholdError`),`error`)}}),Q=(0,J.useMemo)(()=>{if(!q)return null;let e=0,t=0,n=0,r=0,i={};for(let a of q){if(t+=Math.max(0,a.weight_used-(a.weight_used_baseline??0)),a.archived_at)continue;r++;let o=Math.max(0,a.label_weight-a.weight_used);e+=o,(a.label_weight>0?o/a.label_weight*100:0)<(a.low_stock_threshold_pct??un)&&n++;let s=a.material||`Unknown`;i[s]||(i[s]={count:0,weight:0}),i[s].count++,i[s].weight+=o}return{totalWeight:e,totalConsumed:t,lowStock:n,byMaterial:i,totalSpools:r}},[q,un]),_n=(Kt?.length??0)+(e?qt.length:0),vn=Le(xt?.currency||`USD`),yn=(0,J.useMemo)(()=>{let e={};for(let t of Kt||[])e[t.spool_id]={printer_id:t.printer_id,printer_name:t.printer_name,ams_id:t.ams_id,tray_id:t.tray_id,ams_label:t.ams_label??null};for(let t of qt)typeof t?.spoolman_spool_id!=`number`||t.spoolman_spool_id<=0||typeof t.printer_id!=`number`||typeof t.ams_id!=`number`||typeof t.tray_id!=`number`||e[t.spoolman_spool_id]||(e[t.spoolman_spool_id]={printer_id:t.printer_id,printer_name:t.printer_name??null,ams_id:t.ams_id,tray_id:t.tray_id,ams_label:t.ams_label??null});return e},[Kt,qt]),bn=(0,J.useMemo)(()=>{let e={};for(let t of Xt||[])e[t.id]=t;return e},[Xt]),{data:xn}=u({queryKey:[`locationHaSensors`],queryFn:()=>r.getLocationHASensors()}),Sn=(0,J.useMemo)(()=>new Set((xn??[]).map(e=>e.location_id)),[xn]),Cn=(0,J.useMemo)(()=>{let e=new Set;for(let t of q||[])t.location_id&&Sn.has(t.location_id)&&e.add(t.location_id);return Array.from(e)},[q,Sn]),wn=W===`cards`||W===`table`&&nt.some(e=>e.visible&&(e.id===`temperature`||e.id===`humidity`||e.id===`battery`)),Tn=f({queries:Cn.map(e=>({queryKey:[`locationHaSensorReadings`,e],queryFn:()=>r.getLocationHASensorReadings(e,!1),refetchInterval:Ct,enabled:wn}))}),En=(0,J.useMemo)(()=>{let e={};return Cn.forEach((t,n)=>{let r=Tn[n]?.data;r&&(e[t]=r)}),e},[Cn,Tn]),Dn=(0,J.useMemo)(()=>Q?Object.entries(Q.byMaterial).sort((e,t)=>t[1].weight-e[1].weight).slice(0,4):[],[Q]),On=(0,J.useMemo)(()=>{let e=q||[];if(e=me===`active`?e.filter(e=>!e.archived_at):e.filter(e=>!!e.archived_at),H===`used`?e=e.filter(e=>e.weight_used>0):H===`new`?e=e.filter(e=>e.weight_used===0):H===`lowstock`&&(e=e.filter(e=>{let t=Math.max(0,e.label_weight-e.weight_used);return(e.label_weight>0?t/e.label_weight*100:0)<(e.low_stock_threshold_pct??un)})),ye&&(e=e.filter(e=>e.material===ye)),Ce&&(e=e.filter(e=>e.brand===Ce)),Ee&&(e=Ee===`__none__`?e.filter(e=>!e.category):e.filter(e=>e.category===Ee)),Ae&&(e=Ae===Hn?e.filter(e=>!e.material_number?.trim()):e.filter(e=>e.material_number===Ae)),Me)if(Me===`__none__`)e=e.filter(e=>(e.suppliers??[]).length===0);else{let t=Number(Me);e=e.filter(e=>(e.suppliers??[]).some(e=>e.supplier_id===t))}if(Be){let t=Number(Be);e=e.filter(e=>e.core_weight_catalog_id===t)}if(X)if(X===`__none__`)e=e.filter(e=>!e.location_id&&!e.storage_location?.trim());else{let t=Number(X),n=Lt.find(e=>e.id===t)?.name?.trim().toLowerCase();e=e.filter(e=>e.location_id==null?n?(e.storage_location||``).trim().toLowerCase()===n:!1:e.location_id===t)}return We===`stock`?e=e.filter(e=>!e.slicer_filament):We===`configured`&&(e=e.filter(e=>!!e.slicer_filament)),Ye&&(e=At(e,Ye)),e},[q,me,H,ye,Ce,Ee,Ae,Me,Be,We,X,Ye,un,Lt,i]),$=()=>vt(0),kn=(0,J.useCallback)(e=>{C(t=>(t.delete(`location_id`),e&&t.set(`location_id`,e),t),{replace:!0}),$()},[C]),An=[...new Set(q?.map(e=>e.material)||[])].sort(),Pn=[...new Set(q?.map(e=>e.brand).filter(Boolean)||[])].sort(),Fn=[...new Set(q?.map(e=>e.category?.trim()).filter(Boolean)||[])].sort(),In=(q??[]).some(e=>!e.category),Vn=[...new Set(q?.map(e=>e.material_number?.trim()).filter(Boolean)||[])].sort((e,t)=>e.localeCompare(t,void 0,{numeric:!0})),Un=(q??[]).some(e=>!e.material_number?.trim()),Yn=(0,J.useMemo)(()=>{let e=new Map;for(let t of q??[])for(let n of t.suppliers??[])e.set(n.supplier_id,n.supplier_name);return[...e.entries()].map(([e,t])=>({id:e,name:t})).sort((e,t)=>e.name.localeCompare(t.name))},[q]),Xn=(q??[]).some(e=>(e.suppliers??[]).length===0),Qn=[...new Set(q?.map(e=>e.core_weight_catalog_id).filter(e=>e!=null)||[])].sort((e,t)=>{let n=(bn[e]?.name||``).toLowerCase(),r=(bn[t]?.name||``).toLowerCase();return n.localeCompare(r)}),er=(q??[]).some(e=>!e.location_id&&!e.storage_location?.trim()),rr=me!==`active`||H!==`all`||!!ye||!!Ce||!!Ee||!!Ae||!!Me||!!Be||!!X||We!==`all`||!!Ye,ir=e=>{rt(e),Kn(e)},sr=(0,J.useMemo)(()=>nt.filter(e=>e.visible).map(e=>e.id),[nt]),cr=e=>{$n[e]&&(tt(t=>{let n;return n=t?.column===e?t.direction===`asc`?{column:e,direction:`desc`}:null:{column:e,direction:`asc`},nr(n),n}),$())},lr=(0,J.useMemo)(()=>{if(!$e)return On;let e=$n[$e.column];return e?[...On].sort((t,n)=>{let r=e(t,yn,En),i=e(n,yn,En);return ri?$e.direction===`asc`?1:-1:0}):On},[On,$e,yn,En]),ur=(0,J.useMemo)(()=>{if(!st)return lr.map(e=>({type:`single`,spool:e}));let e=new Map;for(let t of lr)if(!(t.weight_used>0||yn[t.id])){let n=Bn(t),r=e.get(n);r?r.push(t):e.set(n,[t])}let t=[],n=new Set;for(let r of lr){if(r.weight_used>0||yn[r.id]){t.push({type:`single`,spool:r});continue}let i=Bn(r);if(n.has(i))continue;n.add(i);let a=e.get(i);a.length===1?t.push({type:`single`,spool:a[0]}):t.push({type:`group`,key:i,spools:a,representative:a[0]})}return t},[lr,st,yn]),dr=yt===-1,hr=ur.length,gr=dr?hr||1:yt,_r=Math.max(1,Math.ceil(hr/gr)),vr=dr?0:Math.min(_t,_r-1),yr=dr?ur:ur.slice(vr*gr,(vr+1)*gr),br=()=>{let e=!st;ct(e),ut(new Set),$();try{localStorage.setItem(`bambuddy-inventory-group`,String(e))}catch{}},xr=e=>{ut(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},Sr=e=>{bt(e),vt(0);try{localStorage.setItem(`bambuddy-inventory-pageSize`,String(e))}catch{}};return(0,Y.jsxs)(`div`,{className:`p-4 md:p-8 space-y-6`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,Y.jsx)(oe,{className:`w-7 h-7 text-bambu-green`}),n(`inventory.title`)]}),(0,Y.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:n(`inventory.subtitle`)})]}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Y.jsxs)(V,{variant:`secondary`,disabled:e,onClick:()=>ie(!0),title:Pt,children:[(0,Y.jsx)(Ge,{className:`w-4 h-4`}),n(`inventory.csv.importButton`,`Import CSV`)]}),(0,Y.jsxs)(V,{variant:`secondary`,disabled:e||z,onClick:Mt,title:Pt,children:[z?(0,Y.jsx)(F,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(Qe,{className:`w-4 h-4`}),n(`inventory.csv.exportButton`,`Export CSV`)]}),(0,Y.jsxs)(V,{variant:`secondary`,onClick:()=>de(!0),children:[(0,Y.jsx)(ae,{className:`w-4 h-4`}),n(`locations.manage`)]}),(0,Y.jsxs)(V,{variant:`secondary`,onClick:()=>pe(!0),children:[(0,Y.jsx)(Ft,{className:`w-4 h-4`}),n(`inventory.suppliers.title`)]}),(0,Y.jsxs)(V,{variant:`secondary`,disabled:On.length===0,onClick:()=>P(G.size>0?[...G]:On.map(e=>e.id)),title:On.length===0?n(`inventory.labels.noSpoolsTitle`,`No spools to label`):G.size>0?n(`inventory.labels.selectedTitle`,`Print labels for the {{count}} selected spools`,{count:G.size}):n(`inventory.labels.bulkTitle`,`Pick spools to print labels for from the {{count}} currently shown`,{count:On.length}),children:[(0,Y.jsx)(U,{className:`w-4 h-4`}),n(`inventory.labels.printLabels`,`Print labels…`)]}),(0,Y.jsxs)(V,{onClick:()=>E({spool:null,mode:`create`}),children:[(0,Y.jsx)(Pe,{className:`w-4 h-4`}),n(`inventory.addSpool`)]})]})]}),Q&&!jt&&(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-3 lg:grid-cols-5 gap-3`,children:[(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,Y.jsx)(oe,{className:`w-4 h-4 text-bambu-green`}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray font-medium uppercase tracking-wide`,children:n(`inventory.totalInventory`)})]}),(0,Y.jsx)(`div`,{className:`text-xl font-bold text-white`,children:qn(Q.totalWeight,!0)}),(0,Y.jsxs)(`div`,{className:`text-xs text-bambu-gray mt-1`,children:[Q.totalSpools,` `,Q.totalSpools===1?n(`inventory.spool`):n(`inventory.spools`)]})]}),(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2 mb-1`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(le,{className:`w-4 h-4 text-blue-600 dark:text-blue-400`}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray font-medium uppercase tracking-wide`,children:n(`inventory.totalConsumed`)})]}),Q.totalConsumed>0&&cn.length>0&&(0,Y.jsx)(`button`,{onClick:()=>A({type:`reset-all-consumed-counters`}),className:`p-1 text-bambu-gray hover:text-red-600 dark:hover:text-red-400 rounded transition-colors`,title:n(`inventory.resetAllConsumedCountersTooltip`),"aria-label":n(`inventory.resetAllConsumedCounters`),children:(0,Y.jsx)(S,{className:`w-3.5 h-3.5`})})]}),(0,Y.jsx)(`div`,{className:`text-xl font-bold text-white`,children:qn(Q.totalConsumed,!0)}),(0,Y.jsx)(`div`,{className:`text-xs text-bambu-gray mt-1`,children:n(`inventory.sinceTracking`)})]}),(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,Y.jsx)(ze,{className:`w-4 h-4 text-green-600 dark:text-green-400`}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray font-medium uppercase tracking-wide`,children:n(`inventory.byMaterial`)})]}),(0,Y.jsx)(`div`,{className:`flex flex-wrap gap-1.5 mt-1`,children:Dn.map(([e,t])=>(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium ${Jn[e]||`bg-bambu-dark-tertiary text-bambu-gray`}`,children:[e,` `,(0,Y.jsx)(`span`,{className:`opacity-70`,children:qn(t.weight,!0)})]},e))})]}),(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,Y.jsx)(U,{className:`w-4 h-4 text-purple-600 dark:text-purple-400`}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray font-medium uppercase tracking-wide`,children:n(`inventory.inPrinter`)})]}),(0,Y.jsx)(`div`,{className:`text-xl font-bold text-white`,children:_n}),(0,Y.jsx)(`div`,{className:`text-xs text-bambu-gray mt-1`,children:n(`inventory.loadedInAms`)})]}),(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,Y.jsx)(B,{className:`w-4 h-4 text-yellow-600 dark:text-yellow-400`}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray font-medium uppercase tracking-wide`,children:n(`inventory.lowStock`)})]}),(0,Y.jsx)(`div`,{className:`text-xl font-bold ${Q.lowStock>0?`text-yellow-700 dark:text-yellow-400`:`text-white`}`,children:Q.lowStock}),(0,Y.jsx)(`div`,{className:`text-xs text-bambu-gray mt-1 flex items-center gap-2`,children:dn?(0,Y.jsxs)(`form`,{onSubmit:e=>{e.preventDefault();let t=parseFloat(pn);!isNaN(t)&&t>=.1&&t<=99.9?hn.mutate(t):p(n(`inventory.lowStockThresholdError`),`error`)},className:`flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:`<`}),(0,Y.jsx)(`input`,{type:`text`,inputMode:`decimal`,pattern:`^\\d{0,2}(\\.\\d?)?$`,maxLength:4,value:pn,onChange:e=>{let t=e.target.value.replace(/[^\d.]/g,``);/^\d{0,2}(\.\d?)?$/.test(t)&&mn(t)},className:`px-1.5 py-1 rounded border border-bambu-dark-tertiary text-xs text-white bg-bambu-dark-secondary focus:outline-none focus:border-bambu-green w-14 text-center`,onWheel:e=>e.currentTarget.blur(),disabled:hn.isPending}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:`%`}),(0,Y.jsx)(V,{type:`submit`,size:`sm`,disabled:hn.isPending,children:n(`common.save`)}),(0,Y.jsx)(V,{type:`button`,size:`sm`,variant:`ghost`,onClick:()=>fn(!1),disabled:hn.isPending,children:n(`common.cancel`)})]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`span`,{className:`text-bambu-gray`,children:[`< `,un,`%`]}),(0,Y.jsx)(`button`,{className:`p-1.5 text-bambu-gray hover:text-white rounded transition-colors`,title:n(`common.edit`),onClick:()=>{mn(un.toString()),fn(!0)},children:(0,Y.jsx)(I,{className:`w-4 h-4`})})]})})]})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col sm:flex-row gap-3 items-start sm:items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`relative flex-1 max-w-md ${W===`forecast`?`invisible pointer-events-none`:``}`,children:[(0,Y.jsx)(se,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50`}),(0,Y.jsx)(`input`,{type:`text`,value:Ye,onChange:e=>{Xe(e.target.value),$()},placeholder:n(`inventory.search`),className:`w-full pl-10 pr-8 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`}),Ye&&(0,Y.jsx)(`button`,{onClick:()=>{Xe(``),$()},className:`absolute right-3 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white`,children:(0,Y.jsx)(he,{className:`w-4 h-4`})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[W===`table`&&(0,Y.jsxs)(`button`,{onClick:()=>ot(!0),className:`flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium text-bambu-gray border border-bambu-dark-tertiary rounded-lg hover:bg-bambu-dark-tertiary transition-colors`,title:n(`inventory.configureColumns`),children:[(0,Y.jsx)(j,{className:`w-4 h-4`}),(0,Y.jsx)(`span`,{className:`hidden sm:inline`,children:n(`inventory.columns`)})]}),W!==`forecast`&&(0,Y.jsxs)(`button`,{onClick:br,className:`flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium border rounded-lg transition-colors ${st?`bg-bambu-green/20 text-bambu-green border-bambu-green/30`:`text-bambu-gray border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary`}`,title:n(`inventory.groupSimilar`),children:[(0,Y.jsx)(Nt,{className:`w-4 h-4`}),(0,Y.jsx)(`span`,{className:`hidden sm:inline`,children:n(`inventory.groupSimilar`)})]}),(0,Y.jsxs)(`div`,{className:`flex bg-bambu-dark-primary border border-bambu-dark-tertiary rounded-lg overflow-hidden`,children:[(0,Y.jsxs)(`button`,{onClick:()=>Ze(`table`),className:`flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium transition-colors ${W===`table`?`bg-bambu-green text-white`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:[(0,Y.jsx)(It,{className:`w-4 h-4`}),(0,Y.jsx)(`span`,{className:`hidden sm:inline`,children:n(`inventory.table`)})]}),(0,Y.jsxs)(`button`,{onClick:()=>Ze(`cards`),className:`flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium transition-colors ${W===`cards`?`bg-bambu-green text-white`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:[(0,Y.jsx)(N,{className:`w-4 h-4`}),(0,Y.jsx)(`span`,{className:`hidden sm:inline`,children:n(`inventory.cards`)})]}),(0,Y.jsxs)(`button`,{onClick:()=>b&&Ze(`forecast`),disabled:!b,title:b?void 0:n(`forecast.noReadAccess`),className:`flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium transition-colors disabled:opacity-40 disabled:cursor-not-allowed ${W===`forecast`?`bg-bambu-green text-white`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:[b?(0,Y.jsx)(m,{className:`w-4 h-4`}):(0,Y.jsx)(ne,{className:`w-4 h-4`}),(0,Y.jsx)(`span`,{className:`hidden sm:inline`,children:n(`forecast.title`)})]})]})]})]}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 ${W===`forecast`?`hidden`:``}`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center rounded-lg border border-bambu-dark-tertiary overflow-hidden`,children:[(0,Y.jsxs)(`button`,{onClick:()=>{ge(`active`),$()},className:`flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium transition-colors ${me===`active`?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:[(0,Y.jsx)(oe,{className:`w-3.5 h-3.5`}),n(`inventory.active`)]}),(0,Y.jsxs)(`button`,{onClick:()=>{ge(`archived`),$()},className:`flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium transition-colors ${me===`archived`?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:[(0,Y.jsx)(Te,{className:`w-3.5 h-3.5`}),n(`inventory.archived`)]})]}),(0,Y.jsx)(`div`,{className:`w-px h-5 bg-bambu-dark-tertiary`}),(0,Y.jsxs)(`div`,{className:`flex items-center rounded-lg border border-bambu-dark-tertiary overflow-hidden`,children:[(0,Y.jsx)(`button`,{onClick:()=>{_e(`all`),$()},className:`px-3 py-1.5 text-xs font-medium transition-colors ${H===`all`?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:n(`inventory.all`)}),(0,Y.jsxs)(`button`,{onClick:()=>{_e(`used`),$()},className:`flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium transition-colors ${H===`used`?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:[(0,Y.jsx)(Oe,{className:`w-3.5 h-3.5`}),n(`inventory.used`)]}),(0,Y.jsx)(`button`,{onClick:()=>{_e(`new`),$()},className:`px-3 py-1.5 text-xs font-medium transition-colors ${H===`new`?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:n(`inventory.new`)}),(0,Y.jsxs)(`button`,{onClick:()=>{_e(`lowstock`),$()},className:`flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium transition-colors ${H===`lowstock`?`bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:[(0,Y.jsx)(B,{className:`w-3.5 h-3.5`}),n(`inventory.lowStock`)]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center rounded-lg border border-bambu-dark-tertiary overflow-hidden`,children:[(0,Y.jsx)(`button`,{onClick:()=>{Ke(`all`),$()},className:`px-3 py-1.5 text-xs font-medium transition-colors ${We===`all`?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:n(`inventory.all`)}),(0,Y.jsx)(`button`,{onClick:()=>{Ke(`stock`),$()},className:`px-3 py-1.5 text-xs font-medium transition-colors ${We===`stock`?`bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:n(`inventory.stock`)}),(0,Y.jsx)(`button`,{onClick:()=>{Ke(`configured`),$()},className:`px-3 py-1.5 text-xs font-medium transition-colors ${We===`configured`?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:n(`inventory.configured`)})]}),(0,Y.jsx)(`div`,{className:`w-px h-5 bg-bambu-dark-tertiary`}),(0,Y.jsxs)(`select`,{value:ye,onChange:e=>{xe(e.target.value),$()},className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${ye?`bg-bambu-green/20 text-bambu-green border-bambu-green/30`:`bg-transparent text-bambu-gray border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary`}`,children:[(0,Y.jsx)(`option`,{value:``,children:n(`inventory.material`)}),An.map(e=>(0,Y.jsx)(`option`,{value:e,children:e},e))]}),(0,Y.jsxs)(`select`,{value:Ce,onChange:e=>{we(e.target.value),$()},className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${Ce?`bg-bambu-green/20 text-bambu-green border-bambu-green/30`:`bg-transparent text-bambu-gray border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary`}`,children:[(0,Y.jsx)(`option`,{value:``,children:n(`inventory.brand`)}),Pn.map(e=>(0,Y.jsx)(`option`,{value:e,children:e},e))]}),(Fn.length>0||Ee)&&(0,Y.jsxs)(`select`,{value:Ee,onChange:e=>{ke(e.target.value),$()},className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${Ee?`bg-bambu-green/20 text-bambu-green border-bambu-green/30`:`bg-transparent text-bambu-gray border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary`}`,children:[(0,Y.jsx)(`option`,{value:``,children:n(`inventory.category`)}),Fn.map(e=>(0,Y.jsx)(`option`,{value:e,children:e},e)),In&&(0,Y.jsx)(`option`,{value:`__none__`,children:n(`inventory.categoryNone`)})]}),(Vn.length>0||Ae)&&(0,Y.jsxs)(`select`,{value:Ae,onChange:e=>{je(e.target.value),$()},className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${Ae?`bg-bambu-green/20 text-bambu-green border-bambu-green/30`:`bg-transparent text-bambu-gray border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary`}`,children:[(0,Y.jsx)(`option`,{value:``,children:n(`inventory.materialNumber`)}),Vn.map(e=>(0,Y.jsx)(`option`,{value:e,children:e},e)),Un&&(0,Y.jsx)(`option`,{value:Hn,children:n(`inventory.materialNumberNone`)})]}),(Yn.length>0||Me)&&(0,Y.jsxs)(`select`,{value:Me,onChange:e=>{Re(e.target.value),$()},className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${Me?`bg-bambu-green/20 text-bambu-green border-bambu-green/30`:`bg-transparent text-bambu-gray border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary`}`,children:[(0,Y.jsx)(`option`,{value:``,children:n(`inventory.suppliers.label`)}),Yn.map(e=>(0,Y.jsx)(`option`,{value:String(e.id),children:e.name},e.id)),Xn&&(0,Y.jsx)(`option`,{value:`__none__`,children:n(`inventory.suppliers.none`)})]}),Qn.length>0&&(0,Y.jsxs)(`select`,{value:Be,onChange:e=>{He(e.target.value),$()},className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${Be?`bg-bambu-green/20 text-bambu-green border-bambu-green/30`:`bg-transparent text-bambu-gray border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary`}`,children:[(0,Y.jsx)(`option`,{value:``,children:n(`inventory.spoolName`)}),Qn.map(e=>(0,Y.jsx)(`option`,{value:e,children:bn[e]?.name||`#${e}`},e))]}),(Lt.length>0||X)&&(0,Y.jsxs)(`select`,{value:X,onChange:e=>{kn(e.target.value)},className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${X?`bg-bambu-green/20 text-bambu-green border-bambu-green/30`:`bg-transparent text-bambu-gray border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary`}`,children:[(0,Y.jsx)(`option`,{value:``,children:n(`inventory.storageLocation`)}),Lt.map(e=>(0,Y.jsx)(`option`,{value:String(e.id),children:e.name},e.id)),er&&(0,Y.jsx)(`option`,{value:`__none__`,children:n(`inventory.storageLocationNone`)})]}),rr&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`div`,{className:`w-px h-5 bg-bambu-dark-tertiary`}),(0,Y.jsxs)(`button`,{onClick:()=>{ge(`active`),_e(`all`),xe(``),we(``),ke(``),je(``),Re(``),He(``),Ke(`all`),Xe(``),C(e=>(e.delete(`location_id`),e),{replace:!0}),$()},className:`flex items-center gap-1 text-xs text-bambu-gray hover:text-bambu-green transition-colors`,children:[(0,Y.jsx)(he,{className:`w-3.5 h-3.5`}),n(`inventory.clearFilters`)]})]}),W!==`forecast`&&(0,Y.jsxs)(`span`,{className:`ml-auto text-xs text-bambu-gray`,children:[lr.length,` `,lr.length===1?n(`inventory.spool`):n(`inventory.spools`),st&&hr0&&W!==`forecast`&&(0,Y.jsxs)(`div`,{className:`sticky top-2 z-10 mb-4 flex items-center gap-2 px-3 py-2 bg-bambu-green/10 border border-bambu-green/30 rounded-lg backdrop-blur-sm`,children:[(0,Y.jsx)(`span`,{className:`text-sm text-bambu-green font-medium`,children:n(`inventory.bulk.selectionCount`,{count:G.size})}),(0,Y.jsxs)(`div`,{className:`ml-auto flex flex-wrap items-center gap-2`,children:[(0,Y.jsxs)(V,{size:`sm`,variant:`secondary`,onClick:()=>pt(!0),children:[(0,Y.jsx)(I,{className:`w-3.5 h-3.5 mr-1.5`}),n(`inventory.bulk.edit`)]}),(0,Y.jsxs)(V,{size:`sm`,variant:`secondary`,onClick:()=>P([...G]),children:[(0,Y.jsx)(U,{className:`w-3.5 h-3.5 mr-1.5`}),n(`inventory.bulk.printLabels`)]}),(0,Y.jsxs)(V,{size:`sm`,variant:`secondary`,onClick:()=>mt(`reset-consumed-counter`),children:[(0,Y.jsx)(S,{className:`w-3.5 h-3.5 mr-1.5`}),n(`inventory.bulk.resetUsage`)]}),me===`archived`?(0,Y.jsxs)(V,{size:`sm`,variant:`secondary`,onClick:()=>mt(`restore`),children:[(0,Y.jsx)(Se,{className:`w-3.5 h-3.5 mr-1.5`}),n(`inventory.bulk.restore`)]}):(0,Y.jsxs)(V,{size:`sm`,variant:`secondary`,onClick:()=>mt(`archive`),children:[(0,Y.jsx)(Te,{className:`w-3.5 h-3.5 mr-1.5`}),n(`inventory.bulk.archive`)]}),(0,Y.jsxs)(V,{size:`sm`,variant:`danger`,onClick:()=>mt(`delete`),children:[(0,Y.jsx)(be,{className:`w-3.5 h-3.5 mr-1.5`}),n(`inventory.bulk.delete`)]}),(0,Y.jsx)(`button`,{className:`p-1.5 text-bambu-gray hover:text-white rounded transition-colors`,onClick:gt,title:n(`inventory.bulk.clearSelection`),"aria-label":n(`inventory.bulk.clearSelection`),children:(0,Y.jsx)(he,{className:`w-4 h-4`})})]})]}),jt?(0,Y.jsx)(`div`,{className:`flex justify-center py-16`,children:(0,Y.jsx)(F,{className:`w-8 h-8 text-bambu-green animate-spin`})}):W===`forecast`?(0,Y.jsx)(Wt,{spools:q||[]}):W===`cards`?yr.length>0?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4`,children:yr.map(e=>{if(e.type===`group`){let{key:t,spools:r,representative:i}=e,a=r.reduce((e,t)=>e+Math.max(0,t.label_weight-t.weight_used),0),o=ve({rgba:i.rgba,extraColors:i.extra_colors,effectType:i.effect_type,subtype:i.subtype,effectSize:`groupheader`}),s=lt.has(t);return(0,Y.jsxs)(`div`,{className:`col-span-full`,children:[(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-green/30 hover:border-bambu-green transition-colors cursor-pointer`,onClick:()=>xr(t),children:[(0,Y.jsx)(`div`,{className:`h-10 flex items-center px-4 gap-3`,style:o,children:(0,Y.jsx)(`span`,{className:`bg-white/90 text-gray-800 px-3 py-0.5 rounded-full text-sm font-medium`,children:Ve(i.color_name,i.rgba,i.color_name_is_synthesized)||`-`})}),(0,Y.jsxs)(`div`,{className:`px-4 py-3 flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Y.jsx)(T,{className:`w-4 h-4 text-bambu-gray transition-transform ${s?``:`-rotate-90`}`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`h3`,{className:`font-semibold text-white`,children:[i.material,i.subtype?` ${i.subtype}`:``]}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i.brand||`-`})]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,title:n(`inventory.remaining`),children:qn(a)}),(0,Y.jsx)(`span`,{className:`text-xs font-medium bg-bambu-green/20 text-bambu-green px-2 py-0.5 rounded-full`,children:n(`inventory.groupedSpools`,{count:r.length})})]})]})]}),s&&(0,Y.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4 mt-2 ml-4`,children:r.map(e=>{let t=Math.max(0,e.label_weight-e.weight_used);return(0,Y.jsx)(or,{spool:e,remaining:t,pct:e.label_weight>0?t/e.label_weight*100:0,onClick:()=>E({spool:e,mode:`edit`}),onPrintLabel:()=>P([e.id]),onCopy:()=>E({spool:e,mode:`copy`}),t:n,colorizeLocationSensors:wt,locationSensorAboveColor:Tt,locationSensorBelowColor:Et,locationSensorOptimalColor:Dt,dateFormat:St},e.id)})})]},`group-${t}`)}let t=e.spool,r=Math.max(0,t.label_weight-t.weight_used);return(0,Y.jsx)(or,{spool:t,remaining:r,pct:t.label_weight>0?r/t.label_weight*100:0,onClick:()=>E({spool:t,mode:`edit`}),onPrintLabel:()=>P([t.id]),onCopy:()=>E({spool:t,mode:`copy`}),t:n,colorizeLocationSensors:wt,locationSensorAboveColor:Tt,locationSensorBelowColor:Et,locationSensorOptimalColor:Dt,dateFormat:St},t.id)})}),(0,Y.jsx)(ar,{pageIndex:vr,pageSize:yt,totalRows:hr,totalPages:_r,onPageChange:vt,onPageSizeChange:Sr,t:n})]}):(0,Y.jsx)(mr,{hasFilters:rr,onAddSpool:()=>E({spool:null,mode:`create`}),t:n}):yr.length>0?(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-dark-tertiary`,children:[(0,Y.jsx)(`div`,{className:`overflow-x-auto`,children:(0,Y.jsxs)(`table`,{className:`w-full`,children:[(0,Y.jsx)(`thead`,{children:(0,Y.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary bg-bambu-dark-tertiary/30`,children:[(0,Y.jsx)(`th`,{className:`w-10 px-3 py-3`,children:(0,Y.jsx)(`input`,{type:`checkbox`,className:`h-4 w-4 cursor-pointer`,"aria-label":n(`inventory.bulk.selectAllVisible`),checked:yr.length>0&&yr.every(e=>(e.type===`group`?e.spools.map(e=>e.id):[e.spool.id]).every(e=>G.has(e))),onChange:e=>{if(e.target.checked){let e=new Set(G);for(let t of yr){let n=t.type===`group`?t.spools.map(e=>e.id):[t.spool.id];for(let t of n)e.add(t)}dt(e)}else{let e=new Set(G);for(let t of yr){let n=t.type===`group`?t.spools.map(e=>e.id):[t.spool.id];for(let t of n)e.delete(t)}dt(e)}}})}),sr.map(e=>{let t=!!$n[e],r=$e?.column===e;return(0,Y.jsx)(`th`,{className:`text-left py-3 px-4 text-xs font-medium uppercase tracking-wide select-none ${e===`remaining`?`min-w-[150px]`:``} ${t?`cursor-pointer hover:text-bambu-green transition-colors`:``} ${r?`text-bambu-green`:`text-bambu-gray`}`,onClick:t?()=>cr(e):void 0,children:(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[Zn[e]?.(n)??e,t&&(r?$e.direction===`asc`?(0,Y.jsx)(y,{className:`w-3 h-3`}):(0,Y.jsx)(_,{className:`w-3 h-3`}):(0,Y.jsx)(v,{className:`w-3 h-3 opacity-30`}))]})},e)}),(0,Y.jsx)(`th`,{className:`text-right py-3 px-4 text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:n(`common.actions`)})]})}),(0,Y.jsx)(`tbody`,{children:yr.map(e=>{if(e.type===`group`){let{key:t,spools:r}=e,i=lt.has(t),a=Rn(r),o=Math.max(0,a.label_weight-a.weight_used);return(0,Y.jsx)(pr,{spools:r,headerSpool:a,remaining:o,pct:a.label_weight>0?o/a.label_weight*100:0,isExpanded:i,onToggle:()=>xr(t),selectedIds:G,onToggleSelected:ht,onToggleGroupSelected:(e,t)=>{dt(n=>{let r=new Set(n);for(let n of e)t?r.add(n):r.delete(n);return r})},onEdit:e=>E({spool:e,mode:`edit`}),onCopy:e=>E({spool:e,mode:`copy`}),onArchive:e=>A({type:`archive`,spoolId:e}),onDelete:e=>A({type:`delete`,spoolId:e}),onPrintLabel:e=>P([e]),onResetConsumedCounter:e=>A({type:`reset-consumed-counter`,spoolId:e}),visibleColumns:sr,assignmentMap:yn,catalogMap:bn,locationReadingsMap:En,currencySymbol:vn,dateFormat:St,t:n,onSyncWeight:ln,colorizeLocationSensors:wt,locationSensorAboveColor:Tt,locationSensorBelowColor:Et,locationSensorOptimalColor:Dt},`group-${t}`)}let t=e.spool,r=Math.max(0,t.label_weight-t.weight_used);return(0,Y.jsx)(fr,{spool:t,remaining:r,pct:t.label_weight>0?r/t.label_weight*100:0,isSelected:G.has(t.id),onToggleSelected:()=>ht(t.id),onEdit:()=>E({spool:t,mode:`edit`}),onCopy:()=>E({spool:t,mode:`copy`}),onRestore:()=>$t.mutate(t.id),onArchive:()=>A({type:`archive`,spoolId:t.id}),onDelete:()=>A({type:`delete`,spoolId:t.id}),onPrintLabel:()=>P([t.id]),onResetConsumedCounter:()=>A({type:`reset-consumed-counter`,spoolId:t.id}),visibleColumns:sr,assignmentMap:yn,catalogMap:bn,locationReadingsMap:En,currencySymbol:vn,dateFormat:St,t:n,onSyncWeight:ln,colorizeLocationSensors:wt,locationSensorAboveColor:Tt,locationSensorBelowColor:Et,locationSensorOptimalColor:Dt},t.id)})})]})}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 bg-bambu-dark-tertiary/50 border-t border-bambu-dark-tertiary text-sm`,children:[(0,Y.jsx)(`span`,{className:`text-bambu-gray`,children:dr?`${hr} ${n(hr===1?`inventory.spool`:`inventory.spools`)}`:(0,Y.jsxs)(Y.Fragment,{children:[n(`inventory.showing`),` `,vr*gr+1,` `,n(`inventory.to`),` `,Math.min((vr+1)*gr,hr),` `,n(`inventory.of`),` `,hr,` `,n(`inventory.spools`)]})}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{className:`text-bambu-gray`,children:n(`inventory.show`)}),(0,Y.jsxs)(`select`,{value:yt,onChange:e=>Sr(Number(e.target.value)),className:`px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:outline-none focus:border-bambu-green`,children:[[15,30,50,100].map(e=>(0,Y.jsx)(`option`,{value:e,children:e},e)),(0,Y.jsx)(`option`,{value:-1,children:n(`inventory.all`)})]}),!dr&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`button`,{onClick:()=>vt(0),disabled:vr===0,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,title:`First page`,children:(0,Y.jsx)(ee,{className:`w-4 h-4`})}),(0,Y.jsx)(`button`,{onClick:()=>vt(e=>Math.max(0,e-1)),disabled:vr===0,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,children:(0,Y.jsx)(Ue,{className:`w-4 h-4`})}),(0,Y.jsxs)(`span`,{className:`text-bambu-gray px-2 whitespace-nowrap`,children:[n(`inventory.page`),` `,vr+1,` `,n(`inventory.of`),` `,_r]}),(0,Y.jsx)(`button`,{onClick:()=>vt(e=>Math.min(_r-1,e+1)),disabled:vr>=_r-1,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,children:(0,Y.jsx)(De,{className:`w-4 h-4`})}),(0,Y.jsx)(`button`,{onClick:()=>vt(_r-1),disabled:vr>=_r-1,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,title:`Last page`,children:(0,Y.jsx)(k,{className:`w-4 h-4`})})]})]})]})]}):(0,Y.jsx)(mr,{hasFilters:rr,onAddSpool:()=>E({spool:null,mode:`create`}),t:n}),w!==null&&(0,Y.jsx)(gn,{isOpen:!0,onClose:()=>E(null),spool:w.spool,mode:w.mode,currencySymbol:vn,spoolmanMode:e,spoolsQueryKey:Ot}),O&&(0,Y.jsx)(Fe,{title:O.type===`delete`?n(`common.delete`):O.type===`archive`?n(`inventory.archive`):O.type===`reset-consumed-counter`?n(`inventory.resetConsumedCounter`):n(`inventory.resetAllConsumedCounters`),message:O.type===`delete`?n(`inventory.deleteConfirm`):O.type===`archive`?n(`inventory.archiveConfirm`):O.type===`reset-consumed-counter`?n(`inventory.resetConsumedCounterConfirm`):n(`inventory.resetAllConsumedCountersConfirm`,{count:cn.length}),confirmText:O.type===`delete`?n(`common.delete`):O.type===`archive`?n(`inventory.archive`):n(`inventory.resetConsumedCounter`),variant:O.type===`archive`?`warning`:`danger`,onConfirm:()=>{O.type===`delete`?Zt.mutate(O.spoolId):O.type===`archive`?Qt.mutate(O.spoolId):O.type===`reset-consumed-counter`?en.mutate(O.spoolId):tn.mutate(cn),A(null)},onCancel:()=>A(null)}),(0,Y.jsx)(it,{isOpen:at,onClose:()=>ot(!1),columns:nt,defaultColumns:Wn,onSave:ir}),(0,Y.jsx)(jn,{isOpen:M!==null,onClose:()=>P(null),availableSpools:On,initialSelectedIds:M??[],spoolmanMode:e}),(0,Y.jsx)(Ln,{isOpen:ft,selectedCount:G.size,isPending:rn.isPending,availableLocations:Lt.map(e=>({id:e.id,name:e.name})),availableMaterials:zn((q??[]).map(e=>e.material)),availableSubtypes:zn((q??[]).map(e=>e.subtype)),availableBrands:zn((q??[]).map(e=>e.brand)),availableCategories:zn((q??[]).map(e=>e.category)),availableMaterialNumbers:zn((q??[]).map(e=>e.material_number)),availableSlicerFilaments:zn((q??[]).map(e=>e.slicer_filament)),availableSlicerFilamentNames:zn((q??[]).map(e=>e.slicer_filament_name)),spoolmanMode:e,onClose:()=>pt(!1),onApply:e=>rn.mutate({ids:[...G],update:e})}),K&&(0,Y.jsx)(Fe,{title:n(K===`delete`?`inventory.bulk.deleteTitle`:K===`archive`?`inventory.bulk.archiveTitle`:K===`restore`?`inventory.bulk.restoreTitle`:`inventory.bulk.resetUsageTitle`),message:n(K===`delete`?`inventory.bulk.deleteMessage`:K===`archive`?`inventory.bulk.archiveMessage`:K===`restore`?`inventory.bulk.restoreMessage`:`inventory.bulk.resetUsageMessage`,{count:G.size}),confirmText:n(K===`delete`?`common.delete`:K===`archive`?`inventory.archive`:K===`restore`?`inventory.restore`:`inventory.resetConsumedCounter`),variant:K===`delete`?`danger`:`warning`,isLoading:an.isPending||on.isPending||sn.isPending||tn.isPending,onConfirm:()=>{let e=[...G];K===`delete`?an.mutate(e):K===`archive`?on.mutate(e):K===`restore`?sn.mutate(e):tn.mutate(e)},onCancel:()=>mt(null)}),L&&(0,Y.jsx)(Mn,{onClose:()=>ie(!1),onImported:e=>{ie(!1),a.invalidateQueries({queryKey:Ot}),p(n(`inventory.csv.importSuccess`,`{{count}} spools imported`,{count:e}),`success`)}}),(0,Y.jsx)(re,{open:ue,onClose:()=>de(!1),onPickLocation:e=>kn(String(e))}),(0,Y.jsx)(Nn,{open:fe,onClose:()=>pe(!1)})]})}function ar({pageIndex:e,pageSize:t,totalRows:n,totalPages:r,onPageChange:i,onPageSizeChange:a,t:o}){let s=t===-1;if(r<=1&&!s)return null;let c=s?n||1:t;return(0,Y.jsxs)(`div`,{className:`flex items-center justify-between pt-2 text-sm`,children:[(0,Y.jsx)(`span`,{className:`text-bambu-gray`,children:s?`${n} ${o(n===1?`inventory.spool`:`inventory.spools`)}`:(0,Y.jsxs)(Y.Fragment,{children:[o(`inventory.showing`),` `,e*c+1,` `,o(`inventory.to`),` `,Math.min((e+1)*c,n),` `,o(`inventory.of`),` `,n,` `,o(`inventory.spools`)]})}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{className:`text-bambu-gray`,children:o(`inventory.show`)}),(0,Y.jsxs)(`select`,{value:t,onChange:e=>a(Number(e.target.value)),className:`px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:outline-none focus:border-bambu-green`,children:[[15,30,50,100].map(e=>(0,Y.jsx)(`option`,{value:e,children:e},e)),(0,Y.jsx)(`option`,{value:-1,children:o(`inventory.all`)})]}),!s&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`button`,{onClick:()=>i(0),disabled:e===0,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,children:(0,Y.jsx)(ee,{className:`w-4 h-4`})}),(0,Y.jsx)(`button`,{onClick:()=>i(Math.max(0,e-1)),disabled:e===0,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,children:(0,Y.jsx)(Ue,{className:`w-4 h-4`})}),(0,Y.jsxs)(`span`,{className:`text-bambu-gray px-2 whitespace-nowrap`,children:[o(`inventory.page`),` `,e+1,` `,o(`inventory.of`),` `,r]}),(0,Y.jsx)(`button`,{onClick:()=>i(Math.min(r-1,e+1)),disabled:e>=r-1,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,children:(0,Y.jsx)(De,{className:`w-4 h-4`})}),(0,Y.jsx)(`button`,{onClick:()=>i(r-1),disabled:e>=r-1,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,children:(0,Y.jsx)(k,{className:`w-4 h-4`})})]})]})]})}function or({spool:e,remaining:t,pct:n,onClick:r,onPrintLabel:i,onCopy:a,t:o,colorizeLocationSensors:s,locationSensorAboveColor:c,locationSensorBelowColor:l,locationSensorOptimalColor:u,dateFormat:d}){let f=ve({rgba:e.rgba,extraColors:e.extra_colors,effectType:e.effect_type,subtype:e.subtype,effectSize:`card`});return(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-dark-tertiary hover:border-bambu-green transition-colors cursor-pointer ${e.archived_at?`opacity-50`:``}`,onClick:r,children:[(0,Y.jsxs)(`div`,{className:`h-14 flex items-center justify-center`,style:f,children:[(0,Y.jsx)(`span`,{className:`bg-white/90 text-gray-800 px-3 py-0.5 rounded-full text-sm font-medium`,children:Ve(e.color_name,e.rgba,e.color_name_is_synthesized)||`-`}),a&&(0,Y.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),a()},className:`p-1.5 bg-black/20 hover:bg-black/40 text-white rounded-full transition-colors`,title:o(`inventory.copySpool`),children:(0,Y.jsx)(M,{className:`w-3.5 h-3.5`})})]}),(0,Y.jsxs)(`div`,{className:`p-4 space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`h3`,{className:`font-semibold text-white`,children:[e.material,e.subtype?` ${e.subtype}`:``]}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e.brand||`-`})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1`,children:[i&&(0,Y.jsx)(`button`,{onClick:e=>{e.stopPropagation(),i()},className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,title:o(`inventory.labels.printOne`),"aria-label":o(`inventory.labels.printOne`),children:(0,Y.jsx)(U,{className:`w-4 h-4`})}),(0,Y.jsxs)(`span`,{className:`text-xs font-mono text-bambu-gray bg-bambu-dark-tertiary px-2 py-1 rounded`,children:[`#`,e.id]})]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`div`,{className:`flex justify-between text-xs text-bambu-gray mb-1`,children:[(0,Y.jsx)(`span`,{children:o(`inventory.remaining`)}),(0,Y.jsxs)(`span`,{children:[Math.round(n),`%`]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`div`,{className:`flex-1 h-2 bg-bambu-dark-tertiary rounded-full overflow-hidden`,children:(0,Y.jsx)(`div`,{className:`h-full rounded-full ${n>50?`bg-bambu-green`:n>20?`bg-yellow-500`:`bg-red-500`}`,style:{width:`${Math.min(n,100)}%`}})}),(0,Y.jsxs)(`span`,{className:`text-xs text-bambu-gray min-w-[40px] text-right`,children:[Math.round(t),`g`]})]})]}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 text-xs`,children:[e.last_dried_at&&(0,Y.jsxs)(`div`,{className:`col-span-2`,children:[(0,Y.jsxs)(`span`,{className:`text-bambu-gray/60`,children:[o(`inventory.lastDried`),`: `]}),(0,Y.jsx)(`span`,{className:`text-bambu-gray`,children:[Xn(e.last_dried_at,d),Yn(e)].filter(Boolean).join(` · `)})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`span`,{className:`text-bambu-gray/60`,children:[o(`inventory.labelWeight`),`: `]}),(0,Y.jsx)(`span`,{className:`text-bambu-gray`,children:qn(e.label_weight)})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`span`,{className:`text-bambu-gray/60`,children:[o(`inventory.weightUsed`),`: `]}),(0,Y.jsx)(`span`,{className:`text-bambu-gray`,children:e.weight_used>0?qn(e.weight_used):`-`})]})]}),e.location_id&&(0,Y.jsx)(dr,{locationId:e.location_id,locationName:e.storage_location??null,isLast:!e.note,colorize:s,aboveColor:c,belowColor:l,optimalColor:u}),e.note&&(0,Y.jsx)(`div`,{className:`text-xs text-bambu-gray/60 pt-3 border-t border-bambu-dark-tertiary truncate`,title:e.note,children:e.note})]})]})}var sr={temperature:0,humidity:1,battery:2};function cr(e){return e===`humidity`?`mr-[2px]`:e===`battery`?`mr-[3px]`:``}function lr(e,t){return h(e,t,{decimals:2})}function ur(e,t,n,r,i){return t&&L(ie(e),n,r,i)||`text-bambu-gray`}function dr({locationId:e,locationName:t,isLast:n,colorize:i,aboveColor:a,belowColor:o,optimalColor:s}){let{t:l}=c(),{data:d}=u({queryKey:[`settings`],queryFn:r.getSettings}),f=(d?.location_sensor_poll_interval||120)*1e3,{data:p}=u({queryKey:[`locationHaSensors`],queryFn:()=>r.getLocationHASensors()}),m=(p??[]).some(t=>t.location_id===e),{data:h}=u({queryKey:[`locationHaSensorReadings`,e],queryFn:()=>r.getLocationHASensorReadings(e,!1),refetchInterval:f,enabled:m}),_=h?.filter(e=>e.show_on_card);if(!_?.length)return null;let v=_.find(e=>e.device_class===`battery`),y=_.filter(e=>e.device_class!==`battery`).sort((e,t)=>(sr[e.device_class??``]??99)-(sr[t.device_class??``]??99));return(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 pt-3 border-t border-bambu-dark-tertiary text-xs text-bambu-gray ${n?`-mb-1`:``}`,children:[t&&(0,Y.jsx)(`span`,{className:`truncate`,children:t}),(0,Y.jsx)(`span`,{className:`text-bambu-gray/40`,children:`|`}),(0,Y.jsx)(`div`,{className:`flex items-center gap-3`,children:y.map((e,t)=>{let n=g(e),r=t===0?`ml-[-3.6px]`:``;return(0,Y.jsxs)(`span`,{title:e.name,className:`flex items-center gap-[3px]`,children:[(0,Y.jsx)(n,{className:`w-3 h-3 ${cr(e.device_class)} ${r}`}),(0,Y.jsx)(`span`,{className:ur(e,i,a,o,s),children:lr(e,l)})]},e.id)})}),v&&(()=>{let e=g(v);return(0,Y.jsxs)(`span`,{title:v.name,className:`flex items-center gap-[3px] ml-auto`,children:[(0,Y.jsx)(e,{className:`w-3 h-3 ${cr(v.device_class)}`}),(0,Y.jsx)(`span`,{className:ur(v,i,a,o,s),children:lr(v,l)})]},v.id)})()]})}function fr({spool:e,remaining:t,pct:n,isSelected:r,onToggleSelected:i,onEdit:a,onCopy:o,onRestore:s,onArchive:c,onDelete:l,onPrintLabel:u,onResetConsumedCounter:d,visibleColumns:f,assignmentMap:p,catalogMap:m,locationReadingsMap:h,currencySymbol:g,dateFormat:_,t:v,onSyncWeight:y,colorizeLocationSensors:b,locationSensorAboveColor:x,locationSensorBelowColor:C,locationSensorOptimalColor:w}){return(0,Y.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/50 hover:bg-bambu-dark-tertiary/30 transition-colors cursor-pointer ${e.archived_at?`opacity-50`:``} ${r?`bg-bambu-green/10`:``}`,onClick:a,children:[(0,Y.jsx)(`td`,{className:`w-10 px-3 py-3`,onClick:e=>e.stopPropagation(),children:i&&(0,Y.jsx)(`input`,{type:`checkbox`,className:`h-4 w-4 cursor-pointer`,"aria-label":v(`inventory.bulk.selectRow`),checked:!!r,onChange:i})}),f.map(r=>(0,Y.jsx)(`td`,{className:`py-3 px-4`,children:Qn[r]?.({spool:e,remaining:t,pct:n,assignmentMap:p,catalogMap:m,locationReadingsMap:h,currencySymbol:g,dateFormat:_,t:v,onSyncWeight:y,colorizeLocationSensors:b,locationSensorAboveColor:x,locationSensorBelowColor:C,locationSensorOptimalColor:w})},r)),(0,Y.jsx)(`td`,{className:`py-3 px-4`,children:(0,Y.jsxs)(`div`,{className:`flex items-center justify-end gap-1`,onClick:e=>e.stopPropagation(),children:[(0,Y.jsx)(`button`,{onClick:a,className:`p-1.5 text-bambu-gray hover:text-white rounded transition-colors`,title:v(`common.edit`),children:(0,Y.jsx)(I,{className:`w-4 h-4`})}),o&&(0,Y.jsx)(`button`,{onClick:o,className:`p-1.5 text-bambu-gray hover:text-bambu-green rounded transition-colors`,title:v(`inventory.copySpool`),children:(0,Y.jsx)(M,{className:`w-4 h-4`})}),u&&(0,Y.jsx)(`button`,{onClick:u,className:`p-1.5 text-bambu-gray hover:text-white rounded transition-colors`,title:v(`inventory.labels.printOne`),children:(0,Y.jsx)(U,{className:`w-4 h-4`})}),d&&e.weight_used>0&&(0,Y.jsx)(`button`,{onClick:d,className:`p-1.5 text-bambu-gray hover:text-orange-600 dark:hover:text-orange-400 rounded transition-colors`,title:v(`inventory.resetConsumedCounterTooltip`),children:(0,Y.jsx)(S,{className:`w-4 h-4`})}),e.archived_at?(0,Y.jsx)(`button`,{onClick:s,className:`p-1.5 text-bambu-gray hover:text-bambu-green rounded transition-colors`,title:v(`inventory.restore`),children:(0,Y.jsx)(Se,{className:`w-4 h-4`})}):(0,Y.jsx)(`button`,{onClick:c,className:`p-1.5 text-bambu-gray hover:text-yellow-600 dark:hover:text-yellow-400 rounded transition-colors`,title:v(`inventory.archive`),children:(0,Y.jsx)(Te,{className:`w-4 h-4`})}),(0,Y.jsx)(`button`,{onClick:l,className:`p-1.5 text-bambu-gray hover:text-red-600 dark:hover:text-red-400 rounded transition-colors`,title:v(`common.delete`),children:(0,Y.jsx)(be,{className:`w-4 h-4`})})]})})]})}function pr({spools:e,headerSpool:t,remaining:n,pct:r,isExpanded:i,onToggle:a,onEdit:o,onCopy:s,onArchive:c,onDelete:l,onPrintLabel:u,onResetConsumedCounter:d,visibleColumns:f,assignmentMap:p,catalogMap:m,locationReadingsMap:h,currencySymbol:g,dateFormat:_,t:v,onSyncWeight:y,colorizeLocationSensors:b,locationSensorAboveColor:x,locationSensorBelowColor:S,locationSensorOptimalColor:C,selectedIds:w,onToggleSelected:E,onToggleGroupSelected:D}){let O=!!w&&e.every(e=>w.has(e.id));return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/50 hover:bg-bambu-dark-tertiary/30 transition-colors cursor-pointer bg-bambu-green/5`,onClick:a,children:[(0,Y.jsx)(`td`,{className:`w-10 px-3 py-3`,onClick:e=>e.stopPropagation(),children:D&&(0,Y.jsx)(`input`,{type:`checkbox`,className:`h-4 w-4 cursor-pointer`,"aria-label":v(`inventory.bulk.selectGroup`),checked:O,onChange:t=>D(e.map(e=>e.id),t.target.checked)})}),f.map((a,o)=>(0,Y.jsx)(`td`,{className:`py-3 px-4`,children:o===0?(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(T,{className:`w-4 h-4 text-bambu-gray transition-transform ${i?``:`-rotate-90`}`}),Qn[a]?.({spool:t,remaining:n,pct:r,assignmentMap:p,catalogMap:m,locationReadingsMap:h,currencySymbol:g,dateFormat:_,t:v,onSyncWeight:y,colorizeLocationSensors:b,locationSensorAboveColor:x,locationSensorBelowColor:S,locationSensorOptimalColor:C})]}):a===`id`?(0,Y.jsx)(`span`,{className:`text-xs font-medium bg-bambu-green/20 text-bambu-green px-2 py-0.5 rounded-full`,children:v(`inventory.groupedSpools`,{count:e.length})}):Qn[a]?.({spool:t,remaining:n,pct:r,assignmentMap:p,catalogMap:m,locationReadingsMap:h,currencySymbol:g,dateFormat:_,t:v,onSyncWeight:y,colorizeLocationSensors:b,locationSensorAboveColor:x,locationSensorBelowColor:S,locationSensorOptimalColor:C})},a)),(0,Y.jsx)(`td`,{className:`py-3 px-4`,children:(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:e.map(e=>`#${e.id}`).join(`, `)})})]}),i&&e.map(e=>{let t=Math.max(0,e.label_weight-e.weight_used);return(0,Y.jsx)(fr,{spool:e,remaining:t,pct:e.label_weight>0?t/e.label_weight*100:0,isSelected:w?.has(e.id),onToggleSelected:E?()=>E(e.id):void 0,onEdit:()=>o(e),onCopy:s?()=>s(e):void 0,onRestore:()=>{},onArchive:()=>c(e.id),onDelete:()=>l(e.id),onPrintLabel:u?()=>u(e.id):void 0,onResetConsumedCounter:d?()=>d(e.id):void 0,visibleColumns:f,assignmentMap:p,catalogMap:m,locationReadingsMap:h,currencySymbol:g,dateFormat:_,t:v,onSyncWeight:y,colorizeLocationSensors:b,locationSensorAboveColor:x,locationSensorBelowColor:S,locationSensorOptimalColor:C},e.id)})]})}function mr({hasFilters:e,onAddSpool:t,t:n}){return(0,Y.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-16 px-4`,children:[(0,Y.jsxs)(`div`,{className:`relative mb-6`,children:[(0,Y.jsx)(`div`,{className:`absolute inset-0 -m-4 bg-bambu-green/5 rounded-full blur-2xl`}),(0,Y.jsxs)(`div`,{className:`relative flex items-center justify-center w-24 h-24 rounded-2xl bg-gradient-to-br from-bambu-dark-secondary to-bambu-dark-tertiary border border-bambu-dark-tertiary shadow-lg`,children:[(0,Y.jsx)(`div`,{className:`absolute -top-1 -right-1 w-3 h-3 rounded-full bg-bambu-green/30`}),(0,Y.jsx)(`div`,{className:`absolute -bottom-2 -left-2 w-2 h-2 rounded-full bg-bambu-green/20`}),e?(0,Y.jsx)(se,{className:`w-10 h-10 text-bambu-gray/40`,strokeWidth:1.5}):(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsx)(`div`,{className:`w-14 h-14 rounded-full border-4 border-bambu-gray/20 flex items-center justify-center`,children:(0,Y.jsx)(`div`,{className:`w-6 h-6 rounded-full bg-bambu-gray/10 border-2 border-bambu-gray/20`})}),(0,Y.jsx)(`div`,{className:`absolute -bottom-1 -right-1 w-6 h-6 rounded-full bg-bambu-green flex items-center justify-center shadow-md`,children:(0,Y.jsx)(`span`,{className:`text-white text-lg font-bold leading-none`,children:`+`})})]})]})]}),(0,Y.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-2 text-center`,children:e?n(`inventory.noSpoolsMatch`):n(`inventory.noSpools`).split(`.`)[0]}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray text-center max-w-sm mb-6`,children:n(e?`inventory.noSpoolsMatchDesc`:`inventory.noSpools`)}),!e&&(0,Y.jsxs)(V,{onClick:t,children:[(0,Y.jsx)(oe,{className:`w-4 h-4`}),n(`inventory.addSpool`)]})]})}export{rr as default}; \ No newline at end of file diff --git a/static/assets/LibraryTrashPage-GKtQzVNm.js b/static/assets/LibraryTrashPage-zY9GRWm9.js similarity index 99% rename from static/assets/LibraryTrashPage-GKtQzVNm.js rename to static/assets/LibraryTrashPage-zY9GRWm9.js index cc79e8408..5c4d91f83 100644 --- a/static/assets/LibraryTrashPage-GKtQzVNm.js +++ b/static/assets/LibraryTrashPage-zY9GRWm9.js @@ -1 +1 @@ -import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,w as i}from"./client-DnySrlFv.js";import{n as a}from"./QueryClientProvider-Ce8_sN3w.js";import{t as o}from"./useQuery-BBCjCezC.js";import{t as s}from"./useMutation-B-Tr2hIP.js";import{t as c}from"./arrow-left-0Q6F2rjC.js";import{n as l}from"./ToastContext-BRX0SW3C.js";import{t as u}from"./loader-circle-BEmFtawu.js";import{t as d}from"./file-DDkFXH-b.js";import{t as f}from"./Button-DDr6eAFy.js";import{v as p}from"./date-G9KUauqz.js";import{At as m,Gt as h,Rn as g,Ut as _,Vn as v,_t as y,yt as b}from"./index-0t--Yqoi.js";var x=e(n(),1),S=t();function C(e){let t=p(e);if(!t)return``;let n=Math.ceil((t.getTime()-Date.now())/(1e3*60*60*24));return n<=0?`any moment`:n===1?`1 day`:`${n} days`}function w(e){let t=p(e);return t?t.toLocaleString():e}function T(){let{t:e}=i(),t=v(),n=a(),{showToast:p}=l(),{hasPermission:T,authEnabled:E}=b(),[D,O]=(0,x.useState)(null),[k,A]=(0,x.useState)(new Set),j=!E||T(`library:purge`),M=o({queryKey:[`library-trash`],queryFn:()=>r.listLibraryTrash(200,0)}),N=o({queryKey:[`library-trash-settings`],queryFn:()=>r.getLibraryTrashSettings(),enabled:j}),[P,F]=(0,x.useState)(null);(0,x.useEffect)(()=>{N.data&&P===null&&F(N.data.retention_days)},[N.data,P]);let I=s({mutationFn:e=>{let t=N.data;return r.updateLibraryTrashSettings({retention_days:e,auto_purge_enabled:t?.auto_purge_enabled??!1,auto_purge_days:t?.auto_purge_days??90,auto_purge_include_never_printed:t?.auto_purge_include_never_printed??!0})},onSuccess:t=>{p(e(`libraryTrash.toast.retentionSaved`,{days:t.retention_days}),`success`),n.invalidateQueries({queryKey:[`library-trash-settings`]}),n.invalidateQueries({queryKey:[`library-trash`]})},onError:t=>p(t.message||e(`libraryTrash.toast.retentionFailed`),`error`)}),L=s({mutationFn:e=>r.restoreLibraryTrash(e),onSuccess:()=>{p(e(`libraryTrash.toast.restored`),`success`),n.invalidateQueries({queryKey:[`library-trash`]}),n.invalidateQueries({queryKey:[`library-trash-count`]}),n.invalidateQueries({queryKey:[`library-files`]}),n.invalidateQueries({queryKey:[`library-folders`]})},onError:t=>p(t.message||e(`libraryTrash.toast.restoreFailed`),`error`)}),R=s({mutationFn:e=>r.hardDeleteLibraryTrash(e),onSuccess:()=>{p(e(`libraryTrash.toast.purged`),`success`),n.invalidateQueries({queryKey:[`library-trash`]}),n.invalidateQueries({queryKey:[`library-trash-count`]})},onError:t=>p(t.message||e(`libraryTrash.toast.purgeFailed`),`error`)}),z=s({mutationFn:()=>r.emptyLibraryTrash(),onSuccess:t=>{p(e(`libraryTrash.toast.emptied`,{count:t.deleted}),`success`),n.invalidateQueries({queryKey:[`library-trash`]}),n.invalidateQueries({queryKey:[`library-trash-count`]})},onError:t=>p(t.message||e(`libraryTrash.toast.emptyFailed`),`error`)}),B=s({mutationFn:e=>Promise.all(e.map(e=>r.restoreLibraryTrash(e))),onSuccess:(t,r)=>{p(e(`libraryTrash.toast.bulkRestored`,{count:r.length}),`success`),A(new Set),n.invalidateQueries({queryKey:[`library-trash`]}),n.invalidateQueries({queryKey:[`library-trash-count`]}),n.invalidateQueries({queryKey:[`library-files`]}),n.invalidateQueries({queryKey:[`library-folders`]})},onError:t=>p(t.message||e(`libraryTrash.toast.restoreFailed`),`error`)}),V=s({mutationFn:e=>Promise.all(e.map(e=>r.hardDeleteLibraryTrash(e))),onSuccess:(t,r)=>{p(e(`libraryTrash.toast.bulkPurged`,{count:r.length}),`success`),A(new Set),n.invalidateQueries({queryKey:[`library-trash`]}),n.invalidateQueries({queryKey:[`library-trash-count`]})},onError:t=>p(t.message||e(`libraryTrash.toast.purgeFailed`),`error`)}),H=(0,x.useMemo)(()=>M.data?.items??[],[M.data?.items]),U=M.data?.retention_days??30,W=(0,x.useMemo)(()=>H.reduce((e,t)=>e+t.file_size,0),[H]),G=H.length>0&&H.every(e=>k.has(e.id)),K=k.size>0&&!G,q=e=>{A(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};return(0,S.jsxs)(`div`,{className:`p-6 max-w-screen-2xl mx-auto`,children:[(0,S.jsx)(`div`,{className:`flex items-center gap-3 mb-4`,children:(0,S.jsxs)(g,{to:`/files`,className:`inline-flex items-center gap-1 text-sm text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-gray-200`,children:[(0,S.jsx)(c,{className:`w-4 h-4`}),` `,e(`libraryTrash.backToFiles`)]})}),(0,S.jsxs)(`div`,{className:`flex items-start justify-between mb-6 gap-4 flex-wrap`,children:[(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`h1`,{className:`text-2xl font-bold text-gray-900 dark:text-gray-100`,children:e(`libraryTrash.title`)}),(0,S.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400 mt-1`,children:e(j?`libraryTrash.subtitleAdmin`:`libraryTrash.subtitleUser`,{days:U})})]}),H.length>0&&(0,S.jsxs)(f,{variant:`secondary`,onClick:()=>O({type:`empty`}),className:`text-red-600 dark:text-red-400`,children:[(0,S.jsx)(m,{className:`w-4 h-4 mr-1`}),e(`libraryTrash.emptyTrash`)]})]}),j&&N.data&&(0,S.jsxs)(`div`,{className:`mb-4 border border-gray-200 dark:border-gray-700 rounded-lg p-3 flex items-center gap-3 bg-gray-50 dark:bg-gray-800/40`,children:[(0,S.jsx)(`label`,{htmlFor:`retention-days`,className:`text-sm font-medium text-gray-700 dark:text-gray-300`,children:e(`libraryTrash.retentionLabel`)}),(0,S.jsx)(`input`,{id:`retention-days`,type:`number`,min:1,max:365,value:P??N.data.retention_days,onChange:e=>F(Math.max(1,Math.min(365,parseInt(e.target.value||`0`,10)||0))),className:`w-20 rounded border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-800 text-sm px-2 py-1 text-gray-900 dark:text-gray-100`}),(0,S.jsx)(`span`,{className:`text-sm text-gray-600 dark:text-gray-400`,children:e(`libraryTrash.days`)}),(0,S.jsxs)(f,{variant:`secondary`,onClick:()=>P!=null&&I.mutate(P),disabled:I.isPending||P==null||P===N.data.retention_days,className:`ml-auto`,children:[(0,S.jsx)(_,{className:`w-4 h-4 mr-1`}),e(`common.save`)]})]}),M.isLoading?(0,S.jsxs)(`div`,{className:`flex items-center gap-2 text-gray-500 dark:text-gray-400`,children:[(0,S.jsx)(u,{className:`w-4 h-4 animate-spin`}),` `,e(`libraryTrash.loading`)]}):H.length===0?(0,S.jsx)(`div`,{className:`border border-dashed border-gray-300 dark:border-gray-700 rounded-lg p-12 text-center`,children:(0,S.jsx)(`p`,{className:`text-gray-500 dark:text-gray-400`,children:e(`libraryTrash.empty`)})}):(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,S.jsx)(`div`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:e(`libraryTrash.summary`,{count:H.length,size:d(W)})}),k.size>0&&(0,S.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,S.jsx)(`span`,{className:`text-gray-600 dark:text-gray-400`,children:e(`libraryTrash.selectionCount`,{count:k.size})}),(0,S.jsxs)(f,{variant:`secondary`,onClick:()=>B.mutate(Array.from(k)),disabled:B.isPending,children:[(0,S.jsx)(h,{className:`w-4 h-4 mr-1`}),e(`libraryTrash.bulkRestore`)]}),(0,S.jsxs)(f,{variant:`secondary`,onClick:()=>O({type:`bulkDelete`,count:k.size}),disabled:V.isPending,className:`text-red-600 dark:text-red-400`,children:[(0,S.jsx)(m,{className:`w-4 h-4 mr-1`}),e(`libraryTrash.bulkPurge`)]})]})]}),(0,S.jsx)(`div`,{className:`border border-gray-200 dark:border-gray-700 rounded-lg overflow-x-auto`,children:(0,S.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,S.jsx)(`thead`,{className:`bg-gray-50 dark:bg-gray-800 text-left text-gray-600 dark:text-gray-300`,children:(0,S.jsxs)(`tr`,{children:[(0,S.jsx)(`th`,{className:`px-3 py-2 w-10`,children:(0,S.jsx)(`input`,{type:`checkbox`,checked:G,ref:e=>{e&&(e.indeterminate=K)},onChange:()=>{A(e=>e.size===H.length?new Set:new Set(H.map(e=>e.id)))},"aria-label":e(`libraryTrash.selectAll`),className:`rounded border-gray-300 cursor-pointer`})}),(0,S.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:e(`libraryTrash.col.filename`)}),(0,S.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:e(`libraryTrash.col.folder`)}),(0,S.jsx)(`th`,{className:`px-3 py-2 font-medium text-right`,children:e(`libraryTrash.col.size`)}),(0,S.jsx)(`th`,{className:`px-3 py-2 font-medium whitespace-nowrap`,children:e(`libraryTrash.col.deleted`)}),(0,S.jsx)(`th`,{className:`px-3 py-2 font-medium whitespace-nowrap`,children:e(`libraryTrash.col.autoPurge`)}),j&&(0,S.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:e(`libraryTrash.col.owner`)}),(0,S.jsx)(`th`,{className:`px-3 py-2 font-medium text-right`,children:e(`libraryTrash.col.actions`)})]})}),(0,S.jsx)(`tbody`,{className:`divide-y divide-gray-100 dark:divide-gray-800`,children:H.map(t=>(0,S.jsxs)(`tr`,{className:`hover:bg-gray-50 dark:hover:bg-gray-800/50`,children:[(0,S.jsx)(`td`,{className:`px-3 py-2`,children:(0,S.jsx)(`input`,{type:`checkbox`,checked:k.has(t.id),onChange:()=>q(t.id),"aria-label":e(`libraryTrash.selectOne`,{filename:t.filename}),className:`rounded border-gray-300 cursor-pointer`})}),(0,S.jsx)(`td`,{className:`px-3 py-2 text-gray-900 dark:text-gray-100 truncate max-w-md`,title:t.filename,children:t.filename}),(0,S.jsx)(`td`,{className:`px-3 py-2 text-gray-600 dark:text-gray-400`,children:t.folder_name??`—`}),(0,S.jsx)(`td`,{className:`px-3 py-2 text-right text-gray-600 dark:text-gray-400 tabular-nums whitespace-nowrap`,children:d(t.file_size)}),(0,S.jsx)(`td`,{className:`px-3 py-2 text-gray-600 dark:text-gray-400 whitespace-nowrap`,children:w(t.deleted_at)}),(0,S.jsx)(`td`,{className:`px-3 py-2 text-gray-600 dark:text-gray-400 whitespace-nowrap`,children:(0,S.jsx)(`span`,{title:w(t.auto_purge_at),children:e(`libraryTrash.autoPurgeIn`,{when:C(t.auto_purge_at)})})}),j&&(0,S.jsx)(`td`,{className:`px-3 py-2 text-gray-600 dark:text-gray-400`,children:t.created_by_username??`—`}),(0,S.jsxs)(`td`,{className:`px-3 py-2 text-right whitespace-nowrap`,children:[(0,S.jsxs)(`button`,{onClick:()=>L.mutate(t.id),disabled:L.isPending,className:`inline-flex items-center gap-1 px-2 py-1 text-xs text-blue-600 hover:text-blue-800 dark:text-blue-400 dark:hover:text-blue-300`,children:[(0,S.jsx)(h,{className:`w-3.5 h-3.5`}),e(`libraryTrash.restore`)]}),(0,S.jsxs)(`button`,{onClick:()=>O({type:`delete`,id:t.id,filename:t.filename}),disabled:R.isPending,className:`inline-flex items-center gap-1 px-2 py-1 text-xs text-red-600 hover:text-red-800 dark:text-red-400 dark:hover:text-red-300 ml-2`,children:[(0,S.jsx)(m,{className:`w-3.5 h-3.5`}),e(`libraryTrash.purgeNow`)]})]})]},t.id))})]})})]}),D&&(0,S.jsx)(y,{onCancel:()=>O(null),onConfirm:()=>{D&&(D.type===`delete`?R.mutate(D.id):D.type===`bulkDelete`?V.mutate(Array.from(k)):z.mutate(),O(null))},title:D.type===`delete`?e(`libraryTrash.confirm.purgeTitle`):D.type===`bulkDelete`?e(`libraryTrash.confirm.bulkPurgeTitle`):e(`libraryTrash.confirm.emptyTitle`),message:D.type===`delete`?e(`libraryTrash.confirm.purgeBody`,{filename:D.filename}):D.type===`bulkDelete`?e(`libraryTrash.confirm.bulkPurgeBody`,{count:D.count}):e(`libraryTrash.confirm.emptyBody`,{count:H.length}),confirmText:e(`libraryTrash.confirm.cta`),variant:`danger`}),M.isError&&(0,S.jsxs)(`div`,{className:`mt-4 text-sm text-red-600 dark:text-red-400`,children:[M.error?.message??e(`libraryTrash.loadError`),(0,S.jsx)(f,{variant:`secondary`,onClick:()=>t(`/files`),className:`ml-3`,children:e(`libraryTrash.backToFiles`)})]})]})}export{T as LibraryTrashPage}; \ No newline at end of file +import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,w as i}from"./client-DnySrlFv.js";import{n as a}from"./QueryClientProvider-Ce8_sN3w.js";import{t as o}from"./useQuery-BBCjCezC.js";import{t as s}from"./useMutation-B-Tr2hIP.js";import{t as c}from"./arrow-left-0Q6F2rjC.js";import{n as l}from"./ToastContext-BRX0SW3C.js";import{t as u}from"./loader-circle-BEmFtawu.js";import{t as d}from"./file-DDkFXH-b.js";import{t as f}from"./Button-DDr6eAFy.js";import{v as p}from"./date-G9KUauqz.js";import{At as m,Gt as h,Rn as g,Ut as _,Vn as v,_t as y,yt as b}from"./index-Cxa-KVmA.js";var x=e(n(),1),S=t();function C(e){let t=p(e);if(!t)return``;let n=Math.ceil((t.getTime()-Date.now())/(1e3*60*60*24));return n<=0?`any moment`:n===1?`1 day`:`${n} days`}function w(e){let t=p(e);return t?t.toLocaleString():e}function T(){let{t:e}=i(),t=v(),n=a(),{showToast:p}=l(),{hasPermission:T,authEnabled:E}=b(),[D,O]=(0,x.useState)(null),[k,A]=(0,x.useState)(new Set),j=!E||T(`library:purge`),M=o({queryKey:[`library-trash`],queryFn:()=>r.listLibraryTrash(200,0)}),N=o({queryKey:[`library-trash-settings`],queryFn:()=>r.getLibraryTrashSettings(),enabled:j}),[P,F]=(0,x.useState)(null);(0,x.useEffect)(()=>{N.data&&P===null&&F(N.data.retention_days)},[N.data,P]);let I=s({mutationFn:e=>{let t=N.data;return r.updateLibraryTrashSettings({retention_days:e,auto_purge_enabled:t?.auto_purge_enabled??!1,auto_purge_days:t?.auto_purge_days??90,auto_purge_include_never_printed:t?.auto_purge_include_never_printed??!0})},onSuccess:t=>{p(e(`libraryTrash.toast.retentionSaved`,{days:t.retention_days}),`success`),n.invalidateQueries({queryKey:[`library-trash-settings`]}),n.invalidateQueries({queryKey:[`library-trash`]})},onError:t=>p(t.message||e(`libraryTrash.toast.retentionFailed`),`error`)}),L=s({mutationFn:e=>r.restoreLibraryTrash(e),onSuccess:()=>{p(e(`libraryTrash.toast.restored`),`success`),n.invalidateQueries({queryKey:[`library-trash`]}),n.invalidateQueries({queryKey:[`library-trash-count`]}),n.invalidateQueries({queryKey:[`library-files`]}),n.invalidateQueries({queryKey:[`library-folders`]})},onError:t=>p(t.message||e(`libraryTrash.toast.restoreFailed`),`error`)}),R=s({mutationFn:e=>r.hardDeleteLibraryTrash(e),onSuccess:()=>{p(e(`libraryTrash.toast.purged`),`success`),n.invalidateQueries({queryKey:[`library-trash`]}),n.invalidateQueries({queryKey:[`library-trash-count`]})},onError:t=>p(t.message||e(`libraryTrash.toast.purgeFailed`),`error`)}),z=s({mutationFn:()=>r.emptyLibraryTrash(),onSuccess:t=>{p(e(`libraryTrash.toast.emptied`,{count:t.deleted}),`success`),n.invalidateQueries({queryKey:[`library-trash`]}),n.invalidateQueries({queryKey:[`library-trash-count`]})},onError:t=>p(t.message||e(`libraryTrash.toast.emptyFailed`),`error`)}),B=s({mutationFn:e=>Promise.all(e.map(e=>r.restoreLibraryTrash(e))),onSuccess:(t,r)=>{p(e(`libraryTrash.toast.bulkRestored`,{count:r.length}),`success`),A(new Set),n.invalidateQueries({queryKey:[`library-trash`]}),n.invalidateQueries({queryKey:[`library-trash-count`]}),n.invalidateQueries({queryKey:[`library-files`]}),n.invalidateQueries({queryKey:[`library-folders`]})},onError:t=>p(t.message||e(`libraryTrash.toast.restoreFailed`),`error`)}),V=s({mutationFn:e=>Promise.all(e.map(e=>r.hardDeleteLibraryTrash(e))),onSuccess:(t,r)=>{p(e(`libraryTrash.toast.bulkPurged`,{count:r.length}),`success`),A(new Set),n.invalidateQueries({queryKey:[`library-trash`]}),n.invalidateQueries({queryKey:[`library-trash-count`]})},onError:t=>p(t.message||e(`libraryTrash.toast.purgeFailed`),`error`)}),H=(0,x.useMemo)(()=>M.data?.items??[],[M.data?.items]),U=M.data?.retention_days??30,W=(0,x.useMemo)(()=>H.reduce((e,t)=>e+t.file_size,0),[H]),G=H.length>0&&H.every(e=>k.has(e.id)),K=k.size>0&&!G,q=e=>{A(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};return(0,S.jsxs)(`div`,{className:`p-6 max-w-screen-2xl mx-auto`,children:[(0,S.jsx)(`div`,{className:`flex items-center gap-3 mb-4`,children:(0,S.jsxs)(g,{to:`/files`,className:`inline-flex items-center gap-1 text-sm text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-gray-200`,children:[(0,S.jsx)(c,{className:`w-4 h-4`}),` `,e(`libraryTrash.backToFiles`)]})}),(0,S.jsxs)(`div`,{className:`flex items-start justify-between mb-6 gap-4 flex-wrap`,children:[(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`h1`,{className:`text-2xl font-bold text-gray-900 dark:text-gray-100`,children:e(`libraryTrash.title`)}),(0,S.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400 mt-1`,children:e(j?`libraryTrash.subtitleAdmin`:`libraryTrash.subtitleUser`,{days:U})})]}),H.length>0&&(0,S.jsxs)(f,{variant:`secondary`,onClick:()=>O({type:`empty`}),className:`text-red-600 dark:text-red-400`,children:[(0,S.jsx)(m,{className:`w-4 h-4 mr-1`}),e(`libraryTrash.emptyTrash`)]})]}),j&&N.data&&(0,S.jsxs)(`div`,{className:`mb-4 border border-gray-200 dark:border-gray-700 rounded-lg p-3 flex items-center gap-3 bg-gray-50 dark:bg-gray-800/40`,children:[(0,S.jsx)(`label`,{htmlFor:`retention-days`,className:`text-sm font-medium text-gray-700 dark:text-gray-300`,children:e(`libraryTrash.retentionLabel`)}),(0,S.jsx)(`input`,{id:`retention-days`,type:`number`,min:1,max:365,value:P??N.data.retention_days,onChange:e=>F(Math.max(1,Math.min(365,parseInt(e.target.value||`0`,10)||0))),className:`w-20 rounded border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-800 text-sm px-2 py-1 text-gray-900 dark:text-gray-100`}),(0,S.jsx)(`span`,{className:`text-sm text-gray-600 dark:text-gray-400`,children:e(`libraryTrash.days`)}),(0,S.jsxs)(f,{variant:`secondary`,onClick:()=>P!=null&&I.mutate(P),disabled:I.isPending||P==null||P===N.data.retention_days,className:`ml-auto`,children:[(0,S.jsx)(_,{className:`w-4 h-4 mr-1`}),e(`common.save`)]})]}),M.isLoading?(0,S.jsxs)(`div`,{className:`flex items-center gap-2 text-gray-500 dark:text-gray-400`,children:[(0,S.jsx)(u,{className:`w-4 h-4 animate-spin`}),` `,e(`libraryTrash.loading`)]}):H.length===0?(0,S.jsx)(`div`,{className:`border border-dashed border-gray-300 dark:border-gray-700 rounded-lg p-12 text-center`,children:(0,S.jsx)(`p`,{className:`text-gray-500 dark:text-gray-400`,children:e(`libraryTrash.empty`)})}):(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,S.jsx)(`div`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:e(`libraryTrash.summary`,{count:H.length,size:d(W)})}),k.size>0&&(0,S.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,S.jsx)(`span`,{className:`text-gray-600 dark:text-gray-400`,children:e(`libraryTrash.selectionCount`,{count:k.size})}),(0,S.jsxs)(f,{variant:`secondary`,onClick:()=>B.mutate(Array.from(k)),disabled:B.isPending,children:[(0,S.jsx)(h,{className:`w-4 h-4 mr-1`}),e(`libraryTrash.bulkRestore`)]}),(0,S.jsxs)(f,{variant:`secondary`,onClick:()=>O({type:`bulkDelete`,count:k.size}),disabled:V.isPending,className:`text-red-600 dark:text-red-400`,children:[(0,S.jsx)(m,{className:`w-4 h-4 mr-1`}),e(`libraryTrash.bulkPurge`)]})]})]}),(0,S.jsx)(`div`,{className:`border border-gray-200 dark:border-gray-700 rounded-lg overflow-x-auto`,children:(0,S.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,S.jsx)(`thead`,{className:`bg-gray-50 dark:bg-gray-800 text-left text-gray-600 dark:text-gray-300`,children:(0,S.jsxs)(`tr`,{children:[(0,S.jsx)(`th`,{className:`px-3 py-2 w-10`,children:(0,S.jsx)(`input`,{type:`checkbox`,checked:G,ref:e=>{e&&(e.indeterminate=K)},onChange:()=>{A(e=>e.size===H.length?new Set:new Set(H.map(e=>e.id)))},"aria-label":e(`libraryTrash.selectAll`),className:`rounded border-gray-300 cursor-pointer`})}),(0,S.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:e(`libraryTrash.col.filename`)}),(0,S.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:e(`libraryTrash.col.folder`)}),(0,S.jsx)(`th`,{className:`px-3 py-2 font-medium text-right`,children:e(`libraryTrash.col.size`)}),(0,S.jsx)(`th`,{className:`px-3 py-2 font-medium whitespace-nowrap`,children:e(`libraryTrash.col.deleted`)}),(0,S.jsx)(`th`,{className:`px-3 py-2 font-medium whitespace-nowrap`,children:e(`libraryTrash.col.autoPurge`)}),j&&(0,S.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:e(`libraryTrash.col.owner`)}),(0,S.jsx)(`th`,{className:`px-3 py-2 font-medium text-right`,children:e(`libraryTrash.col.actions`)})]})}),(0,S.jsx)(`tbody`,{className:`divide-y divide-gray-100 dark:divide-gray-800`,children:H.map(t=>(0,S.jsxs)(`tr`,{className:`hover:bg-gray-50 dark:hover:bg-gray-800/50`,children:[(0,S.jsx)(`td`,{className:`px-3 py-2`,children:(0,S.jsx)(`input`,{type:`checkbox`,checked:k.has(t.id),onChange:()=>q(t.id),"aria-label":e(`libraryTrash.selectOne`,{filename:t.filename}),className:`rounded border-gray-300 cursor-pointer`})}),(0,S.jsx)(`td`,{className:`px-3 py-2 text-gray-900 dark:text-gray-100 truncate max-w-md`,title:t.filename,children:t.filename}),(0,S.jsx)(`td`,{className:`px-3 py-2 text-gray-600 dark:text-gray-400`,children:t.folder_name??`—`}),(0,S.jsx)(`td`,{className:`px-3 py-2 text-right text-gray-600 dark:text-gray-400 tabular-nums whitespace-nowrap`,children:d(t.file_size)}),(0,S.jsx)(`td`,{className:`px-3 py-2 text-gray-600 dark:text-gray-400 whitespace-nowrap`,children:w(t.deleted_at)}),(0,S.jsx)(`td`,{className:`px-3 py-2 text-gray-600 dark:text-gray-400 whitespace-nowrap`,children:(0,S.jsx)(`span`,{title:w(t.auto_purge_at),children:e(`libraryTrash.autoPurgeIn`,{when:C(t.auto_purge_at)})})}),j&&(0,S.jsx)(`td`,{className:`px-3 py-2 text-gray-600 dark:text-gray-400`,children:t.created_by_username??`—`}),(0,S.jsxs)(`td`,{className:`px-3 py-2 text-right whitespace-nowrap`,children:[(0,S.jsxs)(`button`,{onClick:()=>L.mutate(t.id),disabled:L.isPending,className:`inline-flex items-center gap-1 px-2 py-1 text-xs text-blue-600 hover:text-blue-800 dark:text-blue-400 dark:hover:text-blue-300`,children:[(0,S.jsx)(h,{className:`w-3.5 h-3.5`}),e(`libraryTrash.restore`)]}),(0,S.jsxs)(`button`,{onClick:()=>O({type:`delete`,id:t.id,filename:t.filename}),disabled:R.isPending,className:`inline-flex items-center gap-1 px-2 py-1 text-xs text-red-600 hover:text-red-800 dark:text-red-400 dark:hover:text-red-300 ml-2`,children:[(0,S.jsx)(m,{className:`w-3.5 h-3.5`}),e(`libraryTrash.purgeNow`)]})]})]},t.id))})]})})]}),D&&(0,S.jsx)(y,{onCancel:()=>O(null),onConfirm:()=>{D&&(D.type===`delete`?R.mutate(D.id):D.type===`bulkDelete`?V.mutate(Array.from(k)):z.mutate(),O(null))},title:D.type===`delete`?e(`libraryTrash.confirm.purgeTitle`):D.type===`bulkDelete`?e(`libraryTrash.confirm.bulkPurgeTitle`):e(`libraryTrash.confirm.emptyTitle`),message:D.type===`delete`?e(`libraryTrash.confirm.purgeBody`,{filename:D.filename}):D.type===`bulkDelete`?e(`libraryTrash.confirm.bulkPurgeBody`,{count:D.count}):e(`libraryTrash.confirm.emptyBody`,{count:H.length}),confirmText:e(`libraryTrash.confirm.cta`),variant:`danger`}),M.isError&&(0,S.jsxs)(`div`,{className:`mt-4 text-sm text-red-600 dark:text-red-400`,children:[M.error?.message??e(`libraryTrash.loadError`),(0,S.jsx)(f,{variant:`secondary`,onClick:()=>t(`/files`),className:`ml-3`,children:e(`libraryTrash.backToFiles`)})]})]})}export{T as LibraryTrashPage}; \ No newline at end of file diff --git a/static/assets/LoginPage-rGUF5BC3.js b/static/assets/LoginPage-DXBBHPDD.js similarity index 99% rename from static/assets/LoginPage-rGUF5BC3.js rename to static/assets/LoginPage-DXBBHPDD.js index 0e15b780e..53a3359fd 100644 --- a/static/assets/LoginPage-rGUF5BC3.js +++ b/static/assets/LoginPage-DXBBHPDD.js @@ -1 +1 @@ -import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,w as i}from"./client-DnySrlFv.js";import{t as a}from"./useQuery-BBCjCezC.js";import{t as o}from"./useMutation-B-Tr2hIP.js";import{n as s}from"./ToastContext-BRX0SW3C.js";import{t as ee}from"./shield-bODVqOJd.js";import{t as te}from"./smartphone-DaDGaGLT.js";import{t as ne}from"./x-DR-Trv6U.js";import{i as re,n as ie,t as ae}from"./Card-Bzc64K35.js";import{t as c}from"./Button-DDr6eAFy.js";import{Bn as oe,Vn as se,Wn as ce,in as le,ln as ue,vt as de,yt as fe}from"./index-0t--Yqoi.js";var l=e(n(),1),u=t(),d=`auth_remember_me`,f=`auth_post_login_redirect`;function p(e){return e?`persistent`:`session`}function pe(){try{let e=sessionStorage.getItem(d)===`1`;return sessionStorage.removeItem(d),e}catch(e){return console.warn(`consumeSavedRememberMe: sessionStorage unavailable, Remember Me preference lost across OIDC redirect`,e),!1}}function m(e){return!e||!e.startsWith(`/`)||e.startsWith(`//`)||e.startsWith(`/login`)?null:e}function h(e){let t=m(e);if(t)try{sessionStorage.setItem(f,t)}catch(e){console.warn(`stashPostLoginRedirect: sessionStorage unavailable, post-login target will be lost across OIDC redirect`,e)}}function me(){try{let e=sessionStorage.getItem(f);return sessionStorage.removeItem(f),m(e)}catch(e){return console.warn(`consumePostLoginRedirect: sessionStorage unavailable`,e),null}}function he({provider:e,onClick:t,disabled:n}){let{t:a}=i(),[o,s]=(0,l.useState)(!1);return(0,u.jsxs)(`button`,{type:`button`,onClick:t,disabled:n,className:`w-full flex items-center justify-center gap-3 py-3 px-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary hover:border-bambu-green/50 rounded-lg text-white font-medium transition-colors disabled:opacity-50`,children:[e.has_icon&&!o?(0,u.jsx)(`img`,{src:r.oidcProviderIconUrl(e.id),alt:``,className:`w-5 h-5 object-contain`,onError:()=>s(!0)}):(0,u.jsx)(ee,{className:`w-5 h-5 text-bambu-green`}),a(`login.twoFA.signInWith`,{provider:e.name})]})}function g(){let e=se(),t=oe(),[n]=ce(),{t:f}=i(),{login:g,loginWithToken:_,user:v,loading:ge}=fe(),{showToast:y}=s(),{mode:_e}=de();function b(){let e=t.state?.from;if(e?.pathname){let t=m(`${e.pathname}${e.search??``}`);if(t)return t}return me()??`/`}let[x,ve]=(0,l.useState)(``),[S,ye]=(0,l.useState)(``),[be,C]=(0,l.useState)(!1),[w,T]=(0,l.useState)(``),[E,D]=(0,l.useState)(`credentials`),[O,k]=(0,l.useState)(``),[A,j]=(0,l.useState)([]),[M,N]=(0,l.useState)(`totp`),[P,F]=(0,l.useState)(``),[I,L]=(0,l.useState)(!1),xe=(0,l.useRef)(null),[R,z]=(0,l.useState)(!1),[Se,B]=(0,l.useState)(``),[V,H]=(0,l.useState)(``),[U,W]=(0,l.useState)(``),{data:G}=a({queryKey:[`advancedAuthStatus`],queryFn:()=>r.getAdvancedAuthStatus()}),{data:K}=a({queryKey:[`oidcProviders`],queryFn:()=>r.getOIDCProviders()}),[Ce,we]=(0,l.useState)(!1);(0,l.useEffect)(()=>{!ge&&v&&E===`credentials`&&e(`/`,{replace:!0})},[ge,v,E,e]);let Te=(0,l.useRef)(!1);(0,l.useEffect)(()=>{if(Te.current||n.get(`fallback`)===`local`||!G||!G.autologin_provider_id||window.location.hash.startsWith(`#oidc_token=`)||n.get(`oidc_error`))return;Te.current=!0;let e=G.autologin_provider_id,i=new Promise((e,t)=>setTimeout(()=>t(Error(`autologin timeout`)),5e3));Promise.race([r.getOIDCAuthorizeUrl(e),i]).then(e=>{let n=t.state?.from;n?.pathname&&h(`${n.pathname}${n.search??``}`),window.location.href=e.auth_url}).catch(()=>{we(!0)})},[G,n,t.state]);let q=G?.local_login_enabled!==!1,Ee=Ce&&G?.autologin_provider_id!=null;(0,l.useEffect)(()=>{let t=window.location.hash,n=t.startsWith(`#reset_token=`)?t.slice(13):null;n&&(B(n),D(`reset-password`),e(`/login`,{replace:!0}))},[]),(0,l.useEffect)(()=>{let t=window.location.hash,i=t.startsWith(`#oidc_token=`)?t.slice(12):null,a=n.get(`oidc_error`);if(!i&&!a)return;let o=pe();if(a){y({oidc_provider_error:f(`login.oidcErrors.providerError`),missing_parameters:f(`login.oidcErrors.missingParameters`),invalid_state:f(`login.oidcErrors.invalidState`),state_expired:f(`login.oidcErrors.stateExpired`),provider_not_found:f(`login.oidcErrors.providerNotFound`),discovery_failed:f(`login.oidcErrors.discoveryFailed`),invalid_discovery_document:f(`login.oidcErrors.invalidDiscovery`),token_exchange_network_error:f(`login.oidcErrors.networkError`),token_exchange_bad_response:f(`login.oidcErrors.badResponse`),no_id_token:f(`login.oidcErrors.noIdToken`),token_validation_failed:f(`login.oidcErrors.validationFailed`),nonce_mismatch:f(`login.oidcErrors.nonceMismatch`),missing_sub_claim:f(`login.oidcErrors.missingSubClaim`),no_linked_account:f(`login.oidcErrors.noLinkedAccount`),account_inactive:f(`login.oidcErrors.accountInactive`),user_resolution_failed:f(`login.oidcErrors.userResolutionFailed`),internal_error:f(`login.oidcErrors.internalError`)}[a]??(a.startsWith(`token_exchange_`)?f(`login.oidcErrors.tokenExchangeFailed`):f(`login.oidcLoginFailed`)),`error`),e(`/login`,{replace:!0});return}i&&r.exchangeOIDCToken(i).then(t=>{if(t.requires_2fa&&t.pre_auth_token){z(o),k(t.pre_auth_token);let n=t.two_fa_methods??[];j(n),n.includes(`totp`)?N(`totp`):n.includes(`email`)?N(`email`):N(`backup`),D(`2fa`),e(`/login`,{replace:!0})}else t.access_token&&t.user?(_(t.access_token,t.user,p(o)),y(f(`login.loginSuccess`)),e(b(),{replace:!0})):(y(f(`login.oidcLoginFailed`),`error`),e(`/login`,{replace:!0}))}).catch(t=>{console.error(`OIDC token exchange failed`,t),y(f(`login.oidcLoginFailed`),`error`),e(`/login`,{replace:!0})})},[n]);let J=o({mutationFn:()=>g(x,S,p(R)),onSuccess:t=>{if(t.requires_2fa&&t.pre_auth_token){k(t.pre_auth_token);let e=t.two_fa_methods??[];j(e),e.includes(`totp`)?N(`totp`):e.includes(`email`)?N(`email`):N(`backup`),D(`2fa`)}else t.access_token&&t.user&&(y(f(`login.loginSuccess`)),e(b(),{replace:!0}))},onError:e=>{y(e.message||f(`login.loginFailed`),`error`)}}),Y=o({mutationFn:e=>r.forgotPassword({email:e}),onSuccess:e=>{y(e.message,`success`),C(!1),T(``)},onError:e=>{y(e.message,`error`)}}),X=o({mutationFn:()=>r.forgotPasswordConfirm(Se,V),onSuccess:e=>{y(e.message,`success`),D(`credentials`),B(``),H(``),W(``)},onError:e=>{y(e.message||f(`login.resetPassword.resetFailed`),`error`)}}),Z=o({mutationFn:()=>r.sendEmailOTP(O),onSuccess:e=>{L(!0),e.pre_auth_token&&k(e.pre_auth_token),y(e.message,`success`)},onError:e=>{y(e.message||f(`login.twoFA.sendCodeFailed`),`error`)}}),Q=o({mutationFn:()=>r.verify2FA({pre_auth_token:O,code:P,method:M}),onSuccess:t=>{t.access_token&&t.user?(_(t.access_token,t.user,p(R)),y(f(`login.loginSuccess`)),e(b(),{replace:!0})):(console.error(`2FA verify: unexpected response shape`,t),y(f(`login.loginFailed`),`error`))},onError:e=>{y(e.message||f(`login.twoFA.invalidCode`),`error`),F(``)}}),De=o({mutationFn:e=>r.getOIDCAuthorizeUrl(e),onSuccess:e=>{try{R?sessionStorage.setItem(d,`1`):sessionStorage.removeItem(d)}catch(e){console.warn(`setItem/removeItem auth_remember_me failed, Remember Me will not carry through OIDC redirect`,e)}let n=t.state?.from;n?.pathname&&h(`${n.pathname}${n.search??``}`),window.location.href=e.auth_url},onError:e=>{y(e.message||f(`login.oidcLoginFailed`),`error`)}}),Oe=e=>{if(e.preventDefault(),!x||!S){y(f(`login.enterCredentials`),`error`);return}J.mutate()},ke=e=>{if(e.preventDefault(),!P.trim()){y(f(`login.twoFA.enterCode`),`error`);return}Q.mutate()},Ae=e=>{if(e.preventDefault(),!w){y(f(`login.enterEmail`),`error`);return}Y.mutate(w)},$=e=>{N(e),F(``),L(!1),setTimeout(()=>xe.current?.focus(),0)};return E===`reset-password`?(0,u.jsx)(`div`,{className:`min-h-screen flex items-center justify-center bg-bambu-dark p-4`,children:(0,u.jsxs)(`div`,{className:`max-w-md w-full space-y-8 p-8 bg-gradient-to-br from-bambu-card to-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary shadow-lg`,children:[(0,u.jsxs)(`div`,{className:`text-center`,children:[(0,u.jsx)(`div`,{className:`flex items-center justify-center mb-4`,children:(0,u.jsx)(`div`,{className:`w-14 h-14 rounded-full bg-bambu-green/20 flex items-center justify-center`,children:(0,u.jsx)(ue,{className:`w-7 h-7 text-bambu-green`})})}),(0,u.jsx)(`h2`,{className:`text-2xl font-bold text-white`,children:f(`login.resetPassword.title`)}),(0,u.jsx)(`p`,{className:`mt-2 text-sm text-bambu-gray`,children:f(`login.resetPassword.subtitle`)})]}),(0,u.jsxs)(`form`,{onSubmit:e=>{if(e.preventDefault(),V!==U){y(f(`login.resetPassword.passwordsDoNotMatch`),`error`);return}if(V.length<8){y(f(`login.resetPassword.passwordTooShort`),`error`);return}X.mutate()},className:`space-y-4`,children:[(0,u.jsxs)(`div`,{children:[(0,u.jsx)(`label`,{htmlFor:`new-password`,className:`block text-sm font-medium text-white mb-2`,children:f(`login.resetPassword.newPassword`)}),(0,u.jsx)(`input`,{id:`new-password`,type:`password`,required:!0,value:V,onChange:e=>H(e.target.value),className:`block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:f(`login.resetPassword.newPasswordPlaceholder`),autoFocus:!0,autoComplete:`new-password`,minLength:8})]}),(0,u.jsxs)(`div`,{children:[(0,u.jsx)(`label`,{htmlFor:`confirm-password`,className:`block text-sm font-medium text-white mb-2`,children:f(`login.resetPassword.confirmPassword`)}),(0,u.jsx)(`input`,{id:`confirm-password`,type:`password`,required:!0,value:U,onChange:e=>W(e.target.value),className:`block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:f(`login.resetPassword.confirmPasswordPlaceholder`),autoComplete:`new-password`})]}),(0,u.jsx)(`button`,{type:`submit`,disabled:X.isPending||!V||!U,className:`w-full flex justify-center py-3 px-4 bg-bambu-green hover:bg-bambu-green-light text-white font-medium rounded-lg shadow-lg shadow-bambu-green/20 hover:shadow-bambu-green/30 focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:ring-offset-2 focus:ring-offset-bambu-dark-secondary transition-all disabled:opacity-50 disabled:cursor-not-allowed`,children:X.isPending?f(`login.resetPassword.saving`):f(`login.resetPassword.submit`)})]}),(0,u.jsx)(`div`,{className:`text-center`,children:(0,u.jsx)(`button`,{type:`button`,onClick:()=>{D(`credentials`),B(``),H(``),W(``)},className:`text-sm text-bambu-gray hover:text-bambu-green transition-colors`,children:f(`login.resetPassword.backToLogin`)})})]})}):E===`2fa`?(0,u.jsx)(`div`,{className:`min-h-screen flex items-center justify-center bg-bambu-dark p-4`,children:(0,u.jsxs)(`div`,{className:`max-w-md w-full space-y-8 p-8 bg-gradient-to-br from-bambu-card to-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary shadow-lg`,children:[(0,u.jsxs)(`div`,{className:`text-center`,children:[(0,u.jsx)(`div`,{className:`flex items-center justify-center mb-4`,children:(0,u.jsx)(`div`,{className:`w-14 h-14 rounded-full bg-bambu-green/20 flex items-center justify-center`,children:(0,u.jsx)(ee,{className:`w-7 h-7 text-bambu-green`})})}),(0,u.jsx)(`h2`,{className:`text-2xl font-bold text-white`,children:f(`login.twoFA.title`)}),(0,u.jsx)(`p`,{className:`mt-2 text-sm text-bambu-gray`,children:f(`login.twoFA.subtitle`)})]}),A.length>1&&(0,u.jsxs)(`div`,{className:`flex gap-2`,children:[A.includes(`totp`)&&(0,u.jsxs)(`button`,{type:`button`,onClick:()=>$(`totp`),className:`flex-1 flex flex-col items-center gap-1 py-2 px-3 rounded-lg border text-xs font-medium transition-colors ${M===`totp`?`border-bambu-green bg-bambu-green/10 text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:border-bambu-green/50`}`,children:[(0,u.jsx)(te,{className:`w-4 h-4`}),f(`login.twoFA.methodAuthenticator`)]}),A.includes(`email`)&&(0,u.jsxs)(`button`,{type:`button`,onClick:()=>$(`email`),className:`flex-1 flex flex-col items-center gap-1 py-2 px-3 rounded-lg border text-xs font-medium transition-colors ${M===`email`?`border-bambu-green bg-bambu-green/10 text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:border-bambu-green/50`}`,children:[(0,u.jsx)(le,{className:`w-4 h-4`}),f(`login.twoFA.methodEmail`)]}),A.includes(`backup`)&&(0,u.jsxs)(`button`,{type:`button`,onClick:()=>$(`backup`),className:`flex-1 flex flex-col items-center gap-1 py-2 px-3 rounded-lg border text-xs font-medium transition-colors ${M===`backup`?`border-bambu-green bg-bambu-green/10 text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:border-bambu-green/50`}`,children:[(0,u.jsx)(ue,{className:`w-4 h-4`}),f(`login.twoFA.methodBackup`)]})]}),(0,u.jsxs)(`form`,{onSubmit:ke,className:`space-y-4`,children:[M===`totp`&&(0,u.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:f(`login.twoFA.instructionsTotp`)}),M===`email`&&(0,u.jsxs)(`div`,{className:`space-y-3`,children:[(0,u.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:f(I?`login.twoFA.instructionsEmail`:`login.twoFA.instructionsEmailNotSent`)}),!I&&(0,u.jsx)(c,{type:`button`,variant:`secondary`,className:`w-full`,onClick:()=>Z.mutate(),disabled:Z.isPending,children:Z.isPending?f(`login.twoFA.sendingCode`):f(`login.twoFA.sendCodeButton`)}),I&&(0,u.jsx)(`button`,{type:`button`,onClick:()=>{L(!1),Z.mutate()},className:`text-xs text-bambu-gray hover:text-bambu-green transition-colors`,children:f(`login.twoFA.resendCode`)})]}),M===`backup`&&(0,u.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:f(`login.twoFA.instructionsBackup`)}),(0,u.jsxs)(`div`,{children:[(0,u.jsx)(`label`,{htmlFor:`twofa-code`,className:`block text-sm font-medium text-white mb-2`,children:f(M===`backup`?`login.twoFA.backupCodeLabel`:`login.twoFA.codeLabel`)}),(0,u.jsx)(`input`,{ref:xe,id:`twofa-code`,type:`text`,inputMode:M===`backup`?`text`:`numeric`,autoComplete:`one-time-code`,value:P,onChange:e=>F(e.target.value.trim()),disabled:M===`email`&&!I,className:`block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray text-center tracking-widest text-xl font-mono focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors disabled:opacity-40`,placeholder:f(M===`backup`?`login.twoFA.backupCodePlaceholder`:`login.twoFA.codePlaceholder`),maxLength:M===`backup`?8:6,autoFocus:!0})]}),(0,u.jsx)(`button`,{type:`submit`,disabled:Q.isPending||!P.trim()||M===`email`&&!I,className:`w-full flex justify-center py-3 px-4 bg-bambu-green hover:bg-bambu-green-light text-white font-medium rounded-lg shadow-lg shadow-bambu-green/20 hover:shadow-bambu-green/30 focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:ring-offset-2 focus:ring-offset-bambu-dark-secondary transition-all disabled:opacity-50 disabled:cursor-not-allowed`,children:Q.isPending?f(`login.twoFA.verifyingButton`):f(`login.twoFA.verifyButton`)})]}),(0,u.jsx)(`div`,{className:`text-center`,children:(0,u.jsx)(`button`,{type:`button`,onClick:()=>{D(`credentials`),k(``),F(``),L(!1)},className:`text-sm text-bambu-gray hover:text-bambu-green transition-colors`,children:f(`login.twoFA.backToLogin`)})})]})}):(0,u.jsxs)(`div`,{className:`min-h-screen flex items-center justify-center bg-bambu-dark p-4`,children:[(0,u.jsxs)(`div`,{className:`max-w-md w-full space-y-8 p-8 bg-gradient-to-br from-bambu-card to-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary shadow-lg`,children:[(0,u.jsxs)(`div`,{className:`text-center`,children:[(0,u.jsx)(`div`,{className:`flex items-center justify-center mb-6`,children:(0,u.jsx)(`img`,{src:_e===`dark`?`/img/bambuddy_logo_dark_transparent.png`:`/img/bambuddy_logo_light.png`,alt:`Bambuddy`,className:`h-16`})}),(0,u.jsx)(`h2`,{className:`text-3xl font-bold text-white`,children:f(`login.title`)}),(0,u.jsx)(`p`,{className:`mt-2 text-sm text-bambu-gray`,children:f(`login.subtitle`)})]}),Ee&&(0,u.jsx)(`div`,{className:`mt-6 rounded-lg border border-amber-300 dark:border-amber-500/40 bg-amber-50 dark:bg-amber-500/10 px-4 py-3 text-sm text-amber-800 dark:text-amber-200`,children:f(`login.autologinFailed`)}),!q&&(0,u.jsx)(`div`,{className:`mt-6 rounded-lg border border-bambu-dark-tertiary bg-bambu-dark/40 px-4 py-3 text-sm text-bambu-gray`,children:f(`login.localDisabledNotice`)}),q&&(0,u.jsxs)(`form`,{className:`mt-8 space-y-6`,onSubmit:Oe,children:[(0,u.jsxs)(`div`,{className:`space-y-4`,children:[(0,u.jsxs)(`div`,{children:[(0,u.jsx)(`label`,{htmlFor:`username`,className:`block text-sm font-medium text-white mb-2`,children:G?.advanced_auth_enabled?f(`login.usernameOrEmail`):f(`login.username`)}),(0,u.jsx)(`input`,{id:`username`,type:`text`,required:!0,value:x,onChange:e=>ve(e.target.value),className:`block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:G?.advanced_auth_enabled?f(`login.usernameOrEmailPlaceholder`):f(`login.usernamePlaceholder`),autoComplete:`username`})]}),(0,u.jsxs)(`div`,{children:[(0,u.jsx)(`label`,{htmlFor:`password`,className:`block text-sm font-medium text-white mb-2`,children:f(`login.password`)||`Password`}),(0,u.jsx)(`input`,{id:`password`,type:`password`,required:!0,value:S,onChange:e=>ye(e.target.value),className:`block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:f(`login.passwordPlaceholder`),autoComplete:`current-password`})]})]}),(0,u.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,u.jsx)(`input`,{id:`remember-me`,type:`checkbox`,checked:R,onChange:e=>z(e.target.checked),className:`h-4 w-4 rounded border-bambu-dark-tertiary bg-bambu-dark-secondary text-bambu-green focus:ring-bambu-green/50 cursor-pointer`}),(0,u.jsx)(`label`,{htmlFor:`remember-me`,className:`text-sm text-bambu-gray cursor-pointer`,children:f(`login.rememberMe`)})]}),(0,u.jsx)(`div`,{children:(0,u.jsx)(`button`,{type:`submit`,disabled:J.isPending,className:`w-full flex justify-center py-3 px-4 bg-bambu-green hover:bg-bambu-green-light text-white font-medium rounded-lg shadow-lg shadow-bambu-green/20 hover:shadow-bambu-green/30 focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:ring-offset-2 focus:ring-offset-bambu-dark-secondary transition-all disabled:opacity-50 disabled:cursor-not-allowed disabled:hover:bg-bambu-green`,children:J.isPending?f(`login.signingIn`):f(`login.signIn`)})}),(0,u.jsx)(`div`,{className:`text-center`,children:(0,u.jsx)(`button`,{type:`button`,onClick:()=>C(!0),className:`text-sm text-bambu-gray hover:text-bambu-green transition-colors`,children:f(`login.forgotPassword`)})})]}),K&&K.length>0&&(0,u.jsxs)(`div`,{className:`space-y-3`,children:[q&&(0,u.jsxs)(`div`,{className:`relative`,children:[(0,u.jsx)(`div`,{className:`absolute inset-0 flex items-center`,children:(0,u.jsx)(`div`,{className:`w-full border-t border-bambu-dark-tertiary`})}),(0,u.jsx)(`div`,{className:`relative flex justify-center text-sm`,children:(0,u.jsx)(`span`,{className:`px-2 bg-bambu-dark-secondary text-bambu-gray`,children:f(`login.twoFA.orContinueWith`)})})]}),!q&&(0,u.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,u.jsx)(`input`,{id:`remember-me`,type:`checkbox`,checked:R,onChange:e=>z(e.target.checked),className:`h-4 w-4 rounded border-bambu-dark-tertiary bg-bambu-dark-secondary text-bambu-green focus:ring-bambu-green/50 cursor-pointer`}),(0,u.jsx)(`label`,{htmlFor:`remember-me`,className:`text-sm text-bambu-gray cursor-pointer`,children:f(`login.rememberMe`)})]}),(0,u.jsx)(`div`,{className:`space-y-2`,children:K.map(e=>(0,u.jsx)(he,{provider:e,onClick:()=>De.mutate(e.id),disabled:De.isPending},e.id))})]})]}),be&&(0,u.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:()=>C(!1),children:(0,u.jsxs)(ae,{className:`w-full max-w-md`,onClick:e=>e.stopPropagation(),children:[(0,u.jsx)(re,{children:(0,u.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,u.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,u.jsx)(le,{className:`w-5 h-5 text-bambu-green`}),(0,u.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:f(`login.forgotPasswordTitle`)})]}),(0,u.jsx)(c,{variant:`ghost`,size:`sm`,onClick:()=>{C(!1),T(``)},children:(0,u.jsx)(ne,{className:`w-5 h-5`})})]})}),(0,u.jsx)(ie,{children:G?.advanced_auth_enabled?(0,u.jsxs)(`form`,{onSubmit:Ae,className:`space-y-4`,children:[(0,u.jsx)(`p`,{className:`text-bambu-gray text-sm`,children:f(`login.forgotPasswordEmailMessage`)}),(0,u.jsxs)(`div`,{children:[(0,u.jsx)(`label`,{htmlFor:`forgot-email`,className:`block text-sm font-medium text-white mb-2`,children:f(`login.emailAddress`)}),(0,u.jsx)(`input`,{id:`forgot-email`,type:`email`,required:!0,value:w,onChange:e=>T(e.target.value),className:`block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:f(`login.emailPlaceholder`)})]}),(0,u.jsxs)(`div`,{className:`flex gap-2`,children:[(0,u.jsx)(c,{type:`button`,variant:`secondary`,className:`flex-1`,onClick:()=>{C(!1),T(``)},children:f(`login.cancel`)}),(0,u.jsx)(c,{type:`submit`,className:`flex-1`,disabled:Y.isPending,children:Y.isPending?f(`login.sending`):f(`login.sendResetEmail`)})]})]}):(0,u.jsxs)(`div`,{className:`space-y-4`,children:[(0,u.jsx)(`p`,{className:`text-bambu-gray`,children:f(`login.forgotPasswordMessage`)}),(0,u.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4 space-y-2`,children:[(0,u.jsx)(`p`,{className:`text-sm text-white font-medium`,children:f(`login.howToReset`)}),(0,u.jsxs)(`ol`,{className:`text-sm text-bambu-gray space-y-1 list-decimal list-inside`,children:[(0,u.jsx)(`li`,{children:f(`login.resetStep1`)}),(0,u.jsx)(`li`,{children:f(`login.resetStep2`)}),(0,u.jsx)(`li`,{children:f(`login.resetStep3`)}),(0,u.jsx)(`li`,{children:f(`login.resetStep4`)})]})]}),(0,u.jsx)(c,{variant:`secondary`,className:`w-full`,onClick:()=>C(!1),children:f(`login.gotIt`)})]})})]})})]})}export{g as LoginPage}; \ No newline at end of file +import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,w as i}from"./client-DnySrlFv.js";import{t as a}from"./useQuery-BBCjCezC.js";import{t as o}from"./useMutation-B-Tr2hIP.js";import{n as s}from"./ToastContext-BRX0SW3C.js";import{t as ee}from"./shield-bODVqOJd.js";import{t as te}from"./smartphone-DaDGaGLT.js";import{t as ne}from"./x-DR-Trv6U.js";import{i as re,n as ie,t as ae}from"./Card-Bzc64K35.js";import{t as c}from"./Button-DDr6eAFy.js";import{Bn as oe,Vn as se,Wn as ce,in as le,ln as ue,vt as de,yt as fe}from"./index-Cxa-KVmA.js";var l=e(n(),1),u=t(),d=`auth_remember_me`,f=`auth_post_login_redirect`;function p(e){return e?`persistent`:`session`}function pe(){try{let e=sessionStorage.getItem(d)===`1`;return sessionStorage.removeItem(d),e}catch(e){return console.warn(`consumeSavedRememberMe: sessionStorage unavailable, Remember Me preference lost across OIDC redirect`,e),!1}}function m(e){return!e||!e.startsWith(`/`)||e.startsWith(`//`)||e.startsWith(`/login`)?null:e}function h(e){let t=m(e);if(t)try{sessionStorage.setItem(f,t)}catch(e){console.warn(`stashPostLoginRedirect: sessionStorage unavailable, post-login target will be lost across OIDC redirect`,e)}}function me(){try{let e=sessionStorage.getItem(f);return sessionStorage.removeItem(f),m(e)}catch(e){return console.warn(`consumePostLoginRedirect: sessionStorage unavailable`,e),null}}function he({provider:e,onClick:t,disabled:n}){let{t:a}=i(),[o,s]=(0,l.useState)(!1);return(0,u.jsxs)(`button`,{type:`button`,onClick:t,disabled:n,className:`w-full flex items-center justify-center gap-3 py-3 px-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary hover:border-bambu-green/50 rounded-lg text-white font-medium transition-colors disabled:opacity-50`,children:[e.has_icon&&!o?(0,u.jsx)(`img`,{src:r.oidcProviderIconUrl(e.id),alt:``,className:`w-5 h-5 object-contain`,onError:()=>s(!0)}):(0,u.jsx)(ee,{className:`w-5 h-5 text-bambu-green`}),a(`login.twoFA.signInWith`,{provider:e.name})]})}function g(){let e=se(),t=oe(),[n]=ce(),{t:f}=i(),{login:g,loginWithToken:_,user:v,loading:ge}=fe(),{showToast:y}=s(),{mode:_e}=de();function b(){let e=t.state?.from;if(e?.pathname){let t=m(`${e.pathname}${e.search??``}`);if(t)return t}return me()??`/`}let[x,ve]=(0,l.useState)(``),[S,ye]=(0,l.useState)(``),[be,C]=(0,l.useState)(!1),[w,T]=(0,l.useState)(``),[E,D]=(0,l.useState)(`credentials`),[O,k]=(0,l.useState)(``),[A,j]=(0,l.useState)([]),[M,N]=(0,l.useState)(`totp`),[P,F]=(0,l.useState)(``),[I,L]=(0,l.useState)(!1),xe=(0,l.useRef)(null),[R,z]=(0,l.useState)(!1),[Se,B]=(0,l.useState)(``),[V,H]=(0,l.useState)(``),[U,W]=(0,l.useState)(``),{data:G}=a({queryKey:[`advancedAuthStatus`],queryFn:()=>r.getAdvancedAuthStatus()}),{data:K}=a({queryKey:[`oidcProviders`],queryFn:()=>r.getOIDCProviders()}),[Ce,we]=(0,l.useState)(!1);(0,l.useEffect)(()=>{!ge&&v&&E===`credentials`&&e(`/`,{replace:!0})},[ge,v,E,e]);let Te=(0,l.useRef)(!1);(0,l.useEffect)(()=>{if(Te.current||n.get(`fallback`)===`local`||!G||!G.autologin_provider_id||window.location.hash.startsWith(`#oidc_token=`)||n.get(`oidc_error`))return;Te.current=!0;let e=G.autologin_provider_id,i=new Promise((e,t)=>setTimeout(()=>t(Error(`autologin timeout`)),5e3));Promise.race([r.getOIDCAuthorizeUrl(e),i]).then(e=>{let n=t.state?.from;n?.pathname&&h(`${n.pathname}${n.search??``}`),window.location.href=e.auth_url}).catch(()=>{we(!0)})},[G,n,t.state]);let q=G?.local_login_enabled!==!1,Ee=Ce&&G?.autologin_provider_id!=null;(0,l.useEffect)(()=>{let t=window.location.hash,n=t.startsWith(`#reset_token=`)?t.slice(13):null;n&&(B(n),D(`reset-password`),e(`/login`,{replace:!0}))},[]),(0,l.useEffect)(()=>{let t=window.location.hash,i=t.startsWith(`#oidc_token=`)?t.slice(12):null,a=n.get(`oidc_error`);if(!i&&!a)return;let o=pe();if(a){y({oidc_provider_error:f(`login.oidcErrors.providerError`),missing_parameters:f(`login.oidcErrors.missingParameters`),invalid_state:f(`login.oidcErrors.invalidState`),state_expired:f(`login.oidcErrors.stateExpired`),provider_not_found:f(`login.oidcErrors.providerNotFound`),discovery_failed:f(`login.oidcErrors.discoveryFailed`),invalid_discovery_document:f(`login.oidcErrors.invalidDiscovery`),token_exchange_network_error:f(`login.oidcErrors.networkError`),token_exchange_bad_response:f(`login.oidcErrors.badResponse`),no_id_token:f(`login.oidcErrors.noIdToken`),token_validation_failed:f(`login.oidcErrors.validationFailed`),nonce_mismatch:f(`login.oidcErrors.nonceMismatch`),missing_sub_claim:f(`login.oidcErrors.missingSubClaim`),no_linked_account:f(`login.oidcErrors.noLinkedAccount`),account_inactive:f(`login.oidcErrors.accountInactive`),user_resolution_failed:f(`login.oidcErrors.userResolutionFailed`),internal_error:f(`login.oidcErrors.internalError`)}[a]??(a.startsWith(`token_exchange_`)?f(`login.oidcErrors.tokenExchangeFailed`):f(`login.oidcLoginFailed`)),`error`),e(`/login`,{replace:!0});return}i&&r.exchangeOIDCToken(i).then(t=>{if(t.requires_2fa&&t.pre_auth_token){z(o),k(t.pre_auth_token);let n=t.two_fa_methods??[];j(n),n.includes(`totp`)?N(`totp`):n.includes(`email`)?N(`email`):N(`backup`),D(`2fa`),e(`/login`,{replace:!0})}else t.access_token&&t.user?(_(t.access_token,t.user,p(o)),y(f(`login.loginSuccess`)),e(b(),{replace:!0})):(y(f(`login.oidcLoginFailed`),`error`),e(`/login`,{replace:!0}))}).catch(t=>{console.error(`OIDC token exchange failed`,t),y(f(`login.oidcLoginFailed`),`error`),e(`/login`,{replace:!0})})},[n]);let J=o({mutationFn:()=>g(x,S,p(R)),onSuccess:t=>{if(t.requires_2fa&&t.pre_auth_token){k(t.pre_auth_token);let e=t.two_fa_methods??[];j(e),e.includes(`totp`)?N(`totp`):e.includes(`email`)?N(`email`):N(`backup`),D(`2fa`)}else t.access_token&&t.user&&(y(f(`login.loginSuccess`)),e(b(),{replace:!0}))},onError:e=>{y(e.message||f(`login.loginFailed`),`error`)}}),Y=o({mutationFn:e=>r.forgotPassword({email:e}),onSuccess:e=>{y(e.message,`success`),C(!1),T(``)},onError:e=>{y(e.message,`error`)}}),X=o({mutationFn:()=>r.forgotPasswordConfirm(Se,V),onSuccess:e=>{y(e.message,`success`),D(`credentials`),B(``),H(``),W(``)},onError:e=>{y(e.message||f(`login.resetPassword.resetFailed`),`error`)}}),Z=o({mutationFn:()=>r.sendEmailOTP(O),onSuccess:e=>{L(!0),e.pre_auth_token&&k(e.pre_auth_token),y(e.message,`success`)},onError:e=>{y(e.message||f(`login.twoFA.sendCodeFailed`),`error`)}}),Q=o({mutationFn:()=>r.verify2FA({pre_auth_token:O,code:P,method:M}),onSuccess:t=>{t.access_token&&t.user?(_(t.access_token,t.user,p(R)),y(f(`login.loginSuccess`)),e(b(),{replace:!0})):(console.error(`2FA verify: unexpected response shape`,t),y(f(`login.loginFailed`),`error`))},onError:e=>{y(e.message||f(`login.twoFA.invalidCode`),`error`),F(``)}}),De=o({mutationFn:e=>r.getOIDCAuthorizeUrl(e),onSuccess:e=>{try{R?sessionStorage.setItem(d,`1`):sessionStorage.removeItem(d)}catch(e){console.warn(`setItem/removeItem auth_remember_me failed, Remember Me will not carry through OIDC redirect`,e)}let n=t.state?.from;n?.pathname&&h(`${n.pathname}${n.search??``}`),window.location.href=e.auth_url},onError:e=>{y(e.message||f(`login.oidcLoginFailed`),`error`)}}),Oe=e=>{if(e.preventDefault(),!x||!S){y(f(`login.enterCredentials`),`error`);return}J.mutate()},ke=e=>{if(e.preventDefault(),!P.trim()){y(f(`login.twoFA.enterCode`),`error`);return}Q.mutate()},Ae=e=>{if(e.preventDefault(),!w){y(f(`login.enterEmail`),`error`);return}Y.mutate(w)},$=e=>{N(e),F(``),L(!1),setTimeout(()=>xe.current?.focus(),0)};return E===`reset-password`?(0,u.jsx)(`div`,{className:`min-h-screen flex items-center justify-center bg-bambu-dark p-4`,children:(0,u.jsxs)(`div`,{className:`max-w-md w-full space-y-8 p-8 bg-gradient-to-br from-bambu-card to-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary shadow-lg`,children:[(0,u.jsxs)(`div`,{className:`text-center`,children:[(0,u.jsx)(`div`,{className:`flex items-center justify-center mb-4`,children:(0,u.jsx)(`div`,{className:`w-14 h-14 rounded-full bg-bambu-green/20 flex items-center justify-center`,children:(0,u.jsx)(ue,{className:`w-7 h-7 text-bambu-green`})})}),(0,u.jsx)(`h2`,{className:`text-2xl font-bold text-white`,children:f(`login.resetPassword.title`)}),(0,u.jsx)(`p`,{className:`mt-2 text-sm text-bambu-gray`,children:f(`login.resetPassword.subtitle`)})]}),(0,u.jsxs)(`form`,{onSubmit:e=>{if(e.preventDefault(),V!==U){y(f(`login.resetPassword.passwordsDoNotMatch`),`error`);return}if(V.length<8){y(f(`login.resetPassword.passwordTooShort`),`error`);return}X.mutate()},className:`space-y-4`,children:[(0,u.jsxs)(`div`,{children:[(0,u.jsx)(`label`,{htmlFor:`new-password`,className:`block text-sm font-medium text-white mb-2`,children:f(`login.resetPassword.newPassword`)}),(0,u.jsx)(`input`,{id:`new-password`,type:`password`,required:!0,value:V,onChange:e=>H(e.target.value),className:`block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:f(`login.resetPassword.newPasswordPlaceholder`),autoFocus:!0,autoComplete:`new-password`,minLength:8})]}),(0,u.jsxs)(`div`,{children:[(0,u.jsx)(`label`,{htmlFor:`confirm-password`,className:`block text-sm font-medium text-white mb-2`,children:f(`login.resetPassword.confirmPassword`)}),(0,u.jsx)(`input`,{id:`confirm-password`,type:`password`,required:!0,value:U,onChange:e=>W(e.target.value),className:`block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:f(`login.resetPassword.confirmPasswordPlaceholder`),autoComplete:`new-password`})]}),(0,u.jsx)(`button`,{type:`submit`,disabled:X.isPending||!V||!U,className:`w-full flex justify-center py-3 px-4 bg-bambu-green hover:bg-bambu-green-light text-white font-medium rounded-lg shadow-lg shadow-bambu-green/20 hover:shadow-bambu-green/30 focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:ring-offset-2 focus:ring-offset-bambu-dark-secondary transition-all disabled:opacity-50 disabled:cursor-not-allowed`,children:X.isPending?f(`login.resetPassword.saving`):f(`login.resetPassword.submit`)})]}),(0,u.jsx)(`div`,{className:`text-center`,children:(0,u.jsx)(`button`,{type:`button`,onClick:()=>{D(`credentials`),B(``),H(``),W(``)},className:`text-sm text-bambu-gray hover:text-bambu-green transition-colors`,children:f(`login.resetPassword.backToLogin`)})})]})}):E===`2fa`?(0,u.jsx)(`div`,{className:`min-h-screen flex items-center justify-center bg-bambu-dark p-4`,children:(0,u.jsxs)(`div`,{className:`max-w-md w-full space-y-8 p-8 bg-gradient-to-br from-bambu-card to-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary shadow-lg`,children:[(0,u.jsxs)(`div`,{className:`text-center`,children:[(0,u.jsx)(`div`,{className:`flex items-center justify-center mb-4`,children:(0,u.jsx)(`div`,{className:`w-14 h-14 rounded-full bg-bambu-green/20 flex items-center justify-center`,children:(0,u.jsx)(ee,{className:`w-7 h-7 text-bambu-green`})})}),(0,u.jsx)(`h2`,{className:`text-2xl font-bold text-white`,children:f(`login.twoFA.title`)}),(0,u.jsx)(`p`,{className:`mt-2 text-sm text-bambu-gray`,children:f(`login.twoFA.subtitle`)})]}),A.length>1&&(0,u.jsxs)(`div`,{className:`flex gap-2`,children:[A.includes(`totp`)&&(0,u.jsxs)(`button`,{type:`button`,onClick:()=>$(`totp`),className:`flex-1 flex flex-col items-center gap-1 py-2 px-3 rounded-lg border text-xs font-medium transition-colors ${M===`totp`?`border-bambu-green bg-bambu-green/10 text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:border-bambu-green/50`}`,children:[(0,u.jsx)(te,{className:`w-4 h-4`}),f(`login.twoFA.methodAuthenticator`)]}),A.includes(`email`)&&(0,u.jsxs)(`button`,{type:`button`,onClick:()=>$(`email`),className:`flex-1 flex flex-col items-center gap-1 py-2 px-3 rounded-lg border text-xs font-medium transition-colors ${M===`email`?`border-bambu-green bg-bambu-green/10 text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:border-bambu-green/50`}`,children:[(0,u.jsx)(le,{className:`w-4 h-4`}),f(`login.twoFA.methodEmail`)]}),A.includes(`backup`)&&(0,u.jsxs)(`button`,{type:`button`,onClick:()=>$(`backup`),className:`flex-1 flex flex-col items-center gap-1 py-2 px-3 rounded-lg border text-xs font-medium transition-colors ${M===`backup`?`border-bambu-green bg-bambu-green/10 text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:border-bambu-green/50`}`,children:[(0,u.jsx)(ue,{className:`w-4 h-4`}),f(`login.twoFA.methodBackup`)]})]}),(0,u.jsxs)(`form`,{onSubmit:ke,className:`space-y-4`,children:[M===`totp`&&(0,u.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:f(`login.twoFA.instructionsTotp`)}),M===`email`&&(0,u.jsxs)(`div`,{className:`space-y-3`,children:[(0,u.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:f(I?`login.twoFA.instructionsEmail`:`login.twoFA.instructionsEmailNotSent`)}),!I&&(0,u.jsx)(c,{type:`button`,variant:`secondary`,className:`w-full`,onClick:()=>Z.mutate(),disabled:Z.isPending,children:Z.isPending?f(`login.twoFA.sendingCode`):f(`login.twoFA.sendCodeButton`)}),I&&(0,u.jsx)(`button`,{type:`button`,onClick:()=>{L(!1),Z.mutate()},className:`text-xs text-bambu-gray hover:text-bambu-green transition-colors`,children:f(`login.twoFA.resendCode`)})]}),M===`backup`&&(0,u.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:f(`login.twoFA.instructionsBackup`)}),(0,u.jsxs)(`div`,{children:[(0,u.jsx)(`label`,{htmlFor:`twofa-code`,className:`block text-sm font-medium text-white mb-2`,children:f(M===`backup`?`login.twoFA.backupCodeLabel`:`login.twoFA.codeLabel`)}),(0,u.jsx)(`input`,{ref:xe,id:`twofa-code`,type:`text`,inputMode:M===`backup`?`text`:`numeric`,autoComplete:`one-time-code`,value:P,onChange:e=>F(e.target.value.trim()),disabled:M===`email`&&!I,className:`block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray text-center tracking-widest text-xl font-mono focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors disabled:opacity-40`,placeholder:f(M===`backup`?`login.twoFA.backupCodePlaceholder`:`login.twoFA.codePlaceholder`),maxLength:M===`backup`?8:6,autoFocus:!0})]}),(0,u.jsx)(`button`,{type:`submit`,disabled:Q.isPending||!P.trim()||M===`email`&&!I,className:`w-full flex justify-center py-3 px-4 bg-bambu-green hover:bg-bambu-green-light text-white font-medium rounded-lg shadow-lg shadow-bambu-green/20 hover:shadow-bambu-green/30 focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:ring-offset-2 focus:ring-offset-bambu-dark-secondary transition-all disabled:opacity-50 disabled:cursor-not-allowed`,children:Q.isPending?f(`login.twoFA.verifyingButton`):f(`login.twoFA.verifyButton`)})]}),(0,u.jsx)(`div`,{className:`text-center`,children:(0,u.jsx)(`button`,{type:`button`,onClick:()=>{D(`credentials`),k(``),F(``),L(!1)},className:`text-sm text-bambu-gray hover:text-bambu-green transition-colors`,children:f(`login.twoFA.backToLogin`)})})]})}):(0,u.jsxs)(`div`,{className:`min-h-screen flex items-center justify-center bg-bambu-dark p-4`,children:[(0,u.jsxs)(`div`,{className:`max-w-md w-full space-y-8 p-8 bg-gradient-to-br from-bambu-card to-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary shadow-lg`,children:[(0,u.jsxs)(`div`,{className:`text-center`,children:[(0,u.jsx)(`div`,{className:`flex items-center justify-center mb-6`,children:(0,u.jsx)(`img`,{src:_e===`dark`?`/img/bambuddy_logo_dark_transparent.png`:`/img/bambuddy_logo_light.png`,alt:`Bambuddy`,className:`h-16`})}),(0,u.jsx)(`h2`,{className:`text-3xl font-bold text-white`,children:f(`login.title`)}),(0,u.jsx)(`p`,{className:`mt-2 text-sm text-bambu-gray`,children:f(`login.subtitle`)})]}),Ee&&(0,u.jsx)(`div`,{className:`mt-6 rounded-lg border border-amber-300 dark:border-amber-500/40 bg-amber-50 dark:bg-amber-500/10 px-4 py-3 text-sm text-amber-800 dark:text-amber-200`,children:f(`login.autologinFailed`)}),!q&&(0,u.jsx)(`div`,{className:`mt-6 rounded-lg border border-bambu-dark-tertiary bg-bambu-dark/40 px-4 py-3 text-sm text-bambu-gray`,children:f(`login.localDisabledNotice`)}),q&&(0,u.jsxs)(`form`,{className:`mt-8 space-y-6`,onSubmit:Oe,children:[(0,u.jsxs)(`div`,{className:`space-y-4`,children:[(0,u.jsxs)(`div`,{children:[(0,u.jsx)(`label`,{htmlFor:`username`,className:`block text-sm font-medium text-white mb-2`,children:G?.advanced_auth_enabled?f(`login.usernameOrEmail`):f(`login.username`)}),(0,u.jsx)(`input`,{id:`username`,type:`text`,required:!0,value:x,onChange:e=>ve(e.target.value),className:`block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:G?.advanced_auth_enabled?f(`login.usernameOrEmailPlaceholder`):f(`login.usernamePlaceholder`),autoComplete:`username`})]}),(0,u.jsxs)(`div`,{children:[(0,u.jsx)(`label`,{htmlFor:`password`,className:`block text-sm font-medium text-white mb-2`,children:f(`login.password`)||`Password`}),(0,u.jsx)(`input`,{id:`password`,type:`password`,required:!0,value:S,onChange:e=>ye(e.target.value),className:`block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:f(`login.passwordPlaceholder`),autoComplete:`current-password`})]})]}),(0,u.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,u.jsx)(`input`,{id:`remember-me`,type:`checkbox`,checked:R,onChange:e=>z(e.target.checked),className:`h-4 w-4 rounded border-bambu-dark-tertiary bg-bambu-dark-secondary text-bambu-green focus:ring-bambu-green/50 cursor-pointer`}),(0,u.jsx)(`label`,{htmlFor:`remember-me`,className:`text-sm text-bambu-gray cursor-pointer`,children:f(`login.rememberMe`)})]}),(0,u.jsx)(`div`,{children:(0,u.jsx)(`button`,{type:`submit`,disabled:J.isPending,className:`w-full flex justify-center py-3 px-4 bg-bambu-green hover:bg-bambu-green-light text-white font-medium rounded-lg shadow-lg shadow-bambu-green/20 hover:shadow-bambu-green/30 focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:ring-offset-2 focus:ring-offset-bambu-dark-secondary transition-all disabled:opacity-50 disabled:cursor-not-allowed disabled:hover:bg-bambu-green`,children:J.isPending?f(`login.signingIn`):f(`login.signIn`)})}),(0,u.jsx)(`div`,{className:`text-center`,children:(0,u.jsx)(`button`,{type:`button`,onClick:()=>C(!0),className:`text-sm text-bambu-gray hover:text-bambu-green transition-colors`,children:f(`login.forgotPassword`)})})]}),K&&K.length>0&&(0,u.jsxs)(`div`,{className:`space-y-3`,children:[q&&(0,u.jsxs)(`div`,{className:`relative`,children:[(0,u.jsx)(`div`,{className:`absolute inset-0 flex items-center`,children:(0,u.jsx)(`div`,{className:`w-full border-t border-bambu-dark-tertiary`})}),(0,u.jsx)(`div`,{className:`relative flex justify-center text-sm`,children:(0,u.jsx)(`span`,{className:`px-2 bg-bambu-dark-secondary text-bambu-gray`,children:f(`login.twoFA.orContinueWith`)})})]}),!q&&(0,u.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,u.jsx)(`input`,{id:`remember-me`,type:`checkbox`,checked:R,onChange:e=>z(e.target.checked),className:`h-4 w-4 rounded border-bambu-dark-tertiary bg-bambu-dark-secondary text-bambu-green focus:ring-bambu-green/50 cursor-pointer`}),(0,u.jsx)(`label`,{htmlFor:`remember-me`,className:`text-sm text-bambu-gray cursor-pointer`,children:f(`login.rememberMe`)})]}),(0,u.jsx)(`div`,{className:`space-y-2`,children:K.map(e=>(0,u.jsx)(he,{provider:e,onClick:()=>De.mutate(e.id),disabled:De.isPending},e.id))})]})]}),be&&(0,u.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:()=>C(!1),children:(0,u.jsxs)(ae,{className:`w-full max-w-md`,onClick:e=>e.stopPropagation(),children:[(0,u.jsx)(re,{children:(0,u.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,u.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,u.jsx)(le,{className:`w-5 h-5 text-bambu-green`}),(0,u.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:f(`login.forgotPasswordTitle`)})]}),(0,u.jsx)(c,{variant:`ghost`,size:`sm`,onClick:()=>{C(!1),T(``)},children:(0,u.jsx)(ne,{className:`w-5 h-5`})})]})}),(0,u.jsx)(ie,{children:G?.advanced_auth_enabled?(0,u.jsxs)(`form`,{onSubmit:Ae,className:`space-y-4`,children:[(0,u.jsx)(`p`,{className:`text-bambu-gray text-sm`,children:f(`login.forgotPasswordEmailMessage`)}),(0,u.jsxs)(`div`,{children:[(0,u.jsx)(`label`,{htmlFor:`forgot-email`,className:`block text-sm font-medium text-white mb-2`,children:f(`login.emailAddress`)}),(0,u.jsx)(`input`,{id:`forgot-email`,type:`email`,required:!0,value:w,onChange:e=>T(e.target.value),className:`block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:f(`login.emailPlaceholder`)})]}),(0,u.jsxs)(`div`,{className:`flex gap-2`,children:[(0,u.jsx)(c,{type:`button`,variant:`secondary`,className:`flex-1`,onClick:()=>{C(!1),T(``)},children:f(`login.cancel`)}),(0,u.jsx)(c,{type:`submit`,className:`flex-1`,disabled:Y.isPending,children:Y.isPending?f(`login.sending`):f(`login.sendResetEmail`)})]})]}):(0,u.jsxs)(`div`,{className:`space-y-4`,children:[(0,u.jsx)(`p`,{className:`text-bambu-gray`,children:f(`login.forgotPasswordMessage`)}),(0,u.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4 space-y-2`,children:[(0,u.jsx)(`p`,{className:`text-sm text-white font-medium`,children:f(`login.howToReset`)}),(0,u.jsxs)(`ol`,{className:`text-sm text-bambu-gray space-y-1 list-decimal list-inside`,children:[(0,u.jsx)(`li`,{children:f(`login.resetStep1`)}),(0,u.jsx)(`li`,{children:f(`login.resetStep2`)}),(0,u.jsx)(`li`,{children:f(`login.resetStep3`)}),(0,u.jsx)(`li`,{children:f(`login.resetStep4`)})]})]}),(0,u.jsx)(c,{variant:`secondary`,className:`w-full`,onClick:()=>C(!1),children:f(`login.gotIt`)})]})})]})})]})}export{g as LoginPage}; \ No newline at end of file diff --git a/static/assets/MaintenancePage-GtlPlRFZ.js b/static/assets/MaintenancePage-B6wtSJnR.js similarity index 99% rename from static/assets/MaintenancePage-GtlPlRFZ.js rename to static/assets/MaintenancePage-B6wtSJnR.js index 55413fd3e..7ea3281fb 100644 --- a/static/assets/MaintenancePage-GtlPlRFZ.js +++ b/static/assets/MaintenancePage-B6wtSJnR.js @@ -1 +1 @@ -import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,w as i}from"./client-DnySrlFv.js";import{n as a}from"./QueryClientProvider-Ce8_sN3w.js";import{t as o}from"./useQuery-BBCjCezC.js";import{t as s}from"./useMutation-B-Tr2hIP.js";import{t as c}from"./createLucideIcon-DvBYJlWL.js";import{t as l}from"./box-DAdKb9s5.js";import{n as u,t as d}from"./fan-D6AmXZMv.js";import{t as f}from"./calendar-BLKPnWqV.js";import{t as p}from"./check-Ck0cMLU4.js";import{a as m,i as h}from"./info-ROUoQhJR.js";import{n as g}from"./ToastContext-BRX0SW3C.js";import{t as _}from"./cog-Dol1I0kq.js";import{t as v}from"./droplet-CqYXMF2u.js";import{t as y}from"./funnel-C3dyAMK9.js";import{t as ee}from"./loader-circle-BEmFtawu.js";import{t as b}from"./pen-line-BWR04BX-.js";import{t as x}from"./sparkles-DRqKNlhr.js";import{t as S}from"./target-B40GQtrA.js";import{n as C,t as w}from"./wind-CI8UoBMf.js";import{t as T}from"./timer-GUTR9dAu.js";import{t as E}from"./triangle-alert-Dt_1FcBy.js";import{n as D,t as O}from"./Card-Bzc64K35.js";import{t as k}from"./Button-DDr6eAFy.js";import{At as te,Cn as A,Gt as j,Jt as ne,Kt as M,Lt as re,On as N,Vt as P,Zt as ie,_t as ae,bn as F,bt as I,cn as L,xt as R,yt as oe}from"./index-0t--Yqoi.js";import{t as z}from"./Toggle-KiqA_5fU.js";var B=c(`circle-dot`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}]]),V=c(`ruler`,[[`path`,{d:`M21.3 15.3a2.4 2.4 0 0 1 0 3.4l-2.6 2.6a2.4 2.4 0 0 1-3.4 0L2.7 8.7a2.41 2.41 0 0 1 0-3.4l2.6-2.6a2.41 2.41 0 0 1 3.4 0Z`,key:`icamh8`}],[`path`,{d:`m14.5 12.5 2-2`,key:`inckbg`}],[`path`,{d:`m11.5 9.5 2-2`,key:`fmmyf7`}],[`path`,{d:`m8.5 6.5 2-2`,key:`vc6u1g`}],[`path`,{d:`m17.5 15.5 2-2`,key:`wo5hmg`}]]),H=e(n(),1);function U(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 W=t(),G={Droplet:v,Flame:F,Ruler:V,Sparkles:x,Square:re,Cable:u,Wrench:R,Calendar:f,Timer:T,Cog:_,Fan:d,Zap:I,Wind:w,Thermometer:C,Layers:L,Box:l,Target:S,RefreshCw:M,Settings:P,Filter:y,CircleDot:B};function K(e){return e&&G[e]||R}function q(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 J(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 Y({item:e,onPerform:t,onToggle:n,hasPermission:r,t:i}){let a=K(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,W.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,W.jsxs)(`div`,{className:`flex items-start gap-3 max-[550px]:flex-wrap`,children:[(0,W.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,W.jsx)(a,{className:`w-5 h-5 ${c()}`}),e.enabled&&(e.is_due||e.is_warning)&&(0,W.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,W.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,W.jsx)(`h3`,{className:`font-medium truncate ${e.enabled?`text-white`:`text-bambu-gray`}`,children:e.maintenance_type_name}),o===`days`&&(0,W.jsx)(`span`,{title:i(`maintenance.timeBasedInterval`),children:(0,W.jsx)(f,{className:`w-3.5 h-3.5 text-bambu-gray shrink-0`})}),(()=>{let t=e.maintenance_type_wiki_url||U(e.maintenance_type_name,e.printer_model);return t?(0,W.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,W.jsx)(A,{className:`w-3.5 h-3.5`})}):null})()]}),(0,W.jsx)(`div`,{className:`mt-2 mb-1.5`,children:(0,W.jsx)(`div`,{className:`w-full h-1.5 bg-bambu-dark rounded-full overflow-hidden`,children:(0,W.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,W.jsxs)(`div`,{className:`text-xs flex items-center gap-1 ${c()}`,children:[e.is_due&&(0,W.jsx)(E,{className:`w-3 h-3`}),e.is_warning&&!e.is_due&&(0,W.jsx)(N,{className:`w-3 h-3`}),!e.is_due&&!e.is_warning&&e.enabled&&(0,W.jsx)(p,{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:q(Math.abs(t),`days`,i)}):e.is_warning?i(`maintenance.dueIn`,{duration:q(t,`days`,i)}):i(`maintenance.timeLeft`,{duration:q(t,`days`,i)})}else return e.is_due?i(`maintenance.overdueBy`,{duration:q(Math.abs(e.hours_until_due),`hours`,i)}):e.is_warning?i(`maintenance.dueIn`,{duration:q(e.hours_until_due,`hours`,i)}):i(`maintenance.timeLeft`,{duration:q(e.hours_until_due,`hours`,i)})})()]})]}),(0,W.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0 max-[550px]:w-full max-[550px]:justify-end max-[550px]:mt-1`,children:[(0,W.jsx)(`span`,{title:r(`maintenance:update`)?void 0:i(`maintenance.noPermissionUpdate`),children:(0,W.jsx)(z,{checked:e.enabled,onChange:t=>n(e.id,t),disabled:!r(`maintenance:update`)})}),(0,W.jsxs)(k,{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,W.jsx)(j,{className:`w-3.5 h-3.5`}),i(`common.reset`)]})]})]})})}function X({overview:e,onPerform:t,onToggle:n,onSetHours:r,hasPermission:i,t:a}){let[o,s]=(0,H.useState)(!1),[c,l]=(0,H.useState)(!1),[u,d]=(0,H.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),g=f.find(e=>e.enabled&&(e.is_due||e.is_warning)),_=()=>{let t=parseFloat(u);!isNaN(t)&&t>=0&&(r(e.printer_id,t),l(!1))};return(0,W.jsxs)(O,{className:`overflow-hidden`,children:[(0,W.jsxs)(`div`,{className:`p-5`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,W.jsx)(`h2`,{className:`text-xl font-semibold text-white`,children:e.printer_name}),(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.due_count>0&&(0,W.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,W.jsx)(E,{className:`w-3 h-3`}),a(`maintenance.overdueCount`,{count:e.due_count})]}),e.warning_count>0&&(0,W.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,W.jsx)(N,{className:`w-3 h-3`}),a(`maintenance.dueSoonCount`,{count:e.warning_count})]}),e.due_count===0&&e.warning_count===0&&(0,W.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,W.jsx)(p,{className:`w-3 h-3`}),a(`maintenance.allGood`)]})]})]}),(0,W.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,W.jsx)(h,{className:`w-4 h-4`}):(0,W.jsx)(m,{className:`w-4 h-4`}),a(o?`common.collapse`:`common.expand`)]})]}),(0,W.jsxs)(`div`,{className:`flex items-center gap-6 mt-4`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,W.jsx)(`div`,{className:`p-2 bg-bambu-dark/50 rounded-lg`,children:(0,W.jsx)(T,{className:`w-4 h-4 text-bambu-gray`})}),c?(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,W.jsx)(`input`,{type:`number`,value:u,onChange:e=>d(e.target.value),onKeyDown:e=>{e.key===`Enter`&&_(),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,W.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:a(`common.hours`)}),(0,W.jsx)(k,{size:`sm`,onClick:_,children:a(`common.save`)}),(0,W.jsx)(k,{size:`sm`,variant:`secondary`,onClick:()=>l(!1),children:a(`common.cancel`)})]}):(0,W.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,W.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,W.jsx)(b,{className:`w-3 h-3 text-bambu-gray ${i(`maintenance:update`)?`group-hover:text-bambu-green`:``}`})]}),(0,W.jsx)(`div`,{className:`text-xs text-bambu-gray`,children:a(`maintenance.totalPrintTime`)})]})]}),(0,W.jsx)(`div`,{className:`w-px h-10 bg-bambu-dark-tertiary`}),g&&(0,W.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,W.jsx)(`div`,{className:`p-2 rounded-lg ${g.is_due?`bg-red-500/20`:`bg-amber-500/20`}`,children:(0,W.jsx)(K(g.maintenance_type_icon),{className:`w-4 h-4 ${g.is_due?`text-red-600 dark:text-red-400`:`text-amber-600 dark:text-amber-400`}`})}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`div`,{className:`text-sm font-medium ${g.is_due?`text-red-700 dark:text-red-400`:`text-amber-700 dark:text-amber-400`}`,children:g.maintenance_type_name}),(0,W.jsx)(`div`,{className:`text-xs ${g.is_due?`text-red-700/80 dark:text-red-400/70`:`text-amber-700/80 dark:text-amber-400/70`}`,children:g.is_due?a(`common.overdue`):a(`maintenance.dueSoon`)})]})]})]})]}),o&&(0,W.jsx)(D,{className:`pt-0 border-t border-bambu-dark-tertiary`,children:(0,W.jsx)(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-3 pt-4`,children:f.map(e=>(0,W.jsx)(Y,{item:e,onPerform:t,onToggle:n,hasPermission:i,t:a},e.id))})})]})}function Z({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[p,h]=(0,H.useState)(null),[g,_]=(0,H.useState)(``),[v,y]=(0,H.useState)(`hours`),[ee,x]=(0,H.useState)(!1),[S,C]=(0,H.useState)(``),[w,E]=(0,H.useState)(`100`),[A,j]=(0,H.useState)(`hours`),[M,re]=(0,H.useState)(`Wrench`),[P,F]=(0,H.useState)(``),[I,L]=(0,H.useState)(new Set),[R,oe]=(0,H.useState)(null),[z,B]=(0,H.useState)(null),V=(0,H.useMemo)(()=>e?e.map(e=>({id:e.printer_id,name:e.printer_name})):[],[e]),U=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})):[],q=t=>{if(!e)return[];let n=new Set(U(t).map(e=>e.printerId));return V.filter(e=>!n.has(e.id))},[Y,X]=(0,H.useState)(null),[Z,Q]=(0,H.useState)(``),[$,se]=(0,H.useState)(``),[ce,le]=(0,H.useState)(`hours`),[ue,de]=(0,H.useState)(`Wrench`),[fe,pe]=(0,H.useState)(``),me=e=>{X(e),Q(e.name),se(e.default_interval_hours.toString()),le(e.interval_type||`hours`),de(e.icon||`Wrench`),pe(e.wiki_url||``)},he=()=>{Y&&Z.trim()&&parseFloat($)>0&&(i(Y.id,{name:Z.trim(),default_interval_hours:parseFloat($),interval_type:ce,icon:ue,wiki_url:fe.trim()||null}),X(null))},ge=(e,t,r)=>{let i=parseFloat(g);!isNaN(i)&&i>0&&n(e,{custom_interval_hours:Math.abs(i-t)<.01?null:i,custom_interval_type:v===r?null:v}),h(null)},_e=e=>{e.preventDefault(),S.trim()&&parseFloat(w)>0&&I.size>0&&(r({name:S.trim(),default_interval_hours:parseFloat(w),interval_type:A,icon:M,wiki_url:P.trim()||null},Array.from(I)),C(``),E(`100`),j(`hours`),F(``),L(new Set),x(!1))},ve=e=>{L(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},ye=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))||[],be=t.filter(e=>e.is_system),xe=t.filter(e=>!e.is_system);return(0,W.jsxs)(`div`,{className:`space-y-8`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between mb-4`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:d(`maintenance.maintenanceTypes`)}),(0,W.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:d(`maintenance.maintenanceTypesDescription`)})]}),(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,W.jsx)(k,{variant:`secondary`,onClick:o,disabled:!u(`maintenance:delete`)||s,title:u(`maintenance:delete`)?void 0:d(`maintenance.noPermissionDeleteTypes`),children:d(`maintenance.restoreDefaults`)}),(0,W.jsxs)(k,{onClick:()=>x(!ee),disabled:!u(`maintenance:create`),title:u(`maintenance:create`)?void 0:d(`maintenance.noPermissionEditTypes`),children:[(0,W.jsx)(ie,{className:`w-4 h-4`}),d(`maintenance.addCustomType`)]})]})]}),ee&&(0,W.jsx)(O,{className:`mb-6`,children:(0,W.jsx)(D,{className:`py-4`,children:(0,W.jsxs)(`form`,{onSubmit:_e,children:[(0,W.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4`,children:[(0,W.jsxs)(`div`,{className:`lg:col-span-2`,children:[(0,W.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1.5`,children:d(`common.name`)}),(0,W.jsx)(`input`,{type:`text`,value:S,onChange:e=>C(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,W.jsxs)(`div`,{children:[(0,W.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1.5`,children:d(`maintenance.intervalType`)}),(0,W.jsxs)(`select`,{value:A,onChange:e=>{j(e.target.value),e.target.value===`days`?E(`30`):E(`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,W.jsx)(`option`,{value:`hours`,children:d(`maintenance.printHours`)}),(0,W.jsx)(`option`,{value:`days`,children:d(`maintenance.calendarDays`)})]})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1.5`,children:d(`maintenance.intervalValue`,{type:A===`days`?d(`maintenance.calendarDays`).toLowerCase():d(`common.hours`)})}),(0,W.jsx)(`input`,{type:`number`,value:w,onChange:e=>E(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,W.jsx)(`div`,{className:`mt-4 flex items-end justify-between`,children:(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1.5`,children:d(`maintenance.icon`)}),(0,W.jsx)(`div`,{className:`flex gap-1`,children:Object.keys(G).map(e=>{let t=G[e];return(0,W.jsx)(`button`,{type:`button`,onClick:()=>re(e),className:`p-2 rounded-lg transition-colors ${M===e?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary`}`,children:(0,W.jsx)(t,{className:`w-4 h-4`})},e)})})]})}),(0,W.jsxs)(`div`,{className:`mt-4`,children:[(0,W.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1.5`,children:d(`maintenance.documentationLink`)}),(0,W.jsx)(`input`,{type:`url`,value:P,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 text-sm focus:border-bambu-green focus:outline-none`,placeholder:`https://wiki.bambulab.com/...`})]}),(0,W.jsxs)(`div`,{className:`mt-4`,children:[(0,W.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1.5`,children:d(`maintenance.assignToPrinters`)}),(0,W.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:V.map(e=>(0,W.jsx)(`button`,{type:`button`,onClick:()=>ve(e.id),className:`px-3 py-1.5 rounded-lg text-sm transition-colors ${I.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))}),I.size===0&&(0,W.jsx)(`p`,{className:`text-xs text-orange-700 dark:text-orange-400 mt-1`,children:d(`maintenance.selectAtLeastOnePrinter`)})]}),(0,W.jsxs)(`div`,{className:`mt-4 flex justify-end gap-2`,children:[(0,W.jsx)(k,{type:`button`,variant:`secondary`,onClick:()=>{x(!1),L(new Set)},children:d(`common.cancel`)}),(0,W.jsx)(k,{type:`submit`,disabled:!S.trim()||I.size===0,children:d(`maintenance.addType`)})]})]})})}),(0,W.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3`,children:[be.map(e=>{let t=K(e.icon),n=e.interval_type||`hours`;return(0,W.jsx)(`div`,{className:`bg-bambu-dark-secondary rounded-xl p-4 border border-bambu-dark-tertiary`,children:(0,W.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,W.jsx)(`div`,{className:`p-2.5 bg-bambu-dark rounded-lg`,children:(0,W.jsx)(t,{className:`w-5 h-5 text-bambu-gray`})}),(0,W.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,W.jsx)(`div`,{className:`text-sm font-medium text-white truncate`,children:e.name}),(0,W.jsxs)(`div`,{className:`text-xs text-bambu-gray mt-0.5 flex items-center gap-1`,children:[n===`days`?(0,W.jsx)(f,{className:`w-3 h-3`}):(0,W.jsx)(T,{className:`w-3 h-3`}),J(e.default_interval_hours,n,d)]})]}),(0,W.jsx)(`button`,{onClick:()=>{u(`maintenance:delete`)&&B(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,W.jsx)(te,{className:`w-4 h-4`})})]})},e.id)}),xe.map(e=>{let t=K(e.icon),n=e.interval_type||`hours`;if(Y?.id===e.id)return(0,W.jsx)(`div`,{className:`bg-bambu-dark-secondary rounded-xl p-4 border border-bambu-green`,children:(0,W.jsxs)(`div`,{className:`space-y-3`,children:[(0,W.jsx)(`input`,{type:`text`,value:Z,onChange:e=>Q(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,W.jsxs)(`div`,{className:`flex gap-2`,children:[(0,W.jsxs)(`select`,{value:ce,onChange:e=>le(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,W.jsx)(`option`,{value:`hours`,children:d(`maintenance.printHours`)}),(0,W.jsx)(`option`,{value:`days`,children:d(`maintenance.calendarDays`)})]}),(0,W.jsx)(`input`,{type:`number`,value:$,onChange:e=>se(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,W.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:Object.keys(G).map(e=>{let t=G[e];return(0,W.jsx)(`button`,{type:`button`,onClick:()=>de(e),className:`p-1.5 rounded transition-colors ${ue===e?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,children:(0,W.jsx)(t,{className:`w-3.5 h-3.5`})},e)})}),(0,W.jsx)(`input`,{type:`url`,value:fe,onChange:e=>pe(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,W.jsxs)(`div`,{className:`flex gap-2`,children:[(0,W.jsx)(k,{size:`sm`,onClick:he,disabled:!Z.trim(),children:d(`common.save`)}),(0,W.jsx)(k,{size:`sm`,variant:`secondary`,onClick:()=>X(null),children:d(`common.cancel`)})]})]})},e.id);let r=U(e.id),i=q(e.id),o=R===e.id;return(0,W.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl p-4 border border-bambu-green/30`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,W.jsx)(`div`,{className:`p-2.5 bg-bambu-green/20 rounded-lg`,children:(0,W.jsx)(t,{className:`w-5 h-5 text-bambu-green`})}),(0,W.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,W.jsx)(`span`,{className:`text-sm font-medium text-white truncate`,children:e.name}),(0,W.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,W.jsxs)(`div`,{className:`text-xs text-bambu-gray mt-0.5 flex items-center gap-1`,children:[n===`days`?(0,W.jsx)(f,{className:`w-3 h-3`}):(0,W.jsx)(T,{className:`w-3 h-3`}),J(e.default_interval_hours,n,d)]})]}),(0,W.jsxs)(`button`,{onClick:()=>oe(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,W.jsx)(ne,{className:`w-3 h-3`}),(0,W.jsx)(`span`,{className:`text-xs font-medium`,children:r.length}),(0,W.jsx)(m,{className:`w-3 h-3 transition-transform ${o?`rotate-180`:``}`})]}),(0,W.jsx)(`button`,{onClick:()=>me(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,W.jsx)(b,{className:`w-4 h-4`})}),(0,W.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,W.jsx)(te,{className:`w-4 h-4`})})]}),o&&(0,W.jsxs)(`div`,{className:`mt-3 pt-3 border-t border-bambu-dark-tertiary`,children:[(0,W.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:d(`maintenance.assignedToPrinters`)}),r.length===0?(0,W.jsx)(`p`,{className:`text-xs text-orange-700 dark:text-orange-400`,children:d(`maintenance.noPrintersAssigned`)}):(0,W.jsx)(`div`,{className:`flex flex-wrap gap-1 mb-2`,children:r.map(e=>(0,W.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,W.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,W.jsxs)(`div`,{className:`flex flex-wrap gap-1`,children:[(0,W.jsx)(`span`,{className:`text-xs text-bambu-gray mr-1`,children:d(`maintenance.addPrinterShort`)}),i.map(t=>(0,W.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)})]})]}),ye.length>0&&(0,W.jsxs)(`div`,{children:[(0,W.jsxs)(`div`,{className:`mb-4`,children:[(0,W.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:d(`maintenance.intervalOverrides`)}),(0,W.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:d(`maintenance.intervalOverridesDescription`)})]}),(0,W.jsx)(`div`,{className:`space-y-4`,children:ye.map(e=>(0,W.jsx)(O,{children:(0,W.jsxs)(D,{className:`py-4`,children:[(0,W.jsx)(`h3`,{className:`text-sm font-medium text-white mb-3`,children:e.printerName}),(0,W.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-2`,children:e.items.map(e=>{let n=K(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=p===e.id;return(0,W.jsxs)(`div`,{className:`flex items-center gap-2 p-2.5 bg-bambu-dark rounded-lg`,children:[(0,W.jsx)(n,{className:`w-4 h-4 text-bambu-gray shrink-0`}),(0,W.jsx)(`span`,{className:`text-xs text-bambu-gray flex-1 truncate`,children:e.maintenance_type_name}),s?(0,W.jsxs)(`div`,{className:`flex items-center gap-1`,children:[v===`days`?(0,W.jsx)(f,{className:`w-3.5 h-3.5 text-bambu-gray shrink-0`}):(0,W.jsx)(T,{className:`w-3.5 h-3.5 text-bambu-gray shrink-0`}),(0,W.jsxs)(`select`,{value:v,onChange:e=>y(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,W.jsx)(`option`,{value:`hours`,children:d(`maintenance.printHours`)}),(0,W.jsx)(`option`,{value:`days`,children:d(`maintenance.calendarDays`)})]}),(0,W.jsx)(`input`,{type:`number`,value:g,onChange:e=>_(e.target.value),onKeyDown:t=>{t.key===`Enter`&&ge(e.id,i,a),t.key===`Escape`&&h(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,W.jsx)(k,{size:`sm`,onClick:()=>ge(e.id,i,a),children:`OK`})]}):(0,W.jsxs)(`button`,{onClick:()=>{u(`maintenance:update`)&&(h(e.id),_(e.interval_hours.toString()),y(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,W.jsx)(f,{className:`w-3 h-3`}):(0,W.jsx)(T,{className:`w-3 h-3`}),J(e.interval_hours,o,d),(0,W.jsx)(b,{className:`w-3 h-3 text-bambu-gray`})]})]},e.id)})})]})},e.printerId))})]}),ye.length===0&&(0,W.jsx)(O,{children:(0,W.jsxs)(D,{className:`text-center py-12`,children:[(0,W.jsx)(N,{className:`w-12 h-12 mx-auto mb-4 text-bambu-gray/30`}),(0,W.jsx)(`p`,{className:`text-bambu-gray`,children:d(`common.noPrinters`)}),(0,W.jsx)(`p`,{className:`text-sm text-bambu-gray/70 mt-1`,children:d(`maintenance.intervalOverridesDescription`)})]})}),z&&(0,W.jsx)(ae,{title:d(`maintenance.deleteSystemTypeTitle`),message:d(`maintenance.deleteSystemTypeMessage`,{name:z.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(z.id),B(null)},onCancel:()=>B(null)})]})}function Q(){let{t:e}=i(),t=a(),{showToast:n}=g(),{hasPermission:c}=oe(),[l,u]=(0,H.useState)(`status`),{data:d,isLoading:f}=o({queryKey:[`maintenanceOverview`],queryFn:r.getMaintenanceOverview}),{data:p}=o({queryKey:[`maintenanceTypes`],queryFn:r.getMaintenanceTypes}),m=s({mutationFn:({id:e,notes:t})=>r.performMaintenance(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceOverview`]}),t.invalidateQueries({queryKey:[`maintenanceSummary`]}),n(e(`maintenance.maintenanceComplete`))},onError:e=>{n(e.message,`error`)}}),h=s({mutationFn:({id:e,data:t})=>r.updateMaintenanceItem(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceOverview`]})},onError:e=>{n(e.message,`error`)}}),_=s({mutationFn:({id:e,data:t})=>r.updateMaintenanceType(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceTypes`]}),t.invalidateQueries({queryKey:[`maintenanceOverview`]}),n(e(`maintenance.typeUpdated`))},onError:e=>{n(e.message,`error`)}}),v=s({mutationFn:r.deleteMaintenanceType,onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceTypes`]}),t.invalidateQueries({queryKey:[`maintenanceOverview`]}),n(e(`maintenance.typeDeleted`))},onError:e=>{n(e.message,`error`)}}),y=s({mutationFn:r.restoreDefaultMaintenanceTypes,onSuccess:r=>{t.invalidateQueries({queryKey:[`maintenanceTypes`]}),t.invalidateQueries({queryKey:[`maintenanceOverview`]}),n(e(`maintenance.defaultsRestored`,{count:r.restored}))},onError:e=>{n(e.message,`error`)}}),b=s({mutationFn:({printerId:e,hours:t})=>r.setPrinterHours(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceOverview`]}),t.invalidateQueries({queryKey:[`maintenanceSummary`]}),n(e(`maintenance.printHoursUpdated`))},onError:e=>{n(e.message,`error`)}}),x=s({mutationFn:({printerId:e,typeId:t})=>r.assignMaintenanceType(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceOverview`]}),n(e(`maintenance.printerAssigned`))},onError:e=>{n(e.message,`error`)}}),S=s({mutationFn:r.removeMaintenanceItem,onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceOverview`]}),n(e(`maintenance.printerRemoved`))},onError:e=>{n(e.message,`error`)}}),C=e=>{m.mutate({id:e})},w=(e,t)=>{h.mutate({id:e,data:{enabled:t}})},T=(e,t)=>{b.mutate({printerId:e,hours:t})};if(f)return(0,W.jsx)(`div`,{className:`p-4 md:p-8 flex justify-center`,children:(0,W.jsx)(ee,{className:`w-8 h-8 text-bambu-green animate-spin`})});let E=d?.reduce((e,t)=>e+t.due_count,0)||0,k=d?.reduce((e,t)=>e+t.warning_count,0)||0;return(0,W.jsxs)(`div`,{className:`p-4 md:p-8`,children:[(0,W.jsxs)(`div`,{className:`mb-6`,children:[(0,W.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,W.jsx)(R,{className:`w-7 h-7 text-bambu-green`}),e(`maintenance.title`)]}),(0,W.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:l===`status`?(0,W.jsxs)(W.Fragment,{children:[E>0&&(0,W.jsx)(`span`,{className:`text-red-700 dark:text-red-400`,children:e(`maintenance.dueCount`,{count:E})}),E>0&&k>0&&` · `,k>0&&(0,W.jsx)(`span`,{className:`text-amber-700 dark:text-amber-400`,children:e(`maintenance.warningCount`,{count:k})}),E===0&&k===0&&(0,W.jsx)(`span`,{className:`text-bambu-green`,children:e(`maintenance.allOk`)})]}):e(`maintenance.configureSettings`)})]}),(0,W.jsxs)(`div`,{className:`flex gap-1 mb-6 border-b border-bambu-dark-tertiary`,children:[(0,W.jsx)(`button`,{onClick:()=>u(`status`),className:`px-4 py-2 text-sm font-medium border-b-2 -mb-px transition-colors ${l===`status`?`text-bambu-green border-bambu-green`:`text-bambu-gray border-transparent hover:text-white`}`,children:e(`maintenance.statusTab`)}),(0,W.jsx)(`button`,{onClick:()=>u(`settings`),className:`px-4 py-2 text-sm font-medium border-b-2 -mb-px transition-colors ${l===`settings`?`text-bambu-green border-bambu-green`:`text-bambu-gray border-transparent hover:text-white`}`,children:e(`maintenance.settingsTab`)})]}),l===`status`?(0,W.jsx)(`div`,{className:`space-y-6`,children:d&&d.length>0?[...d].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,W.jsx)(X,{overview:t,onPerform:C,onToggle:w,onSetHours:T,hasPermission:c,t:e},t.printer_id)):(0,W.jsx)(O,{children:(0,W.jsxs)(D,{className:`text-center py-16`,children:[(0,W.jsx)(R,{className:`w-16 h-16 mx-auto mb-4 text-bambu-gray/30`}),(0,W.jsx)(`p`,{className:`text-lg font-medium text-white mb-2`,children:e(`common.noPrinters`)}),(0,W.jsx)(`p`,{className:`text-bambu-gray`,children:e(`maintenance.configureSettings`)})]})})}):(0,W.jsx)(Z,{overview:d,types:p||[],onUpdateInterval:(e,t)=>h.mutate({id:e,data:t}),onAddType:async(i,a)=>{let o=await r.createMaintenanceType(i);for(let e of a)await r.assignMaintenanceType(e,o.id);t.invalidateQueries({queryKey:[`maintenanceTypes`]}),t.invalidateQueries({queryKey:[`maintenanceOverview`]}),n(e(`maintenance.typeUpdated`))},onUpdateType:(e,t)=>_.mutate({id:e,data:t}),onDeleteType:e=>v.mutate(e),onRestoreDefaults:()=>y.mutate(),isRestoringDefaults:y.isPending,onAssignType:(e,t)=>x.mutate({printerId:e,typeId:t}),onRemoveItem:e=>S.mutate(e),hasPermission:c,t:e})]})}export{Q as MaintenancePage}; \ No newline at end of file +import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,w as i}from"./client-DnySrlFv.js";import{n as a}from"./QueryClientProvider-Ce8_sN3w.js";import{t as o}from"./useQuery-BBCjCezC.js";import{t as s}from"./useMutation-B-Tr2hIP.js";import{t as c}from"./createLucideIcon-DvBYJlWL.js";import{t as l}from"./box-DAdKb9s5.js";import{n as u,t as d}from"./fan-D6AmXZMv.js";import{t as f}from"./calendar-BLKPnWqV.js";import{t as p}from"./check-Ck0cMLU4.js";import{a as m,i as h}from"./info-ROUoQhJR.js";import{n as g}from"./ToastContext-BRX0SW3C.js";import{t as _}from"./cog-Dol1I0kq.js";import{t as v}from"./droplet-CqYXMF2u.js";import{t as y}from"./funnel-C3dyAMK9.js";import{t as ee}from"./loader-circle-BEmFtawu.js";import{t as b}from"./pen-line-BWR04BX-.js";import{t as x}from"./sparkles-DRqKNlhr.js";import{t as S}from"./target-B40GQtrA.js";import{n as C,t as w}from"./wind-CI8UoBMf.js";import{t as T}from"./timer-GUTR9dAu.js";import{t as E}from"./triangle-alert-Dt_1FcBy.js";import{n as D,t as O}from"./Card-Bzc64K35.js";import{t as k}from"./Button-DDr6eAFy.js";import{At as te,Cn as A,Gt as j,Jt as ne,Kt as M,Lt as re,On as N,Vt as P,Zt as ie,_t as ae,bn as F,bt as I,cn as L,xt as R,yt as oe}from"./index-Cxa-KVmA.js";import{t as z}from"./Toggle-KiqA_5fU.js";var B=c(`circle-dot`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}]]),V=c(`ruler`,[[`path`,{d:`M21.3 15.3a2.4 2.4 0 0 1 0 3.4l-2.6 2.6a2.4 2.4 0 0 1-3.4 0L2.7 8.7a2.41 2.41 0 0 1 0-3.4l2.6-2.6a2.41 2.41 0 0 1 3.4 0Z`,key:`icamh8`}],[`path`,{d:`m14.5 12.5 2-2`,key:`inckbg`}],[`path`,{d:`m11.5 9.5 2-2`,key:`fmmyf7`}],[`path`,{d:`m8.5 6.5 2-2`,key:`vc6u1g`}],[`path`,{d:`m17.5 15.5 2-2`,key:`wo5hmg`}]]),H=e(n(),1);function U(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 W=t(),G={Droplet:v,Flame:F,Ruler:V,Sparkles:x,Square:re,Cable:u,Wrench:R,Calendar:f,Timer:T,Cog:_,Fan:d,Zap:I,Wind:w,Thermometer:C,Layers:L,Box:l,Target:S,RefreshCw:M,Settings:P,Filter:y,CircleDot:B};function K(e){return e&&G[e]||R}function q(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 J(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 Y({item:e,onPerform:t,onToggle:n,hasPermission:r,t:i}){let a=K(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,W.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,W.jsxs)(`div`,{className:`flex items-start gap-3 max-[550px]:flex-wrap`,children:[(0,W.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,W.jsx)(a,{className:`w-5 h-5 ${c()}`}),e.enabled&&(e.is_due||e.is_warning)&&(0,W.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,W.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,W.jsx)(`h3`,{className:`font-medium truncate ${e.enabled?`text-white`:`text-bambu-gray`}`,children:e.maintenance_type_name}),o===`days`&&(0,W.jsx)(`span`,{title:i(`maintenance.timeBasedInterval`),children:(0,W.jsx)(f,{className:`w-3.5 h-3.5 text-bambu-gray shrink-0`})}),(()=>{let t=e.maintenance_type_wiki_url||U(e.maintenance_type_name,e.printer_model);return t?(0,W.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,W.jsx)(A,{className:`w-3.5 h-3.5`})}):null})()]}),(0,W.jsx)(`div`,{className:`mt-2 mb-1.5`,children:(0,W.jsx)(`div`,{className:`w-full h-1.5 bg-bambu-dark rounded-full overflow-hidden`,children:(0,W.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,W.jsxs)(`div`,{className:`text-xs flex items-center gap-1 ${c()}`,children:[e.is_due&&(0,W.jsx)(E,{className:`w-3 h-3`}),e.is_warning&&!e.is_due&&(0,W.jsx)(N,{className:`w-3 h-3`}),!e.is_due&&!e.is_warning&&e.enabled&&(0,W.jsx)(p,{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:q(Math.abs(t),`days`,i)}):e.is_warning?i(`maintenance.dueIn`,{duration:q(t,`days`,i)}):i(`maintenance.timeLeft`,{duration:q(t,`days`,i)})}else return e.is_due?i(`maintenance.overdueBy`,{duration:q(Math.abs(e.hours_until_due),`hours`,i)}):e.is_warning?i(`maintenance.dueIn`,{duration:q(e.hours_until_due,`hours`,i)}):i(`maintenance.timeLeft`,{duration:q(e.hours_until_due,`hours`,i)})})()]})]}),(0,W.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0 max-[550px]:w-full max-[550px]:justify-end max-[550px]:mt-1`,children:[(0,W.jsx)(`span`,{title:r(`maintenance:update`)?void 0:i(`maintenance.noPermissionUpdate`),children:(0,W.jsx)(z,{checked:e.enabled,onChange:t=>n(e.id,t),disabled:!r(`maintenance:update`)})}),(0,W.jsxs)(k,{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,W.jsx)(j,{className:`w-3.5 h-3.5`}),i(`common.reset`)]})]})]})})}function X({overview:e,onPerform:t,onToggle:n,onSetHours:r,hasPermission:i,t:a}){let[o,s]=(0,H.useState)(!1),[c,l]=(0,H.useState)(!1),[u,d]=(0,H.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),g=f.find(e=>e.enabled&&(e.is_due||e.is_warning)),_=()=>{let t=parseFloat(u);!isNaN(t)&&t>=0&&(r(e.printer_id,t),l(!1))};return(0,W.jsxs)(O,{className:`overflow-hidden`,children:[(0,W.jsxs)(`div`,{className:`p-5`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,W.jsx)(`h2`,{className:`text-xl font-semibold text-white`,children:e.printer_name}),(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.due_count>0&&(0,W.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,W.jsx)(E,{className:`w-3 h-3`}),a(`maintenance.overdueCount`,{count:e.due_count})]}),e.warning_count>0&&(0,W.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,W.jsx)(N,{className:`w-3 h-3`}),a(`maintenance.dueSoonCount`,{count:e.warning_count})]}),e.due_count===0&&e.warning_count===0&&(0,W.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,W.jsx)(p,{className:`w-3 h-3`}),a(`maintenance.allGood`)]})]})]}),(0,W.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,W.jsx)(h,{className:`w-4 h-4`}):(0,W.jsx)(m,{className:`w-4 h-4`}),a(o?`common.collapse`:`common.expand`)]})]}),(0,W.jsxs)(`div`,{className:`flex items-center gap-6 mt-4`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,W.jsx)(`div`,{className:`p-2 bg-bambu-dark/50 rounded-lg`,children:(0,W.jsx)(T,{className:`w-4 h-4 text-bambu-gray`})}),c?(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,W.jsx)(`input`,{type:`number`,value:u,onChange:e=>d(e.target.value),onKeyDown:e=>{e.key===`Enter`&&_(),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,W.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:a(`common.hours`)}),(0,W.jsx)(k,{size:`sm`,onClick:_,children:a(`common.save`)}),(0,W.jsx)(k,{size:`sm`,variant:`secondary`,onClick:()=>l(!1),children:a(`common.cancel`)})]}):(0,W.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,W.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,W.jsx)(b,{className:`w-3 h-3 text-bambu-gray ${i(`maintenance:update`)?`group-hover:text-bambu-green`:``}`})]}),(0,W.jsx)(`div`,{className:`text-xs text-bambu-gray`,children:a(`maintenance.totalPrintTime`)})]})]}),(0,W.jsx)(`div`,{className:`w-px h-10 bg-bambu-dark-tertiary`}),g&&(0,W.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,W.jsx)(`div`,{className:`p-2 rounded-lg ${g.is_due?`bg-red-500/20`:`bg-amber-500/20`}`,children:(0,W.jsx)(K(g.maintenance_type_icon),{className:`w-4 h-4 ${g.is_due?`text-red-600 dark:text-red-400`:`text-amber-600 dark:text-amber-400`}`})}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`div`,{className:`text-sm font-medium ${g.is_due?`text-red-700 dark:text-red-400`:`text-amber-700 dark:text-amber-400`}`,children:g.maintenance_type_name}),(0,W.jsx)(`div`,{className:`text-xs ${g.is_due?`text-red-700/80 dark:text-red-400/70`:`text-amber-700/80 dark:text-amber-400/70`}`,children:g.is_due?a(`common.overdue`):a(`maintenance.dueSoon`)})]})]})]})]}),o&&(0,W.jsx)(D,{className:`pt-0 border-t border-bambu-dark-tertiary`,children:(0,W.jsx)(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-3 pt-4`,children:f.map(e=>(0,W.jsx)(Y,{item:e,onPerform:t,onToggle:n,hasPermission:i,t:a},e.id))})})]})}function Z({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[p,h]=(0,H.useState)(null),[g,_]=(0,H.useState)(``),[v,y]=(0,H.useState)(`hours`),[ee,x]=(0,H.useState)(!1),[S,C]=(0,H.useState)(``),[w,E]=(0,H.useState)(`100`),[A,j]=(0,H.useState)(`hours`),[M,re]=(0,H.useState)(`Wrench`),[P,F]=(0,H.useState)(``),[I,L]=(0,H.useState)(new Set),[R,oe]=(0,H.useState)(null),[z,B]=(0,H.useState)(null),V=(0,H.useMemo)(()=>e?e.map(e=>({id:e.printer_id,name:e.printer_name})):[],[e]),U=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})):[],q=t=>{if(!e)return[];let n=new Set(U(t).map(e=>e.printerId));return V.filter(e=>!n.has(e.id))},[Y,X]=(0,H.useState)(null),[Z,Q]=(0,H.useState)(``),[$,se]=(0,H.useState)(``),[ce,le]=(0,H.useState)(`hours`),[ue,de]=(0,H.useState)(`Wrench`),[fe,pe]=(0,H.useState)(``),me=e=>{X(e),Q(e.name),se(e.default_interval_hours.toString()),le(e.interval_type||`hours`),de(e.icon||`Wrench`),pe(e.wiki_url||``)},he=()=>{Y&&Z.trim()&&parseFloat($)>0&&(i(Y.id,{name:Z.trim(),default_interval_hours:parseFloat($),interval_type:ce,icon:ue,wiki_url:fe.trim()||null}),X(null))},ge=(e,t,r)=>{let i=parseFloat(g);!isNaN(i)&&i>0&&n(e,{custom_interval_hours:Math.abs(i-t)<.01?null:i,custom_interval_type:v===r?null:v}),h(null)},_e=e=>{e.preventDefault(),S.trim()&&parseFloat(w)>0&&I.size>0&&(r({name:S.trim(),default_interval_hours:parseFloat(w),interval_type:A,icon:M,wiki_url:P.trim()||null},Array.from(I)),C(``),E(`100`),j(`hours`),F(``),L(new Set),x(!1))},ve=e=>{L(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},ye=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))||[],be=t.filter(e=>e.is_system),xe=t.filter(e=>!e.is_system);return(0,W.jsxs)(`div`,{className:`space-y-8`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between mb-4`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:d(`maintenance.maintenanceTypes`)}),(0,W.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:d(`maintenance.maintenanceTypesDescription`)})]}),(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,W.jsx)(k,{variant:`secondary`,onClick:o,disabled:!u(`maintenance:delete`)||s,title:u(`maintenance:delete`)?void 0:d(`maintenance.noPermissionDeleteTypes`),children:d(`maintenance.restoreDefaults`)}),(0,W.jsxs)(k,{onClick:()=>x(!ee),disabled:!u(`maintenance:create`),title:u(`maintenance:create`)?void 0:d(`maintenance.noPermissionEditTypes`),children:[(0,W.jsx)(ie,{className:`w-4 h-4`}),d(`maintenance.addCustomType`)]})]})]}),ee&&(0,W.jsx)(O,{className:`mb-6`,children:(0,W.jsx)(D,{className:`py-4`,children:(0,W.jsxs)(`form`,{onSubmit:_e,children:[(0,W.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4`,children:[(0,W.jsxs)(`div`,{className:`lg:col-span-2`,children:[(0,W.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1.5`,children:d(`common.name`)}),(0,W.jsx)(`input`,{type:`text`,value:S,onChange:e=>C(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,W.jsxs)(`div`,{children:[(0,W.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1.5`,children:d(`maintenance.intervalType`)}),(0,W.jsxs)(`select`,{value:A,onChange:e=>{j(e.target.value),e.target.value===`days`?E(`30`):E(`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,W.jsx)(`option`,{value:`hours`,children:d(`maintenance.printHours`)}),(0,W.jsx)(`option`,{value:`days`,children:d(`maintenance.calendarDays`)})]})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1.5`,children:d(`maintenance.intervalValue`,{type:A===`days`?d(`maintenance.calendarDays`).toLowerCase():d(`common.hours`)})}),(0,W.jsx)(`input`,{type:`number`,value:w,onChange:e=>E(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,W.jsx)(`div`,{className:`mt-4 flex items-end justify-between`,children:(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1.5`,children:d(`maintenance.icon`)}),(0,W.jsx)(`div`,{className:`flex gap-1`,children:Object.keys(G).map(e=>{let t=G[e];return(0,W.jsx)(`button`,{type:`button`,onClick:()=>re(e),className:`p-2 rounded-lg transition-colors ${M===e?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary`}`,children:(0,W.jsx)(t,{className:`w-4 h-4`})},e)})})]})}),(0,W.jsxs)(`div`,{className:`mt-4`,children:[(0,W.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1.5`,children:d(`maintenance.documentationLink`)}),(0,W.jsx)(`input`,{type:`url`,value:P,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 text-sm focus:border-bambu-green focus:outline-none`,placeholder:`https://wiki.bambulab.com/...`})]}),(0,W.jsxs)(`div`,{className:`mt-4`,children:[(0,W.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1.5`,children:d(`maintenance.assignToPrinters`)}),(0,W.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:V.map(e=>(0,W.jsx)(`button`,{type:`button`,onClick:()=>ve(e.id),className:`px-3 py-1.5 rounded-lg text-sm transition-colors ${I.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))}),I.size===0&&(0,W.jsx)(`p`,{className:`text-xs text-orange-700 dark:text-orange-400 mt-1`,children:d(`maintenance.selectAtLeastOnePrinter`)})]}),(0,W.jsxs)(`div`,{className:`mt-4 flex justify-end gap-2`,children:[(0,W.jsx)(k,{type:`button`,variant:`secondary`,onClick:()=>{x(!1),L(new Set)},children:d(`common.cancel`)}),(0,W.jsx)(k,{type:`submit`,disabled:!S.trim()||I.size===0,children:d(`maintenance.addType`)})]})]})})}),(0,W.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3`,children:[be.map(e=>{let t=K(e.icon),n=e.interval_type||`hours`;return(0,W.jsx)(`div`,{className:`bg-bambu-dark-secondary rounded-xl p-4 border border-bambu-dark-tertiary`,children:(0,W.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,W.jsx)(`div`,{className:`p-2.5 bg-bambu-dark rounded-lg`,children:(0,W.jsx)(t,{className:`w-5 h-5 text-bambu-gray`})}),(0,W.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,W.jsx)(`div`,{className:`text-sm font-medium text-white truncate`,children:e.name}),(0,W.jsxs)(`div`,{className:`text-xs text-bambu-gray mt-0.5 flex items-center gap-1`,children:[n===`days`?(0,W.jsx)(f,{className:`w-3 h-3`}):(0,W.jsx)(T,{className:`w-3 h-3`}),J(e.default_interval_hours,n,d)]})]}),(0,W.jsx)(`button`,{onClick:()=>{u(`maintenance:delete`)&&B(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,W.jsx)(te,{className:`w-4 h-4`})})]})},e.id)}),xe.map(e=>{let t=K(e.icon),n=e.interval_type||`hours`;if(Y?.id===e.id)return(0,W.jsx)(`div`,{className:`bg-bambu-dark-secondary rounded-xl p-4 border border-bambu-green`,children:(0,W.jsxs)(`div`,{className:`space-y-3`,children:[(0,W.jsx)(`input`,{type:`text`,value:Z,onChange:e=>Q(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,W.jsxs)(`div`,{className:`flex gap-2`,children:[(0,W.jsxs)(`select`,{value:ce,onChange:e=>le(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,W.jsx)(`option`,{value:`hours`,children:d(`maintenance.printHours`)}),(0,W.jsx)(`option`,{value:`days`,children:d(`maintenance.calendarDays`)})]}),(0,W.jsx)(`input`,{type:`number`,value:$,onChange:e=>se(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,W.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:Object.keys(G).map(e=>{let t=G[e];return(0,W.jsx)(`button`,{type:`button`,onClick:()=>de(e),className:`p-1.5 rounded transition-colors ${ue===e?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,children:(0,W.jsx)(t,{className:`w-3.5 h-3.5`})},e)})}),(0,W.jsx)(`input`,{type:`url`,value:fe,onChange:e=>pe(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,W.jsxs)(`div`,{className:`flex gap-2`,children:[(0,W.jsx)(k,{size:`sm`,onClick:he,disabled:!Z.trim(),children:d(`common.save`)}),(0,W.jsx)(k,{size:`sm`,variant:`secondary`,onClick:()=>X(null),children:d(`common.cancel`)})]})]})},e.id);let r=U(e.id),i=q(e.id),o=R===e.id;return(0,W.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl p-4 border border-bambu-green/30`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,W.jsx)(`div`,{className:`p-2.5 bg-bambu-green/20 rounded-lg`,children:(0,W.jsx)(t,{className:`w-5 h-5 text-bambu-green`})}),(0,W.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,W.jsx)(`span`,{className:`text-sm font-medium text-white truncate`,children:e.name}),(0,W.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,W.jsxs)(`div`,{className:`text-xs text-bambu-gray mt-0.5 flex items-center gap-1`,children:[n===`days`?(0,W.jsx)(f,{className:`w-3 h-3`}):(0,W.jsx)(T,{className:`w-3 h-3`}),J(e.default_interval_hours,n,d)]})]}),(0,W.jsxs)(`button`,{onClick:()=>oe(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,W.jsx)(ne,{className:`w-3 h-3`}),(0,W.jsx)(`span`,{className:`text-xs font-medium`,children:r.length}),(0,W.jsx)(m,{className:`w-3 h-3 transition-transform ${o?`rotate-180`:``}`})]}),(0,W.jsx)(`button`,{onClick:()=>me(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,W.jsx)(b,{className:`w-4 h-4`})}),(0,W.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,W.jsx)(te,{className:`w-4 h-4`})})]}),o&&(0,W.jsxs)(`div`,{className:`mt-3 pt-3 border-t border-bambu-dark-tertiary`,children:[(0,W.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:d(`maintenance.assignedToPrinters`)}),r.length===0?(0,W.jsx)(`p`,{className:`text-xs text-orange-700 dark:text-orange-400`,children:d(`maintenance.noPrintersAssigned`)}):(0,W.jsx)(`div`,{className:`flex flex-wrap gap-1 mb-2`,children:r.map(e=>(0,W.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,W.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,W.jsxs)(`div`,{className:`flex flex-wrap gap-1`,children:[(0,W.jsx)(`span`,{className:`text-xs text-bambu-gray mr-1`,children:d(`maintenance.addPrinterShort`)}),i.map(t=>(0,W.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)})]})]}),ye.length>0&&(0,W.jsxs)(`div`,{children:[(0,W.jsxs)(`div`,{className:`mb-4`,children:[(0,W.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:d(`maintenance.intervalOverrides`)}),(0,W.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:d(`maintenance.intervalOverridesDescription`)})]}),(0,W.jsx)(`div`,{className:`space-y-4`,children:ye.map(e=>(0,W.jsx)(O,{children:(0,W.jsxs)(D,{className:`py-4`,children:[(0,W.jsx)(`h3`,{className:`text-sm font-medium text-white mb-3`,children:e.printerName}),(0,W.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-2`,children:e.items.map(e=>{let n=K(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=p===e.id;return(0,W.jsxs)(`div`,{className:`flex items-center gap-2 p-2.5 bg-bambu-dark rounded-lg`,children:[(0,W.jsx)(n,{className:`w-4 h-4 text-bambu-gray shrink-0`}),(0,W.jsx)(`span`,{className:`text-xs text-bambu-gray flex-1 truncate`,children:e.maintenance_type_name}),s?(0,W.jsxs)(`div`,{className:`flex items-center gap-1`,children:[v===`days`?(0,W.jsx)(f,{className:`w-3.5 h-3.5 text-bambu-gray shrink-0`}):(0,W.jsx)(T,{className:`w-3.5 h-3.5 text-bambu-gray shrink-0`}),(0,W.jsxs)(`select`,{value:v,onChange:e=>y(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,W.jsx)(`option`,{value:`hours`,children:d(`maintenance.printHours`)}),(0,W.jsx)(`option`,{value:`days`,children:d(`maintenance.calendarDays`)})]}),(0,W.jsx)(`input`,{type:`number`,value:g,onChange:e=>_(e.target.value),onKeyDown:t=>{t.key===`Enter`&&ge(e.id,i,a),t.key===`Escape`&&h(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,W.jsx)(k,{size:`sm`,onClick:()=>ge(e.id,i,a),children:`OK`})]}):(0,W.jsxs)(`button`,{onClick:()=>{u(`maintenance:update`)&&(h(e.id),_(e.interval_hours.toString()),y(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,W.jsx)(f,{className:`w-3 h-3`}):(0,W.jsx)(T,{className:`w-3 h-3`}),J(e.interval_hours,o,d),(0,W.jsx)(b,{className:`w-3 h-3 text-bambu-gray`})]})]},e.id)})})]})},e.printerId))})]}),ye.length===0&&(0,W.jsx)(O,{children:(0,W.jsxs)(D,{className:`text-center py-12`,children:[(0,W.jsx)(N,{className:`w-12 h-12 mx-auto mb-4 text-bambu-gray/30`}),(0,W.jsx)(`p`,{className:`text-bambu-gray`,children:d(`common.noPrinters`)}),(0,W.jsx)(`p`,{className:`text-sm text-bambu-gray/70 mt-1`,children:d(`maintenance.intervalOverridesDescription`)})]})}),z&&(0,W.jsx)(ae,{title:d(`maintenance.deleteSystemTypeTitle`),message:d(`maintenance.deleteSystemTypeMessage`,{name:z.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(z.id),B(null)},onCancel:()=>B(null)})]})}function Q(){let{t:e}=i(),t=a(),{showToast:n}=g(),{hasPermission:c}=oe(),[l,u]=(0,H.useState)(`status`),{data:d,isLoading:f}=o({queryKey:[`maintenanceOverview`],queryFn:r.getMaintenanceOverview}),{data:p}=o({queryKey:[`maintenanceTypes`],queryFn:r.getMaintenanceTypes}),m=s({mutationFn:({id:e,notes:t})=>r.performMaintenance(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceOverview`]}),t.invalidateQueries({queryKey:[`maintenanceSummary`]}),n(e(`maintenance.maintenanceComplete`))},onError:e=>{n(e.message,`error`)}}),h=s({mutationFn:({id:e,data:t})=>r.updateMaintenanceItem(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceOverview`]})},onError:e=>{n(e.message,`error`)}}),_=s({mutationFn:({id:e,data:t})=>r.updateMaintenanceType(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceTypes`]}),t.invalidateQueries({queryKey:[`maintenanceOverview`]}),n(e(`maintenance.typeUpdated`))},onError:e=>{n(e.message,`error`)}}),v=s({mutationFn:r.deleteMaintenanceType,onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceTypes`]}),t.invalidateQueries({queryKey:[`maintenanceOverview`]}),n(e(`maintenance.typeDeleted`))},onError:e=>{n(e.message,`error`)}}),y=s({mutationFn:r.restoreDefaultMaintenanceTypes,onSuccess:r=>{t.invalidateQueries({queryKey:[`maintenanceTypes`]}),t.invalidateQueries({queryKey:[`maintenanceOverview`]}),n(e(`maintenance.defaultsRestored`,{count:r.restored}))},onError:e=>{n(e.message,`error`)}}),b=s({mutationFn:({printerId:e,hours:t})=>r.setPrinterHours(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceOverview`]}),t.invalidateQueries({queryKey:[`maintenanceSummary`]}),n(e(`maintenance.printHoursUpdated`))},onError:e=>{n(e.message,`error`)}}),x=s({mutationFn:({printerId:e,typeId:t})=>r.assignMaintenanceType(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceOverview`]}),n(e(`maintenance.printerAssigned`))},onError:e=>{n(e.message,`error`)}}),S=s({mutationFn:r.removeMaintenanceItem,onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceOverview`]}),n(e(`maintenance.printerRemoved`))},onError:e=>{n(e.message,`error`)}}),C=e=>{m.mutate({id:e})},w=(e,t)=>{h.mutate({id:e,data:{enabled:t}})},T=(e,t)=>{b.mutate({printerId:e,hours:t})};if(f)return(0,W.jsx)(`div`,{className:`p-4 md:p-8 flex justify-center`,children:(0,W.jsx)(ee,{className:`w-8 h-8 text-bambu-green animate-spin`})});let E=d?.reduce((e,t)=>e+t.due_count,0)||0,k=d?.reduce((e,t)=>e+t.warning_count,0)||0;return(0,W.jsxs)(`div`,{className:`p-4 md:p-8`,children:[(0,W.jsxs)(`div`,{className:`mb-6`,children:[(0,W.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,W.jsx)(R,{className:`w-7 h-7 text-bambu-green`}),e(`maintenance.title`)]}),(0,W.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:l===`status`?(0,W.jsxs)(W.Fragment,{children:[E>0&&(0,W.jsx)(`span`,{className:`text-red-700 dark:text-red-400`,children:e(`maintenance.dueCount`,{count:E})}),E>0&&k>0&&` · `,k>0&&(0,W.jsx)(`span`,{className:`text-amber-700 dark:text-amber-400`,children:e(`maintenance.warningCount`,{count:k})}),E===0&&k===0&&(0,W.jsx)(`span`,{className:`text-bambu-green`,children:e(`maintenance.allOk`)})]}):e(`maintenance.configureSettings`)})]}),(0,W.jsxs)(`div`,{className:`flex gap-1 mb-6 border-b border-bambu-dark-tertiary`,children:[(0,W.jsx)(`button`,{onClick:()=>u(`status`),className:`px-4 py-2 text-sm font-medium border-b-2 -mb-px transition-colors ${l===`status`?`text-bambu-green border-bambu-green`:`text-bambu-gray border-transparent hover:text-white`}`,children:e(`maintenance.statusTab`)}),(0,W.jsx)(`button`,{onClick:()=>u(`settings`),className:`px-4 py-2 text-sm font-medium border-b-2 -mb-px transition-colors ${l===`settings`?`text-bambu-green border-bambu-green`:`text-bambu-gray border-transparent hover:text-white`}`,children:e(`maintenance.settingsTab`)})]}),l===`status`?(0,W.jsx)(`div`,{className:`space-y-6`,children:d&&d.length>0?[...d].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,W.jsx)(X,{overview:t,onPerform:C,onToggle:w,onSetHours:T,hasPermission:c,t:e},t.printer_id)):(0,W.jsx)(O,{children:(0,W.jsxs)(D,{className:`text-center py-16`,children:[(0,W.jsx)(R,{className:`w-16 h-16 mx-auto mb-4 text-bambu-gray/30`}),(0,W.jsx)(`p`,{className:`text-lg font-medium text-white mb-2`,children:e(`common.noPrinters`)}),(0,W.jsx)(`p`,{className:`text-bambu-gray`,children:e(`maintenance.configureSettings`)})]})})}):(0,W.jsx)(Z,{overview:d,types:p||[],onUpdateInterval:(e,t)=>h.mutate({id:e,data:t}),onAddType:async(i,a)=>{let o=await r.createMaintenanceType(i);for(let e of a)await r.assignMaintenanceType(e,o.id);t.invalidateQueries({queryKey:[`maintenanceTypes`]}),t.invalidateQueries({queryKey:[`maintenanceOverview`]}),n(e(`maintenance.typeUpdated`))},onUpdateType:(e,t)=>_.mutate({id:e,data:t}),onDeleteType:e=>v.mutate(e),onRestoreDefaults:()=>y.mutate(),isRestoringDefaults:y.isPending,onAssignType:(e,t)=>x.mutate({printerId:e,typeId:t}),onRemoveItem:e=>S.mutate(e),hasPermission:c,t:e})]})}export{Q as MaintenancePage}; \ No newline at end of file diff --git a/static/assets/ModelSourcesPage-Crhk7_mU.js b/static/assets/ModelSourcesPage-CI9pVpjC.js similarity index 99% rename from static/assets/ModelSourcesPage-Crhk7_mU.js rename to static/assets/ModelSourcesPage-CI9pVpjC.js index f6e58c795..462341d0d 100644 --- a/static/assets/ModelSourcesPage-Crhk7_mU.js +++ b/static/assets/ModelSourcesPage-CI9pVpjC.js @@ -1 +1 @@ -import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,t as i,w as a}from"./client-DnySrlFv.js";import{n as o}from"./QueryClientProvider-Ce8_sN3w.js";import{t as s}from"./useQuery-BBCjCezC.js";import{t as c}from"./useMutation-B-Tr2hIP.js";import{t as l}from"./createLucideIcon-DvBYJlWL.js";import{t as u}from"./arrow-left-0Q6F2rjC.js";import{t as d}from"./arrow-right-DedpIMhP.js";import{t as f}from"./box-DAdKb9s5.js";import{t as p}from"./check-Ck0cMLU4.js";import{r as m}from"./info-ROUoQhJR.js";import{n as h}from"./ToastContext-BRX0SW3C.js";import{t as g}from"./cog-Dol1I0kq.js";import{t as _}from"./SliceModal-TzmWgODN.js";import{t as v}from"./loader-circle-BEmFtawu.js";import{t as y}from"./search-0n0CBc74.js";import{t as b}from"./x-DR-Trv6U.js";import{i as x,n as S,t as C}from"./Card-Bzc64K35.js";import{t as w}from"./Button-DDr6eAFy.js";import{At as T,Cn as E,Mn as D,Rn as O,Vn as k,Vt as A,Wn as j,_t as M,hn as N,jn as ee,vn as P,wn as te,yt as ne}from"./index-0t--Yqoi.js";import{a as re,o as ie}from"./slicer-DgCA7cW6.js";import{t as ae}from"./purify.es-F_7NWVtX.js";import{t as oe}from"./libraryFiles-B0B1SFfn.js";var F=l(`images`,[[`path`,{d:`m22 11-1.296-1.296a2.4 2.4 0 0 0-3.408 0L11 16`,key:`9kzy35`}],[`path`,{d:`M4 8a2 2 0 0 0-2 2v10a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2`,key:`1t0f0t`}],[`circle`,{cx:`13`,cy:`7`,r:`1`,fill:`currentColor`,key:`1obus6`}],[`rect`,{x:`8`,y:`2`,width:`14`,height:`14`,rx:`2`,key:`1gvhby`}]]),I=l(`library`,[[`path`,{d:`m16 6 4 14`,key:`ji33uf`}],[`path`,{d:`M12 6v14`,key:`1n7gus`}],[`path`,{d:`M8 8v12`,key:`1gg7y9`}],[`path`,{d:`M4 4v16`,key:`6qkkli`}]]),L=e(n(),1),R=t(),z=new Set([`manyfold_not_configured`,`manyfold_credentials`,`manyfold_scope`,`manyfold_rate_limited`,`manyfold_unreachable`,`manyfold_forbidden`,`manyfold_not_found`,`manyfold_too_large`,`manyfold_not_importable`,`manyfold_bad_url`,`manyfold_secret_required`,`manyfold_failed`]);function B(e,t){return e instanceof i&&e.code&&z.has(e.code)?t(`manyfold.errors.${e.code}`):e instanceof Error&&e.message?e.message:t(`manyfold.errors.manyfold_failed`)}function V(e){return((e.split(`/`)[1]??``).replace(/^x-/,``).split(/[+.;]/)[0]||`?`).toUpperCase()}function H(e,t=0,n=[]){n.push({folder:e,depth:t});for(let r of e.children??[])H(r,t+1,n);return n}function U({modelId:e,className:t}){let{data:n,isLoading:i}=s({queryKey:[`manyfold-preview`,e],queryFn:()=>r.getManyfoldPreview(e),staleTime:1/0,retry:!1}),[a,o]=(0,L.useState)(null);return(0,L.useEffect)(()=>{if(!n){o(null);return}let e=URL.createObjectURL(n);return o(e),()=>URL.revokeObjectURL(e)},[n]),(0,R.jsx)(`div`,{className:`flex items-center justify-center bg-bambu-dark overflow-hidden ${t??``}`,children:a?(0,R.jsx)(`img`,{src:a,alt:``,className:`w-full h-full object-contain`}):i?(0,R.jsx)(v,{className:`w-6 h-6 text-bambu-gray animate-spin`}):(0,R.jsx)(f,{className:`w-10 h-10 text-bambu-gray/50`,"aria-hidden":!0})})}function W({onDone:e}){let{t}=a(),{showToast:n}=h(),i=o(),l=s({queryKey:[`manyfold-config`],queryFn:()=>r.getManyfoldConfig()}),[u,d]=(0,L.useState)(``),[f,p]=(0,L.useState)(``),[m,g]=(0,L.useState)(``),[_,y]=(0,L.useState)(null),[b,T]=(0,L.useState)(!1);(0,L.useEffect)(()=>{l.data&&(d(l.data.url),p(l.data.client_id))},[l.data]);let E=l.data?.has_client_secret??!1,D={url:u.trim(),client_id:f.trim(),client_secret:m.trim()||void 0},O=!!D.url&&!!D.client_id&&(!!D.client_secret||E),k=()=>{i.invalidateQueries({queryKey:[`manyfold-config`]}),i.invalidateQueries({queryKey:[`manyfold-status`]}),i.invalidateQueries({queryKey:[`manyfold-models`]}),i.invalidateQueries({queryKey:[`manyfold-model`]}),i.invalidateQueries({queryKey:[`manyfold-preview`]})},j=c({mutationFn:()=>r.testManyfoldConfig(D),onSuccess:e=>y({ok:!0,text:t(`manyfold.testOk`,{count:e.model_count})}),onError:e=>y({ok:!1,text:B(e,t)})}),N=c({mutationFn:()=>r.updateManyfoldConfig(D),onSuccess:()=>{g(``),k(),n(t(`settings.toast.settingsSaved`),`success`),e?.()},onError:e=>n(B(e,t),`error`)}),ee=c({mutationFn:()=>r.deleteManyfoldConfig(),onSuccess:()=>{T(!1),d(``),p(``),g(``),y(null),k(),n(t(`manyfold.disconnected`),`success`)},onError:e=>{T(!1),n(B(e,t),`error`)}}),P=`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`;return(0,R.jsxs)(C,{children:[(0,R.jsx)(x,{children:(0,R.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,R.jsx)(A,{className:`w-5 h-5 text-bambu-green`}),t(`manyfold.connectionTitle`)]})}),(0,R.jsxs)(S,{className:`space-y-4`,children:[(0,R.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:t(`manyfold.connectionHelp`)}),(0,R.jsxs)(`form`,{className:`space-y-3`,onSubmit:e=>{e.preventDefault(),O&&N.mutate()},children:[(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`label`,{htmlFor:`manyfold-url`,className:`block text-sm text-bambu-gray mb-1`,children:t(`manyfold.url`)}),(0,R.jsx)(`input`,{id:`manyfold-url`,type:`url`,value:u,onChange:e=>{d(e.target.value),y(null)},placeholder:t(`manyfold.urlPlaceholder`),className:P,autoComplete:`off`})]}),(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`label`,{htmlFor:`manyfold-client-id`,className:`block text-sm text-bambu-gray mb-1`,children:t(`manyfold.clientId`)}),(0,R.jsx)(`input`,{id:`manyfold-client-id`,type:`text`,value:f,onChange:e=>{p(e.target.value),y(null)},className:P,autoComplete:`off`})]}),(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`label`,{htmlFor:`manyfold-client-secret`,className:`block text-sm text-bambu-gray mb-1`,children:t(`manyfold.clientSecret`)}),(0,R.jsx)(`input`,{id:`manyfold-client-secret`,type:`password`,value:m,onChange:e=>{g(e.target.value),y(null)},placeholder:E?t(`manyfold.clientSecretStored`):``,className:P,autoComplete:`new-password`})]}),_&&(0,R.jsx)(`p`,{role:`status`,className:`text-sm ${_.ok?`text-bambu-green`:`text-red-400`}`,children:_.text}),(0,R.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,R.jsxs)(w,{type:`submit`,disabled:!O||N.isPending,children:[N.isPending?(0,R.jsx)(v,{className:`w-4 h-4 animate-spin`}):null,t(`common.save`)]}),(0,R.jsxs)(w,{type:`button`,variant:`secondary`,disabled:!O||j.isPending,onClick:()=>j.mutate(),children:[j.isPending?(0,R.jsx)(v,{className:`w-4 h-4 animate-spin`}):null,t(`manyfold.test`)]}),l.data?.configured&&(0,R.jsx)(w,{type:`button`,variant:`danger`,onClick:()=>T(!0),children:t(`manyfold.disconnect`)}),e&&l.data?.configured&&(0,R.jsx)(w,{type:`button`,variant:`ghost`,onClick:e,children:t(`common.cancel`)})]})]})]}),b&&(0,R.jsx)(M,{title:t(`manyfold.disconnectTitle`),message:t(`manyfold.disconnectBody`),confirmText:t(`manyfold.disconnect`),variant:`danger`,isLoading:ee.isPending,onCancel:()=>T(!1),onConfirm:()=>ee.mutate()})]})}function se({value:e,onChange:t,disabled:n}){let{t:i}=a(),o=(s({queryKey:[`library-folders`],queryFn:()=>r.getLibraryFolders()}).data??[]).filter(e=>!(e.is_external&&e.external_readonly)).flatMap(e=>H(e));return(0,R.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-bambu-gray`,children:[i(`manyfold.importTo`),(0,R.jsxs)(`select`,{value:e??``,disabled:n,onChange:e=>t(e.target.value?Number(e.target.value):null),className:`px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm`,children:[(0,R.jsx)(`option`,{value:``,children:i(`manyfold.folderAuto`)}),o.map(({folder:e,depth:t})=>(0,R.jsx)(`option`,{value:e.id,disabled:e.can_write===!1,children:`${`— `.repeat(t)}${e.name}`},e.id))]})]})}function G(e){return e.length>3?`${e.slice(0,3).join(`, `)} +${e.length-3}`:e.join(`, `)}function K(){let{t:e}=a(),{showToast:t}=h(),n=o(),[i,s]=(0,L.useState)(null);return{run:async(i,a)=>{if(i.length===0){t(e(`manyfold.bulkNothing`),`info`);return}let o=0,c=0,l=[],u=null;try{for(let e=0;er.getManyfoldModel(e)}),N=s({queryKey:[`settings`],queryFn:()=>r.getSettings()}),ee=N.data?.use_slicer_api??!1,re=ie(N.data?.open_in_slicer,N.data?.preferred_slicer),ae=c({mutationFn:t=>r.importManyfoldFile(e,t.id,y),onMutate:e=>D(e.id),onSettled:()=>D(null),onSuccess:t=>{f.invalidateQueries({queryKey:[`manyfold-model`,e]}),f.invalidateQueries({queryKey:[`library-files`]}),f.invalidateQueries({queryKey:[`library-folders`]}),d(t.was_existing?i(`manyfold.alreadyInLibrary`):i(`manyfold.imported`,{filename:t.filename}),`success`)},onError:e=>d(B(e,i),`error`)});if(M.isLoading)return(0,R.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,R.jsx)(v,{className:`w-8 h-8 text-bambu-green animate-spin`})});if(M.isError||!M.data)return(0,R.jsxs)(`div`,{className:`space-y-4`,children:[(0,R.jsxs)(w,{variant:`ghost`,size:`sm`,onClick:t,children:[(0,R.jsx)(u,{className:`w-4 h-4`}),i(`manyfold.back`)]}),(0,R.jsx)(`p`,{className:`text-red-400 text-sm`,children:B(M.error,i)})]});let F=M.data,I=F.files.filter(e=>e.importable&&!e.library_file),z=I.filter(e=>O.has(e.id)),H=I.length>0&&z.length===I.length,W=j.busy||ae.isPending,G=async e=>{await j.run(e.map(e=>({modelId:F.id,fileId:e.id,name:e.name})),y),A(new Set)};return(0,R.jsxs)(`div`,{className:`space-y-4`,children:[(0,R.jsxs)(w,{variant:`ghost`,size:`sm`,onClick:t,children:[(0,R.jsx)(u,{className:`w-4 h-4`}),i(`manyfold.back`)]}),(0,R.jsx)(C,{children:(0,R.jsx)(S,{children:(0,R.jsxs)(`div`,{className:`flex flex-col md:flex-row gap-6 py-2`,children:[(0,R.jsx)(U,{modelId:F.id,className:`w-full md:w-72 aspect-square rounded-lg shrink-0`}),(0,R.jsxs)(`div`,{className:`min-w-0 flex-1 space-y-3`,children:[(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`h2`,{className:`text-xl font-semibold text-white break-words`,children:F.name}),F.caption&&(0,R.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:F.caption})]}),F.description&&(0,R.jsx)(`p`,{className:`text-sm text-bambu-gray whitespace-pre-line break-words`,children:F.description}),F.tags.length>0&&(0,R.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:F.tags.map(e=>(0,R.jsx)(`span`,{className:`px-2 py-0.5 rounded-full bg-bambu-dark-tertiary text-xs text-white`,children:e},e))}),(0,R.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2 text-sm`,children:[F.license&&(0,R.jsxs)(`span`,{className:`text-bambu-gray`,children:[i(`manyfold.license`),`: `,(0,R.jsx)(`span`,{className:`text-white`,children:F.license})]}),(0,R.jsxs)(`a`,{href:F.url,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-1 text-bambu-green hover:underline`,children:[(0,R.jsx)(E,{className:`w-3.5 h-3.5`}),i(`manyfold.openInManyfold`)]})]})]})]})})}),(0,R.jsxs)(C,{children:[(0,R.jsxs)(x,{children:[(0,R.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,R.jsx)(`h3`,{className:`text-lg font-semibold text-white`,children:i(`manyfold.files`)}),_&&(0,R.jsx)(se,{value:y,onChange:b,disabled:W})]}),_&&I.length>0&&(0,R.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 mt-3`,children:[(0,R.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-white`,children:[(0,R.jsx)(`input`,{type:`checkbox`,checked:H,ref:e=>{e&&(e.indeterminate=z.length>0&&!H)},disabled:W,onChange:()=>A(H?new Set:new Set(I.map(e=>e.id))),className:`accent-bambu-green`}),i(`manyfold.selectAll`)]}),j.progress?(0,R.jsxs)(`span`,{className:`inline-flex items-center gap-2 text-sm text-bambu-gray`,children:[(0,R.jsx)(v,{className:`w-4 h-4 animate-spin`}),i(`manyfold.importProgress`,j.progress)]}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(w,{variant:`primary`,size:`sm`,disabled:W||z.length===0,onClick:()=>G(z),children:[(0,R.jsx)(te,{className:`w-3.5 h-3.5`}),i(`manyfold.importSelected`,{count:z.length})]}),(0,R.jsx)(w,{variant:`secondary`,size:`sm`,disabled:W,onClick:()=>G(I),children:i(`manyfold.importAll`)})]})]})]}),(0,R.jsx)(S,{children:F.files.length===0?(0,R.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`manyfold.noFiles`)}):(0,R.jsx)(`ul`,{className:`divide-y divide-bambu-dark-tertiary`,children:F.files.map(e=>{let t=e.library_file,r=t!==null&&oe({filename:t.filename},ee,re);return(0,R.jsxs)(`li`,{className:`flex flex-wrap items-center gap-3 py-2`,children:[_&&I.length>0&&(0,R.jsx)(`span`,{className:`w-4 shrink-0 flex`,children:e.importable&&!t&&(0,R.jsx)(`input`,{type:`checkbox`,"aria-label":i(`manyfold.selectFile`,{name:e.name}),checked:O.has(e.id),disabled:W,onChange:()=>A(t=>{let n=new Set(t);return n.has(e.id)?n.delete(e.id):n.add(e.id),n}),className:`accent-bambu-green`})}),(0,R.jsx)(`span`,{className:`px-1.5 py-0.5 rounded bg-bambu-dark-tertiary text-[11px] font-mono text-bambu-gray shrink-0`,children:V(e.mime)}),(0,R.jsx)(`span`,{className:`text-sm text-white min-w-0 flex-1 break-words`,children:e.name}),(0,R.jsx)(`div`,{className:`flex flex-wrap items-center gap-2`,children:e.importable?t?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-xs text-bambu-green`,children:[(0,R.jsx)(p,{className:`w-3.5 h-3.5`}),i(`manyfold.inLibrary`)]}),(0,R.jsxs)(w,{variant:`ghost`,size:`sm`,onClick:()=>m(t.folder_id?`/files?folder=${t.folder_id}`:`/files`),children:[(0,R.jsx)(P,{className:`w-3.5 h-3.5`}),i(`manyfold.showInLibrary`)]}),r&&(0,R.jsxs)(w,{variant:`ghost`,size:`sm`,onClick:()=>n(t.id,t.filename),children:[(0,R.jsx)(g,{className:`w-3.5 h-3.5`}),i(`slice.action`,`Slice`)]})]}):_?(0,R.jsxs)(w,{variant:`secondary`,size:`sm`,disabled:W,onClick:()=>ae.mutate(e),children:[T===e.id?(0,R.jsx)(v,{className:`w-3.5 h-3.5 animate-spin`}):(0,R.jsx)(te,{className:`w-3.5 h-3.5`}),T===e.id?i(`manyfold.importing`):i(`manyfold.import`)]}):null:(0,R.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:i(`manyfold.notImportable`)})})]},e.id)})})})]})]})}function le(){let{t:e}=a(),{hasPermission:t}=ne(),n=t(`settings:update`),[i,c]=(0,L.useState)(!1),[l,u]=(0,L.useState)(``),[d,f]=(0,L.useState)(``),[p,m]=(0,L.useState)(1),[g,b]=(0,L.useState)(null),[x,T]=(0,L.useState)(null),[E,O]=(0,L.useState)(new Map),[k,j]=(0,L.useState)(null),[M,N]=(0,L.useState)(null),P=t(`manyfold:import`),ae=o(),{showToast:oe}=h(),F=K(),I=M!==null||F.busy,z=M?e(`manyfold.collectProgress`,M):F.progress?e(`manyfold.importProgress`,F.progress):null,V=(e,t)=>O(n=>{let r=new Map(n);return r.has(e)?r.delete(e):r.set(e,t),r}),H=async()=>{let t=[...E.keys()],n=[],i=[];try{for(let e=0;er.getManyfoldModel(t[e])});for(let e of i.files)e.importable&&!e.library_file&&n.push({modelId:i.id,fileId:e.id,name:`${i.name}: ${e.name}`})}catch{i.push(E.get(t[e])??t[e])}}}finally{N(null)}i.length&&oe(e(`manyfold.modelsUnreadable`,{names:G(i)}),`error`),await F.run(n,k),O(new Map)},le=s({queryKey:[`settings`],queryFn:()=>r.getSettings()}),q=s({queryKey:[`manyfold-status`],queryFn:()=>r.getManyfoldStatus()}),ue=q.data?.configured??!1,J=s({queryKey:[`manyfold-models`,d,p],queryFn:()=>r.listManyfoldModels(d,p),enabled:ue,placeholderData:e=>e}),Y=async(e,t)=>{if(le.data?.use_slicer_api){T({kind:`libraryFile`,id:e,filename:t});return}let n=ie(le.data?.open_in_slicer,le.data?.preferred_slicer);try{let{token:i}=await r.createLibrarySlicerToken(e);re(`${window.location.origin}${r.getLibrarySlicerDownloadUrl(e,i,t)}`,n)}catch{re(`${window.location.origin}${r.getLibraryFileDownloadUrl(e)}`,n)}};if(q.isLoading)return(0,R.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,R.jsx)(v,{className:`w-8 h-8 text-bambu-green animate-spin`})});if(!ue||i)return(0,R.jsxs)(`div`,{className:`space-y-6`,children:[(0,R.jsx)(`p`,{className:`text-bambu-gray`,children:e(`manyfold.description`)}),n?(0,R.jsx)(W,{onDone:ue?()=>c(!1):void 0}):(0,R.jsx)(C,{children:(0,R.jsx)(S,{children:(0,R.jsxs)(`div`,{className:`py-2`,children:[(0,R.jsx)(`p`,{className:`font-medium text-white`,children:e(`manyfold.notConnectedTitle`)}),(0,R.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:e(`manyfold.notConnectedBody`)})]})})})]});let X=J.data;return(0,R.jsxs)(`div`,{className:`space-y-6`,children:[g?(0,R.jsx)(ce,{modelId:g,onBack:()=>b(null),onSlice:Y}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,R.jsx)(`p`,{className:`text-bambu-gray flex-1 min-w-[16rem]`,children:e(`manyfold.description`)}),n&&(0,R.jsxs)(w,{variant:`ghost`,size:`sm`,onClick:()=>c(!0),children:[(0,R.jsx)(A,{className:`w-4 h-4`}),e(`manyfold.editConnection`)]})]}),(0,R.jsxs)(`form`,{className:`flex gap-2`,role:`search`,onSubmit:e=>{e.preventDefault(),f(l.trim()),m(1)},children:[(0,R.jsxs)(`div`,{className:`relative flex-1`,children:[(0,R.jsx)(y,{className:`w-4 h-4 text-bambu-gray absolute left-3 top-1/2 -translate-y-1/2`}),(0,R.jsx)(`input`,{type:`search`,value:l,onChange:e=>u(e.target.value),placeholder:e(`manyfold.searchPlaceholder`),"aria-label":e(`manyfold.searchPlaceholder`),className:`w-full pl-9 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`})]}),(0,R.jsx)(w,{type:`submit`,children:e(`common.search`)})]}),J.isError?(0,R.jsx)(`p`,{className:`text-sm text-red-400`,children:B(J.error,e)}):X?X.models.length===0?(0,R.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`manyfold.noModels`)}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,R.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`manyfold.modelCount`,{count:X.total})}),P&&(0,R.jsx)(w,{variant:`ghost`,size:`sm`,disabled:I,onClick:()=>O(e=>{let t=new Map(e);for(let e of X.models)t.set(e.id,e.name);return t}),children:e(`manyfold.selectPage`)})]}),P&&E.size>0&&(0,R.jsxs)(`div`,{className:`sticky top-0 z-10 flex flex-wrap items-center gap-3 rounded-lg border border-bambu-green/40 bg-bambu-dark-secondary px-4 py-3`,children:[(0,R.jsx)(`span`,{className:`text-sm text-white`,children:e(`manyfold.modelsSelected`,{count:E.size})}),(0,R.jsx)(se,{value:k,onChange:j,disabled:I}),z?(0,R.jsxs)(`span`,{className:`inline-flex items-center gap-2 text-sm text-bambu-gray`,children:[(0,R.jsx)(v,{className:`w-4 h-4 animate-spin`}),z]}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(w,{variant:`primary`,size:`sm`,onClick:H,children:[(0,R.jsx)(te,{className:`w-3.5 h-3.5`}),e(`manyfold.importModels`)]}),(0,R.jsx)(w,{variant:`ghost`,size:`sm`,onClick:()=>O(new Map),children:e(`manyfold.clearSelection`)})]})]}),(0,R.jsx)(`div`,{className:`grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-4 xl:grid-cols-6 gap-4`,children:X.models.map(t=>{let n=E.has(t.id);return(0,R.jsxs)(`div`,{className:`relative rounded-lg border bg-bambu-dark-secondary overflow-hidden transition-colors ${n?`border-bambu-green ring-1 ring-bambu-green`:`border-bambu-dark-tertiary hover:border-bambu-green`}`,children:[(0,R.jsxs)(`button`,{type:`button`,onClick:()=>b(t.id),disabled:I,className:`block w-full text-left disabled:cursor-wait`,children:[(0,R.jsx)(U,{modelId:t.id,className:`aspect-square`}),(0,R.jsx)(`span`,{className:`block px-3 py-2 text-sm text-white truncate`,title:t.name,children:t.name})]}),P&&(0,R.jsx)(`label`,{className:`absolute top-2 left-2 flex items-center justify-center w-7 h-7 rounded bg-black/60 cursor-pointer`,children:(0,R.jsx)(`input`,{type:`checkbox`,"aria-label":e(`manyfold.selectModel`,{name:t.name}),checked:n,disabled:I,onChange:()=>V(t.id,t.name),className:`accent-bambu-green w-4 h-4`})})]},t.id)})}),(X.has_previous||X.has_next)&&(0,R.jsxs)(`div`,{className:`flex items-center justify-center gap-3`,children:[(0,R.jsxs)(w,{variant:`secondary`,size:`sm`,disabled:!X.has_previous||J.isFetching,onClick:()=>m(e=>Math.max(1,e-1)),children:[(0,R.jsx)(ee,{className:`w-4 h-4`}),e(`manyfold.previous`)]}),(0,R.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e(`manyfold.page`,{page:X.page})}),(0,R.jsxs)(w,{variant:`secondary`,size:`sm`,disabled:!X.has_next||J.isFetching,onClick:()=>m(e=>e+1),children:[e(`manyfold.next`),(0,R.jsx)(D,{className:`w-4 h-4`})]})]})]}):(0,R.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,R.jsx)(v,{className:`w-8 h-8 text-bambu-green animate-spin`})})]}),x&&(0,R.jsx)(_,{source:x,onClose:()=>T(null)})]})}function q(e,t){let n=e?.[t];return typeof n==`string`?n:``}function ue(e){return e.replace(/(https?:\/\/(?:makerworld|public-cdn)\.bblmw\.com\/[^\s"']+)/gi,e=>`/api/v1/makerworld/thumbnail?url=${encodeURIComponent(e)}`)}function J(e){return e?/^https?:\/\/(makerworld|public-cdn)\.bblmw\.com\//i.test(e)?`/api/v1/makerworld/thumbnail?url=${encodeURIComponent(e)}`:e:``}function Y(e,t){let n=e?.[t];return typeof n==`number`?n:null}function X(e,t){let n=e?.[t];return n&&typeof n==`object`&&!Array.isArray(n)?n:void 0}function de(e,t=0,n=[]){n.push({folder:e,depth:t});for(let r of e.children??[])de(r,t+1,n);return n}function fe(e,t){return t(e<1?`makerworld.phaseResolving`:`makerworld.phaseDownloading`)}function pe(e){let[t,n]=(0,L.useState)(0);return(0,L.useEffect)(()=>{if(!e){n(0);return}let t=Date.now(),r=()=>n(Math.floor((Date.now()-t)/1e3));r();let i=window.setInterval(r,1e3);return()=>window.clearInterval(i)},[e]),t}function me({embedded:e=!1}={}){let{t}=a(),{hasPermission:n}=ne(),{showToast:i}=h(),l=o(),u=n(`makerworld:import`),[f,y]=(0,L.useState)(``),[k,A]=(0,L.useState)(null),[j,oe]=(0,L.useState)(null),[I,z]=(0,L.useState)(null),[B,V]=(0,L.useState)(null),[H,U]=(0,L.useState)(null),[W,se]=(0,L.useState)(``),[G,K]=(0,L.useState)({}),ce=s({queryKey:[`makerworld-status`],queryFn:()=>r.getMakerworldStatus()}),le=s({queryKey:[`library-folders`],queryFn:()=>r.getLibraryFolders()}),me=s({queryKey:[`makerworld-recent-imports`],queryFn:()=>r.getMakerworldRecentImports(10)}),he=s({queryKey:[`settings`],queryFn:()=>r.getSettings()}),ge=he.data?.use_slicer_api??!1,_e=he.data?.preferred_slicer||`bambu_studio`,ve=ie(he.data?.open_in_slicer,he.data?.preferred_slicer),ye=ge?_e:ve,be=ye===`orcaslicer`?`OrcaSlicer`:`Bambu Studio`,[xe,Se]=(0,L.useState)(null),Ce=(e,t)=>{Se({kind:`libraryFile`,id:e,filename:t})},we=c({mutationFn:e=>r.resolveMakerworldUrl(e),onSuccess:(e,t)=>{A(e),se(t),K({})},onError:e=>i(e.message||t(`makerworld.errors.resolveFailed`),`error`)});(0,L.useEffect)(()=>{k!==null&&f.trim()!==W.trim()&&(A(null),se(``),K({}))},[f,k,W]);let Z=c({mutationFn:({instanceId:e,profileId:t})=>r.importMakerworldInstance(k?.model_id??0,e,t,j),onSuccess:e=>{l.invalidateQueries({queryKey:[`library-files`]}),l.invalidateQueries({queryKey:[`library-folders`]}),e.profile_id&&K(t=>({...t,[e.profile_id]:e})),i(e.was_existing?t(`makerworld.alreadyInLibrary`):t(`makerworld.importSuccess`,{filename:e.filename}),`success`)},onError:e=>i(e.message||t(`makerworld.errors.downloadFailed`),`error`)}),Te=c({mutationFn:({libraryFileId:e})=>r.deleteLibraryFile(e),onSuccess:(e,{profileId:n})=>{l.invalidateQueries({queryKey:[`library-files`]}),l.invalidateQueries({queryKey:[`library-folders`]}),l.invalidateQueries({queryKey:[`makerworld-recent-imports`]}),K(e=>{let t={...e};return delete t[n],t}),V(null),i(t(`makerworld.importDeleted`),`success`)},onError:e=>{V(null),i(e.message||t(`makerworld.errors.deleteFailed`),`error`)}}),Ee=c({mutationFn:({instanceId:e,profileId:t})=>r.importMakerworldInstance(k?.model_id??0,e,t,j),onSuccess:async e=>{l.invalidateQueries({queryKey:[`library-files`]}),l.invalidateQueries({queryKey:[`library-folders`]}),l.invalidateQueries({queryKey:[`makerworld-recent-imports`]}),e.profile_id&&K(t=>({...t,[e.profile_id]:e})),ge?Ce(e.library_file_id,e.filename):await je(e.library_file_id,e.filename,ye)},onError:e=>i(e.message||t(`makerworld.errors.downloadFailed`),`error`)}),Q=pe(Z.isPending||Ee.isPending),De=fe(Q,t),Oe=e=>{e?.preventDefault();let t=f.trim();t&&we.mutate(t)};(0,L.useEffect)(()=>{if(!H)return;let e=e=>{e.key===`Escape`?U(null):e.key===`ArrowLeft`?U(e=>e&&e.index>0?{...e,index:e.index-1}:e):e.key===`ArrowRight`&&U(e=>e&&e.indexwindow.removeEventListener(`keydown`,e)},[H]);let ke=e=>{let t=(Array.isArray(e.pictures)?e.pictures:[]).filter(e=>typeof e==`object`&&!!e).map(e=>({name:q(e,`name`)||`image`,url:q(e,`url`)})).filter(e=>e.url);if(t.length>0)return t;let n=q(e,`cover`);return n?[{name:`cover`,url:n}]:[]},Ae=async()=>{if(!k)return;let e=k.instances.filter(e=>{let t=Y(e,`profileId`);return t!==null&&!G[t]});if(e.length!==0){z({current:0,total:e.length});try{for(let t=0;t{try{let{token:i}=await r.createLibrarySlicerToken(e),a=r.getLibrarySlicerDownloadUrl(e,i,t);re(`${window.location.origin}${a}`,n)}catch{let t=r.getLibraryFileDownloadUrl(e);re(`${window.location.origin}${t}`,n)}},$=k?.design,Me=X($,`designCreator`),Ne=k?.instances??[],Pe=(k?.already_imported_library_ids.length??0)>0,Fe=ce.data?.can_download??!1,Ie=ce.data?.sign_in_expired??!1,Le=(0,L.useMemo)(()=>q($,`coverUrl`),[$]),Re=q($,`title`),ze=q($,`summary`),Be=q($,`license`),Ve=Y($,`downloadCount`);return(0,R.jsxs)(`div`,{className:e?`space-y-6`:`p-4 md:p-8 max-w-screen-2xl space-y-6`,children:[e?(0,R.jsx)(`p`,{className:`text-bambu-gray`,children:t(`makerworld.description`)}):(0,R.jsxs)(`div`,{children:[(0,R.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,R.jsx)(N,{className:`w-7 h-7 text-bambu-green`}),t(`makerworld.title`)]}),(0,R.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:t(`makerworld.description`)})]}),(0,R.jsxs)(`div`,{className:`grid gap-6 lg:grid-cols-[1fr_20rem]`,children:[(0,R.jsxs)(`div`,{className:`space-y-6 min-w-0`,children:[!Fe&&(0,R.jsx)(C,{className:`border-amber-300 dark:border-amber-700 bg-amber-50 dark:bg-amber-900/20`,children:(0,R.jsx)(S,{children:(0,R.jsxs)(`div`,{className:`flex items-start gap-3 py-2`,children:[(0,R.jsx)(m,{className:`w-5 h-5 text-amber-600 dark:text-amber-400 mt-0.5 shrink-0`}),(0,R.jsxs)(`div`,{className:`text-sm`,children:[(0,R.jsx)(`p`,{className:`font-medium text-amber-900 dark:text-amber-100`,children:t(Ie?`makerworld.signInExpiredTitle`:`makerworld.signInRequiredTitle`)}),(0,R.jsxs)(`p`,{className:`text-amber-800 dark:text-amber-200 mt-1`,children:[t(Ie?`makerworld.signInExpiredBody`:`makerworld.signInRequiredBody`),` `,(0,R.jsx)(O,{to:`/profiles`,className:`underline`,children:t(`makerworld.openCloudSettings`)})]})]})]})})}),(0,R.jsxs)(C,{children:[(0,R.jsx)(x,{children:(0,R.jsx)(`h2`,{className:`text-lg font-semibold`,children:t(`makerworld.pasteUrlHeader`)})}),(0,R.jsx)(S,{children:(0,R.jsxs)(`form`,{onSubmit:Oe,className:`flex gap-2`,children:[(0,R.jsx)(`input`,{type:`text`,value:f,onChange:e=>y(e.target.value),placeholder:t(`makerworld.pasteUrlPlaceholder`),className:`flex-1 min-w-0 px-3 py-2 border rounded bg-white dark:bg-gray-800 border-gray-300 dark:border-gray-700`,autoComplete:`off`}),(0,R.jsxs)(w,{type:`submit`,variant:`primary`,disabled:!f.trim()||we.isPending,children:[we.isPending?(0,R.jsx)(v,{className:`w-4 h-4 animate-spin`}):(0,R.jsx)(d,{className:`w-4 h-4`}),(0,R.jsx)(`span`,{className:`ml-2`,children:t(`makerworld.resolveButton`)})]})]})})]}),k&&(0,R.jsx)(C,{children:(0,R.jsx)(S,{children:(0,R.jsxs)(`div`,{className:`flex gap-4 py-2`,children:[Le&&(0,R.jsx)(`img`,{src:J(Le),alt:Re,className:`w-32 h-32 object-cover rounded`,loading:`lazy`}),(0,R.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,R.jsx)(`h3`,{className:`text-xl font-semibold truncate`,children:Re||t(`makerworld.untitledModel`)}),Me&&(0,R.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400 mt-1`,children:t(`makerworld.byCreator`,{name:q(Me,`name`)})}),(0,R.jsxs)(`div`,{className:`flex flex-wrap gap-3 mt-2 text-xs text-gray-500 dark:text-gray-400`,children:[Ve!==null&&(0,R.jsx)(`span`,{children:t(`makerworld.downloadsCount`,{count:Ve})}),Be&&(0,R.jsxs)(`span`,{children:[t(`makerworld.licensePrefix`),`: `,Be]}),Pe&&(0,R.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-emerald-600 dark:text-emerald-400`,children:[(0,R.jsx)(p,{className:`w-3 h-3`}),` `,t(`makerworld.alreadyImported`)]})]}),ze&&(0,R.jsx)(`div`,{className:`mt-3 text-sm prose prose-sm max-w-none dark:prose-invert line-clamp-3`,dangerouslySetInnerHTML:{__html:ae.sanitize(ue(ze))}}),k&&(0,R.jsxs)(`a`,{href:`https://makerworld.com/models/${k.model_id}${k.profile_id?`#profileId-${k.profile_id}`:``}`,target:`_blank`,rel:`noopener noreferrer`,className:`mt-3 inline-flex items-center gap-1 text-xs text-brand-500 hover:underline`,children:[(0,R.jsx)(E,{className:`w-3 h-3`}),` `,t(`makerworld.openOnMakerworld`)]})]})]})})}),k&&Ne.length>0&&(0,R.jsxs)(C,{children:[(0,R.jsx)(x,{children:(0,R.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,R.jsx)(`h2`,{className:`text-lg font-semibold`,children:t(`makerworld.platesHeader`,{count:Ne.length})}),(0,R.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,R.jsx)(`label`,{className:`text-xs text-gray-600 dark:text-gray-400`,children:t(`makerworld.importTo`)}),(0,R.jsxs)(`select`,{value:j??``,onChange:e=>oe(e.target.value?Number(e.target.value):null),className:`text-sm px-2 py-1 border rounded bg-white dark:bg-gray-800 border-gray-300 dark:border-gray-700`,disabled:I!==null,children:[(0,R.jsx)(`option`,{value:``,children:t(`makerworld.folderAuto`)}),(le.data??[]).filter(e=>!(e.is_external&&e.external_readonly)).flatMap(e=>de(e)).map(({folder:e,depth:t})=>(0,R.jsx)(`option`,{value:e.id,disabled:e.can_write===!1,children:`${`— `.repeat(t)}${e.name}`},e.id))]}),(0,R.jsx)(w,{variant:`primary`,size:`sm`,disabled:!u||!Fe||I!==null||Z.isPending||Ee.isPending,onClick:Ae,children:I===null?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(te,{className:`w-4 h-4`}),(0,R.jsx)(`span`,{className:`ml-2`,children:t(`makerworld.importAll`)})]}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(v,{className:`w-4 h-4 animate-spin`}),(0,R.jsxs)(`span`,{className:`ml-2`,children:[t(`makerworld.importAllProgress`,{current:I.current,total:I.total}),Q>0&&` · ${De} · ${Q}s`]})]})})]})]})}),(0,R.jsx)(S,{children:(0,R.jsx)(`div`,{className:`grid gap-3`,children:Ne.map((e,n)=>{let r=Y(e,`id`),i=Y(e,`profileId`),a=q(e,`title`),o=q(e,`cover`),s=Y(e,`materialCnt`),c=e?.needAms===!0,l=Y(e,`downloadCount`),d=e?.compatibility??null,f=e?.otherCompatibility??null,m=d?.devProductName??null,h=Array.isArray(f)?f.map(e=>e?.devProductName??``).filter(Boolean):[];if(r==null)return null;let _=Z.isPending&&Z.variables?.instanceId===r,y=Ee.isPending&&Ee.variables?.instanceId===r,b=i===null?void 0:G[i];return(0,R.jsxs)(`div`,{className:`flex flex-col gap-2 p-3 border rounded border-gray-200 dark:border-gray-700`,children:[(0,R.jsxs)(`div`,{className:`flex gap-3 items-center`,children:[(()=>{let n=ke(e),r=n.length>0;return(0,R.jsxs)(`button`,{type:`button`,disabled:!r,onClick:()=>r&&U({images:n,index:0}),className:`relative w-16 h-16 shrink-0 rounded overflow-hidden group`,"aria-label":t(`makerworld.openGallery`),children:[o?(0,R.jsx)(`img`,{src:J(o),alt:``,className:`w-16 h-16 object-cover`,loading:`lazy`}):(0,R.jsx)(`div`,{className:`w-16 h-16 bg-gray-100 dark:bg-gray-800`}),n.length>1&&(0,R.jsxs)(`span`,{className:`absolute bottom-0.5 right-0.5 bg-black/70 text-white text-[10px] px-1.5 py-0.5 rounded flex items-center gap-1`,children:[(0,R.jsx)(F,{className:`w-2.5 h-2.5`}),n.length]})]})})(),(0,R.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,R.jsx)(`p`,{className:`font-medium truncate`,children:a||t(`makerworld.plateDefaultName`,{n:n+1})}),(0,R.jsxs)(`div`,{className:`flex flex-wrap gap-3 text-xs text-gray-500 dark:text-gray-400 mt-1`,children:[m&&(0,R.jsx)(`span`,{className:`font-medium text-gray-700 dark:text-gray-300`,children:t(`makerworld.slicedFor`,{printer:m,defaultValue:`Sliced for {{printer}}`})}),s!==null&&(0,R.jsx)(`span`,{children:t(`makerworld.materialCount`,{count:s})}),c&&(0,R.jsx)(`span`,{children:t(`makerworld.amsRequired`)}),l!==null&&(0,R.jsx)(`span`,{children:t(`makerworld.downloadsCount`,{count:l})})]}),h.length>0&&(0,R.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mt-1`,title:h.join(`, `),children:t(`makerworld.alsoCompatible`,{printers:h.slice(0,6).join(`, `)+(h.length>6?`…`:``),defaultValue:`Also marked compatible: {{printers}}`})})]}),(0,R.jsxs)(`div`,{className:`flex gap-2 shrink-0`,children:[(0,R.jsx)(w,{variant:`ghost`,size:`sm`,disabled:!u||!Fe||_||y||I!==null,onClick:()=>Z.mutate({instanceId:r,profileId:i}),title:Fe?void 0:t(`makerworld.signInRequiredTitle`),children:_?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(v,{className:`w-4 h-4 animate-spin`}),(0,R.jsxs)(`span`,{className:`ml-2`,children:[De,Q>0&&` · ${Q}s`]})]}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(te,{className:`w-4 h-4`}),(0,R.jsx)(`span`,{className:`ml-2`,children:t(`makerworld.importToLibrary`)})]})}),(0,R.jsx)(w,{variant:`primary`,size:`sm`,disabled:!u||!Fe||_||y||I!==null,onClick:()=>Ee.mutate({instanceId:r,profileId:i}),title:Fe?void 0:t(`makerworld.signInRequiredTitle`),children:y?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(v,{className:`w-4 h-4 animate-spin`}),(0,R.jsxs)(`span`,{className:`ml-2`,children:[De,Q>0&&` · ${Q}s`]})]}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(E,{className:`w-4 h-4`}),(0,R.jsx)(`span`,{className:`ml-2`,children:t(`makerworld.sliceIn`,{slicer:be})})]})})]})]}),b&&(0,R.jsxs)(`div`,{className:`flex items-center gap-2 pl-20 text-xs`,children:[(0,R.jsx)(p,{className:`w-3.5 h-3.5 text-emerald-600 dark:text-emerald-400 shrink-0`}),(0,R.jsx)(`span`,{className:`text-emerald-700 dark:text-emerald-300`,children:b.was_existing?t(`makerworld.lastImportAlreadyInLibrary`):t(`makerworld.lastImportSuccess`)}),(0,R.jsxs)(w,{variant:`ghost`,size:`sm`,onClick:()=>{let e=b.folder_id?`/files?folder=${b.folder_id}`:`/files`;window.location.assign(e)},children:[(0,R.jsx)(P,{className:`w-3.5 h-3.5`}),(0,R.jsx)(`span`,{className:`ml-1.5`,children:t(`makerworld.viewInLibrary`)})]}),ge?(0,R.jsxs)(w,{variant:`ghost`,size:`sm`,onClick:()=>Ce(b.library_file_id,b.filename),children:[(0,R.jsx)(g,{className:`w-3.5 h-3.5`}),(0,R.jsx)(`span`,{className:`ml-1.5`,children:t(`slice.action`,`Slice`)})]}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(w,{variant:`ghost`,size:`sm`,onClick:()=>je(b.library_file_id,b.filename,`bambu_studio`),children:[(0,R.jsx)(E,{className:`w-3.5 h-3.5`}),(0,R.jsx)(`span`,{className:`ml-1.5`,children:t(`makerworld.openInBambuStudio`)})]}),(0,R.jsxs)(w,{variant:`ghost`,size:`sm`,onClick:()=>je(b.library_file_id,b.filename,`orcaslicer`),children:[(0,R.jsx)(E,{className:`w-3.5 h-3.5`}),(0,R.jsx)(`span`,{className:`ml-1.5`,children:t(`makerworld.openInOrcaSlicer`)})]})]}),(0,R.jsx)(`div`,{className:`ml-auto`,children:(0,R.jsx)(w,{variant:`ghost`,size:`sm`,disabled:Te.isPending&&Te.variables?.profileId===i,onClick:()=>{i!==null&&V({libraryFileId:b.library_file_id,profileId:i,filename:b.filename})},title:t(`makerworld.deleteImport`),children:Te.isPending&&Te.variables?.profileId===i?(0,R.jsx)(v,{className:`w-3.5 h-3.5 animate-spin`}):(0,R.jsx)(T,{className:`w-3.5 h-3.5 text-red-500`})})})]})]},r)})})})]})]}),(0,R.jsx)(`aside`,{className:`lg:sticky lg:top-6 lg:self-start min-w-0`,children:me.data&&me.data.length>0&&(0,R.jsxs)(C,{children:[(0,R.jsx)(x,{children:(0,R.jsx)(`h2`,{className:`text-base font-semibold`,children:t(`makerworld.recentImportsHeader`)})}),(0,R.jsx)(S,{children:(0,R.jsx)(`div`,{className:`flex flex-col gap-2 max-h-[28rem] overflow-y-auto -mx-2 px-2`,children:me.data.map(e=>(0,R.jsxs)(`div`,{className:`flex gap-2 p-2 border rounded border-gray-200 dark:border-gray-700`,children:[e.thumbnail_path?(0,R.jsx)(`img`,{src:r.getLibraryFileThumbnailUrl(e.library_file_id),alt:``,className:`w-12 h-12 shrink-0 object-cover rounded bg-gray-100 dark:bg-gray-800`,loading:`lazy`}):(0,R.jsx)(`div`,{className:`w-12 h-12 shrink-0 rounded bg-gray-100 dark:bg-gray-800`}),(0,R.jsxs)(`div`,{className:`flex-1 min-w-0 flex flex-col gap-1`,children:[(0,R.jsx)(`p`,{className:`text-xs font-medium truncate`,title:e.filename,children:e.filename}),(0,R.jsxs)(`div`,{className:`flex gap-0.5`,children:[(0,R.jsx)(w,{variant:`ghost`,size:`sm`,onClick:()=>{let t=e.folder_id?`/files?folder=${e.folder_id}`:`/files`;window.location.assign(t)},title:t(`makerworld.viewInLibrary`),children:(0,R.jsx)(P,{className:`w-3.5 h-3.5`})}),ge?(0,R.jsx)(w,{variant:`ghost`,size:`sm`,onClick:()=>Ce(e.library_file_id,e.filename),title:t(`slice.action`,`Slice`),children:(0,R.jsx)(g,{className:`w-3.5 h-3.5`})}):(0,R.jsx)(w,{variant:`ghost`,size:`sm`,onClick:()=>je(e.library_file_id,e.filename,`bambu_studio`),title:t(`makerworld.openInBambuStudio`),children:(0,R.jsx)(E,{className:`w-3.5 h-3.5`})}),e.source_url&&(0,R.jsx)(`a`,{href:e.source_url,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center justify-center h-7 w-7 rounded text-gray-500 hover:text-gray-700 dark:hover:text-gray-300`,title:t(`makerworld.openOnMakerworld`),children:(0,R.jsx)(N,{className:`w-3.5 h-3.5`})})]})]})]},e.library_file_id))})})]})})]}),(0,R.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 pt-4 border-t border-gray-200 dark:border-gray-700`,children:t(`makerworld.disclaimer`)}),B&&(0,R.jsx)(M,{title:t(`makerworld.deleteImport`),message:t(`makerworld.confirmDelete`,{filename:B.filename}),confirmText:t(`makerworld.deleteImport`),variant:`danger`,isLoading:Te.isPending,loadingText:t(`makerworld.importDeleting`),onCancel:()=>V(null),onConfirm:()=>Te.mutate({libraryFileId:B.libraryFileId,profileId:B.profileId})}),xe&&(0,R.jsx)(_,{source:xe,onClose:()=>Se(null)}),H&&(0,R.jsxs)(`div`,{className:`fixed inset-0 bg-black/90 flex items-center justify-center z-50`,onClick:()=>U(null),role:`dialog`,"aria-modal":`true`,children:[(0,R.jsx)(`button`,{type:`button`,className:`absolute top-4 right-4 p-2 bg-white/10 hover:bg-white/20 rounded-full text-white`,onClick:e=>{e.stopPropagation(),U(null)},"aria-label":t(`common.close`,`Close`),children:(0,R.jsx)(b,{className:`w-5 h-5`})}),H.images.length>1&&(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`button`,{type:`button`,className:`absolute left-4 p-2 bg-white/10 hover:bg-white/20 rounded-full text-white disabled:opacity-30`,disabled:H.index===0,onClick:e=>{e.stopPropagation(),U(e=>e&&{...e,index:Math.max(0,e.index-1)})},"aria-label":t(`makerworld.galleryPrev`),children:(0,R.jsx)(ee,{className:`w-6 h-6`})}),(0,R.jsx)(`button`,{type:`button`,className:`absolute right-4 p-2 bg-white/10 hover:bg-white/20 rounded-full text-white disabled:opacity-30`,disabled:H.index>=H.images.length-1,onClick:e=>{e.stopPropagation(),U(e=>e&&{...e,index:Math.min(e.images.length-1,e.index+1)})},"aria-label":t(`makerworld.galleryNext`),children:(0,R.jsx)(D,{className:`w-6 h-6`})})]}),(0,R.jsx)(`img`,{src:J(H.images[H.index].url),alt:H.images[H.index].name,className:`max-w-[90vw] max-h-[90vh] object-contain`,onClick:e=>e.stopPropagation()}),H.images.length>1&&(0,R.jsxs)(`div`,{className:`absolute bottom-6 left-1/2 -translate-x-1/2 text-white bg-black/60 px-3 py-1 rounded text-xs`,children:[H.index+1,` / `,H.images.length]})]})]})}function he(){let{t:e}=a(),{hasPermission:t}=ne(),[n,i]=j(),o=t(`manyfold:view`),c=s({queryKey:[`manyfold-status`],queryFn:()=>r.getManyfoldStatus(),enabled:o}),l=o&&(c.data?.configured===!0||t(`settings:update`)),u=[];t(`makerworld:view`)&&u.push({id:`makerworld`,label:e(`modelSources.tabMakerworld`),icon:N}),l&&u.push({id:`manyfold`,label:e(`modelSources.tabManyfold`),icon:I});let d=n.get(`tab`),f=u.find(e=>e.id===d)?.id??u[0]?.id??(o?`manyfold`:void 0);return(0,R.jsxs)(`div`,{className:`p-4 md:p-8 max-w-screen-2xl`,children:[(0,R.jsx)(`div`,{className:`mb-6`,children:(0,R.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,R.jsx)(N,{className:`w-7 h-7 text-bambu-green`}),e(`modelSources.title`)]})}),u.length>1&&(0,R.jsx)(`div`,{className:`flex border-b border-bambu-dark-tertiary mb-6`,role:`tablist`,children:u.map(({id:e,label:t,icon:n})=>(0,R.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":f===e,onClick:()=>i({tab:e},{replace:!0}),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${f===e?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-white border-transparent`}`,children:[(0,R.jsx)(n,{className:`w-4 h-4`}),t]},e))}),f===`makerworld`&&(0,R.jsx)(me,{embedded:!0}),f===`manyfold`&&(0,R.jsx)(le,{})]})}export{he as ModelSourcesPage}; \ No newline at end of file +import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,t as i,w as a}from"./client-DnySrlFv.js";import{n as o}from"./QueryClientProvider-Ce8_sN3w.js";import{t as s}from"./useQuery-BBCjCezC.js";import{t as c}from"./useMutation-B-Tr2hIP.js";import{t as l}from"./createLucideIcon-DvBYJlWL.js";import{t as u}from"./arrow-left-0Q6F2rjC.js";import{t as d}from"./arrow-right-DedpIMhP.js";import{t as f}from"./box-DAdKb9s5.js";import{t as p}from"./check-Ck0cMLU4.js";import{r as m}from"./info-ROUoQhJR.js";import{n as h}from"./ToastContext-BRX0SW3C.js";import{t as g}from"./cog-Dol1I0kq.js";import{t as _}from"./SliceModal-YlJTMEj6.js";import{t as v}from"./loader-circle-BEmFtawu.js";import{t as y}from"./search-0n0CBc74.js";import{t as b}from"./x-DR-Trv6U.js";import{i as x,n as S,t as C}from"./Card-Bzc64K35.js";import{t as w}from"./Button-DDr6eAFy.js";import{At as T,Cn as E,Mn as D,Rn as O,Vn as k,Vt as A,Wn as j,_t as M,hn as N,jn as ee,vn as P,wn as te,yt as ne}from"./index-Cxa-KVmA.js";import{a as re,o as ie}from"./slicer-DgCA7cW6.js";import{t as ae}from"./purify.es-F_7NWVtX.js";import{t as oe}from"./libraryFiles-B0B1SFfn.js";var F=l(`images`,[[`path`,{d:`m22 11-1.296-1.296a2.4 2.4 0 0 0-3.408 0L11 16`,key:`9kzy35`}],[`path`,{d:`M4 8a2 2 0 0 0-2 2v10a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2`,key:`1t0f0t`}],[`circle`,{cx:`13`,cy:`7`,r:`1`,fill:`currentColor`,key:`1obus6`}],[`rect`,{x:`8`,y:`2`,width:`14`,height:`14`,rx:`2`,key:`1gvhby`}]]),I=l(`library`,[[`path`,{d:`m16 6 4 14`,key:`ji33uf`}],[`path`,{d:`M12 6v14`,key:`1n7gus`}],[`path`,{d:`M8 8v12`,key:`1gg7y9`}],[`path`,{d:`M4 4v16`,key:`6qkkli`}]]),L=e(n(),1),R=t(),z=new Set([`manyfold_not_configured`,`manyfold_credentials`,`manyfold_scope`,`manyfold_rate_limited`,`manyfold_unreachable`,`manyfold_forbidden`,`manyfold_not_found`,`manyfold_too_large`,`manyfold_not_importable`,`manyfold_bad_url`,`manyfold_secret_required`,`manyfold_failed`]);function B(e,t){return e instanceof i&&e.code&&z.has(e.code)?t(`manyfold.errors.${e.code}`):e instanceof Error&&e.message?e.message:t(`manyfold.errors.manyfold_failed`)}function V(e){return((e.split(`/`)[1]??``).replace(/^x-/,``).split(/[+.;]/)[0]||`?`).toUpperCase()}function H(e,t=0,n=[]){n.push({folder:e,depth:t});for(let r of e.children??[])H(r,t+1,n);return n}function U({modelId:e,className:t}){let{data:n,isLoading:i}=s({queryKey:[`manyfold-preview`,e],queryFn:()=>r.getManyfoldPreview(e),staleTime:1/0,retry:!1}),[a,o]=(0,L.useState)(null);return(0,L.useEffect)(()=>{if(!n){o(null);return}let e=URL.createObjectURL(n);return o(e),()=>URL.revokeObjectURL(e)},[n]),(0,R.jsx)(`div`,{className:`flex items-center justify-center bg-bambu-dark overflow-hidden ${t??``}`,children:a?(0,R.jsx)(`img`,{src:a,alt:``,className:`w-full h-full object-contain`}):i?(0,R.jsx)(v,{className:`w-6 h-6 text-bambu-gray animate-spin`}):(0,R.jsx)(f,{className:`w-10 h-10 text-bambu-gray/50`,"aria-hidden":!0})})}function W({onDone:e}){let{t}=a(),{showToast:n}=h(),i=o(),l=s({queryKey:[`manyfold-config`],queryFn:()=>r.getManyfoldConfig()}),[u,d]=(0,L.useState)(``),[f,p]=(0,L.useState)(``),[m,g]=(0,L.useState)(``),[_,y]=(0,L.useState)(null),[b,T]=(0,L.useState)(!1);(0,L.useEffect)(()=>{l.data&&(d(l.data.url),p(l.data.client_id))},[l.data]);let E=l.data?.has_client_secret??!1,D={url:u.trim(),client_id:f.trim(),client_secret:m.trim()||void 0},O=!!D.url&&!!D.client_id&&(!!D.client_secret||E),k=()=>{i.invalidateQueries({queryKey:[`manyfold-config`]}),i.invalidateQueries({queryKey:[`manyfold-status`]}),i.invalidateQueries({queryKey:[`manyfold-models`]}),i.invalidateQueries({queryKey:[`manyfold-model`]}),i.invalidateQueries({queryKey:[`manyfold-preview`]})},j=c({mutationFn:()=>r.testManyfoldConfig(D),onSuccess:e=>y({ok:!0,text:t(`manyfold.testOk`,{count:e.model_count})}),onError:e=>y({ok:!1,text:B(e,t)})}),N=c({mutationFn:()=>r.updateManyfoldConfig(D),onSuccess:()=>{g(``),k(),n(t(`settings.toast.settingsSaved`),`success`),e?.()},onError:e=>n(B(e,t),`error`)}),ee=c({mutationFn:()=>r.deleteManyfoldConfig(),onSuccess:()=>{T(!1),d(``),p(``),g(``),y(null),k(),n(t(`manyfold.disconnected`),`success`)},onError:e=>{T(!1),n(B(e,t),`error`)}}),P=`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`;return(0,R.jsxs)(C,{children:[(0,R.jsx)(x,{children:(0,R.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,R.jsx)(A,{className:`w-5 h-5 text-bambu-green`}),t(`manyfold.connectionTitle`)]})}),(0,R.jsxs)(S,{className:`space-y-4`,children:[(0,R.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:t(`manyfold.connectionHelp`)}),(0,R.jsxs)(`form`,{className:`space-y-3`,onSubmit:e=>{e.preventDefault(),O&&N.mutate()},children:[(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`label`,{htmlFor:`manyfold-url`,className:`block text-sm text-bambu-gray mb-1`,children:t(`manyfold.url`)}),(0,R.jsx)(`input`,{id:`manyfold-url`,type:`url`,value:u,onChange:e=>{d(e.target.value),y(null)},placeholder:t(`manyfold.urlPlaceholder`),className:P,autoComplete:`off`})]}),(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`label`,{htmlFor:`manyfold-client-id`,className:`block text-sm text-bambu-gray mb-1`,children:t(`manyfold.clientId`)}),(0,R.jsx)(`input`,{id:`manyfold-client-id`,type:`text`,value:f,onChange:e=>{p(e.target.value),y(null)},className:P,autoComplete:`off`})]}),(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`label`,{htmlFor:`manyfold-client-secret`,className:`block text-sm text-bambu-gray mb-1`,children:t(`manyfold.clientSecret`)}),(0,R.jsx)(`input`,{id:`manyfold-client-secret`,type:`password`,value:m,onChange:e=>{g(e.target.value),y(null)},placeholder:E?t(`manyfold.clientSecretStored`):``,className:P,autoComplete:`new-password`})]}),_&&(0,R.jsx)(`p`,{role:`status`,className:`text-sm ${_.ok?`text-bambu-green`:`text-red-400`}`,children:_.text}),(0,R.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,R.jsxs)(w,{type:`submit`,disabled:!O||N.isPending,children:[N.isPending?(0,R.jsx)(v,{className:`w-4 h-4 animate-spin`}):null,t(`common.save`)]}),(0,R.jsxs)(w,{type:`button`,variant:`secondary`,disabled:!O||j.isPending,onClick:()=>j.mutate(),children:[j.isPending?(0,R.jsx)(v,{className:`w-4 h-4 animate-spin`}):null,t(`manyfold.test`)]}),l.data?.configured&&(0,R.jsx)(w,{type:`button`,variant:`danger`,onClick:()=>T(!0),children:t(`manyfold.disconnect`)}),e&&l.data?.configured&&(0,R.jsx)(w,{type:`button`,variant:`ghost`,onClick:e,children:t(`common.cancel`)})]})]})]}),b&&(0,R.jsx)(M,{title:t(`manyfold.disconnectTitle`),message:t(`manyfold.disconnectBody`),confirmText:t(`manyfold.disconnect`),variant:`danger`,isLoading:ee.isPending,onCancel:()=>T(!1),onConfirm:()=>ee.mutate()})]})}function se({value:e,onChange:t,disabled:n}){let{t:i}=a(),o=(s({queryKey:[`library-folders`],queryFn:()=>r.getLibraryFolders()}).data??[]).filter(e=>!(e.is_external&&e.external_readonly)).flatMap(e=>H(e));return(0,R.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-bambu-gray`,children:[i(`manyfold.importTo`),(0,R.jsxs)(`select`,{value:e??``,disabled:n,onChange:e=>t(e.target.value?Number(e.target.value):null),className:`px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm`,children:[(0,R.jsx)(`option`,{value:``,children:i(`manyfold.folderAuto`)}),o.map(({folder:e,depth:t})=>(0,R.jsx)(`option`,{value:e.id,disabled:e.can_write===!1,children:`${`— `.repeat(t)}${e.name}`},e.id))]})]})}function G(e){return e.length>3?`${e.slice(0,3).join(`, `)} +${e.length-3}`:e.join(`, `)}function K(){let{t:e}=a(),{showToast:t}=h(),n=o(),[i,s]=(0,L.useState)(null);return{run:async(i,a)=>{if(i.length===0){t(e(`manyfold.bulkNothing`),`info`);return}let o=0,c=0,l=[],u=null;try{for(let e=0;er.getManyfoldModel(e)}),N=s({queryKey:[`settings`],queryFn:()=>r.getSettings()}),ee=N.data?.use_slicer_api??!1,re=ie(N.data?.open_in_slicer,N.data?.preferred_slicer),ae=c({mutationFn:t=>r.importManyfoldFile(e,t.id,y),onMutate:e=>D(e.id),onSettled:()=>D(null),onSuccess:t=>{f.invalidateQueries({queryKey:[`manyfold-model`,e]}),f.invalidateQueries({queryKey:[`library-files`]}),f.invalidateQueries({queryKey:[`library-folders`]}),d(t.was_existing?i(`manyfold.alreadyInLibrary`):i(`manyfold.imported`,{filename:t.filename}),`success`)},onError:e=>d(B(e,i),`error`)});if(M.isLoading)return(0,R.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,R.jsx)(v,{className:`w-8 h-8 text-bambu-green animate-spin`})});if(M.isError||!M.data)return(0,R.jsxs)(`div`,{className:`space-y-4`,children:[(0,R.jsxs)(w,{variant:`ghost`,size:`sm`,onClick:t,children:[(0,R.jsx)(u,{className:`w-4 h-4`}),i(`manyfold.back`)]}),(0,R.jsx)(`p`,{className:`text-red-400 text-sm`,children:B(M.error,i)})]});let F=M.data,I=F.files.filter(e=>e.importable&&!e.library_file),z=I.filter(e=>O.has(e.id)),H=I.length>0&&z.length===I.length,W=j.busy||ae.isPending,G=async e=>{await j.run(e.map(e=>({modelId:F.id,fileId:e.id,name:e.name})),y),A(new Set)};return(0,R.jsxs)(`div`,{className:`space-y-4`,children:[(0,R.jsxs)(w,{variant:`ghost`,size:`sm`,onClick:t,children:[(0,R.jsx)(u,{className:`w-4 h-4`}),i(`manyfold.back`)]}),(0,R.jsx)(C,{children:(0,R.jsx)(S,{children:(0,R.jsxs)(`div`,{className:`flex flex-col md:flex-row gap-6 py-2`,children:[(0,R.jsx)(U,{modelId:F.id,className:`w-full md:w-72 aspect-square rounded-lg shrink-0`}),(0,R.jsxs)(`div`,{className:`min-w-0 flex-1 space-y-3`,children:[(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`h2`,{className:`text-xl font-semibold text-white break-words`,children:F.name}),F.caption&&(0,R.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:F.caption})]}),F.description&&(0,R.jsx)(`p`,{className:`text-sm text-bambu-gray whitespace-pre-line break-words`,children:F.description}),F.tags.length>0&&(0,R.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:F.tags.map(e=>(0,R.jsx)(`span`,{className:`px-2 py-0.5 rounded-full bg-bambu-dark-tertiary text-xs text-white`,children:e},e))}),(0,R.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2 text-sm`,children:[F.license&&(0,R.jsxs)(`span`,{className:`text-bambu-gray`,children:[i(`manyfold.license`),`: `,(0,R.jsx)(`span`,{className:`text-white`,children:F.license})]}),(0,R.jsxs)(`a`,{href:F.url,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-1 text-bambu-green hover:underline`,children:[(0,R.jsx)(E,{className:`w-3.5 h-3.5`}),i(`manyfold.openInManyfold`)]})]})]})]})})}),(0,R.jsxs)(C,{children:[(0,R.jsxs)(x,{children:[(0,R.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,R.jsx)(`h3`,{className:`text-lg font-semibold text-white`,children:i(`manyfold.files`)}),_&&(0,R.jsx)(se,{value:y,onChange:b,disabled:W})]}),_&&I.length>0&&(0,R.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 mt-3`,children:[(0,R.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-white`,children:[(0,R.jsx)(`input`,{type:`checkbox`,checked:H,ref:e=>{e&&(e.indeterminate=z.length>0&&!H)},disabled:W,onChange:()=>A(H?new Set:new Set(I.map(e=>e.id))),className:`accent-bambu-green`}),i(`manyfold.selectAll`)]}),j.progress?(0,R.jsxs)(`span`,{className:`inline-flex items-center gap-2 text-sm text-bambu-gray`,children:[(0,R.jsx)(v,{className:`w-4 h-4 animate-spin`}),i(`manyfold.importProgress`,j.progress)]}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(w,{variant:`primary`,size:`sm`,disabled:W||z.length===0,onClick:()=>G(z),children:[(0,R.jsx)(te,{className:`w-3.5 h-3.5`}),i(`manyfold.importSelected`,{count:z.length})]}),(0,R.jsx)(w,{variant:`secondary`,size:`sm`,disabled:W,onClick:()=>G(I),children:i(`manyfold.importAll`)})]})]})]}),(0,R.jsx)(S,{children:F.files.length===0?(0,R.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`manyfold.noFiles`)}):(0,R.jsx)(`ul`,{className:`divide-y divide-bambu-dark-tertiary`,children:F.files.map(e=>{let t=e.library_file,r=t!==null&&oe({filename:t.filename},ee,re);return(0,R.jsxs)(`li`,{className:`flex flex-wrap items-center gap-3 py-2`,children:[_&&I.length>0&&(0,R.jsx)(`span`,{className:`w-4 shrink-0 flex`,children:e.importable&&!t&&(0,R.jsx)(`input`,{type:`checkbox`,"aria-label":i(`manyfold.selectFile`,{name:e.name}),checked:O.has(e.id),disabled:W,onChange:()=>A(t=>{let n=new Set(t);return n.has(e.id)?n.delete(e.id):n.add(e.id),n}),className:`accent-bambu-green`})}),(0,R.jsx)(`span`,{className:`px-1.5 py-0.5 rounded bg-bambu-dark-tertiary text-[11px] font-mono text-bambu-gray shrink-0`,children:V(e.mime)}),(0,R.jsx)(`span`,{className:`text-sm text-white min-w-0 flex-1 break-words`,children:e.name}),(0,R.jsx)(`div`,{className:`flex flex-wrap items-center gap-2`,children:e.importable?t?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-xs text-bambu-green`,children:[(0,R.jsx)(p,{className:`w-3.5 h-3.5`}),i(`manyfold.inLibrary`)]}),(0,R.jsxs)(w,{variant:`ghost`,size:`sm`,onClick:()=>m(t.folder_id?`/files?folder=${t.folder_id}`:`/files`),children:[(0,R.jsx)(P,{className:`w-3.5 h-3.5`}),i(`manyfold.showInLibrary`)]}),r&&(0,R.jsxs)(w,{variant:`ghost`,size:`sm`,onClick:()=>n(t.id,t.filename),children:[(0,R.jsx)(g,{className:`w-3.5 h-3.5`}),i(`slice.action`,`Slice`)]})]}):_?(0,R.jsxs)(w,{variant:`secondary`,size:`sm`,disabled:W,onClick:()=>ae.mutate(e),children:[T===e.id?(0,R.jsx)(v,{className:`w-3.5 h-3.5 animate-spin`}):(0,R.jsx)(te,{className:`w-3.5 h-3.5`}),T===e.id?i(`manyfold.importing`):i(`manyfold.import`)]}):null:(0,R.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:i(`manyfold.notImportable`)})})]},e.id)})})})]})]})}function le(){let{t:e}=a(),{hasPermission:t}=ne(),n=t(`settings:update`),[i,c]=(0,L.useState)(!1),[l,u]=(0,L.useState)(``),[d,f]=(0,L.useState)(``),[p,m]=(0,L.useState)(1),[g,b]=(0,L.useState)(null),[x,T]=(0,L.useState)(null),[E,O]=(0,L.useState)(new Map),[k,j]=(0,L.useState)(null),[M,N]=(0,L.useState)(null),P=t(`manyfold:import`),ae=o(),{showToast:oe}=h(),F=K(),I=M!==null||F.busy,z=M?e(`manyfold.collectProgress`,M):F.progress?e(`manyfold.importProgress`,F.progress):null,V=(e,t)=>O(n=>{let r=new Map(n);return r.has(e)?r.delete(e):r.set(e,t),r}),H=async()=>{let t=[...E.keys()],n=[],i=[];try{for(let e=0;er.getManyfoldModel(t[e])});for(let e of i.files)e.importable&&!e.library_file&&n.push({modelId:i.id,fileId:e.id,name:`${i.name}: ${e.name}`})}catch{i.push(E.get(t[e])??t[e])}}}finally{N(null)}i.length&&oe(e(`manyfold.modelsUnreadable`,{names:G(i)}),`error`),await F.run(n,k),O(new Map)},le=s({queryKey:[`settings`],queryFn:()=>r.getSettings()}),q=s({queryKey:[`manyfold-status`],queryFn:()=>r.getManyfoldStatus()}),ue=q.data?.configured??!1,J=s({queryKey:[`manyfold-models`,d,p],queryFn:()=>r.listManyfoldModels(d,p),enabled:ue,placeholderData:e=>e}),Y=async(e,t)=>{if(le.data?.use_slicer_api){T({kind:`libraryFile`,id:e,filename:t});return}let n=ie(le.data?.open_in_slicer,le.data?.preferred_slicer);try{let{token:i}=await r.createLibrarySlicerToken(e);re(`${window.location.origin}${r.getLibrarySlicerDownloadUrl(e,i,t)}`,n)}catch{re(`${window.location.origin}${r.getLibraryFileDownloadUrl(e)}`,n)}};if(q.isLoading)return(0,R.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,R.jsx)(v,{className:`w-8 h-8 text-bambu-green animate-spin`})});if(!ue||i)return(0,R.jsxs)(`div`,{className:`space-y-6`,children:[(0,R.jsx)(`p`,{className:`text-bambu-gray`,children:e(`manyfold.description`)}),n?(0,R.jsx)(W,{onDone:ue?()=>c(!1):void 0}):(0,R.jsx)(C,{children:(0,R.jsx)(S,{children:(0,R.jsxs)(`div`,{className:`py-2`,children:[(0,R.jsx)(`p`,{className:`font-medium text-white`,children:e(`manyfold.notConnectedTitle`)}),(0,R.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:e(`manyfold.notConnectedBody`)})]})})})]});let X=J.data;return(0,R.jsxs)(`div`,{className:`space-y-6`,children:[g?(0,R.jsx)(ce,{modelId:g,onBack:()=>b(null),onSlice:Y}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,R.jsx)(`p`,{className:`text-bambu-gray flex-1 min-w-[16rem]`,children:e(`manyfold.description`)}),n&&(0,R.jsxs)(w,{variant:`ghost`,size:`sm`,onClick:()=>c(!0),children:[(0,R.jsx)(A,{className:`w-4 h-4`}),e(`manyfold.editConnection`)]})]}),(0,R.jsxs)(`form`,{className:`flex gap-2`,role:`search`,onSubmit:e=>{e.preventDefault(),f(l.trim()),m(1)},children:[(0,R.jsxs)(`div`,{className:`relative flex-1`,children:[(0,R.jsx)(y,{className:`w-4 h-4 text-bambu-gray absolute left-3 top-1/2 -translate-y-1/2`}),(0,R.jsx)(`input`,{type:`search`,value:l,onChange:e=>u(e.target.value),placeholder:e(`manyfold.searchPlaceholder`),"aria-label":e(`manyfold.searchPlaceholder`),className:`w-full pl-9 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`})]}),(0,R.jsx)(w,{type:`submit`,children:e(`common.search`)})]}),J.isError?(0,R.jsx)(`p`,{className:`text-sm text-red-400`,children:B(J.error,e)}):X?X.models.length===0?(0,R.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`manyfold.noModels`)}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,R.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`manyfold.modelCount`,{count:X.total})}),P&&(0,R.jsx)(w,{variant:`ghost`,size:`sm`,disabled:I,onClick:()=>O(e=>{let t=new Map(e);for(let e of X.models)t.set(e.id,e.name);return t}),children:e(`manyfold.selectPage`)})]}),P&&E.size>0&&(0,R.jsxs)(`div`,{className:`sticky top-0 z-10 flex flex-wrap items-center gap-3 rounded-lg border border-bambu-green/40 bg-bambu-dark-secondary px-4 py-3`,children:[(0,R.jsx)(`span`,{className:`text-sm text-white`,children:e(`manyfold.modelsSelected`,{count:E.size})}),(0,R.jsx)(se,{value:k,onChange:j,disabled:I}),z?(0,R.jsxs)(`span`,{className:`inline-flex items-center gap-2 text-sm text-bambu-gray`,children:[(0,R.jsx)(v,{className:`w-4 h-4 animate-spin`}),z]}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(w,{variant:`primary`,size:`sm`,onClick:H,children:[(0,R.jsx)(te,{className:`w-3.5 h-3.5`}),e(`manyfold.importModels`)]}),(0,R.jsx)(w,{variant:`ghost`,size:`sm`,onClick:()=>O(new Map),children:e(`manyfold.clearSelection`)})]})]}),(0,R.jsx)(`div`,{className:`grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-4 xl:grid-cols-6 gap-4`,children:X.models.map(t=>{let n=E.has(t.id);return(0,R.jsxs)(`div`,{className:`relative rounded-lg border bg-bambu-dark-secondary overflow-hidden transition-colors ${n?`border-bambu-green ring-1 ring-bambu-green`:`border-bambu-dark-tertiary hover:border-bambu-green`}`,children:[(0,R.jsxs)(`button`,{type:`button`,onClick:()=>b(t.id),disabled:I,className:`block w-full text-left disabled:cursor-wait`,children:[(0,R.jsx)(U,{modelId:t.id,className:`aspect-square`}),(0,R.jsx)(`span`,{className:`block px-3 py-2 text-sm text-white truncate`,title:t.name,children:t.name})]}),P&&(0,R.jsx)(`label`,{className:`absolute top-2 left-2 flex items-center justify-center w-7 h-7 rounded bg-black/60 cursor-pointer`,children:(0,R.jsx)(`input`,{type:`checkbox`,"aria-label":e(`manyfold.selectModel`,{name:t.name}),checked:n,disabled:I,onChange:()=>V(t.id,t.name),className:`accent-bambu-green w-4 h-4`})})]},t.id)})}),(X.has_previous||X.has_next)&&(0,R.jsxs)(`div`,{className:`flex items-center justify-center gap-3`,children:[(0,R.jsxs)(w,{variant:`secondary`,size:`sm`,disabled:!X.has_previous||J.isFetching,onClick:()=>m(e=>Math.max(1,e-1)),children:[(0,R.jsx)(ee,{className:`w-4 h-4`}),e(`manyfold.previous`)]}),(0,R.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e(`manyfold.page`,{page:X.page})}),(0,R.jsxs)(w,{variant:`secondary`,size:`sm`,disabled:!X.has_next||J.isFetching,onClick:()=>m(e=>e+1),children:[e(`manyfold.next`),(0,R.jsx)(D,{className:`w-4 h-4`})]})]})]}):(0,R.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,R.jsx)(v,{className:`w-8 h-8 text-bambu-green animate-spin`})})]}),x&&(0,R.jsx)(_,{source:x,onClose:()=>T(null)})]})}function q(e,t){let n=e?.[t];return typeof n==`string`?n:``}function ue(e){return e.replace(/(https?:\/\/(?:makerworld|public-cdn)\.bblmw\.com\/[^\s"']+)/gi,e=>`/api/v1/makerworld/thumbnail?url=${encodeURIComponent(e)}`)}function J(e){return e?/^https?:\/\/(makerworld|public-cdn)\.bblmw\.com\//i.test(e)?`/api/v1/makerworld/thumbnail?url=${encodeURIComponent(e)}`:e:``}function Y(e,t){let n=e?.[t];return typeof n==`number`?n:null}function X(e,t){let n=e?.[t];return n&&typeof n==`object`&&!Array.isArray(n)?n:void 0}function de(e,t=0,n=[]){n.push({folder:e,depth:t});for(let r of e.children??[])de(r,t+1,n);return n}function fe(e,t){return t(e<1?`makerworld.phaseResolving`:`makerworld.phaseDownloading`)}function pe(e){let[t,n]=(0,L.useState)(0);return(0,L.useEffect)(()=>{if(!e){n(0);return}let t=Date.now(),r=()=>n(Math.floor((Date.now()-t)/1e3));r();let i=window.setInterval(r,1e3);return()=>window.clearInterval(i)},[e]),t}function me({embedded:e=!1}={}){let{t}=a(),{hasPermission:n}=ne(),{showToast:i}=h(),l=o(),u=n(`makerworld:import`),[f,y]=(0,L.useState)(``),[k,A]=(0,L.useState)(null),[j,oe]=(0,L.useState)(null),[I,z]=(0,L.useState)(null),[B,V]=(0,L.useState)(null),[H,U]=(0,L.useState)(null),[W,se]=(0,L.useState)(``),[G,K]=(0,L.useState)({}),ce=s({queryKey:[`makerworld-status`],queryFn:()=>r.getMakerworldStatus()}),le=s({queryKey:[`library-folders`],queryFn:()=>r.getLibraryFolders()}),me=s({queryKey:[`makerworld-recent-imports`],queryFn:()=>r.getMakerworldRecentImports(10)}),he=s({queryKey:[`settings`],queryFn:()=>r.getSettings()}),ge=he.data?.use_slicer_api??!1,_e=he.data?.preferred_slicer||`bambu_studio`,ve=ie(he.data?.open_in_slicer,he.data?.preferred_slicer),ye=ge?_e:ve,be=ye===`orcaslicer`?`OrcaSlicer`:`Bambu Studio`,[xe,Se]=(0,L.useState)(null),Ce=(e,t)=>{Se({kind:`libraryFile`,id:e,filename:t})},we=c({mutationFn:e=>r.resolveMakerworldUrl(e),onSuccess:(e,t)=>{A(e),se(t),K({})},onError:e=>i(e.message||t(`makerworld.errors.resolveFailed`),`error`)});(0,L.useEffect)(()=>{k!==null&&f.trim()!==W.trim()&&(A(null),se(``),K({}))},[f,k,W]);let Z=c({mutationFn:({instanceId:e,profileId:t})=>r.importMakerworldInstance(k?.model_id??0,e,t,j),onSuccess:e=>{l.invalidateQueries({queryKey:[`library-files`]}),l.invalidateQueries({queryKey:[`library-folders`]}),e.profile_id&&K(t=>({...t,[e.profile_id]:e})),i(e.was_existing?t(`makerworld.alreadyInLibrary`):t(`makerworld.importSuccess`,{filename:e.filename}),`success`)},onError:e=>i(e.message||t(`makerworld.errors.downloadFailed`),`error`)}),Te=c({mutationFn:({libraryFileId:e})=>r.deleteLibraryFile(e),onSuccess:(e,{profileId:n})=>{l.invalidateQueries({queryKey:[`library-files`]}),l.invalidateQueries({queryKey:[`library-folders`]}),l.invalidateQueries({queryKey:[`makerworld-recent-imports`]}),K(e=>{let t={...e};return delete t[n],t}),V(null),i(t(`makerworld.importDeleted`),`success`)},onError:e=>{V(null),i(e.message||t(`makerworld.errors.deleteFailed`),`error`)}}),Ee=c({mutationFn:({instanceId:e,profileId:t})=>r.importMakerworldInstance(k?.model_id??0,e,t,j),onSuccess:async e=>{l.invalidateQueries({queryKey:[`library-files`]}),l.invalidateQueries({queryKey:[`library-folders`]}),l.invalidateQueries({queryKey:[`makerworld-recent-imports`]}),e.profile_id&&K(t=>({...t,[e.profile_id]:e})),ge?Ce(e.library_file_id,e.filename):await je(e.library_file_id,e.filename,ye)},onError:e=>i(e.message||t(`makerworld.errors.downloadFailed`),`error`)}),Q=pe(Z.isPending||Ee.isPending),De=fe(Q,t),Oe=e=>{e?.preventDefault();let t=f.trim();t&&we.mutate(t)};(0,L.useEffect)(()=>{if(!H)return;let e=e=>{e.key===`Escape`?U(null):e.key===`ArrowLeft`?U(e=>e&&e.index>0?{...e,index:e.index-1}:e):e.key===`ArrowRight`&&U(e=>e&&e.indexwindow.removeEventListener(`keydown`,e)},[H]);let ke=e=>{let t=(Array.isArray(e.pictures)?e.pictures:[]).filter(e=>typeof e==`object`&&!!e).map(e=>({name:q(e,`name`)||`image`,url:q(e,`url`)})).filter(e=>e.url);if(t.length>0)return t;let n=q(e,`cover`);return n?[{name:`cover`,url:n}]:[]},Ae=async()=>{if(!k)return;let e=k.instances.filter(e=>{let t=Y(e,`profileId`);return t!==null&&!G[t]});if(e.length!==0){z({current:0,total:e.length});try{for(let t=0;t{try{let{token:i}=await r.createLibrarySlicerToken(e),a=r.getLibrarySlicerDownloadUrl(e,i,t);re(`${window.location.origin}${a}`,n)}catch{let t=r.getLibraryFileDownloadUrl(e);re(`${window.location.origin}${t}`,n)}},$=k?.design,Me=X($,`designCreator`),Ne=k?.instances??[],Pe=(k?.already_imported_library_ids.length??0)>0,Fe=ce.data?.can_download??!1,Ie=ce.data?.sign_in_expired??!1,Le=(0,L.useMemo)(()=>q($,`coverUrl`),[$]),Re=q($,`title`),ze=q($,`summary`),Be=q($,`license`),Ve=Y($,`downloadCount`);return(0,R.jsxs)(`div`,{className:e?`space-y-6`:`p-4 md:p-8 max-w-screen-2xl space-y-6`,children:[e?(0,R.jsx)(`p`,{className:`text-bambu-gray`,children:t(`makerworld.description`)}):(0,R.jsxs)(`div`,{children:[(0,R.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,R.jsx)(N,{className:`w-7 h-7 text-bambu-green`}),t(`makerworld.title`)]}),(0,R.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:t(`makerworld.description`)})]}),(0,R.jsxs)(`div`,{className:`grid gap-6 lg:grid-cols-[1fr_20rem]`,children:[(0,R.jsxs)(`div`,{className:`space-y-6 min-w-0`,children:[!Fe&&(0,R.jsx)(C,{className:`border-amber-300 dark:border-amber-700 bg-amber-50 dark:bg-amber-900/20`,children:(0,R.jsx)(S,{children:(0,R.jsxs)(`div`,{className:`flex items-start gap-3 py-2`,children:[(0,R.jsx)(m,{className:`w-5 h-5 text-amber-600 dark:text-amber-400 mt-0.5 shrink-0`}),(0,R.jsxs)(`div`,{className:`text-sm`,children:[(0,R.jsx)(`p`,{className:`font-medium text-amber-900 dark:text-amber-100`,children:t(Ie?`makerworld.signInExpiredTitle`:`makerworld.signInRequiredTitle`)}),(0,R.jsxs)(`p`,{className:`text-amber-800 dark:text-amber-200 mt-1`,children:[t(Ie?`makerworld.signInExpiredBody`:`makerworld.signInRequiredBody`),` `,(0,R.jsx)(O,{to:`/profiles`,className:`underline`,children:t(`makerworld.openCloudSettings`)})]})]})]})})}),(0,R.jsxs)(C,{children:[(0,R.jsx)(x,{children:(0,R.jsx)(`h2`,{className:`text-lg font-semibold`,children:t(`makerworld.pasteUrlHeader`)})}),(0,R.jsx)(S,{children:(0,R.jsxs)(`form`,{onSubmit:Oe,className:`flex gap-2`,children:[(0,R.jsx)(`input`,{type:`text`,value:f,onChange:e=>y(e.target.value),placeholder:t(`makerworld.pasteUrlPlaceholder`),className:`flex-1 min-w-0 px-3 py-2 border rounded bg-white dark:bg-gray-800 border-gray-300 dark:border-gray-700`,autoComplete:`off`}),(0,R.jsxs)(w,{type:`submit`,variant:`primary`,disabled:!f.trim()||we.isPending,children:[we.isPending?(0,R.jsx)(v,{className:`w-4 h-4 animate-spin`}):(0,R.jsx)(d,{className:`w-4 h-4`}),(0,R.jsx)(`span`,{className:`ml-2`,children:t(`makerworld.resolveButton`)})]})]})})]}),k&&(0,R.jsx)(C,{children:(0,R.jsx)(S,{children:(0,R.jsxs)(`div`,{className:`flex gap-4 py-2`,children:[Le&&(0,R.jsx)(`img`,{src:J(Le),alt:Re,className:`w-32 h-32 object-cover rounded`,loading:`lazy`}),(0,R.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,R.jsx)(`h3`,{className:`text-xl font-semibold truncate`,children:Re||t(`makerworld.untitledModel`)}),Me&&(0,R.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400 mt-1`,children:t(`makerworld.byCreator`,{name:q(Me,`name`)})}),(0,R.jsxs)(`div`,{className:`flex flex-wrap gap-3 mt-2 text-xs text-gray-500 dark:text-gray-400`,children:[Ve!==null&&(0,R.jsx)(`span`,{children:t(`makerworld.downloadsCount`,{count:Ve})}),Be&&(0,R.jsxs)(`span`,{children:[t(`makerworld.licensePrefix`),`: `,Be]}),Pe&&(0,R.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-emerald-600 dark:text-emerald-400`,children:[(0,R.jsx)(p,{className:`w-3 h-3`}),` `,t(`makerworld.alreadyImported`)]})]}),ze&&(0,R.jsx)(`div`,{className:`mt-3 text-sm prose prose-sm max-w-none dark:prose-invert line-clamp-3`,dangerouslySetInnerHTML:{__html:ae.sanitize(ue(ze))}}),k&&(0,R.jsxs)(`a`,{href:`https://makerworld.com/models/${k.model_id}${k.profile_id?`#profileId-${k.profile_id}`:``}`,target:`_blank`,rel:`noopener noreferrer`,className:`mt-3 inline-flex items-center gap-1 text-xs text-brand-500 hover:underline`,children:[(0,R.jsx)(E,{className:`w-3 h-3`}),` `,t(`makerworld.openOnMakerworld`)]})]})]})})}),k&&Ne.length>0&&(0,R.jsxs)(C,{children:[(0,R.jsx)(x,{children:(0,R.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,R.jsx)(`h2`,{className:`text-lg font-semibold`,children:t(`makerworld.platesHeader`,{count:Ne.length})}),(0,R.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,R.jsx)(`label`,{className:`text-xs text-gray-600 dark:text-gray-400`,children:t(`makerworld.importTo`)}),(0,R.jsxs)(`select`,{value:j??``,onChange:e=>oe(e.target.value?Number(e.target.value):null),className:`text-sm px-2 py-1 border rounded bg-white dark:bg-gray-800 border-gray-300 dark:border-gray-700`,disabled:I!==null,children:[(0,R.jsx)(`option`,{value:``,children:t(`makerworld.folderAuto`)}),(le.data??[]).filter(e=>!(e.is_external&&e.external_readonly)).flatMap(e=>de(e)).map(({folder:e,depth:t})=>(0,R.jsx)(`option`,{value:e.id,disabled:e.can_write===!1,children:`${`— `.repeat(t)}${e.name}`},e.id))]}),(0,R.jsx)(w,{variant:`primary`,size:`sm`,disabled:!u||!Fe||I!==null||Z.isPending||Ee.isPending,onClick:Ae,children:I===null?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(te,{className:`w-4 h-4`}),(0,R.jsx)(`span`,{className:`ml-2`,children:t(`makerworld.importAll`)})]}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(v,{className:`w-4 h-4 animate-spin`}),(0,R.jsxs)(`span`,{className:`ml-2`,children:[t(`makerworld.importAllProgress`,{current:I.current,total:I.total}),Q>0&&` · ${De} · ${Q}s`]})]})})]})]})}),(0,R.jsx)(S,{children:(0,R.jsx)(`div`,{className:`grid gap-3`,children:Ne.map((e,n)=>{let r=Y(e,`id`),i=Y(e,`profileId`),a=q(e,`title`),o=q(e,`cover`),s=Y(e,`materialCnt`),c=e?.needAms===!0,l=Y(e,`downloadCount`),d=e?.compatibility??null,f=e?.otherCompatibility??null,m=d?.devProductName??null,h=Array.isArray(f)?f.map(e=>e?.devProductName??``).filter(Boolean):[];if(r==null)return null;let _=Z.isPending&&Z.variables?.instanceId===r,y=Ee.isPending&&Ee.variables?.instanceId===r,b=i===null?void 0:G[i];return(0,R.jsxs)(`div`,{className:`flex flex-col gap-2 p-3 border rounded border-gray-200 dark:border-gray-700`,children:[(0,R.jsxs)(`div`,{className:`flex gap-3 items-center`,children:[(()=>{let n=ke(e),r=n.length>0;return(0,R.jsxs)(`button`,{type:`button`,disabled:!r,onClick:()=>r&&U({images:n,index:0}),className:`relative w-16 h-16 shrink-0 rounded overflow-hidden group`,"aria-label":t(`makerworld.openGallery`),children:[o?(0,R.jsx)(`img`,{src:J(o),alt:``,className:`w-16 h-16 object-cover`,loading:`lazy`}):(0,R.jsx)(`div`,{className:`w-16 h-16 bg-gray-100 dark:bg-gray-800`}),n.length>1&&(0,R.jsxs)(`span`,{className:`absolute bottom-0.5 right-0.5 bg-black/70 text-white text-[10px] px-1.5 py-0.5 rounded flex items-center gap-1`,children:[(0,R.jsx)(F,{className:`w-2.5 h-2.5`}),n.length]})]})})(),(0,R.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,R.jsx)(`p`,{className:`font-medium truncate`,children:a||t(`makerworld.plateDefaultName`,{n:n+1})}),(0,R.jsxs)(`div`,{className:`flex flex-wrap gap-3 text-xs text-gray-500 dark:text-gray-400 mt-1`,children:[m&&(0,R.jsx)(`span`,{className:`font-medium text-gray-700 dark:text-gray-300`,children:t(`makerworld.slicedFor`,{printer:m,defaultValue:`Sliced for {{printer}}`})}),s!==null&&(0,R.jsx)(`span`,{children:t(`makerworld.materialCount`,{count:s})}),c&&(0,R.jsx)(`span`,{children:t(`makerworld.amsRequired`)}),l!==null&&(0,R.jsx)(`span`,{children:t(`makerworld.downloadsCount`,{count:l})})]}),h.length>0&&(0,R.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mt-1`,title:h.join(`, `),children:t(`makerworld.alsoCompatible`,{printers:h.slice(0,6).join(`, `)+(h.length>6?`…`:``),defaultValue:`Also marked compatible: {{printers}}`})})]}),(0,R.jsxs)(`div`,{className:`flex gap-2 shrink-0`,children:[(0,R.jsx)(w,{variant:`ghost`,size:`sm`,disabled:!u||!Fe||_||y||I!==null,onClick:()=>Z.mutate({instanceId:r,profileId:i}),title:Fe?void 0:t(`makerworld.signInRequiredTitle`),children:_?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(v,{className:`w-4 h-4 animate-spin`}),(0,R.jsxs)(`span`,{className:`ml-2`,children:[De,Q>0&&` · ${Q}s`]})]}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(te,{className:`w-4 h-4`}),(0,R.jsx)(`span`,{className:`ml-2`,children:t(`makerworld.importToLibrary`)})]})}),(0,R.jsx)(w,{variant:`primary`,size:`sm`,disabled:!u||!Fe||_||y||I!==null,onClick:()=>Ee.mutate({instanceId:r,profileId:i}),title:Fe?void 0:t(`makerworld.signInRequiredTitle`),children:y?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(v,{className:`w-4 h-4 animate-spin`}),(0,R.jsxs)(`span`,{className:`ml-2`,children:[De,Q>0&&` · ${Q}s`]})]}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(E,{className:`w-4 h-4`}),(0,R.jsx)(`span`,{className:`ml-2`,children:t(`makerworld.sliceIn`,{slicer:be})})]})})]})]}),b&&(0,R.jsxs)(`div`,{className:`flex items-center gap-2 pl-20 text-xs`,children:[(0,R.jsx)(p,{className:`w-3.5 h-3.5 text-emerald-600 dark:text-emerald-400 shrink-0`}),(0,R.jsx)(`span`,{className:`text-emerald-700 dark:text-emerald-300`,children:b.was_existing?t(`makerworld.lastImportAlreadyInLibrary`):t(`makerworld.lastImportSuccess`)}),(0,R.jsxs)(w,{variant:`ghost`,size:`sm`,onClick:()=>{let e=b.folder_id?`/files?folder=${b.folder_id}`:`/files`;window.location.assign(e)},children:[(0,R.jsx)(P,{className:`w-3.5 h-3.5`}),(0,R.jsx)(`span`,{className:`ml-1.5`,children:t(`makerworld.viewInLibrary`)})]}),ge?(0,R.jsxs)(w,{variant:`ghost`,size:`sm`,onClick:()=>Ce(b.library_file_id,b.filename),children:[(0,R.jsx)(g,{className:`w-3.5 h-3.5`}),(0,R.jsx)(`span`,{className:`ml-1.5`,children:t(`slice.action`,`Slice`)})]}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(w,{variant:`ghost`,size:`sm`,onClick:()=>je(b.library_file_id,b.filename,`bambu_studio`),children:[(0,R.jsx)(E,{className:`w-3.5 h-3.5`}),(0,R.jsx)(`span`,{className:`ml-1.5`,children:t(`makerworld.openInBambuStudio`)})]}),(0,R.jsxs)(w,{variant:`ghost`,size:`sm`,onClick:()=>je(b.library_file_id,b.filename,`orcaslicer`),children:[(0,R.jsx)(E,{className:`w-3.5 h-3.5`}),(0,R.jsx)(`span`,{className:`ml-1.5`,children:t(`makerworld.openInOrcaSlicer`)})]})]}),(0,R.jsx)(`div`,{className:`ml-auto`,children:(0,R.jsx)(w,{variant:`ghost`,size:`sm`,disabled:Te.isPending&&Te.variables?.profileId===i,onClick:()=>{i!==null&&V({libraryFileId:b.library_file_id,profileId:i,filename:b.filename})},title:t(`makerworld.deleteImport`),children:Te.isPending&&Te.variables?.profileId===i?(0,R.jsx)(v,{className:`w-3.5 h-3.5 animate-spin`}):(0,R.jsx)(T,{className:`w-3.5 h-3.5 text-red-500`})})})]})]},r)})})})]})]}),(0,R.jsx)(`aside`,{className:`lg:sticky lg:top-6 lg:self-start min-w-0`,children:me.data&&me.data.length>0&&(0,R.jsxs)(C,{children:[(0,R.jsx)(x,{children:(0,R.jsx)(`h2`,{className:`text-base font-semibold`,children:t(`makerworld.recentImportsHeader`)})}),(0,R.jsx)(S,{children:(0,R.jsx)(`div`,{className:`flex flex-col gap-2 max-h-[28rem] overflow-y-auto -mx-2 px-2`,children:me.data.map(e=>(0,R.jsxs)(`div`,{className:`flex gap-2 p-2 border rounded border-gray-200 dark:border-gray-700`,children:[e.thumbnail_path?(0,R.jsx)(`img`,{src:r.getLibraryFileThumbnailUrl(e.library_file_id),alt:``,className:`w-12 h-12 shrink-0 object-cover rounded bg-gray-100 dark:bg-gray-800`,loading:`lazy`}):(0,R.jsx)(`div`,{className:`w-12 h-12 shrink-0 rounded bg-gray-100 dark:bg-gray-800`}),(0,R.jsxs)(`div`,{className:`flex-1 min-w-0 flex flex-col gap-1`,children:[(0,R.jsx)(`p`,{className:`text-xs font-medium truncate`,title:e.filename,children:e.filename}),(0,R.jsxs)(`div`,{className:`flex gap-0.5`,children:[(0,R.jsx)(w,{variant:`ghost`,size:`sm`,onClick:()=>{let t=e.folder_id?`/files?folder=${e.folder_id}`:`/files`;window.location.assign(t)},title:t(`makerworld.viewInLibrary`),children:(0,R.jsx)(P,{className:`w-3.5 h-3.5`})}),ge?(0,R.jsx)(w,{variant:`ghost`,size:`sm`,onClick:()=>Ce(e.library_file_id,e.filename),title:t(`slice.action`,`Slice`),children:(0,R.jsx)(g,{className:`w-3.5 h-3.5`})}):(0,R.jsx)(w,{variant:`ghost`,size:`sm`,onClick:()=>je(e.library_file_id,e.filename,`bambu_studio`),title:t(`makerworld.openInBambuStudio`),children:(0,R.jsx)(E,{className:`w-3.5 h-3.5`})}),e.source_url&&(0,R.jsx)(`a`,{href:e.source_url,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center justify-center h-7 w-7 rounded text-gray-500 hover:text-gray-700 dark:hover:text-gray-300`,title:t(`makerworld.openOnMakerworld`),children:(0,R.jsx)(N,{className:`w-3.5 h-3.5`})})]})]})]},e.library_file_id))})})]})})]}),(0,R.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 pt-4 border-t border-gray-200 dark:border-gray-700`,children:t(`makerworld.disclaimer`)}),B&&(0,R.jsx)(M,{title:t(`makerworld.deleteImport`),message:t(`makerworld.confirmDelete`,{filename:B.filename}),confirmText:t(`makerworld.deleteImport`),variant:`danger`,isLoading:Te.isPending,loadingText:t(`makerworld.importDeleting`),onCancel:()=>V(null),onConfirm:()=>Te.mutate({libraryFileId:B.libraryFileId,profileId:B.profileId})}),xe&&(0,R.jsx)(_,{source:xe,onClose:()=>Se(null)}),H&&(0,R.jsxs)(`div`,{className:`fixed inset-0 bg-black/90 flex items-center justify-center z-50`,onClick:()=>U(null),role:`dialog`,"aria-modal":`true`,children:[(0,R.jsx)(`button`,{type:`button`,className:`absolute top-4 right-4 p-2 bg-white/10 hover:bg-white/20 rounded-full text-white`,onClick:e=>{e.stopPropagation(),U(null)},"aria-label":t(`common.close`,`Close`),children:(0,R.jsx)(b,{className:`w-5 h-5`})}),H.images.length>1&&(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`button`,{type:`button`,className:`absolute left-4 p-2 bg-white/10 hover:bg-white/20 rounded-full text-white disabled:opacity-30`,disabled:H.index===0,onClick:e=>{e.stopPropagation(),U(e=>e&&{...e,index:Math.max(0,e.index-1)})},"aria-label":t(`makerworld.galleryPrev`),children:(0,R.jsx)(ee,{className:`w-6 h-6`})}),(0,R.jsx)(`button`,{type:`button`,className:`absolute right-4 p-2 bg-white/10 hover:bg-white/20 rounded-full text-white disabled:opacity-30`,disabled:H.index>=H.images.length-1,onClick:e=>{e.stopPropagation(),U(e=>e&&{...e,index:Math.min(e.images.length-1,e.index+1)})},"aria-label":t(`makerworld.galleryNext`),children:(0,R.jsx)(D,{className:`w-6 h-6`})})]}),(0,R.jsx)(`img`,{src:J(H.images[H.index].url),alt:H.images[H.index].name,className:`max-w-[90vw] max-h-[90vh] object-contain`,onClick:e=>e.stopPropagation()}),H.images.length>1&&(0,R.jsxs)(`div`,{className:`absolute bottom-6 left-1/2 -translate-x-1/2 text-white bg-black/60 px-3 py-1 rounded text-xs`,children:[H.index+1,` / `,H.images.length]})]})]})}function he(){let{t:e}=a(),{hasPermission:t}=ne(),[n,i]=j(),o=t(`manyfold:view`),c=s({queryKey:[`manyfold-status`],queryFn:()=>r.getManyfoldStatus(),enabled:o}),l=o&&(c.data?.configured===!0||t(`settings:update`)),u=[];t(`makerworld:view`)&&u.push({id:`makerworld`,label:e(`modelSources.tabMakerworld`),icon:N}),l&&u.push({id:`manyfold`,label:e(`modelSources.tabManyfold`),icon:I});let d=n.get(`tab`),f=u.find(e=>e.id===d)?.id??u[0]?.id??(o?`manyfold`:void 0);return(0,R.jsxs)(`div`,{className:`p-4 md:p-8 max-w-screen-2xl`,children:[(0,R.jsx)(`div`,{className:`mb-6`,children:(0,R.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,R.jsx)(N,{className:`w-7 h-7 text-bambu-green`}),e(`modelSources.title`)]})}),u.length>1&&(0,R.jsx)(`div`,{className:`flex border-b border-bambu-dark-tertiary mb-6`,role:`tablist`,children:u.map(({id:e,label:t,icon:n})=>(0,R.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":f===e,onClick:()=>i({tab:e},{replace:!0}),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${f===e?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-white border-transparent`}`,children:[(0,R.jsx)(n,{className:`w-4 h-4`}),t]},e))}),f===`makerworld`&&(0,R.jsx)(me,{embedded:!0}),f===`manyfold`&&(0,R.jsx)(le,{})]})}export{he as ModelSourcesPage}; \ No newline at end of file diff --git a/static/assets/NotificationsPage-B3GOs-as.js b/static/assets/NotificationsPage-DTBdRJe1.js similarity index 99% rename from static/assets/NotificationsPage-B3GOs-as.js rename to static/assets/NotificationsPage-DTBdRJe1.js index aaaeb4bad..f588277aa 100644 --- a/static/assets/NotificationsPage-B3GOs-as.js +++ b/static/assets/NotificationsPage-DTBdRJe1.js @@ -1 +1 @@ -import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,w as i}from"./client-DnySrlFv.js";import{n as a}from"./QueryClientProvider-Ce8_sN3w.js";import{t as o}from"./useQuery-BBCjCezC.js";import{t as s}from"./useMutation-B-Tr2hIP.js";import{n as c}from"./ToastContext-BRX0SW3C.js";import{t as l}from"./loader-circle-BEmFtawu.js";import{i as u,n as d,t as f}from"./Card-Bzc64K35.js";import{t as p}from"./Button-DDr6eAFy.js";import{An as m,In as h,Ut as g,Vn as _,in as v,yt as y}from"./index-0t--Yqoi.js";var b=e(n(),1),x=t();function S(){let{t:e}=i(),{user:t}=y(),{showToast:n}=c(),S=a(),C=_(),[w,T]=(0,b.useState)(!0),[E,D]=(0,b.useState)(!0),[O,k]=(0,b.useState)(!0),[A,j]=(0,b.useState)(!0),[M,N]=(0,b.useState)(!1),{data:P,isLoading:F}=o({queryKey:[`advancedAuthStatus`],queryFn:r.getAdvancedAuthStatus,staleTime:300*1e3}),{data:I,isLoading:L}=o({queryKey:[`settings`],queryFn:r.getSettings,staleTime:300*1e3}),{data:R,isLoading:z}=o({queryKey:[`user-email-preferences`],queryFn:()=>r.getUserEmailPreferences()});(0,b.useEffect)(()=>{(P&&!P.advanced_auth_enabled||I&&!I.user_notifications_enabled)&&C(`/settings`,{replace:!0})},[P,I,C]),(0,b.useEffect)(()=>{R&&(T(R.notify_print_start),D(R.notify_print_complete),k(R.notify_print_failed),j(R.notify_print_stopped),N(!1))},[R]);let B=s({mutationFn:()=>r.updateUserEmailPreferences({notify_print_start:w,notify_print_complete:E,notify_print_failed:O,notify_print_stopped:A}),onSuccess:()=>{S.invalidateQueries({queryKey:[`user-email-preferences`]}),N(!1),n(e(`notifications.userEmail.saveSuccess`),`success`)},onError:t=>{n(t.message||e(`notifications.userEmail.saveError`),`error`)}}),V=(e,t)=>{e(!t),N(!0)};return z||F||L?(0,x.jsx)(`div`,{className:`flex items-center justify-center h-64`,children:(0,x.jsx)(l,{className:`w-8 h-8 animate-spin text-bambu-green`})}):(0,x.jsxs)(`div`,{className:`p-4 md:p-6 max-w-2xl mx-auto`,children:[(0,x.jsxs)(`div`,{className:`flex items-center gap-3 mb-6`,children:[(0,x.jsx)(h,{className:`w-7 h-7 text-bambu-green`}),(0,x.jsx)(`h1`,{className:`text-2xl font-bold text-white`,children:e(`notifications.userEmail.title`)})]}),(0,x.jsx)(f,{className:`mb-6 border-blue-300 bg-blue-50 dark:border-blue-500/30 dark:bg-blue-500/5`,children:(0,x.jsx)(d,{className:`py-4`,children:(0,x.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,x.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center bg-blue-100 dark:bg-blue-500/20 flex-shrink-0`,children:(0,x.jsx)(v,{className:`w-5 h-5 text-blue-600 dark:text-blue-400`})}),(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`h3`,{className:`text-white font-medium`,children:e(`notifications.userEmail.emailNotifications`)}),(0,x.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:e(`notifications.userEmail.emailNotificationsDesc`)}),t?.email?(0,x.jsxs)(`p`,{className:`text-sm text-blue-700 dark:text-blue-400 mt-2`,children:[e(`notifications.userEmail.sendingTo`),`: `,(0,x.jsx)(`strong`,{children:t.email})]}):(0,x.jsx)(`p`,{className:`text-sm text-yellow-700 dark:text-yellow-400 mt-2`,children:e(`notifications.userEmail.noEmailWarning`)})]})]})})}),(0,x.jsxs)(f,{className:`mb-6`,children:[(0,x.jsxs)(u,{children:[(0,x.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`notifications.userEmail.printJobNotifications`)}),(0,x.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:e(`notifications.userEmail.printJobNotificationsDesc`)})]}),(0,x.jsxs)(d,{className:`space-y-4`,children:[(0,x.jsxs)(`div`,{className:`flex items-center justify-between p-4 bg-bambu-dark rounded-lg`,children:[(0,x.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,x.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center ${w?`bg-bambu-green/20`:`bg-bambu-dark-tertiary`}`,children:(0,x.jsx)(m,{className:`w-5 h-5 ${w?`text-bambu-green`:`text-bambu-gray`}`})}),(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`p`,{className:`text-white font-medium`,children:e(`notifications.userEmail.printJobStarts`)}),(0,x.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`notifications.userEmail.printJobStartsDesc`)})]})]}),(0,x.jsx)(`button`,{onClick:()=>V(T,w),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors focus:outline-none focus:ring-2 focus:ring-bambu-green focus:ring-offset-2 focus:ring-offset-bambu-dark ${w?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,role:`switch`,"aria-checked":w,children:(0,x.jsx)(`span`,{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${w?`translate-x-6`:`translate-x-1`}`})})]}),(0,x.jsxs)(`div`,{className:`flex items-center justify-between p-4 bg-bambu-dark rounded-lg`,children:[(0,x.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,x.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center ${E?`bg-bambu-green/20`:`bg-bambu-dark-tertiary`}`,children:(0,x.jsx)(m,{className:`w-5 h-5 ${E?`text-bambu-green`:`text-bambu-gray`}`})}),(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`p`,{className:`text-white font-medium`,children:e(`notifications.userEmail.printJobFinishes`)}),(0,x.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`notifications.userEmail.printJobFinishesDesc`)})]})]}),(0,x.jsx)(`button`,{onClick:()=>V(D,E),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors focus:outline-none focus:ring-2 focus:ring-bambu-green focus:ring-offset-2 focus:ring-offset-bambu-dark ${E?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,role:`switch`,"aria-checked":E,children:(0,x.jsx)(`span`,{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${E?`translate-x-6`:`translate-x-1`}`})})]}),(0,x.jsxs)(`div`,{className:`flex items-center justify-between p-4 bg-bambu-dark rounded-lg`,children:[(0,x.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,x.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center ${O?`bg-bambu-green/20`:`bg-bambu-dark-tertiary`}`,children:(0,x.jsx)(m,{className:`w-5 h-5 ${O?`text-bambu-green`:`text-bambu-gray`}`})}),(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`p`,{className:`text-white font-medium`,children:e(`notifications.userEmail.printErrors`)}),(0,x.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`notifications.userEmail.printErrorsDesc`)})]})]}),(0,x.jsx)(`button`,{onClick:()=>V(k,O),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors focus:outline-none focus:ring-2 focus:ring-bambu-green focus:ring-offset-2 focus:ring-offset-bambu-dark ${O?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,role:`switch`,"aria-checked":O,children:(0,x.jsx)(`span`,{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${O?`translate-x-6`:`translate-x-1`}`})})]}),(0,x.jsxs)(`div`,{className:`flex items-center justify-between p-4 bg-bambu-dark rounded-lg`,children:[(0,x.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,x.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center ${A?`bg-bambu-green/20`:`bg-bambu-dark-tertiary`}`,children:(0,x.jsx)(m,{className:`w-5 h-5 ${A?`text-bambu-green`:`text-bambu-gray`}`})}),(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`p`,{className:`text-white font-medium`,children:e(`notifications.userEmail.printJobStops`)}),(0,x.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`notifications.userEmail.printJobStopsDesc`)})]})]}),(0,x.jsx)(`button`,{onClick:()=>V(j,A),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors focus:outline-none focus:ring-2 focus:ring-bambu-green focus:ring-offset-2 focus:ring-offset-bambu-dark ${A?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,role:`switch`,"aria-checked":A,children:(0,x.jsx)(`span`,{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${A?`translate-x-6`:`translate-x-1`}`})})]})]})]}),(0,x.jsx)(`div`,{className:`flex justify-end`,children:(0,x.jsx)(p,{onClick:()=>B.mutate(),disabled:!M||B.isPending||!t?.email,children:B.isPending?(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(l,{className:`w-4 h-4 animate-spin`}),e(`common.saving`)]}):(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(g,{className:`w-4 h-4`}),e(`common.save`)]})})})]})}export{S as NotificationsPage}; \ No newline at end of file +import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,w as i}from"./client-DnySrlFv.js";import{n as a}from"./QueryClientProvider-Ce8_sN3w.js";import{t as o}from"./useQuery-BBCjCezC.js";import{t as s}from"./useMutation-B-Tr2hIP.js";import{n as c}from"./ToastContext-BRX0SW3C.js";import{t as l}from"./loader-circle-BEmFtawu.js";import{i as u,n as d,t as f}from"./Card-Bzc64K35.js";import{t as p}from"./Button-DDr6eAFy.js";import{An as m,In as h,Ut as g,Vn as _,in as v,yt as y}from"./index-Cxa-KVmA.js";var b=e(n(),1),x=t();function S(){let{t:e}=i(),{user:t}=y(),{showToast:n}=c(),S=a(),C=_(),[w,T]=(0,b.useState)(!0),[E,D]=(0,b.useState)(!0),[O,k]=(0,b.useState)(!0),[A,j]=(0,b.useState)(!0),[M,N]=(0,b.useState)(!1),{data:P,isLoading:F}=o({queryKey:[`advancedAuthStatus`],queryFn:r.getAdvancedAuthStatus,staleTime:300*1e3}),{data:I,isLoading:L}=o({queryKey:[`settings`],queryFn:r.getSettings,staleTime:300*1e3}),{data:R,isLoading:z}=o({queryKey:[`user-email-preferences`],queryFn:()=>r.getUserEmailPreferences()});(0,b.useEffect)(()=>{(P&&!P.advanced_auth_enabled||I&&!I.user_notifications_enabled)&&C(`/settings`,{replace:!0})},[P,I,C]),(0,b.useEffect)(()=>{R&&(T(R.notify_print_start),D(R.notify_print_complete),k(R.notify_print_failed),j(R.notify_print_stopped),N(!1))},[R]);let B=s({mutationFn:()=>r.updateUserEmailPreferences({notify_print_start:w,notify_print_complete:E,notify_print_failed:O,notify_print_stopped:A}),onSuccess:()=>{S.invalidateQueries({queryKey:[`user-email-preferences`]}),N(!1),n(e(`notifications.userEmail.saveSuccess`),`success`)},onError:t=>{n(t.message||e(`notifications.userEmail.saveError`),`error`)}}),V=(e,t)=>{e(!t),N(!0)};return z||F||L?(0,x.jsx)(`div`,{className:`flex items-center justify-center h-64`,children:(0,x.jsx)(l,{className:`w-8 h-8 animate-spin text-bambu-green`})}):(0,x.jsxs)(`div`,{className:`p-4 md:p-6 max-w-2xl mx-auto`,children:[(0,x.jsxs)(`div`,{className:`flex items-center gap-3 mb-6`,children:[(0,x.jsx)(h,{className:`w-7 h-7 text-bambu-green`}),(0,x.jsx)(`h1`,{className:`text-2xl font-bold text-white`,children:e(`notifications.userEmail.title`)})]}),(0,x.jsx)(f,{className:`mb-6 border-blue-300 bg-blue-50 dark:border-blue-500/30 dark:bg-blue-500/5`,children:(0,x.jsx)(d,{className:`py-4`,children:(0,x.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,x.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center bg-blue-100 dark:bg-blue-500/20 flex-shrink-0`,children:(0,x.jsx)(v,{className:`w-5 h-5 text-blue-600 dark:text-blue-400`})}),(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`h3`,{className:`text-white font-medium`,children:e(`notifications.userEmail.emailNotifications`)}),(0,x.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:e(`notifications.userEmail.emailNotificationsDesc`)}),t?.email?(0,x.jsxs)(`p`,{className:`text-sm text-blue-700 dark:text-blue-400 mt-2`,children:[e(`notifications.userEmail.sendingTo`),`: `,(0,x.jsx)(`strong`,{children:t.email})]}):(0,x.jsx)(`p`,{className:`text-sm text-yellow-700 dark:text-yellow-400 mt-2`,children:e(`notifications.userEmail.noEmailWarning`)})]})]})})}),(0,x.jsxs)(f,{className:`mb-6`,children:[(0,x.jsxs)(u,{children:[(0,x.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`notifications.userEmail.printJobNotifications`)}),(0,x.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:e(`notifications.userEmail.printJobNotificationsDesc`)})]}),(0,x.jsxs)(d,{className:`space-y-4`,children:[(0,x.jsxs)(`div`,{className:`flex items-center justify-between p-4 bg-bambu-dark rounded-lg`,children:[(0,x.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,x.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center ${w?`bg-bambu-green/20`:`bg-bambu-dark-tertiary`}`,children:(0,x.jsx)(m,{className:`w-5 h-5 ${w?`text-bambu-green`:`text-bambu-gray`}`})}),(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`p`,{className:`text-white font-medium`,children:e(`notifications.userEmail.printJobStarts`)}),(0,x.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`notifications.userEmail.printJobStartsDesc`)})]})]}),(0,x.jsx)(`button`,{onClick:()=>V(T,w),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors focus:outline-none focus:ring-2 focus:ring-bambu-green focus:ring-offset-2 focus:ring-offset-bambu-dark ${w?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,role:`switch`,"aria-checked":w,children:(0,x.jsx)(`span`,{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${w?`translate-x-6`:`translate-x-1`}`})})]}),(0,x.jsxs)(`div`,{className:`flex items-center justify-between p-4 bg-bambu-dark rounded-lg`,children:[(0,x.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,x.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center ${E?`bg-bambu-green/20`:`bg-bambu-dark-tertiary`}`,children:(0,x.jsx)(m,{className:`w-5 h-5 ${E?`text-bambu-green`:`text-bambu-gray`}`})}),(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`p`,{className:`text-white font-medium`,children:e(`notifications.userEmail.printJobFinishes`)}),(0,x.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`notifications.userEmail.printJobFinishesDesc`)})]})]}),(0,x.jsx)(`button`,{onClick:()=>V(D,E),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors focus:outline-none focus:ring-2 focus:ring-bambu-green focus:ring-offset-2 focus:ring-offset-bambu-dark ${E?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,role:`switch`,"aria-checked":E,children:(0,x.jsx)(`span`,{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${E?`translate-x-6`:`translate-x-1`}`})})]}),(0,x.jsxs)(`div`,{className:`flex items-center justify-between p-4 bg-bambu-dark rounded-lg`,children:[(0,x.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,x.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center ${O?`bg-bambu-green/20`:`bg-bambu-dark-tertiary`}`,children:(0,x.jsx)(m,{className:`w-5 h-5 ${O?`text-bambu-green`:`text-bambu-gray`}`})}),(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`p`,{className:`text-white font-medium`,children:e(`notifications.userEmail.printErrors`)}),(0,x.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`notifications.userEmail.printErrorsDesc`)})]})]}),(0,x.jsx)(`button`,{onClick:()=>V(k,O),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors focus:outline-none focus:ring-2 focus:ring-bambu-green focus:ring-offset-2 focus:ring-offset-bambu-dark ${O?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,role:`switch`,"aria-checked":O,children:(0,x.jsx)(`span`,{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${O?`translate-x-6`:`translate-x-1`}`})})]}),(0,x.jsxs)(`div`,{className:`flex items-center justify-between p-4 bg-bambu-dark rounded-lg`,children:[(0,x.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,x.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center ${A?`bg-bambu-green/20`:`bg-bambu-dark-tertiary`}`,children:(0,x.jsx)(m,{className:`w-5 h-5 ${A?`text-bambu-green`:`text-bambu-gray`}`})}),(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`p`,{className:`text-white font-medium`,children:e(`notifications.userEmail.printJobStops`)}),(0,x.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`notifications.userEmail.printJobStopsDesc`)})]})]}),(0,x.jsx)(`button`,{onClick:()=>V(j,A),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors focus:outline-none focus:ring-2 focus:ring-bambu-green focus:ring-offset-2 focus:ring-offset-bambu-dark ${A?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,role:`switch`,"aria-checked":A,children:(0,x.jsx)(`span`,{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${A?`translate-x-6`:`translate-x-1`}`})})]})]})]}),(0,x.jsx)(`div`,{className:`flex justify-end`,children:(0,x.jsx)(p,{onClick:()=>B.mutate(),disabled:!M||B.isPending||!t?.email,children:B.isPending?(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(l,{className:`w-4 h-4 animate-spin`}),e(`common.saving`)]}):(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(g,{className:`w-4 h-4`}),e(`common.save`)]})})})]})}export{S as NotificationsPage}; \ No newline at end of file diff --git a/static/assets/PdfPreviewModal-Con0pW4P.js b/static/assets/PdfPreviewModal-gJCfcyUW.js similarity index 97% rename from static/assets/PdfPreviewModal-Con0pW4P.js rename to static/assets/PdfPreviewModal-gJCfcyUW.js index 177055a93..e03ddb891 100644 --- a/static/assets/PdfPreviewModal-Con0pW4P.js +++ b/static/assets/PdfPreviewModal-gJCfcyUW.js @@ -1,2 +1,2 @@ -const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/pdf-Pg2jLqZQ.js","assets/index-0t--Yqoi.js","assets/chunk-aKtaBQYM.js","assets/QueryClientProvider-Ce8_sN3w.js","assets/client-DnySrlFv.js","assets/useMutation-B-Tr2hIP.js","assets/useQueries-Be6PMvSC.js","assets/useQuery-BBCjCezC.js","assets/createLucideIcon-DvBYJlWL.js","assets/arrow-down-Cj0DZhNf.js","assets/arrow-up-D-pfJ3WZ.js","assets/calendar-BLKPnWqV.js","assets/check-Ck0cMLU4.js","assets/info-ROUoQhJR.js","assets/ToastContext-BRX0SW3C.js","assets/loader-circle-BEmFtawu.js","assets/x-DR-Trv6U.js","assets/file-DDkFXH-b.js","assets/triangle-alert-Dt_1FcBy.js","assets/react-dom-B8Dg6xzp.js","assets/Button-DDr6eAFy.js","assets/Card-Bzc64K35.js","assets/filamentSwatchHelpers-D3oXQSGk.js","assets/date-G9KUauqz.js","assets/index-LBjsy7mY.css"])))=>i.map(i=>d[i]); -import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,l as i,w as a}from"./client-DnySrlFv.js";import{t as o}from"./loader-circle-BEmFtawu.js";import{n as s,t as c}from"./zoom-out-DNNe6DMN.js";import{t as l}from"./file-DDkFXH-b.js";import{Kn as u,Mn as d,jn as ee,xn as te}from"./index-0t--Yqoi.js";import{n as ne,r as f,t as p}from"./usePreviewFullscreen-ButueZqN.js";var m=e(n(),1),h=t(),g=.4,_=4,v=1.25,y=30,b=Math.log(v)/y,re=150,x=16*1024*1024,S=`/assets/pdfjs/`,C=e=>Math.min(_,Math.max(g,e));function w(e){let t=document.createElement(`canvas`);t.width=256,t.height=256;let n=t.getContext(`2d`);if(!n)return Promise.resolve(null);n.fillStyle=`#ffffff`,n.fillRect(0,0,256,256);let r=256/Math.max(e.width,e.height),i=e.width*r,a=e.height*r;return n.drawImage(e,(256-i)/2,(256-a)/2,i,a),new Promise(e=>t.toBlob(e,`image/png`))}function ie(e){return e.deltaMode===1?e.deltaY*16:e.deltaMode===2?e.deltaY*100:e.deltaY}function T({libraryFileId:e,filename:t,fileSize:n,onClose:g,onSnapshot:_}){let{t:T}=a(),E=p(),{panelRef:D,isFullscreen:ae,toggleFullscreen:oe}=E,O=(0,m.useRef)(null),k=(0,m.useRef)(null),A=(0,m.useRef)(null),j=(0,m.useRef)(!1),M=(0,m.useRef)(_);(0,m.useEffect)(()=>{M.current=_});let[N,P]=(0,m.useState)(null),[F,I]=(0,m.useState)(1),[L,R]=(0,m.useState)(1),[z,B]=(0,m.useState)(1),[V,se]=(0,m.useState)(0),[H,U]=(0,m.useState)(null),[ce,W]=(0,m.useState)(!0),G=(0,m.useRef)(L),K=(0,m.useRef)(null),q=(0,m.useRef)(null),J=(0,m.useRef)(new Map),Y=(0,m.useRef)(null),X=(0,m.useCallback)((e,t,n)=>{let r=O.current,i=k.current;if(r&&i){let e=r.getBoundingClientRect(),a=i.getBoundingClientRect(),o=t==null?e.width/2:t-e.left,s=n==null?e.height/2:n-e.top;q.current=a.width>0&&a.height>0?{fx:(o+e.left-a.left)/a.width,fy:(s+e.top-a.top)/a.height,px:o,py:s}:null}R(t=>C(t*e))},[]);(0,m.useEffect)(()=>{let e=e=>{e.ctrlKey||e.metaKey||e.altKey||(e.key===`+`||e.key===`=`?(e.preventDefault(),X(v)):e.key===`-`?(e.preventDefault(),X(1/v)):e.key===`0`&&(e.preventDefault(),q.current=null,R(1)))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[X]),(0,m.useEffect)(()=>{let e=O.current;if(!e)return;let t=t=>{if(!k.current||!K.current||!(t.ctrlKey||t.metaKey)&&!(e.scrollHeight<=e.clientHeight&&e.scrollWidth<=e.clientWidth))return;t.preventDefault();let n=Math.max(-30,Math.min(y,ie(t)));X(Math.exp(-n*b),t.clientX,t.clientY)};return e.addEventListener(`wheel`,t,{passive:!1}),()=>e.removeEventListener(`wheel`,t)},[X]);let le=e=>{e.pointerType===`touch`&&(J.current.set(e.pointerId,{x:e.clientX,y:e.clientY}),Y.current=null)},ue=e=>{if(e.pointerType!==`touch`)return;let t=J.current,n=t.get(e.pointerId);if(!n)return;if(t.set(e.pointerId,{x:e.clientX,y:e.clientY}),t.size===1){let t=O.current;t&&(t.scrollLeft-=e.clientX-n.x,t.scrollTop-=e.clientY-n.y);return}if(t.size!==2)return;let[r,i]=Array.from(t.values()),a=Math.hypot(r.x-i.x,r.y-i.y),o=Y.current;Y.current=a,o!=null&&o>0&&a>0&&X(a/o,(r.x+i.x)/2,(r.y+i.y)/2)},Z=e=>{e.pointerType===`touch`&&(J.current.delete(e.pointerId),Y.current=null)};(0,m.useLayoutEffect)(()=>{G.current=L;let e=k.current,t=O.current,n=K.current;if(!e||!t||!n)return;e.style.width=`${n.width*L}px`,e.style.height=`${n.height*L}px`;let r=q.current;q.current=null,r&&(t.scrollLeft=e.offsetLeft+r.fx*e.offsetWidth-r.px,t.scrollTop=e.offsetTop+r.fy*e.offsetHeight-r.py)},[L]),(0,m.useEffect)(()=>{if(L===z)return;let e=window.setTimeout(()=>B(L),re);return()=>window.clearTimeout(e)},[L,z]),(0,m.useEffect)(()=>{let e=D.current;if(!e)return;let t=new ResizeObserver(()=>se(e=>e+1));return t.observe(e),()=>t.disconnect()},[D]),(0,m.useEffect)(()=>{let t=!1,a=null;if(P(null),U(null),I(1),W(!0),n>52428800){U(T(`fileManager.preview.tooLarge`,{size:l(n)})),W(!1);return}let o={},s=i();return s&&(o.Authorization=`Bearer ${s}`),(async()=>{let n=await fetch(r.getLibraryFileDownloadUrl(e),{headers:o});if(!n.ok)throw Error(`HTTP ${n.status}`);let i=await n.arrayBuffer(),s=await u(()=>import(`./pdf-Pg2jLqZQ.js`),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24]));if(s.GlobalWorkerOptions.workerSrc||(s.GlobalWorkerOptions.workerSrc=(await u(async()=>{let{default:e}=await import(`./pdf.worker.min-DpOxPwGP.js`);return{default:e}},[])).default),a=s.getDocument({data:new Uint8Array(i),cMapUrl:`${S}cmaps/`,iccUrl:`${S}iccs/`,standardFontDataUrl:`${S}standard_fonts/`,wasmUrl:`${S}wasm/`}),t){a.destroy();return}let c=await a.promise;t||P(c)})().catch(e=>{console.error(`[pdf-preview] load failed`,e),t||(U(T(`fileManager.preview.error`)),W(!1))}),()=>{t=!0,A.current?.cancel(),A.current=null,a?.destroy()}},[e,n,T]),(0,m.useEffect)(()=>{if(!N)return;let e=!1;return W(!0),(async()=>{let t=await N.getPage(F),n=k.current,r=O.current;if(!n||!r||e)return;let i=t.getViewport({scale:1}),a=Math.max((r.clientWidth-32)/i.width,.1),o=Math.min(window.devicePixelRatio||1,2),s=a*z*o,c=i.width*s*(i.height*s),l=c>x?s*Math.sqrt(x/c):s,u=t.getViewport({scale:l});n.width=u.width,n.height=u.height,K.current={width:i.width*a,height:i.height*a},n.style.width=`${K.current.width*G.current}px`,n.style.height=`${K.current.height*G.current}px`,A.current?.cancel();let d=t.render({canvas:n,viewport:u});if(A.current=d,await d.promise,!e&&(W(!1),F===1&&M.current&&!j.current)){j.current=!0;let t=await w(n);t&&!e&&M.current?.(t)}})().catch(t=>{!e&&t?.name!==`RenderingCancelledException`&&(console.error(`[pdf-preview] render failed`,t),U(T(`fileManager.preview.error`)),W(!1))}),()=>{e=!0}},[N,F,z,V,T]);let Q=N?.numPages??0,$=f;return(0,h.jsx)(ne,{title:t,fullscreen:E,onClose:g,icon:(0,h.jsx)(te,{className:`w-5 h-5 text-bambu-green flex-shrink-0`}),actions:(0,h.jsxs)(h.Fragment,{children:[N&&Q>1&&(0,h.jsxs)(`div`,{className:`flex items-center gap-1 mr-2`,children:[(0,h.jsx)(`button`,{onClick:()=>I(e=>Math.max(1,e-1)),disabled:F<=1,className:`${$} disabled:opacity-40 disabled:cursor-not-allowed`,"aria-label":T(`fileManager.preview.prevPage`),children:(0,h.jsx)(ee,{className:`w-4 h-4`})}),(0,h.jsx)(`span`,{className:`text-sm text-bambu-gray whitespace-nowrap`,children:T(`fileManager.preview.page`,{current:F,total:Q})}),(0,h.jsx)(`button`,{onClick:()=>I(e=>Math.min(Q,e+1)),disabled:F>=Q,className:`${$} disabled:opacity-40 disabled:cursor-not-allowed`,"aria-label":T(`fileManager.preview.nextPage`),children:(0,h.jsx)(d,{className:`w-4 h-4`})})]}),N&&(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`button`,{onClick:()=>X(1/v),className:$,"aria-label":T(`fileManager.preview.zoomOut`),children:(0,h.jsx)(c,{className:`w-4 h-4`})}),(0,h.jsx)(`button`,{onClick:()=>X(v),className:$,"aria-label":T(`fileManager.preview.zoomIn`),children:(0,h.jsx)(s,{className:`w-4 h-4`})})]})]}),children:(0,h.jsxs)(`div`,{ref:O,"data-testid":`pdf-preview-page`,className:`relative flex-1 min-h-0 overflow-auto bg-bambu-dark p-4 touch-none ${ae?``:`rounded-b-lg`}`,onDoubleClick:oe,onPointerDown:le,onPointerMove:ue,onPointerUp:Z,onPointerCancel:Z,onPointerLeave:Z,children:[H?(0,h.jsx)(`div`,{className:`h-full flex items-center justify-center`,children:(0,h.jsx)(`p`,{className:`text-bambu-gray text-center`,children:H})}):(0,h.jsx)(`div`,{className:`flex justify-center min-w-fit`,children:(0,h.jsx)(`canvas`,{ref:k,className:`shadow-lg`})}),!H&&ce&&(0,h.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center pointer-events-none`,children:(0,h.jsx)(o,{className:`w-8 h-8 text-bambu-green animate-spin`})})]})})}export{T as PdfPreviewModal}; \ No newline at end of file +const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/pdf-0GqeufOV.js","assets/index-Cxa-KVmA.js","assets/chunk-aKtaBQYM.js","assets/QueryClientProvider-Ce8_sN3w.js","assets/client-DnySrlFv.js","assets/useMutation-B-Tr2hIP.js","assets/useQueries-Be6PMvSC.js","assets/useQuery-BBCjCezC.js","assets/createLucideIcon-DvBYJlWL.js","assets/arrow-down-Cj0DZhNf.js","assets/arrow-up-D-pfJ3WZ.js","assets/calendar-BLKPnWqV.js","assets/check-Ck0cMLU4.js","assets/info-ROUoQhJR.js","assets/ToastContext-BRX0SW3C.js","assets/loader-circle-BEmFtawu.js","assets/x-DR-Trv6U.js","assets/file-DDkFXH-b.js","assets/triangle-alert-Dt_1FcBy.js","assets/react-dom-B8Dg6xzp.js","assets/Button-DDr6eAFy.js","assets/Card-Bzc64K35.js","assets/filamentSwatchHelpers-D3oXQSGk.js","assets/date-G9KUauqz.js","assets/index-LBjsy7mY.css"])))=>i.map(i=>d[i]); +import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,l as i,w as a}from"./client-DnySrlFv.js";import{t as o}from"./loader-circle-BEmFtawu.js";import{n as s,t as c}from"./zoom-out-DNNe6DMN.js";import{t as l}from"./file-DDkFXH-b.js";import{Kn as u,Mn as d,jn as ee,xn as te}from"./index-Cxa-KVmA.js";import{n as ne,r as f,t as p}from"./usePreviewFullscreen-ButueZqN.js";var m=e(n(),1),h=t(),g=.4,_=4,v=1.25,y=30,b=Math.log(v)/y,re=150,x=16*1024*1024,S=`/assets/pdfjs/`,C=e=>Math.min(_,Math.max(g,e));function w(e){let t=document.createElement(`canvas`);t.width=256,t.height=256;let n=t.getContext(`2d`);if(!n)return Promise.resolve(null);n.fillStyle=`#ffffff`,n.fillRect(0,0,256,256);let r=256/Math.max(e.width,e.height),i=e.width*r,a=e.height*r;return n.drawImage(e,(256-i)/2,(256-a)/2,i,a),new Promise(e=>t.toBlob(e,`image/png`))}function ie(e){return e.deltaMode===1?e.deltaY*16:e.deltaMode===2?e.deltaY*100:e.deltaY}function T({libraryFileId:e,filename:t,fileSize:n,onClose:g,onSnapshot:_}){let{t:T}=a(),E=p(),{panelRef:D,isFullscreen:ae,toggleFullscreen:oe}=E,O=(0,m.useRef)(null),k=(0,m.useRef)(null),A=(0,m.useRef)(null),j=(0,m.useRef)(!1),M=(0,m.useRef)(_);(0,m.useEffect)(()=>{M.current=_});let[N,P]=(0,m.useState)(null),[F,I]=(0,m.useState)(1),[L,R]=(0,m.useState)(1),[z,B]=(0,m.useState)(1),[V,se]=(0,m.useState)(0),[H,U]=(0,m.useState)(null),[ce,W]=(0,m.useState)(!0),G=(0,m.useRef)(L),K=(0,m.useRef)(null),q=(0,m.useRef)(null),J=(0,m.useRef)(new Map),Y=(0,m.useRef)(null),X=(0,m.useCallback)((e,t,n)=>{let r=O.current,i=k.current;if(r&&i){let e=r.getBoundingClientRect(),a=i.getBoundingClientRect(),o=t==null?e.width/2:t-e.left,s=n==null?e.height/2:n-e.top;q.current=a.width>0&&a.height>0?{fx:(o+e.left-a.left)/a.width,fy:(s+e.top-a.top)/a.height,px:o,py:s}:null}R(t=>C(t*e))},[]);(0,m.useEffect)(()=>{let e=e=>{e.ctrlKey||e.metaKey||e.altKey||(e.key===`+`||e.key===`=`?(e.preventDefault(),X(v)):e.key===`-`?(e.preventDefault(),X(1/v)):e.key===`0`&&(e.preventDefault(),q.current=null,R(1)))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[X]),(0,m.useEffect)(()=>{let e=O.current;if(!e)return;let t=t=>{if(!k.current||!K.current||!(t.ctrlKey||t.metaKey)&&!(e.scrollHeight<=e.clientHeight&&e.scrollWidth<=e.clientWidth))return;t.preventDefault();let n=Math.max(-30,Math.min(y,ie(t)));X(Math.exp(-n*b),t.clientX,t.clientY)};return e.addEventListener(`wheel`,t,{passive:!1}),()=>e.removeEventListener(`wheel`,t)},[X]);let le=e=>{e.pointerType===`touch`&&(J.current.set(e.pointerId,{x:e.clientX,y:e.clientY}),Y.current=null)},ue=e=>{if(e.pointerType!==`touch`)return;let t=J.current,n=t.get(e.pointerId);if(!n)return;if(t.set(e.pointerId,{x:e.clientX,y:e.clientY}),t.size===1){let t=O.current;t&&(t.scrollLeft-=e.clientX-n.x,t.scrollTop-=e.clientY-n.y);return}if(t.size!==2)return;let[r,i]=Array.from(t.values()),a=Math.hypot(r.x-i.x,r.y-i.y),o=Y.current;Y.current=a,o!=null&&o>0&&a>0&&X(a/o,(r.x+i.x)/2,(r.y+i.y)/2)},Z=e=>{e.pointerType===`touch`&&(J.current.delete(e.pointerId),Y.current=null)};(0,m.useLayoutEffect)(()=>{G.current=L;let e=k.current,t=O.current,n=K.current;if(!e||!t||!n)return;e.style.width=`${n.width*L}px`,e.style.height=`${n.height*L}px`;let r=q.current;q.current=null,r&&(t.scrollLeft=e.offsetLeft+r.fx*e.offsetWidth-r.px,t.scrollTop=e.offsetTop+r.fy*e.offsetHeight-r.py)},[L]),(0,m.useEffect)(()=>{if(L===z)return;let e=window.setTimeout(()=>B(L),re);return()=>window.clearTimeout(e)},[L,z]),(0,m.useEffect)(()=>{let e=D.current;if(!e)return;let t=new ResizeObserver(()=>se(e=>e+1));return t.observe(e),()=>t.disconnect()},[D]),(0,m.useEffect)(()=>{let t=!1,a=null;if(P(null),U(null),I(1),W(!0),n>52428800){U(T(`fileManager.preview.tooLarge`,{size:l(n)})),W(!1);return}let o={},s=i();return s&&(o.Authorization=`Bearer ${s}`),(async()=>{let n=await fetch(r.getLibraryFileDownloadUrl(e),{headers:o});if(!n.ok)throw Error(`HTTP ${n.status}`);let i=await n.arrayBuffer(),s=await u(()=>import(`./pdf-0GqeufOV.js`),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24]));if(s.GlobalWorkerOptions.workerSrc||(s.GlobalWorkerOptions.workerSrc=(await u(async()=>{let{default:e}=await import(`./pdf.worker.min-DpOxPwGP.js`);return{default:e}},[])).default),a=s.getDocument({data:new Uint8Array(i),cMapUrl:`${S}cmaps/`,iccUrl:`${S}iccs/`,standardFontDataUrl:`${S}standard_fonts/`,wasmUrl:`${S}wasm/`}),t){a.destroy();return}let c=await a.promise;t||P(c)})().catch(e=>{console.error(`[pdf-preview] load failed`,e),t||(U(T(`fileManager.preview.error`)),W(!1))}),()=>{t=!0,A.current?.cancel(),A.current=null,a?.destroy()}},[e,n,T]),(0,m.useEffect)(()=>{if(!N)return;let e=!1;return W(!0),(async()=>{let t=await N.getPage(F),n=k.current,r=O.current;if(!n||!r||e)return;let i=t.getViewport({scale:1}),a=Math.max((r.clientWidth-32)/i.width,.1),o=Math.min(window.devicePixelRatio||1,2),s=a*z*o,c=i.width*s*(i.height*s),l=c>x?s*Math.sqrt(x/c):s,u=t.getViewport({scale:l});n.width=u.width,n.height=u.height,K.current={width:i.width*a,height:i.height*a},n.style.width=`${K.current.width*G.current}px`,n.style.height=`${K.current.height*G.current}px`,A.current?.cancel();let d=t.render({canvas:n,viewport:u});if(A.current=d,await d.promise,!e&&(W(!1),F===1&&M.current&&!j.current)){j.current=!0;let t=await w(n);t&&!e&&M.current?.(t)}})().catch(t=>{!e&&t?.name!==`RenderingCancelledException`&&(console.error(`[pdf-preview] render failed`,t),U(T(`fileManager.preview.error`)),W(!1))}),()=>{e=!0}},[N,F,z,V,T]);let Q=N?.numPages??0,$=f;return(0,h.jsx)(ne,{title:t,fullscreen:E,onClose:g,icon:(0,h.jsx)(te,{className:`w-5 h-5 text-bambu-green flex-shrink-0`}),actions:(0,h.jsxs)(h.Fragment,{children:[N&&Q>1&&(0,h.jsxs)(`div`,{className:`flex items-center gap-1 mr-2`,children:[(0,h.jsx)(`button`,{onClick:()=>I(e=>Math.max(1,e-1)),disabled:F<=1,className:`${$} disabled:opacity-40 disabled:cursor-not-allowed`,"aria-label":T(`fileManager.preview.prevPage`),children:(0,h.jsx)(ee,{className:`w-4 h-4`})}),(0,h.jsx)(`span`,{className:`text-sm text-bambu-gray whitespace-nowrap`,children:T(`fileManager.preview.page`,{current:F,total:Q})}),(0,h.jsx)(`button`,{onClick:()=>I(e=>Math.min(Q,e+1)),disabled:F>=Q,className:`${$} disabled:opacity-40 disabled:cursor-not-allowed`,"aria-label":T(`fileManager.preview.nextPage`),children:(0,h.jsx)(d,{className:`w-4 h-4`})})]}),N&&(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`button`,{onClick:()=>X(1/v),className:$,"aria-label":T(`fileManager.preview.zoomOut`),children:(0,h.jsx)(c,{className:`w-4 h-4`})}),(0,h.jsx)(`button`,{onClick:()=>X(v),className:$,"aria-label":T(`fileManager.preview.zoomIn`),children:(0,h.jsx)(s,{className:`w-4 h-4`})})]})]}),children:(0,h.jsxs)(`div`,{ref:O,"data-testid":`pdf-preview-page`,className:`relative flex-1 min-h-0 overflow-auto bg-bambu-dark p-4 touch-none ${ae?``:`rounded-b-lg`}`,onDoubleClick:oe,onPointerDown:le,onPointerMove:ue,onPointerUp:Z,onPointerCancel:Z,onPointerLeave:Z,children:[H?(0,h.jsx)(`div`,{className:`h-full flex items-center justify-center`,children:(0,h.jsx)(`p`,{className:`text-bambu-gray text-center`,children:H})}):(0,h.jsx)(`div`,{className:`flex justify-center min-w-fit`,children:(0,h.jsx)(`canvas`,{ref:k,className:`shadow-lg`})}),!H&&ce&&(0,h.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center pointer-events-none`,children:(0,h.jsx)(o,{className:`w-8 h-8 text-bambu-green animate-spin`})})]})})}export{T as PdfPreviewModal}; \ No newline at end of file diff --git a/static/assets/PhotoGalleryModal-C8-A6a4s.js b/static/assets/PhotoGalleryModal-BPFizk3N.js similarity index 99% rename from static/assets/PhotoGalleryModal-C8-A6a4s.js rename to static/assets/PhotoGalleryModal-BPFizk3N.js index 71c489a0a..37ed0fc7f 100644 --- a/static/assets/PhotoGalleryModal-C8-A6a4s.js +++ b/static/assets/PhotoGalleryModal-BPFizk3N.js @@ -1 +1 @@ -import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,w as i}from"./client-DnySrlFv.js";import{n as a}from"./QueryClientProvider-Ce8_sN3w.js";import{t as o}from"./useQuery-BBCjCezC.js";import{t as s}from"./useMutation-B-Tr2hIP.js";import{n as c}from"./ToastContext-BRX0SW3C.js";import{t as l}from"./cog-Dol1I0kq.js";import{t as u}from"./loader-circle-BEmFtawu.js";import{t as d}from"./play-DIDYtk2S.js";import{t as f}from"./triangle-alert-Dt_1FcBy.js";import{t as p}from"./x-DR-Trv6U.js";import{t as m}from"./Button-DDr6eAFy.js";import{At as h,Jt as g,Mn as _,_t as v,jn as y,t as b,wn as x}from"./index-0t--Yqoi.js";var S=e(n(),1),C=t();function w({source:e,onClose:t}){let{t:n}=i(),l=a(),{showToast:u}=c(),[f,m]=(0,S.useState)(null),[h,g]=(0,S.useState)(null),[_,v]=(0,S.useState)(1),{trackJob:y}=b(),{data:x,isLoading:w}=o({queryKey:[`slicer-pipelines`],queryFn:()=>r.listSlicerPipelines()}),{data:D}=o({queryKey:[`printers`],queryFn:()=>r.getPrinters()}),{data:O}=o({queryKey:[`app-settings`],queryFn:()=>r.getSettings()}),k=O?.pipeline_max_copies??50,A={kind:e.kind,id:e.id},j=s({mutationFn:e=>r.checkPipelineEligibility(e,A)}),M=s({mutationFn:({pipelineId:e,force:t})=>r.runPipeline(e,A,t,_),onSuccess:r=>{l.invalidateQueries({queryKey:[`slicer-pipelines`]}),l.invalidateQueries({queryKey:[`pipeline-runs`]}),r.slice_job_id&&y(r.slice_job_id,e.kind,e.filename),u(n(`library.runWithPipeline.toast.started`,`Pipeline run started`),`success`),t()},onError:e=>{u(e.message||n(`library.runWithPipeline.toast.failed`,`Could not start run`),`error`)}}),N=x?.pipelines??[],P=(D??[]).reduce((e,t)=>(e[t.id]=t,e),{});return(0,C.jsx)(`div`,{className:`fixed inset-0 z-50 bg-black/60 flex items-center justify-center p-4`,onClick:t,role:`dialog`,"aria-modal":`true`,"aria-label":n(`library.runWithPipeline.modalTitle`,`Run with pipeline`),children:(0,C.jsxs)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-2xl w-full max-w-md max-h-[80vh] flex flex-col overflow-hidden`,onClick:e=>e.stopPropagation(),children:[(0,C.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 border-b border-bambu-dark-tertiary`,children:[(0,C.jsxs)(`h3`,{className:`text-sm font-semibold text-white flex items-center gap-2`,children:[(0,C.jsx)(d,{className:`w-4 h-4 text-bambu-green`}),f&&h?n(`library.runWithPipeline.confirmTitle`,`Confirm run`):n(`library.runWithPipeline.modalTitle`,`Run with pipeline`)]}),(0,C.jsx)(`button`,{type:`button`,onClick:t,"aria-label":n(`common.close`,`Close`),className:`text-bambu-gray hover:text-white`,children:(0,C.jsx)(p,{className:`w-4 h-4`})})]}),(0,C.jsx)(`div`,{className:`flex-1 overflow-y-auto p-4 space-y-3`,children:f&&h?(0,C.jsx)(E,{pipeline:f,report:h,source:e,onBack:()=>{m(null),g(null)},onConfirm:()=>{f&&M.mutate({pipelineId:f.id,force:!0})},running:M.isPending}):(0,C.jsx)(T,{source:e,pipelines:N,printerById:P,loading:w||j.isPending,onPick:async e=>{if(!(e.target_printer_id||e.target_kind===`printer_class`&&e.target_model_class)){u(n(`library.runWithPipeline.noTargetMessage`,`This pipeline has no target printer set. Open it in Settings to pick one.`),`error`);return}m(e);try{let t=await j.mutateAsync(e.id);g(t),t.ok&&M.mutate({pipelineId:e.id,force:!1})}catch{m(null)}},copies:_,maxCopies:k,onCopiesChange:v})})]})})}function T({source:e,pipelines:t,printerById:n,loading:r,onPick:a,copies:o,maxCopies:s,onCopiesChange:c}){let{t:d}=i();return(0,C.jsxs)(C.Fragment,{children:[(0,C.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[d(`library.runWithPipeline.sourceHint`,`Source`),`:`,` `,(0,C.jsx)(`span`,{className:`text-white`,children:e.filename})]}),(0,C.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,C.jsxs)(`label`,{className:`text-xs text-bambu-gray`,htmlFor:`run-pipeline-copies`,children:[d(`library.runWithPipeline.copies`,`Copies`),`:`]}),(0,C.jsx)(`input`,{id:`run-pipeline-copies`,type:`number`,min:1,max:s,value:o,onChange:e=>{let t=parseInt(e.target.value,10);Number.isNaN(t)||c(Math.max(1,Math.min(s,t)))},"aria-label":d(`library.runWithPipeline.copies`,`Copies`),className:`w-20 px-2 py-1 text-xs bg-bambu-dark border border-bambu-dark-tertiary rounded text-white`}),(0,C.jsx)(`span`,{className:`text-xs text-bambu-gray/60`,children:d(`library.runWithPipeline.copiesHint`,`max {{n}}`,{n:s})})]}),r&&(0,C.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-bambu-gray`,children:[(0,C.jsx)(u,{className:`w-4 h-4 animate-spin`}),d(`library.runWithPipeline.loading`,`Loading…`)]}),!r&&t.length===0&&(0,C.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:d(`library.runWithPipeline.empty`,`No pipelines saved yet. Open the Slice dialog and click "Save as pipeline" to create one.`)}),!r&&t.length>0&&(0,C.jsx)(`ul`,{className:`space-y-1.5`,"aria-label":d(`library.runWithPipeline.pipelineListAria`,`Available pipelines`),children:t.map(e=>{let t=e.target_kind===`printer_class`,r=e.target_printer_id?n[e.target_printer_id]?.name:null,i=t&&e.target_model_class?d(`library.runWithPipeline.classTarget`,`Any {{model}}`,{model:e.target_model_class}):null;return(0,C.jsx)(`li`,{children:(0,C.jsxs)(`button`,{type:`button`,onClick:()=>a(e),disabled:!(e.target_printer_id||t&&e.target_model_class),className:`w-full text-left px-3 py-2 rounded-md border border-bambu-dark-tertiary bg-bambu-dark/40 hover:bg-bambu-dark-tertiary disabled:opacity-50 disabled:cursor-not-allowed transition-colors`,children:[(0,C.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,C.jsx)(l,{className:`w-3.5 h-3.5 text-bambu-green flex-shrink-0`}),(0,C.jsx)(`span`,{className:`text-sm font-medium text-white truncate`,children:e.name})]}),(0,C.jsxs)(`div`,{className:`mt-1 text-xs text-bambu-gray flex items-center gap-1`,children:[(0,C.jsx)(g,{className:`w-3 h-3`}),i?(0,C.jsx)(`span`,{children:i}):r?(0,C.jsx)(`span`,{children:r}):(0,C.jsx)(`span`,{className:`text-amber-700 dark:text-amber-400`,children:d(`library.runWithPipeline.noTarget`,`No target printer set`)})]})]})},e.id)})})]})}function E({pipeline:e,report:t,source:n,onBack:r,onConfirm:a,running:o}){let{t:s}=i();return(0,C.jsxs)(C.Fragment,{children:[(0,C.jsxs)(`div`,{className:`text-xs text-bambu-gray`,children:[(0,C.jsxs)(`p`,{children:[s(`library.runWithPipeline.confirmIntro`,`Pre-flight found issues with this run`),`:`]}),(0,C.jsxs)(`p`,{className:`mt-1`,children:[(0,C.jsxs)(`span`,{className:`text-bambu-gray/70`,children:[s(`library.runWithPipeline.sourceHint`,`Source`),`: `]}),(0,C.jsx)(`span`,{className:`text-white`,children:n.filename})]}),(0,C.jsxs)(`p`,{children:[(0,C.jsxs)(`span`,{className:`text-bambu-gray/70`,children:[s(`library.runWithPipeline.pipelineHint`,`Pipeline`),`: `]}),(0,C.jsx)(`span`,{className:`text-white`,children:e.name})]}),t.target_printer_name&&(0,C.jsxs)(`p`,{children:[(0,C.jsxs)(`span`,{className:`text-bambu-gray/70`,children:[s(`library.runWithPipeline.targetHint`,`Target`),`: `]}),(0,C.jsx)(`span`,{className:`text-white`,children:t.target_printer_name})]})]}),(0,C.jsx)(`ul`,{className:`space-y-1.5`,children:t.issues.map((e,t)=>(0,C.jsxs)(`li`,{className:`flex items-start gap-2 text-xs`,children:[(0,C.jsx)(f,{className:`w-3.5 h-3.5 text-amber-600 dark:text-amber-400 flex-shrink-0 mt-0.5`}),(0,C.jsx)(`span`,{className:`text-bambu-gray`,children:(0,C.jsx)(D,{issue:e})})]},t))}),(0,C.jsxs)(`div`,{className:`flex items-center justify-end gap-2 pt-2 border-t border-bambu-dark-tertiary`,children:[(0,C.jsx)(`button`,{type:`button`,onClick:r,disabled:o,className:`px-3 py-1.5 text-xs text-bambu-gray hover:text-white`,children:s(`common.back`,`Back`)}),(0,C.jsxs)(`button`,{type:`button`,onClick:a,disabled:o,className:`px-3 py-1.5 text-xs bg-amber-500 hover:bg-amber-600 text-white rounded disabled:opacity-50 flex items-center gap-1`,children:[o?(0,C.jsx)(u,{className:`w-3 h-3 animate-spin`}):(0,C.jsx)(d,{className:`w-3 h-3`}),s(`library.runWithPipeline.runAnyway`,`Run anyway`)]})]})]})}function D({issue:e}){let{t}=i();switch(e.kind){case`printer_not_set`:return(0,C.jsx)(C.Fragment,{children:t(`library.runWithPipeline.issue.printerNotSet`,`No target printer set on this pipeline.`)});case`printer_not_found`:return(0,C.jsx)(C.Fragment,{children:t(`library.runWithPipeline.issue.printerNotFound`,`Target printer no longer exists.`)});case`printer_disabled`:return(0,C.jsx)(C.Fragment,{children:t(`library.runWithPipeline.issue.printerDisabled`,`Target printer is disabled.`)});case`printer_offline`:return(0,C.jsx)(C.Fragment,{children:t(`library.runWithPipeline.issue.printerOffline`,`Target printer is offline.`)});case`filament_type_mismatch`:return(0,C.jsx)(C.Fragment,{children:t(`library.runWithPipeline.issue.filamentType`,`Filament slot {{slot}}: expected {{expected}}, AMS has {{actual}}`,{slot:(e.slot_index??0)+1,expected:e.expected??`?`,actual:e.actual??`?`})});case`filament_color_mismatch`:return(0,C.jsx)(C.Fragment,{children:t(`library.runWithPipeline.issue.filamentColor`,`Filament slot {{slot}}: colour differs (expected {{expected}}, AMS has {{actual}})`,{slot:(e.slot_index??0)+1,expected:e.expected??`?`,actual:e.actual??`?`})});case`ams_slot_missing`:return(0,C.jsx)(C.Fragment,{children:t(`library.runWithPipeline.issue.amsSlotMissing`,`AMS slot {{slot}} not available on this printer`,{slot:(e.slot_index??0)+1})});case`filament_unverified`:return(0,C.jsx)(C.Fragment,{children:t(`library.runWithPipeline.issue.filamentUnverified`,`Filament slot {{slot}} comes from a cloud / standard preset and could not be statically verified.`,{slot:(e.slot_index??0)+1})});default:return(0,C.jsx)(C.Fragment,{children:e.kind})}}function O({onFiles:e,onRejected:t,extensions:n,disabled:r=!1}){let[i,a]=(0,S.useState)(!1),o=(0,S.useRef)(e),s=(0,S.useRef)(t),c=(0,S.useRef)(n);(0,S.useEffect)(()=>{o.current=e},[e]),(0,S.useEffect)(()=>{s.current=t},[t]),(0,S.useEffect)(()=>{c.current=n},[n]);let l=(0,S.useCallback)(e=>{r||(e.preventDefault(),e.dataTransfer.types.includes(`Files`)&&a(!0))},[r]),u=(0,S.useCallback)(e=>{r||(e.preventDefault(),e.dataTransfer.types.includes(`Files`)&&a(!0))},[r]),d=(0,S.useCallback)(e=>{if(r)return;e.preventDefault();let t=e.currentTarget,n=e.relatedTarget;(!n||!t.contains(n))&&a(!1)},[r]),f=(0,S.useCallback)(e=>{if(r)return;e.preventDefault(),a(!1);let t=Array.from(e.dataTransfer.files);if(t.length===0)return;let n=c.current,i=n&&n.length>0?t.filter(e=>n.some(t=>e.name.toLowerCase().endsWith(t))):t;i.length>0?o.current(i):s.current?.()},[r]);return(0,S.useEffect)(()=>{if(!i)return;let e=()=>a(!1),t=t=>{t.key===`Escape`&&e()};return document.addEventListener(`drop`,e),document.addEventListener(`dragend`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`drop`,e),document.removeEventListener(`dragend`,e),document.removeEventListener(`keydown`,t)}},[i]),{isDraggingOver:i,dragHandlers:{onDragOver:l,onDragEnter:u,onDragLeave:d,onDrop:f}}}function k(e){let{archiveName:t,photos:n,initialIndex:i,onClose:a,onDelete:o}=e,[s,c]=(0,S.useState)(()=>Math.min(Math.max(i??0,0),Math.max(n.length-1,0))),[l,u]=(0,S.useState)(!1);if((0,S.useEffect)(()=>{if(l)return;let e=e=>{e.key===`Escape`&&a(),e.key===`ArrowLeft`&&c(e=>Math.max(0,e-1)),e.key===`ArrowRight`&&c(e=>Math.min(n.length-1,e+1))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[a,n.length,l]),(0,S.useEffect)(()=>{s>=n.length&&c(Math.max(0,n.length-1))},[n.length,s]),n.length===0)return a(),null;let d=t=>e.getPhotoUrl?e.getPhotoUrl(t):r.getArchivePhotoUrl(e.archiveId,t),f=n[s],g=d(f);return(0,C.jsxs)(`div`,{className:`fixed inset-0 bg-black/90 flex items-center justify-center z-50`,onClick:e=>{e.stopPropagation(),a()},children:[(0,C.jsxs)(`div`,{className:`relative w-full h-full flex flex-col`,onClick:e=>e.stopPropagation(),children:[(0,C.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 bg-black/50`,children:[(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:t}),(0,C.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[`Photo `,s+1,` of `,n.length]})]}),(0,C.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,C.jsxs)(m,{variant:`secondary`,size:`sm`,onClick:()=>{let e=document.createElement(`a`);e.href=g,e.download=`${t}_photo_${s+1}.jpg`,e.click()},children:[(0,C.jsx)(x,{className:`w-4 h-4`}),`Download`]}),o&&(0,C.jsx)(m,{variant:`secondary`,size:`sm`,onClick:()=>{o&&u(!0)},className:`text-red-400 hover:text-red-300`,children:(0,C.jsx)(h,{className:`w-4 h-4`})}),(0,C.jsx)(`button`,{onClick:a,className:`p-2 text-bambu-gray hover:text-white transition-colors`,children:(0,C.jsx)(p,{className:`w-6 h-6`})})]})]}),(0,C.jsxs)(`div`,{className:`flex-1 min-h-0 flex items-center justify-center p-4 relative overflow-hidden`,children:[s>0&&(0,C.jsx)(`button`,{onClick:()=>c(e=>e-1),className:`absolute left-4 z-10 p-3 bg-black/50 hover:bg-black/70 rounded-full transition-colors`,children:(0,C.jsx)(y,{className:`w-8 h-8 text-white`})}),(0,C.jsx)(`img`,{src:g,alt:`Photo ${s+1}`,className:`max-w-full max-h-full object-contain rounded-lg`,style:{maxHeight:`calc(100vh - 200px)`}}),sc(e=>e+1),className:`absolute right-4 z-10 p-3 bg-black/50 hover:bg-black/70 rounded-full transition-colors`,children:(0,C.jsx)(_,{className:`w-8 h-8 text-white`})})]}),n.length>1&&(0,C.jsx)(`div`,{className:`flex justify-center gap-2 p-4 bg-black/50`,children:n.map((e,t)=>(0,C.jsx)(`button`,{onClick:()=>c(t),className:`w-16 h-16 rounded-lg overflow-hidden border-2 transition-colors ${t===s?`border-bambu-green`:`border-transparent hover:border-bambu-gray`}`,children:(0,C.jsx)(`img`,{src:d(e),alt:`Thumbnail ${t+1}`,className:`w-full h-full object-cover`})},e))})]}),l&&(0,C.jsx)(`div`,{onClick:e=>e.stopPropagation(),children:(0,C.jsx)(v,{title:`Delete Photo`,message:`Delete this photo? This cannot be undone.`,confirmText:`Delete`,variant:`danger`,onConfirm:()=>{o?.(f),u(!1)},onCancel:()=>u(!1)})})]})}export{O as n,w as r,k as t}; \ No newline at end of file +import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,w as i}from"./client-DnySrlFv.js";import{n as a}from"./QueryClientProvider-Ce8_sN3w.js";import{t as o}from"./useQuery-BBCjCezC.js";import{t as s}from"./useMutation-B-Tr2hIP.js";import{n as c}from"./ToastContext-BRX0SW3C.js";import{t as l}from"./cog-Dol1I0kq.js";import{t as u}from"./loader-circle-BEmFtawu.js";import{t as d}from"./play-DIDYtk2S.js";import{t as f}from"./triangle-alert-Dt_1FcBy.js";import{t as p}from"./x-DR-Trv6U.js";import{t as m}from"./Button-DDr6eAFy.js";import{At as h,Jt as g,Mn as _,_t as v,jn as y,t as b,wn as x}from"./index-Cxa-KVmA.js";var S=e(n(),1),C=t();function w({source:e,onClose:t}){let{t:n}=i(),l=a(),{showToast:u}=c(),[f,m]=(0,S.useState)(null),[h,g]=(0,S.useState)(null),[_,v]=(0,S.useState)(1),{trackJob:y}=b(),{data:x,isLoading:w}=o({queryKey:[`slicer-pipelines`],queryFn:()=>r.listSlicerPipelines()}),{data:D}=o({queryKey:[`printers`],queryFn:()=>r.getPrinters()}),{data:O}=o({queryKey:[`app-settings`],queryFn:()=>r.getSettings()}),k=O?.pipeline_max_copies??50,A={kind:e.kind,id:e.id},j=s({mutationFn:e=>r.checkPipelineEligibility(e,A)}),M=s({mutationFn:({pipelineId:e,force:t})=>r.runPipeline(e,A,t,_),onSuccess:r=>{l.invalidateQueries({queryKey:[`slicer-pipelines`]}),l.invalidateQueries({queryKey:[`pipeline-runs`]}),r.slice_job_id&&y(r.slice_job_id,e.kind,e.filename),u(n(`library.runWithPipeline.toast.started`,`Pipeline run started`),`success`),t()},onError:e=>{u(e.message||n(`library.runWithPipeline.toast.failed`,`Could not start run`),`error`)}}),N=x?.pipelines??[],P=(D??[]).reduce((e,t)=>(e[t.id]=t,e),{});return(0,C.jsx)(`div`,{className:`fixed inset-0 z-50 bg-black/60 flex items-center justify-center p-4`,onClick:t,role:`dialog`,"aria-modal":`true`,"aria-label":n(`library.runWithPipeline.modalTitle`,`Run with pipeline`),children:(0,C.jsxs)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-2xl w-full max-w-md max-h-[80vh] flex flex-col overflow-hidden`,onClick:e=>e.stopPropagation(),children:[(0,C.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 border-b border-bambu-dark-tertiary`,children:[(0,C.jsxs)(`h3`,{className:`text-sm font-semibold text-white flex items-center gap-2`,children:[(0,C.jsx)(d,{className:`w-4 h-4 text-bambu-green`}),f&&h?n(`library.runWithPipeline.confirmTitle`,`Confirm run`):n(`library.runWithPipeline.modalTitle`,`Run with pipeline`)]}),(0,C.jsx)(`button`,{type:`button`,onClick:t,"aria-label":n(`common.close`,`Close`),className:`text-bambu-gray hover:text-white`,children:(0,C.jsx)(p,{className:`w-4 h-4`})})]}),(0,C.jsx)(`div`,{className:`flex-1 overflow-y-auto p-4 space-y-3`,children:f&&h?(0,C.jsx)(E,{pipeline:f,report:h,source:e,onBack:()=>{m(null),g(null)},onConfirm:()=>{f&&M.mutate({pipelineId:f.id,force:!0})},running:M.isPending}):(0,C.jsx)(T,{source:e,pipelines:N,printerById:P,loading:w||j.isPending,onPick:async e=>{if(!(e.target_printer_id||e.target_kind===`printer_class`&&e.target_model_class)){u(n(`library.runWithPipeline.noTargetMessage`,`This pipeline has no target printer set. Open it in Settings to pick one.`),`error`);return}m(e);try{let t=await j.mutateAsync(e.id);g(t),t.ok&&M.mutate({pipelineId:e.id,force:!1})}catch{m(null)}},copies:_,maxCopies:k,onCopiesChange:v})})]})})}function T({source:e,pipelines:t,printerById:n,loading:r,onPick:a,copies:o,maxCopies:s,onCopiesChange:c}){let{t:d}=i();return(0,C.jsxs)(C.Fragment,{children:[(0,C.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[d(`library.runWithPipeline.sourceHint`,`Source`),`:`,` `,(0,C.jsx)(`span`,{className:`text-white`,children:e.filename})]}),(0,C.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,C.jsxs)(`label`,{className:`text-xs text-bambu-gray`,htmlFor:`run-pipeline-copies`,children:[d(`library.runWithPipeline.copies`,`Copies`),`:`]}),(0,C.jsx)(`input`,{id:`run-pipeline-copies`,type:`number`,min:1,max:s,value:o,onChange:e=>{let t=parseInt(e.target.value,10);Number.isNaN(t)||c(Math.max(1,Math.min(s,t)))},"aria-label":d(`library.runWithPipeline.copies`,`Copies`),className:`w-20 px-2 py-1 text-xs bg-bambu-dark border border-bambu-dark-tertiary rounded text-white`}),(0,C.jsx)(`span`,{className:`text-xs text-bambu-gray/60`,children:d(`library.runWithPipeline.copiesHint`,`max {{n}}`,{n:s})})]}),r&&(0,C.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-bambu-gray`,children:[(0,C.jsx)(u,{className:`w-4 h-4 animate-spin`}),d(`library.runWithPipeline.loading`,`Loading…`)]}),!r&&t.length===0&&(0,C.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:d(`library.runWithPipeline.empty`,`No pipelines saved yet. Open the Slice dialog and click "Save as pipeline" to create one.`)}),!r&&t.length>0&&(0,C.jsx)(`ul`,{className:`space-y-1.5`,"aria-label":d(`library.runWithPipeline.pipelineListAria`,`Available pipelines`),children:t.map(e=>{let t=e.target_kind===`printer_class`,r=e.target_printer_id?n[e.target_printer_id]?.name:null,i=t&&e.target_model_class?d(`library.runWithPipeline.classTarget`,`Any {{model}}`,{model:e.target_model_class}):null;return(0,C.jsx)(`li`,{children:(0,C.jsxs)(`button`,{type:`button`,onClick:()=>a(e),disabled:!(e.target_printer_id||t&&e.target_model_class),className:`w-full text-left px-3 py-2 rounded-md border border-bambu-dark-tertiary bg-bambu-dark/40 hover:bg-bambu-dark-tertiary disabled:opacity-50 disabled:cursor-not-allowed transition-colors`,children:[(0,C.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,C.jsx)(l,{className:`w-3.5 h-3.5 text-bambu-green flex-shrink-0`}),(0,C.jsx)(`span`,{className:`text-sm font-medium text-white truncate`,children:e.name})]}),(0,C.jsxs)(`div`,{className:`mt-1 text-xs text-bambu-gray flex items-center gap-1`,children:[(0,C.jsx)(g,{className:`w-3 h-3`}),i?(0,C.jsx)(`span`,{children:i}):r?(0,C.jsx)(`span`,{children:r}):(0,C.jsx)(`span`,{className:`text-amber-700 dark:text-amber-400`,children:d(`library.runWithPipeline.noTarget`,`No target printer set`)})]})]})},e.id)})})]})}function E({pipeline:e,report:t,source:n,onBack:r,onConfirm:a,running:o}){let{t:s}=i();return(0,C.jsxs)(C.Fragment,{children:[(0,C.jsxs)(`div`,{className:`text-xs text-bambu-gray`,children:[(0,C.jsxs)(`p`,{children:[s(`library.runWithPipeline.confirmIntro`,`Pre-flight found issues with this run`),`:`]}),(0,C.jsxs)(`p`,{className:`mt-1`,children:[(0,C.jsxs)(`span`,{className:`text-bambu-gray/70`,children:[s(`library.runWithPipeline.sourceHint`,`Source`),`: `]}),(0,C.jsx)(`span`,{className:`text-white`,children:n.filename})]}),(0,C.jsxs)(`p`,{children:[(0,C.jsxs)(`span`,{className:`text-bambu-gray/70`,children:[s(`library.runWithPipeline.pipelineHint`,`Pipeline`),`: `]}),(0,C.jsx)(`span`,{className:`text-white`,children:e.name})]}),t.target_printer_name&&(0,C.jsxs)(`p`,{children:[(0,C.jsxs)(`span`,{className:`text-bambu-gray/70`,children:[s(`library.runWithPipeline.targetHint`,`Target`),`: `]}),(0,C.jsx)(`span`,{className:`text-white`,children:t.target_printer_name})]})]}),(0,C.jsx)(`ul`,{className:`space-y-1.5`,children:t.issues.map((e,t)=>(0,C.jsxs)(`li`,{className:`flex items-start gap-2 text-xs`,children:[(0,C.jsx)(f,{className:`w-3.5 h-3.5 text-amber-600 dark:text-amber-400 flex-shrink-0 mt-0.5`}),(0,C.jsx)(`span`,{className:`text-bambu-gray`,children:(0,C.jsx)(D,{issue:e})})]},t))}),(0,C.jsxs)(`div`,{className:`flex items-center justify-end gap-2 pt-2 border-t border-bambu-dark-tertiary`,children:[(0,C.jsx)(`button`,{type:`button`,onClick:r,disabled:o,className:`px-3 py-1.5 text-xs text-bambu-gray hover:text-white`,children:s(`common.back`,`Back`)}),(0,C.jsxs)(`button`,{type:`button`,onClick:a,disabled:o,className:`px-3 py-1.5 text-xs bg-amber-500 hover:bg-amber-600 text-white rounded disabled:opacity-50 flex items-center gap-1`,children:[o?(0,C.jsx)(u,{className:`w-3 h-3 animate-spin`}):(0,C.jsx)(d,{className:`w-3 h-3`}),s(`library.runWithPipeline.runAnyway`,`Run anyway`)]})]})]})}function D({issue:e}){let{t}=i();switch(e.kind){case`printer_not_set`:return(0,C.jsx)(C.Fragment,{children:t(`library.runWithPipeline.issue.printerNotSet`,`No target printer set on this pipeline.`)});case`printer_not_found`:return(0,C.jsx)(C.Fragment,{children:t(`library.runWithPipeline.issue.printerNotFound`,`Target printer no longer exists.`)});case`printer_disabled`:return(0,C.jsx)(C.Fragment,{children:t(`library.runWithPipeline.issue.printerDisabled`,`Target printer is disabled.`)});case`printer_offline`:return(0,C.jsx)(C.Fragment,{children:t(`library.runWithPipeline.issue.printerOffline`,`Target printer is offline.`)});case`filament_type_mismatch`:return(0,C.jsx)(C.Fragment,{children:t(`library.runWithPipeline.issue.filamentType`,`Filament slot {{slot}}: expected {{expected}}, AMS has {{actual}}`,{slot:(e.slot_index??0)+1,expected:e.expected??`?`,actual:e.actual??`?`})});case`filament_color_mismatch`:return(0,C.jsx)(C.Fragment,{children:t(`library.runWithPipeline.issue.filamentColor`,`Filament slot {{slot}}: colour differs (expected {{expected}}, AMS has {{actual}})`,{slot:(e.slot_index??0)+1,expected:e.expected??`?`,actual:e.actual??`?`})});case`ams_slot_missing`:return(0,C.jsx)(C.Fragment,{children:t(`library.runWithPipeline.issue.amsSlotMissing`,`AMS slot {{slot}} not available on this printer`,{slot:(e.slot_index??0)+1})});case`filament_unverified`:return(0,C.jsx)(C.Fragment,{children:t(`library.runWithPipeline.issue.filamentUnverified`,`Filament slot {{slot}} comes from a cloud / standard preset and could not be statically verified.`,{slot:(e.slot_index??0)+1})});default:return(0,C.jsx)(C.Fragment,{children:e.kind})}}function O({onFiles:e,onRejected:t,extensions:n,disabled:r=!1}){let[i,a]=(0,S.useState)(!1),o=(0,S.useRef)(e),s=(0,S.useRef)(t),c=(0,S.useRef)(n);(0,S.useEffect)(()=>{o.current=e},[e]),(0,S.useEffect)(()=>{s.current=t},[t]),(0,S.useEffect)(()=>{c.current=n},[n]);let l=(0,S.useCallback)(e=>{r||(e.preventDefault(),e.dataTransfer.types.includes(`Files`)&&a(!0))},[r]),u=(0,S.useCallback)(e=>{r||(e.preventDefault(),e.dataTransfer.types.includes(`Files`)&&a(!0))},[r]),d=(0,S.useCallback)(e=>{if(r)return;e.preventDefault();let t=e.currentTarget,n=e.relatedTarget;(!n||!t.contains(n))&&a(!1)},[r]),f=(0,S.useCallback)(e=>{if(r)return;e.preventDefault(),a(!1);let t=Array.from(e.dataTransfer.files);if(t.length===0)return;let n=c.current,i=n&&n.length>0?t.filter(e=>n.some(t=>e.name.toLowerCase().endsWith(t))):t;i.length>0?o.current(i):s.current?.()},[r]);return(0,S.useEffect)(()=>{if(!i)return;let e=()=>a(!1),t=t=>{t.key===`Escape`&&e()};return document.addEventListener(`drop`,e),document.addEventListener(`dragend`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`drop`,e),document.removeEventListener(`dragend`,e),document.removeEventListener(`keydown`,t)}},[i]),{isDraggingOver:i,dragHandlers:{onDragOver:l,onDragEnter:u,onDragLeave:d,onDrop:f}}}function k(e){let{archiveName:t,photos:n,initialIndex:i,onClose:a,onDelete:o}=e,[s,c]=(0,S.useState)(()=>Math.min(Math.max(i??0,0),Math.max(n.length-1,0))),[l,u]=(0,S.useState)(!1);if((0,S.useEffect)(()=>{if(l)return;let e=e=>{e.key===`Escape`&&a(),e.key===`ArrowLeft`&&c(e=>Math.max(0,e-1)),e.key===`ArrowRight`&&c(e=>Math.min(n.length-1,e+1))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[a,n.length,l]),(0,S.useEffect)(()=>{s>=n.length&&c(Math.max(0,n.length-1))},[n.length,s]),n.length===0)return a(),null;let d=t=>e.getPhotoUrl?e.getPhotoUrl(t):r.getArchivePhotoUrl(e.archiveId,t),f=n[s],g=d(f);return(0,C.jsxs)(`div`,{className:`fixed inset-0 bg-black/90 flex items-center justify-center z-50`,onClick:e=>{e.stopPropagation(),a()},children:[(0,C.jsxs)(`div`,{className:`relative w-full h-full flex flex-col`,onClick:e=>e.stopPropagation(),children:[(0,C.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 bg-black/50`,children:[(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:t}),(0,C.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[`Photo `,s+1,` of `,n.length]})]}),(0,C.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,C.jsxs)(m,{variant:`secondary`,size:`sm`,onClick:()=>{let e=document.createElement(`a`);e.href=g,e.download=`${t}_photo_${s+1}.jpg`,e.click()},children:[(0,C.jsx)(x,{className:`w-4 h-4`}),`Download`]}),o&&(0,C.jsx)(m,{variant:`secondary`,size:`sm`,onClick:()=>{o&&u(!0)},className:`text-red-400 hover:text-red-300`,children:(0,C.jsx)(h,{className:`w-4 h-4`})}),(0,C.jsx)(`button`,{onClick:a,className:`p-2 text-bambu-gray hover:text-white transition-colors`,children:(0,C.jsx)(p,{className:`w-6 h-6`})})]})]}),(0,C.jsxs)(`div`,{className:`flex-1 min-h-0 flex items-center justify-center p-4 relative overflow-hidden`,children:[s>0&&(0,C.jsx)(`button`,{onClick:()=>c(e=>e-1),className:`absolute left-4 z-10 p-3 bg-black/50 hover:bg-black/70 rounded-full transition-colors`,children:(0,C.jsx)(y,{className:`w-8 h-8 text-white`})}),(0,C.jsx)(`img`,{src:g,alt:`Photo ${s+1}`,className:`max-w-full max-h-full object-contain rounded-lg`,style:{maxHeight:`calc(100vh - 200px)`}}),sc(e=>e+1),className:`absolute right-4 z-10 p-3 bg-black/50 hover:bg-black/70 rounded-full transition-colors`,children:(0,C.jsx)(_,{className:`w-8 h-8 text-white`})})]}),n.length>1&&(0,C.jsx)(`div`,{className:`flex justify-center gap-2 p-4 bg-black/50`,children:n.map((e,t)=>(0,C.jsx)(`button`,{onClick:()=>c(t),className:`w-16 h-16 rounded-lg overflow-hidden border-2 transition-colors ${t===s?`border-bambu-green`:`border-transparent hover:border-bambu-gray`}`,children:(0,C.jsx)(`img`,{src:d(e),alt:`Thumbnail ${t+1}`,className:`w-full h-full object-cover`})},e))})]}),l&&(0,C.jsx)(`div`,{onClick:e=>e.stopPropagation(),children:(0,C.jsx)(v,{title:`Delete Photo`,message:`Delete this photo? This cannot be undone.`,confirmText:`Delete`,variant:`danger`,onConfirm:()=>{o?.(f),u(!1)},onCancel:()=>u(!1)})})]})}export{O as n,w as r,k as t}; \ No newline at end of file diff --git a/static/assets/PrinterLocationsPage-BmifXYE1.js b/static/assets/PrinterLocationsPage-Dj61FxW8.js similarity index 99% rename from static/assets/PrinterLocationsPage-BmifXYE1.js rename to static/assets/PrinterLocationsPage-Dj61FxW8.js index 92588fcef..9563e5e8d 100644 --- a/static/assets/PrinterLocationsPage-BmifXYE1.js +++ b/static/assets/PrinterLocationsPage-Dj61FxW8.js @@ -1 +1 @@ -import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,w as i}from"./client-DnySrlFv.js";import{n as a}from"./QueryClientProvider-Ce8_sN3w.js";import{t as o}from"./useQuery-BBCjCezC.js";import{t as s}from"./useMutation-B-Tr2hIP.js";import{t as c}from"./useQueries-Be6PMvSC.js";import{t as l}from"./createLucideIcon-DvBYJlWL.js";import{t as u}from"./arrow-left-0Q6F2rjC.js";import{t as d}from"./box-DAdKb9s5.js";import{a as f}from"./info-ROUoQhJR.js";import{n as p}from"./ToastContext-BRX0SW3C.js";import{t as m}from"./loader-circle-BEmFtawu.js";import{t as ee}from"./move-Bc1EIjTD.js";import{t as te}from"./search-0n0CBc74.js";import{t as h}from"./x-DR-Trv6U.js";import{n as g,t as _}from"./Card-Bzc64K35.js";import{t as v}from"./Button-DDr6eAFy.js";import{$t as ne,At as re,Lt as y,Rn as ie,Rt as b,Zt as ae,_t as oe,ht as x,mt as se,yt as ce}from"./index-0t--Yqoi.js";var S=l(`user-minus`,[[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}],[`line`,{x1:`22`,x2:`16`,y1:`11`,y2:`11`,key:`1shjgl`}]]),C=e(n(),1),w=t(),le=100,T=[`#ef4444`,`#f97316`,`#eab308`,`#22c55e`,`#14b8a6`,`#3b82f6`,`#8b5cf6`,`#ec4899`,`#6b7280`],ue=[`name-asc`,`name-desc`,`count-asc`,`count-desc`],de=`printerLocations.hideEmpty`,fe=`printerLocations.sort`;function pe(e,t,n){try{let r=localStorage.getItem(e);return t.includes(r)?r:n}catch{return n}}function me(e,t){try{localStorage.setItem(e,t)}catch{}}var he=e=>e.location?.trim()||``;function ge({location:e}){return(0,w.jsxs)(`div`,{className:`p-2 rounded-lg bg-bambu-dark relative overflow-hidden flex-shrink-0`,children:[(0,w.jsx)(se.find(t=>t.name===e.icon)?.icon??d,{className:`w-[25px] h-[25px] text-bambu-gray`}),e.color&&(0,w.jsx)(`div`,{className:`absolute top-0 left-0 w-1 h-full`,style:{backgroundColor:e.color}})]})}function _e({printer:e,status:t,selected:n,canEdit:r,busy:a,onToggle:o,onMove:s,onRemove:c}){let{t:l}=i(),u=t?.state,d=t?.connected,f=l(d?u===`RUNNING`?`printers.status.printing`:u===`PAUSE`?`printers.status.paused`:u===`FINISH`?`printers.status.finished`:`printers.status.idle`:`printers.status.offline`),p=d?u===`RUNNING`?`bg-orange-500/20 text-orange-400`:u===`PAUSE`?`bg-yellow-500/20 text-yellow-400`:u===`FINISH`?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark text-bambu-gray`:`bg-gray-500/20 text-gray-400`;return(0,w.jsxs)(`div`,{className:`flex items-center justify-between gap-2 py-2 px-3 rounded-lg transition-colors ${n?`bg-bambu-green/10 border border-bambu-green/30`:`bg-bambu-dark-secondary hover:bg-bambu-dark`}`,children:[(0,w.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0`,children:[r&&(0,w.jsx)(`button`,{type:`button`,onClick:o,className:`text-bambu-gray hover:text-bambu-green transition-colors`,title:l(`printers.locations.selectPrinter`),"aria-label":l(`printers.locations.selectPrinter`),"aria-pressed":n,children:n?(0,w.jsx)(b,{className:`w-4 h-4 text-bambu-green`}):(0,w.jsx)(y,{className:`w-4 h-4`})}),(0,w.jsx)(`div`,{className:`w-2.5 h-2.5 rounded-full flex-shrink-0 ${d?u===`RUNNING`||u===`PAUSE`?`bg-orange-500`:`bg-bambu-green`:`bg-gray-500`}`}),(0,w.jsxs)(`div`,{className:`min-w-0`,children:[(0,w.jsx)(`p`,{className:`text-white text-sm font-medium truncate`,children:e.name}),(0,w.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:e.model||l(`printers.status.unknown`)})]})]}),(0,w.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[(0,w.jsx)(`span`,{className:`text-xs px-2 py-1 rounded-full ${p}`,children:f}),r&&(0,w.jsx)(v,{variant:`ghost`,size:`sm`,onClick:s,disabled:a,className:`text-bambu-gray hover:text-bambu-green hover:bg-bambu-green/10`,title:l(`printers.locations.move`),"aria-label":l(`printers.locations.move`),children:(0,w.jsx)(ee,{className:`w-3.5 h-3.5`})}),r&&c&&(0,w.jsx)(v,{variant:`ghost`,size:`sm`,onClick:c,disabled:a,className:`text-bambu-gray hover:text-red-400 hover:bg-red-500/10`,title:l(`printers.locations.removeFromLocation`),"aria-label":l(`printers.locations.removeFromLocation`),children:(0,w.jsx)(S,{className:`w-3.5 h-3.5`})})]})]})}function ve({initial:e,saving:t,onSave:n,onCancel:r}){let{t:a}=i(),[o,s]=(0,C.useState)(e?.name??``),[c,l]=(0,C.useState)(e?.icon??``),[u,d]=(0,C.useState)(e?.color??``),f=o.trim().length>0&&!t,p=()=>f&&n({name:o.trim(),icon:c,color:u});return(0,w.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,children:(0,w.jsx)(_,{className:`w-full max-w-md`,children:(0,w.jsxs)(g,{className:`space-y-4`,children:[(0,w.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:a(e?`printers.locations.editTitle`:`printers.locations.createTitle`)}),(0,w.jsx)(`input`,{type:`text`,value:o,maxLength:le,onChange:e=>s(e.target.value),placeholder:a(`printers.locations.namePlaceholder`),"aria-label":a(`printers.locations.namePlaceholder`),className:`w-full px-4 py-2 text-sm bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,autoFocus:!0,onKeyDown:e=>{e.key===`Enter`&&p(),e.key===`Escape`&&r()}}),(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`p`,{className:`text-sm text-bambu-gray mb-2`,children:a(`printers.locations.icon`)}),(0,w.jsx)(x,{value:c,onChange:l})]}),(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`p`,{className:`text-sm text-bambu-gray mb-2`,children:a(`printers.locations.color`)}),(0,w.jsxs)(`div`,{className:`flex gap-2 flex-wrap`,children:[T.map(e=>(0,w.jsx)(`button`,{type:`button`,onClick:()=>d(u===e?``:e),className:`w-8 h-8 rounded-lg transition-all ${u===e?`ring-2 ring-white ring-offset-2 ring-offset-bambu-dark-secondary scale-110`:`hover:scale-105`}`,style:{backgroundColor:e},title:e,"aria-label":e,"aria-pressed":u===e},e)),u&&(0,w.jsx)(`button`,{type:`button`,onClick:()=>d(``),className:`w-8 h-8 rounded-lg border-2 border-bambu-dark-tertiary bg-bambu-dark-secondary text-bambu-gray hover:text-white hover:border-bambu-gray transition-all flex items-center justify-center`,title:a(`printers.locations.noColor`),"aria-label":a(`printers.locations.noColor`),children:(0,w.jsx)(h,{className:`w-3.5 h-3.5`})})]})]}),(0,w.jsxs)(`div`,{className:`flex gap-2 justify-end`,children:[(0,w.jsx)(v,{variant:`secondary`,onClick:r,disabled:t,children:a(`common.cancel`)}),(0,w.jsx)(v,{onClick:p,disabled:!f,children:t?(0,w.jsx)(m,{className:`w-4 h-4 animate-spin`}):a(e?`common.save`:`printers.locations.create`)})]})]})})})}var E=`__none__`;function ye({count:e,printerName:t,locations:n,saving:r,onMove:a,onCancel:o}){let{t:s}=i(),[c,l]=(0,C.useState)(``);return(0,w.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,children:(0,w.jsx)(_,{className:`w-full max-w-md`,children:(0,w.jsxs)(g,{className:`space-y-4`,children:[(0,w.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e===1?s(`printers.locations.moveTitle`):s(`printers.locations.moveTitleMany`,{count:e})}),t&&(0,w.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:t}),(0,w.jsxs)(`select`,{value:c,onChange:e=>l(e.target.value),"aria-label":s(`printers.locations.targetPlaceholder`),className:`w-full px-4 py-2 text-sm bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,disabled:r,autoFocus:!0,children:[(0,w.jsx)(`option`,{value:``,disabled:!0,children:s(`printers.locations.targetPlaceholder`)}),n.map(e=>(0,w.jsx)(`option`,{value:e.name,children:e.name},e.name)),(0,w.jsx)(`option`,{value:E,children:s(`printers.locations.noLocation`)})]}),(0,w.jsxs)(`div`,{className:`flex gap-2 justify-end`,children:[(0,w.jsx)(v,{variant:`secondary`,onClick:o,disabled:r,children:s(`common.cancel`)}),(0,w.jsx)(v,{onClick:()=>a(c===E?null:c),disabled:r||!c,children:r?(0,w.jsx)(m,{className:`w-4 h-4 animate-spin`}):s(`printers.locations.moveButton`)})]})]})})})}function D(){let e=a(),{t}=i(),{showToast:n}=p(),{hasPermission:l}=ce(),h=l(`printers:update`),[x,se]=(0,C.useState)(``),[S,le]=(0,C.useState)(()=>pe(de,[`true`,`false`],`false`)===`true`),[T,E]=(0,C.useState)(()=>pe(fe,ue,`name-asc`)),[D,O]=(0,C.useState)(!1),[k,A]=(0,C.useState)(null),[j,M]=(0,C.useState)(!1),[N,P]=(0,C.useState)(new Set),[F,I]=(0,C.useState)(new Set),[L,R]=(0,C.useState)(null),[z,B]=(0,C.useState)(null),[V,H]=(0,C.useState)(null);(0,C.useEffect)(()=>me(de,String(S)),[S]),(0,C.useEffect)(()=>me(fe,T),[T]),(0,C.useEffect)(()=>{j&&A(null)},[j]);let{data:U,isLoading:be}=o({queryKey:[`printers`],queryFn:r.getPrinters}),{data:W,isLoading:xe}=o({queryKey:[`printer-locations`],queryFn:r.getPrinterLocations}),Se=c({queries:(U??[]).map(e=>({queryKey:[`printerStatus`,e.id],queryFn:()=>r.getPrinterStatus(e.id),refetchInterval:3e4}))}),Ce=new Map((U??[]).map((e,t)=>[e.id,Se[t]?.data])),G=(0,C.useMemo)(()=>{let e=new Map;for(let t of U??[]){let n=he(t);e.set(n,[...e.get(n)??[],t])}return e},[U]),K=G.get(``)??[],we=(U?.length??0)-K.length,Te=(0,C.useMemo)(()=>{let e=x.trim().toLowerCase(),t=(W??[]).filter(t=>(!e||t.name.toLowerCase().includes(e))&&(!S||t.printer_count>0)),n=(e,t)=>e.name.localeCompare(t.name,void 0,{numeric:!0,sensitivity:`base`});return[...t].sort((e,t)=>{switch(T){case`name-desc`:return n(t,e);case`count-asc`:return e.printer_count-t.printer_count||n(e,t);case`count-desc`:return t.printer_count-e.printer_count||n(e,t);default:return n(e,t)}})},[W,x,S,T]),q=()=>{e.invalidateQueries({queryKey:[`printer-locations`]}),e.invalidateQueries({queryKey:[`printers`]})},J=e=>n(t(`printers.locations.failed`,{error:e instanceof Error?e.message:String(e)}),`error`),Y=s({mutationFn:({value:e,location:t})=>t?r.updatePrinterLocation({name:t.name,...e.name===t.name?{}:{new_name:e.name},icon:e.icon||null,color:e.color||null}):r.createPrinterLocation({name:e.name,icon:e.icon||null,color:e.color||null}),onSuccess:(e,{location:r})=>{q(),r&&k===r.name&&A(e.name),n(t(r?`printers.locations.saved`:`printers.locations.created`)),R(null)},onError:J}),X=s({mutationFn:({ids:e,location:t})=>r.assignPrinterLocation(e,t),onSuccess:({moved:e})=>{q(),n(t(`printers.locations.moved`,{count:e})),I(new Set),B(null)},onError:J}),Z=s({mutationFn:e=>r.deletePrinterLocations(e),onSuccess:({deleted:e})=>{q(),n(t(`printers.locations.deleted`,{count:e})),P(new Set),M(!1),H(null)},onError:e=>{J(e),H(null)}}),Q=X.isPending||Z.isPending||Y.isPending,Ee=(e,t)=>{let n=new Set(e);return n.has(t)?n.delete(t):n.add(t),n};if(be||xe)return(0,w.jsx)(`div`,{className:`flex items-center justify-center h-64`,children:(0,w.jsx)(m,{className:`w-8 h-8 text-bambu-green animate-spin`})});let De=(V??[]).reduce((e,t)=>e+(W?.find(e=>e.name===t)?.printer_count??0),0),Oe=e=>({"name-asc":t(`printers.locations.sortNameAsc`),"name-desc":t(`printers.locations.sortNameDesc`),"count-asc":t(`printers.locations.sortCountAsc`),"count-desc":t(`printers.locations.sortCountDesc`)})[e],ke=(e,t)=>(0,w.jsx)(_e,{printer:e,status:Ce.get(e.id),selected:F.has(e.id),canEdit:h&&!j,busy:Q,onToggle:()=>I(Ee(F,e.id)),onMove:()=>B({ids:[e.id],printerName:e.name}),onRemove:t?()=>X.mutate({ids:[e.id],location:null}):void 0},e.id),$=K.length>0&&K.every(e=>F.has(e.id));return(0,w.jsxs)(`div`,{className:`p-4 md:p-8 pb-28`,children:[(0,w.jsxs)(ie,{to:`/`,className:`inline-flex items-center gap-1 mb-3 text-sm text-bambu-gray hover:text-white transition-colors`,children:[(0,w.jsx)(u,{className:`w-4 h-4`}),` `,t(`printers.locations.backToPrinters`)]}),(0,w.jsxs)(`div`,{className:`mb-4`,children:[(0,w.jsxs)(`div`,{className:`flex items-center gap-3 mb-1`,children:[(0,w.jsx)(d,{className:`w-[25px] h-[25px] text-bambu-green`}),(0,w.jsx)(`h1`,{className:`text-2xl font-bold text-white`,children:t(`printers.locations.title`)})]}),(0,w.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:t(`printers.locations.subtitle`,{grouped:we,ungrouped:K.length})})]}),(0,w.jsxs)(`div`,{className:`flex flex-wrap gap-3 mb-6`,children:[(0,w.jsxs)(`div`,{className:`relative flex-1 min-w-[12rem]`,children:[(0,w.jsx)(te,{className:`w-4 h-4 absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray`}),(0,w.jsx)(`input`,{type:`text`,value:x,onChange:e=>se(e.target.value),placeholder:t(`printers.locations.search`),"aria-label":t(`printers.locations.search`),className:`w-full pl-9 pr-4 py-2 text-sm bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`})]}),(0,w.jsx)(v,{onClick:()=>le(!S),variant:S?`primary`:`secondary`,children:t(S?`printers.locations.showEmpty`:`printers.locations.hideEmpty`)}),h&&(0,w.jsxs)(v,{onClick:()=>{P(new Set),M(!j)},variant:j?`primary`:`secondary`,children:[(0,w.jsx)(b,{className:`w-4 h-4 mr-1`}),t(j?`printers.locations.done`:`printers.locations.select`)]}),(0,w.jsxs)(`div`,{className:`relative`,children:[(0,w.jsxs)(v,{onClick:()=>O(!D),variant:`secondary`,"aria-haspopup":`menu`,children:[(0,w.jsx)(f,{className:`w-4 h-4 mr-1 transition-transform ${D?`rotate-180`:``}`}),Oe(T)]}),D&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`div`,{className:`fixed inset-0 z-40`,onClick:()=>O(!1)}),(0,w.jsx)(`div`,{role:`menu`,className:`absolute right-0 top-full mt-1 z-50 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg p-1 min-w-[10rem]`,children:ue.map(e=>(0,w.jsx)(`button`,{role:`menuitem`,onClick:()=>{E(e),O(!1)},className:`w-full text-left px-3 py-2 text-sm rounded transition-colors ${T===e?`bg-bambu-green text-white`:`text-bambu-gray hover:bg-bambu-dark-tertiary hover:text-white`}`,children:Oe(e)},e))})]})]}),h&&(0,w.jsxs)(v,{onClick:()=>R({mode:`create`}),children:[(0,w.jsx)(ae,{className:`w-4 h-4 mr-1`}),t(`printers.locations.create`)]})]}),Te.length===0&&K.length===0?(0,w.jsx)(_,{children:(0,w.jsx)(g,{className:`text-center py-12 text-bambu-gray`,children:t(x?`printers.locations.noResults`:`printers.locations.none`)})}):(0,w.jsxs)(`div`,{className:`space-y-3`,children:[Te.map(e=>{let n=k===e.name,r=N.has(e.name);return(0,w.jsx)(_,{children:(0,w.jsxs)(g,{className:`p-4`,children:[(0,w.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,w.jsxs)(`button`,{type:`button`,onClick:()=>j?P(Ee(N,e.name)):A(n?null:e.name),className:`flex items-center gap-3 flex-1 min-w-0 text-left`,"aria-expanded":j?void 0:n,"aria-pressed":j?r:void 0,children:[j?r?(0,w.jsx)(b,{className:`w-4 h-4 text-bambu-green flex-shrink-0`}):(0,w.jsx)(y,{className:`w-4 h-4 text-bambu-gray flex-shrink-0`}):(0,w.jsx)(f,{className:`w-4 h-4 text-bambu-gray flex-shrink-0 transition-transform ${n?`rotate-180`:``}`}),(0,w.jsx)(ge,{location:e}),(0,w.jsxs)(`div`,{className:`min-w-0`,children:[(0,w.jsx)(`p`,{className:`text-white font-medium truncate`,children:e.name}),(0,w.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:t(`printers.locations.printerCount`,{count:e.printer_count})})]})]}),h&&!j&&(0,w.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,w.jsx)(v,{variant:`ghost`,size:`sm`,onClick:()=>R({mode:`edit`,location:e}),disabled:Q,className:`text-bambu-gray hover:text-blue-400 hover:bg-blue-500/10`,title:t(`common.edit`),"aria-label":t(`common.edit`),children:(0,w.jsx)(ne,{className:`w-4 h-4`})}),(0,w.jsx)(v,{variant:`ghost`,size:`sm`,onClick:()=>H([e.name]),disabled:Q,className:`text-red-500 hover:text-red-400 hover:bg-red-500/10`,title:t(`common.delete`),"aria-label":t(`common.delete`),children:(0,w.jsx)(re,{className:`w-4 h-4`})})]})]}),n&&(0,w.jsx)(`div`,{className:`border-t border-bambu-dark-tertiary pt-3 mt-3 space-y-2`,children:(G.get(e.name)??[]).length===0?(0,w.jsx)(`p`,{className:`text-sm text-bambu-gray text-center py-4`,children:t(`printers.locations.noPrinters`)}):(G.get(e.name)??[]).map(e=>ke(e,!0))})]})},e.name)}),K.length>0&&(0,w.jsxs)(`div`,{className:`pt-4 border-t border-bambu-dark-tertiary`,children:[(0,w.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,w.jsx)(`h3`,{className:`text-sm font-medium text-bambu-gray`,children:t(`printers.locations.ungroupedPrinters`,{count:K.length})}),h&&!j&&(0,w.jsx)(`button`,{type:`button`,onClick:()=>{let e=new Set(F);K.forEach(t=>$?e.delete(t.id):e.add(t.id)),I(e)},className:`text-xs text-bambu-green hover:text-bambu-green-light transition-colors`,children:t($?`common.deselectAll`:`common.selectAll`)})]}),(0,w.jsx)(`div`,{className:`space-y-2`,children:K.map(e=>ke(e,!1))})]})]}),h&&!j&&F.size>0&&(0,w.jsxs)(`div`,{className:`fixed bottom-6 left-1/2 -translate-x-1/2 bg-bambu-dark border border-bambu-dark-tertiary rounded-xl shadow-2xl px-6 py-4 flex items-center gap-4 z-40`,children:[(0,w.jsx)(`span`,{className:`text-white text-sm`,children:t(`printers.locations.selected`,{count:F.size})}),(0,w.jsxs)(v,{onClick:()=>B({ids:Array.from(F)}),disabled:Q,children:[(0,w.jsx)(ee,{className:`w-4 h-4 mr-1`}),t(`printers.locations.moveButton`)]}),(0,w.jsx)(v,{variant:`ghost`,onClick:()=>I(new Set),disabled:Q,children:t(`common.cancel`)})]}),j&&N.size>0&&(0,w.jsxs)(`div`,{className:`fixed bottom-6 left-1/2 -translate-x-1/2 bg-bambu-dark border border-bambu-dark-tertiary rounded-xl shadow-2xl px-6 py-4 flex items-center gap-4 z-40`,children:[(0,w.jsx)(`span`,{className:`text-white text-sm`,children:t(`printers.locations.selected`,{count:N.size})}),(0,w.jsxs)(v,{variant:`danger`,onClick:()=>H(Array.from(N)),disabled:Q,children:[(0,w.jsx)(re,{className:`w-4 h-4 mr-1`}),t(`printers.locations.deleteSelected`)]}),(0,w.jsx)(v,{variant:`ghost`,onClick:()=>P(new Set),disabled:Q,children:t(`common.cancel`)})]}),L&&(0,w.jsx)(ve,{initial:L.mode===`edit`?L.location:void 0,saving:Y.isPending,onSave:e=>Y.mutate({value:e,location:L.mode===`edit`?L.location:void 0}),onCancel:()=>R(null)}),z&&(0,w.jsx)(ye,{count:z.ids.length,printerName:z.printerName,locations:W??[],saving:X.isPending,onMove:e=>X.mutate({ids:z.ids,location:e}),onCancel:()=>B(null)}),V&&(0,w.jsx)(oe,{title:V.length===1?t(`printers.locations.deleteTitle`):t(`printers.locations.deleteTitleMany`,{count:V.length}),message:t(`printers.locations.deleteMessage`,{count:De,names:V.join(`, `)}),confirmText:t(`common.delete`),variant:`danger`,isLoading:Z.isPending,onConfirm:()=>Z.mutate(V),onCancel:()=>H(null)})]})}export{D as PrinterLocationsPage}; \ No newline at end of file +import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,w as i}from"./client-DnySrlFv.js";import{n as a}from"./QueryClientProvider-Ce8_sN3w.js";import{t as o}from"./useQuery-BBCjCezC.js";import{t as s}from"./useMutation-B-Tr2hIP.js";import{t as c}from"./useQueries-Be6PMvSC.js";import{t as l}from"./createLucideIcon-DvBYJlWL.js";import{t as u}from"./arrow-left-0Q6F2rjC.js";import{t as d}from"./box-DAdKb9s5.js";import{a as f}from"./info-ROUoQhJR.js";import{n as p}from"./ToastContext-BRX0SW3C.js";import{t as m}from"./loader-circle-BEmFtawu.js";import{t as ee}from"./move-Bc1EIjTD.js";import{t as te}from"./search-0n0CBc74.js";import{t as h}from"./x-DR-Trv6U.js";import{n as g,t as _}from"./Card-Bzc64K35.js";import{t as v}from"./Button-DDr6eAFy.js";import{$t as ne,At as re,Lt as y,Rn as ie,Rt as b,Zt as ae,_t as oe,ht as x,mt as se,yt as ce}from"./index-Cxa-KVmA.js";var S=l(`user-minus`,[[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}],[`line`,{x1:`22`,x2:`16`,y1:`11`,y2:`11`,key:`1shjgl`}]]),C=e(n(),1),w=t(),le=100,T=[`#ef4444`,`#f97316`,`#eab308`,`#22c55e`,`#14b8a6`,`#3b82f6`,`#8b5cf6`,`#ec4899`,`#6b7280`],ue=[`name-asc`,`name-desc`,`count-asc`,`count-desc`],de=`printerLocations.hideEmpty`,fe=`printerLocations.sort`;function pe(e,t,n){try{let r=localStorage.getItem(e);return t.includes(r)?r:n}catch{return n}}function me(e,t){try{localStorage.setItem(e,t)}catch{}}var he=e=>e.location?.trim()||``;function ge({location:e}){return(0,w.jsxs)(`div`,{className:`p-2 rounded-lg bg-bambu-dark relative overflow-hidden flex-shrink-0`,children:[(0,w.jsx)(se.find(t=>t.name===e.icon)?.icon??d,{className:`w-[25px] h-[25px] text-bambu-gray`}),e.color&&(0,w.jsx)(`div`,{className:`absolute top-0 left-0 w-1 h-full`,style:{backgroundColor:e.color}})]})}function _e({printer:e,status:t,selected:n,canEdit:r,busy:a,onToggle:o,onMove:s,onRemove:c}){let{t:l}=i(),u=t?.state,d=t?.connected,f=l(d?u===`RUNNING`?`printers.status.printing`:u===`PAUSE`?`printers.status.paused`:u===`FINISH`?`printers.status.finished`:`printers.status.idle`:`printers.status.offline`),p=d?u===`RUNNING`?`bg-orange-500/20 text-orange-400`:u===`PAUSE`?`bg-yellow-500/20 text-yellow-400`:u===`FINISH`?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark text-bambu-gray`:`bg-gray-500/20 text-gray-400`;return(0,w.jsxs)(`div`,{className:`flex items-center justify-between gap-2 py-2 px-3 rounded-lg transition-colors ${n?`bg-bambu-green/10 border border-bambu-green/30`:`bg-bambu-dark-secondary hover:bg-bambu-dark`}`,children:[(0,w.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0`,children:[r&&(0,w.jsx)(`button`,{type:`button`,onClick:o,className:`text-bambu-gray hover:text-bambu-green transition-colors`,title:l(`printers.locations.selectPrinter`),"aria-label":l(`printers.locations.selectPrinter`),"aria-pressed":n,children:n?(0,w.jsx)(b,{className:`w-4 h-4 text-bambu-green`}):(0,w.jsx)(y,{className:`w-4 h-4`})}),(0,w.jsx)(`div`,{className:`w-2.5 h-2.5 rounded-full flex-shrink-0 ${d?u===`RUNNING`||u===`PAUSE`?`bg-orange-500`:`bg-bambu-green`:`bg-gray-500`}`}),(0,w.jsxs)(`div`,{className:`min-w-0`,children:[(0,w.jsx)(`p`,{className:`text-white text-sm font-medium truncate`,children:e.name}),(0,w.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:e.model||l(`printers.status.unknown`)})]})]}),(0,w.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[(0,w.jsx)(`span`,{className:`text-xs px-2 py-1 rounded-full ${p}`,children:f}),r&&(0,w.jsx)(v,{variant:`ghost`,size:`sm`,onClick:s,disabled:a,className:`text-bambu-gray hover:text-bambu-green hover:bg-bambu-green/10`,title:l(`printers.locations.move`),"aria-label":l(`printers.locations.move`),children:(0,w.jsx)(ee,{className:`w-3.5 h-3.5`})}),r&&c&&(0,w.jsx)(v,{variant:`ghost`,size:`sm`,onClick:c,disabled:a,className:`text-bambu-gray hover:text-red-400 hover:bg-red-500/10`,title:l(`printers.locations.removeFromLocation`),"aria-label":l(`printers.locations.removeFromLocation`),children:(0,w.jsx)(S,{className:`w-3.5 h-3.5`})})]})]})}function ve({initial:e,saving:t,onSave:n,onCancel:r}){let{t:a}=i(),[o,s]=(0,C.useState)(e?.name??``),[c,l]=(0,C.useState)(e?.icon??``),[u,d]=(0,C.useState)(e?.color??``),f=o.trim().length>0&&!t,p=()=>f&&n({name:o.trim(),icon:c,color:u});return(0,w.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,children:(0,w.jsx)(_,{className:`w-full max-w-md`,children:(0,w.jsxs)(g,{className:`space-y-4`,children:[(0,w.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:a(e?`printers.locations.editTitle`:`printers.locations.createTitle`)}),(0,w.jsx)(`input`,{type:`text`,value:o,maxLength:le,onChange:e=>s(e.target.value),placeholder:a(`printers.locations.namePlaceholder`),"aria-label":a(`printers.locations.namePlaceholder`),className:`w-full px-4 py-2 text-sm bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,autoFocus:!0,onKeyDown:e=>{e.key===`Enter`&&p(),e.key===`Escape`&&r()}}),(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`p`,{className:`text-sm text-bambu-gray mb-2`,children:a(`printers.locations.icon`)}),(0,w.jsx)(x,{value:c,onChange:l})]}),(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`p`,{className:`text-sm text-bambu-gray mb-2`,children:a(`printers.locations.color`)}),(0,w.jsxs)(`div`,{className:`flex gap-2 flex-wrap`,children:[T.map(e=>(0,w.jsx)(`button`,{type:`button`,onClick:()=>d(u===e?``:e),className:`w-8 h-8 rounded-lg transition-all ${u===e?`ring-2 ring-white ring-offset-2 ring-offset-bambu-dark-secondary scale-110`:`hover:scale-105`}`,style:{backgroundColor:e},title:e,"aria-label":e,"aria-pressed":u===e},e)),u&&(0,w.jsx)(`button`,{type:`button`,onClick:()=>d(``),className:`w-8 h-8 rounded-lg border-2 border-bambu-dark-tertiary bg-bambu-dark-secondary text-bambu-gray hover:text-white hover:border-bambu-gray transition-all flex items-center justify-center`,title:a(`printers.locations.noColor`),"aria-label":a(`printers.locations.noColor`),children:(0,w.jsx)(h,{className:`w-3.5 h-3.5`})})]})]}),(0,w.jsxs)(`div`,{className:`flex gap-2 justify-end`,children:[(0,w.jsx)(v,{variant:`secondary`,onClick:r,disabled:t,children:a(`common.cancel`)}),(0,w.jsx)(v,{onClick:p,disabled:!f,children:t?(0,w.jsx)(m,{className:`w-4 h-4 animate-spin`}):a(e?`common.save`:`printers.locations.create`)})]})]})})})}var E=`__none__`;function ye({count:e,printerName:t,locations:n,saving:r,onMove:a,onCancel:o}){let{t:s}=i(),[c,l]=(0,C.useState)(``);return(0,w.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,children:(0,w.jsx)(_,{className:`w-full max-w-md`,children:(0,w.jsxs)(g,{className:`space-y-4`,children:[(0,w.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e===1?s(`printers.locations.moveTitle`):s(`printers.locations.moveTitleMany`,{count:e})}),t&&(0,w.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:t}),(0,w.jsxs)(`select`,{value:c,onChange:e=>l(e.target.value),"aria-label":s(`printers.locations.targetPlaceholder`),className:`w-full px-4 py-2 text-sm bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,disabled:r,autoFocus:!0,children:[(0,w.jsx)(`option`,{value:``,disabled:!0,children:s(`printers.locations.targetPlaceholder`)}),n.map(e=>(0,w.jsx)(`option`,{value:e.name,children:e.name},e.name)),(0,w.jsx)(`option`,{value:E,children:s(`printers.locations.noLocation`)})]}),(0,w.jsxs)(`div`,{className:`flex gap-2 justify-end`,children:[(0,w.jsx)(v,{variant:`secondary`,onClick:o,disabled:r,children:s(`common.cancel`)}),(0,w.jsx)(v,{onClick:()=>a(c===E?null:c),disabled:r||!c,children:r?(0,w.jsx)(m,{className:`w-4 h-4 animate-spin`}):s(`printers.locations.moveButton`)})]})]})})})}function D(){let e=a(),{t}=i(),{showToast:n}=p(),{hasPermission:l}=ce(),h=l(`printers:update`),[x,se]=(0,C.useState)(``),[S,le]=(0,C.useState)(()=>pe(de,[`true`,`false`],`false`)===`true`),[T,E]=(0,C.useState)(()=>pe(fe,ue,`name-asc`)),[D,O]=(0,C.useState)(!1),[k,A]=(0,C.useState)(null),[j,M]=(0,C.useState)(!1),[N,P]=(0,C.useState)(new Set),[F,I]=(0,C.useState)(new Set),[L,R]=(0,C.useState)(null),[z,B]=(0,C.useState)(null),[V,H]=(0,C.useState)(null);(0,C.useEffect)(()=>me(de,String(S)),[S]),(0,C.useEffect)(()=>me(fe,T),[T]),(0,C.useEffect)(()=>{j&&A(null)},[j]);let{data:U,isLoading:be}=o({queryKey:[`printers`],queryFn:r.getPrinters}),{data:W,isLoading:xe}=o({queryKey:[`printer-locations`],queryFn:r.getPrinterLocations}),Se=c({queries:(U??[]).map(e=>({queryKey:[`printerStatus`,e.id],queryFn:()=>r.getPrinterStatus(e.id),refetchInterval:3e4}))}),Ce=new Map((U??[]).map((e,t)=>[e.id,Se[t]?.data])),G=(0,C.useMemo)(()=>{let e=new Map;for(let t of U??[]){let n=he(t);e.set(n,[...e.get(n)??[],t])}return e},[U]),K=G.get(``)??[],we=(U?.length??0)-K.length,Te=(0,C.useMemo)(()=>{let e=x.trim().toLowerCase(),t=(W??[]).filter(t=>(!e||t.name.toLowerCase().includes(e))&&(!S||t.printer_count>0)),n=(e,t)=>e.name.localeCompare(t.name,void 0,{numeric:!0,sensitivity:`base`});return[...t].sort((e,t)=>{switch(T){case`name-desc`:return n(t,e);case`count-asc`:return e.printer_count-t.printer_count||n(e,t);case`count-desc`:return t.printer_count-e.printer_count||n(e,t);default:return n(e,t)}})},[W,x,S,T]),q=()=>{e.invalidateQueries({queryKey:[`printer-locations`]}),e.invalidateQueries({queryKey:[`printers`]})},J=e=>n(t(`printers.locations.failed`,{error:e instanceof Error?e.message:String(e)}),`error`),Y=s({mutationFn:({value:e,location:t})=>t?r.updatePrinterLocation({name:t.name,...e.name===t.name?{}:{new_name:e.name},icon:e.icon||null,color:e.color||null}):r.createPrinterLocation({name:e.name,icon:e.icon||null,color:e.color||null}),onSuccess:(e,{location:r})=>{q(),r&&k===r.name&&A(e.name),n(t(r?`printers.locations.saved`:`printers.locations.created`)),R(null)},onError:J}),X=s({mutationFn:({ids:e,location:t})=>r.assignPrinterLocation(e,t),onSuccess:({moved:e})=>{q(),n(t(`printers.locations.moved`,{count:e})),I(new Set),B(null)},onError:J}),Z=s({mutationFn:e=>r.deletePrinterLocations(e),onSuccess:({deleted:e})=>{q(),n(t(`printers.locations.deleted`,{count:e})),P(new Set),M(!1),H(null)},onError:e=>{J(e),H(null)}}),Q=X.isPending||Z.isPending||Y.isPending,Ee=(e,t)=>{let n=new Set(e);return n.has(t)?n.delete(t):n.add(t),n};if(be||xe)return(0,w.jsx)(`div`,{className:`flex items-center justify-center h-64`,children:(0,w.jsx)(m,{className:`w-8 h-8 text-bambu-green animate-spin`})});let De=(V??[]).reduce((e,t)=>e+(W?.find(e=>e.name===t)?.printer_count??0),0),Oe=e=>({"name-asc":t(`printers.locations.sortNameAsc`),"name-desc":t(`printers.locations.sortNameDesc`),"count-asc":t(`printers.locations.sortCountAsc`),"count-desc":t(`printers.locations.sortCountDesc`)})[e],ke=(e,t)=>(0,w.jsx)(_e,{printer:e,status:Ce.get(e.id),selected:F.has(e.id),canEdit:h&&!j,busy:Q,onToggle:()=>I(Ee(F,e.id)),onMove:()=>B({ids:[e.id],printerName:e.name}),onRemove:t?()=>X.mutate({ids:[e.id],location:null}):void 0},e.id),$=K.length>0&&K.every(e=>F.has(e.id));return(0,w.jsxs)(`div`,{className:`p-4 md:p-8 pb-28`,children:[(0,w.jsxs)(ie,{to:`/`,className:`inline-flex items-center gap-1 mb-3 text-sm text-bambu-gray hover:text-white transition-colors`,children:[(0,w.jsx)(u,{className:`w-4 h-4`}),` `,t(`printers.locations.backToPrinters`)]}),(0,w.jsxs)(`div`,{className:`mb-4`,children:[(0,w.jsxs)(`div`,{className:`flex items-center gap-3 mb-1`,children:[(0,w.jsx)(d,{className:`w-[25px] h-[25px] text-bambu-green`}),(0,w.jsx)(`h1`,{className:`text-2xl font-bold text-white`,children:t(`printers.locations.title`)})]}),(0,w.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:t(`printers.locations.subtitle`,{grouped:we,ungrouped:K.length})})]}),(0,w.jsxs)(`div`,{className:`flex flex-wrap gap-3 mb-6`,children:[(0,w.jsxs)(`div`,{className:`relative flex-1 min-w-[12rem]`,children:[(0,w.jsx)(te,{className:`w-4 h-4 absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray`}),(0,w.jsx)(`input`,{type:`text`,value:x,onChange:e=>se(e.target.value),placeholder:t(`printers.locations.search`),"aria-label":t(`printers.locations.search`),className:`w-full pl-9 pr-4 py-2 text-sm bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`})]}),(0,w.jsx)(v,{onClick:()=>le(!S),variant:S?`primary`:`secondary`,children:t(S?`printers.locations.showEmpty`:`printers.locations.hideEmpty`)}),h&&(0,w.jsxs)(v,{onClick:()=>{P(new Set),M(!j)},variant:j?`primary`:`secondary`,children:[(0,w.jsx)(b,{className:`w-4 h-4 mr-1`}),t(j?`printers.locations.done`:`printers.locations.select`)]}),(0,w.jsxs)(`div`,{className:`relative`,children:[(0,w.jsxs)(v,{onClick:()=>O(!D),variant:`secondary`,"aria-haspopup":`menu`,children:[(0,w.jsx)(f,{className:`w-4 h-4 mr-1 transition-transform ${D?`rotate-180`:``}`}),Oe(T)]}),D&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`div`,{className:`fixed inset-0 z-40`,onClick:()=>O(!1)}),(0,w.jsx)(`div`,{role:`menu`,className:`absolute right-0 top-full mt-1 z-50 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg p-1 min-w-[10rem]`,children:ue.map(e=>(0,w.jsx)(`button`,{role:`menuitem`,onClick:()=>{E(e),O(!1)},className:`w-full text-left px-3 py-2 text-sm rounded transition-colors ${T===e?`bg-bambu-green text-white`:`text-bambu-gray hover:bg-bambu-dark-tertiary hover:text-white`}`,children:Oe(e)},e))})]})]}),h&&(0,w.jsxs)(v,{onClick:()=>R({mode:`create`}),children:[(0,w.jsx)(ae,{className:`w-4 h-4 mr-1`}),t(`printers.locations.create`)]})]}),Te.length===0&&K.length===0?(0,w.jsx)(_,{children:(0,w.jsx)(g,{className:`text-center py-12 text-bambu-gray`,children:t(x?`printers.locations.noResults`:`printers.locations.none`)})}):(0,w.jsxs)(`div`,{className:`space-y-3`,children:[Te.map(e=>{let n=k===e.name,r=N.has(e.name);return(0,w.jsx)(_,{children:(0,w.jsxs)(g,{className:`p-4`,children:[(0,w.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,w.jsxs)(`button`,{type:`button`,onClick:()=>j?P(Ee(N,e.name)):A(n?null:e.name),className:`flex items-center gap-3 flex-1 min-w-0 text-left`,"aria-expanded":j?void 0:n,"aria-pressed":j?r:void 0,children:[j?r?(0,w.jsx)(b,{className:`w-4 h-4 text-bambu-green flex-shrink-0`}):(0,w.jsx)(y,{className:`w-4 h-4 text-bambu-gray flex-shrink-0`}):(0,w.jsx)(f,{className:`w-4 h-4 text-bambu-gray flex-shrink-0 transition-transform ${n?`rotate-180`:``}`}),(0,w.jsx)(ge,{location:e}),(0,w.jsxs)(`div`,{className:`min-w-0`,children:[(0,w.jsx)(`p`,{className:`text-white font-medium truncate`,children:e.name}),(0,w.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:t(`printers.locations.printerCount`,{count:e.printer_count})})]})]}),h&&!j&&(0,w.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,w.jsx)(v,{variant:`ghost`,size:`sm`,onClick:()=>R({mode:`edit`,location:e}),disabled:Q,className:`text-bambu-gray hover:text-blue-400 hover:bg-blue-500/10`,title:t(`common.edit`),"aria-label":t(`common.edit`),children:(0,w.jsx)(ne,{className:`w-4 h-4`})}),(0,w.jsx)(v,{variant:`ghost`,size:`sm`,onClick:()=>H([e.name]),disabled:Q,className:`text-red-500 hover:text-red-400 hover:bg-red-500/10`,title:t(`common.delete`),"aria-label":t(`common.delete`),children:(0,w.jsx)(re,{className:`w-4 h-4`})})]})]}),n&&(0,w.jsx)(`div`,{className:`border-t border-bambu-dark-tertiary pt-3 mt-3 space-y-2`,children:(G.get(e.name)??[]).length===0?(0,w.jsx)(`p`,{className:`text-sm text-bambu-gray text-center py-4`,children:t(`printers.locations.noPrinters`)}):(G.get(e.name)??[]).map(e=>ke(e,!0))})]})},e.name)}),K.length>0&&(0,w.jsxs)(`div`,{className:`pt-4 border-t border-bambu-dark-tertiary`,children:[(0,w.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,w.jsx)(`h3`,{className:`text-sm font-medium text-bambu-gray`,children:t(`printers.locations.ungroupedPrinters`,{count:K.length})}),h&&!j&&(0,w.jsx)(`button`,{type:`button`,onClick:()=>{let e=new Set(F);K.forEach(t=>$?e.delete(t.id):e.add(t.id)),I(e)},className:`text-xs text-bambu-green hover:text-bambu-green-light transition-colors`,children:t($?`common.deselectAll`:`common.selectAll`)})]}),(0,w.jsx)(`div`,{className:`space-y-2`,children:K.map(e=>ke(e,!1))})]})]}),h&&!j&&F.size>0&&(0,w.jsxs)(`div`,{className:`fixed bottom-6 left-1/2 -translate-x-1/2 bg-bambu-dark border border-bambu-dark-tertiary rounded-xl shadow-2xl px-6 py-4 flex items-center gap-4 z-40`,children:[(0,w.jsx)(`span`,{className:`text-white text-sm`,children:t(`printers.locations.selected`,{count:F.size})}),(0,w.jsxs)(v,{onClick:()=>B({ids:Array.from(F)}),disabled:Q,children:[(0,w.jsx)(ee,{className:`w-4 h-4 mr-1`}),t(`printers.locations.moveButton`)]}),(0,w.jsx)(v,{variant:`ghost`,onClick:()=>I(new Set),disabled:Q,children:t(`common.cancel`)})]}),j&&N.size>0&&(0,w.jsxs)(`div`,{className:`fixed bottom-6 left-1/2 -translate-x-1/2 bg-bambu-dark border border-bambu-dark-tertiary rounded-xl shadow-2xl px-6 py-4 flex items-center gap-4 z-40`,children:[(0,w.jsx)(`span`,{className:`text-white text-sm`,children:t(`printers.locations.selected`,{count:N.size})}),(0,w.jsxs)(v,{variant:`danger`,onClick:()=>H(Array.from(N)),disabled:Q,children:[(0,w.jsx)(re,{className:`w-4 h-4 mr-1`}),t(`printers.locations.deleteSelected`)]}),(0,w.jsx)(v,{variant:`ghost`,onClick:()=>P(new Set),disabled:Q,children:t(`common.cancel`)})]}),L&&(0,w.jsx)(ve,{initial:L.mode===`edit`?L.location:void 0,saving:Y.isPending,onSave:e=>Y.mutate({value:e,location:L.mode===`edit`?L.location:void 0}),onCancel:()=>R(null)}),z&&(0,w.jsx)(ye,{count:z.ids.length,printerName:z.printerName,locations:W??[],saving:X.isPending,onMove:e=>X.mutate({ids:z.ids,location:e}),onCancel:()=>B(null)}),V&&(0,w.jsx)(oe,{title:V.length===1?t(`printers.locations.deleteTitle`):t(`printers.locations.deleteTitleMany`,{count:V.length}),message:t(`printers.locations.deleteMessage`,{count:De,names:V.join(`, `)}),confirmText:t(`common.delete`),variant:`danger`,isLoading:Z.isPending,onConfirm:()=>Z.mutate(V),onCancel:()=>H(null)})]})}export{D as PrinterLocationsPage}; \ No newline at end of file diff --git a/static/assets/PrintersPage-Dsyz3sPW.js b/static/assets/PrintersPage-CLG7I78P.js similarity index 99% rename from static/assets/PrintersPage-Dsyz3sPW.js rename to static/assets/PrintersPage-CLG7I78P.js index bf751928b..28385c047 100644 --- a/static/assets/PrintersPage-Dsyz3sPW.js +++ b/static/assets/PrintersPage-CLG7I78P.js @@ -1,4 +1,4 @@ -import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,S as r,a as i,c as a,l as o,s,t as c,w as l,x as u}from"./client-DnySrlFv.js";import{t as d}from"./react-dom-B8Dg6xzp.js";import{n as f}from"./QueryClientProvider-Ce8_sN3w.js";import{t as p}from"./useQuery-BBCjCezC.js";import{t as m}from"./useMutation-B-Tr2hIP.js";import{t as h}from"./createLucideIcon-DvBYJlWL.js";import{c as g,i as _,n as v,o as y,r as b,s as x}from"./haSensorDisplay-lPbcOxD8.js";import{t as S}from"./arrow-down-Cj0DZhNf.js";import{t as C}from"./arrow-left-0Q6F2rjC.js";import{t as w}from"./arrow-right-DedpIMhP.js";import{t as T}from"./arrow-up-down-BdyOV_2F.js";import{t as E}from"./arrow-up-D-pfJ3WZ.js";import{i as D,n as O,r as k,t as A}from"./ReferenceLine-clJprXoH.js";import{t as j}from"./box-DAdKb9s5.js";import{n as M,t as N}from"./fan-D6AmXZMv.js";import{t as P}from"./calendar-BLKPnWqV.js";import{t as F}from"./check-Ck0cMLU4.js";import{a as I,n as L,r as R,t as ee}from"./info-ROUoQhJR.js";import{n as te,r as ne}from"./ToastContext-BRX0SW3C.js";import{t as z}from"./copy-Cu_0GKCU.js";import{t as re}from"./ellipsis-vertical-t2D7cYyp.js";import{t as B}from"./eye-off-6CkaxYwP.js";import{t as ie}from"./file-box-04V4jZ9_.js";import{t as ae}from"./GcodeToolpathViewer-Cg6UnTDw.js";import{n as V,t as oe}from"./ContextMenu-BOFgRmSk.js";import{n as se,t as ce}from"./scan-search-BDoNAXzz.js";import{t as le}from"./funnel-C3dyAMK9.js";import{t as ue}from"./gauge-D21zgWMb.js";import{t as de}from"./grip-vertical-C_1RDxRw.js";import{t as fe}from"./hard-drive-CgXAHN37.js";import{t as pe}from"./layout-grid-DkD3u6wa.js";import{t as H}from"./loader-circle-BEmFtawu.js";import{t as me}from"./log-in-n0ckHxnD.js";import{t as he}from"./maximize-2-kPQ77q72.js";import{t as U}from"./minimize-2-dqT-k7oI.js";import{a as ge,i as _e,n as ve,r as ye,t as W}from"./CameraDiagnoseModal-38LtfiVu.js";import{t as G}from"./minus-DypeGjGR.js";import{a as be,c as xe,i as Se,l as K,n as Ce,r as we,s as Te,t as q,u as J}from"./CopyButton-C5In5weo.js";import{t as Ee}from"./move-Bc1EIjTD.js";import{t as De}from"./package-BGUevlqS.js";import{t as Oe}from"./pause-DFb6GX_6.js";import{t as ke}from"./play-DIDYtk2S.js";import{t as Ae}from"./search-0n0CBc74.js";import{t as je}from"./settings-2-Cvn837lh.js";import{n as Me,t as Ne}from"./wind-CI8UoBMf.js";import{D as Pe,Fn as Fe,It as Ie,Kt as Le,L as Re,Ln as ze,Lt as Be,M as Ve,Mn as He,On as Ue,Pn as We,R as Ge,Rn as Ke,S as qe,Sn as Je,St as Ye,T as Xe,Ut as Ze,Xt as Qe,Zt as $e,an as et,at as tt,b as nt,c as rt,cn as it,d as at,f as ot,gn as st,j as ct,jt as lt,k as ut,l as dt,ln as ft,mn as pt,mt,nn as ht,p as gt,pt as _t,s as vt,sn as yt,t as bt,u as xt,vn as St,w as Ct,wn as wt,x as Tt,y as Et,z as Dt}from"./CartesianChart-BAcHzPFb.js";import{t as Ot}from"./triangle-alert-Dt_1FcBy.js";import{t as kt}from"./unlink-C098nwOf.js";import{i as At,n as jt,r as Mt,t as Nt}from"./CameraWall-Cv6o1Fp5.js";import{t as Pt}from"./x-DR-Trv6U.js";import{n as Ft,t as It}from"./zoom-out-DNNe6DMN.js";import{n as Lt,t as Rt}from"./Card-Bzc64K35.js";import{t as zt}from"./file-DDkFXH-b.js";import{t as Y}from"./Button-DDr6eAFy.js";import{a as Bt,c as Vt,i as Ht,o as Ut,s as Wt,t as Gt,u as Kt,v as qt}from"./date-G9KUauqz.js";import{n as Jt,r as Yt}from"./filamentSwatchHelpers-D3oXQSGk.js";import{$ as Xt,$t as Zt,At as Qt,Cn as $t,Ct as en,D as tn,E as nn,Et as rn,Ft as an,G as on,H as sn,J as cn,Jt as ln,K as un,Kt as dn,Lt as fn,Mn as pn,Mt as mn,N as hn,Nt as gn,O as _n,On as vn,Ot as yn,Rn as bn,Rt as xn,Sn,U as Cn,V as wn,Vn as Tn,Vt as En,W as Dn,Wt as On,X as kn,Y as An,Yt as jn,Z as Mn,Zt as Nn,_ as Pn,_n as Fn,_t as In,an as Ln,at as Rn,b as zn,bn as Bn,bt as Vn,cn as Hn,ct as Un,dt as Wn,et as Gn,fn as Kn,ft as qn,h as Jn,jn as Yn,jt as Xn,k as Zn,q as Qn,sn as $n,tt as er,un as tr,ut as nr,v as rr,vt as ir,wn as ar,xn as or,xt as sr,y as cr,yt as lr,z as ur}from"./index-0t--Yqoi.js";import{n as dr,t as fr}from"./FileUploadModal-CpDg524n.js";import{n as pr,t as mr}from"./ErrorBarContext-CcijMMkA.js";import{t as hr}from"./Toggle-KiqA_5fU.js";import{t as gr}from"./printerModel-DrNvERGQ.js";import{t as _r}from"./queueItemName-UFY7kpjG.js";import{n as vr,r as yr,t as br}from"./ConfigureAmsSlotModal-D0mYskEf.js";var xr=h(`air-vent`,[[`path`,{d:`M18 17.5a2.5 2.5 0 1 1-4 2.03V12`,key:`yd12zl`}],[`path`,{d:`M6 12H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v5a2 2 0 0 1-2 2h-2`,key:`larmp2`}],[`path`,{d:`M6 8h12`,key:`6g4wlu`}],[`path`,{d:`M6.6 15.572A2 2 0 1 0 10 17v-5`,key:`1x1kqn`}]]),Sr=h(`chart-line`,[[`path`,{d:`M3 3v16a2 2 0 0 0 2 2h16`,key:`c24i48`}],[`path`,{d:`m19 9-5 5-4-4-3 3`,key:`2osh9i`}]]),Cr=h(`ellipsis`,[[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}],[`circle`,{cx:`19`,cy:`12`,r:`1`,key:`1wjl8i`}],[`circle`,{cx:`5`,cy:`12`,r:`1`,key:`1pcz8c`}]]),wr=h(`fullscreen`,[[`path`,{d:`M3 7V5a2 2 0 0 1 2-2h2`,key:`aa7l1z`}],[`path`,{d:`M17 3h2a2 2 0 0 1 2 2v2`,key:`4qcy5o`}],[`path`,{d:`M21 17v2a2 2 0 0 1-2 2h-2`,key:`6vwrx8`}],[`path`,{d:`M7 21H5a2 2 0 0 1-2-2v-2`,key:`ioqczr`}],[`rect`,{width:`10`,height:`8`,x:`7`,y:`8`,rx:`1`,key:`vys8me`}]]),Tr=h(`hourglass`,[[`path`,{d:`M5 22h14`,key:`ehvnwv`}],[`path`,{d:`M5 2h14`,key:`pdyrp9`}],[`path`,{d:`M17 22v-4.172a2 2 0 0 0-.586-1.414L12 12l-4.414 4.414A2 2 0 0 0 7 17.828V22`,key:`1d314k`}],[`path`,{d:`M7 2v4.172a2 2 0 0 0 .586 1.414L12 12l4.414-4.414A2 2 0 0 0 17 6.172V2`,key:`1vvvr6`}]]),Er=h(`key-round`,[[`path`,{d:`M2.586 17.414A2 2 0 0 0 2 18.828V21a1 1 0 0 0 1 1h3a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h1a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h.172a2 2 0 0 0 1.414-.586l.814-.814a6.5 6.5 0 1 0-4-4z`,key:`1s6t7t`}],[`circle`,{cx:`16.5`,cy:`7.5`,r:`.5`,fill:`currentColor`,key:`w0ekpg`}]]),Dr=h(`picture-in-picture-2`,[[`path`,{d:`M21 9V6a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v10c0 1.1.9 2 2 2h4`,key:`daa4of`}],[`rect`,{width:`10`,height:`7`,x:`12`,y:`13`,rx:`2`,key:`1nb8gs`}]]),Or=h(`repeat`,[[`path`,{d:`m17 2 4 4-4 4`,key:`nntrym`}],[`path`,{d:`M3 11v-1a4 4 0 0 1 4-4h14`,key:`84bu3i`}],[`path`,{d:`m7 22-4-4 4-4`,key:`1wqhfi`}],[`path`,{d:`M21 13v1a4 4 0 0 1-4 4H3`,key:`1rx37r`}]]),kr=h(`signal`,[[`path`,{d:`M2 20h.01`,key:`4haj6o`}],[`path`,{d:`M7 20v-4`,key:`j294jx`}],[`path`,{d:`M12 20v-8`,key:`i3yub9`}],[`path`,{d:`M17 20V8`,key:`1tkaf5`}],[`path`,{d:`M22 4v16`,key:`sih9yq`}]]),Ar=h(`sliders-horizontal`,[[`path`,{d:`M10 5H3`,key:`1qgfaw`}],[`path`,{d:`M12 19H3`,key:`yhmn1j`}],[`path`,{d:`M14 3v4`,key:`1sua03`}],[`path`,{d:`M16 17v4`,key:`1q0r14`}],[`path`,{d:`M21 12h-9`,key:`1o4lsq`}],[`path`,{d:`M21 19h-5`,key:`1rlt1p`}],[`path`,{d:`M21 5h-7`,key:`1oszz2`}],[`path`,{d:`M8 10v4`,key:`tgpxqk`}],[`path`,{d:`M8 12H3`,key:`a7s4jb`}]]),jr=h(`snowflake`,[[`path`,{d:`m10 20-1.25-2.5L6 18`,key:`18frcb`}],[`path`,{d:`M10 4 8.75 6.5 6 6`,key:`7mghy3`}],[`path`,{d:`m14 20 1.25-2.5L18 18`,key:`1chtki`}],[`path`,{d:`m14 4 1.25 2.5L18 6`,key:`1b4wsy`}],[`path`,{d:`m17 21-3-6h-4`,key:`15hhxa`}],[`path`,{d:`m17 3-3 6 1.5 3`,key:`11697g`}],[`path`,{d:`M2 12h6.5L10 9`,key:`kv9z4n`}],[`path`,{d:`m20 10-1.5 2 1.5 2`,key:`1swlpi`}],[`path`,{d:`M22 12h-6.5L14 15`,key:`1mxi28`}],[`path`,{d:`m4 10 1.5 2L4 14`,key:`k9enpj`}],[`path`,{d:`m7 21 3-6-1.5-3`,key:`j8hb9u`}],[`path`,{d:`m7 3 3 6h4`,key:`1otusx`}]]),Mr=h(`square-minus`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M8 12h8`,key:`1wcyev`}]]),Nr=(e,t,n,r)=>tt(e,`xAxis`,t,r),Pr=(e,t,n,r)=>_t(e,`xAxis`,t,r),Fr=(e,t,n,r)=>tt(e,`yAxis`,n,r),Ir=(e,t,n,r)=>_t(e,`yAxis`,n,r),Lr=pt([Ze,Nr,Fr,Pr,Ir],(e,t,n,r,i)=>ft(e,`xAxis`)?ht(t,r,!1):ht(n,i,!1)),Rr=(e,t,n,r,i)=>i;function zr(e){return e.type===`line`}var Br=pt([Ze,Nr,Fr,Pr,Ir,pt([mt,Rr],(e,t)=>e.filter(zr).find(e=>e.id===t)),Lr,lt],(e,t,n,r,i,a,o,s)=>{var{chartData:c,dataStartIndex:l,dataEndIndex:u}=s;if(!(a==null||t==null||n==null||r==null||i==null||r.length===0||i.length===0||o==null||e!==`horizontal`&&e!==`vertical`)){var{dataKey:d,data:f}=a,p=f!=null&&f.length>0?f:c?.slice(l,u+1);if(p!=null)return di({layout:e,xAxis:t,yAxis:n,xAxisTicks:r,yAxisTicks:i,dataKey:d,bandSize:o,displayedData:p})}}),X=e(n()),Vr=[`id`],Hr=[`type`,`layout`,`connectNulls`,`needClip`,`shape`],Ur=[`activeDot`,`animateNewValues`,`animationBegin`,`animationDuration`,`animationEasing`,`connectNulls`,`dot`,`hide`,`isAnimationActive`,`label`,`legendType`,`xAxisId`,`yAxisId`,`id`];function Wr(){return Wr=Object.assign?Object.assign.bind():function(e){for(var t=1;t{var{dataKey:t,name:n,stroke:r,legendType:i,hide:a}=e;return[{inactive:a,dataKey:t,type:i,color:r,value:yt(n,t),payload:e}]},Qr=X.memo(e=>{var{dataKey:t,data:n,stroke:r,strokeWidth:i,fill:a,name:o,hide:s,unit:c,tooltipType:l,id:u}=e,d={dataDefinedOnItem:n,getPosition:Ue,settings:{stroke:r,strokeWidth:i,fill:a,dataKey:t,nameKey:void 0,name:yt(o,t),hide:s,type:l,color:r,unit:c,graphicalItemId:u}};return X.createElement(Pe,{tooltipEntrySettings:d})}),$r=(e,t)=>`${t}px ${e-t}px`;function ei(e,t){for(var n=e.length%2==0?e:[...e,0],r=[],i=0;i{var r=n.reduce((e,t)=>e+t);if(!r)return $r(t,e);for(var i=Math.floor(e/r),a=e%r,o=t-e,s=[],c=0,l=0;ca){s=[...n.slice(0,c),a-l];break}}var f=s.length%2==0?[0,o]:[o];return[...ei(n,i),...s,...f].map(e=>`${e}px`).join(`, `)};function ni(e){var{clipPathId:t,points:n,props:r}=e,{dot:i,dataKey:a,needClip:o}=r,{id:s}=r,c=Fe(Yr(r,Vr));return X.createElement(Tt,{points:n,dot:i,className:`recharts-line-dots`,dotClassName:`recharts-line-dot`,dataKey:a,baseProps:c,needClip:o,clipPathId:t})}function Q(e){var{showLabels:t,children:n,points:r}=e,i=(0,X.useMemo)(()=>r?.map(e=>{var t={x:e.x??0,y:e.y??0,width:0,lowerWidth:0,upperWidth:0,height:0};return Z(Z({},t),{},{value:e.value,payload:e.payload,viewBox:t,parentViewBox:void 0,fill:void 0})}),[r]);return X.createElement(ct,{value:t?i:void 0},n)}function ri(e){var{clipPathId:t,pathRef:n,points:r,strokeDasharray:i,props:a}=e,{type:o,layout:s,connectNulls:c,needClip:l,shape:u}=a,d=Z(Z({},We(Yr(a,Hr))),{},{fill:`none`,className:`recharts-line-curve`,clipPath:l?`url(#clipPath-${t})`:void 0,points:r,type:o,layout:s,connectNulls:c,strokeDasharray:i??a.strokeDasharray});return X.createElement(X.Fragment,null,r?.length>1&&X.createElement(pr,Wr({shapeType:`curve`,option:u},d,{pathRef:n})),X.createElement(ni,{points:r,clipPathId:t,props:a}))}function ii(e){try{return e&&e.getTotalLength&&e.getTotalLength()||0}catch{return 0}}function ai(e){var{clipPathId:t,props:n,pathRef:r,previousPointsRef:i,longestAnimatedLengthRef:a}=e,{points:o,strokeDasharray:s,isAnimationActive:c,animationBegin:l,animationDuration:u,animationEasing:d,animateNewValues:f,width:p,height:m,onAnimationEnd:h,onAnimationStart:g}=n,_=i.current,v=Ie(o,`recharts-line-`),y=(0,X.useRef)(v),[b,x]=(0,X.useState)(!1),S=!b,C=(0,X.useCallback)(()=>{typeof h==`function`&&h(),x(!1)},[h]),w=(0,X.useCallback)(()=>{typeof g==`function`&&g(),x(!0)},[g]),T=ii(r.current),E=(0,X.useRef)(0);y.current!==v&&(E.current=a.current,y.current=v);var D=E.current;return X.createElement(Q,{points:o,showLabels:S},n.children,X.createElement(Be,{animationId:v,begin:l,duration:u,isActive:c,easing:d,onAnimationEnd:C,onAnimationStart:w,key:v},e=>{var l=Je(D,T+D,e),u=Math.min(l,T),d=c?s?ti(u,T,`${s}`.split(/[,\s]+/gim).map(e=>parseFloat(e))):$r(T,u):s==null?void 0:String(s);if(e>0&&T>0&&(i.current=o,a.current=Math.max(a.current,u)),_){var h=_.length/o.length,g=e===1?o:o.map((t,n)=>{var r=Math.floor(n*h);if(_[r]){var i=_[r];return Z(Z({},t),{},{x:Je(i.x,t.x,e),y:Je(i.y,t.y,e)})}return f?Z(Z({},t),{},{x:Je(p*2,t.x,e),y:Je(m/2,t.y,e)}):Z(Z({},t),{},{x:t.x,y:t.y})});return i.current=g,X.createElement(ri,{props:n,points:g,clipPathId:t,pathRef:r,strokeDasharray:d})}return X.createElement(ri,{props:n,points:o,clipPathId:t,pathRef:r,strokeDasharray:d})}),X.createElement(Ve,{label:n.label}))}function oi(e){var{clipPathId:t,props:n}=e,r=(0,X.useRef)(null),i=(0,X.useRef)(0),a=(0,X.useRef)(null);return X.createElement(ai,{props:n,clipPathId:t,previousPointsRef:r,longestAnimatedLengthRef:i,pathRef:a})}var si=(e,t)=>({x:e.x??void 0,y:e.y??void 0,value:e.value,errorVal:it(e.payload,t)}),ci=class extends X.Component{render(){var{hide:e,dot:t,points:n,className:r,xAxisId:i,yAxisId:a,top:o,left:s,width:c,height:l,id:u,needClip:d,zIndex:f}=this.props;if(e)return null;var p=ze(`recharts-line`,r),m=u,{r:h,strokeWidth:g}=xt(t),_=ut(t),v=h*2+g,y=d?`url(#clipPath-${_?``:`dots-`}${m})`:void 0;return X.createElement(Dt,{zIndex:f},X.createElement(He,{className:p},d&&X.createElement(`defs`,null,X.createElement(at,{clipPathId:m,xAxisId:i,yAxisId:a}),!_&&X.createElement(`clipPath`,{id:`clipPath-dots-${m}`},X.createElement(`rect`,{x:s-v/2,y:o-v/2,width:c+v,height:l+v}))),X.createElement(mr,{xAxisId:i,yAxisId:a,data:n,dataPointFormatter:si,errorBarOffset:0},X.createElement(oi,{props:this.props,clipPathId:m}))),X.createElement(Et,{activeDot:this.props.activeDot,points:n,mainColor:this.props.stroke,itemDataKey:this.props.dataKey,clipPath:y}))}},li={activeDot:!0,animateNewValues:!0,animationBegin:0,animationDuration:1500,animationEasing:`ease`,connectNulls:!1,dot:!0,fill:`#fff`,hide:!1,isAnimationActive:`auto`,label:!1,legendType:`line`,stroke:`#3182bd`,strokeWidth:1,xAxisId:0,yAxisId:0,zIndex:Ye.line,type:`linear`};function ui(e){var t=St(e,li),{activeDot:n,animateNewValues:r,animationBegin:i,animationDuration:a,animationEasing:o,connectNulls:s,dot:c,hide:l,isAnimationActive:u,label:d,legendType:f,xAxisId:p,yAxisId:m,id:h}=t,g=Yr(t,Ur),{needClip:_}=ot(p,m),v=nt(),y=Le(),b=$e(),x=st(e=>Br(e,p,m,b,h));if(y!==`horizontal`&&y!==`vertical`||x==null||v==null)return null;var{height:S,width:C,x:w,y:T}=v;return X.createElement(ci,Wr({},g,{id:h,connectNulls:s,dot:c,activeDot:n,animateNewValues:r,animationBegin:i,animationDuration:a,animationEasing:o,isAnimationActive:u,hide:l,label:d,legendType:f,xAxisId:p,yAxisId:m,points:x,layout:y,height:S,width:C,left:w,top:T,needClip:_}))}function di(e){var{layout:t,xAxis:n,yAxis:r,xAxisTicks:i,yAxisTicks:a,dataKey:o,bandSize:s,displayedData:c}=e;return c.map((e,c)=>{var l=it(e,o);if(t===`horizontal`)return{x:et({axis:n,ticks:i,bandSize:s,entry:e,index:c}),y:(wt(l)?null:r.scale.map(l))??null,value:l,payload:e};var u=wt(l)?null:n.scale.map(l),d=et({axis:r,ticks:a,bandSize:s,entry:e,index:c});return u==null||d==null?null:{x:u,y:d,value:l,payload:e}}).filter(Boolean)}function fi(e){var t=St(e,li),n=$e();return X.createElement(Ct,{id:t.id,type:`line`},e=>X.createElement(X.Fragment,null,X.createElement(Xe,{legendPayload:Zr(t)}),X.createElement(Qr,{dataKey:t.dataKey,data:t.data,stroke:t.stroke,strokeWidth:t.strokeWidth,fill:t.fill,name:t.name,hide:t.hide,unit:t.unit,tooltipType:t.tooltipType,id:e}),X.createElement(qe,{type:`line`,id:e,data:t.data,xAxisId:t.xAxisId,yAxisId:t.yAxisId,zAxisId:0,dataKey:t.dataKey,hide:t.hide,isPanorama:n}),X.createElement(ui,Wr({},t,{id:e}))))}var pi=X.memo(fi,dt);pi.displayName=`Line`;var mi=[`axis`],hi=(0,X.forwardRef)((e,t)=>X.createElement(bt,{chartName:`LineChart`,defaultTooltipEventType:`axis`,validateTooltipEventTypes:mi,tooltipPayloadSearcher:Ge,categoricalChartProps:e,ref:t})),gi=e(d(),1);function _i(e,t){let n=e.split(`.`).map(e=>parseInt(e,10)||0),r=t.split(`.`).map(e=>parseInt(e,10)||0);for(;n.length<4;)n.push(0);for(;r.length<4;)r.push(0);for(let e=0;e<4;e++)if(n[e]!==r[e])return n[e]-r[e];return 0}function vi(e,t,n,r){if(!e)return``;if(r)return`${e} — ${r}`;if(!t)return e;let i=t.match(/plate_(\d+)\.gcode/);return i&&parseInt(i[1],10)>1?`${e} — ${n(`printers.plateNumber`,`Plate {{number}}`,{number:i[1]})}`:e}var yi=new Set([`A1`,`A1MINI`,`A2L`,`A1M`,`N1`,`N2S`,`N9`,`A04`,`A11`,`A12`]);function bi(e){return e?yi.has(e.toUpperCase().replace(/[^A-Z0-9]/g,``)):!1}function xi(e){let t=typeof window<`u`&&window.visualViewport?window.visualViewport.height:typeof window<`u`?window.innerHeight:0,{triggerRect:n,popoverWidth:r,estimatedHeight:i,viewportHeight:a=t,viewportWidth:o=window.innerWidth,margin:s=8,gap:c=4,horizontalAlign:l=`right`}=e,u=n.bottom+c,d=`below`;if(u+i>a-s){let e=n.top-c-i;e>=s&&(u=e,d=`above`)}let f=n.left+(n.right-n.left)/2,p=l===`center`?f-r/2:n.right-r;po-s&&(p=Math.max(s,o-r-s));let m=d===`above`?n.top-c:u,h=Math.max(14,Math.min(r-14,f-p));return{top:u,left:p,placement:d,anchorY:m,arrowLeft:h}}var Si=`cameraViewMode`,Ci=`cameraWindowState`;function wi(e){return e===`window`||e===`embedded`}function Ti(){try{let e=localStorage.getItem(Si);return wi(e)?e:null}catch{return null}}function Ei(e){try{localStorage.setItem(Si,e)}catch{}}function Di(e){let t={width:640,height:400};try{let e=localStorage.getItem(Ci);if(e){let n=JSON.parse(e);n&&typeof n==`object`&&(t=n)}}catch{}let n=[`width=${t.width??640}`,`height=${t.height??400}`,t.left===void 0?``:`left=${t.left}`,t.top===void 0?``:`top=${t.top}`,`menubar=no,toolbar=no,location=no,status=no`].filter(Boolean).join(`,`);window.open(`/camera/${e}`,`camera-${e}`,n)}var Oi={NYLON:`PA`,PA6:`PA`,PA11:`PA`,PA12:`PA`,PAHT:`PA`,PPA:`PA`};function ki(e,t){let n=(e||``).split(` `)[0].toUpperCase();for(let e of[n,n.split(`-`)[0]]){let n=Oi[e]??e;if(t[n])return n}return`PLA`}function Ai(e,t,n,r=new Date){return e===`now`?null:e===`delay`?new Date(r.getTime()+t*6e4).toISOString():new Date(n).toISOString()}var ji=`printerHiddenExternalSpools`;function Mi(){try{let e=localStorage.getItem(ji);if(!e)return{};let t=JSON.parse(e);return!t||typeof t!=`object`||Array.isArray(t)?{}:t}catch{return{}}}function Ni(e){return Mi()[String(e)]===!0}function Pi(e,t){let n=Mi();t?n[String(e)]=!0:delete n[String(e)];try{localStorage.setItem(ji,JSON.stringify(n))}catch{}}var $=t(),Fi=[{key:`printing`,dot:`bg-bambu-green`},{key:`paused`,dot:`bg-status-warning`},{key:`finished`,dot:`bg-blue-400`},{key:`idle`,dot:`bg-bambu-green`},{key:`error`,dot:`bg-status-error`},{key:`offline`,dot:`bg-gray-400`}];function Ii({selectedIds:e,printers:t,onClose:n,onSelectAll:r,onSelectByLocation:i,onSelectByState:a,onAction:o,actionPending:s}){let{t:c}=l(),{hasPermission:u}=lr(),d=f(),[p,m]=(0,X.useState)(!1),[h,g]=(0,X.useState)(!1),_=Array.from(e).map(e=>({id:e,status:d.getQueryData([`printerStatus`,e])})),v=_.some(({status:e})=>e?.connected&&e.state===`RUNNING`),y=_.some(({status:e})=>e?.connected&&e.state===`PAUSE`),b=v||y,x=_.some(({status:e})=>!!(e?.connected&&e.awaiting_plate_clear)),S=_.some(({status:e})=>!e?.connected||!e.hms_errors?!1:Mt(e.hms_errors).length>0),C=u(`printers:control`),w=u(`printers:clear_plate`),T=[...new Set(t.map(e=>e.location).filter(e=>!!e))].sort(),E={printing:0,paused:0,finished:0,idle:0,error:0,offline:0};t.forEach(e=>{let t=d.getQueryData([`printerStatus`,e.id]);if(!t||!t.connected){E.offline++;return}let n=t.hms_errors?Mt(t.hms_errors).length>0:!1;switch(n&&E.error++,t.state){case`RUNNING`:E.printing++;break;case`PAUSE`:E.paused++;break;case`FINISH`:E.finished++;break;case`FAILED`:n||E.finished++;break;default:E.idle++;break}});let O={printing:c(`printers.status.printing`),paused:c(`printers.status.paused`,`Paused`),finished:c(`printers.status.finished`,`Finished`),idle:c(`printers.status.idle`),error:c(`printers.status.problem`),offline:c(`printers.status.offline`)};return(0,$.jsxs)(`div`,{className:`fixed bottom-6 left-1/2 -translate-x-1/2 z-40 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl px-4 py-3 flex items-center gap-3 flex-wrap`,children:[(0,$.jsx)(Y,{variant:`secondary`,size:`sm`,onClick:n,children:(0,$.jsx)(Pt,{className:`w-4 h-4`})}),(0,$.jsx)(`div`,{className:`w-px h-6 bg-bambu-dark-tertiary`}),(0,$.jsx)(`span`,{className:`text-white font-medium text-sm`,children:c(`printers.bulk.selected`,{count:e.size})}),(0,$.jsx)(`div`,{className:`w-px h-6 bg-bambu-dark-tertiary`}),(0,$.jsx)(Y,{variant:`secondary`,size:`sm`,onClick:r,children:c(`printers.bulk.selectAll`)}),(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsxs)(Y,{variant:`secondary`,size:`sm`,onClick:()=>{g(!h),m(!1)},children:[c(`printers.bulk.selectByState`),(0,$.jsx)(I,{className:`w-3 h-3 transition-transform ${h?`rotate-180`:``}`})]}),h&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>g(!1)}),(0,$.jsx)(`div`,{className:`absolute bottom-full mb-2 left-0 w-48 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg z-20 py-1`,children:Fi.filter(({key:e})=>E[e]>0).map(({key:e,dot:t})=>(0,$.jsxs)(`button`,{onClick:()=>{a(e),g(!1)},className:`w-full text-left px-3 py-2 text-sm text-bambu-gray-light hover:bg-bambu-dark-tertiary hover:text-white transition-colors flex items-center gap-2`,children:[(0,$.jsx)(`div`,{className:`w-2 h-2 rounded-full ${t}`}),O[e],(0,$.jsx)(`span`,{className:`ml-auto text-bambu-gray text-xs`,children:E[e]})]},e))})]})]}),T.length>0&&(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsxs)(Y,{variant:`secondary`,size:`sm`,onClick:()=>{m(!p),g(!1)},children:[c(`printers.bulk.selectByLocation`),(0,$.jsx)(I,{className:`w-3 h-3 transition-transform ${p?`rotate-180`:``}`})]}),p&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>m(!1)}),(0,$.jsx)(`div`,{className:`absolute bottom-full mb-2 left-0 w-48 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg z-20 py-1`,children:T.map(e=>(0,$.jsx)(`button`,{onClick:()=>{i(e),m(!1)},className:`w-full text-left px-3 py-2 text-sm text-bambu-gray-light hover:bg-bambu-dark-tertiary hover:text-white transition-colors`,children:e},e))})]})]}),(0,$.jsx)(`div`,{className:`w-px h-6 bg-bambu-dark-tertiary`}),(0,$.jsxs)(Y,{size:`sm`,className:`bg-red-500 hover:bg-red-600`,onClick:()=>o(`stop`),disabled:s||!C||!b,title:C?b?void 0:c(`printers.bulk.noneApplicable`):c(`printers.permission.noControl`),children:[(0,$.jsx)(fn,{className:`w-3.5 h-3.5`}),c(`printers.bulk.actions.stop`)]}),(0,$.jsxs)(Y,{variant:`secondary`,size:`sm`,onClick:()=>o(`pause`),disabled:s||!C||!v,title:C?v?void 0:c(`printers.bulk.noneApplicable`):c(`printers.permission.noControl`),children:[(0,$.jsx)(Oe,{className:`w-3.5 h-3.5`}),c(`printers.bulk.actions.pause`)]}),(0,$.jsxs)(Y,{variant:`secondary`,size:`sm`,onClick:()=>o(`resume`),disabled:s||!C||!y,title:C?y?void 0:c(`printers.bulk.noneApplicable`):c(`printers.permission.noControl`),children:[(0,$.jsx)(ke,{className:`w-3.5 h-3.5`}),c(`printers.bulk.actions.resume`)]}),(0,$.jsxs)(Y,{variant:`secondary`,size:`sm`,onClick:()=>o(`clearHMS`),disabled:s||!C||!S,title:C?S?void 0:c(`printers.bulk.noneApplicable`):c(`printers.permission.noControl`),children:[(0,$.jsx)(D,{className:`w-3.5 h-3.5`}),c(`printers.bulk.actions.clearHMS`)]}),(0,$.jsxs)(Y,{variant:`secondary`,size:`sm`,onClick:()=>o(`clearPlate`),disabled:s||!w||!x,title:w?x?void 0:c(`printers.bulk.noneApplicable`):c(`printers.permission.noControl`),children:[(0,$.jsx)(k,{className:`w-3.5 h-3.5`}),c(`printers.bulk.actions.clearPlate`)]})]})}function Li({printerId:e,filePath:t,filename:n,onClose:r}){let[a,o]=(0,X.useState)(null),[s,c]=(0,X.useState)([]),[l,u]=(0,X.useState)(!1),[d,f]=(0,X.useState)(null),p=n.toLowerCase().split(`.`).pop()||``,m=p===`3mf`||p===`stl`,h=p===`gcode`||p===`3mf`;(0,X.useEffect)(()=>{o(m?`3d`:h?`gcode`:null)},[m,h]),(0,X.useEffect)(()=>{c([]),f(null),m&&(u(!0),i.getPrinterFilePlates(e,t).then(e=>c(e.plates||[])).catch(()=>c([])).finally(()=>u(!1)))},[t,m,e]);let g=s.length>1,_=d==null?null:s.find(e=>e.index===d)??null;return(0,$.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-6`,onClick:r,children:(0,$.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-4xl h-[80vh] flex flex-col`,onClick:e=>e.stopPropagation(),children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,$.jsx)(`h2`,{className:`text-lg font-semibold text-white truncate flex-1 mr-4`,children:n}),(0,$.jsx)(Y,{variant:`ghost`,size:`sm`,onClick:r,children:(0,$.jsx)(Pt,{className:`w-5 h-5`})})]}),(0,$.jsxs)(`div`,{className:`flex border-b border-bambu-dark-tertiary`,children:[(0,$.jsxs)(`button`,{onClick:()=>m&&o(`3d`),disabled:!m,className:`flex items-center gap-2 px-6 py-3 text-sm font-medium transition-colors ${a===`3d`?`text-bambu-green border-b-2 border-bambu-green`:m?`text-bambu-gray hover:text-white`:`text-bambu-gray/30 cursor-not-allowed`}`,children:[(0,$.jsx)(j,{className:`w-4 h-4`}),`3D Model`,!m&&(0,$.jsx)(`span`,{className:`text-xs`,children:`(not available)`})]}),(0,$.jsxs)(`button`,{onClick:()=>h&&o(`gcode`),disabled:!h,className:`flex items-center gap-2 px-6 py-3 text-sm font-medium transition-colors ${a===`gcode`?`text-bambu-green border-b-2 border-bambu-green`:h?`text-bambu-gray hover:text-white`:`text-bambu-gray/30 cursor-not-allowed`}`,children:[(0,$.jsx)(or,{className:`w-4 h-4`}),`G-code Preview`,!h&&(0,$.jsx)(`span`,{className:`text-xs`,children:`(not sliced)`})]})]}),(0,$.jsx)(`div`,{className:`flex-1 overflow-hidden p-4`,children:a===`3d`&&m?(0,$.jsxs)(`div`,{className:`w-full h-full flex flex-col gap-3`,children:[g&&(0,$.jsxs)(`div`,{className:`rounded-lg border border-bambu-dark-tertiary bg-bambu-dark p-3`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-bambu-gray mb-2`,children:[(0,$.jsx)(j,{className:`w-4 h-4`}),`Plates`,l&&(0,$.jsx)(H,{className:`w-3 h-3 animate-spin`})]}),(0,$.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-3 gap-2`,children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>f(null),className:`flex items-center gap-2 rounded-lg border p-2 text-left transition-colors ${d==null?`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary bg-bambu-dark-secondary hover:border-bambu-gray`}`,children:[(0,$.jsx)(`div`,{className:`w-10 h-10 rounded bg-bambu-dark-tertiary flex items-center justify-center`,children:(0,$.jsx)(j,{className:`w-5 h-5 text-bambu-gray`})}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`p`,{className:`text-sm text-white font-medium truncate`,children:`All Plates`}),(0,$.jsxs)(`p`,{className:`text-xs text-bambu-gray truncate`,children:[s.length,` plate`,s.length===1?``:`s`]})]}),d==null&&(0,$.jsx)(xn,{className:`w-4 h-4 text-bambu-green flex-shrink-0`})]}),s.map(n=>(0,$.jsxs)(`button`,{type:`button`,onClick:()=>f(n.index),className:`flex items-center gap-2 rounded-lg border p-2 text-left transition-colors ${d===n.index?`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary bg-bambu-dark-secondary hover:border-bambu-gray`}`,children:[n.has_thumbnail?(0,$.jsx)(`img`,{src:i.getPrinterFilePlateThumbnail(e,n.index,t),alt:`Plate ${n.index}`,className:`w-10 h-10 rounded object-cover bg-bambu-dark-tertiary`}):(0,$.jsx)(`div`,{className:`w-10 h-10 rounded bg-bambu-dark-tertiary flex items-center justify-center`,children:(0,$.jsx)(j,{className:`w-5 h-5 text-bambu-gray`})}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`p`,{className:`text-sm text-white font-medium truncate`,children:n.name||`Plate ${n.index}`}),(0,$.jsx)(`p`,{className:`text-xs text-bambu-gray truncate`,children:n.objects.length>0?n.objects.slice(0,2).join(`, `)+(n.objects.length>2?`…`:``):`${n.filaments.length} filament${n.filaments.length===1?``:`s`}`})]}),d===n.index&&(0,$.jsx)(xn,{className:`w-4 h-4 text-bambu-green flex-shrink-0`})]},n.index))]}),_&&(0,$.jsxs)(`div`,{className:`mt-3 text-xs text-bambu-gray flex flex-wrap gap-x-4 gap-y-1`,children:[(0,$.jsxs)(`span`,{children:[`Plate `,_.index]}),_.print_time_seconds!=null&&(0,$.jsxs)(`span`,{children:[`ETA `,Math.round(_.print_time_seconds/60),` min`]}),_.filament_used_grams!=null&&(0,$.jsxs)(`span`,{children:[_.filament_used_grams.toFixed(1),` g`]}),_.filaments.length>0&&(0,$.jsxs)(`span`,{children:[_.filaments.length,` filament`,_.filaments.length===1?``:`s`]})]})]}),(0,$.jsx)(`div`,{className:`flex-1`,children:(0,$.jsx)(dr,{url:i.getPrinterFileDownloadUrl(e,t),fileType:p,selectedPlateId:d,className:`w-full h-full`})})]}):a===`gcode`&&h?(0,$.jsx)(ae,{gcodeUrl:i.getPrinterFileGcodeUrl(e,t),className:`w-full h-full`}):(0,$.jsx)(`div`,{className:`w-full h-full flex items-center justify-center text-bambu-gray`,children:`No preview available for this file`})})]})})}function Ri(e){if(e===0)return`0 GB`;let t=e/(1024*1024*1024);return t>=1?`${t.toFixed(1)} GB`:`${(e/(1024*1024)).toFixed(0)} MB`}function zi(e,t){if(t)return Fn;switch(e.toLowerCase().split(`.`).pop()||``){case`3mf`:return ie;case`gcode`:return or;case`mp4`:case`avi`:return se;case`png`:case`jpg`:case`jpeg`:return tr;default:return V}}var Bi=[{value:`name-asc`,label:`Name (A-Z)`},{value:`name-desc`,label:`Name (Z-A)`},{value:`size-asc`,label:`Size (smallest)`},{value:`size-desc`,label:`Size (largest)`},{value:`date-asc`,label:`Date (oldest)`},{value:`date-desc`,label:`Date (newest)`}];function Vi({printerId:e,printerName:t,onClose:n}){let{t:r}=l(),{showToast:a}=te(),o=f(),[s,c]=(0,X.useState)(`/`),[u,d]=(0,X.useState)(new Set),[h,g]=(0,X.useState)(``),[_,v]=(0,X.useState)([]),[y,b]=(0,X.useState)(`name-asc`),[x,S]=(0,X.useState)(null),[C,w]=(0,X.useState)(null),E=(0,X.useRef)(null),D=(0,X.useRef)(null);(0,X.useEffect)(()=>{let e=e=>{e.key===`Escape`&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n]);let{data:O,isLoading:k,refetch:A}=p({queryKey:[`printerFiles`,e,s],queryFn:()=>i.getPrinterFiles(e,s)}),{data:M}=p({queryKey:[`printerStorage`,e],queryFn:()=>i.getPrinterStorage(e),staleTime:3e4}),N=(0,X.useMemo)(()=>[...O?.files??[]].filter(e=>!h||e.name.toLowerCase().includes(h.toLowerCase())).sort((e,t)=>{if(e.is_directory&&!t.is_directory)return-1;if(!e.is_directory&&t.is_directory)return 1;switch(y){case`name-asc`:return e.name.localeCompare(t.name);case`name-desc`:return t.name.localeCompare(e.name);case`size-asc`:return e.size-t.size;case`size-desc`:return t.size-e.size;case`date-asc`:return(e.mtime?qt(e.mtime)?.getTime()??0:0)-(t.mtime?qt(t.mtime)?.getTime()??0:0);case`date-desc`:{let n=e.mtime?qt(e.mtime)?.getTime()??0:0;return(t.mtime?qt(t.mtime)?.getTime()??0:0)-n}default:return e.name.localeCompare(t.name)}}),[O?.files,h,y]),P=!!O&&!O.warnings?.includes(`printer_unavailable`);(0,X.useEffect)(()=>{if(!P)return;let e=new Set(N.filter(e=>!e.is_directory).map(e=>e.path));d(t=>new Set([...t].filter(t=>e.has(t)))),E.current&&!e.has(E.current)&&(E.current=null)},[N,P]),(0,X.useEffect)(()=>()=>D.current?.abort(),[]);let F=m({mutationFn:async t=>{for(let n of t)await i.deletePrinterFile(e,n)},onSuccess:()=>{a(r(`printerFiles.toast.filesDeleted`,{count:_.length})),o.invalidateQueries({queryKey:[`printerFiles`,e]}),d(new Set),E.current=null,v([])},onError:e=>{a(r(`printerFiles.toast.deleteFailed`,{error:e.message}),`error`)}}),I=e=>{c(e),d(new Set),E.current=null},L=()=>{if(s===`/`)return;let e=s.split(`/`).filter(Boolean);e.pop(),c(e.length?`/`+e.join(`/`):`/`),d(new Set),E.current=null},R=(e,t)=>{t.stopPropagation();let n=N.filter(e=>!e.is_directory).map(e=>e.path),r=E.current?n.indexOf(E.current):-1,i=n.indexOf(e),a=t.shiftKey&&r!==-1&&i!==-1;a||(E.current=e),d(t=>{let o=new Set(t);if(a){let e=Math.min(r,i),t=Math.max(r,i);n.slice(e,t+1).forEach(e=>o.add(e))}else o.has(e)?o.delete(e):o.add(e);return o})};return(0,$.jsxs)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,onClick:n,children:[(0,$.jsxs)(`div`,{className:`w-full max-w-3xl max-h-[85vh] flex flex-col bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary overflow-hidden`,onClick:e=>e.stopPropagation(),children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary flex-shrink-0`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsx)(fe,{className:`w-5 h-5 text-bambu-green`}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:r(`printerFiles.title`)}),(0,$.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:t})]})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-4`,children:[M&&(M.used_bytes!=null||M.free_bytes!=null)&&(0,$.jsxs)(`div`,{className:`text-sm text-bambu-gray flex items-center gap-2`,children:[M.used_bytes!=null&&(0,$.jsxs)(`span`,{children:[r(`printerFiles.storageUsed`),` `,Ri(M.used_bytes)]}),M.used_bytes!=null&&M.free_bytes!=null&&(0,$.jsx)(`span`,{className:`text-bambu-dark-tertiary`,children:`|`}),M.free_bytes!=null&&(0,$.jsxs)(`span`,{children:[r(`printerFiles.storageFree`),` `,Ri(M.free_bytes)]})]}),(0,$.jsx)(`button`,{onClick:n,className:`text-bambu-gray hover:text-white transition-colors`,title:`Close file manager`,"aria-label":`Close file manager`,children:(0,$.jsx)(Pt,{className:`w-5 h-5`})})]})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2 p-3 border-b border-bambu-dark-tertiary bg-bambu-dark/50 flex-shrink-0`,children:[[{path:`/`,label:`Root`},{path:`/cache`,label:`Cache`},{path:`/model`,label:`Models`},{path:`/timelapse`,label:`Timelapse`}].map(e=>(0,$.jsx)(`button`,{onClick:()=>{I(e.path),g(``)},className:`px-3 py-1 text-sm rounded-full transition-colors ${s===e.path?`bg-bambu-green text-white`:`bg-bambu-dark-tertiary text-bambu-gray hover:text-white`}`,children:e.label},e.path)),(0,$.jsx)(`div`,{className:`flex-1`}),(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsx)(Ae,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,$.jsx)(`input`,{type:`text`,placeholder:r(`printerFiles.filterPlaceholder`),value:h,onChange:e=>g(e.target.value),className:`w-40 pl-8 pr-3 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`})]}),(0,$.jsxs)(`div`,{className:`relative flex items-center gap-1`,children:[(0,$.jsx)(T,{className:`w-4 h-4 text-bambu-gray`}),(0,$.jsx)(`select`,{value:y,onChange:e=>b(e.target.value),className:`appearance-none bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm py-1.5 pl-2 pr-6 focus:border-bambu-green focus:outline-none cursor-pointer`,title:`Sort files`,"aria-label":`Sort files`,children:Bi.map(e=>(0,$.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),(0,$.jsx)(Y,{variant:`secondary`,size:`sm`,onClick:()=>A(),disabled:k,"aria-label":r(`common.refresh`),title:r(`common.refresh`),children:(0,$.jsx)(dn,{className:`w-4 h-4 ${k?`animate-spin`:``}`})})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2 px-4 py-2 bg-bambu-dark text-sm flex-shrink-0`,children:[(0,$.jsx)(`button`,{onClick:L,disabled:s===`/`,className:`p-1 rounded hover:bg-bambu-dark-tertiary disabled:opacity-50 disabled:cursor-not-allowed`,title:`Go to parent folder`,"aria-label":`Go to parent folder`,children:(0,$.jsx)(Yn,{className:`w-4 h-4`})}),(0,$.jsx)(`span`,{className:`text-bambu-gray font-mono`,children:s})]}),(0,$.jsx)(`div`,{className:`flex-1 overflow-y-auto p-2 min-h-0`,children:k?(0,$.jsx)(`div`,{className:`flex items-center justify-center py-12`,children:(0,$.jsx)(H,{className:`w-8 h-8 text-bambu-green animate-spin`})}):O?.warnings?.includes(`printer_unavailable`)?(0,$.jsx)(`div`,{className:`text-center py-12 text-amber-600 dark:text-amber-400`,children:r(`printerFiles.printerUnavailable`)}):O?.files?.length?(0,$.jsx)(`div`,{className:`space-y-1`,children:N.map(e=>{let t=zi(e.name,e.is_directory),n=u.has(e.path);return(0,$.jsxs)(`div`,{className:`flex items-center gap-3 p-2 rounded-lg cursor-pointer transition-colors ${n?`bg-bambu-green/20 border border-bambu-green/50`:`hover:bg-bambu-dark-tertiary`}`,onClick:t=>{e.is_directory?I(e.path):R(e.path,t)},children:[e.is_directory?null:(0,$.jsx)(`button`,{onClick:t=>R(e.path,t),className:`flex-shrink-0 text-bambu-gray hover:text-white`,"aria-label":r(n?`printerFiles.deselectFile`:`printerFiles.selectFile`,{name:e.name}),title:r(`printerFiles.shiftSelectHint`),children:n?(0,$.jsx)(xn,{className:`w-5 h-5 text-bambu-green`}):(0,$.jsx)(fn,{className:`w-5 h-5`})}),(0,$.jsx)(t,{className:`w-5 h-5 flex-shrink-0 ${e.is_directory?`text-bambu-green`:`text-bambu-gray`}`}),(0,$.jsx)(`span`,{className:`flex-1 text-white truncate`,children:e.name}),!e.is_directory&&(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:zt(e.size)}),(e.name.toLowerCase().endsWith(`.3mf`)||e.name.toLowerCase().endsWith(`.gcode`)||e.name.toLowerCase().endsWith(`.stl`))&&(0,$.jsx)(`button`,{onClick:t=>{t.stopPropagation(),w({path:e.path,name:e.name})},className:`p-1 rounded hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green`,title:`3D View`,children:(0,$.jsx)(j,{className:`w-4 h-4`})})]}),e.is_directory&&(0,$.jsx)(Yn,{className:`w-4 h-4 text-bambu-gray rotate-180`})]},e.path)})}):(0,$.jsx)(`div`,{className:`text-center py-12 text-bambu-gray`,children:r(`printerFiles.noFiles`)})}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-t border-bambu-dark-tertiary bg-bambu-dark/50 flex-shrink-0`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,$.jsx)(`div`,{className:`text-sm text-bambu-gray`,children:u.size>0?`${u.size} selected`:h?`${O?.files?.filter(e=>e.name.toLowerCase().includes(h.toLowerCase())).length||0} of ${O?.files?.length||0} items`:`${O?.files?.length||0} items`}),O?.files?.some(e=>!e.is_directory)&&(0,$.jsx)(`div`,{className:`flex items-center gap-2`,children:u.size>0?(0,$.jsxs)(`button`,{onClick:()=>{d(new Set),E.current=null},className:`flex items-center gap-1 text-xs text-bambu-gray hover:text-white transition-colors`,children:[(0,$.jsx)(Mr,{className:`w-4 h-4`}),`Deselect All`]}):(0,$.jsxs)(`button`,{onClick:()=>{let e=N.filter(e=>!e.is_directory).map(e=>e.path);d(new Set(e)),E.current=null},className:`flex items-center gap-1 text-xs text-bambu-gray hover:text-white transition-colors`,children:[(0,$.jsx)(xn,{className:`w-4 h-4`}),`Select All`]})})]}),(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(Y,{variant:`secondary`,disabled:u.size===0||x!==null,onClick:async()=>{if(u.size===0)return;let n=N.filter(e=>!e.is_directory&&u.has(e.path)).map(e=>e.path);if(n.length===0)return;let o=new AbortController;D.current=o,S({current:0,total:n.length});try{let s=Object.fromEntries(n.map(e=>[e,O?.files.find(t=>t.path===e)?.size??0])),c=await i.downloadPrinterFilesAsZip(e,n,s,n.length===1?O?.files.find(e=>e.path===n[0])?.name??`printer-file`:`${t.replace(/[^a-zA-Z0-9]/g,`_`)}-files.zip`,n.length>1,o.signal,(e,t)=>S({current:e,total:t}));c.failed>0?a(r(`printerFiles.zipPartial`,{successful:c.successful,total:c.requested}),`warning`):a(r(`printerFiles.zipStarted`,{count:c.successful})),d(new Set),E.current=null}catch(e){a(r(`printerFiles.downloadFailed`,{error:e instanceof Error?e.message:r(`printerFiles.unknownError`)}),`error`)}finally{D.current===o&&(D.current=null),S(null)}},children:x?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(H,{className:`w-4 h-4 animate-spin`}),x.current,`/`,x.total]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(ar,{className:`w-4 h-4`}),`Download`,u.size>1?` (${u.size})`:``]})}),(0,$.jsxs)(Y,{variant:`secondary`,disabled:u.size===0||F.isPending,onClick:()=>{u.size!==0&&v(N.filter(e=>!e.is_directory&&u.has(e.path)).map(e=>e.path))},className:`text-red-700 hover:text-red-800 dark:text-red-400 dark:hover:text-red-300`,children:[F.isPending?(0,$.jsx)(H,{className:`w-4 h-4 animate-spin`}):(0,$.jsx)(Qt,{className:`w-4 h-4`}),r(`printerFiles.deleteButton`),u.size>1?` (${u.size})`:``]})]})]})]}),_.length>0&&(0,$.jsx)(In,{title:_.length>1?r(`printerFiles.deleteFiles`,{count:_.length}):r(`fileManager.deleteFile`),message:_.length>1?r(`printerFiles.deleteFilesConfirm`,{count:_.length}):r(`printerFiles.deleteFileConfirm`,{name:_[0].split(`/`).pop()}),confirmText:r(`common.delete`),variant:`danger`,onConfirm:()=>{F.mutate(_)},onCancel:()=>v([])}),C&&(0,$.jsx)(Li,{printerId:e,filePath:C.path,filename:C.name,onClose:()=>w(null)})]})}var Hi=`embeddedCameraState_`,Ui=5,Wi=2e3,Gi=3e4,Ki=5e3,qi={x:window.innerWidth-420,y:20,width:400,height:300};function Ji({printerId:e,printerName:t,viewerIndex:n=0,onClose:a}){let{t:s}=l(),c=f(),{showToast:u}=te(),{hasPermission:d}=lr(),h=`${Hi}${e}`,[g,_]=(0,X.useState)(()=>{try{let e=localStorage.getItem(h);if(e){let t=JSON.parse(e);return{x:Math.min(Math.max(0,t.x),window.innerWidth-100),y:Math.min(Math.max(0,t.y),window.innerHeight-100),width:Math.max(200,Math.min(t.width,window.innerWidth-20)),height:Math.max(150,Math.min(t.height,window.innerHeight-20))}}}catch{}let e=n*30;return{...qi,x:Math.max(0,qi.x-e),y:Math.max(0,qi.y+e)}}),[v,y]=(0,X.useState)(!1),[b,x]=(0,X.useState)(!1),[S,C]=(0,X.useState)({x:0,y:0}),[w,T]=(0,X.useState)(!1),[E,D]=(0,X.useState)(!1),[O,k]=(0,X.useState)(1),[A,j]=(0,X.useState)({x:0,y:0}),[M,N]=(0,X.useState)(!1),[P,F]=(0,X.useState)({x:0,y:0}),[I,L]=(0,X.useState)(null),[R,ee]=(0,X.useState)(null),[ne,z]=(0,X.useState)(!1),[re,B]=(0,X.useState)(!0),[ie,ae]=(0,X.useState)(Date.now()),[V,oe]=(0,X.useState)(0),[se,ce]=(0,X.useState)(!1),[le,ue]=(0,X.useState)(0),fe=(0,X.useRef)(null),pe=(0,X.useRef)(null),H=(0,X.useRef)(null),me=(0,X.useRef)(null),G=(0,X.useRef)(null),[be,xe]=(0,X.useState)(!1),[Se,K]=(0,X.useState)(!1),{data:Ce}=p({queryKey:[`printer`,e],queryFn:()=>i.getPrinter(e),enabled:e>0}),{data:we}=p({queryKey:[`printerStatus`,e],queryFn:()=>i.getPrinterStatus(e),refetchInterval:3e4,enabled:e>0}),Te=m({mutationFn:t=>i.setChamberLight(e,t),onMutate:async t=>{await c.cancelQueries({queryKey:[`printerStatus`,e]});let n=c.getQueryData([`printerStatus`,e]);return c.setQueryData([`printerStatus`,e],e=>({...e,chamber_light:t})),{previousStatus:n}},onSuccess:(e,t)=>{u(`Chamber light ${t?`on`:`off`}`)},onError:(t,n,r)=>{r?.previousStatus&&c.setQueryData([`printerStatus`,e],r.previousStatus),u(t.message||s(`printers.toast.failedToControlChamberLight`),`error`)}}),q=(we?.state===`RUNNING`||we?.state===`PAUSE`)&&(we?.printable_objects_count??0)>=2;(0,X.useEffect)(()=>{let e=setTimeout(()=>{localStorage.setItem(h,JSON.stringify(g))},500);return()=>clearTimeout(e)},[g,h]);let J=(0,X.useRef)(!1);(0,X.useEffect)(()=>{J.current=!1;let t=`/api/v1/printers/${e}/camera/stop`,n=()=>{if(e>0&&!J.current){J.current=!0;let e={},n=o();n&&(e.Authorization=`Bearer ${n}`),fetch(t,{method:`POST`,keepalive:!0,headers:e}).catch(()=>{})}},r=pe.current;return()=>{r&&(r.src=``),n(),H.current&&clearTimeout(H.current),me.current&&clearInterval(me.current),G.current&&clearInterval(G.current)}},[e]),(0,X.useEffect)(()=>{if(re){let e=setTimeout(()=>B(!1),3e3);return()=>clearTimeout(e)}},[re,ie]);let Ee=(0,X.useCallback)(()=>{if(V>=Ui){ce(!1),z(!0);return}let e=Math.min(Wi*2**V,Gi);ce(!0),ue(Math.ceil(e/1e3)),me.current=setInterval(()=>{ue(e=>e<=1?(me.current&&clearInterval(me.current),0):e-1)},1e3),H.current=setTimeout(()=>{oe(e=>e+1),ce(!1),B(!0),z(!1),pe.current&&(pe.current.src=``),ae(Date.now())},e)},[V]);(0,X.useEffect)(()=>{if(re||se||w){G.current&&=(clearInterval(G.current),null);return}return G.current=setInterval(async()=>{try{let t=await i.getCameraStatus(e);(t.stalled||!t.active&&!ne)&&(G.current&&=(clearInterval(G.current),null),B(!1),Ee())}catch{}},Ki),()=>{G.current&&=(clearInterval(G.current),null)}},[re,ne,se,w,e,Ee]),(0,X.useEffect)(()=>{let e=()=>{let e=!!document.fullscreenElement;D(e),e||(k(1),j({x:0,y:0}))};return document.addEventListener(`fullscreenchange`,e),()=>document.removeEventListener(`fullscreenchange`,e)},[]);let De=()=>{fe.current&&(document.fullscreenElement?document.exitFullscreen():fe.current.requestFullscreen())},Oe=()=>{k(e=>Math.min(e+.5,4))},ke=()=>{k(e=>{let t=Math.max(e-.5,1);return t===1&&j({x:0,y:0}),t})},Ae=e=>{e.preventDefault(),e.deltaY<0?Oe():ke()},je=e=>{O>1&&(e.preventDefault(),N(!0),F({x:e.clientX-A.x,y:e.clientY-A.y}))},Me=(0,X.useCallback)(()=>{if(!fe.current||!pe.current)return{x:200,y:150};let e=fe.current.getBoundingClientRect(),t=e.width*(O-1)/2,n=e.height*(O-1)/2;return{x:Math.max(50,t),y:Math.max(50,n)}},[O]),Ne=e=>{if(M&&O>1){let t=e.clientX-P.x,n=e.clientY-P.y,r=Me();j({x:Math.max(-r.x,Math.min(r.x,t)),y:Math.max(-r.y,Math.min(r.y,n))})}},Pe=()=>{N(!1)},Fe=e=>{if(e.length<2)return 0;let t=e[0].clientX-e[1].clientX,n=e[0].clientY-e[1].clientY;return Math.sqrt(t*t+n*n)},Ie=e=>e.length<2?{x:e[0].clientX,y:e[0].clientY}:{x:(e[0].clientX+e[1].clientX)/2,y:(e[0].clientY+e[1].clientY)/2},Le=e=>{e.touches.length===2?(e.preventDefault(),L(Fe(e.touches)),ee(Ie(e.touches))):e.touches.length===1&&O>1&&(e.preventDefault(),N(!0),F({x:e.touches[0].clientX-A.x,y:e.touches[0].clientY-A.y}))},Re=e=>{if(e.touches.length===2&&I!==null){e.preventDefault();let t=Fe(e.touches),n=t/I;k(e=>{let t=Math.max(1,Math.min(4,e*n));return t===1&&j({x:0,y:0}),t}),L(t);let r=Ie(e.touches);if(R){let e=Me();j(t=>({x:Math.max(-e.x,Math.min(e.x,t.x+(r.x-R.x))),y:Math.max(-e.y,Math.min(e.y,t.y+(r.y-R.y)))}))}ee(r)}else if(e.touches.length===1&&M&&O>1){e.preventDefault();let t=e.touches[0].clientX-P.x,n=e.touches[0].clientY-P.y,r=Me();j({x:Math.max(-r.x,Math.min(r.x,t)),y:Math.max(-r.y,Math.min(r.y,n))})}},ze=e=>{e.touches.length<2&&(L(null),ee(null)),e.touches.length===0&&N(!1)},Be=()=>{k(1),j({x:0,y:0})},Ve=()=>{B(!1),V{B(!1),z(!1),oe(0),ce(!1),H.current&&clearTimeout(H.current),me.current&&clearInterval(me.current)},Ue=()=>{B(!0),z(!1),oe(0),ce(!1),H.current&&clearTimeout(H.current),me.current&&clearInterval(me.current);let t={},n=o();n&&(t.Authorization=`Bearer ${n}`),fetch(`/api/v1/printers/${e}/camera/stop`,{method:`POST`,headers:t}).catch(()=>{}),pe.current&&(pe.current.src=``),setTimeout(()=>ae(Date.now()),100)},We=e=>{e.target.closest(`.no-drag`)||(y(!0),C({x:e.clientX-g.x,y:e.clientY-g.y}))},Ge=e=>{if(e.target.closest(`.no-drag`))return;let t=e.touches[0];y(!0),C({x:t.clientX-g.x,y:t.clientY-g.y})},Ke=e=>{e.stopPropagation(),x(!0)},qe=e=>{e.stopPropagation(),x(!0)};(0,X.useEffect)(()=>{let e=e=>{if(v)_(t=>({...t,x:Math.max(0,Math.min(e.clientX-S.x,window.innerWidth-t.width)),y:Math.max(0,Math.min(e.clientY-S.y,window.innerHeight-t.height))}));else if(b&&fe.current){let t=fe.current.getBoundingClientRect();_(n=>({...n,width:Math.max(200,Math.min(e.clientX-t.left,window.innerWidth-n.x-10)),height:Math.max(150,Math.min(e.clientY-t.top,window.innerHeight-n.y-10))}))}},t=e=>{if(!v&&!b)return;e.preventDefault();let t=e.touches[0];if(v)_(e=>({...e,x:Math.max(0,Math.min(t.clientX-S.x,window.innerWidth-e.width)),y:Math.max(0,Math.min(t.clientY-S.y,window.innerHeight-e.height))}));else if(b&&fe.current){let e=fe.current.getBoundingClientRect();_(n=>({...n,width:Math.max(200,Math.min(t.clientX-e.left,window.innerWidth-n.x-10)),height:Math.max(150,Math.min(t.clientY-e.top,window.innerHeight-n.y-10))}))}},n=()=>{y(!1),x(!1)};if(v||b)return document.addEventListener(`mousemove`,e),document.addEventListener(`mouseup`,n),document.addEventListener(`touchmove`,t,{passive:!1}),document.addEventListener(`touchend`,n),document.addEventListener(`touchcancel`,n),()=>{document.removeEventListener(`mousemove`,e),document.removeEventListener(`mouseup`,n),document.removeEventListener(`touchmove`,t),document.removeEventListener(`touchend`,n),document.removeEventListener(`touchcancel`,n)}},[v,b,S]);let Je=r(`/api/v1/printers/${e}/camera/stream?fps=15&t=${ie}`);return(0,$.jsxs)(`div`,{ref:fe,className:`${E?`fixed inset-0 z-[100]`:`fixed z-40 rounded-lg shadow-2xl border border-bambu-dark-tertiary`} bg-bambu-dark-secondary overflow-hidden`,style:E?void 0:{left:g.x,top:g.y,width:w?200:g.width,height:w?40:g.height,cursor:v?`grabbing`:`default`},children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-2 bg-bambu-dark border-b border-bambu-dark-tertiary cursor-grab active:cursor-grabbing`,onMouseDown:We,onTouchStart:Ge,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-white truncate`,children:[(0,$.jsx)(de,{className:`w-4 h-4 text-bambu-gray flex-shrink-0`}),(0,$.jsx)(`span`,{className:`truncate`,children:Ce?.name||t})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1 no-drag`,children:[(0,$.jsx)(`button`,{onClick:()=>Te.mutate(!we?.chamber_light),disabled:!we?.connected||Te.isPending||!d(`printers:control`),className:`p-1 rounded disabled:opacity-50 ${we?.chamber_light?`bg-yellow-500/20 hover:bg-yellow-500/30`:`hover:bg-bambu-dark-tertiary`}`,title:d(`printers:control`)?s(`camera.chamberLight`):s(`printers.permission.noControl`),children:(0,$.jsx)(_e,{on:we?.chamber_light??!1,className:`w-3.5 h-3.5`})}),(0,$.jsx)(`button`,{onClick:()=>xe(!0),disabled:!q||!d(`printers:control`),className:`p-1 rounded disabled:opacity-50 ${q&&d(`printers:control`)?`hover:bg-bambu-dark-tertiary`:``}`,title:d(`printers:control`)?s(q?`printers.skipObjects.tooltip`:`printers.skipObjects.onlyWhilePrinting`):s(`printers.permission.noControl`),children:(0,$.jsx)(ve,{className:`w-3.5 h-3.5 text-bambu-gray`})}),(0,$.jsx)(`button`,{onClick:Ue,disabled:re||se,className:`p-1 hover:bg-bambu-dark-tertiary rounded disabled:opacity-50`,title:`Refresh stream`,children:(0,$.jsx)(dn,{className:`w-3.5 h-3.5 text-bambu-gray ${re?`animate-spin`:``}`})}),(0,$.jsx)(`button`,{onClick:()=>K(!0),className:`p-1 hover:bg-bambu-dark-tertiary rounded`,title:s(`camera.diagnose.button`),children:(0,$.jsx)(an,{className:`w-3.5 h-3.5 text-bambu-gray`})}),(0,$.jsx)(`button`,{onClick:De,className:`p-1 hover:bg-bambu-dark-tertiary rounded`,title:E?`Exit fullscreen`:`Fullscreen`,children:E?(0,$.jsx)(ge,{className:`w-3.5 h-3.5 text-bambu-gray`}):(0,$.jsx)(wr,{className:`w-3.5 h-3.5 text-bambu-gray`})}),(0,$.jsx)(`button`,{onClick:()=>T(!w),className:`p-1 hover:bg-bambu-dark-tertiary rounded`,title:w?`Expand`:`Minimize`,children:w?(0,$.jsx)(he,{className:`w-3.5 h-3.5 text-bambu-gray`}):(0,$.jsx)(U,{className:`w-3.5 h-3.5 text-bambu-gray`})}),(0,$.jsx)(`button`,{onClick:a,className:`p-1 hover:bg-red-500/20 rounded`,title:`Close`,children:(0,$.jsx)(Pt,{className:`w-3.5 h-3.5 text-bambu-gray hover:text-red-600 dark:hover:text-red-400`})})]})]}),!w&&(0,$.jsxs)(`div`,{className:`relative w-full bg-black flex items-center justify-center overflow-hidden h-[calc(100%-40px)]`,onWheel:Ae,onMouseMove:Ne,onMouseUp:Pe,onMouseLeave:Pe,onTouchStart:Le,onTouchMove:Re,onTouchEnd:ze,style:{touchAction:`none`},children:[re&&!se&&(0,$.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-black/50 z-10`,children:(0,$.jsx)(dn,{className:`w-6 h-6 text-bambu-gray animate-spin`})}),se&&(0,$.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-black/80 z-10`,children:(0,$.jsxs)(`div`,{className:`text-center p-2`,children:[(0,$.jsx)(en,{className:`w-6 h-6 text-orange-400 mx-auto mb-2`}),(0,$.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[`Reconnecting in `,le,`s...`]})]})}),ne&&!se&&(0,$.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-black z-10`,children:(0,$.jsxs)(`div`,{className:`text-center p-2`,children:[(0,$.jsx)(Ot,{className:`w-6 h-6 text-orange-400 mx-auto mb-2`}),(0,$.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:s(`camera.unavailable`)}),(0,$.jsxs)(`div`,{className:`flex gap-2 justify-center`,children:[(0,$.jsx)(`button`,{onClick:Ue,className:`px-2 py-1 text-xs bg-bambu-green text-white rounded hover:bg-bambu-green/80`,children:s(`camera.retry`)}),(0,$.jsx)(`button`,{onClick:()=>K(!0),className:`px-2 py-1 text-xs bg-bambu-dark border border-bambu-dark-tertiary text-bambu-gray hover:text-white rounded transition-colors`,children:s(`camera.diagnose.button`)})]})]})}),(0,$.jsx)(`img`,{ref:pe,src:Je,alt:`Camera stream`,className:`max-w-full max-h-full object-contain select-none`,style:{transform:`scale(${O}) translate(${A.x/O}px, ${A.y/O}px) rotate(${Ce?.camera_rotation||0}deg)`,...Ce?.camera_rotation===90||Ce?.camera_rotation===270?{maxWidth:`100%`,maxHeight:`100%`}:{},cursor:O>1?M?`grabbing`:`grab`:`default`},onError:Ve,onLoad:He,onMouseDown:je,draggable:!1},ie),(0,$.jsxs)(`div`,{className:`absolute bottom-2 left-2 flex items-center gap-1 bg-black/60 rounded px-1.5 py-1 no-drag`,children:[(0,$.jsx)(`button`,{onClick:ke,disabled:O<=1,className:`p-1 hover:bg-white/10 rounded disabled:opacity-30`,title:`Zoom out`,children:(0,$.jsx)(It,{className:`w-3.5 h-3.5 text-white`})}),(0,$.jsxs)(`button`,{onClick:Be,className:`px-1.5 py-0.5 text-xs text-white hover:bg-white/10 rounded min-w-[32px]`,title:`Reset zoom`,children:[Math.round(O*100),`%`]}),(0,$.jsx)(`button`,{onClick:Oe,disabled:O>=4,className:`p-1 hover:bg-white/10 rounded disabled:opacity-30`,title:`Zoom in`,children:(0,$.jsx)(Ft,{className:`w-3.5 h-3.5 text-white`})})]}),!E&&(0,$.jsx)(`div`,{className:`absolute bottom-0 right-0 w-6 h-6 cursor-se-resize no-drag hover:bg-white/10 rounded-tl transition-colors`,onMouseDown:Ke,onTouchStart:qe,title:`Drag to resize`,children:(0,$.jsx)(`svg`,{className:`w-6 h-6 text-bambu-gray/70 hover:text-bambu-gray`,viewBox:`0 0 24 24`,fill:`currentColor`,children:(0,$.jsx)(`path`,{d:`M22 22H20V20H22V22ZM22 18H20V16H22V18ZM18 22H16V20H18V22ZM22 14H20V12H22V14ZM18 18H16V16H18V18ZM14 22H12V20H14V22ZM22 10H20V8H22V10ZM18 14H16V12H18V14ZM14 18H12V16H14V18ZM10 22H8V20H10V22Z`})})})]}),(0,$.jsx)(ye,{printerId:e,isOpen:be,onClose:()=>xe(!1)}),Se&&(0,$.jsx)(W,{printerId:e,printerName:Ce?.name||null,onClose:()=>K(!1)})]})}function Yi({printerId:e,printerName:t,onClose:n}){let{t:r}=l(),a=f(),[o,s]=(0,X.useState)(!0),[c,u]=(0,X.useState)(new Set),[d,h]=(0,X.useState)(``),[g,_]=(0,X.useState)(`all`),v=(0,X.useRef)(null),{data:y,isLoading:b,refetch:x}=p({queryKey:[`mqtt-logs`,e],queryFn:()=>i.getMQTTLogs(e),refetchInterval:1e3}),C=m({mutationFn:()=>i.enableMQTTLogging(e),onSuccess:()=>{a.invalidateQueries({queryKey:[`mqtt-logs`,e]})}}),w=m({mutationFn:()=>i.disableMQTTLogging(e),onSuccess:()=>{a.invalidateQueries({queryKey:[`mqtt-logs`,e]})}}),T=m({mutationFn:()=>i.clearMQTTLogs(e),onSuccess:()=>{a.invalidateQueries({queryKey:[`mqtt-logs`,e]})}});(0,X.useEffect)(()=>{let e=e=>{e.key===`Escape`&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n]),(0,X.useEffect)(()=>{o&&v.current&&(v.current.scrollTop=v.current.scrollHeight)},[y?.logs,o]);let D=e=>{u(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},O=e=>new Date(e).toLocaleTimeString(`en-US`,{hour12:!1,fractionalSecondDigits:3}),k=(e,t)=>{if(e==null)return``;let n=typeof e==`string`?JSON.parse(e):e,r=JSON.stringify(n,null,t?2:0);return!t&&r.length>100?r.substring(0,100)+`...`:r},A=y?.logging_enabled??!1,j=(0,X.useMemo)(()=>y?.logs??[],[y?.logs]),M=(0,X.useMemo)(()=>j.filter(e=>{if(g!==`all`&&e.direction!==g)return!1;if(d.trim()){let t=d.toLowerCase(),n=e.topic.toLowerCase().includes(t),r=JSON.stringify(e.payload).toLowerCase().includes(t);return n||r}return!0}),[j,d,g]);return(0,$.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,$.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg max-w-4xl w-full max-h-[85vh] flex flex-col`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:r(`mqttDebug.title`)}),(0,$.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:t})]}),(0,$.jsx)(`button`,{onClick:n,className:`text-bambu-gray hover:text-white transition-colors`,children:(0,$.jsx)(Pt,{className:`w-5 h-5`})})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 p-4 border-b border-bambu-dark-tertiary`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[A?(0,$.jsxs)(Y,{size:`sm`,variant:`secondary`,onClick:()=>w.mutate(),disabled:w.isPending,children:[(0,$.jsx)(fn,{className:`w-4 h-4`}),r(`mqttDebug.stopLogging`)]}):(0,$.jsxs)(Y,{size:`sm`,onClick:()=>C.mutate(),disabled:C.isPending,children:[(0,$.jsx)(ke,{className:`w-4 h-4`}),r(`mqttDebug.startLogging`)]}),(0,$.jsxs)(Y,{size:`sm`,variant:`secondary`,onClick:()=>T.mutate(),disabled:T.isPending||j.length===0,children:[(0,$.jsx)(Qt,{className:`w-4 h-4`}),r(`mqttDebug.clearLog`)]}),(0,$.jsx)(Y,{size:`sm`,variant:`secondary`,onClick:()=>x(),disabled:b,children:(0,$.jsx)(dn,{className:`w-4 h-4 ${b?`animate-spin`:``}`})}),(0,$.jsx)(`div`,{className:`flex-1`}),(0,$.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-bambu-gray cursor-pointer`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:o,onChange:e=>s(e.target.checked),className:`rounded border-bambu-dark-tertiary`}),`Auto-scroll`]}),(0,$.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[M.length,`/`,j.length]})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsxs)(`div`,{className:`relative flex-1`,children:[(0,$.jsx)(Ae,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,$.jsx)(`input`,{type:`text`,placeholder:r(`mqttDebug.searchPlaceholder`),value:d,onChange:e=>h(e.target.value),className:`w-full pl-8 pr-3 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`}),d&&(0,$.jsx)(`button`,{onClick:()=>h(``),className:`absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white`,children:(0,$.jsx)(Pt,{className:`w-4 h-4`})})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1 bg-bambu-dark rounded border border-bambu-dark-tertiary`,children:[(0,$.jsx)(`button`,{onClick:()=>_(`all`),className:`px-2 py-1.5 text-xs rounded-l transition-colors ${g===`all`?`bg-bambu-green text-white`:`text-bambu-gray hover:text-white`}`,children:r(`mqttDebug.all`)}),(0,$.jsxs)(`button`,{onClick:()=>_(`in`),className:`px-2 py-1.5 text-xs transition-colors flex items-center gap-1 ${g===`in`?`bg-blue-500 text-white`:`text-bambu-gray hover:text-white`}`,children:[(0,$.jsx)(S,{className:`w-3 h-3`}),r(`mqttDebug.incoming`)]}),(0,$.jsxs)(`button`,{onClick:()=>_(`out`),className:`px-2 py-1.5 text-xs rounded-r transition-colors flex items-center gap-1 ${g===`out`?`bg-green-500 text-white`:`text-bambu-gray hover:text-white`}`,children:[(0,$.jsx)(E,{className:`w-3 h-3`}),r(`mqttDebug.outgoing`)]})]})]})]}),(0,$.jsx)(`div`,{ref:v,className:`flex-1 overflow-auto p-4 font-mono text-xs bg-black min-h-[400px]`,children:j.length===0?(0,$.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full text-bambu-gray`,children:[(0,$.jsx)(`p`,{className:`mb-2`,children:r(`mqttDebug.noMessages`)}),!A&&(0,$.jsx)(`p`,{className:`text-sm`,children:r(`mqttDebug.startLoggingHint`)})]}):M.length===0?(0,$.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full text-bambu-gray`,children:[(0,$.jsx)(`p`,{className:`mb-2`,children:r(`mqttDebug.noMessagesMatch`)}),(0,$.jsx)(`p`,{className:`text-sm`,children:r(`mqttDebug.adjustFilterHint`)})]}):(0,$.jsx)(`div`,{className:`space-y-1`,children:M.map((e,t)=>{let n=c.has(t),i=e.direction===`in`;return(0,$.jsxs)(`div`,{className:`p-2 rounded cursor-pointer hover:bg-bambu-dark-secondary transition-colors ${n?`bg-bambu-dark-secondary`:``}`,onClick:()=>D(t),children:[(0,$.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,$.jsx)(`span`,{className:`text-bambu-gray shrink-0`,children:O(e.timestamp)}),(0,$.jsx)(`span`,{className:`shrink-0 ${i?`text-blue-400`:`text-green-400`}`,title:r(i?`mqttDebug.incoming`:`mqttDebug.outgoing`),children:i?(0,$.jsx)(S,{className:`w-3 h-3`}):(0,$.jsx)(E,{className:`w-3 h-3`})}),(0,$.jsx)(`span`,{className:`text-purple-400 shrink-0`,children:e.topic})]}),n?(0,$.jsx)(`pre`,{className:`mt-2 p-3 bg-gray-900 border border-gray-700 rounded text-green-400 overflow-x-auto whitespace-pre-wrap break-all max-h-96 overflow-y-auto text-xs`,children:k(e.payload,!0)}):(0,$.jsx)(`pre`,{className:`mt-1 text-white/80 truncate`,children:k(e.payload,!1)})]},t)})})}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-t border-bambu-dark-tertiary`,children:[(0,$.jsx)(`div`,{className:`text-sm text-bambu-gray`,children:A?(0,$.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`w-2 h-2 bg-green-500 rounded-full animate-pulse`}),r(`mqttDebug.loggingActive`)]}):(0,$.jsx)(`span`,{children:r(`mqttDebug.loggingStopped`)})}),(0,$.jsx)(Y,{variant:`secondary`,onClick:n,children:r(`common.close`)})]})]})})}function Xi(e){if(!e)return`idle`;switch(e.class){case`failure`:case`warning`:case`safe`:case`error`:return e.class;default:return`unknown`}}function Zi(e){return e===`failure`||e===`warning`||e===`safe`}function Qi({printerName:e,detection:t,lastError:n,onClose:r}){let{t:i}=l(),a=Tn();(0,X.useEffect)(()=>{let e=e=>{e.key===`Escape`&&r()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[r]);let o=Xi(t),s=o===`failure`?`text-status-error`:o===`warning`?`text-status-warning`:o===`safe`?`text-status-ok`:o===`error`?`text-amber-600 dark:text-amber-400`:`text-bambu-gray`,c=t?.error??n;return(0,$.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,children:(0,$.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg shadow-xl max-w-lg w-full max-h-[80vh] flex flex-col`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(K,{className:`w-5 h-5 text-bambu-green`}),(0,$.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`printers.aiDetection.modalTitle`,{name:e})})]}),(0,$.jsx)(`button`,{onClick:r,className:`p-1 hover:bg-bambu-dark-tertiary rounded-lg transition-colors`,"aria-label":i(`common.close`),children:(0,$.jsx)(Pt,{className:`w-5 h-5 text-bambu-gray`})})]}),(0,$.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-4 space-y-4 text-sm`,children:[(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsxs)(`div`,{className:`flex justify-between`,children:[(0,$.jsx)(`span`,{className:`text-bambu-gray`,children:i(`printers.aiDetection.currentStatus`)}),(0,$.jsx)(`span`,{className:`font-medium ${s}`,children:i(`printers.aiDetection.${o}`)})]}),t&&Zi(o)&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`flex justify-between`,children:[(0,$.jsx)(`span`,{className:`text-bambu-gray`,children:i(`printers.aiDetection.score`)}),(0,$.jsx)(`span`,{className:`text-white font-mono`,children:t.score.toFixed(3)})]}),(0,$.jsxs)(`div`,{className:`flex justify-between`,children:[(0,$.jsx)(`span`,{className:`text-bambu-gray`,children:i(`printers.aiDetection.framesAnalyzed`)}),(0,$.jsx)(`span`,{className:`text-white font-mono`,children:t.frame_count})]})]}),o===`error`&&(0,$.jsx)(`p`,{className:`text-bambu-gray`,children:i(`printers.aiDetection.errorHint`)}),!t&&(0,$.jsx)(`p`,{className:`text-bambu-gray`,children:i(`printers.aiDetection.idleHint`)})]}),c&&(0,$.jsxs)(`div`,{className:`flex items-start gap-2 p-3 rounded-lg bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30`,children:[(0,$.jsx)(R,{className:`w-4 h-4 mt-0.5 flex-shrink-0 text-red-700 dark:text-red-400`}),(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`div`,{className:`font-medium text-red-700 dark:text-red-400`,children:i(`printers.aiDetection.lastError`)}),(0,$.jsx)(`p`,{className:`text-red-700/80 dark:text-red-300/80 break-words mt-1`,children:c})]})]})]}),(0,$.jsx)(`div`,{className:`p-4 border-t border-bambu-dark-tertiary flex items-center justify-end`,children:(0,$.jsxs)(`button`,{onClick:()=>a(`/settings?tab=failure-detection`),className:`flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium rounded-lg bg-bambu-dark-tertiary text-bambu-gray hover:text-white transition-colors`,children:[(0,$.jsx)(En,{className:`w-4 h-4`}),i(`printers.aiDetection.openSettings`)]})})]})})}function $i({printerId:e,printerModel:t,loadedFilamentTypes:n,loadedFilaments:r,loadedVariants:a,variant:o=`card`}){let{t:s}=l(),{data:c}=p({queryKey:[`queue`,e,`pending`,t],queryFn:()=>i.getQueue(e,`pending`,t||void 0),refetchInterval:3e4}),u=c?nn(c,n,r,a):void 0,d=u?.length||0;if(d===0)return null;let f=u?.[0];return(0,$.jsx)(bn,{to:`/queue`,className:o===`panelExtension`?`block mt-2 border-t border-bambu-dark-tertiary pt-2 pl-1 hover:opacity-90 transition-opacity`:`block mb-3 p-3 bg-bambu-dark rounded-lg hover:bg-bambu-dark-tertiary transition-colors`,children:(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 flex-1`,children:[(0,$.jsx)(P,{className:`w-5 h-5 text-yellow-600 dark:text-yellow-400 flex-shrink-0`}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:s(`queue.nextInQueue`)}),(0,$.jsx)(`p`,{className:`text-sm text-white truncate`,children:f?_r(f):``})]})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[(0,$.jsxs)(`span`,{className:`text-xs text-bambu-gray flex items-center gap-1`,children:[(0,$.jsx)(vn,{className:`w-3 h-3`}),f?.scheduled_time?Kt(f.scheduled_time,`system`,s):s(`time.waiting`)]}),d>1&&(0,$.jsxs)(`span`,{className:`text-xs px-1.5 py-0.5 bg-yellow-100 dark:bg-yellow-400/20 text-yellow-700 dark:text-yellow-400 rounded`,children:[`+`,d-1]}),(0,$.jsx)(pn,{className:`w-4 h-4 text-bambu-gray`})]})]})})}function ea({printerId:e}){let{t}=l(),{data:n}=p({queryKey:[`haSensorReadings`,e],queryFn:()=>i.getHASensorReadings(e),refetchInterval:15e3});if(!n?.length)return null;let r=e=>v(e,t);return(0,$.jsxs)(`div`,{className:`flex items-center gap-2 mt-2`,children:[(0,$.jsx)(ue,{className:`w-[var(--pc-i35,0.875rem)] h-[var(--pc-i35,0.875rem)] text-blue-600 dark:text-blue-400 flex-shrink-0`}),(0,$.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:t(`haSensors.label`)}),(0,$.jsx)(`div`,{className:`h-[2px] w-5 bg-bambu-dark-tertiary/50`}),(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:n.map(e=>{let n=b(e),i=!e.reachable||e.state===null;return(0,$.jsxs)(`span`,{title:e.block_print?t(`haSensors.blocksPrints`,{entity:e.entity_id}):e.entity_id,className:`px-2 py-0.5 text-xs rounded flex items-center gap-1 ${i?`bg-bambu-dark-tertiary/50 text-bambu-gray`:e.alerting?`bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400`:`bg-bambu-dark-tertiary text-bambu-gray`}`,children:[(0,$.jsx)(n,{className:`w-[var(--pc-i25,0.625rem)] h-[var(--pc-i25,0.625rem)]`}),(0,$.jsx)(`span`,{children:e.name}),(0,$.jsx)(`span`,{className:`font-medium`,children:r(e)})]},e.id)})})]})}var ta=[{value:`6h`,label:`6h`,hours:6},{value:`24h`,label:`24h`,hours:24},{value:`48h`,label:`48h`,hours:48},{value:`7d`,label:`7d`,hours:168}];function na({isOpen:e,onClose:t,printerId:n,printerName:r,amsId:a,amsLabel:o,initialMode:s=`humidity`,thresholds:c}){let{t:u}=l(),[d,f]=(0,X.useState)(`24h`),[m,h]=(0,X.useState)(s),{data:g}=p({queryKey:[`settings`],queryFn:i.getSettings}),v=g?.time_format||`system`;(0,X.useEffect)(()=>{if(!e)return;let n=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,n),()=>window.removeEventListener(`keydown`,n)},[e,t]);let b=ta.find(e=>e.value===d)?.hours||24,{data:x,isLoading:S,error:C}=p({queryKey:[`ams-history`,n,a,b],queryFn:()=>i.getAMSHistory(n,a,b),enabled:e,refetchInterval:6e4});if(!e)return null;let w=x?.data.map(e=>({time:(qt(e.recorded_at)||new Date).getTime(),humidity:e.humidity,temperature:e.temperature}))||[],T=Date.now()-b*60*60*1e3,E=Date.now(),D=[...w];if(D.length>0){let e=D[0];e.time>T&&D.unshift({...e,time:T});let t=D[D.length-1];t.time{let t=e.filter(e=>e!=null);if(t.length<4)return`stable`;let n=t.slice(0,Math.floor(t.length/4)),r=t.slice(-Math.floor(t.length/4)),i=n.reduce((e,t)=>e+t,0)/n.length,a=r.reduce((e,t)=>e+t,0)/r.length-i;return Math.abs(a)<2?`stable`:a>0?`up`:`down`},R=L(D.map(e=>e.humidity)),ee=L(D.map(e=>e.temperature)),te=({trend:e})=>e===`up`?(0,$.jsx)(_,{className:`w-4 h-4 text-red-600 dark:text-red-400`}):e===`down`?(0,$.jsx)(Ke,{className:`w-4 h-4 text-green-600 dark:text-green-400`}):(0,$.jsx)(G,{className:`w-4 h-4 text-gray-400 dark:text-bambu-gray`}),ne=e=>e==null?`#9ca3af`:e<=k?`#22a352`:e<=j?`#d4a017`:`#c62828`,z=e=>e==null?`#9ca3af`:e<=M?`#22a352`:e<=N?`#d4a017`:`#c62828`,re=`var(--bg-secondary)`,B=`var(--bg-primary)`,ie=`var(--border-color)`,ae=`var(--text-primary)`,V=`var(--text-secondary)`,oe=`var(--text-muted)`;return(0,$.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50`,onClick:t,children:(0,$.jsxs)(`div`,{className:`rounded-xl w-full max-w-4xl max-h-[90vh] overflow-hidden shadow-xl`,style:{backgroundColor:re},onClick:e=>e.stopPropagation(),children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 border-b`,style:{borderColor:ie},children:[(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`h2`,{className:`text-lg font-semibold`,style:{color:ae},children:[o,` `,u(`common.history`,`History`)]}),(0,$.jsx)(`p`,{className:`text-sm`,style:{color:V},children:r})]}),(0,$.jsx)(`button`,{onClick:t,className:`p-2 rounded-lg transition-colors`,style:{color:V},children:(0,$.jsx)(Pt,{className:`w-5 h-5`})})]}),(0,$.jsxs)(`div`,{className:`p-6 space-y-6 overflow-y-auto max-h-[calc(90vh-80px)]`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between max-[550px]:flex-col max-[550px]:items-start max-[550px]:gap-3`,children:[(0,$.jsxs)(`div`,{className:`inline-flex gap-1 rounded-lg p-1 max-w-full flex-wrap w-fit`,style:{backgroundColor:B},children:[(0,$.jsxs)(`button`,{onClick:()=>h(`humidity`),className:`flex items-center gap-2 px-3 py-1.5 text-sm rounded-md transition-colors ${m===`humidity`?`bg-blue-600 text-white`:``}`,style:m===`humidity`?void 0:{color:V},children:[(0,$.jsx)(y,{className:`w-4 h-4`}),u(`common.humidity`,`Humidity`)]}),(0,$.jsxs)(`button`,{onClick:()=>h(`temperature`),className:`flex items-center gap-2 px-3 py-1.5 text-sm rounded-md transition-colors ${m===`temperature`?`bg-orange-600 text-white`:``}`,style:m===`temperature`?void 0:{color:V},children:[(0,$.jsx)(Me,{className:`w-4 h-4`}),u(`common.temperature`,`Temperature`)]})]}),(0,$.jsx)(`div`,{className:`inline-flex gap-1 rounded-lg p-1 max-w-full flex-wrap w-fit`,style:{backgroundColor:B},children:ta.map(e=>(0,$.jsx)(`button`,{onClick:()=>f(e.value),className:`px-3 py-1 text-sm rounded-md transition-colors ${d===e.value?`bg-bambu-green text-white`:``}`,style:d===e.value?void 0:{color:V},children:e.label},e.value))})]}),(0,$.jsx)(`div`,{className:`grid grid-cols-4 gap-4 max-[550px]:grid-cols-2`,children:m===`humidity`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`rounded-lg p-4 max-[550px]:order-2`,style:{backgroundColor:B},children:[(0,$.jsx)(`p`,{className:`text-xs`,style:{color:V},children:u(`common.current`,`Current`)}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`p`,{className:`text-2xl font-bold`,style:{color:ne(F)},children:F==null?`—`:`${F}%`}),(0,$.jsx)(te,{trend:R})]})]}),(0,$.jsxs)(`div`,{className:`rounded-lg p-4 max-[550px]:order-4`,style:{backgroundColor:B},children:[(0,$.jsx)(`p`,{className:`text-xs`,style:{color:V},children:u(`common.average`,`Average`)}),(0,$.jsx)(`p`,{className:`text-2xl font-bold`,style:{color:ae},children:x?.avg_humidity==null?`—`:`${x.avg_humidity}%`})]}),(0,$.jsxs)(`div`,{className:`rounded-lg p-4 max-[550px]:order-1`,style:{backgroundColor:B},children:[(0,$.jsx)(`p`,{className:`text-xs`,style:{color:V},children:u(`common.min`,`Min`)}),(0,$.jsx)(`p`,{className:`text-2xl font-bold text-green-500`,children:x?.min_humidity==null?`—`:`${x.min_humidity}%`})]}),(0,$.jsxs)(`div`,{className:`rounded-lg p-4 max-[550px]:order-3`,style:{backgroundColor:B},children:[(0,$.jsx)(`p`,{className:`text-xs`,style:{color:V},children:u(`common.max`,`Max`)}),(0,$.jsx)(`p`,{className:`text-2xl font-bold text-red-500`,children:x?.max_humidity==null?`—`:`${x.max_humidity}%`})]})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`rounded-lg p-4 max-[550px]:order-2`,style:{backgroundColor:B},children:[(0,$.jsx)(`p`,{className:`text-xs`,style:{color:V},children:u(`common.current`,`Current`)}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`p`,{className:`text-2xl font-bold`,style:{color:z(I)},children:I==null?`—`:`${I}°C`}),(0,$.jsx)(te,{trend:ee})]})]}),(0,$.jsxs)(`div`,{className:`rounded-lg p-4 max-[550px]:order-4`,style:{backgroundColor:B},children:[(0,$.jsx)(`p`,{className:`text-xs`,style:{color:V},children:u(`common.average`,`Average`)}),(0,$.jsx)(`p`,{className:`text-2xl font-bold`,style:{color:ae},children:x?.avg_temperature==null?`—`:`${x.avg_temperature}°C`})]}),(0,$.jsxs)(`div`,{className:`rounded-lg p-4 max-[550px]:order-1`,style:{backgroundColor:B},children:[(0,$.jsx)(`p`,{className:`text-xs`,style:{color:V},children:u(`common.min`,`Min`)}),(0,$.jsx)(`p`,{className:`text-2xl font-bold text-blue-500`,children:x?.min_temperature==null?`—`:`${x.min_temperature}°C`})]}),(0,$.jsxs)(`div`,{className:`rounded-lg p-4 max-[550px]:order-3`,style:{backgroundColor:B},children:[(0,$.jsx)(`p`,{className:`text-xs`,style:{color:V},children:u(`common.max`,`Max`)}),(0,$.jsx)(`p`,{className:`text-2xl font-bold text-red-500`,children:x?.max_temperature==null?`—`:`${x.max_temperature}°C`})]})]})}),(0,$.jsx)(`div`,{className:`rounded-lg p-4`,style:{backgroundColor:B},children:S?(0,$.jsx)(`div`,{className:`h-[300px] flex items-center justify-center`,style:{color:V},children:u(`common.loading`,`Loading...`)}):C?(0,$.jsx)(`div`,{className:`h-[300px] flex items-center justify-center text-red-500`,children:u(`common.error`,`Error loading data`)}):D.length===0?(0,$.jsx)(`div`,{className:`h-[300px] flex items-center justify-center`,style:{color:V},children:u(`common.noData`,`No data available for this time range`)}):(0,$.jsx)(Qe,{width:`100%`,height:300,children:(0,$.jsxs)(hi,{data:D,children:[(0,$.jsx)(gt,{strokeDasharray:`3 3`,stroke:ie}),(0,$.jsx)(rt,{dataKey:`time`,type:`number`,domain:[Date.now()-b*60*60*1e3,Date.now()],tickFormatter:e=>{let t=new Date(e);return b>24?t.toLocaleDateString([],{day:`numeric`,month:`short`}):t.toLocaleTimeString([],Gt({hour:`2-digit`,minute:`2-digit`},v))},stroke:oe,tick:{fontSize:12}}),(0,$.jsx)(vt,{stroke:oe,tick:{fontSize:12},domain:m===`humidity`?[0,100]:[`auto`,`auto`],tickFormatter:e=>m===`humidity`?`${e}%`:`${e}°C`}),(0,$.jsx)(Re,{contentStyle:{backgroundColor:re,border:`1px solid ${ie}`,borderRadius:`8px`,color:ae},labelFormatter:e=>new Date(e).toLocaleString(void 0,Gt({year:`numeric`,month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`},v)),formatter:e=>[m===`humidity`?`${e??0}%`:`${e??0}°C`,m===`humidity`?`Humidity`:`Temperature`]}),(0,$.jsx)(O,{}),m===`humidity`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(A,{y:k,stroke:`#22a352`,strokeDasharray:`5 5`,label:{value:`Good`,fill:`#22a352`,fontSize:10}}),(0,$.jsx)(A,{y:j,stroke:`#d4a017`,strokeDasharray:`5 5`,label:{value:`Fair`,fill:`#d4a017`,fontSize:10}})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(A,{y:M,stroke:`#22a352`,strokeDasharray:`5 5`,label:{value:`Good`,fill:`#22a352`,fontSize:10}}),(0,$.jsx)(A,{y:N,stroke:`#d4a017`,strokeDasharray:`5 5`,label:{value:`Fair`,fill:`#d4a017`,fontSize:10}})]}),(0,$.jsx)(pi,{type:`monotone`,dataKey:m,name:m===`humidity`?`Humidity`:`Temperature`,stroke:m===`humidity`?`#3b82f6`:`#f97316`,strokeWidth:2,dot:!1,activeDot:{r:4},connectNulls:!0})]})})}),(0,$.jsx)(`div`,{className:`text-xs text-center`,style:{color:V},children:u(`amsHistory.recordingInfo`,`Data is recorded every 5 minutes while the printer is connected`)})]})]})})}function ra(e,t,n){let r=n===1||e>=128,i=e>=128?e-128:e,a=String.fromCharCode(65+i);return r?`HT·${t+1}`:`${a}·${t+1}`}function ia(e){let t=(e||``).replace(`#`,``).slice(0,6);if(t.length!==6)return`#FFFFFF`;let n=parseInt(t.slice(0,2),16),r=parseInt(t.slice(2,4),16),i=parseInt(t.slice(4,6),16);return[n,r,i].some(Number.isNaN)?`#FFFFFF`:(.2126*n+.7152*r+.0722*i)/255>.55?`#1A1A1A`:`#FFFFFF`}function aa({group:e,trayCountByAms:t,innerBg:n,textPrimary:r,textSecondary:i,showExtruderBadge:a,extruderLabel:o}){let s=Mn(e.trayColor||void 0),c=ia(e.trayColor),l=c===`#FFFFFF`?`rgba(0,0,0,0.45)`:`rgba(255,255,255,0.7)`,u=e.members.length;return(0,$.jsxs)(`div`,{className:`relative flex flex-col items-center`,children:[a&&(0,$.jsx)(`span`,{className:`absolute -top-1 -left-1 z-10 w-6 h-6 rounded-full flex items-center justify-center text-xs font-bold shadow`,style:{backgroundColor:r,color:n},"aria-label":o,title:o,children:o}),(0,$.jsxs)(`svg`,{viewBox:`-100 -100 200 200`,className:`w-44 h-44`,children:[(0,$.jsx)(`circle`,{cx:`0`,cy:`0`,r:`95`,fill:`none`,stroke:i,strokeOpacity:`0.25`,strokeWidth:`1`}),(0,$.jsx)(`circle`,{cx:`0`,cy:`0`,r:`92`,fill:s}),(0,$.jsx)(`circle`,{cx:`0`,cy:`0`,r:`56`,fill:n}),(0,$.jsx)(`circle`,{cx:`0`,cy:`0`,r:`56`,fill:`none`,stroke:i,strokeOpacity:`0.3`,strokeWidth:`1`}),(0,$.jsx)(`text`,{x:`0`,y:`-4`,textAnchor:`middle`,dominantBaseline:`middle`,fontSize:`14`,fontWeight:`700`,fill:r,children:e.displayName||`—`}),(0,$.jsx)(`text`,{x:`0`,y:`16`,textAnchor:`middle`,dominantBaseline:`middle`,fontSize:`11`,fontWeight:`500`,fill:i,children:`${u}× ↻`}),e.members.map((e,n)=>{let r=(n*360/u-90)*Math.PI/180,i=76*Math.cos(r),a=76*Math.sin(r),o=ra(e.amsId,e.slotIdx,t.get(e.amsId)??4),s=Math.max(22,o.length*7+8);return(0,$.jsxs)(`g`,{children:[(0,$.jsx)(`rect`,{x:i-s/2,y:a-9,width:s,height:18,rx:9,ry:9,fill:l}),(0,$.jsx)(`text`,{x:i,y:a,textAnchor:`middle`,dominantBaseline:`middle`,fontSize:`12`,fontWeight:`700`,fill:c,children:o})]},`${e.amsId}-${e.slotIdx}`)})]})]})}function oa({isOpen:e,state:t,amsUnits:n,amsExtruderMap:r,isDualNozzle:i,canToggle:a,pending:o,onToggle:s,onClose:c}){let{t:u}=l();if((0,X.useEffect)(()=>{if(!e)return;let t=e=>{e.key===`Escape`&&(e.stopPropagation(),c())};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e,c]),!e)return null;let d=`var(--bg-secondary)`,f=`var(--border-color)`,p=`var(--text-primary)`,m=`var(--text-secondary)`,h=(()=>{if(!i||!r)return!1;let e=new Set;for(let t of n||[]){let n=r[String(t.id)];if(n!==void 0&&(e.add(Number(n)),e.size>1))return!0}return!1})(),g=wn(n,r,h),_=new Map((n||[]).map(e=>[e.id,e.tray.length])),v=g.filter(e=>e.members.length>=2),y=t===!0,b=t===null;return(0,$.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,onClick:c,"data-testid":`ams-backup-modal`,children:(0,$.jsxs)(`div`,{className:`rounded-xl w-full max-w-2xl max-h-[90vh] overflow-hidden shadow-xl flex flex-col`,style:{backgroundColor:d},onClick:e=>e.stopPropagation(),role:`dialog`,"aria-modal":`true`,"aria-labelledby":`ams-backup-modal-title`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between px-5 py-3 border-b`,style:{borderColor:f},children:[(0,$.jsx)(`h2`,{id:`ams-backup-modal-title`,className:`text-base font-semibold`,style:{color:p},children:u(`printers.amsBackup.modalTitle`)}),(0,$.jsx)(`button`,{type:`button`,onClick:c,className:`p-1 rounded-md transition-colors hover:bg-black/10`,style:{color:m},"aria-label":u(`common.close`),children:(0,$.jsx)(Pt,{className:`w-5 h-5`})})]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between px-5 py-3 border-b`,style:{borderColor:f,backgroundColor:`var(--bg-primary)`},children:[(0,$.jsxs)(`div`,{className:`min-w-0 mr-3`,children:[(0,$.jsx)(`div`,{className:`text-sm font-medium`,style:{color:p},children:u(b?`printers.amsBackup.stateUnknown`:y?`printers.amsBackup.stateOn`:`printers.amsBackup.stateOff`)}),(0,$.jsx)(`p`,{className:`text-xs mt-0.5`,style:{color:m},children:u(`printers.amsBackup.modalHelp`)})]}),(0,$.jsx)(hr,{checked:y,onChange:s,disabled:!a||b||o})]}),(0,$.jsx)(`div`,{className:`flex-1 overflow-y-auto px-5 py-6`,children:v.length===0?(0,$.jsx)(`p`,{className:`text-sm text-center py-8`,style:{color:m},children:u(`printers.amsBackup.modalNoPairs`)}):(0,$.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-6 justify-items-center`,children:v.map(e=>(0,$.jsx)(aa,{group:e,trayCountByAms:_,innerBg:d,textPrimary:p,textSecondary:m,showExtruderBadge:h,extruderLabel:e.extruder===0?u(`printers.amsBackup.extruderRightShort`):u(`printers.amsBackup.extruderLeftShort`)},e.key))})})]})})}var sa=[{value:`6h`,label:`6h`,hours:6},{value:`24h`,label:`24h`,hours:24},{value:`48h`,label:`48h`,hours:48},{value:`7d`,label:`7d`,hours:168}],ca={nozzle:`#fb923c`,nozzle_2:`#f97316`,bed:`#60a5fa`,chamber:`#34d399`},la={nozzle:`#fed7aa`,nozzle_2:`#fdba74`,bed:`#bfdbfe`,chamber:`#a7f3d0`};function ua({isOpen:e,onClose:t,printerId:n,printerName:r,initialKind:a=`nozzle`,availableKinds:o=[`nozzle`,`bed`,`chamber`]}){let{t:s}=l(),[c,u]=(0,X.useState)(`24h`),[d,f]=(0,X.useState)(a);(0,X.useEffect)(()=>{f(a)},[a]);let{data:m}=p({queryKey:[`settings`],queryFn:i.getSettings}),h=m?.time_format||`system`;(0,X.useEffect)(()=>{if(!e)return;let n=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,n),()=>window.removeEventListener(`keydown`,n)},[e,t]);let g=sa.find(e=>e.value===c)?.hours||24,{data:v,isLoading:y,error:b}=p({queryKey:[`printer-sensor-history`,n,g,o.join(`,`)],queryFn:()=>i.getPrinterSensorHistory(n,g,o),enabled:e,refetchInterval:6e4});if(!e)return null;let x=v?.series.find(e=>e.sensor_kind===d),S=(x?.data||[]).map(e=>({time:(qt(e.recorded_at)||new Date).getTime(),value:e.value,target:e.target})),C=Date.now()-g*60*60*1e3,w=Date.now(),T=[...S];if(T.length>0){let e=T[0];e.time>C&&T.unshift({...e,time:C});let t=T[T.length-1];t.time{let t=e.filter(e=>e!=null);if(t.length<4)return`stable`;let n=t.slice(0,Math.floor(t.length/4)),r=t.slice(-Math.floor(t.length/4)),i=n.reduce((e,t)=>e+t,0)/n.length,a=r.reduce((e,t)=>e+t,0)/r.length-i;return Math.abs(a)<2?`stable`:a>0?`up`:`down`})(T.map(e=>e.value)),M=({trend:e})=>e===`up`?(0,$.jsx)(_,{className:`w-4 h-4 text-red-600 dark:text-red-400`}):e===`down`?(0,$.jsx)(Ke,{className:`w-4 h-4 text-green-600 dark:text-green-400`}):(0,$.jsx)(G,{className:`w-4 h-4 text-gray-400 dark:text-bambu-gray`}),N=`var(--bg-secondary)`,P=`var(--bg-primary)`,F=`var(--border-color)`,I=`var(--text-primary)`,L=`var(--text-secondary)`,R=`var(--text-muted)`,ee=e=>{switch(e){case`nozzle`:return s(`printers.heaterHistory.nozzle`,`Nozzle`);case`nozzle_2`:return s(`printers.heaterHistory.nozzle2`,`Nozzle 2`);case`bed`:return s(`printers.heaterHistory.bed`,`Bed`);case`chamber`:return s(`printers.heaterHistory.chamber`,`Chamber`)}},te=({k:e})=>e===`nozzle`||e===`nozzle_2`?(0,$.jsx)(Bn,{className:`w-4 h-4`}):e===`bed`?(0,$.jsx)(fn,{className:`w-4 h-4`}):(0,$.jsx)(j,{className:`w-4 h-4`});return(0,$.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50`,onClick:t,children:(0,$.jsxs)(`div`,{className:`rounded-xl w-full max-w-4xl max-h-[90vh] overflow-hidden shadow-xl`,style:{backgroundColor:N},onClick:e=>e.stopPropagation(),children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 border-b`,style:{borderColor:F},children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h2`,{className:`text-lg font-semibold`,style:{color:I},children:s(`printers.heaterHistory.title`,`Heater History`)}),(0,$.jsx)(`p`,{className:`text-sm`,style:{color:L},children:r})]}),(0,$.jsx)(`button`,{onClick:t,className:`p-2 rounded-lg transition-colors`,style:{color:L},"aria-label":s(`common.close`,`Close`),children:(0,$.jsx)(Pt,{className:`w-5 h-5`})})]}),(0,$.jsxs)(`div`,{className:`p-6 space-y-6 overflow-y-auto max-h-[calc(90vh-80px)]`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between max-[550px]:flex-col max-[550px]:items-start max-[550px]:gap-3`,children:[(0,$.jsx)(`div`,{className:`inline-flex gap-1 rounded-lg p-1 max-w-full flex-wrap w-fit`,style:{backgroundColor:P},children:o.map(e=>(0,$.jsxs)(`button`,{onClick:()=>f(e),className:`flex items-center gap-2 px-3 py-1.5 text-sm rounded-md transition-colors ${d===e?`text-white`:``}`,style:d===e?{backgroundColor:ca[e]}:{color:L},children:[(0,$.jsx)(te,{k:e}),ee(e)]},e))}),(0,$.jsx)(`div`,{className:`inline-flex gap-1 rounded-lg p-1 max-w-full flex-wrap w-fit`,style:{backgroundColor:P},children:sa.map(e=>(0,$.jsx)(`button`,{onClick:()=>u(e.value),className:`px-3 py-1 text-sm rounded-md transition-colors ${c===e.value?`bg-bambu-green text-white`:``}`,style:c===e.value?void 0:{color:L},children:e.label},e.value))})]}),(0,$.jsxs)(`div`,{className:`grid grid-cols-4 gap-4 max-[550px]:grid-cols-2`,children:[(0,$.jsxs)(`div`,{className:`rounded-lg p-4`,style:{backgroundColor:P},children:[(0,$.jsx)(`p`,{className:`text-xs`,style:{color:L},children:s(`common.current`,`Current`)}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`p`,{className:`text-2xl font-bold`,style:{color:ca[d]},children:D==null?`—`:`${Math.round(D)}°C`}),(0,$.jsx)(M,{trend:A})]}),k!=null&&k>0&&(0,$.jsxs)(`p`,{className:`text-xs mt-1`,style:{color:L},children:[s(`common.target`,`Target`),`: `,Math.round(k),`°C`]})]}),(0,$.jsxs)(`div`,{className:`rounded-lg p-4`,style:{backgroundColor:P},children:[(0,$.jsx)(`p`,{className:`text-xs`,style:{color:L},children:s(`common.average`,`Average`)}),(0,$.jsx)(`p`,{className:`text-2xl font-bold`,style:{color:I},children:x?.avg_value==null?`—`:`${x.avg_value}°C`})]}),(0,$.jsxs)(`div`,{className:`rounded-lg p-4`,style:{backgroundColor:P},children:[(0,$.jsx)(`p`,{className:`text-xs`,style:{color:L},children:s(`common.min`,`Min`)}),(0,$.jsx)(`p`,{className:`text-2xl font-bold`,style:{color:I},children:x?.min_value==null?`—`:`${Math.round(x.min_value)}°C`})]}),(0,$.jsxs)(`div`,{className:`rounded-lg p-4`,style:{backgroundColor:P},children:[(0,$.jsx)(`p`,{className:`text-xs`,style:{color:L},children:s(`common.max`,`Max`)}),(0,$.jsx)(`p`,{className:`text-2xl font-bold`,style:{color:I},children:x?.max_value==null?`—`:`${Math.round(x.max_value)}°C`})]})]}),(0,$.jsx)(`div`,{className:`rounded-lg p-4`,style:{backgroundColor:P},children:y?(0,$.jsx)(`div`,{className:`h-64 flex items-center justify-center`,style:{color:L},children:s(`common.loading`,`Loading...`)}):b?(0,$.jsx)(`div`,{className:`h-64 flex items-center justify-center text-red-700 dark:text-red-400`,children:s(`printers.heaterHistory.error`,`Failed to load history`)}):T.length===0?(0,$.jsx)(`div`,{className:`h-64 flex items-center justify-center`,style:{color:L},children:s(`printers.heaterHistory.empty`,`No data recorded yet`)}):(0,$.jsx)(Qe,{width:`100%`,height:300,children:(0,$.jsxs)(hi,{data:T,margin:{top:5,right:10,left:0,bottom:5},children:[(0,$.jsx)(gt,{strokeDasharray:`3 3`,stroke:F}),(0,$.jsx)(rt,{dataKey:`time`,type:`number`,domain:[C,w],tickFormatter:e=>new Date(e).toLocaleTimeString([],Gt({hour:`2-digit`,minute:`2-digit`},h)),stroke:R,fontSize:11}),(0,$.jsx)(vt,{stroke:R,fontSize:11,domain:[0,`auto`],tickFormatter:e=>`${Math.round(e)}°`}),(0,$.jsx)(Re,{contentStyle:{backgroundColor:N,border:`1px solid ${F}`,borderRadius:6,color:I},labelFormatter:e=>new Date(e).toLocaleString(void 0,Gt({month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`},h)),formatter:e=>e==null?`—`:`${Math.round(Number(e))}°C`}),(0,$.jsx)(O,{}),(0,$.jsx)(pi,{type:`monotone`,dataKey:`value`,name:s(`common.current`,`Current`),stroke:ca[d],strokeWidth:2,dot:!1,isAnimationActive:!1}),(0,$.jsx)(pi,{type:`stepAfter`,dataKey:`target`,name:s(`common.target`,`Target`),stroke:la[d],strokeDasharray:`4 4`,strokeWidth:1.5,dot:!1,isAnimationActive:!1})]})})})]})]})})}function da({data:e,children:t,disabled:n,className:r=``,spoolman:i,inventory:a,configureSlot:o,actions:s}){let{t:c}=l(),u=Tn(),[d,f]=(0,X.useState)(!1),[p,m]=(0,X.useState)(`top`),[h,g]=(0,X.useState)(null),[_,v]=(0,X.useState)(!1),[b,x]=(0,X.useState)(!1),S=(0,X.useRef)(null),C=(0,X.useRef)(null),w=(0,X.useRef)(null),T=()=>{let t=e.trayUuid;t&&(navigator.clipboard&&window.isSecureContext?navigator.clipboard.writeText(t).then(()=>{v(!0),setTimeout(()=>v(!1),2e3)}).catch(()=>{E(t)}):E(t))},E=e=>{let t=document.createElement(`textarea`);t.value=e,t.style.position=`fixed`,t.style.opacity=`0`,document.body.appendChild(t),t.select();try{document.execCommand(`copy`),v(!0),setTimeout(()=>v(!1),2e3)}catch{console.error(`Failed to copy to clipboard`)}document.body.removeChild(t)};(0,X.useLayoutEffect)(()=>{if(!d){g(null);return}let e=()=>{if(!S.current||!C.current)return;let e=S.current.getBoundingClientRect(),t=C.current.offsetHeight,n=C.current.offsetWidth,r=e.top-56,i=window.innerHeight-e.bottom,a=rr?`bottom`:`top`,o=e.left+e.width/2,s=Math.max(8,Math.min(o-n/2,window.innerWidth-n-8)),c=a===`top`?e.top-t-8:e.bottom+8;m(a),g({top:c,left:s})};e();let t=requestAnimationFrame(e);return window.addEventListener(`scroll`,e,!0),window.addEventListener(`resize`,e),()=>{cancelAnimationFrame(t),window.removeEventListener(`scroll`,e,!0),window.removeEventListener(`resize`,e)}},[d]);let D=()=>{n||(w.current&&clearTimeout(w.current),w.current=setTimeout(()=>f(!0),80))},O=()=>{w.current&&clearTimeout(w.current),w.current=setTimeout(()=>f(!1),100)},k=()=>{w.current&&clearTimeout(w.current),f(!1)};(0,X.useEffect)(()=>()=>{w.current&&clearTimeout(w.current)},[]);let A=e=>e<=15?`#ef4444`:e<=30?`#f97316`:e<=50?`#eab308`:`#22c55e`,j=e.colorHex?`#${e.colorHex.replace(`#`,``)}`:null,M=(a?.assignedSpool?.color_name_is_synthesized?void 0:qn(a?.assignedSpool?.color_name??null,null)?.trim())||e.colorName,N=a?.assignedSpool?qn(a.assignedSpool.color_name,a.assignedSpool.rgba??null,a.assignedSpool.color_name_is_synthesized):null,P=a?.assignedSpool?.remainingWeightGrams??null,I=a?.assignedSpool??null,L=Yt(I?.extra_colors),R=!!I?.effect_type,ee=!!I&&(L.length>0||R),te=ee?Jt({effectSize:`card`,rgba:I?.rgba??j,extraColors:I?.extra_colors,effectType:I?.effect_type,subtype:I?.subtype}):null,ne=L.length>1,re=ee?L.length===1?L[0]:I?.rgba??j:j;return(0,$.jsxs)(`div`,{ref:S,"data-testid":`filament-slot`,className:`relative ${r}`,onMouseEnter:D,onMouseLeave:O,children:[t,d&&(0,gi.createPortal)((0,$.jsxs)(`div`,{ref:C,className:`fixed z-[60]`,style:{top:h?.top??-9999,left:h?.left??-9999,maxWidth:`calc(100vw - 24px)`,visibility:h?`visible`:`hidden`},onMouseEnter:D,onMouseLeave:O,children:[(0,$.jsxs)(`div`,{className:` +import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,S as r,a as i,c as a,l as o,s,t as c,w as l,x as u}from"./client-DnySrlFv.js";import{t as d}from"./react-dom-B8Dg6xzp.js";import{n as f}from"./QueryClientProvider-Ce8_sN3w.js";import{t as p}from"./useQuery-BBCjCezC.js";import{t as m}from"./useMutation-B-Tr2hIP.js";import{t as h}from"./createLucideIcon-DvBYJlWL.js";import{c as g,i as _,n as v,o as y,r as b,s as x}from"./haSensorDisplay-lPbcOxD8.js";import{t as S}from"./arrow-down-Cj0DZhNf.js";import{t as C}from"./arrow-left-0Q6F2rjC.js";import{t as w}from"./arrow-right-DedpIMhP.js";import{t as T}from"./arrow-up-down-BdyOV_2F.js";import{t as E}from"./arrow-up-D-pfJ3WZ.js";import{i as D,n as O,r as k,t as A}from"./ReferenceLine-clJprXoH.js";import{t as j}from"./box-DAdKb9s5.js";import{n as M,t as N}from"./fan-D6AmXZMv.js";import{t as P}from"./calendar-BLKPnWqV.js";import{t as F}from"./check-Ck0cMLU4.js";import{a as I,n as L,r as R,t as ee}from"./info-ROUoQhJR.js";import{n as te,r as ne}from"./ToastContext-BRX0SW3C.js";import{t as z}from"./copy-Cu_0GKCU.js";import{t as re}from"./ellipsis-vertical-t2D7cYyp.js";import{t as B}from"./eye-off-6CkaxYwP.js";import{t as ie}from"./file-box-04V4jZ9_.js";import{t as ae}from"./GcodeToolpathViewer-Cg6UnTDw.js";import{n as V,t as oe}from"./ContextMenu-CwroFwVJ.js";import{n as se,t as ce}from"./scan-search-BDoNAXzz.js";import{t as le}from"./funnel-C3dyAMK9.js";import{t as ue}from"./gauge-D21zgWMb.js";import{t as de}from"./grip-vertical-C_1RDxRw.js";import{t as fe}from"./hard-drive-CgXAHN37.js";import{t as pe}from"./layout-grid-DkD3u6wa.js";import{t as H}from"./loader-circle-BEmFtawu.js";import{t as me}from"./log-in-n0ckHxnD.js";import{t as he}from"./maximize-2-kPQ77q72.js";import{t as U}from"./minimize-2-dqT-k7oI.js";import{a as ge,i as _e,n as ve,r as ye,t as W}from"./CameraDiagnoseModal-BwHHipUP.js";import{t as G}from"./minus-DypeGjGR.js";import{a as be,c as xe,i as Se,l as K,n as Ce,r as we,s as Te,t as q,u as J}from"./CopyButton-C5In5weo.js";import{t as Ee}from"./move-Bc1EIjTD.js";import{t as De}from"./package-BGUevlqS.js";import{t as Oe}from"./pause-DFb6GX_6.js";import{t as ke}from"./play-DIDYtk2S.js";import{t as Ae}from"./search-0n0CBc74.js";import{t as je}from"./settings-2-Cvn837lh.js";import{n as Me,t as Ne}from"./wind-CI8UoBMf.js";import{D as Pe,Fn as Fe,It as Ie,Kt as Le,L as Re,Ln as ze,Lt as Be,M as Ve,Mn as He,On as Ue,Pn as We,R as Ge,Rn as Ke,S as qe,Sn as Je,St as Ye,T as Xe,Ut as Ze,Xt as Qe,Zt as $e,an as et,at as tt,b as nt,c as rt,cn as it,d as at,f as ot,gn as st,j as ct,jt as lt,k as ut,l as dt,ln as ft,mn as pt,mt,nn as ht,p as gt,pt as _t,s as vt,sn as yt,t as bt,u as xt,vn as St,w as Ct,wn as wt,x as Tt,y as Et,z as Dt}from"./CartesianChart-BAcHzPFb.js";import{t as Ot}from"./triangle-alert-Dt_1FcBy.js";import{t as kt}from"./unlink-C098nwOf.js";import{i as At,n as jt,r as Mt,t as Nt}from"./CameraWall-D-W28jK-.js";import{t as Pt}from"./x-DR-Trv6U.js";import{n as Ft,t as It}from"./zoom-out-DNNe6DMN.js";import{n as Lt,t as Rt}from"./Card-Bzc64K35.js";import{t as zt}from"./file-DDkFXH-b.js";import{t as Y}from"./Button-DDr6eAFy.js";import{a as Bt,c as Vt,i as Ht,o as Ut,s as Wt,t as Gt,u as Kt,v as qt}from"./date-G9KUauqz.js";import{n as Jt,r as Yt}from"./filamentSwatchHelpers-D3oXQSGk.js";import{$ as Xt,$t as Zt,At as Qt,Cn as $t,Ct as en,D as tn,E as nn,Et as rn,Ft as an,G as on,H as sn,J as cn,Jt as ln,K as un,Kt as dn,Lt as fn,Mn as pn,Mt as mn,N as hn,Nt as gn,O as _n,On as vn,Ot as yn,Rn as bn,Rt as xn,Sn,U as Cn,V as wn,Vn as Tn,Vt as En,W as Dn,Wt as On,X as kn,Y as An,Yt as jn,Z as Mn,Zt as Nn,_ as Pn,_n as Fn,_t as In,an as Ln,at as Rn,b as zn,bn as Bn,bt as Vn,cn as Hn,ct as Un,dt as Wn,et as Gn,fn as Kn,ft as qn,h as Jn,jn as Yn,jt as Xn,k as Zn,q as Qn,sn as $n,tt as er,un as tr,ut as nr,v as rr,vt as ir,wn as ar,xn as or,xt as sr,y as cr,yt as lr,z as ur}from"./index-Cxa-KVmA.js";import{n as dr,t as fr}from"./FileUploadModal-Dee1GxH_.js";import{n as pr,t as mr}from"./ErrorBarContext-CcijMMkA.js";import{t as hr}from"./Toggle-KiqA_5fU.js";import{t as gr}from"./printerModel-DrNvERGQ.js";import{t as _r}from"./queueItemName-UFY7kpjG.js";import{n as vr,r as yr,t as br}from"./ConfigureAmsSlotModal-BgpDvjjX.js";var xr=h(`air-vent`,[[`path`,{d:`M18 17.5a2.5 2.5 0 1 1-4 2.03V12`,key:`yd12zl`}],[`path`,{d:`M6 12H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v5a2 2 0 0 1-2 2h-2`,key:`larmp2`}],[`path`,{d:`M6 8h12`,key:`6g4wlu`}],[`path`,{d:`M6.6 15.572A2 2 0 1 0 10 17v-5`,key:`1x1kqn`}]]),Sr=h(`chart-line`,[[`path`,{d:`M3 3v16a2 2 0 0 0 2 2h16`,key:`c24i48`}],[`path`,{d:`m19 9-5 5-4-4-3 3`,key:`2osh9i`}]]),Cr=h(`ellipsis`,[[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}],[`circle`,{cx:`19`,cy:`12`,r:`1`,key:`1wjl8i`}],[`circle`,{cx:`5`,cy:`12`,r:`1`,key:`1pcz8c`}]]),wr=h(`fullscreen`,[[`path`,{d:`M3 7V5a2 2 0 0 1 2-2h2`,key:`aa7l1z`}],[`path`,{d:`M17 3h2a2 2 0 0 1 2 2v2`,key:`4qcy5o`}],[`path`,{d:`M21 17v2a2 2 0 0 1-2 2h-2`,key:`6vwrx8`}],[`path`,{d:`M7 21H5a2 2 0 0 1-2-2v-2`,key:`ioqczr`}],[`rect`,{width:`10`,height:`8`,x:`7`,y:`8`,rx:`1`,key:`vys8me`}]]),Tr=h(`hourglass`,[[`path`,{d:`M5 22h14`,key:`ehvnwv`}],[`path`,{d:`M5 2h14`,key:`pdyrp9`}],[`path`,{d:`M17 22v-4.172a2 2 0 0 0-.586-1.414L12 12l-4.414 4.414A2 2 0 0 0 7 17.828V22`,key:`1d314k`}],[`path`,{d:`M7 2v4.172a2 2 0 0 0 .586 1.414L12 12l4.414-4.414A2 2 0 0 0 17 6.172V2`,key:`1vvvr6`}]]),Er=h(`key-round`,[[`path`,{d:`M2.586 17.414A2 2 0 0 0 2 18.828V21a1 1 0 0 0 1 1h3a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h1a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h.172a2 2 0 0 0 1.414-.586l.814-.814a6.5 6.5 0 1 0-4-4z`,key:`1s6t7t`}],[`circle`,{cx:`16.5`,cy:`7.5`,r:`.5`,fill:`currentColor`,key:`w0ekpg`}]]),Dr=h(`picture-in-picture-2`,[[`path`,{d:`M21 9V6a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v10c0 1.1.9 2 2 2h4`,key:`daa4of`}],[`rect`,{width:`10`,height:`7`,x:`12`,y:`13`,rx:`2`,key:`1nb8gs`}]]),Or=h(`repeat`,[[`path`,{d:`m17 2 4 4-4 4`,key:`nntrym`}],[`path`,{d:`M3 11v-1a4 4 0 0 1 4-4h14`,key:`84bu3i`}],[`path`,{d:`m7 22-4-4 4-4`,key:`1wqhfi`}],[`path`,{d:`M21 13v1a4 4 0 0 1-4 4H3`,key:`1rx37r`}]]),kr=h(`signal`,[[`path`,{d:`M2 20h.01`,key:`4haj6o`}],[`path`,{d:`M7 20v-4`,key:`j294jx`}],[`path`,{d:`M12 20v-8`,key:`i3yub9`}],[`path`,{d:`M17 20V8`,key:`1tkaf5`}],[`path`,{d:`M22 4v16`,key:`sih9yq`}]]),Ar=h(`sliders-horizontal`,[[`path`,{d:`M10 5H3`,key:`1qgfaw`}],[`path`,{d:`M12 19H3`,key:`yhmn1j`}],[`path`,{d:`M14 3v4`,key:`1sua03`}],[`path`,{d:`M16 17v4`,key:`1q0r14`}],[`path`,{d:`M21 12h-9`,key:`1o4lsq`}],[`path`,{d:`M21 19h-5`,key:`1rlt1p`}],[`path`,{d:`M21 5h-7`,key:`1oszz2`}],[`path`,{d:`M8 10v4`,key:`tgpxqk`}],[`path`,{d:`M8 12H3`,key:`a7s4jb`}]]),jr=h(`snowflake`,[[`path`,{d:`m10 20-1.25-2.5L6 18`,key:`18frcb`}],[`path`,{d:`M10 4 8.75 6.5 6 6`,key:`7mghy3`}],[`path`,{d:`m14 20 1.25-2.5L18 18`,key:`1chtki`}],[`path`,{d:`m14 4 1.25 2.5L18 6`,key:`1b4wsy`}],[`path`,{d:`m17 21-3-6h-4`,key:`15hhxa`}],[`path`,{d:`m17 3-3 6 1.5 3`,key:`11697g`}],[`path`,{d:`M2 12h6.5L10 9`,key:`kv9z4n`}],[`path`,{d:`m20 10-1.5 2 1.5 2`,key:`1swlpi`}],[`path`,{d:`M22 12h-6.5L14 15`,key:`1mxi28`}],[`path`,{d:`m4 10 1.5 2L4 14`,key:`k9enpj`}],[`path`,{d:`m7 21 3-6-1.5-3`,key:`j8hb9u`}],[`path`,{d:`m7 3 3 6h4`,key:`1otusx`}]]),Mr=h(`square-minus`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M8 12h8`,key:`1wcyev`}]]),Nr=(e,t,n,r)=>tt(e,`xAxis`,t,r),Pr=(e,t,n,r)=>_t(e,`xAxis`,t,r),Fr=(e,t,n,r)=>tt(e,`yAxis`,n,r),Ir=(e,t,n,r)=>_t(e,`yAxis`,n,r),Lr=pt([Ze,Nr,Fr,Pr,Ir],(e,t,n,r,i)=>ft(e,`xAxis`)?ht(t,r,!1):ht(n,i,!1)),Rr=(e,t,n,r,i)=>i;function zr(e){return e.type===`line`}var Br=pt([Ze,Nr,Fr,Pr,Ir,pt([mt,Rr],(e,t)=>e.filter(zr).find(e=>e.id===t)),Lr,lt],(e,t,n,r,i,a,o,s)=>{var{chartData:c,dataStartIndex:l,dataEndIndex:u}=s;if(!(a==null||t==null||n==null||r==null||i==null||r.length===0||i.length===0||o==null||e!==`horizontal`&&e!==`vertical`)){var{dataKey:d,data:f}=a,p=f!=null&&f.length>0?f:c?.slice(l,u+1);if(p!=null)return di({layout:e,xAxis:t,yAxis:n,xAxisTicks:r,yAxisTicks:i,dataKey:d,bandSize:o,displayedData:p})}}),X=e(n()),Vr=[`id`],Hr=[`type`,`layout`,`connectNulls`,`needClip`,`shape`],Ur=[`activeDot`,`animateNewValues`,`animationBegin`,`animationDuration`,`animationEasing`,`connectNulls`,`dot`,`hide`,`isAnimationActive`,`label`,`legendType`,`xAxisId`,`yAxisId`,`id`];function Wr(){return Wr=Object.assign?Object.assign.bind():function(e){for(var t=1;t{var{dataKey:t,name:n,stroke:r,legendType:i,hide:a}=e;return[{inactive:a,dataKey:t,type:i,color:r,value:yt(n,t),payload:e}]},Qr=X.memo(e=>{var{dataKey:t,data:n,stroke:r,strokeWidth:i,fill:a,name:o,hide:s,unit:c,tooltipType:l,id:u}=e,d={dataDefinedOnItem:n,getPosition:Ue,settings:{stroke:r,strokeWidth:i,fill:a,dataKey:t,nameKey:void 0,name:yt(o,t),hide:s,type:l,color:r,unit:c,graphicalItemId:u}};return X.createElement(Pe,{tooltipEntrySettings:d})}),$r=(e,t)=>`${t}px ${e-t}px`;function ei(e,t){for(var n=e.length%2==0?e:[...e,0],r=[],i=0;i{var r=n.reduce((e,t)=>e+t);if(!r)return $r(t,e);for(var i=Math.floor(e/r),a=e%r,o=t-e,s=[],c=0,l=0;ca){s=[...n.slice(0,c),a-l];break}}var f=s.length%2==0?[0,o]:[o];return[...ei(n,i),...s,...f].map(e=>`${e}px`).join(`, `)};function ni(e){var{clipPathId:t,points:n,props:r}=e,{dot:i,dataKey:a,needClip:o}=r,{id:s}=r,c=Fe(Yr(r,Vr));return X.createElement(Tt,{points:n,dot:i,className:`recharts-line-dots`,dotClassName:`recharts-line-dot`,dataKey:a,baseProps:c,needClip:o,clipPathId:t})}function Q(e){var{showLabels:t,children:n,points:r}=e,i=(0,X.useMemo)(()=>r?.map(e=>{var t={x:e.x??0,y:e.y??0,width:0,lowerWidth:0,upperWidth:0,height:0};return Z(Z({},t),{},{value:e.value,payload:e.payload,viewBox:t,parentViewBox:void 0,fill:void 0})}),[r]);return X.createElement(ct,{value:t?i:void 0},n)}function ri(e){var{clipPathId:t,pathRef:n,points:r,strokeDasharray:i,props:a}=e,{type:o,layout:s,connectNulls:c,needClip:l,shape:u}=a,d=Z(Z({},We(Yr(a,Hr))),{},{fill:`none`,className:`recharts-line-curve`,clipPath:l?`url(#clipPath-${t})`:void 0,points:r,type:o,layout:s,connectNulls:c,strokeDasharray:i??a.strokeDasharray});return X.createElement(X.Fragment,null,r?.length>1&&X.createElement(pr,Wr({shapeType:`curve`,option:u},d,{pathRef:n})),X.createElement(ni,{points:r,clipPathId:t,props:a}))}function ii(e){try{return e&&e.getTotalLength&&e.getTotalLength()||0}catch{return 0}}function ai(e){var{clipPathId:t,props:n,pathRef:r,previousPointsRef:i,longestAnimatedLengthRef:a}=e,{points:o,strokeDasharray:s,isAnimationActive:c,animationBegin:l,animationDuration:u,animationEasing:d,animateNewValues:f,width:p,height:m,onAnimationEnd:h,onAnimationStart:g}=n,_=i.current,v=Ie(o,`recharts-line-`),y=(0,X.useRef)(v),[b,x]=(0,X.useState)(!1),S=!b,C=(0,X.useCallback)(()=>{typeof h==`function`&&h(),x(!1)},[h]),w=(0,X.useCallback)(()=>{typeof g==`function`&&g(),x(!0)},[g]),T=ii(r.current),E=(0,X.useRef)(0);y.current!==v&&(E.current=a.current,y.current=v);var D=E.current;return X.createElement(Q,{points:o,showLabels:S},n.children,X.createElement(Be,{animationId:v,begin:l,duration:u,isActive:c,easing:d,onAnimationEnd:C,onAnimationStart:w,key:v},e=>{var l=Je(D,T+D,e),u=Math.min(l,T),d=c?s?ti(u,T,`${s}`.split(/[,\s]+/gim).map(e=>parseFloat(e))):$r(T,u):s==null?void 0:String(s);if(e>0&&T>0&&(i.current=o,a.current=Math.max(a.current,u)),_){var h=_.length/o.length,g=e===1?o:o.map((t,n)=>{var r=Math.floor(n*h);if(_[r]){var i=_[r];return Z(Z({},t),{},{x:Je(i.x,t.x,e),y:Je(i.y,t.y,e)})}return f?Z(Z({},t),{},{x:Je(p*2,t.x,e),y:Je(m/2,t.y,e)}):Z(Z({},t),{},{x:t.x,y:t.y})});return i.current=g,X.createElement(ri,{props:n,points:g,clipPathId:t,pathRef:r,strokeDasharray:d})}return X.createElement(ri,{props:n,points:o,clipPathId:t,pathRef:r,strokeDasharray:d})}),X.createElement(Ve,{label:n.label}))}function oi(e){var{clipPathId:t,props:n}=e,r=(0,X.useRef)(null),i=(0,X.useRef)(0),a=(0,X.useRef)(null);return X.createElement(ai,{props:n,clipPathId:t,previousPointsRef:r,longestAnimatedLengthRef:i,pathRef:a})}var si=(e,t)=>({x:e.x??void 0,y:e.y??void 0,value:e.value,errorVal:it(e.payload,t)}),ci=class extends X.Component{render(){var{hide:e,dot:t,points:n,className:r,xAxisId:i,yAxisId:a,top:o,left:s,width:c,height:l,id:u,needClip:d,zIndex:f}=this.props;if(e)return null;var p=ze(`recharts-line`,r),m=u,{r:h,strokeWidth:g}=xt(t),_=ut(t),v=h*2+g,y=d?`url(#clipPath-${_?``:`dots-`}${m})`:void 0;return X.createElement(Dt,{zIndex:f},X.createElement(He,{className:p},d&&X.createElement(`defs`,null,X.createElement(at,{clipPathId:m,xAxisId:i,yAxisId:a}),!_&&X.createElement(`clipPath`,{id:`clipPath-dots-${m}`},X.createElement(`rect`,{x:s-v/2,y:o-v/2,width:c+v,height:l+v}))),X.createElement(mr,{xAxisId:i,yAxisId:a,data:n,dataPointFormatter:si,errorBarOffset:0},X.createElement(oi,{props:this.props,clipPathId:m}))),X.createElement(Et,{activeDot:this.props.activeDot,points:n,mainColor:this.props.stroke,itemDataKey:this.props.dataKey,clipPath:y}))}},li={activeDot:!0,animateNewValues:!0,animationBegin:0,animationDuration:1500,animationEasing:`ease`,connectNulls:!1,dot:!0,fill:`#fff`,hide:!1,isAnimationActive:`auto`,label:!1,legendType:`line`,stroke:`#3182bd`,strokeWidth:1,xAxisId:0,yAxisId:0,zIndex:Ye.line,type:`linear`};function ui(e){var t=St(e,li),{activeDot:n,animateNewValues:r,animationBegin:i,animationDuration:a,animationEasing:o,connectNulls:s,dot:c,hide:l,isAnimationActive:u,label:d,legendType:f,xAxisId:p,yAxisId:m,id:h}=t,g=Yr(t,Ur),{needClip:_}=ot(p,m),v=nt(),y=Le(),b=$e(),x=st(e=>Br(e,p,m,b,h));if(y!==`horizontal`&&y!==`vertical`||x==null||v==null)return null;var{height:S,width:C,x:w,y:T}=v;return X.createElement(ci,Wr({},g,{id:h,connectNulls:s,dot:c,activeDot:n,animateNewValues:r,animationBegin:i,animationDuration:a,animationEasing:o,isAnimationActive:u,hide:l,label:d,legendType:f,xAxisId:p,yAxisId:m,points:x,layout:y,height:S,width:C,left:w,top:T,needClip:_}))}function di(e){var{layout:t,xAxis:n,yAxis:r,xAxisTicks:i,yAxisTicks:a,dataKey:o,bandSize:s,displayedData:c}=e;return c.map((e,c)=>{var l=it(e,o);if(t===`horizontal`)return{x:et({axis:n,ticks:i,bandSize:s,entry:e,index:c}),y:(wt(l)?null:r.scale.map(l))??null,value:l,payload:e};var u=wt(l)?null:n.scale.map(l),d=et({axis:r,ticks:a,bandSize:s,entry:e,index:c});return u==null||d==null?null:{x:u,y:d,value:l,payload:e}}).filter(Boolean)}function fi(e){var t=St(e,li),n=$e();return X.createElement(Ct,{id:t.id,type:`line`},e=>X.createElement(X.Fragment,null,X.createElement(Xe,{legendPayload:Zr(t)}),X.createElement(Qr,{dataKey:t.dataKey,data:t.data,stroke:t.stroke,strokeWidth:t.strokeWidth,fill:t.fill,name:t.name,hide:t.hide,unit:t.unit,tooltipType:t.tooltipType,id:e}),X.createElement(qe,{type:`line`,id:e,data:t.data,xAxisId:t.xAxisId,yAxisId:t.yAxisId,zAxisId:0,dataKey:t.dataKey,hide:t.hide,isPanorama:n}),X.createElement(ui,Wr({},t,{id:e}))))}var pi=X.memo(fi,dt);pi.displayName=`Line`;var mi=[`axis`],hi=(0,X.forwardRef)((e,t)=>X.createElement(bt,{chartName:`LineChart`,defaultTooltipEventType:`axis`,validateTooltipEventTypes:mi,tooltipPayloadSearcher:Ge,categoricalChartProps:e,ref:t})),gi=e(d(),1);function _i(e,t){let n=e.split(`.`).map(e=>parseInt(e,10)||0),r=t.split(`.`).map(e=>parseInt(e,10)||0);for(;n.length<4;)n.push(0);for(;r.length<4;)r.push(0);for(let e=0;e<4;e++)if(n[e]!==r[e])return n[e]-r[e];return 0}function vi(e,t,n,r){if(!e)return``;if(r)return`${e} — ${r}`;if(!t)return e;let i=t.match(/plate_(\d+)\.gcode/);return i&&parseInt(i[1],10)>1?`${e} — ${n(`printers.plateNumber`,`Plate {{number}}`,{number:i[1]})}`:e}var yi=new Set([`A1`,`A1MINI`,`A2L`,`A1M`,`N1`,`N2S`,`N9`,`A04`,`A11`,`A12`]);function bi(e){return e?yi.has(e.toUpperCase().replace(/[^A-Z0-9]/g,``)):!1}function xi(e){let t=typeof window<`u`&&window.visualViewport?window.visualViewport.height:typeof window<`u`?window.innerHeight:0,{triggerRect:n,popoverWidth:r,estimatedHeight:i,viewportHeight:a=t,viewportWidth:o=window.innerWidth,margin:s=8,gap:c=4,horizontalAlign:l=`right`}=e,u=n.bottom+c,d=`below`;if(u+i>a-s){let e=n.top-c-i;e>=s&&(u=e,d=`above`)}let f=n.left+(n.right-n.left)/2,p=l===`center`?f-r/2:n.right-r;po-s&&(p=Math.max(s,o-r-s));let m=d===`above`?n.top-c:u,h=Math.max(14,Math.min(r-14,f-p));return{top:u,left:p,placement:d,anchorY:m,arrowLeft:h}}var Si=`cameraViewMode`,Ci=`cameraWindowState`;function wi(e){return e===`window`||e===`embedded`}function Ti(){try{let e=localStorage.getItem(Si);return wi(e)?e:null}catch{return null}}function Ei(e){try{localStorage.setItem(Si,e)}catch{}}function Di(e){let t={width:640,height:400};try{let e=localStorage.getItem(Ci);if(e){let n=JSON.parse(e);n&&typeof n==`object`&&(t=n)}}catch{}let n=[`width=${t.width??640}`,`height=${t.height??400}`,t.left===void 0?``:`left=${t.left}`,t.top===void 0?``:`top=${t.top}`,`menubar=no,toolbar=no,location=no,status=no`].filter(Boolean).join(`,`);window.open(`/camera/${e}`,`camera-${e}`,n)}var Oi={NYLON:`PA`,PA6:`PA`,PA11:`PA`,PA12:`PA`,PAHT:`PA`,PPA:`PA`};function ki(e,t){let n=(e||``).split(` `)[0].toUpperCase();for(let e of[n,n.split(`-`)[0]]){let n=Oi[e]??e;if(t[n])return n}return`PLA`}function Ai(e,t,n,r=new Date){return e===`now`?null:e===`delay`?new Date(r.getTime()+t*6e4).toISOString():new Date(n).toISOString()}var ji=`printerHiddenExternalSpools`;function Mi(){try{let e=localStorage.getItem(ji);if(!e)return{};let t=JSON.parse(e);return!t||typeof t!=`object`||Array.isArray(t)?{}:t}catch{return{}}}function Ni(e){return Mi()[String(e)]===!0}function Pi(e,t){let n=Mi();t?n[String(e)]=!0:delete n[String(e)];try{localStorage.setItem(ji,JSON.stringify(n))}catch{}}var $=t(),Fi=[{key:`printing`,dot:`bg-bambu-green`},{key:`paused`,dot:`bg-status-warning`},{key:`finished`,dot:`bg-blue-400`},{key:`idle`,dot:`bg-bambu-green`},{key:`error`,dot:`bg-status-error`},{key:`offline`,dot:`bg-gray-400`}];function Ii({selectedIds:e,printers:t,onClose:n,onSelectAll:r,onSelectByLocation:i,onSelectByState:a,onAction:o,actionPending:s}){let{t:c}=l(),{hasPermission:u}=lr(),d=f(),[p,m]=(0,X.useState)(!1),[h,g]=(0,X.useState)(!1),_=Array.from(e).map(e=>({id:e,status:d.getQueryData([`printerStatus`,e])})),v=_.some(({status:e})=>e?.connected&&e.state===`RUNNING`),y=_.some(({status:e})=>e?.connected&&e.state===`PAUSE`),b=v||y,x=_.some(({status:e})=>!!(e?.connected&&e.awaiting_plate_clear)),S=_.some(({status:e})=>!e?.connected||!e.hms_errors?!1:Mt(e.hms_errors).length>0),C=u(`printers:control`),w=u(`printers:clear_plate`),T=[...new Set(t.map(e=>e.location).filter(e=>!!e))].sort(),E={printing:0,paused:0,finished:0,idle:0,error:0,offline:0};t.forEach(e=>{let t=d.getQueryData([`printerStatus`,e.id]);if(!t||!t.connected){E.offline++;return}let n=t.hms_errors?Mt(t.hms_errors).length>0:!1;switch(n&&E.error++,t.state){case`RUNNING`:E.printing++;break;case`PAUSE`:E.paused++;break;case`FINISH`:E.finished++;break;case`FAILED`:n||E.finished++;break;default:E.idle++;break}});let O={printing:c(`printers.status.printing`),paused:c(`printers.status.paused`,`Paused`),finished:c(`printers.status.finished`,`Finished`),idle:c(`printers.status.idle`),error:c(`printers.status.problem`),offline:c(`printers.status.offline`)};return(0,$.jsxs)(`div`,{className:`fixed bottom-6 left-1/2 -translate-x-1/2 z-40 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl px-4 py-3 flex items-center gap-3 flex-wrap`,children:[(0,$.jsx)(Y,{variant:`secondary`,size:`sm`,onClick:n,children:(0,$.jsx)(Pt,{className:`w-4 h-4`})}),(0,$.jsx)(`div`,{className:`w-px h-6 bg-bambu-dark-tertiary`}),(0,$.jsx)(`span`,{className:`text-white font-medium text-sm`,children:c(`printers.bulk.selected`,{count:e.size})}),(0,$.jsx)(`div`,{className:`w-px h-6 bg-bambu-dark-tertiary`}),(0,$.jsx)(Y,{variant:`secondary`,size:`sm`,onClick:r,children:c(`printers.bulk.selectAll`)}),(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsxs)(Y,{variant:`secondary`,size:`sm`,onClick:()=>{g(!h),m(!1)},children:[c(`printers.bulk.selectByState`),(0,$.jsx)(I,{className:`w-3 h-3 transition-transform ${h?`rotate-180`:``}`})]}),h&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>g(!1)}),(0,$.jsx)(`div`,{className:`absolute bottom-full mb-2 left-0 w-48 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg z-20 py-1`,children:Fi.filter(({key:e})=>E[e]>0).map(({key:e,dot:t})=>(0,$.jsxs)(`button`,{onClick:()=>{a(e),g(!1)},className:`w-full text-left px-3 py-2 text-sm text-bambu-gray-light hover:bg-bambu-dark-tertiary hover:text-white transition-colors flex items-center gap-2`,children:[(0,$.jsx)(`div`,{className:`w-2 h-2 rounded-full ${t}`}),O[e],(0,$.jsx)(`span`,{className:`ml-auto text-bambu-gray text-xs`,children:E[e]})]},e))})]})]}),T.length>0&&(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsxs)(Y,{variant:`secondary`,size:`sm`,onClick:()=>{m(!p),g(!1)},children:[c(`printers.bulk.selectByLocation`),(0,$.jsx)(I,{className:`w-3 h-3 transition-transform ${p?`rotate-180`:``}`})]}),p&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>m(!1)}),(0,$.jsx)(`div`,{className:`absolute bottom-full mb-2 left-0 w-48 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg z-20 py-1`,children:T.map(e=>(0,$.jsx)(`button`,{onClick:()=>{i(e),m(!1)},className:`w-full text-left px-3 py-2 text-sm text-bambu-gray-light hover:bg-bambu-dark-tertiary hover:text-white transition-colors`,children:e},e))})]})]}),(0,$.jsx)(`div`,{className:`w-px h-6 bg-bambu-dark-tertiary`}),(0,$.jsxs)(Y,{size:`sm`,className:`bg-red-500 hover:bg-red-600`,onClick:()=>o(`stop`),disabled:s||!C||!b,title:C?b?void 0:c(`printers.bulk.noneApplicable`):c(`printers.permission.noControl`),children:[(0,$.jsx)(fn,{className:`w-3.5 h-3.5`}),c(`printers.bulk.actions.stop`)]}),(0,$.jsxs)(Y,{variant:`secondary`,size:`sm`,onClick:()=>o(`pause`),disabled:s||!C||!v,title:C?v?void 0:c(`printers.bulk.noneApplicable`):c(`printers.permission.noControl`),children:[(0,$.jsx)(Oe,{className:`w-3.5 h-3.5`}),c(`printers.bulk.actions.pause`)]}),(0,$.jsxs)(Y,{variant:`secondary`,size:`sm`,onClick:()=>o(`resume`),disabled:s||!C||!y,title:C?y?void 0:c(`printers.bulk.noneApplicable`):c(`printers.permission.noControl`),children:[(0,$.jsx)(ke,{className:`w-3.5 h-3.5`}),c(`printers.bulk.actions.resume`)]}),(0,$.jsxs)(Y,{variant:`secondary`,size:`sm`,onClick:()=>o(`clearHMS`),disabled:s||!C||!S,title:C?S?void 0:c(`printers.bulk.noneApplicable`):c(`printers.permission.noControl`),children:[(0,$.jsx)(D,{className:`w-3.5 h-3.5`}),c(`printers.bulk.actions.clearHMS`)]}),(0,$.jsxs)(Y,{variant:`secondary`,size:`sm`,onClick:()=>o(`clearPlate`),disabled:s||!w||!x,title:w?x?void 0:c(`printers.bulk.noneApplicable`):c(`printers.permission.noControl`),children:[(0,$.jsx)(k,{className:`w-3.5 h-3.5`}),c(`printers.bulk.actions.clearPlate`)]})]})}function Li({printerId:e,filePath:t,filename:n,onClose:r}){let[a,o]=(0,X.useState)(null),[s,c]=(0,X.useState)([]),[l,u]=(0,X.useState)(!1),[d,f]=(0,X.useState)(null),p=n.toLowerCase().split(`.`).pop()||``,m=p===`3mf`||p===`stl`,h=p===`gcode`||p===`3mf`;(0,X.useEffect)(()=>{o(m?`3d`:h?`gcode`:null)},[m,h]),(0,X.useEffect)(()=>{c([]),f(null),m&&(u(!0),i.getPrinterFilePlates(e,t).then(e=>c(e.plates||[])).catch(()=>c([])).finally(()=>u(!1)))},[t,m,e]);let g=s.length>1,_=d==null?null:s.find(e=>e.index===d)??null;return(0,$.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-6`,onClick:r,children:(0,$.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-4xl h-[80vh] flex flex-col`,onClick:e=>e.stopPropagation(),children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,$.jsx)(`h2`,{className:`text-lg font-semibold text-white truncate flex-1 mr-4`,children:n}),(0,$.jsx)(Y,{variant:`ghost`,size:`sm`,onClick:r,children:(0,$.jsx)(Pt,{className:`w-5 h-5`})})]}),(0,$.jsxs)(`div`,{className:`flex border-b border-bambu-dark-tertiary`,children:[(0,$.jsxs)(`button`,{onClick:()=>m&&o(`3d`),disabled:!m,className:`flex items-center gap-2 px-6 py-3 text-sm font-medium transition-colors ${a===`3d`?`text-bambu-green border-b-2 border-bambu-green`:m?`text-bambu-gray hover:text-white`:`text-bambu-gray/30 cursor-not-allowed`}`,children:[(0,$.jsx)(j,{className:`w-4 h-4`}),`3D Model`,!m&&(0,$.jsx)(`span`,{className:`text-xs`,children:`(not available)`})]}),(0,$.jsxs)(`button`,{onClick:()=>h&&o(`gcode`),disabled:!h,className:`flex items-center gap-2 px-6 py-3 text-sm font-medium transition-colors ${a===`gcode`?`text-bambu-green border-b-2 border-bambu-green`:h?`text-bambu-gray hover:text-white`:`text-bambu-gray/30 cursor-not-allowed`}`,children:[(0,$.jsx)(or,{className:`w-4 h-4`}),`G-code Preview`,!h&&(0,$.jsx)(`span`,{className:`text-xs`,children:`(not sliced)`})]})]}),(0,$.jsx)(`div`,{className:`flex-1 overflow-hidden p-4`,children:a===`3d`&&m?(0,$.jsxs)(`div`,{className:`w-full h-full flex flex-col gap-3`,children:[g&&(0,$.jsxs)(`div`,{className:`rounded-lg border border-bambu-dark-tertiary bg-bambu-dark p-3`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-bambu-gray mb-2`,children:[(0,$.jsx)(j,{className:`w-4 h-4`}),`Plates`,l&&(0,$.jsx)(H,{className:`w-3 h-3 animate-spin`})]}),(0,$.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-3 gap-2`,children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>f(null),className:`flex items-center gap-2 rounded-lg border p-2 text-left transition-colors ${d==null?`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary bg-bambu-dark-secondary hover:border-bambu-gray`}`,children:[(0,$.jsx)(`div`,{className:`w-10 h-10 rounded bg-bambu-dark-tertiary flex items-center justify-center`,children:(0,$.jsx)(j,{className:`w-5 h-5 text-bambu-gray`})}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`p`,{className:`text-sm text-white font-medium truncate`,children:`All Plates`}),(0,$.jsxs)(`p`,{className:`text-xs text-bambu-gray truncate`,children:[s.length,` plate`,s.length===1?``:`s`]})]}),d==null&&(0,$.jsx)(xn,{className:`w-4 h-4 text-bambu-green flex-shrink-0`})]}),s.map(n=>(0,$.jsxs)(`button`,{type:`button`,onClick:()=>f(n.index),className:`flex items-center gap-2 rounded-lg border p-2 text-left transition-colors ${d===n.index?`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary bg-bambu-dark-secondary hover:border-bambu-gray`}`,children:[n.has_thumbnail?(0,$.jsx)(`img`,{src:i.getPrinterFilePlateThumbnail(e,n.index,t),alt:`Plate ${n.index}`,className:`w-10 h-10 rounded object-cover bg-bambu-dark-tertiary`}):(0,$.jsx)(`div`,{className:`w-10 h-10 rounded bg-bambu-dark-tertiary flex items-center justify-center`,children:(0,$.jsx)(j,{className:`w-5 h-5 text-bambu-gray`})}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`p`,{className:`text-sm text-white font-medium truncate`,children:n.name||`Plate ${n.index}`}),(0,$.jsx)(`p`,{className:`text-xs text-bambu-gray truncate`,children:n.objects.length>0?n.objects.slice(0,2).join(`, `)+(n.objects.length>2?`…`:``):`${n.filaments.length} filament${n.filaments.length===1?``:`s`}`})]}),d===n.index&&(0,$.jsx)(xn,{className:`w-4 h-4 text-bambu-green flex-shrink-0`})]},n.index))]}),_&&(0,$.jsxs)(`div`,{className:`mt-3 text-xs text-bambu-gray flex flex-wrap gap-x-4 gap-y-1`,children:[(0,$.jsxs)(`span`,{children:[`Plate `,_.index]}),_.print_time_seconds!=null&&(0,$.jsxs)(`span`,{children:[`ETA `,Math.round(_.print_time_seconds/60),` min`]}),_.filament_used_grams!=null&&(0,$.jsxs)(`span`,{children:[_.filament_used_grams.toFixed(1),` g`]}),_.filaments.length>0&&(0,$.jsxs)(`span`,{children:[_.filaments.length,` filament`,_.filaments.length===1?``:`s`]})]})]}),(0,$.jsx)(`div`,{className:`flex-1`,children:(0,$.jsx)(dr,{url:i.getPrinterFileDownloadUrl(e,t),fileType:p,selectedPlateId:d,className:`w-full h-full`})})]}):a===`gcode`&&h?(0,$.jsx)(ae,{gcodeUrl:i.getPrinterFileGcodeUrl(e,t),className:`w-full h-full`}):(0,$.jsx)(`div`,{className:`w-full h-full flex items-center justify-center text-bambu-gray`,children:`No preview available for this file`})})]})})}function Ri(e){if(e===0)return`0 GB`;let t=e/(1024*1024*1024);return t>=1?`${t.toFixed(1)} GB`:`${(e/(1024*1024)).toFixed(0)} MB`}function zi(e,t){if(t)return Fn;switch(e.toLowerCase().split(`.`).pop()||``){case`3mf`:return ie;case`gcode`:return or;case`mp4`:case`avi`:return se;case`png`:case`jpg`:case`jpeg`:return tr;default:return V}}var Bi=[{value:`name-asc`,label:`Name (A-Z)`},{value:`name-desc`,label:`Name (Z-A)`},{value:`size-asc`,label:`Size (smallest)`},{value:`size-desc`,label:`Size (largest)`},{value:`date-asc`,label:`Date (oldest)`},{value:`date-desc`,label:`Date (newest)`}];function Vi({printerId:e,printerName:t,onClose:n}){let{t:r}=l(),{showToast:a}=te(),o=f(),[s,c]=(0,X.useState)(`/`),[u,d]=(0,X.useState)(new Set),[h,g]=(0,X.useState)(``),[_,v]=(0,X.useState)([]),[y,b]=(0,X.useState)(`name-asc`),[x,S]=(0,X.useState)(null),[C,w]=(0,X.useState)(null),E=(0,X.useRef)(null),D=(0,X.useRef)(null);(0,X.useEffect)(()=>{let e=e=>{e.key===`Escape`&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n]);let{data:O,isLoading:k,refetch:A}=p({queryKey:[`printerFiles`,e,s],queryFn:()=>i.getPrinterFiles(e,s)}),{data:M}=p({queryKey:[`printerStorage`,e],queryFn:()=>i.getPrinterStorage(e),staleTime:3e4}),N=(0,X.useMemo)(()=>[...O?.files??[]].filter(e=>!h||e.name.toLowerCase().includes(h.toLowerCase())).sort((e,t)=>{if(e.is_directory&&!t.is_directory)return-1;if(!e.is_directory&&t.is_directory)return 1;switch(y){case`name-asc`:return e.name.localeCompare(t.name);case`name-desc`:return t.name.localeCompare(e.name);case`size-asc`:return e.size-t.size;case`size-desc`:return t.size-e.size;case`date-asc`:return(e.mtime?qt(e.mtime)?.getTime()??0:0)-(t.mtime?qt(t.mtime)?.getTime()??0:0);case`date-desc`:{let n=e.mtime?qt(e.mtime)?.getTime()??0:0;return(t.mtime?qt(t.mtime)?.getTime()??0:0)-n}default:return e.name.localeCompare(t.name)}}),[O?.files,h,y]),P=!!O&&!O.warnings?.includes(`printer_unavailable`);(0,X.useEffect)(()=>{if(!P)return;let e=new Set(N.filter(e=>!e.is_directory).map(e=>e.path));d(t=>new Set([...t].filter(t=>e.has(t)))),E.current&&!e.has(E.current)&&(E.current=null)},[N,P]),(0,X.useEffect)(()=>()=>D.current?.abort(),[]);let F=m({mutationFn:async t=>{for(let n of t)await i.deletePrinterFile(e,n)},onSuccess:()=>{a(r(`printerFiles.toast.filesDeleted`,{count:_.length})),o.invalidateQueries({queryKey:[`printerFiles`,e]}),d(new Set),E.current=null,v([])},onError:e=>{a(r(`printerFiles.toast.deleteFailed`,{error:e.message}),`error`)}}),I=e=>{c(e),d(new Set),E.current=null},L=()=>{if(s===`/`)return;let e=s.split(`/`).filter(Boolean);e.pop(),c(e.length?`/`+e.join(`/`):`/`),d(new Set),E.current=null},R=(e,t)=>{t.stopPropagation();let n=N.filter(e=>!e.is_directory).map(e=>e.path),r=E.current?n.indexOf(E.current):-1,i=n.indexOf(e),a=t.shiftKey&&r!==-1&&i!==-1;a||(E.current=e),d(t=>{let o=new Set(t);if(a){let e=Math.min(r,i),t=Math.max(r,i);n.slice(e,t+1).forEach(e=>o.add(e))}else o.has(e)?o.delete(e):o.add(e);return o})};return(0,$.jsxs)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,onClick:n,children:[(0,$.jsxs)(`div`,{className:`w-full max-w-3xl max-h-[85vh] flex flex-col bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary overflow-hidden`,onClick:e=>e.stopPropagation(),children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary flex-shrink-0`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsx)(fe,{className:`w-5 h-5 text-bambu-green`}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:r(`printerFiles.title`)}),(0,$.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:t})]})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-4`,children:[M&&(M.used_bytes!=null||M.free_bytes!=null)&&(0,$.jsxs)(`div`,{className:`text-sm text-bambu-gray flex items-center gap-2`,children:[M.used_bytes!=null&&(0,$.jsxs)(`span`,{children:[r(`printerFiles.storageUsed`),` `,Ri(M.used_bytes)]}),M.used_bytes!=null&&M.free_bytes!=null&&(0,$.jsx)(`span`,{className:`text-bambu-dark-tertiary`,children:`|`}),M.free_bytes!=null&&(0,$.jsxs)(`span`,{children:[r(`printerFiles.storageFree`),` `,Ri(M.free_bytes)]})]}),(0,$.jsx)(`button`,{onClick:n,className:`text-bambu-gray hover:text-white transition-colors`,title:`Close file manager`,"aria-label":`Close file manager`,children:(0,$.jsx)(Pt,{className:`w-5 h-5`})})]})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2 p-3 border-b border-bambu-dark-tertiary bg-bambu-dark/50 flex-shrink-0`,children:[[{path:`/`,label:`Root`},{path:`/cache`,label:`Cache`},{path:`/model`,label:`Models`},{path:`/timelapse`,label:`Timelapse`}].map(e=>(0,$.jsx)(`button`,{onClick:()=>{I(e.path),g(``)},className:`px-3 py-1 text-sm rounded-full transition-colors ${s===e.path?`bg-bambu-green text-white`:`bg-bambu-dark-tertiary text-bambu-gray hover:text-white`}`,children:e.label},e.path)),(0,$.jsx)(`div`,{className:`flex-1`}),(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsx)(Ae,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,$.jsx)(`input`,{type:`text`,placeholder:r(`printerFiles.filterPlaceholder`),value:h,onChange:e=>g(e.target.value),className:`w-40 pl-8 pr-3 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`})]}),(0,$.jsxs)(`div`,{className:`relative flex items-center gap-1`,children:[(0,$.jsx)(T,{className:`w-4 h-4 text-bambu-gray`}),(0,$.jsx)(`select`,{value:y,onChange:e=>b(e.target.value),className:`appearance-none bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm py-1.5 pl-2 pr-6 focus:border-bambu-green focus:outline-none cursor-pointer`,title:`Sort files`,"aria-label":`Sort files`,children:Bi.map(e=>(0,$.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),(0,$.jsx)(Y,{variant:`secondary`,size:`sm`,onClick:()=>A(),disabled:k,"aria-label":r(`common.refresh`),title:r(`common.refresh`),children:(0,$.jsx)(dn,{className:`w-4 h-4 ${k?`animate-spin`:``}`})})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2 px-4 py-2 bg-bambu-dark text-sm flex-shrink-0`,children:[(0,$.jsx)(`button`,{onClick:L,disabled:s===`/`,className:`p-1 rounded hover:bg-bambu-dark-tertiary disabled:opacity-50 disabled:cursor-not-allowed`,title:`Go to parent folder`,"aria-label":`Go to parent folder`,children:(0,$.jsx)(Yn,{className:`w-4 h-4`})}),(0,$.jsx)(`span`,{className:`text-bambu-gray font-mono`,children:s})]}),(0,$.jsx)(`div`,{className:`flex-1 overflow-y-auto p-2 min-h-0`,children:k?(0,$.jsx)(`div`,{className:`flex items-center justify-center py-12`,children:(0,$.jsx)(H,{className:`w-8 h-8 text-bambu-green animate-spin`})}):O?.warnings?.includes(`printer_unavailable`)?(0,$.jsx)(`div`,{className:`text-center py-12 text-amber-600 dark:text-amber-400`,children:r(`printerFiles.printerUnavailable`)}):O?.files?.length?(0,$.jsx)(`div`,{className:`space-y-1`,children:N.map(e=>{let t=zi(e.name,e.is_directory),n=u.has(e.path);return(0,$.jsxs)(`div`,{className:`flex items-center gap-3 p-2 rounded-lg cursor-pointer transition-colors ${n?`bg-bambu-green/20 border border-bambu-green/50`:`hover:bg-bambu-dark-tertiary`}`,onClick:t=>{e.is_directory?I(e.path):R(e.path,t)},children:[e.is_directory?null:(0,$.jsx)(`button`,{onClick:t=>R(e.path,t),className:`flex-shrink-0 text-bambu-gray hover:text-white`,"aria-label":r(n?`printerFiles.deselectFile`:`printerFiles.selectFile`,{name:e.name}),title:r(`printerFiles.shiftSelectHint`),children:n?(0,$.jsx)(xn,{className:`w-5 h-5 text-bambu-green`}):(0,$.jsx)(fn,{className:`w-5 h-5`})}),(0,$.jsx)(t,{className:`w-5 h-5 flex-shrink-0 ${e.is_directory?`text-bambu-green`:`text-bambu-gray`}`}),(0,$.jsx)(`span`,{className:`flex-1 text-white truncate`,children:e.name}),!e.is_directory&&(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:zt(e.size)}),(e.name.toLowerCase().endsWith(`.3mf`)||e.name.toLowerCase().endsWith(`.gcode`)||e.name.toLowerCase().endsWith(`.stl`))&&(0,$.jsx)(`button`,{onClick:t=>{t.stopPropagation(),w({path:e.path,name:e.name})},className:`p-1 rounded hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green`,title:`3D View`,children:(0,$.jsx)(j,{className:`w-4 h-4`})})]}),e.is_directory&&(0,$.jsx)(Yn,{className:`w-4 h-4 text-bambu-gray rotate-180`})]},e.path)})}):(0,$.jsx)(`div`,{className:`text-center py-12 text-bambu-gray`,children:r(`printerFiles.noFiles`)})}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-t border-bambu-dark-tertiary bg-bambu-dark/50 flex-shrink-0`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,$.jsx)(`div`,{className:`text-sm text-bambu-gray`,children:u.size>0?`${u.size} selected`:h?`${O?.files?.filter(e=>e.name.toLowerCase().includes(h.toLowerCase())).length||0} of ${O?.files?.length||0} items`:`${O?.files?.length||0} items`}),O?.files?.some(e=>!e.is_directory)&&(0,$.jsx)(`div`,{className:`flex items-center gap-2`,children:u.size>0?(0,$.jsxs)(`button`,{onClick:()=>{d(new Set),E.current=null},className:`flex items-center gap-1 text-xs text-bambu-gray hover:text-white transition-colors`,children:[(0,$.jsx)(Mr,{className:`w-4 h-4`}),`Deselect All`]}):(0,$.jsxs)(`button`,{onClick:()=>{let e=N.filter(e=>!e.is_directory).map(e=>e.path);d(new Set(e)),E.current=null},className:`flex items-center gap-1 text-xs text-bambu-gray hover:text-white transition-colors`,children:[(0,$.jsx)(xn,{className:`w-4 h-4`}),`Select All`]})})]}),(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(Y,{variant:`secondary`,disabled:u.size===0||x!==null,onClick:async()=>{if(u.size===0)return;let n=N.filter(e=>!e.is_directory&&u.has(e.path)).map(e=>e.path);if(n.length===0)return;let o=new AbortController;D.current=o,S({current:0,total:n.length});try{let s=Object.fromEntries(n.map(e=>[e,O?.files.find(t=>t.path===e)?.size??0])),c=await i.downloadPrinterFilesAsZip(e,n,s,n.length===1?O?.files.find(e=>e.path===n[0])?.name??`printer-file`:`${t.replace(/[^a-zA-Z0-9]/g,`_`)}-files.zip`,n.length>1,o.signal,(e,t)=>S({current:e,total:t}));c.failed>0?a(r(`printerFiles.zipPartial`,{successful:c.successful,total:c.requested}),`warning`):a(r(`printerFiles.zipStarted`,{count:c.successful})),d(new Set),E.current=null}catch(e){a(r(`printerFiles.downloadFailed`,{error:e instanceof Error?e.message:r(`printerFiles.unknownError`)}),`error`)}finally{D.current===o&&(D.current=null),S(null)}},children:x?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(H,{className:`w-4 h-4 animate-spin`}),x.current,`/`,x.total]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(ar,{className:`w-4 h-4`}),`Download`,u.size>1?` (${u.size})`:``]})}),(0,$.jsxs)(Y,{variant:`secondary`,disabled:u.size===0||F.isPending,onClick:()=>{u.size!==0&&v(N.filter(e=>!e.is_directory&&u.has(e.path)).map(e=>e.path))},className:`text-red-700 hover:text-red-800 dark:text-red-400 dark:hover:text-red-300`,children:[F.isPending?(0,$.jsx)(H,{className:`w-4 h-4 animate-spin`}):(0,$.jsx)(Qt,{className:`w-4 h-4`}),r(`printerFiles.deleteButton`),u.size>1?` (${u.size})`:``]})]})]})]}),_.length>0&&(0,$.jsx)(In,{title:_.length>1?r(`printerFiles.deleteFiles`,{count:_.length}):r(`fileManager.deleteFile`),message:_.length>1?r(`printerFiles.deleteFilesConfirm`,{count:_.length}):r(`printerFiles.deleteFileConfirm`,{name:_[0].split(`/`).pop()}),confirmText:r(`common.delete`),variant:`danger`,onConfirm:()=>{F.mutate(_)},onCancel:()=>v([])}),C&&(0,$.jsx)(Li,{printerId:e,filePath:C.path,filename:C.name,onClose:()=>w(null)})]})}var Hi=`embeddedCameraState_`,Ui=5,Wi=2e3,Gi=3e4,Ki=5e3,qi={x:window.innerWidth-420,y:20,width:400,height:300};function Ji({printerId:e,printerName:t,viewerIndex:n=0,onClose:a}){let{t:s}=l(),c=f(),{showToast:u}=te(),{hasPermission:d}=lr(),h=`${Hi}${e}`,[g,_]=(0,X.useState)(()=>{try{let e=localStorage.getItem(h);if(e){let t=JSON.parse(e);return{x:Math.min(Math.max(0,t.x),window.innerWidth-100),y:Math.min(Math.max(0,t.y),window.innerHeight-100),width:Math.max(200,Math.min(t.width,window.innerWidth-20)),height:Math.max(150,Math.min(t.height,window.innerHeight-20))}}}catch{}let e=n*30;return{...qi,x:Math.max(0,qi.x-e),y:Math.max(0,qi.y+e)}}),[v,y]=(0,X.useState)(!1),[b,x]=(0,X.useState)(!1),[S,C]=(0,X.useState)({x:0,y:0}),[w,T]=(0,X.useState)(!1),[E,D]=(0,X.useState)(!1),[O,k]=(0,X.useState)(1),[A,j]=(0,X.useState)({x:0,y:0}),[M,N]=(0,X.useState)(!1),[P,F]=(0,X.useState)({x:0,y:0}),[I,L]=(0,X.useState)(null),[R,ee]=(0,X.useState)(null),[ne,z]=(0,X.useState)(!1),[re,B]=(0,X.useState)(!0),[ie,ae]=(0,X.useState)(Date.now()),[V,oe]=(0,X.useState)(0),[se,ce]=(0,X.useState)(!1),[le,ue]=(0,X.useState)(0),fe=(0,X.useRef)(null),pe=(0,X.useRef)(null),H=(0,X.useRef)(null),me=(0,X.useRef)(null),G=(0,X.useRef)(null),[be,xe]=(0,X.useState)(!1),[Se,K]=(0,X.useState)(!1),{data:Ce}=p({queryKey:[`printer`,e],queryFn:()=>i.getPrinter(e),enabled:e>0}),{data:we}=p({queryKey:[`printerStatus`,e],queryFn:()=>i.getPrinterStatus(e),refetchInterval:3e4,enabled:e>0}),Te=m({mutationFn:t=>i.setChamberLight(e,t),onMutate:async t=>{await c.cancelQueries({queryKey:[`printerStatus`,e]});let n=c.getQueryData([`printerStatus`,e]);return c.setQueryData([`printerStatus`,e],e=>({...e,chamber_light:t})),{previousStatus:n}},onSuccess:(e,t)=>{u(`Chamber light ${t?`on`:`off`}`)},onError:(t,n,r)=>{r?.previousStatus&&c.setQueryData([`printerStatus`,e],r.previousStatus),u(t.message||s(`printers.toast.failedToControlChamberLight`),`error`)}}),q=(we?.state===`RUNNING`||we?.state===`PAUSE`)&&(we?.printable_objects_count??0)>=2;(0,X.useEffect)(()=>{let e=setTimeout(()=>{localStorage.setItem(h,JSON.stringify(g))},500);return()=>clearTimeout(e)},[g,h]);let J=(0,X.useRef)(!1);(0,X.useEffect)(()=>{J.current=!1;let t=`/api/v1/printers/${e}/camera/stop`,n=()=>{if(e>0&&!J.current){J.current=!0;let e={},n=o();n&&(e.Authorization=`Bearer ${n}`),fetch(t,{method:`POST`,keepalive:!0,headers:e}).catch(()=>{})}},r=pe.current;return()=>{r&&(r.src=``),n(),H.current&&clearTimeout(H.current),me.current&&clearInterval(me.current),G.current&&clearInterval(G.current)}},[e]),(0,X.useEffect)(()=>{if(re){let e=setTimeout(()=>B(!1),3e3);return()=>clearTimeout(e)}},[re,ie]);let Ee=(0,X.useCallback)(()=>{if(V>=Ui){ce(!1),z(!0);return}let e=Math.min(Wi*2**V,Gi);ce(!0),ue(Math.ceil(e/1e3)),me.current=setInterval(()=>{ue(e=>e<=1?(me.current&&clearInterval(me.current),0):e-1)},1e3),H.current=setTimeout(()=>{oe(e=>e+1),ce(!1),B(!0),z(!1),pe.current&&(pe.current.src=``),ae(Date.now())},e)},[V]);(0,X.useEffect)(()=>{if(re||se||w){G.current&&=(clearInterval(G.current),null);return}return G.current=setInterval(async()=>{try{let t=await i.getCameraStatus(e);(t.stalled||!t.active&&!ne)&&(G.current&&=(clearInterval(G.current),null),B(!1),Ee())}catch{}},Ki),()=>{G.current&&=(clearInterval(G.current),null)}},[re,ne,se,w,e,Ee]),(0,X.useEffect)(()=>{let e=()=>{let e=!!document.fullscreenElement;D(e),e||(k(1),j({x:0,y:0}))};return document.addEventListener(`fullscreenchange`,e),()=>document.removeEventListener(`fullscreenchange`,e)},[]);let De=()=>{fe.current&&(document.fullscreenElement?document.exitFullscreen():fe.current.requestFullscreen())},Oe=()=>{k(e=>Math.min(e+.5,4))},ke=()=>{k(e=>{let t=Math.max(e-.5,1);return t===1&&j({x:0,y:0}),t})},Ae=e=>{e.preventDefault(),e.deltaY<0?Oe():ke()},je=e=>{O>1&&(e.preventDefault(),N(!0),F({x:e.clientX-A.x,y:e.clientY-A.y}))},Me=(0,X.useCallback)(()=>{if(!fe.current||!pe.current)return{x:200,y:150};let e=fe.current.getBoundingClientRect(),t=e.width*(O-1)/2,n=e.height*(O-1)/2;return{x:Math.max(50,t),y:Math.max(50,n)}},[O]),Ne=e=>{if(M&&O>1){let t=e.clientX-P.x,n=e.clientY-P.y,r=Me();j({x:Math.max(-r.x,Math.min(r.x,t)),y:Math.max(-r.y,Math.min(r.y,n))})}},Pe=()=>{N(!1)},Fe=e=>{if(e.length<2)return 0;let t=e[0].clientX-e[1].clientX,n=e[0].clientY-e[1].clientY;return Math.sqrt(t*t+n*n)},Ie=e=>e.length<2?{x:e[0].clientX,y:e[0].clientY}:{x:(e[0].clientX+e[1].clientX)/2,y:(e[0].clientY+e[1].clientY)/2},Le=e=>{e.touches.length===2?(e.preventDefault(),L(Fe(e.touches)),ee(Ie(e.touches))):e.touches.length===1&&O>1&&(e.preventDefault(),N(!0),F({x:e.touches[0].clientX-A.x,y:e.touches[0].clientY-A.y}))},Re=e=>{if(e.touches.length===2&&I!==null){e.preventDefault();let t=Fe(e.touches),n=t/I;k(e=>{let t=Math.max(1,Math.min(4,e*n));return t===1&&j({x:0,y:0}),t}),L(t);let r=Ie(e.touches);if(R){let e=Me();j(t=>({x:Math.max(-e.x,Math.min(e.x,t.x+(r.x-R.x))),y:Math.max(-e.y,Math.min(e.y,t.y+(r.y-R.y)))}))}ee(r)}else if(e.touches.length===1&&M&&O>1){e.preventDefault();let t=e.touches[0].clientX-P.x,n=e.touches[0].clientY-P.y,r=Me();j({x:Math.max(-r.x,Math.min(r.x,t)),y:Math.max(-r.y,Math.min(r.y,n))})}},ze=e=>{e.touches.length<2&&(L(null),ee(null)),e.touches.length===0&&N(!1)},Be=()=>{k(1),j({x:0,y:0})},Ve=()=>{B(!1),V{B(!1),z(!1),oe(0),ce(!1),H.current&&clearTimeout(H.current),me.current&&clearInterval(me.current)},Ue=()=>{B(!0),z(!1),oe(0),ce(!1),H.current&&clearTimeout(H.current),me.current&&clearInterval(me.current);let t={},n=o();n&&(t.Authorization=`Bearer ${n}`),fetch(`/api/v1/printers/${e}/camera/stop`,{method:`POST`,headers:t}).catch(()=>{}),pe.current&&(pe.current.src=``),setTimeout(()=>ae(Date.now()),100)},We=e=>{e.target.closest(`.no-drag`)||(y(!0),C({x:e.clientX-g.x,y:e.clientY-g.y}))},Ge=e=>{if(e.target.closest(`.no-drag`))return;let t=e.touches[0];y(!0),C({x:t.clientX-g.x,y:t.clientY-g.y})},Ke=e=>{e.stopPropagation(),x(!0)},qe=e=>{e.stopPropagation(),x(!0)};(0,X.useEffect)(()=>{let e=e=>{if(v)_(t=>({...t,x:Math.max(0,Math.min(e.clientX-S.x,window.innerWidth-t.width)),y:Math.max(0,Math.min(e.clientY-S.y,window.innerHeight-t.height))}));else if(b&&fe.current){let t=fe.current.getBoundingClientRect();_(n=>({...n,width:Math.max(200,Math.min(e.clientX-t.left,window.innerWidth-n.x-10)),height:Math.max(150,Math.min(e.clientY-t.top,window.innerHeight-n.y-10))}))}},t=e=>{if(!v&&!b)return;e.preventDefault();let t=e.touches[0];if(v)_(e=>({...e,x:Math.max(0,Math.min(t.clientX-S.x,window.innerWidth-e.width)),y:Math.max(0,Math.min(t.clientY-S.y,window.innerHeight-e.height))}));else if(b&&fe.current){let e=fe.current.getBoundingClientRect();_(n=>({...n,width:Math.max(200,Math.min(t.clientX-e.left,window.innerWidth-n.x-10)),height:Math.max(150,Math.min(t.clientY-e.top,window.innerHeight-n.y-10))}))}},n=()=>{y(!1),x(!1)};if(v||b)return document.addEventListener(`mousemove`,e),document.addEventListener(`mouseup`,n),document.addEventListener(`touchmove`,t,{passive:!1}),document.addEventListener(`touchend`,n),document.addEventListener(`touchcancel`,n),()=>{document.removeEventListener(`mousemove`,e),document.removeEventListener(`mouseup`,n),document.removeEventListener(`touchmove`,t),document.removeEventListener(`touchend`,n),document.removeEventListener(`touchcancel`,n)}},[v,b,S]);let Je=r(`/api/v1/printers/${e}/camera/stream?fps=15&t=${ie}`);return(0,$.jsxs)(`div`,{ref:fe,className:`${E?`fixed inset-0 z-[100]`:`fixed z-40 rounded-lg shadow-2xl border border-bambu-dark-tertiary`} bg-bambu-dark-secondary overflow-hidden`,style:E?void 0:{left:g.x,top:g.y,width:w?200:g.width,height:w?40:g.height,cursor:v?`grabbing`:`default`},children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-2 bg-bambu-dark border-b border-bambu-dark-tertiary cursor-grab active:cursor-grabbing`,onMouseDown:We,onTouchStart:Ge,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-white truncate`,children:[(0,$.jsx)(de,{className:`w-4 h-4 text-bambu-gray flex-shrink-0`}),(0,$.jsx)(`span`,{className:`truncate`,children:Ce?.name||t})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1 no-drag`,children:[(0,$.jsx)(`button`,{onClick:()=>Te.mutate(!we?.chamber_light),disabled:!we?.connected||Te.isPending||!d(`printers:control`),className:`p-1 rounded disabled:opacity-50 ${we?.chamber_light?`bg-yellow-500/20 hover:bg-yellow-500/30`:`hover:bg-bambu-dark-tertiary`}`,title:d(`printers:control`)?s(`camera.chamberLight`):s(`printers.permission.noControl`),children:(0,$.jsx)(_e,{on:we?.chamber_light??!1,className:`w-3.5 h-3.5`})}),(0,$.jsx)(`button`,{onClick:()=>xe(!0),disabled:!q||!d(`printers:control`),className:`p-1 rounded disabled:opacity-50 ${q&&d(`printers:control`)?`hover:bg-bambu-dark-tertiary`:``}`,title:d(`printers:control`)?s(q?`printers.skipObjects.tooltip`:`printers.skipObjects.onlyWhilePrinting`):s(`printers.permission.noControl`),children:(0,$.jsx)(ve,{className:`w-3.5 h-3.5 text-bambu-gray`})}),(0,$.jsx)(`button`,{onClick:Ue,disabled:re||se,className:`p-1 hover:bg-bambu-dark-tertiary rounded disabled:opacity-50`,title:`Refresh stream`,children:(0,$.jsx)(dn,{className:`w-3.5 h-3.5 text-bambu-gray ${re?`animate-spin`:``}`})}),(0,$.jsx)(`button`,{onClick:()=>K(!0),className:`p-1 hover:bg-bambu-dark-tertiary rounded`,title:s(`camera.diagnose.button`),children:(0,$.jsx)(an,{className:`w-3.5 h-3.5 text-bambu-gray`})}),(0,$.jsx)(`button`,{onClick:De,className:`p-1 hover:bg-bambu-dark-tertiary rounded`,title:E?`Exit fullscreen`:`Fullscreen`,children:E?(0,$.jsx)(ge,{className:`w-3.5 h-3.5 text-bambu-gray`}):(0,$.jsx)(wr,{className:`w-3.5 h-3.5 text-bambu-gray`})}),(0,$.jsx)(`button`,{onClick:()=>T(!w),className:`p-1 hover:bg-bambu-dark-tertiary rounded`,title:w?`Expand`:`Minimize`,children:w?(0,$.jsx)(he,{className:`w-3.5 h-3.5 text-bambu-gray`}):(0,$.jsx)(U,{className:`w-3.5 h-3.5 text-bambu-gray`})}),(0,$.jsx)(`button`,{onClick:a,className:`p-1 hover:bg-red-500/20 rounded`,title:`Close`,children:(0,$.jsx)(Pt,{className:`w-3.5 h-3.5 text-bambu-gray hover:text-red-600 dark:hover:text-red-400`})})]})]}),!w&&(0,$.jsxs)(`div`,{className:`relative w-full bg-black flex items-center justify-center overflow-hidden h-[calc(100%-40px)]`,onWheel:Ae,onMouseMove:Ne,onMouseUp:Pe,onMouseLeave:Pe,onTouchStart:Le,onTouchMove:Re,onTouchEnd:ze,style:{touchAction:`none`},children:[re&&!se&&(0,$.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-black/50 z-10`,children:(0,$.jsx)(dn,{className:`w-6 h-6 text-bambu-gray animate-spin`})}),se&&(0,$.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-black/80 z-10`,children:(0,$.jsxs)(`div`,{className:`text-center p-2`,children:[(0,$.jsx)(en,{className:`w-6 h-6 text-orange-400 mx-auto mb-2`}),(0,$.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[`Reconnecting in `,le,`s...`]})]})}),ne&&!se&&(0,$.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-black z-10`,children:(0,$.jsxs)(`div`,{className:`text-center p-2`,children:[(0,$.jsx)(Ot,{className:`w-6 h-6 text-orange-400 mx-auto mb-2`}),(0,$.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:s(`camera.unavailable`)}),(0,$.jsxs)(`div`,{className:`flex gap-2 justify-center`,children:[(0,$.jsx)(`button`,{onClick:Ue,className:`px-2 py-1 text-xs bg-bambu-green text-white rounded hover:bg-bambu-green/80`,children:s(`camera.retry`)}),(0,$.jsx)(`button`,{onClick:()=>K(!0),className:`px-2 py-1 text-xs bg-bambu-dark border border-bambu-dark-tertiary text-bambu-gray hover:text-white rounded transition-colors`,children:s(`camera.diagnose.button`)})]})]})}),(0,$.jsx)(`img`,{ref:pe,src:Je,alt:`Camera stream`,className:`max-w-full max-h-full object-contain select-none`,style:{transform:`scale(${O}) translate(${A.x/O}px, ${A.y/O}px) rotate(${Ce?.camera_rotation||0}deg)`,...Ce?.camera_rotation===90||Ce?.camera_rotation===270?{maxWidth:`100%`,maxHeight:`100%`}:{},cursor:O>1?M?`grabbing`:`grab`:`default`},onError:Ve,onLoad:He,onMouseDown:je,draggable:!1},ie),(0,$.jsxs)(`div`,{className:`absolute bottom-2 left-2 flex items-center gap-1 bg-black/60 rounded px-1.5 py-1 no-drag`,children:[(0,$.jsx)(`button`,{onClick:ke,disabled:O<=1,className:`p-1 hover:bg-white/10 rounded disabled:opacity-30`,title:`Zoom out`,children:(0,$.jsx)(It,{className:`w-3.5 h-3.5 text-white`})}),(0,$.jsxs)(`button`,{onClick:Be,className:`px-1.5 py-0.5 text-xs text-white hover:bg-white/10 rounded min-w-[32px]`,title:`Reset zoom`,children:[Math.round(O*100),`%`]}),(0,$.jsx)(`button`,{onClick:Oe,disabled:O>=4,className:`p-1 hover:bg-white/10 rounded disabled:opacity-30`,title:`Zoom in`,children:(0,$.jsx)(Ft,{className:`w-3.5 h-3.5 text-white`})})]}),!E&&(0,$.jsx)(`div`,{className:`absolute bottom-0 right-0 w-6 h-6 cursor-se-resize no-drag hover:bg-white/10 rounded-tl transition-colors`,onMouseDown:Ke,onTouchStart:qe,title:`Drag to resize`,children:(0,$.jsx)(`svg`,{className:`w-6 h-6 text-bambu-gray/70 hover:text-bambu-gray`,viewBox:`0 0 24 24`,fill:`currentColor`,children:(0,$.jsx)(`path`,{d:`M22 22H20V20H22V22ZM22 18H20V16H22V18ZM18 22H16V20H18V22ZM22 14H20V12H22V14ZM18 18H16V16H18V18ZM14 22H12V20H14V22ZM22 10H20V8H22V10ZM18 14H16V12H18V14ZM14 18H12V16H14V18ZM10 22H8V20H10V22Z`})})})]}),(0,$.jsx)(ye,{printerId:e,isOpen:be,onClose:()=>xe(!1)}),Se&&(0,$.jsx)(W,{printerId:e,printerName:Ce?.name||null,onClose:()=>K(!1)})]})}function Yi({printerId:e,printerName:t,onClose:n}){let{t:r}=l(),a=f(),[o,s]=(0,X.useState)(!0),[c,u]=(0,X.useState)(new Set),[d,h]=(0,X.useState)(``),[g,_]=(0,X.useState)(`all`),v=(0,X.useRef)(null),{data:y,isLoading:b,refetch:x}=p({queryKey:[`mqtt-logs`,e],queryFn:()=>i.getMQTTLogs(e),refetchInterval:1e3}),C=m({mutationFn:()=>i.enableMQTTLogging(e),onSuccess:()=>{a.invalidateQueries({queryKey:[`mqtt-logs`,e]})}}),w=m({mutationFn:()=>i.disableMQTTLogging(e),onSuccess:()=>{a.invalidateQueries({queryKey:[`mqtt-logs`,e]})}}),T=m({mutationFn:()=>i.clearMQTTLogs(e),onSuccess:()=>{a.invalidateQueries({queryKey:[`mqtt-logs`,e]})}});(0,X.useEffect)(()=>{let e=e=>{e.key===`Escape`&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n]),(0,X.useEffect)(()=>{o&&v.current&&(v.current.scrollTop=v.current.scrollHeight)},[y?.logs,o]);let D=e=>{u(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},O=e=>new Date(e).toLocaleTimeString(`en-US`,{hour12:!1,fractionalSecondDigits:3}),k=(e,t)=>{if(e==null)return``;let n=typeof e==`string`?JSON.parse(e):e,r=JSON.stringify(n,null,t?2:0);return!t&&r.length>100?r.substring(0,100)+`...`:r},A=y?.logging_enabled??!1,j=(0,X.useMemo)(()=>y?.logs??[],[y?.logs]),M=(0,X.useMemo)(()=>j.filter(e=>{if(g!==`all`&&e.direction!==g)return!1;if(d.trim()){let t=d.toLowerCase(),n=e.topic.toLowerCase().includes(t),r=JSON.stringify(e.payload).toLowerCase().includes(t);return n||r}return!0}),[j,d,g]);return(0,$.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,$.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg max-w-4xl w-full max-h-[85vh] flex flex-col`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:r(`mqttDebug.title`)}),(0,$.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:t})]}),(0,$.jsx)(`button`,{onClick:n,className:`text-bambu-gray hover:text-white transition-colors`,children:(0,$.jsx)(Pt,{className:`w-5 h-5`})})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 p-4 border-b border-bambu-dark-tertiary`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[A?(0,$.jsxs)(Y,{size:`sm`,variant:`secondary`,onClick:()=>w.mutate(),disabled:w.isPending,children:[(0,$.jsx)(fn,{className:`w-4 h-4`}),r(`mqttDebug.stopLogging`)]}):(0,$.jsxs)(Y,{size:`sm`,onClick:()=>C.mutate(),disabled:C.isPending,children:[(0,$.jsx)(ke,{className:`w-4 h-4`}),r(`mqttDebug.startLogging`)]}),(0,$.jsxs)(Y,{size:`sm`,variant:`secondary`,onClick:()=>T.mutate(),disabled:T.isPending||j.length===0,children:[(0,$.jsx)(Qt,{className:`w-4 h-4`}),r(`mqttDebug.clearLog`)]}),(0,$.jsx)(Y,{size:`sm`,variant:`secondary`,onClick:()=>x(),disabled:b,children:(0,$.jsx)(dn,{className:`w-4 h-4 ${b?`animate-spin`:``}`})}),(0,$.jsx)(`div`,{className:`flex-1`}),(0,$.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-bambu-gray cursor-pointer`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:o,onChange:e=>s(e.target.checked),className:`rounded border-bambu-dark-tertiary`}),`Auto-scroll`]}),(0,$.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[M.length,`/`,j.length]})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsxs)(`div`,{className:`relative flex-1`,children:[(0,$.jsx)(Ae,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,$.jsx)(`input`,{type:`text`,placeholder:r(`mqttDebug.searchPlaceholder`),value:d,onChange:e=>h(e.target.value),className:`w-full pl-8 pr-3 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`}),d&&(0,$.jsx)(`button`,{onClick:()=>h(``),className:`absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white`,children:(0,$.jsx)(Pt,{className:`w-4 h-4`})})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1 bg-bambu-dark rounded border border-bambu-dark-tertiary`,children:[(0,$.jsx)(`button`,{onClick:()=>_(`all`),className:`px-2 py-1.5 text-xs rounded-l transition-colors ${g===`all`?`bg-bambu-green text-white`:`text-bambu-gray hover:text-white`}`,children:r(`mqttDebug.all`)}),(0,$.jsxs)(`button`,{onClick:()=>_(`in`),className:`px-2 py-1.5 text-xs transition-colors flex items-center gap-1 ${g===`in`?`bg-blue-500 text-white`:`text-bambu-gray hover:text-white`}`,children:[(0,$.jsx)(S,{className:`w-3 h-3`}),r(`mqttDebug.incoming`)]}),(0,$.jsxs)(`button`,{onClick:()=>_(`out`),className:`px-2 py-1.5 text-xs rounded-r transition-colors flex items-center gap-1 ${g===`out`?`bg-green-500 text-white`:`text-bambu-gray hover:text-white`}`,children:[(0,$.jsx)(E,{className:`w-3 h-3`}),r(`mqttDebug.outgoing`)]})]})]})]}),(0,$.jsx)(`div`,{ref:v,className:`flex-1 overflow-auto p-4 font-mono text-xs bg-black min-h-[400px]`,children:j.length===0?(0,$.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full text-bambu-gray`,children:[(0,$.jsx)(`p`,{className:`mb-2`,children:r(`mqttDebug.noMessages`)}),!A&&(0,$.jsx)(`p`,{className:`text-sm`,children:r(`mqttDebug.startLoggingHint`)})]}):M.length===0?(0,$.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full text-bambu-gray`,children:[(0,$.jsx)(`p`,{className:`mb-2`,children:r(`mqttDebug.noMessagesMatch`)}),(0,$.jsx)(`p`,{className:`text-sm`,children:r(`mqttDebug.adjustFilterHint`)})]}):(0,$.jsx)(`div`,{className:`space-y-1`,children:M.map((e,t)=>{let n=c.has(t),i=e.direction===`in`;return(0,$.jsxs)(`div`,{className:`p-2 rounded cursor-pointer hover:bg-bambu-dark-secondary transition-colors ${n?`bg-bambu-dark-secondary`:``}`,onClick:()=>D(t),children:[(0,$.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,$.jsx)(`span`,{className:`text-bambu-gray shrink-0`,children:O(e.timestamp)}),(0,$.jsx)(`span`,{className:`shrink-0 ${i?`text-blue-400`:`text-green-400`}`,title:r(i?`mqttDebug.incoming`:`mqttDebug.outgoing`),children:i?(0,$.jsx)(S,{className:`w-3 h-3`}):(0,$.jsx)(E,{className:`w-3 h-3`})}),(0,$.jsx)(`span`,{className:`text-purple-400 shrink-0`,children:e.topic})]}),n?(0,$.jsx)(`pre`,{className:`mt-2 p-3 bg-gray-900 border border-gray-700 rounded text-green-400 overflow-x-auto whitespace-pre-wrap break-all max-h-96 overflow-y-auto text-xs`,children:k(e.payload,!0)}):(0,$.jsx)(`pre`,{className:`mt-1 text-white/80 truncate`,children:k(e.payload,!1)})]},t)})})}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-t border-bambu-dark-tertiary`,children:[(0,$.jsx)(`div`,{className:`text-sm text-bambu-gray`,children:A?(0,$.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`w-2 h-2 bg-green-500 rounded-full animate-pulse`}),r(`mqttDebug.loggingActive`)]}):(0,$.jsx)(`span`,{children:r(`mqttDebug.loggingStopped`)})}),(0,$.jsx)(Y,{variant:`secondary`,onClick:n,children:r(`common.close`)})]})]})})}function Xi(e){if(!e)return`idle`;switch(e.class){case`failure`:case`warning`:case`safe`:case`error`:return e.class;default:return`unknown`}}function Zi(e){return e===`failure`||e===`warning`||e===`safe`}function Qi({printerName:e,detection:t,lastError:n,onClose:r}){let{t:i}=l(),a=Tn();(0,X.useEffect)(()=>{let e=e=>{e.key===`Escape`&&r()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[r]);let o=Xi(t),s=o===`failure`?`text-status-error`:o===`warning`?`text-status-warning`:o===`safe`?`text-status-ok`:o===`error`?`text-amber-600 dark:text-amber-400`:`text-bambu-gray`,c=t?.error??n;return(0,$.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,children:(0,$.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg shadow-xl max-w-lg w-full max-h-[80vh] flex flex-col`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(K,{className:`w-5 h-5 text-bambu-green`}),(0,$.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`printers.aiDetection.modalTitle`,{name:e})})]}),(0,$.jsx)(`button`,{onClick:r,className:`p-1 hover:bg-bambu-dark-tertiary rounded-lg transition-colors`,"aria-label":i(`common.close`),children:(0,$.jsx)(Pt,{className:`w-5 h-5 text-bambu-gray`})})]}),(0,$.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-4 space-y-4 text-sm`,children:[(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsxs)(`div`,{className:`flex justify-between`,children:[(0,$.jsx)(`span`,{className:`text-bambu-gray`,children:i(`printers.aiDetection.currentStatus`)}),(0,$.jsx)(`span`,{className:`font-medium ${s}`,children:i(`printers.aiDetection.${o}`)})]}),t&&Zi(o)&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`flex justify-between`,children:[(0,$.jsx)(`span`,{className:`text-bambu-gray`,children:i(`printers.aiDetection.score`)}),(0,$.jsx)(`span`,{className:`text-white font-mono`,children:t.score.toFixed(3)})]}),(0,$.jsxs)(`div`,{className:`flex justify-between`,children:[(0,$.jsx)(`span`,{className:`text-bambu-gray`,children:i(`printers.aiDetection.framesAnalyzed`)}),(0,$.jsx)(`span`,{className:`text-white font-mono`,children:t.frame_count})]})]}),o===`error`&&(0,$.jsx)(`p`,{className:`text-bambu-gray`,children:i(`printers.aiDetection.errorHint`)}),!t&&(0,$.jsx)(`p`,{className:`text-bambu-gray`,children:i(`printers.aiDetection.idleHint`)})]}),c&&(0,$.jsxs)(`div`,{className:`flex items-start gap-2 p-3 rounded-lg bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30`,children:[(0,$.jsx)(R,{className:`w-4 h-4 mt-0.5 flex-shrink-0 text-red-700 dark:text-red-400`}),(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`div`,{className:`font-medium text-red-700 dark:text-red-400`,children:i(`printers.aiDetection.lastError`)}),(0,$.jsx)(`p`,{className:`text-red-700/80 dark:text-red-300/80 break-words mt-1`,children:c})]})]})]}),(0,$.jsx)(`div`,{className:`p-4 border-t border-bambu-dark-tertiary flex items-center justify-end`,children:(0,$.jsxs)(`button`,{onClick:()=>a(`/settings?tab=failure-detection`),className:`flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium rounded-lg bg-bambu-dark-tertiary text-bambu-gray hover:text-white transition-colors`,children:[(0,$.jsx)(En,{className:`w-4 h-4`}),i(`printers.aiDetection.openSettings`)]})})]})})}function $i({printerId:e,printerModel:t,loadedFilamentTypes:n,loadedFilaments:r,loadedVariants:a,variant:o=`card`}){let{t:s}=l(),{data:c}=p({queryKey:[`queue`,e,`pending`,t],queryFn:()=>i.getQueue(e,`pending`,t||void 0),refetchInterval:3e4}),u=c?nn(c,n,r,a):void 0,d=u?.length||0;if(d===0)return null;let f=u?.[0];return(0,$.jsx)(bn,{to:`/queue`,className:o===`panelExtension`?`block mt-2 border-t border-bambu-dark-tertiary pt-2 pl-1 hover:opacity-90 transition-opacity`:`block mb-3 p-3 bg-bambu-dark rounded-lg hover:bg-bambu-dark-tertiary transition-colors`,children:(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 flex-1`,children:[(0,$.jsx)(P,{className:`w-5 h-5 text-yellow-600 dark:text-yellow-400 flex-shrink-0`}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:s(`queue.nextInQueue`)}),(0,$.jsx)(`p`,{className:`text-sm text-white truncate`,children:f?_r(f):``})]})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[(0,$.jsxs)(`span`,{className:`text-xs text-bambu-gray flex items-center gap-1`,children:[(0,$.jsx)(vn,{className:`w-3 h-3`}),f?.scheduled_time?Kt(f.scheduled_time,`system`,s):s(`time.waiting`)]}),d>1&&(0,$.jsxs)(`span`,{className:`text-xs px-1.5 py-0.5 bg-yellow-100 dark:bg-yellow-400/20 text-yellow-700 dark:text-yellow-400 rounded`,children:[`+`,d-1]}),(0,$.jsx)(pn,{className:`w-4 h-4 text-bambu-gray`})]})]})})}function ea({printerId:e}){let{t}=l(),{data:n}=p({queryKey:[`haSensorReadings`,e],queryFn:()=>i.getHASensorReadings(e),refetchInterval:15e3});if(!n?.length)return null;let r=e=>v(e,t);return(0,$.jsxs)(`div`,{className:`flex items-center gap-2 mt-2`,children:[(0,$.jsx)(ue,{className:`w-[var(--pc-i35,0.875rem)] h-[var(--pc-i35,0.875rem)] text-blue-600 dark:text-blue-400 flex-shrink-0`}),(0,$.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:t(`haSensors.label`)}),(0,$.jsx)(`div`,{className:`h-[2px] w-5 bg-bambu-dark-tertiary/50`}),(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:n.map(e=>{let n=b(e),i=!e.reachable||e.state===null;return(0,$.jsxs)(`span`,{title:e.block_print?t(`haSensors.blocksPrints`,{entity:e.entity_id}):e.entity_id,className:`px-2 py-0.5 text-xs rounded flex items-center gap-1 ${i?`bg-bambu-dark-tertiary/50 text-bambu-gray`:e.alerting?`bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400`:`bg-bambu-dark-tertiary text-bambu-gray`}`,children:[(0,$.jsx)(n,{className:`w-[var(--pc-i25,0.625rem)] h-[var(--pc-i25,0.625rem)]`}),(0,$.jsx)(`span`,{children:e.name}),(0,$.jsx)(`span`,{className:`font-medium`,children:r(e)})]},e.id)})})]})}var ta=[{value:`6h`,label:`6h`,hours:6},{value:`24h`,label:`24h`,hours:24},{value:`48h`,label:`48h`,hours:48},{value:`7d`,label:`7d`,hours:168}];function na({isOpen:e,onClose:t,printerId:n,printerName:r,amsId:a,amsLabel:o,initialMode:s=`humidity`,thresholds:c}){let{t:u}=l(),[d,f]=(0,X.useState)(`24h`),[m,h]=(0,X.useState)(s),{data:g}=p({queryKey:[`settings`],queryFn:i.getSettings}),v=g?.time_format||`system`;(0,X.useEffect)(()=>{if(!e)return;let n=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,n),()=>window.removeEventListener(`keydown`,n)},[e,t]);let b=ta.find(e=>e.value===d)?.hours||24,{data:x,isLoading:S,error:C}=p({queryKey:[`ams-history`,n,a,b],queryFn:()=>i.getAMSHistory(n,a,b),enabled:e,refetchInterval:6e4});if(!e)return null;let w=x?.data.map(e=>({time:(qt(e.recorded_at)||new Date).getTime(),humidity:e.humidity,temperature:e.temperature}))||[],T=Date.now()-b*60*60*1e3,E=Date.now(),D=[...w];if(D.length>0){let e=D[0];e.time>T&&D.unshift({...e,time:T});let t=D[D.length-1];t.time{let t=e.filter(e=>e!=null);if(t.length<4)return`stable`;let n=t.slice(0,Math.floor(t.length/4)),r=t.slice(-Math.floor(t.length/4)),i=n.reduce((e,t)=>e+t,0)/n.length,a=r.reduce((e,t)=>e+t,0)/r.length-i;return Math.abs(a)<2?`stable`:a>0?`up`:`down`},R=L(D.map(e=>e.humidity)),ee=L(D.map(e=>e.temperature)),te=({trend:e})=>e===`up`?(0,$.jsx)(_,{className:`w-4 h-4 text-red-600 dark:text-red-400`}):e===`down`?(0,$.jsx)(Ke,{className:`w-4 h-4 text-green-600 dark:text-green-400`}):(0,$.jsx)(G,{className:`w-4 h-4 text-gray-400 dark:text-bambu-gray`}),ne=e=>e==null?`#9ca3af`:e<=k?`#22a352`:e<=j?`#d4a017`:`#c62828`,z=e=>e==null?`#9ca3af`:e<=M?`#22a352`:e<=N?`#d4a017`:`#c62828`,re=`var(--bg-secondary)`,B=`var(--bg-primary)`,ie=`var(--border-color)`,ae=`var(--text-primary)`,V=`var(--text-secondary)`,oe=`var(--text-muted)`;return(0,$.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50`,onClick:t,children:(0,$.jsxs)(`div`,{className:`rounded-xl w-full max-w-4xl max-h-[90vh] overflow-hidden shadow-xl`,style:{backgroundColor:re},onClick:e=>e.stopPropagation(),children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 border-b`,style:{borderColor:ie},children:[(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`h2`,{className:`text-lg font-semibold`,style:{color:ae},children:[o,` `,u(`common.history`,`History`)]}),(0,$.jsx)(`p`,{className:`text-sm`,style:{color:V},children:r})]}),(0,$.jsx)(`button`,{onClick:t,className:`p-2 rounded-lg transition-colors`,style:{color:V},children:(0,$.jsx)(Pt,{className:`w-5 h-5`})})]}),(0,$.jsxs)(`div`,{className:`p-6 space-y-6 overflow-y-auto max-h-[calc(90vh-80px)]`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between max-[550px]:flex-col max-[550px]:items-start max-[550px]:gap-3`,children:[(0,$.jsxs)(`div`,{className:`inline-flex gap-1 rounded-lg p-1 max-w-full flex-wrap w-fit`,style:{backgroundColor:B},children:[(0,$.jsxs)(`button`,{onClick:()=>h(`humidity`),className:`flex items-center gap-2 px-3 py-1.5 text-sm rounded-md transition-colors ${m===`humidity`?`bg-blue-600 text-white`:``}`,style:m===`humidity`?void 0:{color:V},children:[(0,$.jsx)(y,{className:`w-4 h-4`}),u(`common.humidity`,`Humidity`)]}),(0,$.jsxs)(`button`,{onClick:()=>h(`temperature`),className:`flex items-center gap-2 px-3 py-1.5 text-sm rounded-md transition-colors ${m===`temperature`?`bg-orange-600 text-white`:``}`,style:m===`temperature`?void 0:{color:V},children:[(0,$.jsx)(Me,{className:`w-4 h-4`}),u(`common.temperature`,`Temperature`)]})]}),(0,$.jsx)(`div`,{className:`inline-flex gap-1 rounded-lg p-1 max-w-full flex-wrap w-fit`,style:{backgroundColor:B},children:ta.map(e=>(0,$.jsx)(`button`,{onClick:()=>f(e.value),className:`px-3 py-1 text-sm rounded-md transition-colors ${d===e.value?`bg-bambu-green text-white`:``}`,style:d===e.value?void 0:{color:V},children:e.label},e.value))})]}),(0,$.jsx)(`div`,{className:`grid grid-cols-4 gap-4 max-[550px]:grid-cols-2`,children:m===`humidity`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`rounded-lg p-4 max-[550px]:order-2`,style:{backgroundColor:B},children:[(0,$.jsx)(`p`,{className:`text-xs`,style:{color:V},children:u(`common.current`,`Current`)}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`p`,{className:`text-2xl font-bold`,style:{color:ne(F)},children:F==null?`—`:`${F}%`}),(0,$.jsx)(te,{trend:R})]})]}),(0,$.jsxs)(`div`,{className:`rounded-lg p-4 max-[550px]:order-4`,style:{backgroundColor:B},children:[(0,$.jsx)(`p`,{className:`text-xs`,style:{color:V},children:u(`common.average`,`Average`)}),(0,$.jsx)(`p`,{className:`text-2xl font-bold`,style:{color:ae},children:x?.avg_humidity==null?`—`:`${x.avg_humidity}%`})]}),(0,$.jsxs)(`div`,{className:`rounded-lg p-4 max-[550px]:order-1`,style:{backgroundColor:B},children:[(0,$.jsx)(`p`,{className:`text-xs`,style:{color:V},children:u(`common.min`,`Min`)}),(0,$.jsx)(`p`,{className:`text-2xl font-bold text-green-500`,children:x?.min_humidity==null?`—`:`${x.min_humidity}%`})]}),(0,$.jsxs)(`div`,{className:`rounded-lg p-4 max-[550px]:order-3`,style:{backgroundColor:B},children:[(0,$.jsx)(`p`,{className:`text-xs`,style:{color:V},children:u(`common.max`,`Max`)}),(0,$.jsx)(`p`,{className:`text-2xl font-bold text-red-500`,children:x?.max_humidity==null?`—`:`${x.max_humidity}%`})]})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`rounded-lg p-4 max-[550px]:order-2`,style:{backgroundColor:B},children:[(0,$.jsx)(`p`,{className:`text-xs`,style:{color:V},children:u(`common.current`,`Current`)}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`p`,{className:`text-2xl font-bold`,style:{color:z(I)},children:I==null?`—`:`${I}°C`}),(0,$.jsx)(te,{trend:ee})]})]}),(0,$.jsxs)(`div`,{className:`rounded-lg p-4 max-[550px]:order-4`,style:{backgroundColor:B},children:[(0,$.jsx)(`p`,{className:`text-xs`,style:{color:V},children:u(`common.average`,`Average`)}),(0,$.jsx)(`p`,{className:`text-2xl font-bold`,style:{color:ae},children:x?.avg_temperature==null?`—`:`${x.avg_temperature}°C`})]}),(0,$.jsxs)(`div`,{className:`rounded-lg p-4 max-[550px]:order-1`,style:{backgroundColor:B},children:[(0,$.jsx)(`p`,{className:`text-xs`,style:{color:V},children:u(`common.min`,`Min`)}),(0,$.jsx)(`p`,{className:`text-2xl font-bold text-blue-500`,children:x?.min_temperature==null?`—`:`${x.min_temperature}°C`})]}),(0,$.jsxs)(`div`,{className:`rounded-lg p-4 max-[550px]:order-3`,style:{backgroundColor:B},children:[(0,$.jsx)(`p`,{className:`text-xs`,style:{color:V},children:u(`common.max`,`Max`)}),(0,$.jsx)(`p`,{className:`text-2xl font-bold text-red-500`,children:x?.max_temperature==null?`—`:`${x.max_temperature}°C`})]})]})}),(0,$.jsx)(`div`,{className:`rounded-lg p-4`,style:{backgroundColor:B},children:S?(0,$.jsx)(`div`,{className:`h-[300px] flex items-center justify-center`,style:{color:V},children:u(`common.loading`,`Loading...`)}):C?(0,$.jsx)(`div`,{className:`h-[300px] flex items-center justify-center text-red-500`,children:u(`common.error`,`Error loading data`)}):D.length===0?(0,$.jsx)(`div`,{className:`h-[300px] flex items-center justify-center`,style:{color:V},children:u(`common.noData`,`No data available for this time range`)}):(0,$.jsx)(Qe,{width:`100%`,height:300,children:(0,$.jsxs)(hi,{data:D,children:[(0,$.jsx)(gt,{strokeDasharray:`3 3`,stroke:ie}),(0,$.jsx)(rt,{dataKey:`time`,type:`number`,domain:[Date.now()-b*60*60*1e3,Date.now()],tickFormatter:e=>{let t=new Date(e);return b>24?t.toLocaleDateString([],{day:`numeric`,month:`short`}):t.toLocaleTimeString([],Gt({hour:`2-digit`,minute:`2-digit`},v))},stroke:oe,tick:{fontSize:12}}),(0,$.jsx)(vt,{stroke:oe,tick:{fontSize:12},domain:m===`humidity`?[0,100]:[`auto`,`auto`],tickFormatter:e=>m===`humidity`?`${e}%`:`${e}°C`}),(0,$.jsx)(Re,{contentStyle:{backgroundColor:re,border:`1px solid ${ie}`,borderRadius:`8px`,color:ae},labelFormatter:e=>new Date(e).toLocaleString(void 0,Gt({year:`numeric`,month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`},v)),formatter:e=>[m===`humidity`?`${e??0}%`:`${e??0}°C`,m===`humidity`?`Humidity`:`Temperature`]}),(0,$.jsx)(O,{}),m===`humidity`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(A,{y:k,stroke:`#22a352`,strokeDasharray:`5 5`,label:{value:`Good`,fill:`#22a352`,fontSize:10}}),(0,$.jsx)(A,{y:j,stroke:`#d4a017`,strokeDasharray:`5 5`,label:{value:`Fair`,fill:`#d4a017`,fontSize:10}})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(A,{y:M,stroke:`#22a352`,strokeDasharray:`5 5`,label:{value:`Good`,fill:`#22a352`,fontSize:10}}),(0,$.jsx)(A,{y:N,stroke:`#d4a017`,strokeDasharray:`5 5`,label:{value:`Fair`,fill:`#d4a017`,fontSize:10}})]}),(0,$.jsx)(pi,{type:`monotone`,dataKey:m,name:m===`humidity`?`Humidity`:`Temperature`,stroke:m===`humidity`?`#3b82f6`:`#f97316`,strokeWidth:2,dot:!1,activeDot:{r:4},connectNulls:!0})]})})}),(0,$.jsx)(`div`,{className:`text-xs text-center`,style:{color:V},children:u(`amsHistory.recordingInfo`,`Data is recorded every 5 minutes while the printer is connected`)})]})]})})}function ra(e,t,n){let r=n===1||e>=128,i=e>=128?e-128:e,a=String.fromCharCode(65+i);return r?`HT·${t+1}`:`${a}·${t+1}`}function ia(e){let t=(e||``).replace(`#`,``).slice(0,6);if(t.length!==6)return`#FFFFFF`;let n=parseInt(t.slice(0,2),16),r=parseInt(t.slice(2,4),16),i=parseInt(t.slice(4,6),16);return[n,r,i].some(Number.isNaN)?`#FFFFFF`:(.2126*n+.7152*r+.0722*i)/255>.55?`#1A1A1A`:`#FFFFFF`}function aa({group:e,trayCountByAms:t,innerBg:n,textPrimary:r,textSecondary:i,showExtruderBadge:a,extruderLabel:o}){let s=Mn(e.trayColor||void 0),c=ia(e.trayColor),l=c===`#FFFFFF`?`rgba(0,0,0,0.45)`:`rgba(255,255,255,0.7)`,u=e.members.length;return(0,$.jsxs)(`div`,{className:`relative flex flex-col items-center`,children:[a&&(0,$.jsx)(`span`,{className:`absolute -top-1 -left-1 z-10 w-6 h-6 rounded-full flex items-center justify-center text-xs font-bold shadow`,style:{backgroundColor:r,color:n},"aria-label":o,title:o,children:o}),(0,$.jsxs)(`svg`,{viewBox:`-100 -100 200 200`,className:`w-44 h-44`,children:[(0,$.jsx)(`circle`,{cx:`0`,cy:`0`,r:`95`,fill:`none`,stroke:i,strokeOpacity:`0.25`,strokeWidth:`1`}),(0,$.jsx)(`circle`,{cx:`0`,cy:`0`,r:`92`,fill:s}),(0,$.jsx)(`circle`,{cx:`0`,cy:`0`,r:`56`,fill:n}),(0,$.jsx)(`circle`,{cx:`0`,cy:`0`,r:`56`,fill:`none`,stroke:i,strokeOpacity:`0.3`,strokeWidth:`1`}),(0,$.jsx)(`text`,{x:`0`,y:`-4`,textAnchor:`middle`,dominantBaseline:`middle`,fontSize:`14`,fontWeight:`700`,fill:r,children:e.displayName||`—`}),(0,$.jsx)(`text`,{x:`0`,y:`16`,textAnchor:`middle`,dominantBaseline:`middle`,fontSize:`11`,fontWeight:`500`,fill:i,children:`${u}× ↻`}),e.members.map((e,n)=>{let r=(n*360/u-90)*Math.PI/180,i=76*Math.cos(r),a=76*Math.sin(r),o=ra(e.amsId,e.slotIdx,t.get(e.amsId)??4),s=Math.max(22,o.length*7+8);return(0,$.jsxs)(`g`,{children:[(0,$.jsx)(`rect`,{x:i-s/2,y:a-9,width:s,height:18,rx:9,ry:9,fill:l}),(0,$.jsx)(`text`,{x:i,y:a,textAnchor:`middle`,dominantBaseline:`middle`,fontSize:`12`,fontWeight:`700`,fill:c,children:o})]},`${e.amsId}-${e.slotIdx}`)})]})]})}function oa({isOpen:e,state:t,amsUnits:n,amsExtruderMap:r,isDualNozzle:i,canToggle:a,pending:o,onToggle:s,onClose:c}){let{t:u}=l();if((0,X.useEffect)(()=>{if(!e)return;let t=e=>{e.key===`Escape`&&(e.stopPropagation(),c())};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e,c]),!e)return null;let d=`var(--bg-secondary)`,f=`var(--border-color)`,p=`var(--text-primary)`,m=`var(--text-secondary)`,h=(()=>{if(!i||!r)return!1;let e=new Set;for(let t of n||[]){let n=r[String(t.id)];if(n!==void 0&&(e.add(Number(n)),e.size>1))return!0}return!1})(),g=wn(n,r,h),_=new Map((n||[]).map(e=>[e.id,e.tray.length])),v=g.filter(e=>e.members.length>=2),y=t===!0,b=t===null;return(0,$.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,onClick:c,"data-testid":`ams-backup-modal`,children:(0,$.jsxs)(`div`,{className:`rounded-xl w-full max-w-2xl max-h-[90vh] overflow-hidden shadow-xl flex flex-col`,style:{backgroundColor:d},onClick:e=>e.stopPropagation(),role:`dialog`,"aria-modal":`true`,"aria-labelledby":`ams-backup-modal-title`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between px-5 py-3 border-b`,style:{borderColor:f},children:[(0,$.jsx)(`h2`,{id:`ams-backup-modal-title`,className:`text-base font-semibold`,style:{color:p},children:u(`printers.amsBackup.modalTitle`)}),(0,$.jsx)(`button`,{type:`button`,onClick:c,className:`p-1 rounded-md transition-colors hover:bg-black/10`,style:{color:m},"aria-label":u(`common.close`),children:(0,$.jsx)(Pt,{className:`w-5 h-5`})})]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between px-5 py-3 border-b`,style:{borderColor:f,backgroundColor:`var(--bg-primary)`},children:[(0,$.jsxs)(`div`,{className:`min-w-0 mr-3`,children:[(0,$.jsx)(`div`,{className:`text-sm font-medium`,style:{color:p},children:u(b?`printers.amsBackup.stateUnknown`:y?`printers.amsBackup.stateOn`:`printers.amsBackup.stateOff`)}),(0,$.jsx)(`p`,{className:`text-xs mt-0.5`,style:{color:m},children:u(`printers.amsBackup.modalHelp`)})]}),(0,$.jsx)(hr,{checked:y,onChange:s,disabled:!a||b||o})]}),(0,$.jsx)(`div`,{className:`flex-1 overflow-y-auto px-5 py-6`,children:v.length===0?(0,$.jsx)(`p`,{className:`text-sm text-center py-8`,style:{color:m},children:u(`printers.amsBackup.modalNoPairs`)}):(0,$.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-6 justify-items-center`,children:v.map(e=>(0,$.jsx)(aa,{group:e,trayCountByAms:_,innerBg:d,textPrimary:p,textSecondary:m,showExtruderBadge:h,extruderLabel:e.extruder===0?u(`printers.amsBackup.extruderRightShort`):u(`printers.amsBackup.extruderLeftShort`)},e.key))})})]})})}var sa=[{value:`6h`,label:`6h`,hours:6},{value:`24h`,label:`24h`,hours:24},{value:`48h`,label:`48h`,hours:48},{value:`7d`,label:`7d`,hours:168}],ca={nozzle:`#fb923c`,nozzle_2:`#f97316`,bed:`#60a5fa`,chamber:`#34d399`},la={nozzle:`#fed7aa`,nozzle_2:`#fdba74`,bed:`#bfdbfe`,chamber:`#a7f3d0`};function ua({isOpen:e,onClose:t,printerId:n,printerName:r,initialKind:a=`nozzle`,availableKinds:o=[`nozzle`,`bed`,`chamber`]}){let{t:s}=l(),[c,u]=(0,X.useState)(`24h`),[d,f]=(0,X.useState)(a);(0,X.useEffect)(()=>{f(a)},[a]);let{data:m}=p({queryKey:[`settings`],queryFn:i.getSettings}),h=m?.time_format||`system`;(0,X.useEffect)(()=>{if(!e)return;let n=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,n),()=>window.removeEventListener(`keydown`,n)},[e,t]);let g=sa.find(e=>e.value===c)?.hours||24,{data:v,isLoading:y,error:b}=p({queryKey:[`printer-sensor-history`,n,g,o.join(`,`)],queryFn:()=>i.getPrinterSensorHistory(n,g,o),enabled:e,refetchInterval:6e4});if(!e)return null;let x=v?.series.find(e=>e.sensor_kind===d),S=(x?.data||[]).map(e=>({time:(qt(e.recorded_at)||new Date).getTime(),value:e.value,target:e.target})),C=Date.now()-g*60*60*1e3,w=Date.now(),T=[...S];if(T.length>0){let e=T[0];e.time>C&&T.unshift({...e,time:C});let t=T[T.length-1];t.time{let t=e.filter(e=>e!=null);if(t.length<4)return`stable`;let n=t.slice(0,Math.floor(t.length/4)),r=t.slice(-Math.floor(t.length/4)),i=n.reduce((e,t)=>e+t,0)/n.length,a=r.reduce((e,t)=>e+t,0)/r.length-i;return Math.abs(a)<2?`stable`:a>0?`up`:`down`})(T.map(e=>e.value)),M=({trend:e})=>e===`up`?(0,$.jsx)(_,{className:`w-4 h-4 text-red-600 dark:text-red-400`}):e===`down`?(0,$.jsx)(Ke,{className:`w-4 h-4 text-green-600 dark:text-green-400`}):(0,$.jsx)(G,{className:`w-4 h-4 text-gray-400 dark:text-bambu-gray`}),N=`var(--bg-secondary)`,P=`var(--bg-primary)`,F=`var(--border-color)`,I=`var(--text-primary)`,L=`var(--text-secondary)`,R=`var(--text-muted)`,ee=e=>{switch(e){case`nozzle`:return s(`printers.heaterHistory.nozzle`,`Nozzle`);case`nozzle_2`:return s(`printers.heaterHistory.nozzle2`,`Nozzle 2`);case`bed`:return s(`printers.heaterHistory.bed`,`Bed`);case`chamber`:return s(`printers.heaterHistory.chamber`,`Chamber`)}},te=({k:e})=>e===`nozzle`||e===`nozzle_2`?(0,$.jsx)(Bn,{className:`w-4 h-4`}):e===`bed`?(0,$.jsx)(fn,{className:`w-4 h-4`}):(0,$.jsx)(j,{className:`w-4 h-4`});return(0,$.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50`,onClick:t,children:(0,$.jsxs)(`div`,{className:`rounded-xl w-full max-w-4xl max-h-[90vh] overflow-hidden shadow-xl`,style:{backgroundColor:N},onClick:e=>e.stopPropagation(),children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 border-b`,style:{borderColor:F},children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h2`,{className:`text-lg font-semibold`,style:{color:I},children:s(`printers.heaterHistory.title`,`Heater History`)}),(0,$.jsx)(`p`,{className:`text-sm`,style:{color:L},children:r})]}),(0,$.jsx)(`button`,{onClick:t,className:`p-2 rounded-lg transition-colors`,style:{color:L},"aria-label":s(`common.close`,`Close`),children:(0,$.jsx)(Pt,{className:`w-5 h-5`})})]}),(0,$.jsxs)(`div`,{className:`p-6 space-y-6 overflow-y-auto max-h-[calc(90vh-80px)]`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between max-[550px]:flex-col max-[550px]:items-start max-[550px]:gap-3`,children:[(0,$.jsx)(`div`,{className:`inline-flex gap-1 rounded-lg p-1 max-w-full flex-wrap w-fit`,style:{backgroundColor:P},children:o.map(e=>(0,$.jsxs)(`button`,{onClick:()=>f(e),className:`flex items-center gap-2 px-3 py-1.5 text-sm rounded-md transition-colors ${d===e?`text-white`:``}`,style:d===e?{backgroundColor:ca[e]}:{color:L},children:[(0,$.jsx)(te,{k:e}),ee(e)]},e))}),(0,$.jsx)(`div`,{className:`inline-flex gap-1 rounded-lg p-1 max-w-full flex-wrap w-fit`,style:{backgroundColor:P},children:sa.map(e=>(0,$.jsx)(`button`,{onClick:()=>u(e.value),className:`px-3 py-1 text-sm rounded-md transition-colors ${c===e.value?`bg-bambu-green text-white`:``}`,style:c===e.value?void 0:{color:L},children:e.label},e.value))})]}),(0,$.jsxs)(`div`,{className:`grid grid-cols-4 gap-4 max-[550px]:grid-cols-2`,children:[(0,$.jsxs)(`div`,{className:`rounded-lg p-4`,style:{backgroundColor:P},children:[(0,$.jsx)(`p`,{className:`text-xs`,style:{color:L},children:s(`common.current`,`Current`)}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`p`,{className:`text-2xl font-bold`,style:{color:ca[d]},children:D==null?`—`:`${Math.round(D)}°C`}),(0,$.jsx)(M,{trend:A})]}),k!=null&&k>0&&(0,$.jsxs)(`p`,{className:`text-xs mt-1`,style:{color:L},children:[s(`common.target`,`Target`),`: `,Math.round(k),`°C`]})]}),(0,$.jsxs)(`div`,{className:`rounded-lg p-4`,style:{backgroundColor:P},children:[(0,$.jsx)(`p`,{className:`text-xs`,style:{color:L},children:s(`common.average`,`Average`)}),(0,$.jsx)(`p`,{className:`text-2xl font-bold`,style:{color:I},children:x?.avg_value==null?`—`:`${x.avg_value}°C`})]}),(0,$.jsxs)(`div`,{className:`rounded-lg p-4`,style:{backgroundColor:P},children:[(0,$.jsx)(`p`,{className:`text-xs`,style:{color:L},children:s(`common.min`,`Min`)}),(0,$.jsx)(`p`,{className:`text-2xl font-bold`,style:{color:I},children:x?.min_value==null?`—`:`${Math.round(x.min_value)}°C`})]}),(0,$.jsxs)(`div`,{className:`rounded-lg p-4`,style:{backgroundColor:P},children:[(0,$.jsx)(`p`,{className:`text-xs`,style:{color:L},children:s(`common.max`,`Max`)}),(0,$.jsx)(`p`,{className:`text-2xl font-bold`,style:{color:I},children:x?.max_value==null?`—`:`${Math.round(x.max_value)}°C`})]})]}),(0,$.jsx)(`div`,{className:`rounded-lg p-4`,style:{backgroundColor:P},children:y?(0,$.jsx)(`div`,{className:`h-64 flex items-center justify-center`,style:{color:L},children:s(`common.loading`,`Loading...`)}):b?(0,$.jsx)(`div`,{className:`h-64 flex items-center justify-center text-red-700 dark:text-red-400`,children:s(`printers.heaterHistory.error`,`Failed to load history`)}):T.length===0?(0,$.jsx)(`div`,{className:`h-64 flex items-center justify-center`,style:{color:L},children:s(`printers.heaterHistory.empty`,`No data recorded yet`)}):(0,$.jsx)(Qe,{width:`100%`,height:300,children:(0,$.jsxs)(hi,{data:T,margin:{top:5,right:10,left:0,bottom:5},children:[(0,$.jsx)(gt,{strokeDasharray:`3 3`,stroke:F}),(0,$.jsx)(rt,{dataKey:`time`,type:`number`,domain:[C,w],tickFormatter:e=>new Date(e).toLocaleTimeString([],Gt({hour:`2-digit`,minute:`2-digit`},h)),stroke:R,fontSize:11}),(0,$.jsx)(vt,{stroke:R,fontSize:11,domain:[0,`auto`],tickFormatter:e=>`${Math.round(e)}°`}),(0,$.jsx)(Re,{contentStyle:{backgroundColor:N,border:`1px solid ${F}`,borderRadius:6,color:I},labelFormatter:e=>new Date(e).toLocaleString(void 0,Gt({month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`},h)),formatter:e=>e==null?`—`:`${Math.round(Number(e))}°C`}),(0,$.jsx)(O,{}),(0,$.jsx)(pi,{type:`monotone`,dataKey:`value`,name:s(`common.current`,`Current`),stroke:ca[d],strokeWidth:2,dot:!1,isAnimationActive:!1}),(0,$.jsx)(pi,{type:`stepAfter`,dataKey:`target`,name:s(`common.target`,`Target`),stroke:la[d],strokeDasharray:`4 4`,strokeWidth:1.5,dot:!1,isAnimationActive:!1})]})})})]})]})})}function da({data:e,children:t,disabled:n,className:r=``,spoolman:i,inventory:a,configureSlot:o,actions:s}){let{t:c}=l(),u=Tn(),[d,f]=(0,X.useState)(!1),[p,m]=(0,X.useState)(`top`),[h,g]=(0,X.useState)(null),[_,v]=(0,X.useState)(!1),[b,x]=(0,X.useState)(!1),S=(0,X.useRef)(null),C=(0,X.useRef)(null),w=(0,X.useRef)(null),T=()=>{let t=e.trayUuid;t&&(navigator.clipboard&&window.isSecureContext?navigator.clipboard.writeText(t).then(()=>{v(!0),setTimeout(()=>v(!1),2e3)}).catch(()=>{E(t)}):E(t))},E=e=>{let t=document.createElement(`textarea`);t.value=e,t.style.position=`fixed`,t.style.opacity=`0`,document.body.appendChild(t),t.select();try{document.execCommand(`copy`),v(!0),setTimeout(()=>v(!1),2e3)}catch{console.error(`Failed to copy to clipboard`)}document.body.removeChild(t)};(0,X.useLayoutEffect)(()=>{if(!d){g(null);return}let e=()=>{if(!S.current||!C.current)return;let e=S.current.getBoundingClientRect(),t=C.current.offsetHeight,n=C.current.offsetWidth,r=e.top-56,i=window.innerHeight-e.bottom,a=rr?`bottom`:`top`,o=e.left+e.width/2,s=Math.max(8,Math.min(o-n/2,window.innerWidth-n-8)),c=a===`top`?e.top-t-8:e.bottom+8;m(a),g({top:c,left:s})};e();let t=requestAnimationFrame(e);return window.addEventListener(`scroll`,e,!0),window.addEventListener(`resize`,e),()=>{cancelAnimationFrame(t),window.removeEventListener(`scroll`,e,!0),window.removeEventListener(`resize`,e)}},[d]);let D=()=>{n||(w.current&&clearTimeout(w.current),w.current=setTimeout(()=>f(!0),80))},O=()=>{w.current&&clearTimeout(w.current),w.current=setTimeout(()=>f(!1),100)},k=()=>{w.current&&clearTimeout(w.current),f(!1)};(0,X.useEffect)(()=>()=>{w.current&&clearTimeout(w.current)},[]);let A=e=>e<=15?`#ef4444`:e<=30?`#f97316`:e<=50?`#eab308`:`#22c55e`,j=e.colorHex?`#${e.colorHex.replace(`#`,``)}`:null,M=(a?.assignedSpool?.color_name_is_synthesized?void 0:qn(a?.assignedSpool?.color_name??null,null)?.trim())||e.colorName,N=a?.assignedSpool?qn(a.assignedSpool.color_name,a.assignedSpool.rgba??null,a.assignedSpool.color_name_is_synthesized):null,P=a?.assignedSpool?.remainingWeightGrams??null,I=a?.assignedSpool??null,L=Yt(I?.extra_colors),R=!!I?.effect_type,ee=!!I&&(L.length>0||R),te=ee?Jt({effectSize:`card`,rgba:I?.rgba??j,extraColors:I?.extra_colors,effectType:I?.effect_type,subtype:I?.subtype}):null,ne=L.length>1,re=ee?L.length===1?L[0]:I?.rgba??j:j;return(0,$.jsxs)(`div`,{ref:S,"data-testid":`filament-slot`,className:`relative ${r}`,onMouseEnter:D,onMouseLeave:O,children:[t,d&&(0,gi.createPortal)((0,$.jsxs)(`div`,{ref:C,className:`fixed z-[60]`,style:{top:h?.top??-9999,left:h?.left??-9999,maxWidth:`calc(100vw - 24px)`,visibility:h?`visible`:`hidden`},onMouseEnter:D,onMouseLeave:O,children:[(0,$.jsxs)(`div`,{className:` w-52 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl overflow-hidden backdrop-blur-sm diff --git a/static/assets/ProfilesPage-CqnWMUyc.js b/static/assets/ProfilesPage-FzXKlAbc.js similarity index 99% rename from static/assets/ProfilesPage-CqnWMUyc.js rename to static/assets/ProfilesPage-FzXKlAbc.js index 66619ce7f..29c64cd1d 100644 --- a/static/assets/ProfilesPage-CqnWMUyc.js +++ b/static/assets/ProfilesPage-FzXKlAbc.js @@ -1,4 +1,4 @@ -import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,w as i}from"./client-DnySrlFv.js";import{n as a}from"./QueryClientProvider-Ce8_sN3w.js";import{t as o}from"./useQuery-BBCjCezC.js";import{t as s}from"./useMutation-B-Tr2hIP.js";import{t as c}from"./createLucideIcon-DvBYJlWL.js";import{t as l}from"./arrow-right-DedpIMhP.js";import{t as u}from"./arrow-up-D-pfJ3WZ.js";import{t as d}from"./check-Ck0cMLU4.js";import{a as f,i as p,r as m}from"./info-ROUoQhJR.js";import{n as h}from"./ToastContext-BRX0SW3C.js";import{t as g}from"./copy-Cu_0GKCU.js";import{t as _}from"./droplet-CqYXMF2u.js";import{t as v}from"./eye-off-6CkaxYwP.js";import{t as y}from"./funnel-C3dyAMK9.js";import{t as b}from"./gauge-D21zgWMb.js";import{t as x}from"./git-compare-J4KX0xAJ.js";import{t as S}from"./hard-drive-CgXAHN37.js";import{t as C}from"./list-CLcpeoSz.js";import{t as w}from"./loader-circle-BEmFtawu.js";import{t as T}from"./log-in-n0ckHxnD.js";import{t as E}from"./minus-DypeGjGR.js";import{t as ee}from"./search-0n0CBc74.js";import{t as te}from"./settings-2-Cvn837lh.js";import{t as D}from"./sparkles-DRqKNlhr.js";import{t as O}from"./sticky-note-BH0LPqRx.js";import{t as k}from"./triangle-alert-Dt_1FcBy.js";import{t as A}from"./x-DR-Trv6U.js";import{n as j,t as M}from"./Card-Bzc64K35.js";import{t as N}from"./Button-DDr6eAFy.js";import{u as P}from"./date-G9KUauqz.js";import{$t as F,At as I,Bt as L,Cn as R,Ct as ne,Dn as z,En as B,Jt as re,Kt as ie,Lt as V,On as ae,Rt as oe,Sn as H,Ut as U,Zt as se,an as W,cn as ce,kt as le,ln as G,wn as ue,yt as de}from"./index-0t--Yqoi.js";import{p as K,u as q}from"./utils-DVekehs6.js";import{t as fe}from"./useCancellableTimeout-3XQzNJkJ.js";var J=c(`equal`,[[`line`,{x1:`5`,x2:`19`,y1:`9`,y2:`9`,key:`1nwqeh`}],[`line`,{x1:`5`,x2:`19`,y1:`15`,y2:`15`,key:`g8yjpy`}]]),pe=c(`sliders-vertical`,[[`path`,{d:`M10 8h4`,key:`1sr2af`}],[`path`,{d:`M12 21v-9`,key:`17s77i`}],[`path`,{d:`M12 8V3`,key:`13r4qs`}],[`path`,{d:`M17 16h4`,key:`h1uq16`}],[`path`,{d:`M19 12V3`,key:`o1uvq1`}],[`path`,{d:`M19 21v-5`,key:`qua636`}],[`path`,{d:`M3 14h4`,key:`bcjad9`}],[`path`,{d:`M5 10V3`,key:`cb8scm`}],[`path`,{d:`M5 21v-7`,key:`1w1uti`}]]),Y=e(n(),1),X={PLA:`GFL99`,"PLA-CF":`GFL98`,"PLA SILK":`GFL96`,"PLA HIGH SPEED":`GFL95`,PETG:`GFG99`,"PETG HF":`GFG96`,"PETG-CF":`GFG98`,PCTG:`GFG97`,ABS:`GFB99`,ASA:`GFB98`,PC:`GFC99`,PA:`GFN99`,"PA-CF":`GFN98`,NYLON:`GFN99`,TPU:`GFU99`,PVA:`GFS99`,HIPS:`GFS98`,PE:`GFP99`,PP:`GFP97`};function me(e){let t=(e||``).toUpperCase().trim();return t&&(X[t]||X[t.replace(/[-\s]?CF$/,``)]||X[t.replace(/\+$/,``)]||X[t.split(/[-\s]/)[0]])||``}function he(e){let t=e.replace(/@.+$/,``).trim();return t.startsWith(`# `)?t.slice(2).trim():t}var ge={local:0,orca_cloud:1,cloud:2,builtin:3};function _e(e){let{localPresets:t,orcaProfiles:n,cloudSettings:r,builtinFilaments:i}=e,a=[],o=e=>e.trim().toLowerCase(),s=new Set,c=new Set,l=new Set,u=(e,t,...n)=>{let r=n.filter(e=>!!e);if(r.some(e=>s.has(e)))return!1;let i=`${e}|${o(t)}`;return c.has(i)?!1:(r.forEach(e=>s.add(e)),c.add(i),l.add(o(t)),!0)};for(let e of t??[]){let t=he(e.name),n=e.filament_type||q(t).material;u(`local`,t)&&a.push({id:`local_${e.id}`,name:t,source:`local`,filamentId:me(n),filamentType:n||``})}for(let e of n??[]){let t=he(e.name),n=q(t).material;u(`orca_cloud`,t,e.setting_id)&&a.push({id:`orca_${e.setting_id}`,name:t,source:`orca_cloud`,filamentId:me(n),filamentType:n})}for(let e of r??[]){let t=he(e.name),n=e.setting_id.startsWith(`GFS`)?K(e.setting_id):``;u(`cloud`,t,e.setting_id,n||void 0)&&a.push({id:e.setting_id,name:t,source:`cloud`,filamentId:n,filamentType:q(t).material})}for(let e of i??[]){let t=e.filament_id.startsWith(`GF`)?`GFS${e.filament_id.slice(2)}`:e.filament_id;l.has(o(e.name))||u(`builtin`,e.name,e.filament_id,t)&&a.push({id:`builtin_${e.filament_id}`,name:e.name,source:`builtin`,filamentId:e.filament_id,filamentType:q(e.name).material})}return a.sort((e,t)=>e.source===t.source?e.name.localeCompare(t.name):ge[e.source]-ge[t.source])}async function ve(e,t){if(e.filamentId)return e.filamentId;if(e.source!==`cloud`||!t)return``;try{return(await t(e.id)).filament_id||``}catch{return``}}var Z=t(),ye=e=>(Math.trunc(parseFloat(e)*1e3)/1e3).toFixed(3),be=`HS00`,xe=`HH00`,Se=e=>{let t=e.match(/^([A-Z]{2}\d{2})/);return t?t[1]:be},Q=e=>Se(e)===xe?`HF`:`S`,Ce=e=>{for(let t of[`High Flow_`,`High Flow `,`Standard_`,`Standard `,`HF_`,`HF `,`S_`,`S `])if(e.startsWith(t))return e.slice(t.length);let t=e.indexOf(`_`);return t>0?e.slice(t+1):e};function we({profile:e,onEdit:t,onCopy:n,selectionMode:r,isSelected:i,onToggleSelect:a,note:o}){let s=Q(e.nozzle_id),c=e.nozzle_diameter;return(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[r&&(0,Z.jsx)(`button`,{onClick:a,className:`text-bambu-gray hover:text-white transition-colors p-1`,children:i?(0,Z.jsx)(oe,{className:`w-4 h-4 text-bambu-green`}):(0,Z.jsx)(V,{className:`w-4 h-4`})}),(0,Z.jsxs)(`button`,{onClick:()=>{r&&a?a():t()},className:`flex-1 text-left px-3 py-2 bg-bambu-dark rounded hover:bg-bambu-dark-tertiary transition-colors ${i?`ring-1 ring-bambu-green`:``}`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`span`,{className:`text-bambu-green font-mono text-sm font-bold whitespace-nowrap`,children:ye(e.k_value)}),(0,Z.jsx)(`span`,{className:`text-white text-sm truncate flex-1`,title:e.name,children:e.name||`Unnamed`}),o&&(0,Z.jsx)(`span`,{title:`Has note`,children:(0,Z.jsx)(O,{className:`w-3 h-3 text-yellow-500`})}),(0,Z.jsxs)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:[s,` `,c]})]}),o&&(0,Z.jsxs)(`div`,{className:`text-xs mt-0.5 truncate text-yellow-500/70`,title:o,children:[`Note: `,o.length>50?o.substring(0,50)+`...`:o]})]}),!r&&n&&(0,Z.jsx)(`button`,{onClick:e=>{e.stopPropagation(),n()},className:`text-bambu-gray hover:text-white transition-colors p-1`,title:`Copy profile`,children:(0,Z.jsx)(g,{className:`w-4 h-4`})})]})}function Te({profile:e,printerId:t,nozzleDiameter:n,existingProfiles:a=[],builtinFilaments:o=[],filamentPresets:c=[],isDualNozzle:l=!1,supportsFlowType:u=!0,initialNote:d=``,initialNoteKey:f=null,onClose:p,onSave:m,onSaveNote:g,hasPermission:_}){let{t:v}=i(),{showToast:y}=h(),[x,S]=(0,Y.useState)(e?.name||``),[C,T]=(0,Y.useState)(e?.k_value?ye(e.k_value):`0.020`),[E,te]=(0,Y.useState)(e?.filament_id||``),[D,O]=(0,Y.useState)(e?Se(e.nozzle_id):be),[k,P]=(0,Y.useState)(e?.nozzle_diameter||n),[F,L]=(0,Y.useState)(e?[e.extruder_id]:l?[0,1]:[0]),[R,ne]=(0,Y.useState)(!1),[z,B]=(0,Y.useState)({current:0,total:0}),[re,ie]=(0,Y.useState)(d),[V,ae]=(0,Y.useState)(``),{schedule:oe}=fe(),H=Y.useMemo(()=>e?.filament_id?o.find(t=>t.filament_id===e.filament_id)?.name||Ce(a.find(t=>t.filament_id===e.filament_id)?.name||e.name||``)||e.filament_id:``,[e,a,o]),U=Y.useMemo(()=>{let e=[[`local`,v(`kProfiles.modal.source.local`)],[`orca_cloud`,v(`kProfiles.modal.source.orcaCloud`)],[`cloud`,v(`kProfiles.modal.source.bambuCloud`)],[`builtin`,v(`kProfiles.modal.source.builtin`)]],t=V.trim().toLowerCase(),n=t?c.filter(e=>e.name.toLowerCase().includes(t)):c;return e.map(([e,t])=>({source:e,label:t,items:n.filter(t=>t.source===e)})).filter(e=>e.items.length>0)},[c,V,v]),se=s({mutationFn:e=>(console.log(`[KProfile] Calling API...`),r.setKProfile(t,e)),onSuccess:(t,n)=>{if(console.log(`[KProfile] Save success:`,t),y(v(`kProfiles.toast.profileSaved`)),g&&re!==d){let t;t=re===``&&f?f:e&&e.slot_id>0?e.setting_id||`slot_${e.slot_id}_${e.filament_id}_${e.extruder_id}`:`name_${x}_${n.filament_id}`,g(t,re)}ne(!0),oe(()=>{ne(!1),m()},2500)},onError:e=>{console.error(`[KProfile] Save error:`,e),y(e.message,`error`),ne(!1)}}),W=s({mutationFn:e=>(console.log(`[KProfile] Deleting profile...`),r.deleteKProfile(t,e)),onSuccess:e=>{console.log(`[KProfile] Delete success:`,e),y(v(`kProfiles.toast.profileDeleted`)),ne(!0),oe(()=>{ne(!1),p()},4e3)},onError:e=>{console.error(`[KProfile] Delete error:`,e),y(e.message,`error`),ne(!1)}}),[ce,le]=(0,Y.useState)(!1),G=()=>{e&&W.mutate({slot_id:e.slot_id,extruder_id:e.extruder_id,nozzle_id:e.nozzle_id,nozzle_diameter:e.nozzle_diameter,filament_id:e.filament_id,setting_id:e.setting_id})};return(0,Z.jsxs)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,children:[(0,Z.jsxs)(M,{className:`w-full max-w-md relative`,children:[R&&(0,Z.jsxs)(`div`,{className:`absolute inset-0 bg-bambu-dark-secondary/90 flex flex-col items-center justify-center z-10 rounded-lg`,children:[(0,Z.jsx)(w,{className:`w-8 h-8 text-bambu-green animate-spin mb-3`}),(0,Z.jsx)(`p`,{className:`text-white font-medium`,children:z.total>1?v(`kProfiles.modal.savingExtruder`,{current:z.current,total:z.total}):v(`kProfiles.modal.syncing`)}),(0,Z.jsx)(`p`,{className:`text-bambu-gray text-sm mt-1`,children:v(`kProfiles.modal.pleaseWait`)})]}),(0,Z.jsxs)(j,{className:`p-0`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,Z.jsx)(`h2`,{className:`text-xl font-semibold text-white`,children:v(e?`kProfiles.modal.editTitle`:`kProfiles.modal.addTitle`)}),(0,Z.jsx)(`button`,{onClick:p,className:`text-bambu-gray hover:text-white transition-colors`,disabled:R,children:(0,Z.jsx)(A,{className:`w-5 h-5`})})]}),(0,Z.jsxs)(`form`,{onSubmit:async n=>{if(n.preventDefault(),l&&!e&&F.length===0){y(v(`kProfiles.toast.selectAtLeastOneExtruder`),`error`);return}let i=parseFloat(C).toFixed(6),a=`${D}-${k}`,o=e&&e.nozzle_id||a,s=e?e.nozzle_diameter:k,u=e?.filament_id||``;if(!e){let e=c.find(e=>e.id===E);if(!e){y(v(`kProfiles.toast.selectFilament`),`error`);return}if(u=await ve(e,r.getCloudSettingDetail),!u){y(v(`kProfiles.toast.filamentNotResolvable`,{name:e.name}),`error`);return}}if(e||F.length===1){let t={name:x,k_value:i,filament_id:u,nozzle_id:o,nozzle_diameter:s,extruder_id:e?e.extruder_id:F[0],setting_id:e?.setting_id,slot_id:e?.slot_id??0};console.log(`[KProfile] Saving profile:`,t),se.mutate(t);return}ne(!0),B({current:1,total:F.length});let d=F.map(e=>({name:x,k_value:i,filament_id:u,nozzle_id:a,nozzle_diameter:k,extruder_id:e,setting_id:void 0,slot_id:0}));console.log(`[KProfile] Saving ${d.length} profiles in batch:`,d);try{await r.setKProfilesBatch(t,d),y(v(`kProfiles.toast.profilesSaved`,{count:F.length})),g&&re&&g(`name_${x}_${u}`,re)}catch(e){console.error(`[KProfile] Failed to save batch:`,e),y(v(`kProfiles.toast.failedToSaveBatch`),`error`),ne(!1),B({current:0,total:0});return}B({current:F.length,total:F.length}),oe(()=>{ne(!1),B({current:0,total:0}),m()},3e3)},className:`p-4 space-y-4`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:v(`kProfiles.modal.profileName`)}),(0,Z.jsx)(`input`,{type:`text`,value:x,onChange:e=>S(e.target.value),disabled:!!e,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none ${e?`opacity-60 cursor-not-allowed`:``}`,placeholder:v(`kProfiles.modal.profileNamePlaceholder`),required:!e})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:v(`kProfiles.modal.kValue`)}),(0,Z.jsx)(`input`,{type:`text`,inputMode:`decimal`,value:C,onChange:e=>{let t=e.target.value;(t===``||/^\d*\.?\d*$/.test(t))&&T(t)},onBlur:e=>{let t=parseFloat(e.target.value);isNaN(t)||T((Math.trunc(t*1e3)/1e3).toFixed(3))},className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none font-mono`,placeholder:v(`kProfiles.modal.kValuePlaceholder`),required:!0}),(0,Z.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:v(`kProfiles.modal.kValueHelp`)})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:v(`kProfiles.modal.filament`)}),e?(0,Z.jsx)(`div`,{className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white opacity-60`,children:H||e.filament_id}):(0,Z.jsxs)(`div`,{className:`border border-bambu-dark-tertiary rounded-lg overflow-hidden`,children:[(0,Z.jsxs)(`div`,{className:`relative border-b border-bambu-dark-tertiary`,children:[(0,Z.jsx)(ee,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,Z.jsx)(`input`,{type:`text`,value:V,onChange:e=>ae(e.target.value),placeholder:v(`kProfiles.modal.searchFilaments`),className:`w-full pl-10 pr-3 py-2 bg-bambu-dark text-white placeholder-bambu-gray focus:outline-none`})]}),(0,Z.jsx)(`div`,{className:`max-h-56 overflow-y-auto bg-bambu-dark`,children:U.length===0?(0,Z.jsx)(`p`,{className:`px-3 py-3 text-xs text-bambu-gray`,children:c.length===0?v(`kProfiles.modal.noFilamentsHelp`):v(`kProfiles.modal.noFilamentMatches`)}):U.map(e=>(0,Z.jsxs)(`div`,{children:[(0,Z.jsxs)(`div`,{className:`sticky top-0 z-10 flex items-center gap-2 px-3 py-1.5 bg-bambu-dark-secondary border-y border-bambu-dark-tertiary`,children:[(0,Z.jsx)(`span`,{className:`text-xs font-bold uppercase tracking-wider text-bambu-green`,children:e.label}),(0,Z.jsx)(`span`,{className:`text-[10px] text-bambu-gray`,children:e.items.length})]}),e.items.map(e=>(0,Z.jsx)(`button`,{type:`button`,onClick:()=>{te(e.id),x||S(`${D===xe?`HF`:`S`} ${e.name}`)},className:`w-full text-left px-3 py-1.5 text-sm transition-colors ${E===e.id?`bg-bambu-green/20 text-white`:`text-white hover:bg-bambu-dark-tertiary`}`,children:e.name},e.id))]},e.source))})]})]}),(0,Z.jsxs)(`div`,{className:u?`grid grid-cols-2 gap-4`:``,children:[(0,Z.jsxs)(`div`,{className:u?``:`hidden`,children:[(0,Z.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:v(`kProfiles.modal.flowType`)}),(0,Z.jsxs)(`select`,{value:D,onChange:t=>{let n=t.target.value;if(O(n),!e&&E&&!x){let e=c.find(e=>e.id===E);e&&S(`${n===xe?`HF`:`S`} ${e.name}`)}},disabled:!!e,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none ${e?`opacity-60 cursor-not-allowed`:``}`,children:[(0,Z.jsx)(`option`,{value:xe,children:v(`kProfiles.modal.highFlow`)}),(0,Z.jsx)(`option`,{value:be,children:v(`kProfiles.modal.standard`)})]})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:v(`kProfiles.modal.nozzleSize`)}),(0,Z.jsxs)(`select`,{value:k,onChange:e=>P(e.target.value),disabled:!!e,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none ${e?`opacity-60 cursor-not-allowed`:``}`,children:[(0,Z.jsx)(`option`,{value:`0.2`,children:`0.2mm`}),(0,Z.jsx)(`option`,{value:`0.4`,children:`0.4mm`}),(0,Z.jsx)(`option`,{value:`0.6`,children:`0.6mm`}),(0,Z.jsx)(`option`,{value:`0.8`,children:`0.8mm`})]})]})]}),l&&(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:v(e?`kProfiles.modal.extruder`:`kProfiles.modal.extruders`)}),e?(0,Z.jsx)(`div`,{className:`px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white opacity-60`,children:e.extruder_id===1?v(`kProfiles.modal.left`):v(`kProfiles.modal.right`)}):(0,Z.jsxs)(`div`,{className:`flex gap-4`,children:[(0,Z.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,checked:F.includes(1),onChange:e=>{e.target.checked?L([...F,1]):L(F.filter(e=>e!==1))},className:`w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green focus:ring-offset-0 accent-bambu-green`}),(0,Z.jsx)(`span`,{className:`text-white`,children:v(`kProfiles.modal.left`)})]}),(0,Z.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,checked:F.includes(0),onChange:e=>{e.target.checked?L([...F,0]):L(F.filter(e=>e!==0))},className:`w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green focus:ring-offset-0 accent-bambu-green`}),(0,Z.jsx)(`span`,{className:`text-white`,children:v(`kProfiles.modal.right`)})]})]})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:v(`kProfiles.modal.notes`)}),(0,Z.jsx)(`textarea`,{value:re,onChange:e=>ie(e.target.value),placeholder:v(`kProfiles.modal.notesPlaceholder`),rows:2,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none resize-none`}),(0,Z.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:v(`kProfiles.modal.notesHelp`)})]}),(0,Z.jsxs)(`div`,{className:`flex gap-2 pt-4`,children:[e&&(0,Z.jsx)(N,{type:`button`,variant:`secondary`,onClick:()=>le(!0),disabled:W.isPending||R||!_(`kprofiles:delete`),title:_(`kprofiles:delete`)?void 0:v(`kProfiles.permission.noDelete`),className:`text-red-500 hover:bg-red-500/10`,children:W.isPending?(0,Z.jsx)(w,{className:`w-4 h-4 animate-spin`}):(0,Z.jsx)(I,{className:`w-4 h-4`})}),(0,Z.jsx)(N,{type:`button`,variant:`secondary`,onClick:p,disabled:R,className:`flex-1`,children:v(`common.cancel`)}),(0,Z.jsxs)(N,{type:`submit`,disabled:se.isPending||R||!_(e?`kprofiles:update`:`kprofiles:create`),title:_(e?`kprofiles:update`:`kprofiles:create`)?void 0:v(e?`kProfiles.permission.noUpdate`:`kProfiles.permission.noCreate`),className:`flex-1`,children:[se.isPending?(0,Z.jsx)(w,{className:`w-4 h-4 animate-spin`}):(0,Z.jsx)(b,{className:`w-4 h-4`}),v(`common.save`)]})]})]})]})]}),ce&&(0,Z.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-[60]`,children:(0,Z.jsx)(M,{className:`w-full max-w-sm`,children:(0,Z.jsxs)(j,{className:`p-6`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-3 mb-4`,children:[(0,Z.jsx)(`div`,{className:`w-10 h-10 rounded-full bg-red-500/20 flex items-center justify-center`,children:(0,Z.jsx)(I,{className:`w-5 h-5 text-red-500`})}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`h3`,{className:`text-lg font-semibold text-white`,children:v(`kProfiles.deleteConfirm.title`)}),(0,Z.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:v(`kProfiles.deleteConfirm.cannotUndo`)})]})]}),(0,Z.jsx)(`p`,{className:`text-bambu-gray mb-6`,children:v(`kProfiles.deleteConfirm.message`,{name:e?.name})}),(0,Z.jsxs)(`div`,{className:`flex gap-3`,children:[(0,Z.jsx)(N,{variant:`secondary`,onClick:()=>le(!1),className:`flex-1`,children:v(`common.cancel`)}),(0,Z.jsxs)(N,{onClick:()=>{le(!1),G()},disabled:W.isPending,className:`flex-1 bg-red-500 hover:bg-red-600 text-white`,children:[W.isPending?(0,Z.jsx)(w,{className:`w-4 h-4 animate-spin`}):(0,Z.jsx)(I,{className:`w-4 h-4`}),v(`common.delete`)]})]})]})})})]})}var Ee={NOZZLE_DIAMETER:`bambusy_kprofiles_nozzle`,SORT_OPTION:`bambusy_kprofiles_sort`};function De(){let{t:e}=i(),{showToast:t}=h(),{hasPermission:n}=de(),[a,s]=(0,Y.useState)(null),[c,l]=(0,Y.useState)(()=>localStorage.getItem(Ee.NOZZLE_DIAMETER)||`0.4`),[u,d]=(0,Y.useState)(null),[f,p]=(0,Y.useState)(!1),[g,_]=(0,Y.useState)(null),[v,y]=(0,Y.useState)(``),[x,S]=(0,Y.useState)(`all`),[C,T]=(0,Y.useState)(`all`),[E,te]=(0,Y.useState)(()=>localStorage.getItem(Ee.SORT_OPTION)||`name`),[D,O]=(0,Y.useState)(!1),[k,P]=(0,Y.useState)(new Set),[F,L]=(0,Y.useState)(!1),[R,z]=(0,Y.useState)(!1),B=(0,Y.useCallback)(e=>`${e.slot_id}_${e.extruder_id}`,[]);(0,Y.useEffect)(()=>{localStorage.setItem(Ee.NOZZLE_DIAMETER,c)},[c]),(0,Y.useEffect)(()=>{localStorage.setItem(Ee.SORT_OPTION,E)},[E]);let{data:V,isLoading:ae}=o({queryKey:[`printers`],queryFn:r.getPrinters}),{data:H,isLoading:U,isFetching:W,error:ce,refetch:G}=o({queryKey:[`kprofiles`,a,c],queryFn:async()=>{console.log(`[KProfiles] Fetching profiles for printer`,a,`nozzle`,c);let e=await r.getKProfiles(a,c);return console.log(`[KProfiles] Received profiles:`,e?.profiles?.length||0,`profiles`),e},enabled:!!a,retry:!1,staleTime:0,gcTime:0,refetchOnMount:`always`}),{data:K}=o({queryKey:[`builtinFilaments`],queryFn:()=>r.getBuiltinFilaments(),staleTime:3e5}),{data:q}=o({queryKey:[`filamentIdMap`],queryFn:()=>r.getFilamentIdMap(),staleTime:3e5}),{data:fe}=o({queryKey:[`localPresets`],queryFn:()=>r.getLocalPresets(),retry:!1}),{data:J}=o({queryKey:[`orcaCloudProfilesForKProfiles`],queryFn:()=>r.orcaCloudListProfiles(),retry:!1}),{data:pe}=o({queryKey:[`cloudSettings`],queryFn:()=>r.getCloudSettings(),retry:!1}),{data:X,refetch:me}=o({queryKey:[`kprofile-notes`,a],queryFn:()=>r.getKProfileNotes(a),enabled:!!a,staleTime:3e4}),he=ce?.message?.includes(`not connected`);(0,Y.useEffect)(()=>{if(!a&&V&&V.length>0){let e=V.find(e=>e.is_active);e&&s(e.id)}},[a,V]),(0,Y.useEffect)(()=>{if(a){let e=setTimeout(()=>{G()},150);return()=>clearTimeout(e)}},[a,c]);let ge=V?.filter(e=>e.is_active)||[],ve=Y.useMemo(()=>{let e=new Map;if(K)for(let t of K)e.set(t.filament_id,t.name);if(q)for(let[t,n]of Object.entries(q))e.has(t)||e.set(t,n);return e},[K,q]),ye=Y.useMemo(()=>Array.from(ve.entries()).map(([e,t])=>({filament_id:e,name:t})),[ve]),xe=Y.useMemo(()=>_e({localPresets:fe?.filament,orcaProfiles:J?.filament,cloudSettings:pe?.filament,builtinFilaments:K}),[fe?.filament,J?.filament,pe?.filament,K]),Se=Y.useCallback(e=>ve.get(e.filament_id)||Ce(e.name),[ve]),Q=Y.useMemo(()=>H?.profiles?H.profiles.filter(e=>{let t=v.toLowerCase(),n=!t||e.name.toLowerCase().includes(t)||e.filament_id.toLowerCase().includes(t),r=x===`all`||x===`left`&&e.extruder_id===1||x===`right`&&e.extruder_id===0,i=C===`all`||C===`hf`&&e.nozzle_id.startsWith(`HH`)||C===`s`&&e.nozzle_id.startsWith(`HS`);return n&&r&&i}).sort((e,t)=>{switch(E){case`k_value`:return parseFloat(e.k_value)-parseFloat(t.k_value);case`filament`:return Se(e).localeCompare(Se(t));default:return e.name.localeCompare(t.name)}}):[],[H?.profiles,v,x,C,E,Se]),De=V?.find(e=>e.id===a),$=De?.nozzle_count===2,Oe=De?.supports_nozzle_flow_type??!0;(0,Y.useEffect)(()=>{Oe||T(`all`)},[Oe]),(0,Y.useEffect)(()=>{let e=e=>{e.target instanceof HTMLInputElement||e.target instanceof HTMLTextAreaElement||e.target instanceof HTMLSelectElement||u||f||g||(e.key===`r`||e.key===`R`?(e.preventDefault(),G()):e.key===`n`||e.key===`N`?(e.preventDefault(),p(!0)):e.key===`Escape`&&D&&(e.preventDefault(),O(!1),P(new Set)))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[u,f,g,D,G]);let ke=(0,Y.useCallback)(()=>{if(!H?.profiles||H.profiles.length===0){t(e(`kProfiles.toast.noProfilesToExport`),`error`);return}let n={version:1,exported_at:new Date().toISOString(),printer:De?.name||`Unknown`,nozzle_diameter:c,profiles:H.profiles.map(e=>({name:e.name,k_value:e.k_value,filament_id:e.filament_id,nozzle_id:e.nozzle_id,nozzle_diameter:e.nozzle_diameter,extruder_id:e.extruder_id}))},r=new Blob([JSON.stringify(n,null,2)],{type:`application/json`}),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=`kprofiles_${De?.name||`printer`}_${c}mm_${new Date().toISOString().split(`T`)[0]}.json`,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(i),t(e(`kProfiles.toast.exportedProfiles`,{count:H.profiles.length}))},[H?.profiles,De,c,t,e]),Ae=(0,Y.useCallback)(()=>{let n=document.createElement(`input`);n.type=`file`,n.accept=`.json`,n.onchange=async n=>{let i=n.target.files?.[0];if(i)try{let n=await i.text(),o=JSON.parse(n);if(!o.profiles||!Array.isArray(o.profiles)){t(e(`kProfiles.toast.invalidFileFormat`),`error`);return}let s=0;for(let e of o.profiles)if(!(!e.name||!e.k_value||!e.filament_id))try{await r.setKProfile(a,{name:e.name,k_value:parseFloat(e.k_value).toFixed(6),filament_id:e.filament_id,nozzle_id:e.nozzle_id||`${be}-${c}`,nozzle_diameter:e.nozzle_diameter||c,extruder_id:e.extruder_id??0,slot_id:0}),s++,await new Promise(e=>setTimeout(e,500))}catch(t){console.error(`Failed to import profile:`,e.name,t)}t(e(`kProfiles.toast.importedProfiles`,{count:s,total:o.profiles.length})),G()}catch(n){console.error(`Import error:`,n),t(e(`kProfiles.toast.failedToParseImport`),`error`)}},n.click()},[a,c,t,G,e]),je=(0,Y.useCallback)(e=>{P(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),Me=(0,Y.useCallback)(()=>{P(new Set(Q.map(e=>B(e))))},[Q,B]),Ne=(0,Y.useCallback)(()=>{k.size!==0&&L(!0)},[k.size]),Pe=(0,Y.useCallback)(async()=>{let n=Q.filter(e=>k.has(B(e)));z(!0);let i=0;for(let e of n)try{await r.deleteKProfile(a,{slot_id:e.slot_id,extruder_id:e.extruder_id,nozzle_id:e.nozzle_id,nozzle_diameter:e.nozzle_diameter,filament_id:e.filament_id,setting_id:e.setting_id}),i++,await new Promise(e=>setTimeout(e,300))}catch(t){console.error(`Failed to delete profile:`,e.name,t)}t(e(`kProfiles.toast.profilesDeleted`,{count:i})),z(!1),L(!1),O(!1),P(new Set),G()},[a,k,Q,t,G,B,e]),Fe=(0,Y.useCallback)(e=>{let t=[];return e.setting_id&&t.push(e.setting_id),t.push(`slot_${e.slot_id}_${e.filament_id}_${e.extruder_id}`),t.push(`name_${e.name}_${e.filament_id}`),t},[]),Ie=(0,Y.useCallback)(async(n,i)=>{if(a)try{await r.setKProfileNote(a,n,i),me()}catch(n){console.error(`Failed to save note:`,n),t(e(`kProfiles.toast.failedToSaveNote`),`error`)}},[a,me,t,e]),Le=(0,Y.useCallback)(e=>{if(!X?.notes)return{note:``,key:null};let t=Fe(e);for(let e of t)if(X.notes[e])return{note:X.notes[e],key:e};return{note:``,key:null}},[X,Fe]),Re=(0,Y.useCallback)(e=>Le(e).note,[Le]);return ae?(0,Z.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,Z.jsx)(w,{className:`w-8 h-8 text-bambu-green animate-spin`})}):!V||V.length===0?(0,Z.jsx)(M,{children:(0,Z.jsxs)(j,{className:`py-12 text-center`,children:[(0,Z.jsx)(m,{className:`w-12 h-12 text-bambu-gray mx-auto mb-4`}),(0,Z.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-2`,children:e(`kProfiles.noPrintersConfigured`)}),(0,Z.jsx)(`p`,{className:`text-bambu-gray`,children:e(`kProfiles.addPrinterInSettings`)})]})}):ge.length===0?(0,Z.jsx)(M,{children:(0,Z.jsxs)(j,{className:`py-12 text-center`,children:[(0,Z.jsx)(re,{className:`w-12 h-12 text-bambu-gray mx-auto mb-4`}),(0,Z.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-2`,children:e(`kProfiles.noActivePrinters`)}),(0,Z.jsx)(`p`,{className:`text-bambu-gray`,children:e(`kProfiles.enablePrinterConnection`)})]})}):(0,Z.jsxs)(Z.Fragment,{children:[W&&!U&&(0,Z.jsxs)(`div`,{className:`fixed inset-0 bg-black/50 flex flex-col items-center justify-center z-40`,children:[(0,Z.jsx)(w,{className:`w-10 h-10 text-bambu-green animate-spin mb-3`}),(0,Z.jsx)(`p`,{className:`text-white font-medium`,children:e(`kProfiles.loadingProfiles`)})]}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap gap-4 mb-6`,children:[(0,Z.jsxs)(`div`,{className:`flex-1 min-w-48`,children:[(0,Z.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:e(`kProfiles.printer`)}),(0,Z.jsx)(`select`,{value:a||``,onChange:e=>s(parseInt(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`,children:ge.map(e=>(0,Z.jsx)(`option`,{value:e.id,children:e.name},e.id))})]}),(0,Z.jsxs)(`div`,{className:`w-32`,children:[(0,Z.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:e(`kProfiles.nozzle`)}),(0,Z.jsxs)(`select`,{value:c,onChange:e=>l(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`,children:[(0,Z.jsx)(`option`,{value:`0.2`,children:`0.2mm`}),(0,Z.jsx)(`option`,{value:`0.4`,children:`0.4mm`}),(0,Z.jsx)(`option`,{value:`0.6`,children:`0.6mm`}),(0,Z.jsx)(`option`,{value:`0.8`,children:`0.8mm`})]})]}),(0,Z.jsxs)(`div`,{className:`flex items-end gap-2`,children:[(0,Z.jsxs)(N,{variant:`secondary`,onClick:()=>G(),disabled:W||!n(`kprofiles:read`),title:n(`kprofiles:read`)?void 0:e(`kProfiles.permission.noRead`),children:[(0,Z.jsx)(ie,{className:`w-4 h-4 ${W?`animate-spin`:``}`}),e(`kProfiles.refresh`)]}),(0,Z.jsxs)(N,{onClick:()=>p(!0),disabled:!n(`kprofiles:create`),title:n(`kprofiles:create`)?void 0:e(`kProfiles.permission.noCreate`),children:[(0,Z.jsx)(se,{className:`w-4 h-4`}),e(`kProfiles.addProfile`)]})]})]}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap gap-4 mb-4`,children:[(0,Z.jsxs)(`div`,{className:`flex-1 min-w-48 relative`,children:[(0,Z.jsx)(ee,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,Z.jsx)(`input`,{type:`text`,value:v,onChange:e=>y(e.target.value),placeholder:e(`kProfiles.searchPlaceholder`),className:`w-full pl-10 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),$&&(0,Z.jsx)(`div`,{className:`w-36`,children:(0,Z.jsxs)(`select`,{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 focus:border-bambu-green focus:outline-none`,children:[(0,Z.jsx)(`option`,{value:`all`,children:e(`kProfiles.allExtruders`)}),(0,Z.jsx)(`option`,{value:`left`,children:e(`kProfiles.leftOnly`)}),(0,Z.jsx)(`option`,{value:`right`,children:e(`kProfiles.rightOnly`)})]})}),Oe&&(0,Z.jsx)(`div`,{className:`w-32`,children:(0,Z.jsxs)(`select`,{value:C,onChange:e=>T(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`,children:[(0,Z.jsx)(`option`,{value:`all`,children:e(`kProfiles.allFlow`)}),(0,Z.jsx)(`option`,{value:`hf`,children:e(`kProfiles.hfOnly`)}),(0,Z.jsx)(`option`,{value:`s`,children:e(`kProfiles.sOnly`)})]})}),(0,Z.jsx)(`div`,{className:`w-32`,children:(0,Z.jsxs)(`select`,{value:E,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 focus:border-bambu-green focus:outline-none`,children:[(0,Z.jsx)(`option`,{value:`name`,children:e(`kProfiles.sortName`)}),(0,Z.jsx)(`option`,{value:`k_value`,children:e(`kProfiles.sortKValue`)}),(0,Z.jsx)(`option`,{value:`filament`,children:e(`kProfiles.sortFilament`)})]})})]}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap gap-2 mb-6`,children:[(0,Z.jsxs)(N,{variant:`secondary`,onClick:ke,disabled:!H?.profiles?.length||!n(`kprofiles:read`),title:n(`kprofiles:read`)?void 0:e(`kProfiles.permission.noExport`),children:[(0,Z.jsx)(ue,{className:`w-4 h-4`}),e(`kProfiles.export`)]}),(0,Z.jsxs)(N,{variant:`secondary`,onClick:Ae,disabled:!n(`kprofiles:create`),title:n(`kprofiles:create`)?void 0:e(`kProfiles.permission.noImport`),children:[(0,Z.jsx)(le,{className:`w-4 h-4`}),e(`kProfiles.import`)]}),(0,Z.jsx)(`div`,{className:`flex-1`}),D?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(N,{variant:`secondary`,onClick:Me,children:[(0,Z.jsx)(oe,{className:`w-4 h-4`}),e(`kProfiles.selectAll`)]}),(0,Z.jsxs)(N,{variant:`secondary`,onClick:Ne,disabled:k.size===0||!n(`kprofiles:delete`),className:`text-red-500 hover:bg-red-500/10`,title:n(`kprofiles:delete`)?void 0:e(`kProfiles.permission.noDelete`),children:[(0,Z.jsx)(I,{className:`w-4 h-4`}),e(`kProfiles.delete`),` (`,k.size,`)`]}),(0,Z.jsxs)(N,{variant:`secondary`,onClick:()=>{O(!1),P(new Set)},children:[(0,Z.jsx)(A,{className:`w-4 h-4`}),e(`common.cancel`)]})]}):(0,Z.jsxs)(N,{variant:`secondary`,onClick:()=>O(!0),disabled:!Q.length||!n(`kprofiles:delete`),title:n(`kprofiles:delete`)?void 0:e(`kProfiles.permission.noDelete`),children:[(0,Z.jsx)(oe,{className:`w-4 h-4`}),e(`kProfiles.select`)]})]}),U?(0,Z.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,Z.jsx)(w,{className:`w-8 h-8 text-bambu-green animate-spin`})}):he?(0,Z.jsx)(M,{children:(0,Z.jsxs)(j,{className:`py-12 text-center`,children:[(0,Z.jsx)(ne,{className:`w-12 h-12 text-bambu-gray mx-auto mb-4`}),(0,Z.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-2`,children:e(`kProfiles.printerOffline`)}),(0,Z.jsx)(`p`,{className:`text-bambu-gray mb-4`,children:e(`kProfiles.printerOfflineDesc`)}),(0,Z.jsxs)(N,{variant:`secondary`,onClick:()=>G(),children:[(0,Z.jsx)(ie,{className:`w-4 h-4`}),e(`common.refresh`)]})]})}):Q.length>0?$?(0,Z.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`h3`,{className:`text-sm font-medium text-bambu-gray mb-2 px-1`,children:e(`kProfiles.leftExtruder`)}),(0,Z.jsx)(`div`,{className:`space-y-1`,children:Q.filter(e=>e.extruder_id===1).map(e=>(0,Z.jsx)(we,{profile:e,onEdit:()=>d(e),onCopy:()=>_(e),selectionMode:D,isSelected:k.has(B(e)),onToggleSelect:()=>je(B(e)),note:Re(e)},B(e)))})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`h3`,{className:`text-sm font-medium text-bambu-gray mb-2 px-1`,children:e(`kProfiles.rightExtruder`)}),(0,Z.jsx)(`div`,{className:`space-y-1`,children:Q.filter(e=>e.extruder_id===0).map(e=>(0,Z.jsx)(we,{profile:e,onEdit:()=>d(e),onCopy:()=>_(e),selectionMode:D,isSelected:k.has(B(e)),onToggleSelect:()=>je(B(e)),note:Re(e)},B(e)))})]})]}):(0,Z.jsx)(`div`,{className:`space-y-1`,children:Q.map(e=>(0,Z.jsx)(we,{profile:e,onEdit:()=>d(e),onCopy:()=>_(e),selectionMode:D,isSelected:k.has(B(e)),onToggleSelect:()=>je(B(e)),note:Re(e)},B(e)))}):v||x!==`all`||C!==`all`?(0,Z.jsx)(M,{children:(0,Z.jsxs)(j,{className:`py-12 text-center`,children:[(0,Z.jsx)(ee,{className:`w-12 h-12 text-bambu-gray mx-auto mb-4`}),(0,Z.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-2`,children:e(`kProfiles.noMatchingProfiles`)}),(0,Z.jsx)(`p`,{className:`text-bambu-gray`,children:e(`kProfiles.noMatchingProfilesDesc`)})]})}):(0,Z.jsx)(M,{children:(0,Z.jsxs)(j,{className:`py-12 text-center`,children:[(0,Z.jsx)(b,{className:`w-12 h-12 text-bambu-gray mx-auto mb-4`}),(0,Z.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-2`,children:e(`kProfiles.noKProfiles`)}),(0,Z.jsx)(`p`,{className:`text-bambu-gray mb-4`,children:e(`kProfiles.noKProfilesDesc`,{diameter:c})}),(0,Z.jsxs)(N,{onClick:()=>p(!0),children:[(0,Z.jsx)(se,{className:`w-4 h-4`}),e(`kProfiles.createFirstProfile`)]})]})}),u&&a&&(()=>{let{note:e,key:t}=Le(u);return(0,Z.jsx)(Te,{profile:u,printerId:a,nozzleDiameter:c,existingProfiles:H?.profiles,builtinFilaments:ye,filamentPresets:xe,isDualNozzle:$,supportsFlowType:Oe,initialNote:e,initialNoteKey:t,onSaveNote:Ie,hasPermission:n,onClose:()=>{console.log(`[KProfiles] Edit modal onClose - refetching profiles...`),d(null),G()},onSave:()=>{d(null),G()}})})(),f&&a&&(0,Z.jsx)(Te,{printerId:a,nozzleDiameter:c,existingProfiles:H?.profiles,builtinFilaments:ye,filamentPresets:xe,isDualNozzle:$,supportsFlowType:Oe,onSaveNote:Ie,hasPermission:n,onClose:()=>{p(!1),G()},onSave:()=>{p(!1),G()}}),g&&a&&(0,Z.jsx)(Te,{printerId:a,nozzleDiameter:c,existingProfiles:H?.profiles,builtinFilaments:ye,filamentPresets:xe,isDualNozzle:$,supportsFlowType:Oe,onSaveNote:Ie,hasPermission:n,profile:{...g,slot_id:0,name:`${g.name} (Copy)`},onClose:()=>{_(null),G()},onSave:()=>{_(null),G()}}),F&&(0,Z.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,children:(0,Z.jsx)(M,{className:`w-full max-w-sm`,children:(0,Z.jsxs)(j,{className:`p-6`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-3 mb-4`,children:[(0,Z.jsx)(`div`,{className:`w-10 h-10 rounded-full bg-red-500/20 flex items-center justify-center`,children:(0,Z.jsx)(I,{className:`w-5 h-5 text-red-500`})}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`h3`,{className:`text-lg font-semibold text-white`,children:e(`kProfiles.bulkDelete.title`)}),(0,Z.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`kProfiles.bulkDelete.cannotUndo`)})]})]}),(0,Z.jsx)(`p`,{className:`text-bambu-gray mb-6`,children:e(`kProfiles.bulkDelete.message`,{count:k.size})}),(0,Z.jsxs)(`div`,{className:`flex gap-3`,children:[(0,Z.jsx)(N,{variant:`secondary`,onClick:()=>L(!1),disabled:R,className:`flex-1`,children:e(`common.cancel`)}),(0,Z.jsxs)(N,{onClick:Pe,disabled:R,className:`flex-1 bg-red-500 hover:bg-red-600 text-white`,children:[R?(0,Z.jsx)(w,{className:`w-4 h-4 animate-spin`}):(0,Z.jsx)(I,{className:`w-4 h-4`}),e(`common.delete`)]})]})]})})})]})}var $=[`PLA`,`PETG`,`PCTG`,`ABS`,`ASA`,`TPU`,`PC`,`PA`,`PVA`,`HIPS`,`PP`,`PET`,`NYLON`],Oe={PLA:`E8E8E8`,PETG:`4A90D9`,ABS:`E67E22`,ASA:`D35400`,TPU:`9B59B6`,PC:`BDC3C7`,PA:`2ECC71`,NYLON:`2ECC71`,PVA:`F1C40F`,HIPS:`95A5A6`,PP:`ECF0F1`,PET:`3498DB`};function ke(e){let t=e.toUpperCase();for(let e of $)if(RegExp(`\\b${e}\\b`).test(t))return e;return null}function Ae(e){let t=e.replace(/@.+$/,``).trim(),n=t.toUpperCase();for(let e of $){let r=n.indexOf(e);if(r>0){let e=t.slice(0,r).trim();if(e&&e.length>1)return e}}return null}function je({preset:e,onDelete:t,onExpand:n,isExpanded:r}){let{t:a}=i(),{hasPermission:o}=de(),s=e.filament_type||ke(e.name),c=e.filament_vendor||Ae(e.name),l=null,u=!1;if(e.default_filament_colour)try{let t=JSON.parse(e.default_filament_colour),n=Array.isArray(t)?t[0]:t;typeof n==`string`&&/^#?[0-9a-fA-F]{6,8}$/.test(n.replace(`#`,``))&&(l=n.replace(`#`,``).slice(0,6),u=!0)}catch{let t=e.default_filament_colour;/^#?[0-9a-fA-F]{6,8}$/.test(t.replace(`#`,``))&&(l=t.replace(`#`,``).slice(0,6),u=!0)}return!l&&s&&(l=Oe[s.toUpperCase()]||null),(0,Z.jsx)(M,{className:`bg-bambu-dark border-bambu-dark-tertiary hover:border-bambu-dark-tertiary/80 transition-colors`,children:(0,Z.jsxs)(j,{className:`p-3`,children:[(0,Z.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,Z.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[e.preset_type===`filament`&&(0,Z.jsx)(`div`,{className:`w-4 h-4 rounded-full border border-black/20 flex-shrink-0 ${!u&&!l?`opacity-25`:u?``:`opacity-50`}`,style:{backgroundColor:l?`#${l}`:`#666`}}),(0,Z.jsx)(`span`,{className:`text-sm font-medium text-white truncate`,children:e.name})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[s&&(0,Z.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-bambu-green/20 text-bambu-green`,children:s}),c&&(0,Z.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:c}),(0,Z.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`,children:a(`profiles.localProfiles.badge`)})]})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-1 flex-shrink-0`,children:[o(`settings:update`)&&(0,Z.jsx)(`button`,{onClick:()=>t(e.id),className:`p-1 text-bambu-gray hover:text-red-600 dark:hover:text-red-400 transition-colors`,title:a(`profiles.localProfiles.delete`),children:(0,Z.jsx)(I,{className:`w-3.5 h-3.5`})}),(0,Z.jsx)(`button`,{onClick:()=>n(r?null:e.id),className:`p-1 text-bambu-gray hover:text-white transition-colors`,children:r?(0,Z.jsx)(p,{className:`w-3.5 h-3.5`}):(0,Z.jsx)(f,{className:`w-3.5 h-3.5`})})]})]}),r&&(0,Z.jsxs)(`div`,{className:`mt-3 pt-3 border-t border-bambu-dark-tertiary text-xs space-y-1.5`,children:[s&&(0,Z.jsxs)(`div`,{className:`flex justify-between`,children:[(0,Z.jsx)(`span`,{className:`text-bambu-gray`,children:a(`profiles.localProfiles.filamentType`)}),(0,Z.jsx)(`span`,{className:`text-white`,children:s})]}),c&&(0,Z.jsxs)(`div`,{className:`flex justify-between`,children:[(0,Z.jsx)(`span`,{className:`text-bambu-gray`,children:a(`profiles.localProfiles.vendor`)}),(0,Z.jsx)(`span`,{className:`text-white`,children:c})]}),e.nozzle_temp_min!=null&&e.nozzle_temp_max!=null&&(0,Z.jsxs)(`div`,{className:`flex justify-between`,children:[(0,Z.jsx)(`span`,{className:`text-bambu-gray`,children:a(`profiles.localProfiles.nozzleTemp`)}),(0,Z.jsxs)(`span`,{className:`text-white`,children:[e.nozzle_temp_min,`–`,e.nozzle_temp_max,`°C`]})]}),e.filament_cost&&(0,Z.jsxs)(`div`,{className:`flex justify-between`,children:[(0,Z.jsx)(`span`,{className:`text-bambu-gray`,children:a(`profiles.localProfiles.cost`)}),(0,Z.jsx)(`span`,{className:`text-white`,children:e.filament_cost})]}),e.filament_density&&(0,Z.jsxs)(`div`,{className:`flex justify-between`,children:[(0,Z.jsx)(`span`,{className:`text-bambu-gray`,children:a(`profiles.localProfiles.density`)}),(0,Z.jsxs)(`span`,{className:`text-white`,children:[e.filament_density,` g/cm³`]})]}),e.pressure_advance&&(0,Z.jsxs)(`div`,{className:`flex justify-between`,children:[(0,Z.jsx)(`span`,{className:`text-bambu-gray`,children:a(`profiles.localProfiles.pressureAdvance`)}),(0,Z.jsx)(`span`,{className:`text-white`,children:e.pressure_advance})]}),e.compatible_printers&&(0,Z.jsxs)(`div`,{className:`flex justify-between`,children:[(0,Z.jsx)(`span`,{className:`text-bambu-gray`,children:a(`profiles.localProfiles.compatiblePrinters`)}),(0,Z.jsx)(`span`,{className:`text-white truncate ml-2`,children:(()=>{try{return JSON.parse(e.compatible_printers).join(`, `)}catch{return e.compatible_printers}})()})]}),e.inherits&&e.inherits!==e.name&&(0,Z.jsxs)(`div`,{className:`flex justify-between`,children:[(0,Z.jsx)(`span`,{className:`text-bambu-gray`,children:a(`profiles.localProfiles.inheritsFrom`)}),(0,Z.jsx)(`span`,{className:`text-white truncate ml-2`,children:e.inherits})]}),(0,Z.jsxs)(`div`,{className:`flex justify-between`,children:[(0,Z.jsx)(`span`,{className:`text-bambu-gray`,children:a(`profiles.localProfiles.source`)}),(0,Z.jsx)(`span`,{className:`text-white capitalize`,children:e.source})]})]})]})})}function Me(){let{t:e}=i(),{hasPermission:t}=de(),n=a(),{showToast:c}=h(),[l,u]=(0,Y.useState)(``),[d,f]=(0,Y.useState)(null),[p,g]=(0,Y.useState)(!1),[v,y]=(0,Y.useState)(null),{data:b,isLoading:x}=o({queryKey:[`localPresets`],queryFn:()=>r.getLocalPresets()}),C=s({mutationFn:async e=>{let t=[];for(let n of Array.from(e)){let e=new FormData;e.append(`file`,n),t.push(await r.importLocalPresets(e))}return t},onSuccess:t=>{n.invalidateQueries({queryKey:[`localPresets`]}),n.invalidateQueries({queryKey:[`slicerPresets`]});let r=0,i=0,a=0;for(let e of t)r+=e.imported,i+=e.skipped,a+=e.errors.length;r>0&&c(e(`profiles.localProfiles.toast.importSuccess`,{count:r})),i>0&&c(e(`profiles.localProfiles.toast.importSkipped`,{count:i}),`warning`),a>0&&c(e(`profiles.localProfiles.toast.importError`,{count:a}),`error`)},onError:e=>{c(e.message,`error`)}}),T=s({mutationFn:e=>r.deleteLocalPreset(e),onSuccess:(t,r)=>{n.setQueryData([`localPresets`],e=>e&&{filament:e.filament.filter(e=>e.id!==r),printer:e.printer.filter(e=>e.id!==r),process:e.process.filter(e=>e.id!==r)}),n.invalidateQueries({queryKey:[`localPresets`]}),n.invalidateQueries({queryKey:[`slicerPresets`]}),y(null),c(e(`profiles.localProfiles.toast.deleted`))}}),E=(0,Y.useCallback)(e=>{!e||e.length===0||C.mutate(e)},[C]),D=(0,Y.useCallback)(e=>{e.preventDefault(),g(!1),E(e.dataTransfer.files)},[E]),O=(0,Y.useCallback)(e=>{if(!l)return e;let t=l.toLowerCase();return e.filter(e=>e.name.toLowerCase().includes(t)||e.filament_type?.toLowerCase().includes(t)||e.filament_vendor?.toLowerCase().includes(t))},[l]),k=(0,Y.useMemo)(()=>O(b?.filament||[]),[b?.filament,O]),A=(0,Y.useMemo)(()=>O(b?.printer||[]),[b?.printer,O]),j=(0,Y.useMemo)(()=>O(b?.process||[]),[b?.process,O]),M=k.length+A.length+j.length,P=(b?.filament?.length??0)+(b?.printer?.length??0)+(b?.process?.length??0)>0;return x?(0,Z.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,Z.jsx)(w,{className:`w-8 h-8 text-bambu-green animate-spin`})}):(0,Z.jsxs)(`div`,{className:`space-y-6`,children:[t(`settings:update`)&&(0,Z.jsxs)(`div`,{onDragOver:e=>{e.preventDefault(),g(!0)},onDragLeave:()=>g(!1),onDrop:D,className:`relative border-2 border-dashed rounded-lg p-6 text-center transition-colors ${p?`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:[(0,Z.jsx)(`input`,{type:`file`,accept:`.json,.zip,.orca_filament,.bbscfg,.bbsflmt`,multiple:!0,className:`absolute inset-0 w-full h-full opacity-0 cursor-pointer`,onChange:e=>E(e.target.files)}),C.isPending?(0,Z.jsxs)(`div`,{className:`flex items-center justify-center gap-2`,children:[(0,Z.jsx)(w,{className:`w-5 h-5 text-bambu-green animate-spin`}),(0,Z.jsx)(`span`,{className:`text-bambu-gray`,children:e(`profiles.localProfiles.importing`)})]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(le,{className:`w-8 h-8 text-bambu-gray mx-auto mb-2`}),(0,Z.jsx)(`p`,{className:`text-sm text-white font-medium`,children:e(`profiles.localProfiles.import`)}),(0,Z.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`profiles.localProfiles.importDesc`)})]})]}),P&&(0,Z.jsxs)(`div`,{className:`relative`,children:[(0,Z.jsx)(ee,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,Z.jsx)(`input`,{type:`text`,value:l,onChange:e=>u(e.target.value),placeholder:e(`profiles.localProfiles.search`),className:`w-full pl-9 pr-4 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`})]}),!P&&!x&&(0,Z.jsxs)(`div`,{className:`text-center py-12`,children:[(0,Z.jsx)(S,{className:`w-12 h-12 text-bambu-gray mx-auto mb-3 opacity-50`}),(0,Z.jsx)(`p`,{className:`text-bambu-gray`,children:e(`profiles.localProfiles.noPresets`)}),(0,Z.jsx)(`p`,{className:`text-xs text-bambu-gray/60 mt-1`,children:e(`profiles.localProfiles.importDesc`)})]}),P&&M===0&&!x&&(0,Z.jsxs)(`div`,{className:`text-center py-12`,children:[(0,Z.jsx)(ee,{className:`w-12 h-12 text-bambu-gray mx-auto mb-3 opacity-50`}),(0,Z.jsx)(`p`,{className:`text-bambu-gray`,children:e(`profiles.localProfiles.noSearchResults`)})]}),M>0&&(0,Z.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6`,children:[k.length>0&&(0,Z.jsxs)(`div`,{children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,Z.jsx)(_,{className:`w-4 h-4 text-bambu-green`}),(0,Z.jsx)(`h3`,{className:`text-sm font-medium text-white`,children:e(`profiles.localProfiles.filament`)}),(0,Z.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[`(`,k.length,`)`]})]}),(0,Z.jsx)(`div`,{className:`space-y-2`,children:k.map(e=>(0,Z.jsx)(je,{preset:e,onDelete:e=>y(e),onExpand:f,isExpanded:d===e.id},e.id))})]}),j.length>0&&(0,Z.jsxs)(`div`,{children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,Z.jsx)(ce,{className:`w-4 h-4 text-blue-600 dark:text-blue-400`}),(0,Z.jsx)(`h3`,{className:`text-sm font-medium text-white`,children:e(`profiles.localProfiles.process`)}),(0,Z.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[`(`,j.length,`)`]})]}),(0,Z.jsx)(`div`,{className:`space-y-2`,children:j.map(e=>(0,Z.jsx)(je,{preset:e,onDelete:e=>y(e),onExpand:f,isExpanded:d===e.id},e.id))})]}),A.length>0&&(0,Z.jsxs)(`div`,{children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,Z.jsx)(te,{className:`w-4 h-4 text-orange-600 dark:text-orange-400`}),(0,Z.jsx)(`h3`,{className:`text-sm font-medium text-white`,children:e(`profiles.localProfiles.printer`)}),(0,Z.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[`(`,A.length,`)`]})]}),(0,Z.jsx)(`div`,{className:`space-y-2`,children:A.map(e=>(0,Z.jsx)(je,{preset:e,onDelete:e=>y(e),onExpand:f,isExpanded:d===e.id},e.id))})]})]}),v!==null&&(0,Z.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50`,children:(0,Z.jsxs)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg p-6 max-w-sm mx-4`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,Z.jsx)(m,{className:`w-5 h-5 text-red-600 dark:text-red-400`}),(0,Z.jsx)(`h3`,{className:`text-white font-medium`,children:e(`profiles.localProfiles.deleteConfirmTitle`)})]}),(0,Z.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4`,children:e(`profiles.localProfiles.deleteConfirm`)}),(0,Z.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,Z.jsx)(N,{variant:`secondary`,size:`sm`,onClick:()=>y(null),children:e(`profiles.localProfiles.cancel`)}),(0,Z.jsxs)(N,{variant:`danger`,size:`sm`,onClick:()=>T.mutate(v),disabled:T.isPending,children:[T.isPending?(0,Z.jsx)(w,{className:`w-4 h-4 animate-spin`}):(0,Z.jsx)(I,{className:`w-4 h-4`}),e(`profiles.localProfiles.delete`)]})]})]})})]})}function Ne(e){let t=e.match(/@?\s*(?:BBL\s+)?(?:Bambu\s+Lab\s+)?([XPAH][1-9][A-Z]?(?:\s*(?:Carbon|mini))?|H2D)/i),n=e.match(/(\d+\.?\d*)\s*(?:mm\s*)?nozzle|nozzle\s*(\d+\.?\d*)/i),r=e.match(/(\d+\.?\d*)mm\s*(?:Standard|Fine|Extra Fine|Draft|Quality)?/i),i=e.match(/\b(PLA|PETG|ABS|ASA|TPU|PC|PA|PVA|HIPS|PP|PET(?:-?CF)?|PA(?:-?CF)?|PLA(?:-?CF)?)\b/i);return{printer:t?t[1].trim():null,nozzle:n?(n[1]||n[2])+`mm`:null,layerHeight:r?r[1]+`mm`:null,filamentType:i?i[1].toUpperCase():null}}function Pe({settings:e,lastSyncTime:t,onRefresh:n,isRefreshing:r,printers:i,t:a}){let[o,s]=(0,Y.useState)(``),[c,l]=(0,Y.useState)(`all`),[u,d]=(0,Y.useState)(`all`),[f,p]=(0,Y.useState)(`all`),[m,h]=(0,Y.useState)(`all`),[g,v]=(0,Y.useState)(`all`),[b,x]=(0,Y.useState)(null),S=(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:Ne(e.name)})),[e]),C=(0,Y.useMemo)(()=>{let e=new Set,t=new Set,n=new Set;return S.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))}},[S,i]),w=(0,Y.useMemo)(()=>u===`all`?null:i.find(e=>e.id.toString()===u)?.model||null,[u,i]),T=(0,Y.useMemo)(()=>S.filter(e=>c===`all`||e.type===c).filter(e=>{if(u===`all`||!w)return!0;let t=e.meta.printer?.toLowerCase()||``,n=w.toLowerCase();return t.includes(n)||n.includes(t)}).filter(e=>f===`all`||e.meta.nozzle===f).filter(e=>m===`all`||e.meta.filamentType===m).filter(e=>g===`all`||e.meta.layerHeight===g).filter(e=>o===``||e.name.toLowerCase().includes(o.toLowerCase())).sort((e,t)=>e.name.localeCompare(t.name)),[S,c,u,w,f,m,g,o]),E=()=>{l(`all`),d(`all`),p(`all`),h(`all`),v(`all`),s(``)},D=c!==`all`||u!==`all`||f!==`all`||m!==`all`||g!==`all`||o!==``,O=e.filament.length+e.printer.length+e.process.length,k=e=>T.filter(t=>t.type===e);return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{className:`space-y-4 mb-6`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-col sm:flex-row gap-3`,children:[(0,Z.jsxs)(`div`,{className:`relative flex-1`,children:[(0,Z.jsx)(ee,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,Z.jsx)(`input`,{type:`text`,value:o,onChange:e=>s(e.target.value),placeholder:a(`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,Z.jsx)(`div`,{className:`flex gap-2`,children:(0,Z.jsxs)(N,{variant:`secondary`,onClick:n,disabled:r,children:[(0,Z.jsx)(ie,{className:`w-4 h-4 ${r?`animate-spin`:``}`}),a(`profiles.cloudView.refresh`)]})})]}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Z.jsx)(y,{className:`w-4 h-4 text-bambu-gray`}),(0,Z.jsx)(Ue,{label:a(`profiles.cloudView.filters.type`),value:c,options:[{value:`all`,label:a(`profiles.cloudView.filters.all`),count:O},{value:`filament`,label:a(`profiles.cloudView.filters.filament`),count:e.filament.length},{value:`printer`,label:a(`profiles.cloudView.filters.printer`),count:e.printer.length},{value:`process`,label:a(`profiles.cloudView.filters.process`),count:e.process.length}],onChange:e=>l(e)}),C.printers.length>0&&(0,Z.jsx)(Ue,{label:a(`profiles.cloudView.filters.printer`),value:u,options:[{value:`all`,label:a(`profiles.cloudView.filters.all`)},...C.printers.map(e=>({value:e.id,label:e.name}))],onChange:d}),C.nozzles.length>0&&(0,Z.jsx)(Ue,{label:a(`profiles.cloudView.filters.nozzle`),value:f,options:[{value:`all`,label:a(`profiles.cloudView.filters.all`)},...C.nozzles.map(e=>({value:e,label:e}))],onChange:p}),C.filaments.length>0&&(c===`all`||c===`filament`)&&(0,Z.jsx)(Ue,{label:a(`profiles.cloudView.filters.filament`),value:m,options:[{value:`all`,label:a(`profiles.cloudView.filters.all`)},...C.filaments.map(e=>({value:e,label:e}))],onChange:h}),C.layerHeights.length>0&&(c===`all`||c===`process`)&&(0,Z.jsx)(Ue,{label:a(`profiles.cloudView.filters.layer`),value:g,options:[{value:`all`,label:a(`profiles.cloudView.filters.all`)},...C.layerHeights.map(e=>({value:e,label:e}))],onChange:v}),D&&(0,Z.jsx)(`button`,{onClick:E,className:`px-3 py-2 text-sm text-bambu-gray hover:text-white transition-colors`,children:a(`profiles.cloudView.clearFilters`)})]})]}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4 mb-4 text-sm text-bambu-gray`,children:[t&&(0,Z.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Z.jsx)(ae,{className:`w-3 h-3`}),a(`profiles.cloudView.lastSynced`),` `,P(t.toISOString(),`system`,a)]}),(0,Z.jsx)(`span`,{children:a(`profiles.cloudView.showingCount`,{showing:T.length,total:O})})]}),T.length===0?(0,Z.jsxs)(`div`,{className:`text-center py-16`,children:[(0,Z.jsx)(ce,{className:`w-12 h-12 text-bambu-gray-dark mx-auto mb-4`}),(0,Z.jsx)(`p`,{className:`text-bambu-gray`,children:a(`profiles.cloudView.noPresetsFound`)}),D&&(0,Z.jsx)(`button`,{onClick:E,className:`mt-2 text-sm text-bambu-green hover:text-bambu-green-light`,children:a(`profiles.cloudView.clearFilters`)})]}):(0,Z.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-6`,children:[(0,Z.jsx)(Fe,{icon:(0,Z.jsx)(_,{className:`w-4 h-4 text-amber-600 dark:text-amber-400`}),title:a(`profiles.cloudView.columns.filament`),presets:k(`filament`),emptyText:a(`profiles.cloudView.noFilamentPresets`),onSelect:x}),(0,Z.jsx)(Fe,{icon:(0,Z.jsx)(te,{className:`w-4 h-4 text-blue-600 dark:text-blue-400`}),title:a(`profiles.cloudView.columns.process`),presets:k(`process`),emptyText:a(`profiles.cloudView.noProcessPresets`),onSelect:x}),(0,Z.jsx)(Fe,{icon:(0,Z.jsx)(re,{className:`w-4 h-4 text-purple-600 dark:text-purple-400`}),title:a(`profiles.cloudView.columns.printer`),presets:k(`printer`),emptyText:a(`profiles.cloudView.noPrinterPresets`),onSelect:x})]}),b&&(0,Z.jsx)(Le,{setting:b,onClose:()=>x(null),t:a})]})}function Fe({icon:e,title:t,presets:n,emptyText:r,onSelect:i}){return(0,Z.jsxs)(`div`,{children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 mb-3 px-1`,children:[e,(0,Z.jsx)(`h3`,{className:`text-sm font-medium text-bambu-gray`,children:t}),(0,Z.jsxs)(`span`,{className:`text-xs text-bambu-gray-dark`,children:[`(`,n.length,`)`]})]}),(0,Z.jsx)(`div`,{className:`space-y-1 max-h-[calc(100vh-320px)] overflow-y-auto pr-1`,children:n.length===0?(0,Z.jsx)(`p`,{className:`text-xs text-bambu-gray-dark px-3 py-2`,children:r}):n.map(e=>(0,Z.jsx)(Ie,{preset:e,onClick:()=>i(e)},e.setting_id))})]})}function Ie({preset:e,onClick:t}){return(0,Z.jsx)(`button`,{onClick:t,className:`w-full text-left px-3 py-2 rounded bg-bambu-dark hover:bg-bambu-dark-tertiary transition-colors`,children:(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`span`,{className:`text-white text-sm truncate flex-1`,title:e.name,children:e.name}),e.meta.filamentType&&e.type===`filament`&&(0,Z.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:e.meta.filamentType}),e.meta.layerHeight&&e.type===`process`&&(0,Z.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:e.meta.layerHeight}),e.meta.printer&&(0,Z.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:e.meta.printer})]})})}function Le({setting:e,onClose:t,t:n}){let{data:i,isLoading:a,error:s}=o({queryKey:[`orcaCloudProfileDetail`,e.setting_id],queryFn:()=>r.orcaCloudGetProfile(e.setting_id),retry:!1});return(0,Z.jsx)(`div`,{className:`fixed inset-0 bg-black/60 z-50 flex items-center justify-center p-4`,onClick:t,children:(0,Z.jsxs)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-2xl max-w-4xl w-full max-h-[90vh] flex flex-col`,onClick:e=>e.stopPropagation(),children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`h2`,{className:`text-lg font-bold text-white`,children:e.name}),(0,Z.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:e.type})]}),(0,Z.jsx)(`button`,{onClick:t,className:`text-bambu-gray hover:text-white p-1`,children:(0,Z.jsx)(A,{className:`w-5 h-5`})})]}),(0,Z.jsx)(`div`,{className:`flex-1 overflow-y-auto p-4`,children:a?(0,Z.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,Z.jsx)(w,{className:`w-8 h-8 text-bambu-green animate-spin`})}):s?(0,Z.jsx)(`p`,{className:`text-center text-bambu-gray py-16`,children:s.message}):i?(0,Z.jsx)(`pre`,{className:`text-xs font-mono text-bambu-gray bg-bambu-dark p-3 rounded overflow-x-auto whitespace-pre`,children:JSON.stringify(i.setting,null,2)}):(0,Z.jsx)(`p`,{className:`text-center text-bambu-gray py-16`,children:n(`profiles.cloudView.noPresetsFound`)})})]})})}function Re(){let{t:e}=i(),t=a(),{showToast:n}=h(),{hasPermission:c}=de(),l=c(`orca_cloud:auth`),[u,d]=(0,Y.useState)(null),[f,p]=(0,Y.useState)(5e3),[m,g]=(0,Y.useState)(null),{data:_,isLoading:v}=o({queryKey:[`orcaCloudStatus`],queryFn:r.orcaCloudStatus}),y=!!_?.connected,{data:b,isLoading:x,refetch:S,isRefetching:C,error:T,dataUpdatedAt:E}=o({queryKey:[`orcaCloudProfiles`],queryFn:r.orcaCloudListProfiles,enabled:y,retry:!1,staleTime:1e3*60*5}),{data:ee=[]}=o({queryKey:[`printers`],queryFn:r.getPrinters,enabled:y}),[te,D]=(0,Y.useState)();(0,Y.useEffect)(()=>{E&&D(new Date(E))},[E]);let O=()=>{d(null),p(5e3)},k=t=>{t===`access_denied`?g(e(`profiles.orcaCloud.errors.denied`)):t===`expired_token`&&g(e(`profiles.orcaCloud.errors.expired`)),O()},A=s({mutationFn:r.orcaCloudDeviceStart,onSuccess:e=>{g(null),p(Math.max(1,e.interval)*1e3),d(e)},onError:t=>{g(t.message||e(`profiles.orcaCloud.errors.startFailed`))}}),j=s({mutationFn:r.orcaCloudLogout,onSuccess:()=>{t.invalidateQueries({queryKey:[`orcaCloudStatus`]}),t.removeQueries({queryKey:[`orcaCloudProfiles`]}),n(e(`profiles.orcaCloud.toast.disconnected`))}}),{data:M,error:P}=o({queryKey:[`orcaCloudDevicePoll`,u?.user_code??`none`],queryFn:r.orcaCloudDevicePoll,enabled:u!==null,gcTime:0,retry:!1,refetchOnWindowFocus:!1,refetchInterval:u===null?!1:f}),F=(0,Y.useRef)(null);return(0,Y.useEffect)(()=>{if(!u||!M)return;let r=M.status;if(r===`slow_down`){p(e=>e+5e3);return}r!==`authorization_pending`&&F.current!==r&&(F.current=r,r===`complete`?(O(),t.invalidateQueries({queryKey:[`orcaCloudStatus`]}),t.invalidateQueries({queryKey:[`orcaCloudProfiles`]}),n(e(`profiles.orcaCloud.connectedShort`))):k(r))},[M,u]),(0,Y.useEffect)(()=>{u&&P&&(g(e(`profiles.orcaCloud.errors.pollFailed`)),O())},[P,u]),(0,Y.useEffect)(()=>{u&&(F.current=null)},[u]),v?(0,Z.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,Z.jsx)(w,{className:`w-8 h-8 text-bambu-green animate-spin`})}):(0,Z.jsxs)(`div`,{children:[y&&(0,Z.jsxs)(`div`,{className:`flex items-center justify-between p-3 mb-6 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Z.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-bambu-green animate-pulse`}),(0,Z.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:_?.email?(0,Z.jsxs)(Z.Fragment,{children:[e(`profiles.orcaCloud.connectedAs`),` `,(0,Z.jsx)(`span`,{className:`text-white`,children:_.email})]}):(0,Z.jsx)(`span`,{className:`text-white`,children:e(`profiles.orcaCloud.connectedShort`)})})]}),(0,Z.jsxs)(N,{variant:`secondary`,size:`sm`,onClick:()=>j.mutate(),disabled:j.isPending||!l,title:l?void 0:e(`profiles.orcaCloud.noLogoutPermission`),children:[(0,Z.jsx)(W,{className:`w-4 h-4`}),e(`profiles.orcaCloud.logout`)]})]}),y?x?(0,Z.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,Z.jsx)(w,{className:`w-8 h-8 text-bambu-green animate-spin`})}):T?(0,Z.jsxs)(`div`,{className:`text-center py-16`,children:[(0,Z.jsx)(`p`,{className:`text-bambu-gray mb-4`,children:T.message}),(0,Z.jsx)(N,{onClick:()=>S(),children:e(`profiles.orcaCloud.retry`)})]}):b?(0,Z.jsx)(Pe,{settings:b,lastSyncTime:te,onRefresh:()=>S(),isRefreshing:C,printers:ee,t:e}):null:(0,Z.jsx)(ze,{pairing:u,connectError:m,onConnect:()=>A.mutate(),onCancel:O,isStarting:A.isPending,canManage:l,t:e})]})}function ze({pairing:e,connectError:t,onConnect:n,onCancel:r,isStarting:i,canManage:a,t:o}){return e?(0,Z.jsx)(M,{children:(0,Z.jsxs)(j,{className:`p-8 text-center max-w-md mx-auto`,children:[(0,Z.jsx)(z,{className:`w-12 h-12 text-bambu-green mx-auto mb-4`}),(0,Z.jsx)(`h2`,{className:`text-xl font-bold text-white mb-2`,children:o(`profiles.orcaCloud.device.title`)}),(0,Z.jsx)(`p`,{className:`text-bambu-gray mb-6`,children:o(`profiles.orcaCloud.device.instruction`)}),(0,Z.jsx)(`p`,{className:`text-xs uppercase tracking-wide text-bambu-gray mb-2`,children:o(`profiles.orcaCloud.device.codeLabel`)}),(0,Z.jsx)(`div`,{className:`mb-6 py-3 px-4 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg`,children:(0,Z.jsx)(`span`,{className:`text-2xl font-mono font-bold tracking-[0.3em] text-white select-all`,children:e.user_code})}),(0,Z.jsx)(`a`,{href:e.verification_uri_complete,target:`_blank`,rel:`noopener noreferrer`,children:(0,Z.jsxs)(N,{className:`w-full mb-3`,children:[(0,Z.jsx)(R,{className:`w-4 h-4`}),o(`profiles.orcaCloud.device.openButton`)]})}),(0,Z.jsx)(`p`,{className:`text-xs text-bambu-gray break-all mb-6`,children:o(`profiles.orcaCloud.device.manualHint`,{url:e.verification_uri})}),(0,Z.jsxs)(`div`,{className:`flex items-center justify-center gap-2 text-sm text-bambu-gray mb-4`,children:[(0,Z.jsx)(w,{className:`w-4 h-4 animate-spin text-bambu-green`}),o(`profiles.orcaCloud.device.waiting`)]}),(0,Z.jsx)(`button`,{type:`button`,onClick:r,className:`text-bambu-gray hover:text-white text-sm`,children:o(`profiles.orcaCloud.device.cancel`)})]})}):(0,Z.jsx)(M,{children:(0,Z.jsxs)(j,{className:`p-8 text-center`,children:[(0,Z.jsx)(z,{className:`w-12 h-12 text-bambu-green mx-auto mb-4`}),(0,Z.jsx)(`h2`,{className:`text-xl font-bold text-white mb-2`,children:o(`profiles.orcaCloud.connect.title`)}),(0,Z.jsx)(`p`,{className:`text-bambu-gray mb-6 max-w-xl mx-auto`,children:o(`profiles.orcaCloud.connect.description`)}),(0,Z.jsxs)(`div`,{className:`max-w-sm mx-auto`,children:[(0,Z.jsxs)(N,{onClick:n,disabled:i||!a,title:a?void 0:o(`profiles.orcaCloud.noConnectPermission`),className:`w-full`,children:[i?(0,Z.jsx)(w,{className:`w-4 h-4 animate-spin`}):(0,Z.jsx)(d,{className:`w-4 h-4`}),o(`profiles.orcaCloud.connectButton`)]}),t&&(0,Z.jsxs)(`p`,{className:`mt-3 text-sm text-red-700 dark:text-red-400 flex items-center justify-center gap-2`,children:[(0,Z.jsx)(m,{className:`w-4 h-4 flex-shrink-0`}),t]})]})]})})}function Be(e,t){let n=`${e} ${t||``}`,r=n.match(/@?\s*(?:BBL\s+)?(?:Bambu\s+Lab\s+)?([XPAH][1-9][A-Z]?(?:\s*(?:Carbon|mini))?|H2D)/i),i=r?r[1].trim():null,a=n.match(/(\d+\.?\d*)\s*(?:mm\s*)?nozzle|nozzle\s*(\d+\.?\d*)/i),o=a?(a[1]||a[2])+`mm`:null,s=n.match(/(\d+\.?\d*)mm\s*(?:Standard|Fine|Extra Fine|Draft|Quality)?/i),c=s?s[1]+`mm`:null,l=n.match(/\b(PLA|PETG|ABS|ASA|TPU|PC|PA|PVA|HIPS|PP|PET(?:-?CF)?|PA(?:-?CF)?|PLA(?:-?CF)?)\b/i);return{printer:i,nozzle:o,layerHeight:c,filamentType:l?l[1].toUpperCase():null}}function Ve(e){return/^(P[FPM]US|PF\d|PP\d)/.test(e)}function He({onSuccess:e,t}){let{showToast:n}=h(),[i,a]=(0,Y.useState)(`email`),[o,c]=(0,Y.useState)(``),[l,u]=(0,Y.useState)(``),[d,f]=(0,Y.useState)(``),[p,m]=(0,Y.useState)(``),[g,_]=(0,Y.useState)(`global`),[v,y]=(0,Y.useState)(null),[b,x]=(0,Y.useState)(null),[S,C]=(0,Y.useState)(!1),E=s({mutationFn:()=>r.cloudLogin(o,l,g),onSuccess:r=>{if(C(r.reason===`captcha`),r.success)n(t(`profiles.login.toast.loggedIn`)),e();else if(r.reason===`captcha`)return;else r.needs_verification?(y(r.verification_type||`email`),x(r.tfa_key||null),r.verification_type===`totp`?n(t(`profiles.login.toast.enterTotp`)):n(t(`profiles.login.toast.codeSent`)),a(`code`)):n(r.message,`error`)},onError:e=>{C(!1),n(e.message,`error`)}}),ee=s({mutationFn:()=>r.cloudVerify(o,d,b||void 0,g),onSuccess:r=>{C(r.reason===`captcha`),r.success?(n(t(`profiles.login.toast.loggedIn`)),e()):r.reason!==`captcha`&&n(r.message,`error`)},onError:e=>{C(!1),n(e.message,`error`)}}),te=s({mutationFn:()=>r.cloudSetToken(p,g),onSuccess:()=>{n(t(`profiles.login.toast.tokenSet`)),e()},onError:e=>n(e.message,`error`)}),D=e=>{e.preventDefault(),i===`email`?E.mutate():i===`code`?ee.mutate():i===`token`&&te.mutate()},O=E.isPending||ee.isPending||te.isPending;return(0,Z.jsx)(M,{className:`max-w-md mx-auto`,children:(0,Z.jsxs)(j,{children:[(0,Z.jsxs)(`div`,{className:`text-center mb-6`,children:[(0,Z.jsx)(`div`,{className:`inline-flex items-center justify-center w-12 h-12 rounded-xl bg-bambu-green/20 mb-3`,children:(0,Z.jsx)(z,{className:`w-6 h-6 text-bambu-green`})}),(0,Z.jsx)(`h2`,{className:`text-xl font-semibold text-white`,children:t(`profiles.login.title`)}),(0,Z.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:t(`profiles.login.subtitle`)})]}),S&&i!==`token`&&(0,Z.jsx)(`div`,{role:`alert`,className:`mb-4 p-3 rounded-lg border border-amber-500/40 bg-amber-500/10`,children:(0,Z.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Z.jsx)(L,{className:`w-4 h-4 text-amber-400 shrink-0 mt-0.5`}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`p`,{className:`text-sm font-medium text-amber-300`,children:t(`profiles.login.captchaTitle`)}),(0,Z.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:t(`profiles.login.captchaBody`)}),(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>{C(!1),a(`token`)},className:`mt-2 text-xs text-bambu-green hover:underline flex items-center gap-1`,children:[(0,Z.jsx)(G,{className:`w-3 h-3`}),t(`profiles.login.useToken`)]})]})]})}),(0,Z.jsxs)(`form`,{onSubmit:D,className:`space-y-4`,children:[i===`email`&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:t(`profiles.login.email`)}),(0,Z.jsx)(`input`,{type:`email`,value:o,onChange:e=>c(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none`,placeholder:`your@email.com`,required:!0})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:t(`profiles.login.password`)}),(0,Z.jsx)(`input`,{type:`password`,value:l,onChange:e=>u(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none`,placeholder:`••••••••`,required:!0})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:t(`profiles.login.region`)}),(0,Z.jsxs)(`select`,{value:g,onChange:e=>_(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`,children:[(0,Z.jsx)(`option`,{value:`global`,children:t(`profiles.login.regionGlobal`)}),(0,Z.jsx)(`option`,{value:`china`,children:t(`profiles.login.regionChina`)})]})]})]}),i===`code`&&(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:t(v===`totp`?`profiles.login.totpCode`:`profiles.login.verificationCode`)}),(0,Z.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:v===`totp`?t(`profiles.login.enterTotpHint`):t(`profiles.login.checkEmail`,{email:o})}),(0,Z.jsx)(`input`,{type:`text`,value:d,onChange:e=>f(e.target.value.replace(/\D/g,``).slice(0,6)),className:`w-full px-3 py-3 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-center text-2xl tracking-widest font-mono focus:border-bambu-green focus:outline-none`,placeholder:`000000`,maxLength:6,required:!0})]}),i===`token`&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:t(`profiles.login.accessToken`)}),(0,Z.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:t(`profiles.login.accessTokenHint`)}),(0,Z.jsx)(`textarea`,{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-xs font-mono placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none resize-none`,placeholder:`eyJ...`,rows:4,required:!0})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:t(`profiles.login.region`)}),(0,Z.jsxs)(`select`,{value:g,onChange:e=>_(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`,children:[(0,Z.jsx)(`option`,{value:`global`,children:t(`profiles.login.regionGlobal`)}),(0,Z.jsx)(`option`,{value:`china`,children:t(`profiles.login.regionChina`)})]})]})]}),(0,Z.jsxs)(`div`,{className:`flex gap-2 max-[550px]:flex-wrap max-[550px]:items-center`,children:[i===`code`&&(0,Z.jsx)(N,{type:`button`,variant:`secondary`,onClick:()=>a(`email`),className:`flex-1`,children:t(`profiles.login.back`)}),(0,Z.jsxs)(N,{type:`submit`,disabled:O,className:`flex-1`,children:[O?(0,Z.jsx)(w,{className:`w-4 h-4 animate-spin`}):(0,Z.jsx)(T,{className:`w-4 h-4`}),t(i===`email`?`profiles.login.loginButton`:i===`code`?`profiles.login.verifyButton`:`profiles.login.setTokenButton`)]})]}),i===`email`&&(0,Z.jsx)(`div`,{className:`pt-4 border-t border-bambu-dark-tertiary`,children:(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>a(`token`),className:`text-sm text-bambu-gray hover:text-white flex items-center gap-2 transition-colors`,children:[(0,Z.jsx)(G,{className:`w-4 h-4`}),t(`profiles.login.useToken`)]})}),i===`token`&&(0,Z.jsx)(`div`,{className:`pt-4 border-t border-bambu-dark-tertiary`,children:(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>a(`email`),className:`text-sm text-bambu-gray hover:text-white flex items-center gap-2 transition-colors`,children:[(0,Z.jsx)(T,{className:`w-4 h-4`}),t(`profiles.login.useEmail`)]})})]})]})})}function Ue({label:e,value:t,options:n,onChange:r}){let[i,a]=(0,Y.useState)(!1),o=n.find(e=>e.value===t);return(0,Z.jsxs)(`div`,{className:`relative`,children:[(0,Z.jsxs)(`button`,{onClick:()=>a(!i),className:`flex items-center gap-2 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-sm text-white hover:border-bambu-gray-dark transition-colors`,children:[(0,Z.jsxs)(`span`,{className:`text-bambu-gray`,children:[e,`:`]}),(0,Z.jsx)(`span`,{children:o?.label||`All`}),(0,Z.jsx)(f,{className:`w-4 h-4 text-bambu-gray transition-transform ${i?`rotate-180`:``}`})]}),i&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>a(!1)}),(0,Z.jsx)(`div`,{className:`absolute top-full left-0 mt-1 min-w-[160px] bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl z-20 py-1 max-h-60 overflow-y-auto`,children:n.map(e=>(0,Z.jsxs)(`button`,{onClick:()=>{r(e.value),a(!1)},className:`w-full px-3 py-2 text-left text-sm flex items-center justify-between hover:bg-bambu-dark-tertiary transition-colors ${t===e.value?`text-bambu-green`:`text-white`}`,children:[(0,Z.jsx)(`span`,{children:e.label}),e.count!==void 0&&(0,Z.jsx)(`span`,{className:`text-bambu-gray text-xs`,children:e.count})]},e.value))})]})]})}function We(){let[e,t]=(0,Y.useState)(!1);return(0,Y.useEffect)(()=>{let e=()=>{t(window.scrollY>300)};return window.addEventListener(`scroll`,e),()=>window.removeEventListener(`scroll`,e)},[]),e?(0,Z.jsx)(`button`,{onClick:()=>{window.scrollTo({top:0,behavior:`smooth`})},className:`fixed bottom-24 right-6 p-3 bg-bambu-green hover:bg-bambu-green-light text-white rounded-full shadow-lg shadow-bambu-green/25 transition-all z-40`,"aria-label":`Scroll to top`,children:(0,Z.jsx)(u,{className:`w-5 h-5`})}):null}function Ge({setting:e,onClick:t,onDuplicate:n,compareMode:r,isCompareSelected:i,compareIndex:a,compareDisabled:o,t:s}){let c=Be(e.name),l=Ve(e.setting_id);return(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 group`,children:[(0,Z.jsx)(`button`,{onClick:t,disabled:o,className:`flex-1 text-left px-3 py-2 rounded transition-colors ${i?`bg-blue-500/20 border border-blue-500/50`:o?`bg-bambu-dark/50 opacity-40 cursor-not-allowed`:`bg-bambu-dark hover:bg-bambu-dark-tertiary`} ${r&&!o?`cursor-pointer`:``}`,children:(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[i&&a!==void 0&&(0,Z.jsx)(`span`,{className:`flex-shrink-0 w-5 h-5 rounded-full bg-blue-500 text-white text-xs flex items-center justify-center font-medium`,children:a+1}),!i&&l&&(0,Z.jsx)(`span`,{className:`flex-shrink-0 w-1.5 h-1.5 rounded-full bg-bambu-green`,title:s(`profiles.presets.myPreset`)}),(0,Z.jsx)(`span`,{className:`text-white text-sm truncate flex-1`,title:e.name,children:e.name}),c.filamentType&&e.type===`filament`&&(0,Z.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:c.filamentType}),c.layerHeight&&e.type===`process`&&(0,Z.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:c.layerHeight}),c.printer&&(0,Z.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:c.printer})]})}),(0,Z.jsx)(`button`,{onClick:e=>{e.stopPropagation(),n()},className:`can-hover:opacity-0 group-hover:opacity-100 focus-visible:opacity-100 text-bambu-gray hover:text-white transition-all p-1`,title:s(`profiles.presets.duplicate`),children:(0,Z.jsx)(g,{className:`w-4 h-4`})})]})}function Ke(e,t=0){let n=` `.repeat(t);if(e===null)return`null`;if(e===void 0)return`undefined`;if(typeof e==`string`){if(e.includes(`\\n`)||e.includes(` +import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,w as i}from"./client-DnySrlFv.js";import{n as a}from"./QueryClientProvider-Ce8_sN3w.js";import{t as o}from"./useQuery-BBCjCezC.js";import{t as s}from"./useMutation-B-Tr2hIP.js";import{t as c}from"./createLucideIcon-DvBYJlWL.js";import{t as l}from"./arrow-right-DedpIMhP.js";import{t as u}from"./arrow-up-D-pfJ3WZ.js";import{t as d}from"./check-Ck0cMLU4.js";import{a as f,i as p,r as m}from"./info-ROUoQhJR.js";import{n as h}from"./ToastContext-BRX0SW3C.js";import{t as g}from"./copy-Cu_0GKCU.js";import{t as _}from"./droplet-CqYXMF2u.js";import{t as v}from"./eye-off-6CkaxYwP.js";import{t as y}from"./funnel-C3dyAMK9.js";import{t as b}from"./gauge-D21zgWMb.js";import{t as x}from"./git-compare-J4KX0xAJ.js";import{t as S}from"./hard-drive-CgXAHN37.js";import{t as C}from"./list-CLcpeoSz.js";import{t as w}from"./loader-circle-BEmFtawu.js";import{t as T}from"./log-in-n0ckHxnD.js";import{t as E}from"./minus-DypeGjGR.js";import{t as ee}from"./search-0n0CBc74.js";import{t as te}from"./settings-2-Cvn837lh.js";import{t as D}from"./sparkles-DRqKNlhr.js";import{t as O}from"./sticky-note-BH0LPqRx.js";import{t as k}from"./triangle-alert-Dt_1FcBy.js";import{t as A}from"./x-DR-Trv6U.js";import{n as j,t as M}from"./Card-Bzc64K35.js";import{t as N}from"./Button-DDr6eAFy.js";import{u as P}from"./date-G9KUauqz.js";import{$t as F,At as I,Bt as L,Cn as R,Ct as ne,Dn as z,En as B,Jt as re,Kt as ie,Lt as V,On as ae,Rt as oe,Sn as H,Ut as U,Zt as se,an as W,cn as ce,kt as le,ln as G,wn as ue,yt as de}from"./index-Cxa-KVmA.js";import{p as K,u as q}from"./utils-subfXwl6.js";import{t as fe}from"./useCancellableTimeout-3XQzNJkJ.js";var J=c(`equal`,[[`line`,{x1:`5`,x2:`19`,y1:`9`,y2:`9`,key:`1nwqeh`}],[`line`,{x1:`5`,x2:`19`,y1:`15`,y2:`15`,key:`g8yjpy`}]]),pe=c(`sliders-vertical`,[[`path`,{d:`M10 8h4`,key:`1sr2af`}],[`path`,{d:`M12 21v-9`,key:`17s77i`}],[`path`,{d:`M12 8V3`,key:`13r4qs`}],[`path`,{d:`M17 16h4`,key:`h1uq16`}],[`path`,{d:`M19 12V3`,key:`o1uvq1`}],[`path`,{d:`M19 21v-5`,key:`qua636`}],[`path`,{d:`M3 14h4`,key:`bcjad9`}],[`path`,{d:`M5 10V3`,key:`cb8scm`}],[`path`,{d:`M5 21v-7`,key:`1w1uti`}]]),Y=e(n(),1),X={PLA:`GFL99`,"PLA-CF":`GFL98`,"PLA SILK":`GFL96`,"PLA HIGH SPEED":`GFL95`,PETG:`GFG99`,"PETG HF":`GFG96`,"PETG-CF":`GFG98`,PCTG:`GFG97`,ABS:`GFB99`,ASA:`GFB98`,PC:`GFC99`,PA:`GFN99`,"PA-CF":`GFN98`,NYLON:`GFN99`,TPU:`GFU99`,PVA:`GFS99`,HIPS:`GFS98`,PE:`GFP99`,PP:`GFP97`};function me(e){let t=(e||``).toUpperCase().trim();return t&&(X[t]||X[t.replace(/[-\s]?CF$/,``)]||X[t.replace(/\+$/,``)]||X[t.split(/[-\s]/)[0]])||``}function he(e){let t=e.replace(/@.+$/,``).trim();return t.startsWith(`# `)?t.slice(2).trim():t}var ge={local:0,orca_cloud:1,cloud:2,builtin:3};function _e(e){let{localPresets:t,orcaProfiles:n,cloudSettings:r,builtinFilaments:i}=e,a=[],o=e=>e.trim().toLowerCase(),s=new Set,c=new Set,l=new Set,u=(e,t,...n)=>{let r=n.filter(e=>!!e);if(r.some(e=>s.has(e)))return!1;let i=`${e}|${o(t)}`;return c.has(i)?!1:(r.forEach(e=>s.add(e)),c.add(i),l.add(o(t)),!0)};for(let e of t??[]){let t=he(e.name),n=e.filament_type||q(t).material;u(`local`,t)&&a.push({id:`local_${e.id}`,name:t,source:`local`,filamentId:me(n),filamentType:n||``})}for(let e of n??[]){let t=he(e.name),n=q(t).material;u(`orca_cloud`,t,e.setting_id)&&a.push({id:`orca_${e.setting_id}`,name:t,source:`orca_cloud`,filamentId:me(n),filamentType:n})}for(let e of r??[]){let t=he(e.name),n=e.setting_id.startsWith(`GFS`)?K(e.setting_id):``;u(`cloud`,t,e.setting_id,n||void 0)&&a.push({id:e.setting_id,name:t,source:`cloud`,filamentId:n,filamentType:q(t).material})}for(let e of i??[]){let t=e.filament_id.startsWith(`GF`)?`GFS${e.filament_id.slice(2)}`:e.filament_id;l.has(o(e.name))||u(`builtin`,e.name,e.filament_id,t)&&a.push({id:`builtin_${e.filament_id}`,name:e.name,source:`builtin`,filamentId:e.filament_id,filamentType:q(e.name).material})}return a.sort((e,t)=>e.source===t.source?e.name.localeCompare(t.name):ge[e.source]-ge[t.source])}async function ve(e,t){if(e.filamentId)return e.filamentId;if(e.source!==`cloud`||!t)return``;try{return(await t(e.id)).filament_id||``}catch{return``}}var Z=t(),ye=e=>(Math.trunc(parseFloat(e)*1e3)/1e3).toFixed(3),be=`HS00`,xe=`HH00`,Se=e=>{let t=e.match(/^([A-Z]{2}\d{2})/);return t?t[1]:be},Q=e=>Se(e)===xe?`HF`:`S`,Ce=e=>{for(let t of[`High Flow_`,`High Flow `,`Standard_`,`Standard `,`HF_`,`HF `,`S_`,`S `])if(e.startsWith(t))return e.slice(t.length);let t=e.indexOf(`_`);return t>0?e.slice(t+1):e};function we({profile:e,onEdit:t,onCopy:n,selectionMode:r,isSelected:i,onToggleSelect:a,note:o}){let s=Q(e.nozzle_id),c=e.nozzle_diameter;return(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[r&&(0,Z.jsx)(`button`,{onClick:a,className:`text-bambu-gray hover:text-white transition-colors p-1`,children:i?(0,Z.jsx)(oe,{className:`w-4 h-4 text-bambu-green`}):(0,Z.jsx)(V,{className:`w-4 h-4`})}),(0,Z.jsxs)(`button`,{onClick:()=>{r&&a?a():t()},className:`flex-1 text-left px-3 py-2 bg-bambu-dark rounded hover:bg-bambu-dark-tertiary transition-colors ${i?`ring-1 ring-bambu-green`:``}`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`span`,{className:`text-bambu-green font-mono text-sm font-bold whitespace-nowrap`,children:ye(e.k_value)}),(0,Z.jsx)(`span`,{className:`text-white text-sm truncate flex-1`,title:e.name,children:e.name||`Unnamed`}),o&&(0,Z.jsx)(`span`,{title:`Has note`,children:(0,Z.jsx)(O,{className:`w-3 h-3 text-yellow-500`})}),(0,Z.jsxs)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:[s,` `,c]})]}),o&&(0,Z.jsxs)(`div`,{className:`text-xs mt-0.5 truncate text-yellow-500/70`,title:o,children:[`Note: `,o.length>50?o.substring(0,50)+`...`:o]})]}),!r&&n&&(0,Z.jsx)(`button`,{onClick:e=>{e.stopPropagation(),n()},className:`text-bambu-gray hover:text-white transition-colors p-1`,title:`Copy profile`,children:(0,Z.jsx)(g,{className:`w-4 h-4`})})]})}function Te({profile:e,printerId:t,nozzleDiameter:n,existingProfiles:a=[],builtinFilaments:o=[],filamentPresets:c=[],isDualNozzle:l=!1,supportsFlowType:u=!0,initialNote:d=``,initialNoteKey:f=null,onClose:p,onSave:m,onSaveNote:g,hasPermission:_}){let{t:v}=i(),{showToast:y}=h(),[x,S]=(0,Y.useState)(e?.name||``),[C,T]=(0,Y.useState)(e?.k_value?ye(e.k_value):`0.020`),[E,te]=(0,Y.useState)(e?.filament_id||``),[D,O]=(0,Y.useState)(e?Se(e.nozzle_id):be),[k,P]=(0,Y.useState)(e?.nozzle_diameter||n),[F,L]=(0,Y.useState)(e?[e.extruder_id]:l?[0,1]:[0]),[R,ne]=(0,Y.useState)(!1),[z,B]=(0,Y.useState)({current:0,total:0}),[re,ie]=(0,Y.useState)(d),[V,ae]=(0,Y.useState)(``),{schedule:oe}=fe(),H=Y.useMemo(()=>e?.filament_id?o.find(t=>t.filament_id===e.filament_id)?.name||Ce(a.find(t=>t.filament_id===e.filament_id)?.name||e.name||``)||e.filament_id:``,[e,a,o]),U=Y.useMemo(()=>{let e=[[`local`,v(`kProfiles.modal.source.local`)],[`orca_cloud`,v(`kProfiles.modal.source.orcaCloud`)],[`cloud`,v(`kProfiles.modal.source.bambuCloud`)],[`builtin`,v(`kProfiles.modal.source.builtin`)]],t=V.trim().toLowerCase(),n=t?c.filter(e=>e.name.toLowerCase().includes(t)):c;return e.map(([e,t])=>({source:e,label:t,items:n.filter(t=>t.source===e)})).filter(e=>e.items.length>0)},[c,V,v]),se=s({mutationFn:e=>(console.log(`[KProfile] Calling API...`),r.setKProfile(t,e)),onSuccess:(t,n)=>{if(console.log(`[KProfile] Save success:`,t),y(v(`kProfiles.toast.profileSaved`)),g&&re!==d){let t;t=re===``&&f?f:e&&e.slot_id>0?e.setting_id||`slot_${e.slot_id}_${e.filament_id}_${e.extruder_id}`:`name_${x}_${n.filament_id}`,g(t,re)}ne(!0),oe(()=>{ne(!1),m()},2500)},onError:e=>{console.error(`[KProfile] Save error:`,e),y(e.message,`error`),ne(!1)}}),W=s({mutationFn:e=>(console.log(`[KProfile] Deleting profile...`),r.deleteKProfile(t,e)),onSuccess:e=>{console.log(`[KProfile] Delete success:`,e),y(v(`kProfiles.toast.profileDeleted`)),ne(!0),oe(()=>{ne(!1),p()},4e3)},onError:e=>{console.error(`[KProfile] Delete error:`,e),y(e.message,`error`),ne(!1)}}),[ce,le]=(0,Y.useState)(!1),G=()=>{e&&W.mutate({slot_id:e.slot_id,extruder_id:e.extruder_id,nozzle_id:e.nozzle_id,nozzle_diameter:e.nozzle_diameter,filament_id:e.filament_id,setting_id:e.setting_id})};return(0,Z.jsxs)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,children:[(0,Z.jsxs)(M,{className:`w-full max-w-md relative`,children:[R&&(0,Z.jsxs)(`div`,{className:`absolute inset-0 bg-bambu-dark-secondary/90 flex flex-col items-center justify-center z-10 rounded-lg`,children:[(0,Z.jsx)(w,{className:`w-8 h-8 text-bambu-green animate-spin mb-3`}),(0,Z.jsx)(`p`,{className:`text-white font-medium`,children:z.total>1?v(`kProfiles.modal.savingExtruder`,{current:z.current,total:z.total}):v(`kProfiles.modal.syncing`)}),(0,Z.jsx)(`p`,{className:`text-bambu-gray text-sm mt-1`,children:v(`kProfiles.modal.pleaseWait`)})]}),(0,Z.jsxs)(j,{className:`p-0`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,Z.jsx)(`h2`,{className:`text-xl font-semibold text-white`,children:v(e?`kProfiles.modal.editTitle`:`kProfiles.modal.addTitle`)}),(0,Z.jsx)(`button`,{onClick:p,className:`text-bambu-gray hover:text-white transition-colors`,disabled:R,children:(0,Z.jsx)(A,{className:`w-5 h-5`})})]}),(0,Z.jsxs)(`form`,{onSubmit:async n=>{if(n.preventDefault(),l&&!e&&F.length===0){y(v(`kProfiles.toast.selectAtLeastOneExtruder`),`error`);return}let i=parseFloat(C).toFixed(6),a=`${D}-${k}`,o=e&&e.nozzle_id||a,s=e?e.nozzle_diameter:k,u=e?.filament_id||``;if(!e){let e=c.find(e=>e.id===E);if(!e){y(v(`kProfiles.toast.selectFilament`),`error`);return}if(u=await ve(e,r.getCloudSettingDetail),!u){y(v(`kProfiles.toast.filamentNotResolvable`,{name:e.name}),`error`);return}}if(e||F.length===1){let t={name:x,k_value:i,filament_id:u,nozzle_id:o,nozzle_diameter:s,extruder_id:e?e.extruder_id:F[0],setting_id:e?.setting_id,slot_id:e?.slot_id??0};console.log(`[KProfile] Saving profile:`,t),se.mutate(t);return}ne(!0),B({current:1,total:F.length});let d=F.map(e=>({name:x,k_value:i,filament_id:u,nozzle_id:a,nozzle_diameter:k,extruder_id:e,setting_id:void 0,slot_id:0}));console.log(`[KProfile] Saving ${d.length} profiles in batch:`,d);try{await r.setKProfilesBatch(t,d),y(v(`kProfiles.toast.profilesSaved`,{count:F.length})),g&&re&&g(`name_${x}_${u}`,re)}catch(e){console.error(`[KProfile] Failed to save batch:`,e),y(v(`kProfiles.toast.failedToSaveBatch`),`error`),ne(!1),B({current:0,total:0});return}B({current:F.length,total:F.length}),oe(()=>{ne(!1),B({current:0,total:0}),m()},3e3)},className:`p-4 space-y-4`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:v(`kProfiles.modal.profileName`)}),(0,Z.jsx)(`input`,{type:`text`,value:x,onChange:e=>S(e.target.value),disabled:!!e,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none ${e?`opacity-60 cursor-not-allowed`:``}`,placeholder:v(`kProfiles.modal.profileNamePlaceholder`),required:!e})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:v(`kProfiles.modal.kValue`)}),(0,Z.jsx)(`input`,{type:`text`,inputMode:`decimal`,value:C,onChange:e=>{let t=e.target.value;(t===``||/^\d*\.?\d*$/.test(t))&&T(t)},onBlur:e=>{let t=parseFloat(e.target.value);isNaN(t)||T((Math.trunc(t*1e3)/1e3).toFixed(3))},className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none font-mono`,placeholder:v(`kProfiles.modal.kValuePlaceholder`),required:!0}),(0,Z.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:v(`kProfiles.modal.kValueHelp`)})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:v(`kProfiles.modal.filament`)}),e?(0,Z.jsx)(`div`,{className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white opacity-60`,children:H||e.filament_id}):(0,Z.jsxs)(`div`,{className:`border border-bambu-dark-tertiary rounded-lg overflow-hidden`,children:[(0,Z.jsxs)(`div`,{className:`relative border-b border-bambu-dark-tertiary`,children:[(0,Z.jsx)(ee,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,Z.jsx)(`input`,{type:`text`,value:V,onChange:e=>ae(e.target.value),placeholder:v(`kProfiles.modal.searchFilaments`),className:`w-full pl-10 pr-3 py-2 bg-bambu-dark text-white placeholder-bambu-gray focus:outline-none`})]}),(0,Z.jsx)(`div`,{className:`max-h-56 overflow-y-auto bg-bambu-dark`,children:U.length===0?(0,Z.jsx)(`p`,{className:`px-3 py-3 text-xs text-bambu-gray`,children:c.length===0?v(`kProfiles.modal.noFilamentsHelp`):v(`kProfiles.modal.noFilamentMatches`)}):U.map(e=>(0,Z.jsxs)(`div`,{children:[(0,Z.jsxs)(`div`,{className:`sticky top-0 z-10 flex items-center gap-2 px-3 py-1.5 bg-bambu-dark-secondary border-y border-bambu-dark-tertiary`,children:[(0,Z.jsx)(`span`,{className:`text-xs font-bold uppercase tracking-wider text-bambu-green`,children:e.label}),(0,Z.jsx)(`span`,{className:`text-[10px] text-bambu-gray`,children:e.items.length})]}),e.items.map(e=>(0,Z.jsx)(`button`,{type:`button`,onClick:()=>{te(e.id),x||S(`${D===xe?`HF`:`S`} ${e.name}`)},className:`w-full text-left px-3 py-1.5 text-sm transition-colors ${E===e.id?`bg-bambu-green/20 text-white`:`text-white hover:bg-bambu-dark-tertiary`}`,children:e.name},e.id))]},e.source))})]})]}),(0,Z.jsxs)(`div`,{className:u?`grid grid-cols-2 gap-4`:``,children:[(0,Z.jsxs)(`div`,{className:u?``:`hidden`,children:[(0,Z.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:v(`kProfiles.modal.flowType`)}),(0,Z.jsxs)(`select`,{value:D,onChange:t=>{let n=t.target.value;if(O(n),!e&&E&&!x){let e=c.find(e=>e.id===E);e&&S(`${n===xe?`HF`:`S`} ${e.name}`)}},disabled:!!e,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none ${e?`opacity-60 cursor-not-allowed`:``}`,children:[(0,Z.jsx)(`option`,{value:xe,children:v(`kProfiles.modal.highFlow`)}),(0,Z.jsx)(`option`,{value:be,children:v(`kProfiles.modal.standard`)})]})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:v(`kProfiles.modal.nozzleSize`)}),(0,Z.jsxs)(`select`,{value:k,onChange:e=>P(e.target.value),disabled:!!e,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none ${e?`opacity-60 cursor-not-allowed`:``}`,children:[(0,Z.jsx)(`option`,{value:`0.2`,children:`0.2mm`}),(0,Z.jsx)(`option`,{value:`0.4`,children:`0.4mm`}),(0,Z.jsx)(`option`,{value:`0.6`,children:`0.6mm`}),(0,Z.jsx)(`option`,{value:`0.8`,children:`0.8mm`})]})]})]}),l&&(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:v(e?`kProfiles.modal.extruder`:`kProfiles.modal.extruders`)}),e?(0,Z.jsx)(`div`,{className:`px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white opacity-60`,children:e.extruder_id===1?v(`kProfiles.modal.left`):v(`kProfiles.modal.right`)}):(0,Z.jsxs)(`div`,{className:`flex gap-4`,children:[(0,Z.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,checked:F.includes(1),onChange:e=>{e.target.checked?L([...F,1]):L(F.filter(e=>e!==1))},className:`w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green focus:ring-offset-0 accent-bambu-green`}),(0,Z.jsx)(`span`,{className:`text-white`,children:v(`kProfiles.modal.left`)})]}),(0,Z.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,checked:F.includes(0),onChange:e=>{e.target.checked?L([...F,0]):L(F.filter(e=>e!==0))},className:`w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green focus:ring-offset-0 accent-bambu-green`}),(0,Z.jsx)(`span`,{className:`text-white`,children:v(`kProfiles.modal.right`)})]})]})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:v(`kProfiles.modal.notes`)}),(0,Z.jsx)(`textarea`,{value:re,onChange:e=>ie(e.target.value),placeholder:v(`kProfiles.modal.notesPlaceholder`),rows:2,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none resize-none`}),(0,Z.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:v(`kProfiles.modal.notesHelp`)})]}),(0,Z.jsxs)(`div`,{className:`flex gap-2 pt-4`,children:[e&&(0,Z.jsx)(N,{type:`button`,variant:`secondary`,onClick:()=>le(!0),disabled:W.isPending||R||!_(`kprofiles:delete`),title:_(`kprofiles:delete`)?void 0:v(`kProfiles.permission.noDelete`),className:`text-red-500 hover:bg-red-500/10`,children:W.isPending?(0,Z.jsx)(w,{className:`w-4 h-4 animate-spin`}):(0,Z.jsx)(I,{className:`w-4 h-4`})}),(0,Z.jsx)(N,{type:`button`,variant:`secondary`,onClick:p,disabled:R,className:`flex-1`,children:v(`common.cancel`)}),(0,Z.jsxs)(N,{type:`submit`,disabled:se.isPending||R||!_(e?`kprofiles:update`:`kprofiles:create`),title:_(e?`kprofiles:update`:`kprofiles:create`)?void 0:v(e?`kProfiles.permission.noUpdate`:`kProfiles.permission.noCreate`),className:`flex-1`,children:[se.isPending?(0,Z.jsx)(w,{className:`w-4 h-4 animate-spin`}):(0,Z.jsx)(b,{className:`w-4 h-4`}),v(`common.save`)]})]})]})]})]}),ce&&(0,Z.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-[60]`,children:(0,Z.jsx)(M,{className:`w-full max-w-sm`,children:(0,Z.jsxs)(j,{className:`p-6`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-3 mb-4`,children:[(0,Z.jsx)(`div`,{className:`w-10 h-10 rounded-full bg-red-500/20 flex items-center justify-center`,children:(0,Z.jsx)(I,{className:`w-5 h-5 text-red-500`})}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`h3`,{className:`text-lg font-semibold text-white`,children:v(`kProfiles.deleteConfirm.title`)}),(0,Z.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:v(`kProfiles.deleteConfirm.cannotUndo`)})]})]}),(0,Z.jsx)(`p`,{className:`text-bambu-gray mb-6`,children:v(`kProfiles.deleteConfirm.message`,{name:e?.name})}),(0,Z.jsxs)(`div`,{className:`flex gap-3`,children:[(0,Z.jsx)(N,{variant:`secondary`,onClick:()=>le(!1),className:`flex-1`,children:v(`common.cancel`)}),(0,Z.jsxs)(N,{onClick:()=>{le(!1),G()},disabled:W.isPending,className:`flex-1 bg-red-500 hover:bg-red-600 text-white`,children:[W.isPending?(0,Z.jsx)(w,{className:`w-4 h-4 animate-spin`}):(0,Z.jsx)(I,{className:`w-4 h-4`}),v(`common.delete`)]})]})]})})})]})}var Ee={NOZZLE_DIAMETER:`bambusy_kprofiles_nozzle`,SORT_OPTION:`bambusy_kprofiles_sort`};function De(){let{t:e}=i(),{showToast:t}=h(),{hasPermission:n}=de(),[a,s]=(0,Y.useState)(null),[c,l]=(0,Y.useState)(()=>localStorage.getItem(Ee.NOZZLE_DIAMETER)||`0.4`),[u,d]=(0,Y.useState)(null),[f,p]=(0,Y.useState)(!1),[g,_]=(0,Y.useState)(null),[v,y]=(0,Y.useState)(``),[x,S]=(0,Y.useState)(`all`),[C,T]=(0,Y.useState)(`all`),[E,te]=(0,Y.useState)(()=>localStorage.getItem(Ee.SORT_OPTION)||`name`),[D,O]=(0,Y.useState)(!1),[k,P]=(0,Y.useState)(new Set),[F,L]=(0,Y.useState)(!1),[R,z]=(0,Y.useState)(!1),B=(0,Y.useCallback)(e=>`${e.slot_id}_${e.extruder_id}`,[]);(0,Y.useEffect)(()=>{localStorage.setItem(Ee.NOZZLE_DIAMETER,c)},[c]),(0,Y.useEffect)(()=>{localStorage.setItem(Ee.SORT_OPTION,E)},[E]);let{data:V,isLoading:ae}=o({queryKey:[`printers`],queryFn:r.getPrinters}),{data:H,isLoading:U,isFetching:W,error:ce,refetch:G}=o({queryKey:[`kprofiles`,a,c],queryFn:async()=>{console.log(`[KProfiles] Fetching profiles for printer`,a,`nozzle`,c);let e=await r.getKProfiles(a,c);return console.log(`[KProfiles] Received profiles:`,e?.profiles?.length||0,`profiles`),e},enabled:!!a,retry:!1,staleTime:0,gcTime:0,refetchOnMount:`always`}),{data:K}=o({queryKey:[`builtinFilaments`],queryFn:()=>r.getBuiltinFilaments(),staleTime:3e5}),{data:q}=o({queryKey:[`filamentIdMap`],queryFn:()=>r.getFilamentIdMap(),staleTime:3e5}),{data:fe}=o({queryKey:[`localPresets`],queryFn:()=>r.getLocalPresets(),retry:!1}),{data:J}=o({queryKey:[`orcaCloudProfilesForKProfiles`],queryFn:()=>r.orcaCloudListProfiles(),retry:!1}),{data:pe}=o({queryKey:[`cloudSettings`],queryFn:()=>r.getCloudSettings(),retry:!1}),{data:X,refetch:me}=o({queryKey:[`kprofile-notes`,a],queryFn:()=>r.getKProfileNotes(a),enabled:!!a,staleTime:3e4}),he=ce?.message?.includes(`not connected`);(0,Y.useEffect)(()=>{if(!a&&V&&V.length>0){let e=V.find(e=>e.is_active);e&&s(e.id)}},[a,V]),(0,Y.useEffect)(()=>{if(a){let e=setTimeout(()=>{G()},150);return()=>clearTimeout(e)}},[a,c]);let ge=V?.filter(e=>e.is_active)||[],ve=Y.useMemo(()=>{let e=new Map;if(K)for(let t of K)e.set(t.filament_id,t.name);if(q)for(let[t,n]of Object.entries(q))e.has(t)||e.set(t,n);return e},[K,q]),ye=Y.useMemo(()=>Array.from(ve.entries()).map(([e,t])=>({filament_id:e,name:t})),[ve]),xe=Y.useMemo(()=>_e({localPresets:fe?.filament,orcaProfiles:J?.filament,cloudSettings:pe?.filament,builtinFilaments:K}),[fe?.filament,J?.filament,pe?.filament,K]),Se=Y.useCallback(e=>ve.get(e.filament_id)||Ce(e.name),[ve]),Q=Y.useMemo(()=>H?.profiles?H.profiles.filter(e=>{let t=v.toLowerCase(),n=!t||e.name.toLowerCase().includes(t)||e.filament_id.toLowerCase().includes(t),r=x===`all`||x===`left`&&e.extruder_id===1||x===`right`&&e.extruder_id===0,i=C===`all`||C===`hf`&&e.nozzle_id.startsWith(`HH`)||C===`s`&&e.nozzle_id.startsWith(`HS`);return n&&r&&i}).sort((e,t)=>{switch(E){case`k_value`:return parseFloat(e.k_value)-parseFloat(t.k_value);case`filament`:return Se(e).localeCompare(Se(t));default:return e.name.localeCompare(t.name)}}):[],[H?.profiles,v,x,C,E,Se]),De=V?.find(e=>e.id===a),$=De?.nozzle_count===2,Oe=De?.supports_nozzle_flow_type??!0;(0,Y.useEffect)(()=>{Oe||T(`all`)},[Oe]),(0,Y.useEffect)(()=>{let e=e=>{e.target instanceof HTMLInputElement||e.target instanceof HTMLTextAreaElement||e.target instanceof HTMLSelectElement||u||f||g||(e.key===`r`||e.key===`R`?(e.preventDefault(),G()):e.key===`n`||e.key===`N`?(e.preventDefault(),p(!0)):e.key===`Escape`&&D&&(e.preventDefault(),O(!1),P(new Set)))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[u,f,g,D,G]);let ke=(0,Y.useCallback)(()=>{if(!H?.profiles||H.profiles.length===0){t(e(`kProfiles.toast.noProfilesToExport`),`error`);return}let n={version:1,exported_at:new Date().toISOString(),printer:De?.name||`Unknown`,nozzle_diameter:c,profiles:H.profiles.map(e=>({name:e.name,k_value:e.k_value,filament_id:e.filament_id,nozzle_id:e.nozzle_id,nozzle_diameter:e.nozzle_diameter,extruder_id:e.extruder_id}))},r=new Blob([JSON.stringify(n,null,2)],{type:`application/json`}),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=`kprofiles_${De?.name||`printer`}_${c}mm_${new Date().toISOString().split(`T`)[0]}.json`,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(i),t(e(`kProfiles.toast.exportedProfiles`,{count:H.profiles.length}))},[H?.profiles,De,c,t,e]),Ae=(0,Y.useCallback)(()=>{let n=document.createElement(`input`);n.type=`file`,n.accept=`.json`,n.onchange=async n=>{let i=n.target.files?.[0];if(i)try{let n=await i.text(),o=JSON.parse(n);if(!o.profiles||!Array.isArray(o.profiles)){t(e(`kProfiles.toast.invalidFileFormat`),`error`);return}let s=0;for(let e of o.profiles)if(!(!e.name||!e.k_value||!e.filament_id))try{await r.setKProfile(a,{name:e.name,k_value:parseFloat(e.k_value).toFixed(6),filament_id:e.filament_id,nozzle_id:e.nozzle_id||`${be}-${c}`,nozzle_diameter:e.nozzle_diameter||c,extruder_id:e.extruder_id??0,slot_id:0}),s++,await new Promise(e=>setTimeout(e,500))}catch(t){console.error(`Failed to import profile:`,e.name,t)}t(e(`kProfiles.toast.importedProfiles`,{count:s,total:o.profiles.length})),G()}catch(n){console.error(`Import error:`,n),t(e(`kProfiles.toast.failedToParseImport`),`error`)}},n.click()},[a,c,t,G,e]),je=(0,Y.useCallback)(e=>{P(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),Me=(0,Y.useCallback)(()=>{P(new Set(Q.map(e=>B(e))))},[Q,B]),Ne=(0,Y.useCallback)(()=>{k.size!==0&&L(!0)},[k.size]),Pe=(0,Y.useCallback)(async()=>{let n=Q.filter(e=>k.has(B(e)));z(!0);let i=0;for(let e of n)try{await r.deleteKProfile(a,{slot_id:e.slot_id,extruder_id:e.extruder_id,nozzle_id:e.nozzle_id,nozzle_diameter:e.nozzle_diameter,filament_id:e.filament_id,setting_id:e.setting_id}),i++,await new Promise(e=>setTimeout(e,300))}catch(t){console.error(`Failed to delete profile:`,e.name,t)}t(e(`kProfiles.toast.profilesDeleted`,{count:i})),z(!1),L(!1),O(!1),P(new Set),G()},[a,k,Q,t,G,B,e]),Fe=(0,Y.useCallback)(e=>{let t=[];return e.setting_id&&t.push(e.setting_id),t.push(`slot_${e.slot_id}_${e.filament_id}_${e.extruder_id}`),t.push(`name_${e.name}_${e.filament_id}`),t},[]),Ie=(0,Y.useCallback)(async(n,i)=>{if(a)try{await r.setKProfileNote(a,n,i),me()}catch(n){console.error(`Failed to save note:`,n),t(e(`kProfiles.toast.failedToSaveNote`),`error`)}},[a,me,t,e]),Le=(0,Y.useCallback)(e=>{if(!X?.notes)return{note:``,key:null};let t=Fe(e);for(let e of t)if(X.notes[e])return{note:X.notes[e],key:e};return{note:``,key:null}},[X,Fe]),Re=(0,Y.useCallback)(e=>Le(e).note,[Le]);return ae?(0,Z.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,Z.jsx)(w,{className:`w-8 h-8 text-bambu-green animate-spin`})}):!V||V.length===0?(0,Z.jsx)(M,{children:(0,Z.jsxs)(j,{className:`py-12 text-center`,children:[(0,Z.jsx)(m,{className:`w-12 h-12 text-bambu-gray mx-auto mb-4`}),(0,Z.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-2`,children:e(`kProfiles.noPrintersConfigured`)}),(0,Z.jsx)(`p`,{className:`text-bambu-gray`,children:e(`kProfiles.addPrinterInSettings`)})]})}):ge.length===0?(0,Z.jsx)(M,{children:(0,Z.jsxs)(j,{className:`py-12 text-center`,children:[(0,Z.jsx)(re,{className:`w-12 h-12 text-bambu-gray mx-auto mb-4`}),(0,Z.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-2`,children:e(`kProfiles.noActivePrinters`)}),(0,Z.jsx)(`p`,{className:`text-bambu-gray`,children:e(`kProfiles.enablePrinterConnection`)})]})}):(0,Z.jsxs)(Z.Fragment,{children:[W&&!U&&(0,Z.jsxs)(`div`,{className:`fixed inset-0 bg-black/50 flex flex-col items-center justify-center z-40`,children:[(0,Z.jsx)(w,{className:`w-10 h-10 text-bambu-green animate-spin mb-3`}),(0,Z.jsx)(`p`,{className:`text-white font-medium`,children:e(`kProfiles.loadingProfiles`)})]}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap gap-4 mb-6`,children:[(0,Z.jsxs)(`div`,{className:`flex-1 min-w-48`,children:[(0,Z.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:e(`kProfiles.printer`)}),(0,Z.jsx)(`select`,{value:a||``,onChange:e=>s(parseInt(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`,children:ge.map(e=>(0,Z.jsx)(`option`,{value:e.id,children:e.name},e.id))})]}),(0,Z.jsxs)(`div`,{className:`w-32`,children:[(0,Z.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:e(`kProfiles.nozzle`)}),(0,Z.jsxs)(`select`,{value:c,onChange:e=>l(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`,children:[(0,Z.jsx)(`option`,{value:`0.2`,children:`0.2mm`}),(0,Z.jsx)(`option`,{value:`0.4`,children:`0.4mm`}),(0,Z.jsx)(`option`,{value:`0.6`,children:`0.6mm`}),(0,Z.jsx)(`option`,{value:`0.8`,children:`0.8mm`})]})]}),(0,Z.jsxs)(`div`,{className:`flex items-end gap-2`,children:[(0,Z.jsxs)(N,{variant:`secondary`,onClick:()=>G(),disabled:W||!n(`kprofiles:read`),title:n(`kprofiles:read`)?void 0:e(`kProfiles.permission.noRead`),children:[(0,Z.jsx)(ie,{className:`w-4 h-4 ${W?`animate-spin`:``}`}),e(`kProfiles.refresh`)]}),(0,Z.jsxs)(N,{onClick:()=>p(!0),disabled:!n(`kprofiles:create`),title:n(`kprofiles:create`)?void 0:e(`kProfiles.permission.noCreate`),children:[(0,Z.jsx)(se,{className:`w-4 h-4`}),e(`kProfiles.addProfile`)]})]})]}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap gap-4 mb-4`,children:[(0,Z.jsxs)(`div`,{className:`flex-1 min-w-48 relative`,children:[(0,Z.jsx)(ee,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,Z.jsx)(`input`,{type:`text`,value:v,onChange:e=>y(e.target.value),placeholder:e(`kProfiles.searchPlaceholder`),className:`w-full pl-10 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),$&&(0,Z.jsx)(`div`,{className:`w-36`,children:(0,Z.jsxs)(`select`,{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 focus:border-bambu-green focus:outline-none`,children:[(0,Z.jsx)(`option`,{value:`all`,children:e(`kProfiles.allExtruders`)}),(0,Z.jsx)(`option`,{value:`left`,children:e(`kProfiles.leftOnly`)}),(0,Z.jsx)(`option`,{value:`right`,children:e(`kProfiles.rightOnly`)})]})}),Oe&&(0,Z.jsx)(`div`,{className:`w-32`,children:(0,Z.jsxs)(`select`,{value:C,onChange:e=>T(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`,children:[(0,Z.jsx)(`option`,{value:`all`,children:e(`kProfiles.allFlow`)}),(0,Z.jsx)(`option`,{value:`hf`,children:e(`kProfiles.hfOnly`)}),(0,Z.jsx)(`option`,{value:`s`,children:e(`kProfiles.sOnly`)})]})}),(0,Z.jsx)(`div`,{className:`w-32`,children:(0,Z.jsxs)(`select`,{value:E,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 focus:border-bambu-green focus:outline-none`,children:[(0,Z.jsx)(`option`,{value:`name`,children:e(`kProfiles.sortName`)}),(0,Z.jsx)(`option`,{value:`k_value`,children:e(`kProfiles.sortKValue`)}),(0,Z.jsx)(`option`,{value:`filament`,children:e(`kProfiles.sortFilament`)})]})})]}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap gap-2 mb-6`,children:[(0,Z.jsxs)(N,{variant:`secondary`,onClick:ke,disabled:!H?.profiles?.length||!n(`kprofiles:read`),title:n(`kprofiles:read`)?void 0:e(`kProfiles.permission.noExport`),children:[(0,Z.jsx)(ue,{className:`w-4 h-4`}),e(`kProfiles.export`)]}),(0,Z.jsxs)(N,{variant:`secondary`,onClick:Ae,disabled:!n(`kprofiles:create`),title:n(`kprofiles:create`)?void 0:e(`kProfiles.permission.noImport`),children:[(0,Z.jsx)(le,{className:`w-4 h-4`}),e(`kProfiles.import`)]}),(0,Z.jsx)(`div`,{className:`flex-1`}),D?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(N,{variant:`secondary`,onClick:Me,children:[(0,Z.jsx)(oe,{className:`w-4 h-4`}),e(`kProfiles.selectAll`)]}),(0,Z.jsxs)(N,{variant:`secondary`,onClick:Ne,disabled:k.size===0||!n(`kprofiles:delete`),className:`text-red-500 hover:bg-red-500/10`,title:n(`kprofiles:delete`)?void 0:e(`kProfiles.permission.noDelete`),children:[(0,Z.jsx)(I,{className:`w-4 h-4`}),e(`kProfiles.delete`),` (`,k.size,`)`]}),(0,Z.jsxs)(N,{variant:`secondary`,onClick:()=>{O(!1),P(new Set)},children:[(0,Z.jsx)(A,{className:`w-4 h-4`}),e(`common.cancel`)]})]}):(0,Z.jsxs)(N,{variant:`secondary`,onClick:()=>O(!0),disabled:!Q.length||!n(`kprofiles:delete`),title:n(`kprofiles:delete`)?void 0:e(`kProfiles.permission.noDelete`),children:[(0,Z.jsx)(oe,{className:`w-4 h-4`}),e(`kProfiles.select`)]})]}),U?(0,Z.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,Z.jsx)(w,{className:`w-8 h-8 text-bambu-green animate-spin`})}):he?(0,Z.jsx)(M,{children:(0,Z.jsxs)(j,{className:`py-12 text-center`,children:[(0,Z.jsx)(ne,{className:`w-12 h-12 text-bambu-gray mx-auto mb-4`}),(0,Z.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-2`,children:e(`kProfiles.printerOffline`)}),(0,Z.jsx)(`p`,{className:`text-bambu-gray mb-4`,children:e(`kProfiles.printerOfflineDesc`)}),(0,Z.jsxs)(N,{variant:`secondary`,onClick:()=>G(),children:[(0,Z.jsx)(ie,{className:`w-4 h-4`}),e(`common.refresh`)]})]})}):Q.length>0?$?(0,Z.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`h3`,{className:`text-sm font-medium text-bambu-gray mb-2 px-1`,children:e(`kProfiles.leftExtruder`)}),(0,Z.jsx)(`div`,{className:`space-y-1`,children:Q.filter(e=>e.extruder_id===1).map(e=>(0,Z.jsx)(we,{profile:e,onEdit:()=>d(e),onCopy:()=>_(e),selectionMode:D,isSelected:k.has(B(e)),onToggleSelect:()=>je(B(e)),note:Re(e)},B(e)))})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`h3`,{className:`text-sm font-medium text-bambu-gray mb-2 px-1`,children:e(`kProfiles.rightExtruder`)}),(0,Z.jsx)(`div`,{className:`space-y-1`,children:Q.filter(e=>e.extruder_id===0).map(e=>(0,Z.jsx)(we,{profile:e,onEdit:()=>d(e),onCopy:()=>_(e),selectionMode:D,isSelected:k.has(B(e)),onToggleSelect:()=>je(B(e)),note:Re(e)},B(e)))})]})]}):(0,Z.jsx)(`div`,{className:`space-y-1`,children:Q.map(e=>(0,Z.jsx)(we,{profile:e,onEdit:()=>d(e),onCopy:()=>_(e),selectionMode:D,isSelected:k.has(B(e)),onToggleSelect:()=>je(B(e)),note:Re(e)},B(e)))}):v||x!==`all`||C!==`all`?(0,Z.jsx)(M,{children:(0,Z.jsxs)(j,{className:`py-12 text-center`,children:[(0,Z.jsx)(ee,{className:`w-12 h-12 text-bambu-gray mx-auto mb-4`}),(0,Z.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-2`,children:e(`kProfiles.noMatchingProfiles`)}),(0,Z.jsx)(`p`,{className:`text-bambu-gray`,children:e(`kProfiles.noMatchingProfilesDesc`)})]})}):(0,Z.jsx)(M,{children:(0,Z.jsxs)(j,{className:`py-12 text-center`,children:[(0,Z.jsx)(b,{className:`w-12 h-12 text-bambu-gray mx-auto mb-4`}),(0,Z.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-2`,children:e(`kProfiles.noKProfiles`)}),(0,Z.jsx)(`p`,{className:`text-bambu-gray mb-4`,children:e(`kProfiles.noKProfilesDesc`,{diameter:c})}),(0,Z.jsxs)(N,{onClick:()=>p(!0),children:[(0,Z.jsx)(se,{className:`w-4 h-4`}),e(`kProfiles.createFirstProfile`)]})]})}),u&&a&&(()=>{let{note:e,key:t}=Le(u);return(0,Z.jsx)(Te,{profile:u,printerId:a,nozzleDiameter:c,existingProfiles:H?.profiles,builtinFilaments:ye,filamentPresets:xe,isDualNozzle:$,supportsFlowType:Oe,initialNote:e,initialNoteKey:t,onSaveNote:Ie,hasPermission:n,onClose:()=>{console.log(`[KProfiles] Edit modal onClose - refetching profiles...`),d(null),G()},onSave:()=>{d(null),G()}})})(),f&&a&&(0,Z.jsx)(Te,{printerId:a,nozzleDiameter:c,existingProfiles:H?.profiles,builtinFilaments:ye,filamentPresets:xe,isDualNozzle:$,supportsFlowType:Oe,onSaveNote:Ie,hasPermission:n,onClose:()=>{p(!1),G()},onSave:()=>{p(!1),G()}}),g&&a&&(0,Z.jsx)(Te,{printerId:a,nozzleDiameter:c,existingProfiles:H?.profiles,builtinFilaments:ye,filamentPresets:xe,isDualNozzle:$,supportsFlowType:Oe,onSaveNote:Ie,hasPermission:n,profile:{...g,slot_id:0,name:`${g.name} (Copy)`},onClose:()=>{_(null),G()},onSave:()=>{_(null),G()}}),F&&(0,Z.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,children:(0,Z.jsx)(M,{className:`w-full max-w-sm`,children:(0,Z.jsxs)(j,{className:`p-6`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-3 mb-4`,children:[(0,Z.jsx)(`div`,{className:`w-10 h-10 rounded-full bg-red-500/20 flex items-center justify-center`,children:(0,Z.jsx)(I,{className:`w-5 h-5 text-red-500`})}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`h3`,{className:`text-lg font-semibold text-white`,children:e(`kProfiles.bulkDelete.title`)}),(0,Z.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`kProfiles.bulkDelete.cannotUndo`)})]})]}),(0,Z.jsx)(`p`,{className:`text-bambu-gray mb-6`,children:e(`kProfiles.bulkDelete.message`,{count:k.size})}),(0,Z.jsxs)(`div`,{className:`flex gap-3`,children:[(0,Z.jsx)(N,{variant:`secondary`,onClick:()=>L(!1),disabled:R,className:`flex-1`,children:e(`common.cancel`)}),(0,Z.jsxs)(N,{onClick:Pe,disabled:R,className:`flex-1 bg-red-500 hover:bg-red-600 text-white`,children:[R?(0,Z.jsx)(w,{className:`w-4 h-4 animate-spin`}):(0,Z.jsx)(I,{className:`w-4 h-4`}),e(`common.delete`)]})]})]})})})]})}var $=[`PLA`,`PETG`,`PCTG`,`ABS`,`ASA`,`TPU`,`PC`,`PA`,`PVA`,`HIPS`,`PP`,`PET`,`NYLON`],Oe={PLA:`E8E8E8`,PETG:`4A90D9`,ABS:`E67E22`,ASA:`D35400`,TPU:`9B59B6`,PC:`BDC3C7`,PA:`2ECC71`,NYLON:`2ECC71`,PVA:`F1C40F`,HIPS:`95A5A6`,PP:`ECF0F1`,PET:`3498DB`};function ke(e){let t=e.toUpperCase();for(let e of $)if(RegExp(`\\b${e}\\b`).test(t))return e;return null}function Ae(e){let t=e.replace(/@.+$/,``).trim(),n=t.toUpperCase();for(let e of $){let r=n.indexOf(e);if(r>0){let e=t.slice(0,r).trim();if(e&&e.length>1)return e}}return null}function je({preset:e,onDelete:t,onExpand:n,isExpanded:r}){let{t:a}=i(),{hasPermission:o}=de(),s=e.filament_type||ke(e.name),c=e.filament_vendor||Ae(e.name),l=null,u=!1;if(e.default_filament_colour)try{let t=JSON.parse(e.default_filament_colour),n=Array.isArray(t)?t[0]:t;typeof n==`string`&&/^#?[0-9a-fA-F]{6,8}$/.test(n.replace(`#`,``))&&(l=n.replace(`#`,``).slice(0,6),u=!0)}catch{let t=e.default_filament_colour;/^#?[0-9a-fA-F]{6,8}$/.test(t.replace(`#`,``))&&(l=t.replace(`#`,``).slice(0,6),u=!0)}return!l&&s&&(l=Oe[s.toUpperCase()]||null),(0,Z.jsx)(M,{className:`bg-bambu-dark border-bambu-dark-tertiary hover:border-bambu-dark-tertiary/80 transition-colors`,children:(0,Z.jsxs)(j,{className:`p-3`,children:[(0,Z.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,Z.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[e.preset_type===`filament`&&(0,Z.jsx)(`div`,{className:`w-4 h-4 rounded-full border border-black/20 flex-shrink-0 ${!u&&!l?`opacity-25`:u?``:`opacity-50`}`,style:{backgroundColor:l?`#${l}`:`#666`}}),(0,Z.jsx)(`span`,{className:`text-sm font-medium text-white truncate`,children:e.name})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[s&&(0,Z.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-bambu-green/20 text-bambu-green`,children:s}),c&&(0,Z.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:c}),(0,Z.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`,children:a(`profiles.localProfiles.badge`)})]})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-1 flex-shrink-0`,children:[o(`settings:update`)&&(0,Z.jsx)(`button`,{onClick:()=>t(e.id),className:`p-1 text-bambu-gray hover:text-red-600 dark:hover:text-red-400 transition-colors`,title:a(`profiles.localProfiles.delete`),children:(0,Z.jsx)(I,{className:`w-3.5 h-3.5`})}),(0,Z.jsx)(`button`,{onClick:()=>n(r?null:e.id),className:`p-1 text-bambu-gray hover:text-white transition-colors`,children:r?(0,Z.jsx)(p,{className:`w-3.5 h-3.5`}):(0,Z.jsx)(f,{className:`w-3.5 h-3.5`})})]})]}),r&&(0,Z.jsxs)(`div`,{className:`mt-3 pt-3 border-t border-bambu-dark-tertiary text-xs space-y-1.5`,children:[s&&(0,Z.jsxs)(`div`,{className:`flex justify-between`,children:[(0,Z.jsx)(`span`,{className:`text-bambu-gray`,children:a(`profiles.localProfiles.filamentType`)}),(0,Z.jsx)(`span`,{className:`text-white`,children:s})]}),c&&(0,Z.jsxs)(`div`,{className:`flex justify-between`,children:[(0,Z.jsx)(`span`,{className:`text-bambu-gray`,children:a(`profiles.localProfiles.vendor`)}),(0,Z.jsx)(`span`,{className:`text-white`,children:c})]}),e.nozzle_temp_min!=null&&e.nozzle_temp_max!=null&&(0,Z.jsxs)(`div`,{className:`flex justify-between`,children:[(0,Z.jsx)(`span`,{className:`text-bambu-gray`,children:a(`profiles.localProfiles.nozzleTemp`)}),(0,Z.jsxs)(`span`,{className:`text-white`,children:[e.nozzle_temp_min,`–`,e.nozzle_temp_max,`°C`]})]}),e.filament_cost&&(0,Z.jsxs)(`div`,{className:`flex justify-between`,children:[(0,Z.jsx)(`span`,{className:`text-bambu-gray`,children:a(`profiles.localProfiles.cost`)}),(0,Z.jsx)(`span`,{className:`text-white`,children:e.filament_cost})]}),e.filament_density&&(0,Z.jsxs)(`div`,{className:`flex justify-between`,children:[(0,Z.jsx)(`span`,{className:`text-bambu-gray`,children:a(`profiles.localProfiles.density`)}),(0,Z.jsxs)(`span`,{className:`text-white`,children:[e.filament_density,` g/cm³`]})]}),e.pressure_advance&&(0,Z.jsxs)(`div`,{className:`flex justify-between`,children:[(0,Z.jsx)(`span`,{className:`text-bambu-gray`,children:a(`profiles.localProfiles.pressureAdvance`)}),(0,Z.jsx)(`span`,{className:`text-white`,children:e.pressure_advance})]}),e.compatible_printers&&(0,Z.jsxs)(`div`,{className:`flex justify-between`,children:[(0,Z.jsx)(`span`,{className:`text-bambu-gray`,children:a(`profiles.localProfiles.compatiblePrinters`)}),(0,Z.jsx)(`span`,{className:`text-white truncate ml-2`,children:(()=>{try{return JSON.parse(e.compatible_printers).join(`, `)}catch{return e.compatible_printers}})()})]}),e.inherits&&e.inherits!==e.name&&(0,Z.jsxs)(`div`,{className:`flex justify-between`,children:[(0,Z.jsx)(`span`,{className:`text-bambu-gray`,children:a(`profiles.localProfiles.inheritsFrom`)}),(0,Z.jsx)(`span`,{className:`text-white truncate ml-2`,children:e.inherits})]}),(0,Z.jsxs)(`div`,{className:`flex justify-between`,children:[(0,Z.jsx)(`span`,{className:`text-bambu-gray`,children:a(`profiles.localProfiles.source`)}),(0,Z.jsx)(`span`,{className:`text-white capitalize`,children:e.source})]})]})]})})}function Me(){let{t:e}=i(),{hasPermission:t}=de(),n=a(),{showToast:c}=h(),[l,u]=(0,Y.useState)(``),[d,f]=(0,Y.useState)(null),[p,g]=(0,Y.useState)(!1),[v,y]=(0,Y.useState)(null),{data:b,isLoading:x}=o({queryKey:[`localPresets`],queryFn:()=>r.getLocalPresets()}),C=s({mutationFn:async e=>{let t=[];for(let n of Array.from(e)){let e=new FormData;e.append(`file`,n),t.push(await r.importLocalPresets(e))}return t},onSuccess:t=>{n.invalidateQueries({queryKey:[`localPresets`]}),n.invalidateQueries({queryKey:[`slicerPresets`]});let r=0,i=0,a=0;for(let e of t)r+=e.imported,i+=e.skipped,a+=e.errors.length;r>0&&c(e(`profiles.localProfiles.toast.importSuccess`,{count:r})),i>0&&c(e(`profiles.localProfiles.toast.importSkipped`,{count:i}),`warning`),a>0&&c(e(`profiles.localProfiles.toast.importError`,{count:a}),`error`)},onError:e=>{c(e.message,`error`)}}),T=s({mutationFn:e=>r.deleteLocalPreset(e),onSuccess:(t,r)=>{n.setQueryData([`localPresets`],e=>e&&{filament:e.filament.filter(e=>e.id!==r),printer:e.printer.filter(e=>e.id!==r),process:e.process.filter(e=>e.id!==r)}),n.invalidateQueries({queryKey:[`localPresets`]}),n.invalidateQueries({queryKey:[`slicerPresets`]}),y(null),c(e(`profiles.localProfiles.toast.deleted`))}}),E=(0,Y.useCallback)(e=>{!e||e.length===0||C.mutate(e)},[C]),D=(0,Y.useCallback)(e=>{e.preventDefault(),g(!1),E(e.dataTransfer.files)},[E]),O=(0,Y.useCallback)(e=>{if(!l)return e;let t=l.toLowerCase();return e.filter(e=>e.name.toLowerCase().includes(t)||e.filament_type?.toLowerCase().includes(t)||e.filament_vendor?.toLowerCase().includes(t))},[l]),k=(0,Y.useMemo)(()=>O(b?.filament||[]),[b?.filament,O]),A=(0,Y.useMemo)(()=>O(b?.printer||[]),[b?.printer,O]),j=(0,Y.useMemo)(()=>O(b?.process||[]),[b?.process,O]),M=k.length+A.length+j.length,P=(b?.filament?.length??0)+(b?.printer?.length??0)+(b?.process?.length??0)>0;return x?(0,Z.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,Z.jsx)(w,{className:`w-8 h-8 text-bambu-green animate-spin`})}):(0,Z.jsxs)(`div`,{className:`space-y-6`,children:[t(`settings:update`)&&(0,Z.jsxs)(`div`,{onDragOver:e=>{e.preventDefault(),g(!0)},onDragLeave:()=>g(!1),onDrop:D,className:`relative border-2 border-dashed rounded-lg p-6 text-center transition-colors ${p?`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:[(0,Z.jsx)(`input`,{type:`file`,accept:`.json,.zip,.orca_filament,.bbscfg,.bbsflmt`,multiple:!0,className:`absolute inset-0 w-full h-full opacity-0 cursor-pointer`,onChange:e=>E(e.target.files)}),C.isPending?(0,Z.jsxs)(`div`,{className:`flex items-center justify-center gap-2`,children:[(0,Z.jsx)(w,{className:`w-5 h-5 text-bambu-green animate-spin`}),(0,Z.jsx)(`span`,{className:`text-bambu-gray`,children:e(`profiles.localProfiles.importing`)})]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(le,{className:`w-8 h-8 text-bambu-gray mx-auto mb-2`}),(0,Z.jsx)(`p`,{className:`text-sm text-white font-medium`,children:e(`profiles.localProfiles.import`)}),(0,Z.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`profiles.localProfiles.importDesc`)})]})]}),P&&(0,Z.jsxs)(`div`,{className:`relative`,children:[(0,Z.jsx)(ee,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,Z.jsx)(`input`,{type:`text`,value:l,onChange:e=>u(e.target.value),placeholder:e(`profiles.localProfiles.search`),className:`w-full pl-9 pr-4 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`})]}),!P&&!x&&(0,Z.jsxs)(`div`,{className:`text-center py-12`,children:[(0,Z.jsx)(S,{className:`w-12 h-12 text-bambu-gray mx-auto mb-3 opacity-50`}),(0,Z.jsx)(`p`,{className:`text-bambu-gray`,children:e(`profiles.localProfiles.noPresets`)}),(0,Z.jsx)(`p`,{className:`text-xs text-bambu-gray/60 mt-1`,children:e(`profiles.localProfiles.importDesc`)})]}),P&&M===0&&!x&&(0,Z.jsxs)(`div`,{className:`text-center py-12`,children:[(0,Z.jsx)(ee,{className:`w-12 h-12 text-bambu-gray mx-auto mb-3 opacity-50`}),(0,Z.jsx)(`p`,{className:`text-bambu-gray`,children:e(`profiles.localProfiles.noSearchResults`)})]}),M>0&&(0,Z.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6`,children:[k.length>0&&(0,Z.jsxs)(`div`,{children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,Z.jsx)(_,{className:`w-4 h-4 text-bambu-green`}),(0,Z.jsx)(`h3`,{className:`text-sm font-medium text-white`,children:e(`profiles.localProfiles.filament`)}),(0,Z.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[`(`,k.length,`)`]})]}),(0,Z.jsx)(`div`,{className:`space-y-2`,children:k.map(e=>(0,Z.jsx)(je,{preset:e,onDelete:e=>y(e),onExpand:f,isExpanded:d===e.id},e.id))})]}),j.length>0&&(0,Z.jsxs)(`div`,{children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,Z.jsx)(ce,{className:`w-4 h-4 text-blue-600 dark:text-blue-400`}),(0,Z.jsx)(`h3`,{className:`text-sm font-medium text-white`,children:e(`profiles.localProfiles.process`)}),(0,Z.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[`(`,j.length,`)`]})]}),(0,Z.jsx)(`div`,{className:`space-y-2`,children:j.map(e=>(0,Z.jsx)(je,{preset:e,onDelete:e=>y(e),onExpand:f,isExpanded:d===e.id},e.id))})]}),A.length>0&&(0,Z.jsxs)(`div`,{children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,Z.jsx)(te,{className:`w-4 h-4 text-orange-600 dark:text-orange-400`}),(0,Z.jsx)(`h3`,{className:`text-sm font-medium text-white`,children:e(`profiles.localProfiles.printer`)}),(0,Z.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[`(`,A.length,`)`]})]}),(0,Z.jsx)(`div`,{className:`space-y-2`,children:A.map(e=>(0,Z.jsx)(je,{preset:e,onDelete:e=>y(e),onExpand:f,isExpanded:d===e.id},e.id))})]})]}),v!==null&&(0,Z.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50`,children:(0,Z.jsxs)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg p-6 max-w-sm mx-4`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,Z.jsx)(m,{className:`w-5 h-5 text-red-600 dark:text-red-400`}),(0,Z.jsx)(`h3`,{className:`text-white font-medium`,children:e(`profiles.localProfiles.deleteConfirmTitle`)})]}),(0,Z.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4`,children:e(`profiles.localProfiles.deleteConfirm`)}),(0,Z.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,Z.jsx)(N,{variant:`secondary`,size:`sm`,onClick:()=>y(null),children:e(`profiles.localProfiles.cancel`)}),(0,Z.jsxs)(N,{variant:`danger`,size:`sm`,onClick:()=>T.mutate(v),disabled:T.isPending,children:[T.isPending?(0,Z.jsx)(w,{className:`w-4 h-4 animate-spin`}):(0,Z.jsx)(I,{className:`w-4 h-4`}),e(`profiles.localProfiles.delete`)]})]})]})})]})}function Ne(e){let t=e.match(/@?\s*(?:BBL\s+)?(?:Bambu\s+Lab\s+)?([XPAH][1-9][A-Z]?(?:\s*(?:Carbon|mini))?|H2D)/i),n=e.match(/(\d+\.?\d*)\s*(?:mm\s*)?nozzle|nozzle\s*(\d+\.?\d*)/i),r=e.match(/(\d+\.?\d*)mm\s*(?:Standard|Fine|Extra Fine|Draft|Quality)?/i),i=e.match(/\b(PLA|PETG|ABS|ASA|TPU|PC|PA|PVA|HIPS|PP|PET(?:-?CF)?|PA(?:-?CF)?|PLA(?:-?CF)?)\b/i);return{printer:t?t[1].trim():null,nozzle:n?(n[1]||n[2])+`mm`:null,layerHeight:r?r[1]+`mm`:null,filamentType:i?i[1].toUpperCase():null}}function Pe({settings:e,lastSyncTime:t,onRefresh:n,isRefreshing:r,printers:i,t:a}){let[o,s]=(0,Y.useState)(``),[c,l]=(0,Y.useState)(`all`),[u,d]=(0,Y.useState)(`all`),[f,p]=(0,Y.useState)(`all`),[m,h]=(0,Y.useState)(`all`),[g,v]=(0,Y.useState)(`all`),[b,x]=(0,Y.useState)(null),S=(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:Ne(e.name)})),[e]),C=(0,Y.useMemo)(()=>{let e=new Set,t=new Set,n=new Set;return S.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))}},[S,i]),w=(0,Y.useMemo)(()=>u===`all`?null:i.find(e=>e.id.toString()===u)?.model||null,[u,i]),T=(0,Y.useMemo)(()=>S.filter(e=>c===`all`||e.type===c).filter(e=>{if(u===`all`||!w)return!0;let t=e.meta.printer?.toLowerCase()||``,n=w.toLowerCase();return t.includes(n)||n.includes(t)}).filter(e=>f===`all`||e.meta.nozzle===f).filter(e=>m===`all`||e.meta.filamentType===m).filter(e=>g===`all`||e.meta.layerHeight===g).filter(e=>o===``||e.name.toLowerCase().includes(o.toLowerCase())).sort((e,t)=>e.name.localeCompare(t.name)),[S,c,u,w,f,m,g,o]),E=()=>{l(`all`),d(`all`),p(`all`),h(`all`),v(`all`),s(``)},D=c!==`all`||u!==`all`||f!==`all`||m!==`all`||g!==`all`||o!==``,O=e.filament.length+e.printer.length+e.process.length,k=e=>T.filter(t=>t.type===e);return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{className:`space-y-4 mb-6`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-col sm:flex-row gap-3`,children:[(0,Z.jsxs)(`div`,{className:`relative flex-1`,children:[(0,Z.jsx)(ee,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,Z.jsx)(`input`,{type:`text`,value:o,onChange:e=>s(e.target.value),placeholder:a(`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,Z.jsx)(`div`,{className:`flex gap-2`,children:(0,Z.jsxs)(N,{variant:`secondary`,onClick:n,disabled:r,children:[(0,Z.jsx)(ie,{className:`w-4 h-4 ${r?`animate-spin`:``}`}),a(`profiles.cloudView.refresh`)]})})]}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Z.jsx)(y,{className:`w-4 h-4 text-bambu-gray`}),(0,Z.jsx)(Ue,{label:a(`profiles.cloudView.filters.type`),value:c,options:[{value:`all`,label:a(`profiles.cloudView.filters.all`),count:O},{value:`filament`,label:a(`profiles.cloudView.filters.filament`),count:e.filament.length},{value:`printer`,label:a(`profiles.cloudView.filters.printer`),count:e.printer.length},{value:`process`,label:a(`profiles.cloudView.filters.process`),count:e.process.length}],onChange:e=>l(e)}),C.printers.length>0&&(0,Z.jsx)(Ue,{label:a(`profiles.cloudView.filters.printer`),value:u,options:[{value:`all`,label:a(`profiles.cloudView.filters.all`)},...C.printers.map(e=>({value:e.id,label:e.name}))],onChange:d}),C.nozzles.length>0&&(0,Z.jsx)(Ue,{label:a(`profiles.cloudView.filters.nozzle`),value:f,options:[{value:`all`,label:a(`profiles.cloudView.filters.all`)},...C.nozzles.map(e=>({value:e,label:e}))],onChange:p}),C.filaments.length>0&&(c===`all`||c===`filament`)&&(0,Z.jsx)(Ue,{label:a(`profiles.cloudView.filters.filament`),value:m,options:[{value:`all`,label:a(`profiles.cloudView.filters.all`)},...C.filaments.map(e=>({value:e,label:e}))],onChange:h}),C.layerHeights.length>0&&(c===`all`||c===`process`)&&(0,Z.jsx)(Ue,{label:a(`profiles.cloudView.filters.layer`),value:g,options:[{value:`all`,label:a(`profiles.cloudView.filters.all`)},...C.layerHeights.map(e=>({value:e,label:e}))],onChange:v}),D&&(0,Z.jsx)(`button`,{onClick:E,className:`px-3 py-2 text-sm text-bambu-gray hover:text-white transition-colors`,children:a(`profiles.cloudView.clearFilters`)})]})]}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4 mb-4 text-sm text-bambu-gray`,children:[t&&(0,Z.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Z.jsx)(ae,{className:`w-3 h-3`}),a(`profiles.cloudView.lastSynced`),` `,P(t.toISOString(),`system`,a)]}),(0,Z.jsx)(`span`,{children:a(`profiles.cloudView.showingCount`,{showing:T.length,total:O})})]}),T.length===0?(0,Z.jsxs)(`div`,{className:`text-center py-16`,children:[(0,Z.jsx)(ce,{className:`w-12 h-12 text-bambu-gray-dark mx-auto mb-4`}),(0,Z.jsx)(`p`,{className:`text-bambu-gray`,children:a(`profiles.cloudView.noPresetsFound`)}),D&&(0,Z.jsx)(`button`,{onClick:E,className:`mt-2 text-sm text-bambu-green hover:text-bambu-green-light`,children:a(`profiles.cloudView.clearFilters`)})]}):(0,Z.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-6`,children:[(0,Z.jsx)(Fe,{icon:(0,Z.jsx)(_,{className:`w-4 h-4 text-amber-600 dark:text-amber-400`}),title:a(`profiles.cloudView.columns.filament`),presets:k(`filament`),emptyText:a(`profiles.cloudView.noFilamentPresets`),onSelect:x}),(0,Z.jsx)(Fe,{icon:(0,Z.jsx)(te,{className:`w-4 h-4 text-blue-600 dark:text-blue-400`}),title:a(`profiles.cloudView.columns.process`),presets:k(`process`),emptyText:a(`profiles.cloudView.noProcessPresets`),onSelect:x}),(0,Z.jsx)(Fe,{icon:(0,Z.jsx)(re,{className:`w-4 h-4 text-purple-600 dark:text-purple-400`}),title:a(`profiles.cloudView.columns.printer`),presets:k(`printer`),emptyText:a(`profiles.cloudView.noPrinterPresets`),onSelect:x})]}),b&&(0,Z.jsx)(Le,{setting:b,onClose:()=>x(null),t:a})]})}function Fe({icon:e,title:t,presets:n,emptyText:r,onSelect:i}){return(0,Z.jsxs)(`div`,{children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 mb-3 px-1`,children:[e,(0,Z.jsx)(`h3`,{className:`text-sm font-medium text-bambu-gray`,children:t}),(0,Z.jsxs)(`span`,{className:`text-xs text-bambu-gray-dark`,children:[`(`,n.length,`)`]})]}),(0,Z.jsx)(`div`,{className:`space-y-1 max-h-[calc(100vh-320px)] overflow-y-auto pr-1`,children:n.length===0?(0,Z.jsx)(`p`,{className:`text-xs text-bambu-gray-dark px-3 py-2`,children:r}):n.map(e=>(0,Z.jsx)(Ie,{preset:e,onClick:()=>i(e)},e.setting_id))})]})}function Ie({preset:e,onClick:t}){return(0,Z.jsx)(`button`,{onClick:t,className:`w-full text-left px-3 py-2 rounded bg-bambu-dark hover:bg-bambu-dark-tertiary transition-colors`,children:(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`span`,{className:`text-white text-sm truncate flex-1`,title:e.name,children:e.name}),e.meta.filamentType&&e.type===`filament`&&(0,Z.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:e.meta.filamentType}),e.meta.layerHeight&&e.type===`process`&&(0,Z.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:e.meta.layerHeight}),e.meta.printer&&(0,Z.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:e.meta.printer})]})})}function Le({setting:e,onClose:t,t:n}){let{data:i,isLoading:a,error:s}=o({queryKey:[`orcaCloudProfileDetail`,e.setting_id],queryFn:()=>r.orcaCloudGetProfile(e.setting_id),retry:!1});return(0,Z.jsx)(`div`,{className:`fixed inset-0 bg-black/60 z-50 flex items-center justify-center p-4`,onClick:t,children:(0,Z.jsxs)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-2xl max-w-4xl w-full max-h-[90vh] flex flex-col`,onClick:e=>e.stopPropagation(),children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`h2`,{className:`text-lg font-bold text-white`,children:e.name}),(0,Z.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:e.type})]}),(0,Z.jsx)(`button`,{onClick:t,className:`text-bambu-gray hover:text-white p-1`,children:(0,Z.jsx)(A,{className:`w-5 h-5`})})]}),(0,Z.jsx)(`div`,{className:`flex-1 overflow-y-auto p-4`,children:a?(0,Z.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,Z.jsx)(w,{className:`w-8 h-8 text-bambu-green animate-spin`})}):s?(0,Z.jsx)(`p`,{className:`text-center text-bambu-gray py-16`,children:s.message}):i?(0,Z.jsx)(`pre`,{className:`text-xs font-mono text-bambu-gray bg-bambu-dark p-3 rounded overflow-x-auto whitespace-pre`,children:JSON.stringify(i.setting,null,2)}):(0,Z.jsx)(`p`,{className:`text-center text-bambu-gray py-16`,children:n(`profiles.cloudView.noPresetsFound`)})})]})})}function Re(){let{t:e}=i(),t=a(),{showToast:n}=h(),{hasPermission:c}=de(),l=c(`orca_cloud:auth`),[u,d]=(0,Y.useState)(null),[f,p]=(0,Y.useState)(5e3),[m,g]=(0,Y.useState)(null),{data:_,isLoading:v}=o({queryKey:[`orcaCloudStatus`],queryFn:r.orcaCloudStatus}),y=!!_?.connected,{data:b,isLoading:x,refetch:S,isRefetching:C,error:T,dataUpdatedAt:E}=o({queryKey:[`orcaCloudProfiles`],queryFn:r.orcaCloudListProfiles,enabled:y,retry:!1,staleTime:1e3*60*5}),{data:ee=[]}=o({queryKey:[`printers`],queryFn:r.getPrinters,enabled:y}),[te,D]=(0,Y.useState)();(0,Y.useEffect)(()=>{E&&D(new Date(E))},[E]);let O=()=>{d(null),p(5e3)},k=t=>{t===`access_denied`?g(e(`profiles.orcaCloud.errors.denied`)):t===`expired_token`&&g(e(`profiles.orcaCloud.errors.expired`)),O()},A=s({mutationFn:r.orcaCloudDeviceStart,onSuccess:e=>{g(null),p(Math.max(1,e.interval)*1e3),d(e)},onError:t=>{g(t.message||e(`profiles.orcaCloud.errors.startFailed`))}}),j=s({mutationFn:r.orcaCloudLogout,onSuccess:()=>{t.invalidateQueries({queryKey:[`orcaCloudStatus`]}),t.removeQueries({queryKey:[`orcaCloudProfiles`]}),n(e(`profiles.orcaCloud.toast.disconnected`))}}),{data:M,error:P}=o({queryKey:[`orcaCloudDevicePoll`,u?.user_code??`none`],queryFn:r.orcaCloudDevicePoll,enabled:u!==null,gcTime:0,retry:!1,refetchOnWindowFocus:!1,refetchInterval:u===null?!1:f}),F=(0,Y.useRef)(null);return(0,Y.useEffect)(()=>{if(!u||!M)return;let r=M.status;if(r===`slow_down`){p(e=>e+5e3);return}r!==`authorization_pending`&&F.current!==r&&(F.current=r,r===`complete`?(O(),t.invalidateQueries({queryKey:[`orcaCloudStatus`]}),t.invalidateQueries({queryKey:[`orcaCloudProfiles`]}),n(e(`profiles.orcaCloud.connectedShort`))):k(r))},[M,u]),(0,Y.useEffect)(()=>{u&&P&&(g(e(`profiles.orcaCloud.errors.pollFailed`)),O())},[P,u]),(0,Y.useEffect)(()=>{u&&(F.current=null)},[u]),v?(0,Z.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,Z.jsx)(w,{className:`w-8 h-8 text-bambu-green animate-spin`})}):(0,Z.jsxs)(`div`,{children:[y&&(0,Z.jsxs)(`div`,{className:`flex items-center justify-between p-3 mb-6 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Z.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-bambu-green animate-pulse`}),(0,Z.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:_?.email?(0,Z.jsxs)(Z.Fragment,{children:[e(`profiles.orcaCloud.connectedAs`),` `,(0,Z.jsx)(`span`,{className:`text-white`,children:_.email})]}):(0,Z.jsx)(`span`,{className:`text-white`,children:e(`profiles.orcaCloud.connectedShort`)})})]}),(0,Z.jsxs)(N,{variant:`secondary`,size:`sm`,onClick:()=>j.mutate(),disabled:j.isPending||!l,title:l?void 0:e(`profiles.orcaCloud.noLogoutPermission`),children:[(0,Z.jsx)(W,{className:`w-4 h-4`}),e(`profiles.orcaCloud.logout`)]})]}),y?x?(0,Z.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,Z.jsx)(w,{className:`w-8 h-8 text-bambu-green animate-spin`})}):T?(0,Z.jsxs)(`div`,{className:`text-center py-16`,children:[(0,Z.jsx)(`p`,{className:`text-bambu-gray mb-4`,children:T.message}),(0,Z.jsx)(N,{onClick:()=>S(),children:e(`profiles.orcaCloud.retry`)})]}):b?(0,Z.jsx)(Pe,{settings:b,lastSyncTime:te,onRefresh:()=>S(),isRefreshing:C,printers:ee,t:e}):null:(0,Z.jsx)(ze,{pairing:u,connectError:m,onConnect:()=>A.mutate(),onCancel:O,isStarting:A.isPending,canManage:l,t:e})]})}function ze({pairing:e,connectError:t,onConnect:n,onCancel:r,isStarting:i,canManage:a,t:o}){return e?(0,Z.jsx)(M,{children:(0,Z.jsxs)(j,{className:`p-8 text-center max-w-md mx-auto`,children:[(0,Z.jsx)(z,{className:`w-12 h-12 text-bambu-green mx-auto mb-4`}),(0,Z.jsx)(`h2`,{className:`text-xl font-bold text-white mb-2`,children:o(`profiles.orcaCloud.device.title`)}),(0,Z.jsx)(`p`,{className:`text-bambu-gray mb-6`,children:o(`profiles.orcaCloud.device.instruction`)}),(0,Z.jsx)(`p`,{className:`text-xs uppercase tracking-wide text-bambu-gray mb-2`,children:o(`profiles.orcaCloud.device.codeLabel`)}),(0,Z.jsx)(`div`,{className:`mb-6 py-3 px-4 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg`,children:(0,Z.jsx)(`span`,{className:`text-2xl font-mono font-bold tracking-[0.3em] text-white select-all`,children:e.user_code})}),(0,Z.jsx)(`a`,{href:e.verification_uri_complete,target:`_blank`,rel:`noopener noreferrer`,children:(0,Z.jsxs)(N,{className:`w-full mb-3`,children:[(0,Z.jsx)(R,{className:`w-4 h-4`}),o(`profiles.orcaCloud.device.openButton`)]})}),(0,Z.jsx)(`p`,{className:`text-xs text-bambu-gray break-all mb-6`,children:o(`profiles.orcaCloud.device.manualHint`,{url:e.verification_uri})}),(0,Z.jsxs)(`div`,{className:`flex items-center justify-center gap-2 text-sm text-bambu-gray mb-4`,children:[(0,Z.jsx)(w,{className:`w-4 h-4 animate-spin text-bambu-green`}),o(`profiles.orcaCloud.device.waiting`)]}),(0,Z.jsx)(`button`,{type:`button`,onClick:r,className:`text-bambu-gray hover:text-white text-sm`,children:o(`profiles.orcaCloud.device.cancel`)})]})}):(0,Z.jsx)(M,{children:(0,Z.jsxs)(j,{className:`p-8 text-center`,children:[(0,Z.jsx)(z,{className:`w-12 h-12 text-bambu-green mx-auto mb-4`}),(0,Z.jsx)(`h2`,{className:`text-xl font-bold text-white mb-2`,children:o(`profiles.orcaCloud.connect.title`)}),(0,Z.jsx)(`p`,{className:`text-bambu-gray mb-6 max-w-xl mx-auto`,children:o(`profiles.orcaCloud.connect.description`)}),(0,Z.jsxs)(`div`,{className:`max-w-sm mx-auto`,children:[(0,Z.jsxs)(N,{onClick:n,disabled:i||!a,title:a?void 0:o(`profiles.orcaCloud.noConnectPermission`),className:`w-full`,children:[i?(0,Z.jsx)(w,{className:`w-4 h-4 animate-spin`}):(0,Z.jsx)(d,{className:`w-4 h-4`}),o(`profiles.orcaCloud.connectButton`)]}),t&&(0,Z.jsxs)(`p`,{className:`mt-3 text-sm text-red-700 dark:text-red-400 flex items-center justify-center gap-2`,children:[(0,Z.jsx)(m,{className:`w-4 h-4 flex-shrink-0`}),t]})]})]})})}function Be(e,t){let n=`${e} ${t||``}`,r=n.match(/@?\s*(?:BBL\s+)?(?:Bambu\s+Lab\s+)?([XPAH][1-9][A-Z]?(?:\s*(?:Carbon|mini))?|H2D)/i),i=r?r[1].trim():null,a=n.match(/(\d+\.?\d*)\s*(?:mm\s*)?nozzle|nozzle\s*(\d+\.?\d*)/i),o=a?(a[1]||a[2])+`mm`:null,s=n.match(/(\d+\.?\d*)mm\s*(?:Standard|Fine|Extra Fine|Draft|Quality)?/i),c=s?s[1]+`mm`:null,l=n.match(/\b(PLA|PETG|ABS|ASA|TPU|PC|PA|PVA|HIPS|PP|PET(?:-?CF)?|PA(?:-?CF)?|PLA(?:-?CF)?)\b/i);return{printer:i,nozzle:o,layerHeight:c,filamentType:l?l[1].toUpperCase():null}}function Ve(e){return/^(P[FPM]US|PF\d|PP\d)/.test(e)}function He({onSuccess:e,t}){let{showToast:n}=h(),[i,a]=(0,Y.useState)(`email`),[o,c]=(0,Y.useState)(``),[l,u]=(0,Y.useState)(``),[d,f]=(0,Y.useState)(``),[p,m]=(0,Y.useState)(``),[g,_]=(0,Y.useState)(`global`),[v,y]=(0,Y.useState)(null),[b,x]=(0,Y.useState)(null),[S,C]=(0,Y.useState)(!1),E=s({mutationFn:()=>r.cloudLogin(o,l,g),onSuccess:r=>{if(C(r.reason===`captcha`),r.success)n(t(`profiles.login.toast.loggedIn`)),e();else if(r.reason===`captcha`)return;else r.needs_verification?(y(r.verification_type||`email`),x(r.tfa_key||null),r.verification_type===`totp`?n(t(`profiles.login.toast.enterTotp`)):n(t(`profiles.login.toast.codeSent`)),a(`code`)):n(r.message,`error`)},onError:e=>{C(!1),n(e.message,`error`)}}),ee=s({mutationFn:()=>r.cloudVerify(o,d,b||void 0,g),onSuccess:r=>{C(r.reason===`captcha`),r.success?(n(t(`profiles.login.toast.loggedIn`)),e()):r.reason!==`captcha`&&n(r.message,`error`)},onError:e=>{C(!1),n(e.message,`error`)}}),te=s({mutationFn:()=>r.cloudSetToken(p,g),onSuccess:()=>{n(t(`profiles.login.toast.tokenSet`)),e()},onError:e=>n(e.message,`error`)}),D=e=>{e.preventDefault(),i===`email`?E.mutate():i===`code`?ee.mutate():i===`token`&&te.mutate()},O=E.isPending||ee.isPending||te.isPending;return(0,Z.jsx)(M,{className:`max-w-md mx-auto`,children:(0,Z.jsxs)(j,{children:[(0,Z.jsxs)(`div`,{className:`text-center mb-6`,children:[(0,Z.jsx)(`div`,{className:`inline-flex items-center justify-center w-12 h-12 rounded-xl bg-bambu-green/20 mb-3`,children:(0,Z.jsx)(z,{className:`w-6 h-6 text-bambu-green`})}),(0,Z.jsx)(`h2`,{className:`text-xl font-semibold text-white`,children:t(`profiles.login.title`)}),(0,Z.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:t(`profiles.login.subtitle`)})]}),S&&i!==`token`&&(0,Z.jsx)(`div`,{role:`alert`,className:`mb-4 p-3 rounded-lg border border-amber-500/40 bg-amber-500/10`,children:(0,Z.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Z.jsx)(L,{className:`w-4 h-4 text-amber-400 shrink-0 mt-0.5`}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`p`,{className:`text-sm font-medium text-amber-300`,children:t(`profiles.login.captchaTitle`)}),(0,Z.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:t(`profiles.login.captchaBody`)}),(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>{C(!1),a(`token`)},className:`mt-2 text-xs text-bambu-green hover:underline flex items-center gap-1`,children:[(0,Z.jsx)(G,{className:`w-3 h-3`}),t(`profiles.login.useToken`)]})]})]})}),(0,Z.jsxs)(`form`,{onSubmit:D,className:`space-y-4`,children:[i===`email`&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:t(`profiles.login.email`)}),(0,Z.jsx)(`input`,{type:`email`,value:o,onChange:e=>c(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none`,placeholder:`your@email.com`,required:!0})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:t(`profiles.login.password`)}),(0,Z.jsx)(`input`,{type:`password`,value:l,onChange:e=>u(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none`,placeholder:`••••••••`,required:!0})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:t(`profiles.login.region`)}),(0,Z.jsxs)(`select`,{value:g,onChange:e=>_(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`,children:[(0,Z.jsx)(`option`,{value:`global`,children:t(`profiles.login.regionGlobal`)}),(0,Z.jsx)(`option`,{value:`china`,children:t(`profiles.login.regionChina`)})]})]})]}),i===`code`&&(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:t(v===`totp`?`profiles.login.totpCode`:`profiles.login.verificationCode`)}),(0,Z.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:v===`totp`?t(`profiles.login.enterTotpHint`):t(`profiles.login.checkEmail`,{email:o})}),(0,Z.jsx)(`input`,{type:`text`,value:d,onChange:e=>f(e.target.value.replace(/\D/g,``).slice(0,6)),className:`w-full px-3 py-3 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-center text-2xl tracking-widest font-mono focus:border-bambu-green focus:outline-none`,placeholder:`000000`,maxLength:6,required:!0})]}),i===`token`&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:t(`profiles.login.accessToken`)}),(0,Z.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:t(`profiles.login.accessTokenHint`)}),(0,Z.jsx)(`textarea`,{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-xs font-mono placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none resize-none`,placeholder:`eyJ...`,rows:4,required:!0})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:t(`profiles.login.region`)}),(0,Z.jsxs)(`select`,{value:g,onChange:e=>_(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`,children:[(0,Z.jsx)(`option`,{value:`global`,children:t(`profiles.login.regionGlobal`)}),(0,Z.jsx)(`option`,{value:`china`,children:t(`profiles.login.regionChina`)})]})]})]}),(0,Z.jsxs)(`div`,{className:`flex gap-2 max-[550px]:flex-wrap max-[550px]:items-center`,children:[i===`code`&&(0,Z.jsx)(N,{type:`button`,variant:`secondary`,onClick:()=>a(`email`),className:`flex-1`,children:t(`profiles.login.back`)}),(0,Z.jsxs)(N,{type:`submit`,disabled:O,className:`flex-1`,children:[O?(0,Z.jsx)(w,{className:`w-4 h-4 animate-spin`}):(0,Z.jsx)(T,{className:`w-4 h-4`}),t(i===`email`?`profiles.login.loginButton`:i===`code`?`profiles.login.verifyButton`:`profiles.login.setTokenButton`)]})]}),i===`email`&&(0,Z.jsx)(`div`,{className:`pt-4 border-t border-bambu-dark-tertiary`,children:(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>a(`token`),className:`text-sm text-bambu-gray hover:text-white flex items-center gap-2 transition-colors`,children:[(0,Z.jsx)(G,{className:`w-4 h-4`}),t(`profiles.login.useToken`)]})}),i===`token`&&(0,Z.jsx)(`div`,{className:`pt-4 border-t border-bambu-dark-tertiary`,children:(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>a(`email`),className:`text-sm text-bambu-gray hover:text-white flex items-center gap-2 transition-colors`,children:[(0,Z.jsx)(T,{className:`w-4 h-4`}),t(`profiles.login.useEmail`)]})})]})]})})}function Ue({label:e,value:t,options:n,onChange:r}){let[i,a]=(0,Y.useState)(!1),o=n.find(e=>e.value===t);return(0,Z.jsxs)(`div`,{className:`relative`,children:[(0,Z.jsxs)(`button`,{onClick:()=>a(!i),className:`flex items-center gap-2 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-sm text-white hover:border-bambu-gray-dark transition-colors`,children:[(0,Z.jsxs)(`span`,{className:`text-bambu-gray`,children:[e,`:`]}),(0,Z.jsx)(`span`,{children:o?.label||`All`}),(0,Z.jsx)(f,{className:`w-4 h-4 text-bambu-gray transition-transform ${i?`rotate-180`:``}`})]}),i&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>a(!1)}),(0,Z.jsx)(`div`,{className:`absolute top-full left-0 mt-1 min-w-[160px] bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl z-20 py-1 max-h-60 overflow-y-auto`,children:n.map(e=>(0,Z.jsxs)(`button`,{onClick:()=>{r(e.value),a(!1)},className:`w-full px-3 py-2 text-left text-sm flex items-center justify-between hover:bg-bambu-dark-tertiary transition-colors ${t===e.value?`text-bambu-green`:`text-white`}`,children:[(0,Z.jsx)(`span`,{children:e.label}),e.count!==void 0&&(0,Z.jsx)(`span`,{className:`text-bambu-gray text-xs`,children:e.count})]},e.value))})]})]})}function We(){let[e,t]=(0,Y.useState)(!1);return(0,Y.useEffect)(()=>{let e=()=>{t(window.scrollY>300)};return window.addEventListener(`scroll`,e),()=>window.removeEventListener(`scroll`,e)},[]),e?(0,Z.jsx)(`button`,{onClick:()=>{window.scrollTo({top:0,behavior:`smooth`})},className:`fixed bottom-24 right-6 p-3 bg-bambu-green hover:bg-bambu-green-light text-white rounded-full shadow-lg shadow-bambu-green/25 transition-all z-40`,"aria-label":`Scroll to top`,children:(0,Z.jsx)(u,{className:`w-5 h-5`})}):null}function Ge({setting:e,onClick:t,onDuplicate:n,compareMode:r,isCompareSelected:i,compareIndex:a,compareDisabled:o,t:s}){let c=Be(e.name),l=Ve(e.setting_id);return(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 group`,children:[(0,Z.jsx)(`button`,{onClick:t,disabled:o,className:`flex-1 text-left px-3 py-2 rounded transition-colors ${i?`bg-blue-500/20 border border-blue-500/50`:o?`bg-bambu-dark/50 opacity-40 cursor-not-allowed`:`bg-bambu-dark hover:bg-bambu-dark-tertiary`} ${r&&!o?`cursor-pointer`:``}`,children:(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[i&&a!==void 0&&(0,Z.jsx)(`span`,{className:`flex-shrink-0 w-5 h-5 rounded-full bg-blue-500 text-white text-xs flex items-center justify-center font-medium`,children:a+1}),!i&&l&&(0,Z.jsx)(`span`,{className:`flex-shrink-0 w-1.5 h-1.5 rounded-full bg-bambu-green`,title:s(`profiles.presets.myPreset`)}),(0,Z.jsx)(`span`,{className:`text-white text-sm truncate flex-1`,title:e.name,children:e.name}),c.filamentType&&e.type===`filament`&&(0,Z.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:c.filamentType}),c.layerHeight&&e.type===`process`&&(0,Z.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:c.layerHeight}),c.printer&&(0,Z.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:c.printer})]})}),(0,Z.jsx)(`button`,{onClick:e=>{e.stopPropagation(),n()},className:`can-hover:opacity-0 group-hover:opacity-100 focus-visible:opacity-100 text-bambu-gray hover:text-white transition-all p-1`,title:s(`profiles.presets.duplicate`),children:(0,Z.jsx)(g,{className:`w-4 h-4`})})]})}function Ke(e,t=0){let n=` `.repeat(t);if(e===null)return`null`;if(e===void 0)return`undefined`;if(typeof e==`string`){if(e.includes(`\\n`)||e.includes(` `)){let t=e.replace(/\\n/g,` `).replace(/\\"/g,`"`).replace(/\\t/g,` `).split(` `);if(t.length>1)return`""" diff --git a/static/assets/ProjectDetailPage-BMGYb4NN.js b/static/assets/ProjectDetailPage-Cg8wQL8j.js similarity index 99% rename from static/assets/ProjectDetailPage-BMGYb4NN.js rename to static/assets/ProjectDetailPage-Cg8wQL8j.js index 61c77b3c5..6fd9d54df 100644 --- a/static/assets/ProjectDetailPage-BMGYb4NN.js +++ b/static/assets/ProjectDetailPage-Cg8wQL8j.js @@ -1 +1 @@ -import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,w as i}from"./client-DnySrlFv.js";import{n as a}from"./QueryClientProvider-Ce8_sN3w.js";import{t as o}from"./useQuery-BBCjCezC.js";import{t as s}from"./useMutation-B-Tr2hIP.js";import{t as ee}from"./arrow-left-0Q6F2rjC.js";import{t as te}from"./RichTextEditor-BBu-zZie.js";import{t as ne}from"./calendar-BLKPnWqV.js";import{n as re}from"./info-ROUoQhJR.js";import{n as ie,r as c}from"./ToastContext-BRX0SW3C.js";import{t as ae}from"./copy-Cu_0GKCU.js";import{t as oe}from"./file-box-04V4jZ9_.js";import{t as se}from"./history-B4lOLL01.js";import{t as l}from"./loader-circle-BEmFtawu.js";import{t as u}from"./package-BGUevlqS.js";import{t as ce}from"./pen-line-BWR04BX-.js";import{t as d}from"./triangle-alert-Dt_1FcBy.js";import{t as le}from"./x-DR-Trv6U.js";import{n as f,t as p}from"./Card-Bzc64K35.js";import{t as m}from"./Button-DDr6eAFy.js";import{a as ue,i as de,s as fe,v as h}from"./date-G9KUauqz.js";import{$t as pe,At as me,Cn as he,Jt as g,Mn as ge,N as _e,On as ve,Pt as ye,Rn as _,Un as be,Ut as xe,Vn as Se,Zt as Ce,_t as we,at as Te,b as Ee,cn as De,vn as Oe,wn as ke,xn as Ae,yt as je,zt as Me}from"./index-0t--Yqoi.js";import{t as Ne}from"./purify.es-F_7NWVtX.js";import{n as Pe}from"./libraryFiles-B0B1SFfn.js";import{ProjectModal as Fe,n as v,t as Ie}from"./ProjectsPage--qAFcLFS.js";var y=e(n(),1),b=t();function x(e){return e>=1e3?`${(e/1e3).toFixed(2)}kg`:`${Math.round(e)}g`}function Le({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,b.jsx)(`span`,{className:`px-2 py-1 rounded text-sm font-medium ${r}`,children:i[e]||e.charAt(0).toUpperCase()+e.slice(1)})}function Re({icon:e,label:t,value:n,subValue:r,hint:i,color:a=`text-bambu-gray`}){return(0,b.jsx)(p,{children:(0,b.jsx)(f,{className:`p-4`,children:(0,b.jsxs)(`div`,{className:`flex items-center gap-3`,title:i,children:[(0,b.jsx)(`div`,{className:`p-2 rounded-lg bg-bambu-dark ${a}`,children:(0,b.jsx)(e,{className:`w-5 h-5`})}),(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:t}),(0,b.jsx)(`p`,{className:`text-xl font-semibold text-white`,children:n}),r&&(0,b.jsx)(`p`,{className:`text-xs text-bambu-gray/70`,children:r})]})]})})})}function ze({archives:e,t}){return e.length===0?(0,b.jsxs)(`div`,{className:`text-center py-8 text-bambu-gray`,children:[(0,b.jsx)(u,{className:`w-12 h-12 mx-auto mb-2 opacity-50`}),(0,b.jsx)(`p`,{children:t(`projectDetail.noPrints`)})]}):(0,b.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,b.jsxs)(_,{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,b.jsx)(`img`,{src:r.getArchiveThumbnail(e.id),alt:e.print_name||`Print`,className:`w-full h-full object-cover`}):(0,b.jsx)(`div`,{className:`w-full h-full flex items-center justify-center text-bambu-gray`,children:(0,b.jsx)(u,{className:`w-8 h-8`})}),e.status===`failed`&&(0,b.jsx)(`div`,{className:`absolute inset-0 bg-red-500/30 flex items-center justify-center`,children:(0,b.jsx)(re,{className:`w-8 h-8 text-white`})}),e.status===`completed`&&(0,b.jsx)(`div`,{className:`absolute top-1 right-1`,children:(0,b.jsx)(c,{className:`w-4 h-4 text-bambu-green`})}),(0,b.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,b.jsx)(`p`,{className:`text-xs text-white truncate`,children:e.print_name||`Unknown`})})]},e.id))})}function Be({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,b.jsxs)(`span`,{className:`px-2 py-1 rounded text-xs font-medium flex items-center gap-1 ${r}`,children:[e===`urgent`&&(0,b.jsx)(d,{className:`w-3 h-3`}),i]})}function S(e,t){if(!e)return null;let n=h(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 C(){let{id:e}=be(),t=Se(),{t:n}=i(),d=a(),{showToast:h}=ie(),{hasPermission:C}=je(),[Ve,w]=(0,y.useState)(!1),[He,T]=(0,y.useState)(!1),[Ue,E]=(0,y.useState)(``),[D,O]=(0,y.useState)(null),k=parseInt(e||`0`,10),{data:A,isLoading:We,error:j}=o({queryKey:[`project`,k],queryFn:()=>r.getProject(k),enabled:k>0}),{data:Ge,isLoading:Ke}=o({queryKey:[`project-archives`,k],queryFn:()=>r.getProjectArchives(k),enabled:k>0}),{data:M,isLoading:qe}=o({queryKey:[`project-bom`,k],queryFn:()=>r.getProjectBOM(k),enabled:k>0}),{data:N,isLoading:Je}=o({queryKey:[`project-timeline`,k],queryFn:()=>r.getProjectTimeline(k,20),enabled:k>0}),{data:Ye}=o({queryKey:[`settings`],queryFn:r.getSettings}),{data:P}=o({queryKey:[`project-folders`,k],queryFn:()=>r.getLibraryFoldersByProject(k),enabled:k>0}),{data:F,isLoading:Xe}=o({queryKey:[`project-files`,k],queryFn:()=>r.getLibraryFiles(null,!1,k),enabled:k>0}),Ze=(0,y.useMemo)(()=>{let e=new Map;for(let t of F??[])if(t.folder_id!=null){let n=e.get(t.folder_id)??[];n.push(t),e.set(t.folder_id,n)}return e},[F]),{data:Qe}=o({queryKey:[`project-file-progress`,k],queryFn:()=>r.getProjectFileProgress(k),enabled:k>0}),I=(0,y.useMemo)(()=>{let e=new Map;for(let t of Qe??[])e.set(t.file_id,t.completed_count);return e},[Qe]),L=(0,y.useMemo)(()=>{let e=A?.target_sets;if(!e||!F)return null;let t=F.filter(e=>Pe(e));return t.length===0?null:Math.min(...t.map(t=>Math.min(I.get(t.id)??0,e)))},[A?.target_sets,F,I]),R=Te(Ye?.currency||`USD`),$e=Ye?.time_format||`system`,z=s({mutationFn:e=>r.updateProject(k,e),onSuccess:()=>{d.invalidateQueries({queryKey:[`project`,k]}),d.invalidateQueries({queryKey:[`projects`]}),w(!1),T(!1),h(n(`projectDetail.toast.projectUpdated`),`success`)},onError:e=>{h(e.message,`error`)}}),et=()=>{E(A?.notes||``),T(!0)},tt=()=>{z.mutate({notes:Ue})},nt=()=>{T(!1),E(``)},[B,rt]=(0,y.useState)(``),[it,at]=(0,y.useState)(1),[V,ot]=(0,y.useState)(``),[st,ct]=(0,y.useState)(``),[lt,ut]=(0,y.useState)(``),[dt,H]=(0,y.useState)(!1),[U,ft]=(0,y.useState)(!1),[W,G]=(0,y.useState)(null),[K,pt]=(0,y.useState)(``),[mt,ht]=(0,y.useState)(1),[q,gt]=(0,y.useState)(``),[_t,vt]=(0,y.useState)(``),[yt,bt]=(0,y.useState)(``),[J,Y]=(0,y.useState)({isOpen:!1,title:``,message:``,onConfirm:()=>{}}),X=s({mutationFn:e=>r.createBOMItem(k,e),onSuccess:()=>{d.invalidateQueries({queryKey:[`project-bom`,k]}),d.invalidateQueries({queryKey:[`project`,k]}),rt(``),at(1),ot(``),ct(``),ut(``),H(!1),h(n(`projectDetail.toast.partAdded`),`success`)},onError:e=>h(e.message,`error`)}),Z=s({mutationFn:({itemId:e,data:t})=>r.updateBOMItem(k,e,t),onSuccess:()=>{d.invalidateQueries({queryKey:[`project-bom`,k]}),d.invalidateQueries({queryKey:[`project`,k]}),G(null)},onError:e=>h(e.message,`error`)}),xt=s({mutationFn:e=>r.deleteBOMItem(k,e),onSuccess:()=>{d.invalidateQueries({queryKey:[`project-bom`,k]}),d.invalidateQueries({queryKey:[`project`,k]}),h(n(`projectDetail.toast.partRemoved`),`success`)},onError:e=>h(e.message,`error`)}),St=e=>{e.preventDefault(),B.trim()&&X.mutate({name:B.trim(),quantity_needed:it,unit_price:V?parseFloat(V):void 0,sourcing_url:st.trim()||void 0,remarks:lt.trim()||void 0})},Ct=e=>{let t=e.is_complete?0:e.quantity_needed;Z.mutate({itemId:e.id,data:{quantity_acquired:t}})},wt=(e,t)=>{Y({isOpen:!0,title:n(`projectDetail.bom.deletePart`),message:n(`projectDetail.bom.deleteConfirm`,{name:t}),onConfirm:()=>{Y(e=>({...e,isOpen:!1})),xt.mutate(e)}})},Tt=e=>{G(e),pt(e.name),ht(e.quantity_needed),gt(e.unit_price?.toString()||``),vt(e.sourcing_url||``),bt(e.remarks||``)},Et=e=>{e.preventDefault(),!(!W||!K.trim())&&Z.mutate({itemId:W.id,data:{name:K.trim(),quantity_needed:mt,unit_price:q?parseFloat(q):void 0,sourcing_url:_t.trim()||void 0,remarks:yt.trim()||void 0}})},Dt=()=>{G(null)},Ot=async()=>{try{let{blob:e,filename:t}=await r.exportProjectZip(Number(k)),i=URL.createObjectURL(e),a=document.createElement(`a`);a.href=i,a.download=t||`${A?.name||`project`}_${new Date().toISOString().split(`T`)[0]}.zip`,a.click(),URL.revokeObjectURL(i),h(n(`projectDetail.toast.projectExported`),`success`)}catch(e){h(e.message,`error`)}},kt=s({mutationFn:()=>r.createTemplateFromProject(k),onSuccess:()=>{d.invalidateQueries({queryKey:[`projects`]}),h(n(`projectDetail.toast.templateCreated`),`success`)},onError:e=>h(e.message,`error`)}),At=e=>ue(e,$e,{month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`});if(We)return(0,b.jsx)(`div`,{className:`flex items-center justify-center py-24`,children:(0,b.jsx)(l,{className:`w-8 h-8 animate-spin text-bambu-green`})});if(j||!A)return(0,b.jsxs)(`div`,{className:`text-center py-24`,children:[(0,b.jsx)(`p`,{className:`text-bambu-gray`,children:j?`${n(`common.error`)}: ${j.message}`:n(`projectDetail.notFound`)}),(0,b.jsx)(m,{variant:`secondary`,className:`mt-4`,onClick:()=>t(`/projects`),children:n(`projectDetail.backToProjects`)})]});let Q=A.stats,jt=Q?.progress_percent??0,$=Q?.parts_progress_percent??0;return(0,b.jsxs)(`div`,{className:`p-4 md:p-8 space-y-8`,children:[(0,b.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-bambu-gray`,children:[(0,b.jsx)(_,{to:`/projects`,className:`hover:text-white transition-colors`,children:n(`nav.projects`)}),(0,b.jsx)(ge,{className:`w-4 h-4`}),(0,b.jsx)(`span`,{className:`text-white`,children:A.name})]}),(0,b.jsxs)(`div`,{className:`flex items-start justify-between`,children:[(0,b.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,b.jsx)(`button`,{onClick:()=>t(`/projects`),className:`p-2 rounded-lg bg-bambu-card hover:bg-bambu-dark-tertiary transition-colors`,children:(0,b.jsx)(ee,{className:`w-5 h-5 text-bambu-gray`})}),(0,b.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,b.jsx)(`div`,{className:`w-4 h-4 rounded-full shrink-0`,style:{backgroundColor:A.color||`#6b7280`}}),(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`h1`,{className:`text-2xl font-bold text-white`,children:A.name}),A.description&&(0,b.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:A.description})]})]}),(0,b.jsx)(Le,{status:A.status,t:n})]}),(0,b.jsxs)(`div`,{className:`flex gap-2`,children:[(0,b.jsxs)(m,{variant:`secondary`,onClick:Ot,disabled:!C(`projects:read`),title:C(`projects:read`)?n(`projectDetail.exportProject`):n(`projectDetail.noExportPermission`),children:[(0,b.jsx)(ke,{className:`w-4 h-4 mr-2`}),n(`projectDetail.export`)]}),(0,b.jsxs)(m,{onClick:()=>w(!0),disabled:!C(`projects:update`),title:C(`projects:update`)?void 0:n(`projectDetail.noEditPermission`),children:[(0,b.jsx)(ce,{className:`w-4 h-4 mr-2`}),n(`common.edit`)]})]})]}),(A.target_count||A.target_parts_count||A.target_sets)&&(0,b.jsx)(p,{children:(0,b.jsxs)(f,{className:`p-4 space-y-4`,children:[A.target_count&&(0,b.jsxs)(`div`,{children:[(0,b.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,b.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:n(`projectDetail.progress.platesProgress`)}),(0,b.jsxs)(`span`,{className:`text-sm font-medium text-white`,children:[Q?.total_archives||0,` / `,A.target_count,` `,n(`projectDetail.progress.printJobs`)]})]}),(0,b.jsx)(`div`,{className:`h-3 bg-bambu-dark rounded-full overflow-hidden`,children:(0,b.jsx)(`div`,{className:`h-full transition-all duration-500`,style:{width:`${Math.min(jt,100)}%`,backgroundColor:jt>=100?`#22c55e`:A.color||`#6b7280`}})}),(0,b.jsxs)(`div`,{className:`flex justify-between mt-1`,children:[(0,b.jsx)(`span`,{className:`text-xs text-bambu-gray/70`,children:n(`projectDetail.progress.percentComplete`,{percent:jt.toFixed(0)})}),Q?.remaining_prints!=null&&Q.remaining_prints>0&&(0,b.jsx)(`span`,{className:`text-xs text-bambu-gray/70`,children:n(`projectDetail.progress.remaining`,{count:Q.remaining_prints})})]})]}),A.target_parts_count&&(0,b.jsxs)(`div`,{children:[(0,b.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,b.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:n(`projectDetail.progress.partsProgress`)}),(0,b.jsxs)(`span`,{className:`text-sm font-medium text-white`,children:[Q?.completed_prints||0,` / `,A.target_parts_count,` `,n(`projectDetail.progress.parts`)]})]}),(0,b.jsx)(`div`,{className:`h-3 bg-bambu-dark rounded-full overflow-hidden`,children:(0,b.jsx)(`div`,{className:`h-full transition-all duration-500`,style:{width:`${Math.min($,100)}%`,backgroundColor:$>=100?`#22c55e`:A.color||`#6b7280`}})}),(0,b.jsxs)(`div`,{className:`flex justify-between mt-1`,children:[(0,b.jsx)(`span`,{className:`text-xs text-bambu-gray/70`,children:n(`projectDetail.progress.percentComplete`,{percent:$.toFixed(0)})}),Q?.remaining_parts!=null&&Q.remaining_parts>0&&(0,b.jsx)(`span`,{className:`text-xs text-bambu-gray/70`,children:n(`projectDetail.progress.remaining`,{count:Q.remaining_parts})})]})]}),A.target_sets?(0,b.jsxs)(`div`,{children:[(0,b.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,b.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:n(`projectDetail.progress.setsProgress`)}),(0,b.jsxs)(`span`,{className:`text-sm font-medium text-white`,children:[L??0,` / `,A.target_sets,` `,n(`projectDetail.progress.sets`)]})]}),(0,b.jsx)(`div`,{className:`h-3 bg-bambu-dark rounded-full overflow-hidden`,children:(0,b.jsx)(`div`,{className:`h-full transition-all duration-500`,style:{width:`${Math.min((L??0)/A.target_sets*100,100)}%`,backgroundColor:(L??0)>=A.target_sets?`#22c55e`:A.color||`#6b7280`}})}),(0,b.jsx)(`p`,{className:`text-xs text-bambu-gray/70 mt-1`,children:n(`projectDetail.progress.setsHint`)})]}):null]})}),Q&&(0,b.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-4`,children:[(0,b.jsx)(p,{children:(0,b.jsx)(f,{className:`p-4`,children:(0,b.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,b.jsx)(`div`,{className:`p-2 rounded-lg bg-bambu-dark text-bambu-green`,children:(0,b.jsx)(u,{className:`w-5 h-5`})}),(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`projectDetail.stats.printJobs`)}),(0,b.jsxs)(`p`,{className:`text-xl font-semibold text-white`,children:[Q.total_archives,` `,(0,b.jsx)(`span`,{className:`text-sm font-normal text-bambu-gray`,children:n(`projectDetail.stats.total`)})]}),Q.failed_prints>0&&(0,b.jsx)(`p`,{className:`text-sm text-status-error`,children:n(`projectDetail.stats.failed`,{count:Q.failed_prints})}),(0,b.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`projectDetail.stats.partsPrinted`,{count:Q.completed_prints})})]})]})})}),(0,b.jsx)(Re,{icon:ve,label:n(`projectDetail.stats.printTime`),value:fe(Q.total_print_time_hours),color:`text-yellow-600 dark:text-yellow-400`}),(0,b.jsx)(Re,{icon:g,label:n(`projectDetail.stats.filamentUsed`),value:x(Q.total_filament_grams),color:`text-purple-600 dark:text-purple-400`})]}),A.rollup_stats&&(0,b.jsx)(p,{children:(0,b.jsxs)(f,{className:`p-4`,children:[(0,b.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2 mb-3`,children:[(0,b.jsx)(v,{className:`w-5 h-5`}),n(`projectDetail.rollup.title`,{count:A.descendant_count})]}),(0,b.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-4`,children:[(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.stats.printJobs`)}),(0,b.jsx)(`p`,{className:`text-lg font-semibold text-white`,children:A.rollup_stats.total_archives}),(0,b.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`projectDetail.stats.partsPrinted`,{count:A.rollup_stats.completed_prints})})]}),(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.stats.printTime`)}),(0,b.jsx)(`p`,{className:`text-lg font-semibold text-white`,children:fe(A.rollup_stats.total_print_time_hours)})]}),(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.stats.filamentUsed`)}),(0,b.jsx)(`p`,{className:`text-lg font-semibold text-white`,children:x(A.rollup_stats.total_filament_grams)})]}),(()=>{let e=A.rollup_stats.estimated_cost+A.rollup_stats.total_energy_cost+(A.rollup_stats.total_wear_cost??0)+A.rollup_stats.bom_cost;return e<=0?null:(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.cost.totalCost`)}),(0,b.jsxs)(`p`,{className:`text-lg font-semibold text-bambu-green`,children:[R,e.toFixed(2)]})]})})()]}),A.rollup_stats.progress_percent!==null&&(0,b.jsxs)(`div`,{className:`mt-4`,children:[(0,b.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,b.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:n(`projectDetail.rollup.progress`)}),(0,b.jsx)(`span`,{className:`text-sm font-medium text-white`,children:n(`projectDetail.rollup.percentComplete`,{percent:A.rollup_stats.progress_percent.toFixed(0)})})]}),(0,b.jsx)(`div`,{className:`h-3 bg-bambu-dark rounded-full overflow-hidden`,children:(0,b.jsx)(`div`,{className:`h-full transition-all duration-500`,style:{width:`${Math.min(A.rollup_stats.progress_percent,100)}%`,backgroundColor:A.rollup_stats.progress_percent>=100?`#22c55e`:A.color||`#6b7280`}})})]})]})}),Q&&(()=>{let e=Q.estimated_cost+Q.total_energy_cost+(Q.total_wear_cost??0)+Q.bom_cost;return Q.estimated_cost>0||e>0||A.budget!==null})()&&(0,b.jsx)(p,{children:(0,b.jsxs)(f,{className:`p-4`,children:[(0,b.jsx)(`h2`,{className:`text-lg font-semibold text-white mb-3`,children:n(`projectDetail.cost.title`)}),(0,b.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-4`,children:[(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.cost.filamentCost`)}),(0,b.jsxs)(`p`,{className:`text-lg font-semibold text-white`,children:[R,Q.estimated_cost.toFixed(2)]})]}),Q.total_energy_kwh>0&&(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.cost.energy`)}),(0,b.jsxs)(`p`,{className:`text-lg font-semibold text-white`,children:[Q.total_energy_kwh.toFixed(3),` kWh`,Q.total_energy_cost>0&&(0,b.jsxs)(`span`,{className:`text-sm text-bambu-gray ml-1`,children:[`(`,R,Q.total_energy_cost.toFixed(2),`)`]})]})]}),(Q.total_wear_cost??0)>0&&(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.cost.wear`)}),(0,b.jsxs)(`p`,{className:`text-lg font-semibold text-white`,children:[R,Q.total_wear_cost.toFixed(2)]})]}),(()=>{let e=Q.estimated_cost+Q.total_energy_cost+(Q.total_wear_cost??0)+Q.bom_cost;return e<=0?null:(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.cost.totalCost`)}),(0,b.jsxs)(`p`,{className:`text-lg font-semibold text-bambu-green`,children:[R,e.toFixed(2)]}),Q.bom_cost>0&&(0,b.jsx)(`p`,{className:`text-xs text-bambu-gray/70`,children:n(`projectDetail.cost.includesBom`)})]})})(),A.budget!==null&&(()=>{let e=Q.estimated_cost+Q.total_energy_cost+(Q.total_wear_cost??0)+Q.bom_cost,t=A.budget-e;return(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.cost.budget`)}),(0,b.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[n(`projectDetail.cost.total`),`: `,(0,b.jsxs)(`span`,{className:`text-white font-semibold`,children:[R,A.budget.toFixed(2)]})]}),(0,b.jsxs)(`p`,{className:`text-sm ${t>=0?`text-bambu-green`:`text-red-700 dark:text-red-400`}`,children:[n(`projectDetail.cost.remaining`),`: `,(0,b.jsxs)(`span`,{className:`font-semibold`,children:[R,t.toFixed(2)]})]})]})})()]})]})}),A.children&&A.children.length>0&&(0,b.jsx)(p,{children:(0,b.jsxs)(f,{className:`p-4`,children:[(0,b.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2 mb-3`,children:[(0,b.jsx)(v,{className:`w-5 h-5`}),n(`projectDetail.subProjects.title`,{count:A.children.length})]}),(0,b.jsx)(`div`,{className:`space-y-2`,children:A.children.map(e=>(0,b.jsxs)(_,{to:`/projects/${e.id}`,className:`flex items-center justify-between gap-4 p-3 bg-bambu-dark rounded-lg hover:bg-bambu-dark-tertiary transition-colors`,children:[(0,b.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0`,children:[(0,b.jsx)(`div`,{className:`w-3 h-3 rounded-full flex-shrink-0`,style:{backgroundColor:e.color||`#6b7280`}}),(0,b.jsx)(`span`,{className:`text-white truncate`,children:e.name}),(0,b.jsx)(`span`,{className:`text-xs px-2 py-0.5 rounded flex-shrink-0 ${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.descendant_count>0&&(0,b.jsxs)(`span`,{className:`text-xs text-bambu-gray flex-shrink-0 inline-flex items-center gap-1`,children:[(0,b.jsx)(v,{className:`w-3 h-3`}),e.descendant_count]})]}),(0,b.jsxs)(`div`,{className:`flex items-center gap-4 text-sm text-bambu-gray flex-shrink-0`,children:[e.total_archives>0&&(0,b.jsx)(`span`,{className:`hidden sm:inline`,children:n(`projectDetail.subProjects.jobs`,{count:e.total_archives})}),e.total_filament_grams>0&&(0,b.jsx)(`span`,{className:`hidden md:inline`,children:x(e.total_filament_grams)}),e.total_cost>0&&(0,b.jsxs)(`span`,{className:`hidden md:inline`,children:[R,e.total_cost.toFixed(2)]}),e.progress_percent!==null&&(0,b.jsxs)(`span`,{children:[e.progress_percent.toFixed(0),`%`]})]})]},e.id))})]})}),A.parent_id&&A.parent_name&&(0,b.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,b.jsx)(De,{className:`w-4 h-4 text-bambu-gray`}),(0,b.jsx)(`span`,{className:`text-bambu-gray`,children:n(`projectDetail.partOf`)}),(0,b.jsx)(_,{to:`/projects/${A.parent_id}`,className:`text-bambu-green hover:underline`,children:A.parent_name})]}),(A.tags||A.due_date||A.priority!==`normal`)&&(0,b.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4`,children:[A.priority&&A.priority!==`normal`&&(0,b.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,b.jsx)(`span`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.priorityLabel`)}),(0,b.jsx)(Be,{priority:A.priority,t:n})]}),A.due_date&&(0,b.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,b.jsx)(ne,{className:`w-4 h-4 text-bambu-gray`}),(0,b.jsx)(`span`,{className:`text-sm text-white`,children:de(A.due_date,{year:`numeric`,month:`short`,day:`numeric`})}),S(A.due_date,n)&&(0,b.jsxs)(`span`,{className:`text-xs ${S(A.due_date,n).color}`,children:[`(`,S(A.due_date,n).label,`)`]})]}),A.tags&&(0,b.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,b.jsx)(ye,{className:`w-4 h-4 text-bambu-gray`}),(0,b.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:A.tags.split(`,`).map((e,t)=>(0,b.jsx)(`span`,{className:`px-2 py-0.5 bg-bambu-dark-tertiary text-bambu-gray text-xs rounded`,children:e.trim()},t))})]})]}),(0,b.jsx)(p,{children:(0,b.jsxs)(f,{className:`p-4`,children:[(0,b.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,b.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,b.jsx)(Ae,{className:`w-5 h-5`}),n(`projectDetail.notes.title`)]}),He?(0,b.jsxs)(`div`,{className:`flex gap-2`,children:[(0,b.jsxs)(m,{variant:`secondary`,size:`sm`,onClick:nt,disabled:z.isPending,children:[(0,b.jsx)(le,{className:`w-4 h-4 mr-1`}),n(`common.cancel`)]}),(0,b.jsxs)(m,{size:`sm`,onClick:tt,disabled:z.isPending,children:[z.isPending?(0,b.jsx)(l,{className:`w-4 h-4 animate-spin mr-1`}):(0,b.jsx)(xe,{className:`w-4 h-4 mr-1`}),n(`common.save`)]})]}):(0,b.jsxs)(m,{variant:`secondary`,size:`sm`,onClick:et,disabled:!C(`projects:update`),title:C(`projects:update`)?void 0:n(`projectDetail.notes.noEditPermission`),children:[(0,b.jsx)(ce,{className:`w-4 h-4 mr-1`}),n(`common.edit`)]})]}),He?(0,b.jsx)(te,{content:Ue,onChange:E,placeholder:n(`projectDetail.notes.placeholder`)}):A.notes?(0,b.jsx)(`div`,{className:`prose prose-invert prose-sm max-w-none`,dangerouslySetInnerHTML:{__html:Ne.sanitize(A.notes)}}):(0,b.jsx)(`p`,{className:`text-bambu-gray/70 text-sm italic`,children:n(`projectDetail.notes.empty`)})]})}),(0,b.jsx)(p,{children:(0,b.jsxs)(f,{className:`p-4`,children:[(0,b.jsx)(`div`,{className:`flex items-center justify-between mb-3`,children:(0,b.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,b.jsx)(Oe,{className:`w-5 h-5`}),n(`projectDetail.files.title`)]})}),(0,b.jsxs)(`p`,{className:`text-xs text-bambu-gray mb-3`,children:[(0,b.jsx)(_,{to:`/files`,className:`text-bambu-green hover:underline`,children:n(`projectDetail.files.linkFolders`)}),` `,n(`projectDetail.files.forQuickAccess`)]}),P&&P.length>0?(0,b.jsx)(`div`,{className:`space-y-4`,children:P.map(e=>{let t=Ze.get(e.id)??[],i=Xe;return(0,b.jsxs)(`div`,{children:[(0,b.jsxs)(_,{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,b.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0`,children:[(0,b.jsx)(Oe,{className:`w-5 h-5 text-bambu-green shrink-0`}),(0,b.jsxs)(`div`,{className:`min-w-0`,children:[(0,b.jsx)(`p`,{className:`text-sm text-white truncate`,children:e.name}),(0,b.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`projectDetail.files.fileCount`,{count:e.file_count})})]})]}),(0,b.jsx)(ge,{className:`w-4 h-4 text-bambu-gray shrink-0`})]}),i?(0,b.jsx)(`div`,{className:`flex items-center gap-2 px-3 py-2 text-bambu-gray text-sm`,children:(0,b.jsx)(l,{className:`w-4 h-4 animate-spin`})}):t.length===0?(0,b.jsx)(`p`,{className:`text-bambu-gray/60 text-xs italic px-3`,children:n(`projectDetail.files.noFiles`)}):(0,b.jsx)(`div`,{className:`space-y-1 pl-3`,children:t.map(e=>{let t=Pe(e);return(0,b.jsxs)(`div`,{className:`flex items-center gap-3 p-2 rounded-lg hover:bg-bambu-dark-tertiary transition-colors`,children:[(0,b.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,b.jsx)(`img`,{src:r.getLibraryFileThumbnailUrl(e.id),alt:e.print_name||e.filename,className:`w-full h-full object-cover`}):(0,b.jsx)(oe,{className:`w-5 h-5 text-bambu-gray/40`})}),(0,b.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,b.jsx)(`p`,{className:`text-sm text-white truncate`,title:e.print_name||e.filename,children:e.print_name||e.filename}),(0,b.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&&(()=>{let t=I.get(e.id)??0,r=A.target_sets;if(!r)return t>0?(0,b.jsxs)(`span`,{className:`shrink-0 text-xs px-1.5 py-0.5 rounded-full bg-bambu-dark text-bambu-gray`,title:n(`projectDetail.files.printedCount`,{count:t}),children:[t,`×`]}):null;let i=Math.min(t/r*100,100),a=t>=r?`text-status-ok`:t>0?`text-status-warning`:`text-bambu-gray`,o=t>=r?`bg-status-ok`:t>0?`bg-status-warning`:`bg-bambu-gray`;return(0,b.jsxs)(`div`,{className:`shrink-0 w-20`,title:n(`projectDetail.files.progressTooltip`,{done:t,target:r}),children:[(0,b.jsxs)(`p`,{className:`text-xs font-medium text-right ${a}`,children:[t,` / `,r]}),(0,b.jsx)(`div`,{className:`h-1 bg-bambu-dark rounded-full overflow-hidden mt-1`,children:(0,b.jsx)(`div`,{className:`h-full ${o}`,style:{width:`${i}%`}})})]})})(),t&&(0,b.jsx)(`div`,{className:`flex items-center gap-1 shrink-0`,children:(0,b.jsx)(`button`,{onClick:()=>O(e),title:n(`common.print`),className:`p-1.5 rounded hover:bg-bambu-green/20 text-bambu-green transition-colors`,children:(0,b.jsx)(g,{className:`w-4 h-4`})})})]},e.id)})})]},e.id)})}):(0,b.jsx)(`p`,{className:`text-bambu-gray/70 text-sm italic`,children:n(`projectDetail.files.empty`)})]})}),(0,b.jsx)(p,{children:(0,b.jsxs)(f,{className:`p-4`,children:[(0,b.jsxs)(`div`,{className:`flex items-center justify-between mb-4`,children:[(0,b.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,b.jsx)(Me,{className:`w-5 h-5`}),n(`projectDetail.bom.title`),Q&&Q.bom_total_items>0&&(0,b.jsxs)(`span`,{className:`text-sm font-normal text-bambu-gray`,children:[`(`,n(`projectDetail.bom.acquired`,{completed:Q.bom_completed_items,total:Q.bom_total_items}),`)`]})]}),(0,b.jsxs)(`div`,{className:`flex items-center gap-2`,children:[M&&M.some(e=>e.is_complete)&&(0,b.jsx)(`button`,{onClick:()=>ft(!U),className:`text-xs px-2 py-1 rounded transition-colors ${U?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,children:n(U?`projectDetail.bom.showAll`:`projectDetail.bom.hideDone`)}),!dt&&(0,b.jsxs)(m,{variant:`secondary`,size:`sm`,onClick:()=>H(!0),disabled:!C(`projects:update`),title:C(`projects:update`)?void 0:n(`projectDetail.bom.noAddPermission`),children:[(0,b.jsx)(Ce,{className:`w-4 h-4 mr-1`}),n(`projectDetail.bom.addPart`)]})]})]}),dt&&(0,b.jsxs)(`form`,{onSubmit:St,className:`bg-bambu-dark rounded-lg p-4 mb-4 space-y-3`,children:[(0,b.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3`,children:[(0,b.jsx)(`input`,{type:`text`,value:B,onChange:e=>rt(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,b.jsxs)(`div`,{className:`flex gap-2`,children:[(0,b.jsx)(_e,{value:it,onChange:at,fallback: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,b.jsx)(`input`,{type:`number`,step:`0.01`,value:V,onChange:e=>ot(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:R})})]})]}),(0,b.jsx)(`input`,{type:`url`,value:st,onChange:e=>ct(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,b.jsx)(`input`,{type:`text`,value:lt,onChange:e=>ut(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,b.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,b.jsx)(m,{type:`button`,variant:`secondary`,size:`sm`,onClick:()=>H(!1),children:n(`common.cancel`)}),(0,b.jsx)(m,{type:`submit`,size:`sm`,disabled:!B.trim()||X.isPending,children:X.isPending?(0,b.jsx)(l,{className:`w-4 h-4 animate-spin`}):n(`projectDetail.bom.addPart`)})]})]}),qe?(0,b.jsx)(`div`,{className:`flex items-center justify-center py-4`,children:(0,b.jsx)(l,{className:`w-6 h-6 animate-spin text-bambu-green`})}):M&&M.length>0?(0,b.jsxs)(`div`,{className:`space-y-2`,children:[M.filter(e=>!U||!e.is_complete).map(e=>(0,b.jsx)(`div`,{className:`p-3 rounded-lg transition-colors ${e.is_complete?`bg-status-ok/10`:`bg-bambu-dark`}`,children:W?.id===e.id?(0,b.jsxs)(`form`,{onSubmit:Et,className:`space-y-3`,children:[(0,b.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3`,children:[(0,b.jsx)(`input`,{type:`text`,value:K,onChange:e=>pt(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,b.jsxs)(`div`,{className:`flex gap-2`,children:[(0,b.jsx)(_e,{value:mt,onChange:ht,fallback: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,b.jsx)(`input`,{type:`number`,step:`0.01`,value:q,onChange:e=>gt(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:R})})]})]}),(0,b.jsx)(`input`,{type:`url`,value:_t,onChange:e=>vt(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,b.jsx)(`input`,{type:`text`,value:yt,onChange:e=>bt(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,b.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,b.jsx)(m,{type:`button`,variant:`secondary`,size:`sm`,onClick:Dt,children:n(`common.cancel`)}),(0,b.jsx)(m,{type:`submit`,size:`sm`,disabled:!K.trim()||Z.isPending,children:Z.isPending?(0,b.jsx)(l,{className:`w-4 h-4 animate-spin`}):n(`common.save`)})]})]}):(0,b.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,b.jsx)(`button`,{onClick:()=>C(`projects:update`)&&Ct(e),disabled:Z.isPending||!C(`projects:update`),title:C(`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`:C(`projects:update`)?`border-bambu-gray hover:border-bambu-green`:`border-bambu-gray/50 cursor-not-allowed`}`,children:e.is_complete&&(0,b.jsx)(c,{className:`w-3 h-3`})}),(0,b.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,b.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,b.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,b.jsxs)(`p`,{className:`text-sm font-medium ${e.is_complete?`text-bambu-gray line-through`:`text-white`}`,children:[e.name,(0,b.jsxs)(`span`,{className:`text-bambu-gray font-normal ml-2`,children:[`x`,e.quantity_needed]})]}),e.unit_price!==null&&(0,b.jsxs)(`span`,{className:`text-xs text-bambu-green whitespace-nowrap`,children:[R,(e.unit_price*e.quantity_needed).toFixed(2)]})]}),(0,b.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,b.jsx)(`button`,{onClick:()=>C(`projects:update`)&&Tt(e),disabled:!C(`projects:update`),className:`p-1 rounded transition-colors shrink-0 ${C(`projects:update`)?`hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white`:`text-bambu-gray/50 cursor-not-allowed`}`,title:C(`projects:update`)?n(`common.edit`):n(`projectDetail.bom.noEditPermission`),children:(0,b.jsx)(pe,{className:`w-4 h-4`})}),(0,b.jsx)(`button`,{onClick:()=>C(`projects:update`)&&wt(e.id,e.name),disabled:!C(`projects:update`),className:`p-1 rounded transition-colors shrink-0 ${C(`projects:update`)?`hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-red-400`:`text-bambu-gray/50 cursor-not-allowed`}`,title:C(`projects:update`)?n(`common.delete`):n(`projectDetail.bom.noDeletePermission`),children:(0,b.jsx)(me,{className:`w-4 h-4`})})]})]}),e.sourcing_url&&(0,b.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,b.jsx)(he,{className:`w-3 h-3 shrink-0`}),(0,b.jsx)(`span`,{className:`truncate`,children:(()=>{try{return new URL(e.sourcing_url).hostname.replace(`www.`,``)}catch{return e.sourcing_url}})()})]}),e.remarks&&(0,b.jsx)(`p`,{className:`mt-1 text-xs text-bambu-gray/80 italic`,children:e.remarks})]})]})},e.id)),Q&&Q.bom_cost>0&&(0,b.jsxs)(`div`,{className:`pt-2 mt-2 border-t border-bambu-dark-tertiary flex justify-between text-sm`,children:[(0,b.jsx)(`span`,{className:`text-bambu-gray`,children:n(`projectDetail.bom.totalCost`)}),(0,b.jsxs)(`span`,{className:`text-white font-medium`,children:[R,Q.bom_cost.toFixed(2)]})]})]}):(0,b.jsx)(`p`,{className:`text-bambu-gray/70 text-sm italic`,children:n(`projectDetail.bom.empty`)})]})}),(0,b.jsx)(p,{children:(0,b.jsxs)(f,{className:`p-4`,children:[(0,b.jsx)(`div`,{className:`flex items-center justify-between mb-3`,children:(0,b.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,b.jsx)(se,{className:`w-5 h-5`}),n(`projectDetail.timeline.title`)]})}),Je?(0,b.jsx)(`div`,{className:`flex items-center justify-center py-4`,children:(0,b.jsx)(l,{className:`w-6 h-6 animate-spin text-bambu-green`})}):N&&N.length>0?(0,b.jsx)(`div`,{className:`space-y-3`,children:N.slice(0,10).map((e,t)=>(0,b.jsxs)(`div`,{className:`flex gap-3`,children:[(0,b.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,b.jsx)(c,{className:`w-4 h-4`}),e.event_type===`print_failed`&&(0,b.jsx)(re,{className:`w-4 h-4`}),e.event_type===`print_started`&&(0,b.jsx)(g,{className:`w-4 h-4`}),e.event_type===`queued`&&(0,b.jsx)(Ie,{className:`w-4 h-4`}),e.event_type===`project_created`&&(0,b.jsx)(Ce,{className:`w-4 h-4`})]}),(0,b.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,b.jsx)(`p`,{className:`text-sm text-white`,children:e.title}),e.description&&(0,b.jsx)(`p`,{className:`text-xs text-bambu-gray truncate`,children:e.description}),(0,b.jsx)(`p`,{className:`text-xs text-bambu-gray/70`,children:At(e.timestamp)})]})]},t))}):(0,b.jsx)(`p`,{className:`text-bambu-gray/70 text-sm italic`,children:n(`projectDetail.timeline.empty`)})]})}),!A.is_template&&(0,b.jsx)(`div`,{className:`flex justify-end`,children:(0,b.jsxs)(m,{variant:`secondary`,size:`sm`,onClick:()=>kt.mutate(),disabled:kt.isPending||!C(`projects:create`),title:C(`projects:create`)?void 0:n(`projectDetail.template.noCreatePermission`),children:[kt.isPending?(0,b.jsx)(l,{className:`w-4 h-4 animate-spin mr-2`}):(0,b.jsx)(ae,{className:`w-4 h-4 mr-2`}),n(`projectDetail.template.saveAsTemplate`)]})}),Q&&(Q.queued_prints>0||Q.in_progress_prints>0)&&(0,b.jsx)(p,{children:(0,b.jsxs)(f,{className:`p-4`,children:[(0,b.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,b.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,b.jsx)(Ie,{className:`w-5 h-5`}),n(`projectDetail.queue.title`)]}),(0,b.jsx)(_,{to:`/queue?project=${k}`,className:`text-sm text-bambu-green hover:underline`,children:n(`projectDetail.queue.viewAll`)})]}),(0,b.jsxs)(`div`,{className:`flex items-center gap-4 text-sm`,children:[Q.in_progress_prints>0&&(0,b.jsx)(`span`,{className:`text-yellow-700 dark:text-yellow-400`,children:n(`projectDetail.queue.printing`,{count:Q.in_progress_prints})}),Q.queued_prints>0&&(0,b.jsx)(`span`,{className:`text-bambu-gray`,children:n(`projectDetail.queue.queued`,{count:Q.queued_prints})})]})]})}),(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`div`,{className:`flex items-center justify-between mb-4`,children:(0,b.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,b.jsx)(u,{className:`w-5 h-5`}),n(`projectDetail.prints.title`,{count:Ge?.length||0})]})}),Ke?(0,b.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,b.jsx)(l,{className:`w-6 h-6 animate-spin text-bambu-green`})}):(0,b.jsx)(ze,{archives:Ge||[],t:n})]}),Ve&&(0,b.jsx)(Fe,{t:n,currencySymbol:R,project:{...A,archive_count:Q?.total_archives||0,total_items:Q?.total_items||0,completed_count:Q?.completed_prints||0,failed_count:Q?.failed_prints||0,queue_count:Q?.queued_prints||0,progress_percent:Q?.progress_percent||null,child_count:A.children?.length??0,archives:[]},onClose:()=>w(!1),onSave:e=>z.mutate(e),isLoading:z.isPending}),J.isOpen&&(0,b.jsx)(we,{title:J.title,message:J.message,confirmText:n(`common.delete`),variant:`danger`,onConfirm:J.onConfirm,onCancel:()=>Y(e=>({...e,isOpen:!1}))}),D&&(0,b.jsx)(Ee,{mode:`create`,libraryFileId:D.id,archiveName:D.print_name||D.filename,projectId:k,onClose:()=>O(null),onSuccess:()=>{O(null),d.invalidateQueries({queryKey:[`archives`]}),d.invalidateQueries({queryKey:[`queue`]})}})]})}export{C as ProjectDetailPage}; \ No newline at end of file +import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,w as i}from"./client-DnySrlFv.js";import{n as a}from"./QueryClientProvider-Ce8_sN3w.js";import{t as o}from"./useQuery-BBCjCezC.js";import{t as s}from"./useMutation-B-Tr2hIP.js";import{t as ee}from"./arrow-left-0Q6F2rjC.js";import{t as te}from"./RichTextEditor-CsfJOD7X.js";import{t as ne}from"./calendar-BLKPnWqV.js";import{n as re}from"./info-ROUoQhJR.js";import{n as ie,r as c}from"./ToastContext-BRX0SW3C.js";import{t as ae}from"./copy-Cu_0GKCU.js";import{t as oe}from"./file-box-04V4jZ9_.js";import{t as se}from"./history-B4lOLL01.js";import{t as l}from"./loader-circle-BEmFtawu.js";import{t as u}from"./package-BGUevlqS.js";import{t as ce}from"./pen-line-BWR04BX-.js";import{t as d}from"./triangle-alert-Dt_1FcBy.js";import{t as le}from"./x-DR-Trv6U.js";import{n as f,t as p}from"./Card-Bzc64K35.js";import{t as m}from"./Button-DDr6eAFy.js";import{a as ue,i as de,s as fe,v as h}from"./date-G9KUauqz.js";import{$t as pe,At as me,Cn as he,Jt as g,Mn as ge,N as _e,On as ve,Pt as ye,Rn as _,Un as be,Ut as xe,Vn as Se,Zt as Ce,_t as we,at as Te,b as Ee,cn as De,vn as Oe,wn as ke,xn as Ae,yt as je,zt as Me}from"./index-Cxa-KVmA.js";import{t as Ne}from"./purify.es-F_7NWVtX.js";import{n as Pe}from"./libraryFiles-B0B1SFfn.js";import{ProjectModal as Fe,n as v,t as Ie}from"./ProjectsPage-CBeO6wA6.js";var y=e(n(),1),b=t();function x(e){return e>=1e3?`${(e/1e3).toFixed(2)}kg`:`${Math.round(e)}g`}function Le({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,b.jsx)(`span`,{className:`px-2 py-1 rounded text-sm font-medium ${r}`,children:i[e]||e.charAt(0).toUpperCase()+e.slice(1)})}function Re({icon:e,label:t,value:n,subValue:r,hint:i,color:a=`text-bambu-gray`}){return(0,b.jsx)(p,{children:(0,b.jsx)(f,{className:`p-4`,children:(0,b.jsxs)(`div`,{className:`flex items-center gap-3`,title:i,children:[(0,b.jsx)(`div`,{className:`p-2 rounded-lg bg-bambu-dark ${a}`,children:(0,b.jsx)(e,{className:`w-5 h-5`})}),(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:t}),(0,b.jsx)(`p`,{className:`text-xl font-semibold text-white`,children:n}),r&&(0,b.jsx)(`p`,{className:`text-xs text-bambu-gray/70`,children:r})]})]})})})}function ze({archives:e,t}){return e.length===0?(0,b.jsxs)(`div`,{className:`text-center py-8 text-bambu-gray`,children:[(0,b.jsx)(u,{className:`w-12 h-12 mx-auto mb-2 opacity-50`}),(0,b.jsx)(`p`,{children:t(`projectDetail.noPrints`)})]}):(0,b.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,b.jsxs)(_,{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,b.jsx)(`img`,{src:r.getArchiveThumbnail(e.id),alt:e.print_name||`Print`,className:`w-full h-full object-cover`}):(0,b.jsx)(`div`,{className:`w-full h-full flex items-center justify-center text-bambu-gray`,children:(0,b.jsx)(u,{className:`w-8 h-8`})}),e.status===`failed`&&(0,b.jsx)(`div`,{className:`absolute inset-0 bg-red-500/30 flex items-center justify-center`,children:(0,b.jsx)(re,{className:`w-8 h-8 text-white`})}),e.status===`completed`&&(0,b.jsx)(`div`,{className:`absolute top-1 right-1`,children:(0,b.jsx)(c,{className:`w-4 h-4 text-bambu-green`})}),(0,b.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,b.jsx)(`p`,{className:`text-xs text-white truncate`,children:e.print_name||`Unknown`})})]},e.id))})}function Be({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,b.jsxs)(`span`,{className:`px-2 py-1 rounded text-xs font-medium flex items-center gap-1 ${r}`,children:[e===`urgent`&&(0,b.jsx)(d,{className:`w-3 h-3`}),i]})}function S(e,t){if(!e)return null;let n=h(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 C(){let{id:e}=be(),t=Se(),{t:n}=i(),d=a(),{showToast:h}=ie(),{hasPermission:C}=je(),[Ve,w]=(0,y.useState)(!1),[He,T]=(0,y.useState)(!1),[Ue,E]=(0,y.useState)(``),[D,O]=(0,y.useState)(null),k=parseInt(e||`0`,10),{data:A,isLoading:We,error:j}=o({queryKey:[`project`,k],queryFn:()=>r.getProject(k),enabled:k>0}),{data:Ge,isLoading:Ke}=o({queryKey:[`project-archives`,k],queryFn:()=>r.getProjectArchives(k),enabled:k>0}),{data:M,isLoading:qe}=o({queryKey:[`project-bom`,k],queryFn:()=>r.getProjectBOM(k),enabled:k>0}),{data:N,isLoading:Je}=o({queryKey:[`project-timeline`,k],queryFn:()=>r.getProjectTimeline(k,20),enabled:k>0}),{data:Ye}=o({queryKey:[`settings`],queryFn:r.getSettings}),{data:P}=o({queryKey:[`project-folders`,k],queryFn:()=>r.getLibraryFoldersByProject(k),enabled:k>0}),{data:F,isLoading:Xe}=o({queryKey:[`project-files`,k],queryFn:()=>r.getLibraryFiles(null,!1,k),enabled:k>0}),Ze=(0,y.useMemo)(()=>{let e=new Map;for(let t of F??[])if(t.folder_id!=null){let n=e.get(t.folder_id)??[];n.push(t),e.set(t.folder_id,n)}return e},[F]),{data:Qe}=o({queryKey:[`project-file-progress`,k],queryFn:()=>r.getProjectFileProgress(k),enabled:k>0}),I=(0,y.useMemo)(()=>{let e=new Map;for(let t of Qe??[])e.set(t.file_id,t.completed_count);return e},[Qe]),L=(0,y.useMemo)(()=>{let e=A?.target_sets;if(!e||!F)return null;let t=F.filter(e=>Pe(e));return t.length===0?null:Math.min(...t.map(t=>Math.min(I.get(t.id)??0,e)))},[A?.target_sets,F,I]),R=Te(Ye?.currency||`USD`),$e=Ye?.time_format||`system`,z=s({mutationFn:e=>r.updateProject(k,e),onSuccess:()=>{d.invalidateQueries({queryKey:[`project`,k]}),d.invalidateQueries({queryKey:[`projects`]}),w(!1),T(!1),h(n(`projectDetail.toast.projectUpdated`),`success`)},onError:e=>{h(e.message,`error`)}}),et=()=>{E(A?.notes||``),T(!0)},tt=()=>{z.mutate({notes:Ue})},nt=()=>{T(!1),E(``)},[B,rt]=(0,y.useState)(``),[it,at]=(0,y.useState)(1),[V,ot]=(0,y.useState)(``),[st,ct]=(0,y.useState)(``),[lt,ut]=(0,y.useState)(``),[dt,H]=(0,y.useState)(!1),[U,ft]=(0,y.useState)(!1),[W,G]=(0,y.useState)(null),[K,pt]=(0,y.useState)(``),[mt,ht]=(0,y.useState)(1),[q,gt]=(0,y.useState)(``),[_t,vt]=(0,y.useState)(``),[yt,bt]=(0,y.useState)(``),[J,Y]=(0,y.useState)({isOpen:!1,title:``,message:``,onConfirm:()=>{}}),X=s({mutationFn:e=>r.createBOMItem(k,e),onSuccess:()=>{d.invalidateQueries({queryKey:[`project-bom`,k]}),d.invalidateQueries({queryKey:[`project`,k]}),rt(``),at(1),ot(``),ct(``),ut(``),H(!1),h(n(`projectDetail.toast.partAdded`),`success`)},onError:e=>h(e.message,`error`)}),Z=s({mutationFn:({itemId:e,data:t})=>r.updateBOMItem(k,e,t),onSuccess:()=>{d.invalidateQueries({queryKey:[`project-bom`,k]}),d.invalidateQueries({queryKey:[`project`,k]}),G(null)},onError:e=>h(e.message,`error`)}),xt=s({mutationFn:e=>r.deleteBOMItem(k,e),onSuccess:()=>{d.invalidateQueries({queryKey:[`project-bom`,k]}),d.invalidateQueries({queryKey:[`project`,k]}),h(n(`projectDetail.toast.partRemoved`),`success`)},onError:e=>h(e.message,`error`)}),St=e=>{e.preventDefault(),B.trim()&&X.mutate({name:B.trim(),quantity_needed:it,unit_price:V?parseFloat(V):void 0,sourcing_url:st.trim()||void 0,remarks:lt.trim()||void 0})},Ct=e=>{let t=e.is_complete?0:e.quantity_needed;Z.mutate({itemId:e.id,data:{quantity_acquired:t}})},wt=(e,t)=>{Y({isOpen:!0,title:n(`projectDetail.bom.deletePart`),message:n(`projectDetail.bom.deleteConfirm`,{name:t}),onConfirm:()=>{Y(e=>({...e,isOpen:!1})),xt.mutate(e)}})},Tt=e=>{G(e),pt(e.name),ht(e.quantity_needed),gt(e.unit_price?.toString()||``),vt(e.sourcing_url||``),bt(e.remarks||``)},Et=e=>{e.preventDefault(),!(!W||!K.trim())&&Z.mutate({itemId:W.id,data:{name:K.trim(),quantity_needed:mt,unit_price:q?parseFloat(q):void 0,sourcing_url:_t.trim()||void 0,remarks:yt.trim()||void 0}})},Dt=()=>{G(null)},Ot=async()=>{try{let{blob:e,filename:t}=await r.exportProjectZip(Number(k)),i=URL.createObjectURL(e),a=document.createElement(`a`);a.href=i,a.download=t||`${A?.name||`project`}_${new Date().toISOString().split(`T`)[0]}.zip`,a.click(),URL.revokeObjectURL(i),h(n(`projectDetail.toast.projectExported`),`success`)}catch(e){h(e.message,`error`)}},kt=s({mutationFn:()=>r.createTemplateFromProject(k),onSuccess:()=>{d.invalidateQueries({queryKey:[`projects`]}),h(n(`projectDetail.toast.templateCreated`),`success`)},onError:e=>h(e.message,`error`)}),At=e=>ue(e,$e,{month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`});if(We)return(0,b.jsx)(`div`,{className:`flex items-center justify-center py-24`,children:(0,b.jsx)(l,{className:`w-8 h-8 animate-spin text-bambu-green`})});if(j||!A)return(0,b.jsxs)(`div`,{className:`text-center py-24`,children:[(0,b.jsx)(`p`,{className:`text-bambu-gray`,children:j?`${n(`common.error`)}: ${j.message}`:n(`projectDetail.notFound`)}),(0,b.jsx)(m,{variant:`secondary`,className:`mt-4`,onClick:()=>t(`/projects`),children:n(`projectDetail.backToProjects`)})]});let Q=A.stats,jt=Q?.progress_percent??0,$=Q?.parts_progress_percent??0;return(0,b.jsxs)(`div`,{className:`p-4 md:p-8 space-y-8`,children:[(0,b.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-bambu-gray`,children:[(0,b.jsx)(_,{to:`/projects`,className:`hover:text-white transition-colors`,children:n(`nav.projects`)}),(0,b.jsx)(ge,{className:`w-4 h-4`}),(0,b.jsx)(`span`,{className:`text-white`,children:A.name})]}),(0,b.jsxs)(`div`,{className:`flex items-start justify-between`,children:[(0,b.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,b.jsx)(`button`,{onClick:()=>t(`/projects`),className:`p-2 rounded-lg bg-bambu-card hover:bg-bambu-dark-tertiary transition-colors`,children:(0,b.jsx)(ee,{className:`w-5 h-5 text-bambu-gray`})}),(0,b.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,b.jsx)(`div`,{className:`w-4 h-4 rounded-full shrink-0`,style:{backgroundColor:A.color||`#6b7280`}}),(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`h1`,{className:`text-2xl font-bold text-white`,children:A.name}),A.description&&(0,b.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:A.description})]})]}),(0,b.jsx)(Le,{status:A.status,t:n})]}),(0,b.jsxs)(`div`,{className:`flex gap-2`,children:[(0,b.jsxs)(m,{variant:`secondary`,onClick:Ot,disabled:!C(`projects:read`),title:C(`projects:read`)?n(`projectDetail.exportProject`):n(`projectDetail.noExportPermission`),children:[(0,b.jsx)(ke,{className:`w-4 h-4 mr-2`}),n(`projectDetail.export`)]}),(0,b.jsxs)(m,{onClick:()=>w(!0),disabled:!C(`projects:update`),title:C(`projects:update`)?void 0:n(`projectDetail.noEditPermission`),children:[(0,b.jsx)(ce,{className:`w-4 h-4 mr-2`}),n(`common.edit`)]})]})]}),(A.target_count||A.target_parts_count||A.target_sets)&&(0,b.jsx)(p,{children:(0,b.jsxs)(f,{className:`p-4 space-y-4`,children:[A.target_count&&(0,b.jsxs)(`div`,{children:[(0,b.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,b.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:n(`projectDetail.progress.platesProgress`)}),(0,b.jsxs)(`span`,{className:`text-sm font-medium text-white`,children:[Q?.total_archives||0,` / `,A.target_count,` `,n(`projectDetail.progress.printJobs`)]})]}),(0,b.jsx)(`div`,{className:`h-3 bg-bambu-dark rounded-full overflow-hidden`,children:(0,b.jsx)(`div`,{className:`h-full transition-all duration-500`,style:{width:`${Math.min(jt,100)}%`,backgroundColor:jt>=100?`#22c55e`:A.color||`#6b7280`}})}),(0,b.jsxs)(`div`,{className:`flex justify-between mt-1`,children:[(0,b.jsx)(`span`,{className:`text-xs text-bambu-gray/70`,children:n(`projectDetail.progress.percentComplete`,{percent:jt.toFixed(0)})}),Q?.remaining_prints!=null&&Q.remaining_prints>0&&(0,b.jsx)(`span`,{className:`text-xs text-bambu-gray/70`,children:n(`projectDetail.progress.remaining`,{count:Q.remaining_prints})})]})]}),A.target_parts_count&&(0,b.jsxs)(`div`,{children:[(0,b.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,b.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:n(`projectDetail.progress.partsProgress`)}),(0,b.jsxs)(`span`,{className:`text-sm font-medium text-white`,children:[Q?.completed_prints||0,` / `,A.target_parts_count,` `,n(`projectDetail.progress.parts`)]})]}),(0,b.jsx)(`div`,{className:`h-3 bg-bambu-dark rounded-full overflow-hidden`,children:(0,b.jsx)(`div`,{className:`h-full transition-all duration-500`,style:{width:`${Math.min($,100)}%`,backgroundColor:$>=100?`#22c55e`:A.color||`#6b7280`}})}),(0,b.jsxs)(`div`,{className:`flex justify-between mt-1`,children:[(0,b.jsx)(`span`,{className:`text-xs text-bambu-gray/70`,children:n(`projectDetail.progress.percentComplete`,{percent:$.toFixed(0)})}),Q?.remaining_parts!=null&&Q.remaining_parts>0&&(0,b.jsx)(`span`,{className:`text-xs text-bambu-gray/70`,children:n(`projectDetail.progress.remaining`,{count:Q.remaining_parts})})]})]}),A.target_sets?(0,b.jsxs)(`div`,{children:[(0,b.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,b.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:n(`projectDetail.progress.setsProgress`)}),(0,b.jsxs)(`span`,{className:`text-sm font-medium text-white`,children:[L??0,` / `,A.target_sets,` `,n(`projectDetail.progress.sets`)]})]}),(0,b.jsx)(`div`,{className:`h-3 bg-bambu-dark rounded-full overflow-hidden`,children:(0,b.jsx)(`div`,{className:`h-full transition-all duration-500`,style:{width:`${Math.min((L??0)/A.target_sets*100,100)}%`,backgroundColor:(L??0)>=A.target_sets?`#22c55e`:A.color||`#6b7280`}})}),(0,b.jsx)(`p`,{className:`text-xs text-bambu-gray/70 mt-1`,children:n(`projectDetail.progress.setsHint`)})]}):null]})}),Q&&(0,b.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-4`,children:[(0,b.jsx)(p,{children:(0,b.jsx)(f,{className:`p-4`,children:(0,b.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,b.jsx)(`div`,{className:`p-2 rounded-lg bg-bambu-dark text-bambu-green`,children:(0,b.jsx)(u,{className:`w-5 h-5`})}),(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`projectDetail.stats.printJobs`)}),(0,b.jsxs)(`p`,{className:`text-xl font-semibold text-white`,children:[Q.total_archives,` `,(0,b.jsx)(`span`,{className:`text-sm font-normal text-bambu-gray`,children:n(`projectDetail.stats.total`)})]}),Q.failed_prints>0&&(0,b.jsx)(`p`,{className:`text-sm text-status-error`,children:n(`projectDetail.stats.failed`,{count:Q.failed_prints})}),(0,b.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`projectDetail.stats.partsPrinted`,{count:Q.completed_prints})})]})]})})}),(0,b.jsx)(Re,{icon:ve,label:n(`projectDetail.stats.printTime`),value:fe(Q.total_print_time_hours),color:`text-yellow-600 dark:text-yellow-400`}),(0,b.jsx)(Re,{icon:g,label:n(`projectDetail.stats.filamentUsed`),value:x(Q.total_filament_grams),color:`text-purple-600 dark:text-purple-400`})]}),A.rollup_stats&&(0,b.jsx)(p,{children:(0,b.jsxs)(f,{className:`p-4`,children:[(0,b.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2 mb-3`,children:[(0,b.jsx)(v,{className:`w-5 h-5`}),n(`projectDetail.rollup.title`,{count:A.descendant_count})]}),(0,b.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-4`,children:[(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.stats.printJobs`)}),(0,b.jsx)(`p`,{className:`text-lg font-semibold text-white`,children:A.rollup_stats.total_archives}),(0,b.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`projectDetail.stats.partsPrinted`,{count:A.rollup_stats.completed_prints})})]}),(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.stats.printTime`)}),(0,b.jsx)(`p`,{className:`text-lg font-semibold text-white`,children:fe(A.rollup_stats.total_print_time_hours)})]}),(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.stats.filamentUsed`)}),(0,b.jsx)(`p`,{className:`text-lg font-semibold text-white`,children:x(A.rollup_stats.total_filament_grams)})]}),(()=>{let e=A.rollup_stats.estimated_cost+A.rollup_stats.total_energy_cost+(A.rollup_stats.total_wear_cost??0)+A.rollup_stats.bom_cost;return e<=0?null:(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.cost.totalCost`)}),(0,b.jsxs)(`p`,{className:`text-lg font-semibold text-bambu-green`,children:[R,e.toFixed(2)]})]})})()]}),A.rollup_stats.progress_percent!==null&&(0,b.jsxs)(`div`,{className:`mt-4`,children:[(0,b.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,b.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:n(`projectDetail.rollup.progress`)}),(0,b.jsx)(`span`,{className:`text-sm font-medium text-white`,children:n(`projectDetail.rollup.percentComplete`,{percent:A.rollup_stats.progress_percent.toFixed(0)})})]}),(0,b.jsx)(`div`,{className:`h-3 bg-bambu-dark rounded-full overflow-hidden`,children:(0,b.jsx)(`div`,{className:`h-full transition-all duration-500`,style:{width:`${Math.min(A.rollup_stats.progress_percent,100)}%`,backgroundColor:A.rollup_stats.progress_percent>=100?`#22c55e`:A.color||`#6b7280`}})})]})]})}),Q&&(()=>{let e=Q.estimated_cost+Q.total_energy_cost+(Q.total_wear_cost??0)+Q.bom_cost;return Q.estimated_cost>0||e>0||A.budget!==null})()&&(0,b.jsx)(p,{children:(0,b.jsxs)(f,{className:`p-4`,children:[(0,b.jsx)(`h2`,{className:`text-lg font-semibold text-white mb-3`,children:n(`projectDetail.cost.title`)}),(0,b.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-4`,children:[(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.cost.filamentCost`)}),(0,b.jsxs)(`p`,{className:`text-lg font-semibold text-white`,children:[R,Q.estimated_cost.toFixed(2)]})]}),Q.total_energy_kwh>0&&(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.cost.energy`)}),(0,b.jsxs)(`p`,{className:`text-lg font-semibold text-white`,children:[Q.total_energy_kwh.toFixed(3),` kWh`,Q.total_energy_cost>0&&(0,b.jsxs)(`span`,{className:`text-sm text-bambu-gray ml-1`,children:[`(`,R,Q.total_energy_cost.toFixed(2),`)`]})]})]}),(Q.total_wear_cost??0)>0&&(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.cost.wear`)}),(0,b.jsxs)(`p`,{className:`text-lg font-semibold text-white`,children:[R,Q.total_wear_cost.toFixed(2)]})]}),(()=>{let e=Q.estimated_cost+Q.total_energy_cost+(Q.total_wear_cost??0)+Q.bom_cost;return e<=0?null:(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.cost.totalCost`)}),(0,b.jsxs)(`p`,{className:`text-lg font-semibold text-bambu-green`,children:[R,e.toFixed(2)]}),Q.bom_cost>0&&(0,b.jsx)(`p`,{className:`text-xs text-bambu-gray/70`,children:n(`projectDetail.cost.includesBom`)})]})})(),A.budget!==null&&(()=>{let e=Q.estimated_cost+Q.total_energy_cost+(Q.total_wear_cost??0)+Q.bom_cost,t=A.budget-e;return(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.cost.budget`)}),(0,b.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[n(`projectDetail.cost.total`),`: `,(0,b.jsxs)(`span`,{className:`text-white font-semibold`,children:[R,A.budget.toFixed(2)]})]}),(0,b.jsxs)(`p`,{className:`text-sm ${t>=0?`text-bambu-green`:`text-red-700 dark:text-red-400`}`,children:[n(`projectDetail.cost.remaining`),`: `,(0,b.jsxs)(`span`,{className:`font-semibold`,children:[R,t.toFixed(2)]})]})]})})()]})]})}),A.children&&A.children.length>0&&(0,b.jsx)(p,{children:(0,b.jsxs)(f,{className:`p-4`,children:[(0,b.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2 mb-3`,children:[(0,b.jsx)(v,{className:`w-5 h-5`}),n(`projectDetail.subProjects.title`,{count:A.children.length})]}),(0,b.jsx)(`div`,{className:`space-y-2`,children:A.children.map(e=>(0,b.jsxs)(_,{to:`/projects/${e.id}`,className:`flex items-center justify-between gap-4 p-3 bg-bambu-dark rounded-lg hover:bg-bambu-dark-tertiary transition-colors`,children:[(0,b.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0`,children:[(0,b.jsx)(`div`,{className:`w-3 h-3 rounded-full flex-shrink-0`,style:{backgroundColor:e.color||`#6b7280`}}),(0,b.jsx)(`span`,{className:`text-white truncate`,children:e.name}),(0,b.jsx)(`span`,{className:`text-xs px-2 py-0.5 rounded flex-shrink-0 ${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.descendant_count>0&&(0,b.jsxs)(`span`,{className:`text-xs text-bambu-gray flex-shrink-0 inline-flex items-center gap-1`,children:[(0,b.jsx)(v,{className:`w-3 h-3`}),e.descendant_count]})]}),(0,b.jsxs)(`div`,{className:`flex items-center gap-4 text-sm text-bambu-gray flex-shrink-0`,children:[e.total_archives>0&&(0,b.jsx)(`span`,{className:`hidden sm:inline`,children:n(`projectDetail.subProjects.jobs`,{count:e.total_archives})}),e.total_filament_grams>0&&(0,b.jsx)(`span`,{className:`hidden md:inline`,children:x(e.total_filament_grams)}),e.total_cost>0&&(0,b.jsxs)(`span`,{className:`hidden md:inline`,children:[R,e.total_cost.toFixed(2)]}),e.progress_percent!==null&&(0,b.jsxs)(`span`,{children:[e.progress_percent.toFixed(0),`%`]})]})]},e.id))})]})}),A.parent_id&&A.parent_name&&(0,b.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,b.jsx)(De,{className:`w-4 h-4 text-bambu-gray`}),(0,b.jsx)(`span`,{className:`text-bambu-gray`,children:n(`projectDetail.partOf`)}),(0,b.jsx)(_,{to:`/projects/${A.parent_id}`,className:`text-bambu-green hover:underline`,children:A.parent_name})]}),(A.tags||A.due_date||A.priority!==`normal`)&&(0,b.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4`,children:[A.priority&&A.priority!==`normal`&&(0,b.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,b.jsx)(`span`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.priorityLabel`)}),(0,b.jsx)(Be,{priority:A.priority,t:n})]}),A.due_date&&(0,b.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,b.jsx)(ne,{className:`w-4 h-4 text-bambu-gray`}),(0,b.jsx)(`span`,{className:`text-sm text-white`,children:de(A.due_date,{year:`numeric`,month:`short`,day:`numeric`})}),S(A.due_date,n)&&(0,b.jsxs)(`span`,{className:`text-xs ${S(A.due_date,n).color}`,children:[`(`,S(A.due_date,n).label,`)`]})]}),A.tags&&(0,b.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,b.jsx)(ye,{className:`w-4 h-4 text-bambu-gray`}),(0,b.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:A.tags.split(`,`).map((e,t)=>(0,b.jsx)(`span`,{className:`px-2 py-0.5 bg-bambu-dark-tertiary text-bambu-gray text-xs rounded`,children:e.trim()},t))})]})]}),(0,b.jsx)(p,{children:(0,b.jsxs)(f,{className:`p-4`,children:[(0,b.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,b.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,b.jsx)(Ae,{className:`w-5 h-5`}),n(`projectDetail.notes.title`)]}),He?(0,b.jsxs)(`div`,{className:`flex gap-2`,children:[(0,b.jsxs)(m,{variant:`secondary`,size:`sm`,onClick:nt,disabled:z.isPending,children:[(0,b.jsx)(le,{className:`w-4 h-4 mr-1`}),n(`common.cancel`)]}),(0,b.jsxs)(m,{size:`sm`,onClick:tt,disabled:z.isPending,children:[z.isPending?(0,b.jsx)(l,{className:`w-4 h-4 animate-spin mr-1`}):(0,b.jsx)(xe,{className:`w-4 h-4 mr-1`}),n(`common.save`)]})]}):(0,b.jsxs)(m,{variant:`secondary`,size:`sm`,onClick:et,disabled:!C(`projects:update`),title:C(`projects:update`)?void 0:n(`projectDetail.notes.noEditPermission`),children:[(0,b.jsx)(ce,{className:`w-4 h-4 mr-1`}),n(`common.edit`)]})]}),He?(0,b.jsx)(te,{content:Ue,onChange:E,placeholder:n(`projectDetail.notes.placeholder`)}):A.notes?(0,b.jsx)(`div`,{className:`prose prose-invert prose-sm max-w-none`,dangerouslySetInnerHTML:{__html:Ne.sanitize(A.notes)}}):(0,b.jsx)(`p`,{className:`text-bambu-gray/70 text-sm italic`,children:n(`projectDetail.notes.empty`)})]})}),(0,b.jsx)(p,{children:(0,b.jsxs)(f,{className:`p-4`,children:[(0,b.jsx)(`div`,{className:`flex items-center justify-between mb-3`,children:(0,b.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,b.jsx)(Oe,{className:`w-5 h-5`}),n(`projectDetail.files.title`)]})}),(0,b.jsxs)(`p`,{className:`text-xs text-bambu-gray mb-3`,children:[(0,b.jsx)(_,{to:`/files`,className:`text-bambu-green hover:underline`,children:n(`projectDetail.files.linkFolders`)}),` `,n(`projectDetail.files.forQuickAccess`)]}),P&&P.length>0?(0,b.jsx)(`div`,{className:`space-y-4`,children:P.map(e=>{let t=Ze.get(e.id)??[],i=Xe;return(0,b.jsxs)(`div`,{children:[(0,b.jsxs)(_,{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,b.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0`,children:[(0,b.jsx)(Oe,{className:`w-5 h-5 text-bambu-green shrink-0`}),(0,b.jsxs)(`div`,{className:`min-w-0`,children:[(0,b.jsx)(`p`,{className:`text-sm text-white truncate`,children:e.name}),(0,b.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`projectDetail.files.fileCount`,{count:e.file_count})})]})]}),(0,b.jsx)(ge,{className:`w-4 h-4 text-bambu-gray shrink-0`})]}),i?(0,b.jsx)(`div`,{className:`flex items-center gap-2 px-3 py-2 text-bambu-gray text-sm`,children:(0,b.jsx)(l,{className:`w-4 h-4 animate-spin`})}):t.length===0?(0,b.jsx)(`p`,{className:`text-bambu-gray/60 text-xs italic px-3`,children:n(`projectDetail.files.noFiles`)}):(0,b.jsx)(`div`,{className:`space-y-1 pl-3`,children:t.map(e=>{let t=Pe(e);return(0,b.jsxs)(`div`,{className:`flex items-center gap-3 p-2 rounded-lg hover:bg-bambu-dark-tertiary transition-colors`,children:[(0,b.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,b.jsx)(`img`,{src:r.getLibraryFileThumbnailUrl(e.id),alt:e.print_name||e.filename,className:`w-full h-full object-cover`}):(0,b.jsx)(oe,{className:`w-5 h-5 text-bambu-gray/40`})}),(0,b.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,b.jsx)(`p`,{className:`text-sm text-white truncate`,title:e.print_name||e.filename,children:e.print_name||e.filename}),(0,b.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&&(()=>{let t=I.get(e.id)??0,r=A.target_sets;if(!r)return t>0?(0,b.jsxs)(`span`,{className:`shrink-0 text-xs px-1.5 py-0.5 rounded-full bg-bambu-dark text-bambu-gray`,title:n(`projectDetail.files.printedCount`,{count:t}),children:[t,`×`]}):null;let i=Math.min(t/r*100,100),a=t>=r?`text-status-ok`:t>0?`text-status-warning`:`text-bambu-gray`,o=t>=r?`bg-status-ok`:t>0?`bg-status-warning`:`bg-bambu-gray`;return(0,b.jsxs)(`div`,{className:`shrink-0 w-20`,title:n(`projectDetail.files.progressTooltip`,{done:t,target:r}),children:[(0,b.jsxs)(`p`,{className:`text-xs font-medium text-right ${a}`,children:[t,` / `,r]}),(0,b.jsx)(`div`,{className:`h-1 bg-bambu-dark rounded-full overflow-hidden mt-1`,children:(0,b.jsx)(`div`,{className:`h-full ${o}`,style:{width:`${i}%`}})})]})})(),t&&(0,b.jsx)(`div`,{className:`flex items-center gap-1 shrink-0`,children:(0,b.jsx)(`button`,{onClick:()=>O(e),title:n(`common.print`),className:`p-1.5 rounded hover:bg-bambu-green/20 text-bambu-green transition-colors`,children:(0,b.jsx)(g,{className:`w-4 h-4`})})})]},e.id)})})]},e.id)})}):(0,b.jsx)(`p`,{className:`text-bambu-gray/70 text-sm italic`,children:n(`projectDetail.files.empty`)})]})}),(0,b.jsx)(p,{children:(0,b.jsxs)(f,{className:`p-4`,children:[(0,b.jsxs)(`div`,{className:`flex items-center justify-between mb-4`,children:[(0,b.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,b.jsx)(Me,{className:`w-5 h-5`}),n(`projectDetail.bom.title`),Q&&Q.bom_total_items>0&&(0,b.jsxs)(`span`,{className:`text-sm font-normal text-bambu-gray`,children:[`(`,n(`projectDetail.bom.acquired`,{completed:Q.bom_completed_items,total:Q.bom_total_items}),`)`]})]}),(0,b.jsxs)(`div`,{className:`flex items-center gap-2`,children:[M&&M.some(e=>e.is_complete)&&(0,b.jsx)(`button`,{onClick:()=>ft(!U),className:`text-xs px-2 py-1 rounded transition-colors ${U?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,children:n(U?`projectDetail.bom.showAll`:`projectDetail.bom.hideDone`)}),!dt&&(0,b.jsxs)(m,{variant:`secondary`,size:`sm`,onClick:()=>H(!0),disabled:!C(`projects:update`),title:C(`projects:update`)?void 0:n(`projectDetail.bom.noAddPermission`),children:[(0,b.jsx)(Ce,{className:`w-4 h-4 mr-1`}),n(`projectDetail.bom.addPart`)]})]})]}),dt&&(0,b.jsxs)(`form`,{onSubmit:St,className:`bg-bambu-dark rounded-lg p-4 mb-4 space-y-3`,children:[(0,b.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3`,children:[(0,b.jsx)(`input`,{type:`text`,value:B,onChange:e=>rt(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,b.jsxs)(`div`,{className:`flex gap-2`,children:[(0,b.jsx)(_e,{value:it,onChange:at,fallback: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,b.jsx)(`input`,{type:`number`,step:`0.01`,value:V,onChange:e=>ot(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:R})})]})]}),(0,b.jsx)(`input`,{type:`url`,value:st,onChange:e=>ct(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,b.jsx)(`input`,{type:`text`,value:lt,onChange:e=>ut(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,b.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,b.jsx)(m,{type:`button`,variant:`secondary`,size:`sm`,onClick:()=>H(!1),children:n(`common.cancel`)}),(0,b.jsx)(m,{type:`submit`,size:`sm`,disabled:!B.trim()||X.isPending,children:X.isPending?(0,b.jsx)(l,{className:`w-4 h-4 animate-spin`}):n(`projectDetail.bom.addPart`)})]})]}),qe?(0,b.jsx)(`div`,{className:`flex items-center justify-center py-4`,children:(0,b.jsx)(l,{className:`w-6 h-6 animate-spin text-bambu-green`})}):M&&M.length>0?(0,b.jsxs)(`div`,{className:`space-y-2`,children:[M.filter(e=>!U||!e.is_complete).map(e=>(0,b.jsx)(`div`,{className:`p-3 rounded-lg transition-colors ${e.is_complete?`bg-status-ok/10`:`bg-bambu-dark`}`,children:W?.id===e.id?(0,b.jsxs)(`form`,{onSubmit:Et,className:`space-y-3`,children:[(0,b.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3`,children:[(0,b.jsx)(`input`,{type:`text`,value:K,onChange:e=>pt(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,b.jsxs)(`div`,{className:`flex gap-2`,children:[(0,b.jsx)(_e,{value:mt,onChange:ht,fallback: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,b.jsx)(`input`,{type:`number`,step:`0.01`,value:q,onChange:e=>gt(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:R})})]})]}),(0,b.jsx)(`input`,{type:`url`,value:_t,onChange:e=>vt(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,b.jsx)(`input`,{type:`text`,value:yt,onChange:e=>bt(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,b.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,b.jsx)(m,{type:`button`,variant:`secondary`,size:`sm`,onClick:Dt,children:n(`common.cancel`)}),(0,b.jsx)(m,{type:`submit`,size:`sm`,disabled:!K.trim()||Z.isPending,children:Z.isPending?(0,b.jsx)(l,{className:`w-4 h-4 animate-spin`}):n(`common.save`)})]})]}):(0,b.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,b.jsx)(`button`,{onClick:()=>C(`projects:update`)&&Ct(e),disabled:Z.isPending||!C(`projects:update`),title:C(`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`:C(`projects:update`)?`border-bambu-gray hover:border-bambu-green`:`border-bambu-gray/50 cursor-not-allowed`}`,children:e.is_complete&&(0,b.jsx)(c,{className:`w-3 h-3`})}),(0,b.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,b.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,b.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,b.jsxs)(`p`,{className:`text-sm font-medium ${e.is_complete?`text-bambu-gray line-through`:`text-white`}`,children:[e.name,(0,b.jsxs)(`span`,{className:`text-bambu-gray font-normal ml-2`,children:[`x`,e.quantity_needed]})]}),e.unit_price!==null&&(0,b.jsxs)(`span`,{className:`text-xs text-bambu-green whitespace-nowrap`,children:[R,(e.unit_price*e.quantity_needed).toFixed(2)]})]}),(0,b.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,b.jsx)(`button`,{onClick:()=>C(`projects:update`)&&Tt(e),disabled:!C(`projects:update`),className:`p-1 rounded transition-colors shrink-0 ${C(`projects:update`)?`hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white`:`text-bambu-gray/50 cursor-not-allowed`}`,title:C(`projects:update`)?n(`common.edit`):n(`projectDetail.bom.noEditPermission`),children:(0,b.jsx)(pe,{className:`w-4 h-4`})}),(0,b.jsx)(`button`,{onClick:()=>C(`projects:update`)&&wt(e.id,e.name),disabled:!C(`projects:update`),className:`p-1 rounded transition-colors shrink-0 ${C(`projects:update`)?`hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-red-400`:`text-bambu-gray/50 cursor-not-allowed`}`,title:C(`projects:update`)?n(`common.delete`):n(`projectDetail.bom.noDeletePermission`),children:(0,b.jsx)(me,{className:`w-4 h-4`})})]})]}),e.sourcing_url&&(0,b.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,b.jsx)(he,{className:`w-3 h-3 shrink-0`}),(0,b.jsx)(`span`,{className:`truncate`,children:(()=>{try{return new URL(e.sourcing_url).hostname.replace(`www.`,``)}catch{return e.sourcing_url}})()})]}),e.remarks&&(0,b.jsx)(`p`,{className:`mt-1 text-xs text-bambu-gray/80 italic`,children:e.remarks})]})]})},e.id)),Q&&Q.bom_cost>0&&(0,b.jsxs)(`div`,{className:`pt-2 mt-2 border-t border-bambu-dark-tertiary flex justify-between text-sm`,children:[(0,b.jsx)(`span`,{className:`text-bambu-gray`,children:n(`projectDetail.bom.totalCost`)}),(0,b.jsxs)(`span`,{className:`text-white font-medium`,children:[R,Q.bom_cost.toFixed(2)]})]})]}):(0,b.jsx)(`p`,{className:`text-bambu-gray/70 text-sm italic`,children:n(`projectDetail.bom.empty`)})]})}),(0,b.jsx)(p,{children:(0,b.jsxs)(f,{className:`p-4`,children:[(0,b.jsx)(`div`,{className:`flex items-center justify-between mb-3`,children:(0,b.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,b.jsx)(se,{className:`w-5 h-5`}),n(`projectDetail.timeline.title`)]})}),Je?(0,b.jsx)(`div`,{className:`flex items-center justify-center py-4`,children:(0,b.jsx)(l,{className:`w-6 h-6 animate-spin text-bambu-green`})}):N&&N.length>0?(0,b.jsx)(`div`,{className:`space-y-3`,children:N.slice(0,10).map((e,t)=>(0,b.jsxs)(`div`,{className:`flex gap-3`,children:[(0,b.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,b.jsx)(c,{className:`w-4 h-4`}),e.event_type===`print_failed`&&(0,b.jsx)(re,{className:`w-4 h-4`}),e.event_type===`print_started`&&(0,b.jsx)(g,{className:`w-4 h-4`}),e.event_type===`queued`&&(0,b.jsx)(Ie,{className:`w-4 h-4`}),e.event_type===`project_created`&&(0,b.jsx)(Ce,{className:`w-4 h-4`})]}),(0,b.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,b.jsx)(`p`,{className:`text-sm text-white`,children:e.title}),e.description&&(0,b.jsx)(`p`,{className:`text-xs text-bambu-gray truncate`,children:e.description}),(0,b.jsx)(`p`,{className:`text-xs text-bambu-gray/70`,children:At(e.timestamp)})]})]},t))}):(0,b.jsx)(`p`,{className:`text-bambu-gray/70 text-sm italic`,children:n(`projectDetail.timeline.empty`)})]})}),!A.is_template&&(0,b.jsx)(`div`,{className:`flex justify-end`,children:(0,b.jsxs)(m,{variant:`secondary`,size:`sm`,onClick:()=>kt.mutate(),disabled:kt.isPending||!C(`projects:create`),title:C(`projects:create`)?void 0:n(`projectDetail.template.noCreatePermission`),children:[kt.isPending?(0,b.jsx)(l,{className:`w-4 h-4 animate-spin mr-2`}):(0,b.jsx)(ae,{className:`w-4 h-4 mr-2`}),n(`projectDetail.template.saveAsTemplate`)]})}),Q&&(Q.queued_prints>0||Q.in_progress_prints>0)&&(0,b.jsx)(p,{children:(0,b.jsxs)(f,{className:`p-4`,children:[(0,b.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,b.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,b.jsx)(Ie,{className:`w-5 h-5`}),n(`projectDetail.queue.title`)]}),(0,b.jsx)(_,{to:`/queue?project=${k}`,className:`text-sm text-bambu-green hover:underline`,children:n(`projectDetail.queue.viewAll`)})]}),(0,b.jsxs)(`div`,{className:`flex items-center gap-4 text-sm`,children:[Q.in_progress_prints>0&&(0,b.jsx)(`span`,{className:`text-yellow-700 dark:text-yellow-400`,children:n(`projectDetail.queue.printing`,{count:Q.in_progress_prints})}),Q.queued_prints>0&&(0,b.jsx)(`span`,{className:`text-bambu-gray`,children:n(`projectDetail.queue.queued`,{count:Q.queued_prints})})]})]})}),(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`div`,{className:`flex items-center justify-between mb-4`,children:(0,b.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,b.jsx)(u,{className:`w-5 h-5`}),n(`projectDetail.prints.title`,{count:Ge?.length||0})]})}),Ke?(0,b.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,b.jsx)(l,{className:`w-6 h-6 animate-spin text-bambu-green`})}):(0,b.jsx)(ze,{archives:Ge||[],t:n})]}),Ve&&(0,b.jsx)(Fe,{t:n,currencySymbol:R,project:{...A,archive_count:Q?.total_archives||0,total_items:Q?.total_items||0,completed_count:Q?.completed_prints||0,failed_count:Q?.failed_prints||0,queue_count:Q?.queued_prints||0,progress_percent:Q?.progress_percent||null,child_count:A.children?.length??0,archives:[]},onClose:()=>w(!1),onSave:e=>z.mutate(e),isLoading:z.isPending}),J.isOpen&&(0,b.jsx)(we,{title:J.title,message:J.message,confirmText:n(`common.delete`),variant:`danger`,onConfirm:J.onConfirm,onCancel:()=>Y(e=>({...e,isOpen:!1}))}),D&&(0,b.jsx)(Ee,{mode:`create`,libraryFileId:D.id,archiveName:D.print_name||D.filename,projectId:k,onClose:()=>O(null),onSuccess:()=>{O(null),d.invalidateQueries({queryKey:[`archives`]}),d.invalidateQueries({queryKey:[`queue`]})}})]})}export{C as ProjectDetailPage}; \ No newline at end of file diff --git a/static/assets/ProjectsPage--qAFcLFS.js b/static/assets/ProjectsPage-CBeO6wA6.js similarity index 99% rename from static/assets/ProjectsPage--qAFcLFS.js rename to static/assets/ProjectsPage-CBeO6wA6.js index d2c7101dd..5d0b5d09f 100644 --- a/static/assets/ProjectsPage--qAFcLFS.js +++ b/static/assets/ProjectsPage-CBeO6wA6.js @@ -1 +1 @@ -import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,w as i}from"./client-DnySrlFv.js";import{t as a}from"./react-dom-B8Dg6xzp.js";import{n as o}from"./QueryClientProvider-Ce8_sN3w.js";import{t as s}from"./useQuery-BBCjCezC.js";import{t as c}from"./useMutation-B-Tr2hIP.js";import{t as l}from"./createLucideIcon-DvBYJlWL.js";import{a as u}from"./info-ROUoQhJR.js";import{n as d}from"./ToastContext-BRX0SW3C.js";import{t as f}from"./ellipsis-vertical-t2D7cYyp.js";import{t as p}from"./loader-circle-BEmFtawu.js";import{t as m}from"./package-BGUevlqS.js";import{t as h}from"./pen-line-BWR04BX-.js";import{t as g}from"./triangle-alert-Dt_1FcBy.js";import{t as _}from"./x-DR-Trv6U.js";import{t as v}from"./Button-DDr6eAFy.js";import{An as y,At as b,Cn as x,I as S,Ln as C,Mn as w,On as T,Vn as E,Zt as D,_t as O,at as k,cn as A,kt as j,un as ee,wn as M,yn as N,yt as P}from"./index-0t--Yqoi.js";var F=l(`folder-tree`,[[`path`,{d:`M20 10a1 1 0 0 0 1-1V6a1 1 0 0 0-1-1h-2.5a1 1 0 0 1-.8-.4l-.9-1.2A1 1 0 0 0 15 3h-2a1 1 0 0 0-1 1v5a1 1 0 0 0 1 1Z`,key:`hod4my`}],[`path`,{d:`M20 21a1 1 0 0 0 1-1v-3a1 1 0 0 0-1-1h-2.9a1 1 0 0 1-.88-.55l-.42-.85a1 1 0 0 0-.92-.6H13a1 1 0 0 0-1 1v5a1 1 0 0 0 1 1Z`,key:`w4yl2u`}],[`path`,{d:`M3 5a2 2 0 0 0 2 2h3`,key:`f2jnh7`}],[`path`,{d:`M3 3v13a2 2 0 0 0 2 2h3`,key:`k8epm1`}]]),I=l(`list-todo`,[[`path`,{d:`M13 5h8`,key:`a7qcls`}],[`path`,{d:`M13 12h8`,key:`h98zly`}],[`path`,{d:`M13 19h8`,key:`c3s6r1`}],[`path`,{d:`m3 17 2 2 4-4`,key:`1jhpwq`}],[`rect`,{x:`3`,y:`4`,width:`6`,height:`6`,rx:`1`,key:`cif1o7`}]]),L=e(n(),1),R=e(a(),1),z=t(),B=[`#ef4444`,`#f97316`,`#eab308`,`#22c55e`,`#06b6d4`,`#3b82f6`,`#8b5cf6`,`#ec4899`,`#6b7280`];function V({project:e,onClose:t,onSave:n,isLoading:i,currencySymbol:a,t:c}){let[l,u]=(0,L.useState)(e?.name||``),[d,f]=(0,L.useState)(e?.description||``),[m,h]=(0,L.useState)(e?.color||B[0]),[g,y]=(0,L.useState)(e?.target_count?.toString()||``),[b,x]=(0,L.useState)(e?.target_parts_count?.toString()||``),[C,w]=(0,L.useState)(e?.target_sets?.toString()||``),[T,E]=(0,L.useState)(e?.status||`active`),[D,O]=(0,L.useState)(e?.tags||``),[k,A]=(0,L.useState)(e?.due_date?.split(`T`)[0]||``),[M,N]=(0,L.useState)(e?.priority||`normal`),[P,F]=(0,L.useState)(e?.budget?.toString()||``),[I,R]=(0,L.useState)(e?.url||``),[V,H]=(0,L.useState)(null),[U,W]=(0,L.useState)(e?.parent_id??null),G=o(),{data:te}=s({queryKey:[`projects`,void 0],queryFn:()=>r.getProjects()}),K=S(te||[],e?.id),[q,J]=(0,L.useState)(e?.cover_image_filename||null),Y=(0,L.useRef)(null),[X,Z]=(0,L.useState)(!1),[Q,$]=(0,L.useState)(0);return(0,z.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,z.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,z.jsx)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary flex-shrink-0`,children:(0,z.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:c(e?`projects.editProject`:`projects.newProject`)})}),(0,z.jsxs)(`form`,{onSubmit:t=>{t.preventDefault();let r=I.trim();if(r&&!/^https?:\/\//i.test(r)){H(c(`projects.urlInvalid`));return}H(null),n({name:l.trim(),description:d.trim()||void 0,color:m,target_count:g?parseInt(g,10):void 0,target_parts_count:b?parseInt(b,10):void 0,target_sets:e?C?parseInt(C,10):null:C?parseInt(C,10):void 0,tags:e?D.trim()||null:D.trim()||void 0,due_date:e?k||null:k||void 0,priority:M,budget:P.trim()?parseFloat(P):null,url:e?r||null:r||void 0,parent_id:e?U??0:U??void 0,...e&&{status:T}})},className:`flex flex-col flex-1 min-h-0`,children:[(0,z.jsxs)(`div`,{className:`p-4 space-y-4 overflow-y-auto flex-1`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:c(`common.name`)}),(0,z.jsx)(`input`,{type:`text`,value:l,onChange:e=>u(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:c(`projects.namePlaceholder`),required:!0})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:c(`common.description`)}),(0,z.jsx)(`textarea`,{value:d,onChange:e=>f(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:c(`projects.descriptionPlaceholder`),rows:2})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:c(`projects.urlLabel`)}),(0,z.jsx)(`input`,{type:`url`,value:I,onChange:e=>{R(e.target.value),V&&H(null)},className:`w-full bg-bambu-dark border rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none ${V?`border-red-500 focus:border-red-500`:`border-bambu-dark-tertiary focus:border-bambu-green`}`,placeholder:c(`projects.urlPlaceholder`),maxLength:2048}),V&&(0,z.jsx)(`p`,{className:`text-xs text-red-600 dark:text-red-400 mt-1`,children:V})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:c(`projects.parentLabel`)}),(0,z.jsxs)(`select`,{value:U??``,onChange:e=>W(e.target.value?parseInt(e.target.value,10):null),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,z.jsx)(`option`,{value:``,children:c(`projects.parentNone`)}),K.map(e=>(0,z.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,z.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:c(`projects.parentHint`)})]}),e&&(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:c(`projects.coverImageLabel`)}),(0,z.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,z.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:q?(0,z.jsx)(`img`,{src:r.getProjectCoverImageUrl(e.id,Q),alt:c(`projects.coverImageAlt`),className:`w-full h-full object-cover`}):(0,z.jsx)(ee,{className:`w-6 h-6 text-bambu-gray`})}),(0,z.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,z.jsx)(`input`,{ref:Y,type:`file`,accept:`image/jpeg,image/png,image/gif,image/webp`,onChange:async t=>{let n=t.target.files?.[0];if(!(!n||!e)){Z(!0);try{J((await r.uploadProjectCoverImage(e.id,n)).filename),$(e=>e+1),G.invalidateQueries({queryKey:[`projects`]})}catch{}finally{Z(!1),Y.current&&(Y.current.value=``)}}},className:`hidden`}),(0,z.jsxs)(v,{type:`button`,variant:`secondary`,onClick:()=>Y.current?.click(),disabled:X,children:[X?(0,z.jsx)(p,{className:`w-4 h-4 animate-spin`}):(0,z.jsx)(j,{className:`w-4 h-4 mr-1`}),c(q?`projects.coverImageReplace`:`projects.coverImageUpload`)]}),q&&(0,z.jsxs)(v,{type:`button`,variant:`secondary`,onClick:async()=>{if(e){Z(!0);try{await r.deleteProjectCoverImage(e.id),J(null),$(e=>e+1),G.invalidateQueries({queryKey:[`projects`]})}finally{Z(!1)}}},disabled:X,children:[(0,z.jsx)(_,{className:`w-4 h-4 mr-1`}),c(`projects.coverImageRemove`)]})]})]})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:c(`projects.color`)}),(0,z.jsx)(`div`,{className:`flex gap-2 flex-wrap`,children:B.map(e=>(0,z.jsx)(`button`,{type:`button`,onClick:()=>h(e),className:`w-8 h-8 rounded-full transition-transform ${m===e?`ring-2 ring-white ring-offset-2 ring-offset-bambu-dark-secondary scale-110`:``}`,style:{backgroundColor:e}},e))})]}),(0,z.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:c(`projects.targetPlates`)}),(0,z.jsx)(`input`,{type:`number`,value:g,onChange:e=>y(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:c(`projects.targetPlatesPlaceholder`),min:`1`}),(0,z.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:c(`projects.targetPlatesHelp`)})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:c(`projects.targetParts`)}),(0,z.jsx)(`input`,{type:`number`,value:b,onChange:e=>x(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:c(`projects.targetPartsPlaceholder`),min:`1`}),(0,z.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:c(`projects.targetPartsHelp`)})]})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:c(`projects.targetSets`)}),(0,z.jsx)(`input`,{type:`number`,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 placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:c(`projects.targetSetsPlaceholder`),min:`1`}),(0,z.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:c(`projects.targetSetsHelp`)})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:c(`projects.tagsLabel`)}),(0,z.jsx)(`input`,{type:`text`,value:D,onChange:e=>O(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:c(`projects.tagsPlaceholder`)})]}),(0,z.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:c(`projects.dueDate`)}),(0,z.jsx)(`input`,{type:`date`,value:k,onChange:e=>A(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,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:c(`projects.priority`)}),(0,z.jsxs)(`select`,{value:M,onChange:e=>N(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,z.jsx)(`option`,{value:`low`,children:c(`projects.priorityLow`)}),(0,z.jsx)(`option`,{value:`normal`,children:c(`projects.priorityNormal`)}),(0,z.jsx)(`option`,{value:`high`,children:c(`projects.priorityHigh`)}),(0,z.jsx)(`option`,{value:`urgent`,children:c(`projects.priorityUrgent`)})]})]})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:c(`projectDetail.cost.budget`)}),(0,z.jsxs)(`div`,{className:`relative`,children:[(0,z.jsx)(`span`,{className:`absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray pointer-events-none`,children:a}),(0,z.jsx)(`input`,{type:`number`,step:`0.01`,min:`0`,value:P,onChange:e=>F(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,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:c(`common.status`)}),(0,z.jsxs)(`select`,{value:T,onChange:e=>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,z.jsx)(`option`,{value:`active`,children:c(`projects.statusActive`)}),(0,z.jsx)(`option`,{value:`completed`,children:c(`projects.statusCompleted`)}),(0,z.jsx)(`option`,{value:`archived`,children:c(`projects.statusArchived`)})]})]})]}),(0,z.jsxs)(`div`,{className:`flex justify-end gap-2 p-4 border-t border-bambu-dark-tertiary flex-shrink-0`,children:[(0,z.jsx)(v,{type:`button`,variant:`secondary`,onClick:t,children:c(`common.cancel`)}),(0,z.jsx)(v,{type:`submit`,disabled:!l.trim()||i,children:i?(0,z.jsx)(p,{className:`w-4 h-4 animate-spin`}):c(e?`common.save`:`projects.create`)})]})]})]})})}function H({projectId:e,altText:t}){let n=(0,L.useRef)(null),[i,a]=(0,L.useState)(!1),[o,s]=(0,L.useState)(null);return(0,z.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,i=e.right+8;i+384>t-8&&(i=e.left-384-8);let o=e.top;o+384>r-8&&(o=r-384-8),o<8&&(o=8),s({left:i,top:o}),a(!0)},onMouseLeave:()=>a(!1),onClick:e=>e.stopPropagation(),children:[(0,z.jsx)(`div`,{className:`w-10 h-10 rounded-lg overflow-hidden bg-bambu-dark border border-bambu-dark-tertiary`,children:(0,z.jsx)(`img`,{src:r.getProjectCoverImageUrl(e),alt:t,className:`w-full h-full object-cover`,loading:`lazy`})}),i&&o&&(0,R.createPortal)((0,z.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:o.left,top:o.top},"aria-hidden":`true`,children:(0,z.jsx)(`img`,{src:r.getProjectCoverImageUrl(e),alt:``,className:`w-full h-full object-contain`,loading:`lazy`})}),document.body)]})}function U({project:e,parentName:t,onClick:n,onEdit:i,onDelete:a,hasPermission:o,t:s}){let c=e.target_count?Math.round(e.archive_count/e.target_count*100):0,l=e.target_parts_count?Math.round(e.completed_count/e.target_parts_count*100):0,u=e.status===`completed`,d=e.status===`archived`,[p,_]=(0,L.useState)(!1),v=u?{icon:y,color:`text-bambu-green`,bg:`bg-bambu-green/10`}:d?{icon:C,color:`text-bambu-gray`,bg:`bg-bambu-gray/10`}:e.queue_count>0?{icon:T,color:`text-blue-600 dark:text-blue-400`,bg:`bg-blue-50 dark:bg-blue-400/10`}:{icon:N,color:`text-bambu-gray`,bg:`bg-bambu-gray/10`};return(0,z.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:n,children:[(0,z.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,z.jsxs)(`div`,{className:`p-5 pl-6`,children:[(0,z.jsxs)(`div`,{className:`flex items-start justify-between mb-4`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 flex-1`,children:[e.cover_image_filename?(0,z.jsx)(H,{projectId:e.id,altText:s(`projects.coverImageAlt`)}):(0,z.jsx)(`div`,{className:`p-2 rounded-lg ${v.bg} flex-shrink-0`,children:(0,z.jsx)(v.icon,{className:`w-5 h-5 ${v.color}`})}),(0,z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,z.jsx)(`h3`,{className:`font-semibold text-white truncate`,children:e.name}),e.url&&(0,z.jsx)(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,onClick:e=>e.stopPropagation(),title:e.url,"aria-label":s(`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,z.jsx)(x,{className:`w-3.5 h-3.5`})}),e.target_parts_count?(0,z.jsxs)(`span`,{className:`text-xs px-2 py-0.5 rounded-full whitespace-nowrap font-medium ${l>=100?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark text-bambu-gray`}`,children:[e.completed_count,`/`,e.target_parts_count,` `,s(`projects.parts`)]}):e.target_count?(0,z.jsxs)(`span`,{className:`text-xs px-2 py-0.5 rounded-full whitespace-nowrap font-medium ${c>=100?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark text-bambu-gray`}`,children:[e.archive_count,`/`,e.target_count,` `,s(`projects.plates`)]}):e.completed_count>0?(0,z.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,` `,s(`projects.parts`)]}):null,u&&(0,z.jsx)(`span`,{className:`text-xs bg-bambu-green/20 text-bambu-green px-2 py-0.5 rounded-full whitespace-nowrap`,children:s(`projects.done`)}),d&&(0,z.jsx)(`span`,{className:`text-xs bg-bambu-gray/20 text-bambu-gray px-2 py-0.5 rounded-full whitespace-nowrap`,children:s(`projects.statusArchived`)}),e.child_count>0&&(0,z.jsxs)(`span`,{className:`text-xs bg-bambu-dark text-bambu-gray px-2 py-0.5 rounded-full whitespace-nowrap inline-flex items-center gap-1`,title:s(`projects.subProjectCount`,{count:e.child_count}),children:[(0,z.jsx)(F,{className:`w-3 h-3`}),e.child_count]})]}),t&&(0,z.jsxs)(`p`,{className:`text-xs text-bambu-gray mt-1 flex items-center gap-1`,children:[(0,z.jsx)(A,{className:`w-3 h-3 flex-shrink-0`}),(0,z.jsx)(`span`,{className:`truncate`,children:s(`projects.partOf`,{name:t})})]}),e.description&&(0,z.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,z.jsxs)(`div`,{className:`flex items-center gap-2 mt-1.5`,children:[n.slice(0,3).map(e=>(0,z.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,z.jsxs)(`div`,{className:`flex items-center gap-0.5`,children:[i.slice(0,5).map(e=>(0,z.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,z.jsxs)(`span`,{className:`text-[10px] text-bambu-gray ml-0.5`,children:[`+`,i.length-5]})]})]})})()]})]}),(0,z.jsxs)(`div`,{className:`relative`,onClick:e=>e.stopPropagation(),children:[(0,z.jsx)(`button`,{className:`p-1.5 rounded-lg hover:bg-bambu-dark text-bambu-gray hover:text-white transition-colors can-hover:opacity-0 group-hover:opacity-100 focus-visible:opacity-100`,onClick:()=>_(!p),children:(0,z.jsx)(f,{className:`w-4 h-4`})}),p&&(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>_(!1)}),(0,z.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,z.jsxs)(`button`,{className:`w-full px-3 py-2 text-left text-sm flex items-center gap-2 ${o(`projects:update`)?`text-white hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{o(`projects:update`)&&(i(),_(!1))},disabled:!o(`projects:update`),title:o(`projects:update`)?void 0:s(`projects.noEditPermission`),children:[(0,z.jsx)(h,{className:`w-4 h-4`}),s(`common.edit`)]}),(0,z.jsxs)(`button`,{className:`w-full px-3 py-2 text-left text-sm flex items-center gap-2 ${o(`projects:delete`)?`text-red-600 dark:text-red-400 hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{o(`projects:delete`)&&(a(),_(!1))},disabled:!o(`projects:delete`),title:o(`projects:delete`)?void 0:s(`projects.noDeletePermission`),children:[(0,z.jsx)(b,{className:`w-4 h-4`}),s(`common.delete`)]})]})]})]})]}),(0,z.jsx)(`div`,{className:`mb-4`,children:e.target_count||e.target_parts_count?(0,z.jsxs)(`div`,{className:`space-y-3`,children:[e.target_count&&(0,z.jsxs)(`div`,{children:[(0,z.jsxs)(`div`,{className:`flex items-center justify-between text-xs mb-1`,children:[(0,z.jsx)(`span`,{className:`text-bambu-gray`,children:s(`projects.plates`)}),(0,z.jsxs)(`span`,{className:c>=100?`text-bambu-green font-medium`:`text-white`,children:[e.archive_count,` / `,e.target_count]})]}),(0,z.jsx)(`div`,{className:`h-2 bg-bambu-dark/80 rounded-full overflow-hidden backdrop-blur-sm`,children:(0,z.jsx)(`div`,{className:`h-full transition-all duration-500 ease-out rounded-full relative`,style:{width:`${Math.min(c,100)}%`,background:c>=100?`linear-gradient(90deg, #22c55e, #4ade80)`:`linear-gradient(90deg, ${e.color||`#6b7280`}, ${e.color||`#6b7280`}cc)`,boxShadow:`0 0 8px ${c>=100?`#22c55e`:e.color||`#6b7280`}60`}})})]}),e.target_parts_count&&(0,z.jsxs)(`div`,{children:[(0,z.jsxs)(`div`,{className:`flex items-center justify-between text-xs mb-1`,children:[(0,z.jsx)(`span`,{className:`text-bambu-gray`,children:s(`projects.parts`)}),(0,z.jsxs)(`span`,{className:l>=100?`text-bambu-green font-medium`:`text-white`,children:[e.completed_count,` / `,e.target_parts_count]})]}),(0,z.jsx)(`div`,{className:`h-2 bg-bambu-dark/80 rounded-full overflow-hidden backdrop-blur-sm`,children:(0,z.jsx)(`div`,{className:`h-full transition-all duration-500 ease-out rounded-full relative`,style:{width:`${Math.min(l,100)}%`,background:l>=100?`linear-gradient(90deg, #22c55e, #4ade80)`:`linear-gradient(90deg, ${e.color||`#6b7280`}, ${e.color||`#6b7280`}cc)`,boxShadow:`0 0 8px ${l>=100?`#22c55e`:e.color||`#6b7280`}60`}})})]}),e.failed_count>0&&(0,z.jsxs)(`div`,{className:`text-xs text-red-600 dark:text-red-400`,children:[e.failed_count,` `,s(`projects.failed`)]})]}):e.completed_count>0||e.failed_count>0?(0,z.jsxs)(`div`,{className:`flex items-center gap-4 text-xs`,children:[e.completed_count>0&&(0,z.jsxs)(`div`,{className:`flex items-center gap-1.5 text-bambu-gray`,children:[(0,z.jsx)(C,{className:`w-3.5 h-3.5`}),(0,z.jsxs)(`span`,{children:[e.completed_count,` `,s(`projects.completed`)]})]}),e.failed_count>0&&(0,z.jsxs)(`div`,{className:`flex items-center gap-1.5 text-red-600 dark:text-red-400`,children:[(0,z.jsx)(g,{className:`w-3.5 h-3.5`}),(0,z.jsxs)(`span`,{children:[e.failed_count,` `,s(`projects.failed`)]})]}),e.queue_count>0&&(0,z.jsxs)(`div`,{className:`flex items-center gap-1.5 text-blue-600 dark:text-blue-400`,children:[(0,z.jsx)(T,{className:`w-3.5 h-3.5`}),(0,z.jsxs)(`span`,{children:[e.queue_count,` `,s(`projects.inQueue`)]})]})]}):(0,z.jsx)(`div`,{className:`text-xs text-bambu-gray/60 italic`,children:s(`projects.noPrintsYet`)})}),e.archives&&e.archives.length>0&&(0,z.jsxs)(`div`,{className:`mb-4`,children:[(0,z.jsx)(`div`,{className:`grid grid-cols-4 gap-1.5`,children:e.archives.slice(0,4).map(e=>(0,z.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,z.jsx)(`img`,{src:r.getArchiveThumbnail(e.id),alt:e.print_name||``,className:`w-full h-full object-cover`}):(0,z.jsx)(`div`,{className:`w-full h-full flex items-center justify-center text-bambu-gray/50`,children:(0,z.jsx)(m,{className:`w-6 h-6`})}),e.status===`failed`&&(0,z.jsx)(`div`,{className:`absolute inset-0 bg-red-500/40 flex items-center justify-center`,children:(0,z.jsx)(g,{className:`w-4 h-4 text-white`})})]},e.id))}),e.archive_count>4&&(0,z.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1.5 text-center`,children:s(`common.more`,{count:e.archive_count-4})})]}),(0,z.jsxs)(`div`,{className:`flex items-center justify-between pt-3 border-t border-bambu-dark-tertiary`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-4 text-xs text-bambu-gray`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-1.5`,title:s(`projects.printJobs`),children:[(0,z.jsx)(A,{className:`w-3.5 h-3.5 text-blue-600 dark:text-blue-400`}),(0,z.jsxs)(`span`,{children:[e.archive_count,` `,s(`projects.plates`)]})]}),(0,z.jsxs)(`div`,{className:`flex items-center gap-1.5`,title:s(`projects.partsPrinted`),children:[(0,z.jsx)(m,{className:`w-3.5 h-3.5 text-bambu-green`}),(0,z.jsxs)(`span`,{children:[e.completed_count,` `,s(`projects.parts`)]})]}),e.failed_count>0&&(0,z.jsxs)(`div`,{className:`flex items-center gap-1.5 text-red-600 dark:text-red-400`,title:s(`projects.failedParts`),children:[(0,z.jsx)(g,{className:`w-3.5 h-3.5`}),(0,z.jsx)(`span`,{children:e.failed_count})]}),e.queue_count>0&&(0,z.jsxs)(`div`,{className:`flex items-center gap-1.5 text-yellow-600 dark:text-yellow-400`,title:s(`projects.inQueue`),children:[(0,z.jsx)(I,{className:`w-3.5 h-3.5`}),(0,z.jsx)(`span`,{children:e.queue_count})]})]}),(0,z.jsx)(w,{className:`w-4 h-4 text-bambu-gray/50 group-hover:text-bambu-gray transition-colors`})]})]})]})}function W(){let{t:e}=i(),t=E(),n=o(),{showToast:a}=d(),{hasPermission:l}=P(),[f,m]=(0,L.useState)(!1),[h,g]=(0,L.useState)(),[_,b]=(0,L.useState)(`active`),[x,S]=(0,L.useState)(null),[A,ee]=(0,L.useState)(()=>localStorage.getItem(`projects-collapse-subprojects`)===`true`),[I,R]=(0,L.useState)({}),B=()=>{let e=!A;ee(e),R({}),localStorage.setItem(`projects-collapse-subprojects`,String(e))},{data:H}=s({queryKey:[`settings`],queryFn:r.getSettings}),W=k(H?.currency||`USD`),{data:G,isLoading:te}=s({queryKey:[`projects`,_===`all`?void 0:_],queryFn:()=>r.getProjects(_===`all`?void 0:_)}),{data:K}=s({queryKey:[`projects`,void 0],queryFn:()=>r.getProjects()}),q=new Map((K||[]).map(e=>[e.id,e.name])),J=G||[],Y=new Set(J.map(e=>e.id)),X=new Map;for(let e of J)if(e.parent_id!==null&&Y.has(e.parent_id)){let t=X.get(e.parent_id)||[];t.push(e),X.set(e.parent_id,t)}let Z=new Set,Q=e=>{if(!Z.has(e)){Z.add(e);for(let t of X.get(e)||[])Q(t.id)}},$=[];for(let e of J)e.parent_id!==null&&Y.has(e.parent_id)||($.push(e),Q(e.id));for(let e of J)Z.has(e.id)||($.push(e),Q(e.id));let ne=(t,n,r)=>{let i=(0,z.jsx)(U,{project:t,parentName:n===0&&t.parent_id!==null?q.get(t.parent_id):void 0,onClick:()=>pe(t),onEdit:()=>fe(t),onDelete:()=>me(t.id),hasPermission:l,t:e}),a=new Set(r).add(t.id),o=(X.get(t.id)||[]).filter(e=>!a.has(e.id));if(o.length===0)return(0,z.jsx)(`div`,{children:i},t.id);let s=I[t.id]??!A;return(0,z.jsxs)(`div`,{className:s?`col-span-full space-y-4`:`space-y-4`,children:[i,(0,z.jsxs)(`div`,{className:`ml-4 md:ml-8 pl-4 md:pl-6 border-l-2 rounded-l space-y-4`,style:{borderColor:t.color||`#6b7280`},children:[(0,z.jsxs)(`button`,{type:`button`,onClick:()=>R(e=>({...e,[t.id]:!s})),"aria-expanded":s,title:e(s?`projects.collapseSubProjects`:`projects.expandSubProjects`),className:`text-xs uppercase tracking-wide text-bambu-gray hover:text-white transition-colors flex items-center gap-1.5 max-w-full min-w-0`,children:[s?(0,z.jsx)(u,{className:`w-3.5 h-3.5 flex-shrink-0`}):(0,z.jsx)(w,{className:`w-3.5 h-3.5 flex-shrink-0`}),(0,z.jsx)(F,{className:`w-3.5 h-3.5 flex-shrink-0`}),(0,z.jsx)(`span`,{className:`truncate`,children:e(`projects.subProjectsOf`,{name:t.name})}),(0,z.jsx)(`span`,{className:`px-1.5 py-0.5 rounded-full bg-bambu-dark normal-case tracking-normal flex-shrink-0`,children:o.length})]}),s&&(0,z.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-8`,children:o.map(e=>ne(e,n+1,a))})]})]},t.id)},re=c({mutationFn:e=>r.createProject(e),onSuccess:()=>{n.invalidateQueries({queryKey:[`projects`]}),m(!1),a(e(`projects.toast.created`),`success`)},onError:e=>{a(e.message,`error`)}}),ie=c({mutationFn:({id:e,data:t})=>r.updateProject(e,t),onSuccess:()=>{n.invalidateQueries({queryKey:[`projects`]}),m(!1),g(void 0),a(e(`projects.toast.updated`),`success`)},onError:e=>{a(e.message,`error`)}}),ae=c({mutationFn:e=>r.deleteProject(e),onSuccess:()=>{S(null),a(e(`projects.toast.deleted`),`success`),setTimeout(()=>window.location.reload(),100)},onError:e=>{S(null),a(e.message,`error`)}}),oe=c({mutationFn:e=>r.importProject(e),onSuccess:()=>{n.invalidateQueries({queryKey:[`projects`]}),a(e(`projects.toast.imported`),`success`)},onError:e=>{a(e.message,`error`)}}),se=(0,L.useRef)(null),ce=async()=>{try{let t=await r.getProjects(),n=await Promise.all(t.map(async e=>await r.exportProjectJson(e.id))),i=new Blob([JSON.stringify(n,null,2)],{type:`application/json`}),o=URL.createObjectURL(i),s=document.createElement(`a`);s.href=o,s.download=`bambuddy_projects_${new Date().toISOString().split(`T`)[0]}.json`,s.click(),URL.revokeObjectURL(o),a(e(`projects.toast.exported`),`success`)}catch(e){a(e.message,`error`)}},le=()=>{se.current?.click()},ue=async t=>{let i=t.target.files?.[0];if(i){try{if(i.name.toLowerCase().endsWith(`.zip`))await r.importProjectFile(i),n.invalidateQueries({queryKey:[`projects`]}),a(e(`projects.toast.imported`),`success`);else{let t=await i.text(),n=JSON.parse(t),r=Array.isArray(n)?n:[n];for(let e of r)await oe.mutateAsync(e);r.length>1&&a(e(`projects.toast.multipleImported`,{count:r.length}),`success`)}}catch(t){a(`${e(`projects.toast.importFailed`)}: ${t.message}`,`error`)}t.target.value=``}},de=e=>{h?ie.mutate({id:h.id,data:e}):re.mutate(e)},fe=e=>{g(e),m(!0)},pe=e=>{t(`/projects/${e.id}`)},me=e=>{S(e)},he=()=>{x!==null&&ae.mutate(x)},ge=K?.reduce((e,t)=>(e[t.status]=(e[t.status]||0)+1,e.all=(e.all||0)+1,e),{})||{};return(0,z.jsxs)(`div`,{className:`p-4 md:p-8 space-y-8`,children:[(0,z.jsx)(`input`,{ref:se,type:`file`,accept:`.json,.zip`,onChange:ue,className:`hidden`}),(0,z.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-4`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,z.jsx)(N,{className:`w-7 h-7 text-bambu-green`}),e(`projects.title`)]}),(0,z.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:e(`projects.subtitle`)})]}),(0,z.jsxs)(`div`,{className:`flex gap-2`,children:[(0,z.jsxs)(v,{variant:`secondary`,onClick:le,disabled:!l(`projects:create`),title:l(`projects:create`)?e(`projects.importProject`):e(`projects.noImportPermission`),children:[(0,z.jsx)(j,{className:`w-4 h-4 mr-2`}),e(`projects.import`)]}),(0,z.jsxs)(v,{variant:`secondary`,onClick:ce,disabled:!l(`projects:read`),title:l(`projects:read`)?e(`projects.exportAll`):e(`projects.noExportPermission`),children:[(0,z.jsx)(M,{className:`w-4 h-4 mr-2`}),e(`projects.export`)]}),(0,z.jsxs)(v,{onClick:()=>m(!0),className:`sm:w-auto w-full`,disabled:!l(`projects:create`),title:l(`projects:create`)?void 0:e(`projects.noCreatePermission`),children:[(0,z.jsx)(D,{className:`w-4 h-4 mr-2`}),e(`projects.newProject`)]})]})]}),(0,z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,z.jsx)(`div`,{className:`flex gap-1 p-1 bg-bambu-dark rounded-xl w-fit`,children:[{key:`active`,label:e(`projects.statusActive`),icon:T},{key:`completed`,label:e(`projects.statusCompleted`),icon:y},{key:`archived`,label:e(`projects.statusArchived`),icon:C},{key:`all`,label:e(`common.all`),icon:N}].map(({key:e,label:t,icon:n})=>(0,z.jsxs)(`button`,{onClick:()=>b(e),className:`flex items-center gap-2 px-4 py-2 text-sm rounded-lg transition-all ${_===e?`bg-bambu-card text-white shadow-sm`:`text-bambu-gray hover:text-white`}`,children:[(0,z.jsx)(n,{className:`w-4 h-4`}),(0,z.jsx)(`span`,{children:t}),ge[e]>0&&(0,z.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded-full ${_===e?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark-tertiary`}`,children:ge[e]})]},e))}),X.size>0&&(0,z.jsxs)(`button`,{type:`button`,onClick:B,"aria-pressed":A,title:e(A?`projects.expandSubProjects`:`projects.collapseSubProjects`),className:`flex items-center gap-2 px-3 py-1.5 text-sm rounded-lg transition-colors ${A?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:text-white hover:bg-bambu-dark`}`,children:[(0,z.jsx)(F,{className:`w-4 h-4`}),e(`common.collapse`)]})]}),te?(0,z.jsx)(`div`,{className:`flex items-center justify-center py-20`,children:(0,z.jsxs)(`div`,{className:`flex flex-col items-center gap-3`,children:[(0,z.jsx)(p,{className:`w-8 h-8 animate-spin text-bambu-green`}),(0,z.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`projects.loading`)})]})}):G?.length===0?(0,z.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-20 px-4`,children:[(0,z.jsx)(`div`,{className:`p-4 bg-bambu-dark rounded-2xl mb-4`,children:(0,z.jsx)(N,{className:`w-12 h-12 text-bambu-gray/50`})}),(0,z.jsx)(`h3`,{className:`text-lg font-medium text-white mb-2`,children:_===`all`?e(`projects.noProjects`):e(`projects.noProjectsFiltered`,{status:_})}),(0,z.jsx)(`p`,{className:`text-bambu-gray text-center max-w-md mb-6`,children:_===`all`?e(`projects.createFirst`):e(`projects.noProjectsFilteredHelp`,{status:_})}),_===`all`&&(0,z.jsxs)(v,{onClick:()=>m(!0),disabled:!l(`projects:create`),title:l(`projects:create`)?void 0:e(`projects.noCreatePermission`),children:[(0,z.jsx)(D,{className:`w-4 h-4 mr-2`}),e(`projects.createFirstButton`)]})]}):(0,z.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-8`,children:$.map(e=>ne(e,0,new Set))}),x!==null&&(0,z.jsx)(O,{title:e(`projects.deleteProject`),message:e(`projects.deleteConfirm`),confirmText:e(`projects.deleteProject`),variant:`danger`,onConfirm:he,onCancel:()=>S(null)}),f&&(0,z.jsx)(V,{project:h,onClose:()=>{m(!1),g(void 0)},onSave:de,isLoading:re.isPending||ie.isPending,currencySymbol:W,t:e})]})}export{V as ProjectModal,W as ProjectsPage,F as n,I as t}; \ No newline at end of file +import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,w as i}from"./client-DnySrlFv.js";import{t as a}from"./react-dom-B8Dg6xzp.js";import{n as o}from"./QueryClientProvider-Ce8_sN3w.js";import{t as s}from"./useQuery-BBCjCezC.js";import{t as c}from"./useMutation-B-Tr2hIP.js";import{t as l}from"./createLucideIcon-DvBYJlWL.js";import{a as u}from"./info-ROUoQhJR.js";import{n as d}from"./ToastContext-BRX0SW3C.js";import{t as f}from"./ellipsis-vertical-t2D7cYyp.js";import{t as p}from"./loader-circle-BEmFtawu.js";import{t as m}from"./package-BGUevlqS.js";import{t as h}from"./pen-line-BWR04BX-.js";import{t as g}from"./triangle-alert-Dt_1FcBy.js";import{t as _}from"./x-DR-Trv6U.js";import{t as v}from"./Button-DDr6eAFy.js";import{An as y,At as b,Cn as x,I as S,Ln as C,Mn as w,On as T,Vn as E,Zt as D,_t as O,at as k,cn as A,kt as j,un as ee,wn as M,yn as N,yt as P}from"./index-Cxa-KVmA.js";var F=l(`folder-tree`,[[`path`,{d:`M20 10a1 1 0 0 0 1-1V6a1 1 0 0 0-1-1h-2.5a1 1 0 0 1-.8-.4l-.9-1.2A1 1 0 0 0 15 3h-2a1 1 0 0 0-1 1v5a1 1 0 0 0 1 1Z`,key:`hod4my`}],[`path`,{d:`M20 21a1 1 0 0 0 1-1v-3a1 1 0 0 0-1-1h-2.9a1 1 0 0 1-.88-.55l-.42-.85a1 1 0 0 0-.92-.6H13a1 1 0 0 0-1 1v5a1 1 0 0 0 1 1Z`,key:`w4yl2u`}],[`path`,{d:`M3 5a2 2 0 0 0 2 2h3`,key:`f2jnh7`}],[`path`,{d:`M3 3v13a2 2 0 0 0 2 2h3`,key:`k8epm1`}]]),I=l(`list-todo`,[[`path`,{d:`M13 5h8`,key:`a7qcls`}],[`path`,{d:`M13 12h8`,key:`h98zly`}],[`path`,{d:`M13 19h8`,key:`c3s6r1`}],[`path`,{d:`m3 17 2 2 4-4`,key:`1jhpwq`}],[`rect`,{x:`3`,y:`4`,width:`6`,height:`6`,rx:`1`,key:`cif1o7`}]]),L=e(n(),1),R=e(a(),1),z=t(),B=[`#ef4444`,`#f97316`,`#eab308`,`#22c55e`,`#06b6d4`,`#3b82f6`,`#8b5cf6`,`#ec4899`,`#6b7280`];function V({project:e,onClose:t,onSave:n,isLoading:i,currencySymbol:a,t:c}){let[l,u]=(0,L.useState)(e?.name||``),[d,f]=(0,L.useState)(e?.description||``),[m,h]=(0,L.useState)(e?.color||B[0]),[g,y]=(0,L.useState)(e?.target_count?.toString()||``),[b,x]=(0,L.useState)(e?.target_parts_count?.toString()||``),[C,w]=(0,L.useState)(e?.target_sets?.toString()||``),[T,E]=(0,L.useState)(e?.status||`active`),[D,O]=(0,L.useState)(e?.tags||``),[k,A]=(0,L.useState)(e?.due_date?.split(`T`)[0]||``),[M,N]=(0,L.useState)(e?.priority||`normal`),[P,F]=(0,L.useState)(e?.budget?.toString()||``),[I,R]=(0,L.useState)(e?.url||``),[V,H]=(0,L.useState)(null),[U,W]=(0,L.useState)(e?.parent_id??null),G=o(),{data:te}=s({queryKey:[`projects`,void 0],queryFn:()=>r.getProjects()}),K=S(te||[],e?.id),[q,J]=(0,L.useState)(e?.cover_image_filename||null),Y=(0,L.useRef)(null),[X,Z]=(0,L.useState)(!1),[Q,$]=(0,L.useState)(0);return(0,z.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,z.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,z.jsx)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary flex-shrink-0`,children:(0,z.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:c(e?`projects.editProject`:`projects.newProject`)})}),(0,z.jsxs)(`form`,{onSubmit:t=>{t.preventDefault();let r=I.trim();if(r&&!/^https?:\/\//i.test(r)){H(c(`projects.urlInvalid`));return}H(null),n({name:l.trim(),description:d.trim()||void 0,color:m,target_count:g?parseInt(g,10):void 0,target_parts_count:b?parseInt(b,10):void 0,target_sets:e?C?parseInt(C,10):null:C?parseInt(C,10):void 0,tags:e?D.trim()||null:D.trim()||void 0,due_date:e?k||null:k||void 0,priority:M,budget:P.trim()?parseFloat(P):null,url:e?r||null:r||void 0,parent_id:e?U??0:U??void 0,...e&&{status:T}})},className:`flex flex-col flex-1 min-h-0`,children:[(0,z.jsxs)(`div`,{className:`p-4 space-y-4 overflow-y-auto flex-1`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:c(`common.name`)}),(0,z.jsx)(`input`,{type:`text`,value:l,onChange:e=>u(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:c(`projects.namePlaceholder`),required:!0})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:c(`common.description`)}),(0,z.jsx)(`textarea`,{value:d,onChange:e=>f(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:c(`projects.descriptionPlaceholder`),rows:2})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:c(`projects.urlLabel`)}),(0,z.jsx)(`input`,{type:`url`,value:I,onChange:e=>{R(e.target.value),V&&H(null)},className:`w-full bg-bambu-dark border rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none ${V?`border-red-500 focus:border-red-500`:`border-bambu-dark-tertiary focus:border-bambu-green`}`,placeholder:c(`projects.urlPlaceholder`),maxLength:2048}),V&&(0,z.jsx)(`p`,{className:`text-xs text-red-600 dark:text-red-400 mt-1`,children:V})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:c(`projects.parentLabel`)}),(0,z.jsxs)(`select`,{value:U??``,onChange:e=>W(e.target.value?parseInt(e.target.value,10):null),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,z.jsx)(`option`,{value:``,children:c(`projects.parentNone`)}),K.map(e=>(0,z.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,z.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:c(`projects.parentHint`)})]}),e&&(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:c(`projects.coverImageLabel`)}),(0,z.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,z.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:q?(0,z.jsx)(`img`,{src:r.getProjectCoverImageUrl(e.id,Q),alt:c(`projects.coverImageAlt`),className:`w-full h-full object-cover`}):(0,z.jsx)(ee,{className:`w-6 h-6 text-bambu-gray`})}),(0,z.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,z.jsx)(`input`,{ref:Y,type:`file`,accept:`image/jpeg,image/png,image/gif,image/webp`,onChange:async t=>{let n=t.target.files?.[0];if(!(!n||!e)){Z(!0);try{J((await r.uploadProjectCoverImage(e.id,n)).filename),$(e=>e+1),G.invalidateQueries({queryKey:[`projects`]})}catch{}finally{Z(!1),Y.current&&(Y.current.value=``)}}},className:`hidden`}),(0,z.jsxs)(v,{type:`button`,variant:`secondary`,onClick:()=>Y.current?.click(),disabled:X,children:[X?(0,z.jsx)(p,{className:`w-4 h-4 animate-spin`}):(0,z.jsx)(j,{className:`w-4 h-4 mr-1`}),c(q?`projects.coverImageReplace`:`projects.coverImageUpload`)]}),q&&(0,z.jsxs)(v,{type:`button`,variant:`secondary`,onClick:async()=>{if(e){Z(!0);try{await r.deleteProjectCoverImage(e.id),J(null),$(e=>e+1),G.invalidateQueries({queryKey:[`projects`]})}finally{Z(!1)}}},disabled:X,children:[(0,z.jsx)(_,{className:`w-4 h-4 mr-1`}),c(`projects.coverImageRemove`)]})]})]})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:c(`projects.color`)}),(0,z.jsx)(`div`,{className:`flex gap-2 flex-wrap`,children:B.map(e=>(0,z.jsx)(`button`,{type:`button`,onClick:()=>h(e),className:`w-8 h-8 rounded-full transition-transform ${m===e?`ring-2 ring-white ring-offset-2 ring-offset-bambu-dark-secondary scale-110`:``}`,style:{backgroundColor:e}},e))})]}),(0,z.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:c(`projects.targetPlates`)}),(0,z.jsx)(`input`,{type:`number`,value:g,onChange:e=>y(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:c(`projects.targetPlatesPlaceholder`),min:`1`}),(0,z.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:c(`projects.targetPlatesHelp`)})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:c(`projects.targetParts`)}),(0,z.jsx)(`input`,{type:`number`,value:b,onChange:e=>x(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:c(`projects.targetPartsPlaceholder`),min:`1`}),(0,z.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:c(`projects.targetPartsHelp`)})]})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:c(`projects.targetSets`)}),(0,z.jsx)(`input`,{type:`number`,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 placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:c(`projects.targetSetsPlaceholder`),min:`1`}),(0,z.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:c(`projects.targetSetsHelp`)})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:c(`projects.tagsLabel`)}),(0,z.jsx)(`input`,{type:`text`,value:D,onChange:e=>O(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:c(`projects.tagsPlaceholder`)})]}),(0,z.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:c(`projects.dueDate`)}),(0,z.jsx)(`input`,{type:`date`,value:k,onChange:e=>A(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,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:c(`projects.priority`)}),(0,z.jsxs)(`select`,{value:M,onChange:e=>N(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,z.jsx)(`option`,{value:`low`,children:c(`projects.priorityLow`)}),(0,z.jsx)(`option`,{value:`normal`,children:c(`projects.priorityNormal`)}),(0,z.jsx)(`option`,{value:`high`,children:c(`projects.priorityHigh`)}),(0,z.jsx)(`option`,{value:`urgent`,children:c(`projects.priorityUrgent`)})]})]})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:c(`projectDetail.cost.budget`)}),(0,z.jsxs)(`div`,{className:`relative`,children:[(0,z.jsx)(`span`,{className:`absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray pointer-events-none`,children:a}),(0,z.jsx)(`input`,{type:`number`,step:`0.01`,min:`0`,value:P,onChange:e=>F(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,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:c(`common.status`)}),(0,z.jsxs)(`select`,{value:T,onChange:e=>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,z.jsx)(`option`,{value:`active`,children:c(`projects.statusActive`)}),(0,z.jsx)(`option`,{value:`completed`,children:c(`projects.statusCompleted`)}),(0,z.jsx)(`option`,{value:`archived`,children:c(`projects.statusArchived`)})]})]})]}),(0,z.jsxs)(`div`,{className:`flex justify-end gap-2 p-4 border-t border-bambu-dark-tertiary flex-shrink-0`,children:[(0,z.jsx)(v,{type:`button`,variant:`secondary`,onClick:t,children:c(`common.cancel`)}),(0,z.jsx)(v,{type:`submit`,disabled:!l.trim()||i,children:i?(0,z.jsx)(p,{className:`w-4 h-4 animate-spin`}):c(e?`common.save`:`projects.create`)})]})]})]})})}function H({projectId:e,altText:t}){let n=(0,L.useRef)(null),[i,a]=(0,L.useState)(!1),[o,s]=(0,L.useState)(null);return(0,z.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,i=e.right+8;i+384>t-8&&(i=e.left-384-8);let o=e.top;o+384>r-8&&(o=r-384-8),o<8&&(o=8),s({left:i,top:o}),a(!0)},onMouseLeave:()=>a(!1),onClick:e=>e.stopPropagation(),children:[(0,z.jsx)(`div`,{className:`w-10 h-10 rounded-lg overflow-hidden bg-bambu-dark border border-bambu-dark-tertiary`,children:(0,z.jsx)(`img`,{src:r.getProjectCoverImageUrl(e),alt:t,className:`w-full h-full object-cover`,loading:`lazy`})}),i&&o&&(0,R.createPortal)((0,z.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:o.left,top:o.top},"aria-hidden":`true`,children:(0,z.jsx)(`img`,{src:r.getProjectCoverImageUrl(e),alt:``,className:`w-full h-full object-contain`,loading:`lazy`})}),document.body)]})}function U({project:e,parentName:t,onClick:n,onEdit:i,onDelete:a,hasPermission:o,t:s}){let c=e.target_count?Math.round(e.archive_count/e.target_count*100):0,l=e.target_parts_count?Math.round(e.completed_count/e.target_parts_count*100):0,u=e.status===`completed`,d=e.status===`archived`,[p,_]=(0,L.useState)(!1),v=u?{icon:y,color:`text-bambu-green`,bg:`bg-bambu-green/10`}:d?{icon:C,color:`text-bambu-gray`,bg:`bg-bambu-gray/10`}:e.queue_count>0?{icon:T,color:`text-blue-600 dark:text-blue-400`,bg:`bg-blue-50 dark:bg-blue-400/10`}:{icon:N,color:`text-bambu-gray`,bg:`bg-bambu-gray/10`};return(0,z.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:n,children:[(0,z.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,z.jsxs)(`div`,{className:`p-5 pl-6`,children:[(0,z.jsxs)(`div`,{className:`flex items-start justify-between mb-4`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 flex-1`,children:[e.cover_image_filename?(0,z.jsx)(H,{projectId:e.id,altText:s(`projects.coverImageAlt`)}):(0,z.jsx)(`div`,{className:`p-2 rounded-lg ${v.bg} flex-shrink-0`,children:(0,z.jsx)(v.icon,{className:`w-5 h-5 ${v.color}`})}),(0,z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,z.jsx)(`h3`,{className:`font-semibold text-white truncate`,children:e.name}),e.url&&(0,z.jsx)(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,onClick:e=>e.stopPropagation(),title:e.url,"aria-label":s(`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,z.jsx)(x,{className:`w-3.5 h-3.5`})}),e.target_parts_count?(0,z.jsxs)(`span`,{className:`text-xs px-2 py-0.5 rounded-full whitespace-nowrap font-medium ${l>=100?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark text-bambu-gray`}`,children:[e.completed_count,`/`,e.target_parts_count,` `,s(`projects.parts`)]}):e.target_count?(0,z.jsxs)(`span`,{className:`text-xs px-2 py-0.5 rounded-full whitespace-nowrap font-medium ${c>=100?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark text-bambu-gray`}`,children:[e.archive_count,`/`,e.target_count,` `,s(`projects.plates`)]}):e.completed_count>0?(0,z.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,` `,s(`projects.parts`)]}):null,u&&(0,z.jsx)(`span`,{className:`text-xs bg-bambu-green/20 text-bambu-green px-2 py-0.5 rounded-full whitespace-nowrap`,children:s(`projects.done`)}),d&&(0,z.jsx)(`span`,{className:`text-xs bg-bambu-gray/20 text-bambu-gray px-2 py-0.5 rounded-full whitespace-nowrap`,children:s(`projects.statusArchived`)}),e.child_count>0&&(0,z.jsxs)(`span`,{className:`text-xs bg-bambu-dark text-bambu-gray px-2 py-0.5 rounded-full whitespace-nowrap inline-flex items-center gap-1`,title:s(`projects.subProjectCount`,{count:e.child_count}),children:[(0,z.jsx)(F,{className:`w-3 h-3`}),e.child_count]})]}),t&&(0,z.jsxs)(`p`,{className:`text-xs text-bambu-gray mt-1 flex items-center gap-1`,children:[(0,z.jsx)(A,{className:`w-3 h-3 flex-shrink-0`}),(0,z.jsx)(`span`,{className:`truncate`,children:s(`projects.partOf`,{name:t})})]}),e.description&&(0,z.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,z.jsxs)(`div`,{className:`flex items-center gap-2 mt-1.5`,children:[n.slice(0,3).map(e=>(0,z.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,z.jsxs)(`div`,{className:`flex items-center gap-0.5`,children:[i.slice(0,5).map(e=>(0,z.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,z.jsxs)(`span`,{className:`text-[10px] text-bambu-gray ml-0.5`,children:[`+`,i.length-5]})]})]})})()]})]}),(0,z.jsxs)(`div`,{className:`relative`,onClick:e=>e.stopPropagation(),children:[(0,z.jsx)(`button`,{className:`p-1.5 rounded-lg hover:bg-bambu-dark text-bambu-gray hover:text-white transition-colors can-hover:opacity-0 group-hover:opacity-100 focus-visible:opacity-100`,onClick:()=>_(!p),children:(0,z.jsx)(f,{className:`w-4 h-4`})}),p&&(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>_(!1)}),(0,z.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,z.jsxs)(`button`,{className:`w-full px-3 py-2 text-left text-sm flex items-center gap-2 ${o(`projects:update`)?`text-white hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{o(`projects:update`)&&(i(),_(!1))},disabled:!o(`projects:update`),title:o(`projects:update`)?void 0:s(`projects.noEditPermission`),children:[(0,z.jsx)(h,{className:`w-4 h-4`}),s(`common.edit`)]}),(0,z.jsxs)(`button`,{className:`w-full px-3 py-2 text-left text-sm flex items-center gap-2 ${o(`projects:delete`)?`text-red-600 dark:text-red-400 hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{o(`projects:delete`)&&(a(),_(!1))},disabled:!o(`projects:delete`),title:o(`projects:delete`)?void 0:s(`projects.noDeletePermission`),children:[(0,z.jsx)(b,{className:`w-4 h-4`}),s(`common.delete`)]})]})]})]})]}),(0,z.jsx)(`div`,{className:`mb-4`,children:e.target_count||e.target_parts_count?(0,z.jsxs)(`div`,{className:`space-y-3`,children:[e.target_count&&(0,z.jsxs)(`div`,{children:[(0,z.jsxs)(`div`,{className:`flex items-center justify-between text-xs mb-1`,children:[(0,z.jsx)(`span`,{className:`text-bambu-gray`,children:s(`projects.plates`)}),(0,z.jsxs)(`span`,{className:c>=100?`text-bambu-green font-medium`:`text-white`,children:[e.archive_count,` / `,e.target_count]})]}),(0,z.jsx)(`div`,{className:`h-2 bg-bambu-dark/80 rounded-full overflow-hidden backdrop-blur-sm`,children:(0,z.jsx)(`div`,{className:`h-full transition-all duration-500 ease-out rounded-full relative`,style:{width:`${Math.min(c,100)}%`,background:c>=100?`linear-gradient(90deg, #22c55e, #4ade80)`:`linear-gradient(90deg, ${e.color||`#6b7280`}, ${e.color||`#6b7280`}cc)`,boxShadow:`0 0 8px ${c>=100?`#22c55e`:e.color||`#6b7280`}60`}})})]}),e.target_parts_count&&(0,z.jsxs)(`div`,{children:[(0,z.jsxs)(`div`,{className:`flex items-center justify-between text-xs mb-1`,children:[(0,z.jsx)(`span`,{className:`text-bambu-gray`,children:s(`projects.parts`)}),(0,z.jsxs)(`span`,{className:l>=100?`text-bambu-green font-medium`:`text-white`,children:[e.completed_count,` / `,e.target_parts_count]})]}),(0,z.jsx)(`div`,{className:`h-2 bg-bambu-dark/80 rounded-full overflow-hidden backdrop-blur-sm`,children:(0,z.jsx)(`div`,{className:`h-full transition-all duration-500 ease-out rounded-full relative`,style:{width:`${Math.min(l,100)}%`,background:l>=100?`linear-gradient(90deg, #22c55e, #4ade80)`:`linear-gradient(90deg, ${e.color||`#6b7280`}, ${e.color||`#6b7280`}cc)`,boxShadow:`0 0 8px ${l>=100?`#22c55e`:e.color||`#6b7280`}60`}})})]}),e.failed_count>0&&(0,z.jsxs)(`div`,{className:`text-xs text-red-600 dark:text-red-400`,children:[e.failed_count,` `,s(`projects.failed`)]})]}):e.completed_count>0||e.failed_count>0?(0,z.jsxs)(`div`,{className:`flex items-center gap-4 text-xs`,children:[e.completed_count>0&&(0,z.jsxs)(`div`,{className:`flex items-center gap-1.5 text-bambu-gray`,children:[(0,z.jsx)(C,{className:`w-3.5 h-3.5`}),(0,z.jsxs)(`span`,{children:[e.completed_count,` `,s(`projects.completed`)]})]}),e.failed_count>0&&(0,z.jsxs)(`div`,{className:`flex items-center gap-1.5 text-red-600 dark:text-red-400`,children:[(0,z.jsx)(g,{className:`w-3.5 h-3.5`}),(0,z.jsxs)(`span`,{children:[e.failed_count,` `,s(`projects.failed`)]})]}),e.queue_count>0&&(0,z.jsxs)(`div`,{className:`flex items-center gap-1.5 text-blue-600 dark:text-blue-400`,children:[(0,z.jsx)(T,{className:`w-3.5 h-3.5`}),(0,z.jsxs)(`span`,{children:[e.queue_count,` `,s(`projects.inQueue`)]})]})]}):(0,z.jsx)(`div`,{className:`text-xs text-bambu-gray/60 italic`,children:s(`projects.noPrintsYet`)})}),e.archives&&e.archives.length>0&&(0,z.jsxs)(`div`,{className:`mb-4`,children:[(0,z.jsx)(`div`,{className:`grid grid-cols-4 gap-1.5`,children:e.archives.slice(0,4).map(e=>(0,z.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,z.jsx)(`img`,{src:r.getArchiveThumbnail(e.id),alt:e.print_name||``,className:`w-full h-full object-cover`}):(0,z.jsx)(`div`,{className:`w-full h-full flex items-center justify-center text-bambu-gray/50`,children:(0,z.jsx)(m,{className:`w-6 h-6`})}),e.status===`failed`&&(0,z.jsx)(`div`,{className:`absolute inset-0 bg-red-500/40 flex items-center justify-center`,children:(0,z.jsx)(g,{className:`w-4 h-4 text-white`})})]},e.id))}),e.archive_count>4&&(0,z.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1.5 text-center`,children:s(`common.more`,{count:e.archive_count-4})})]}),(0,z.jsxs)(`div`,{className:`flex items-center justify-between pt-3 border-t border-bambu-dark-tertiary`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-4 text-xs text-bambu-gray`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-1.5`,title:s(`projects.printJobs`),children:[(0,z.jsx)(A,{className:`w-3.5 h-3.5 text-blue-600 dark:text-blue-400`}),(0,z.jsxs)(`span`,{children:[e.archive_count,` `,s(`projects.plates`)]})]}),(0,z.jsxs)(`div`,{className:`flex items-center gap-1.5`,title:s(`projects.partsPrinted`),children:[(0,z.jsx)(m,{className:`w-3.5 h-3.5 text-bambu-green`}),(0,z.jsxs)(`span`,{children:[e.completed_count,` `,s(`projects.parts`)]})]}),e.failed_count>0&&(0,z.jsxs)(`div`,{className:`flex items-center gap-1.5 text-red-600 dark:text-red-400`,title:s(`projects.failedParts`),children:[(0,z.jsx)(g,{className:`w-3.5 h-3.5`}),(0,z.jsx)(`span`,{children:e.failed_count})]}),e.queue_count>0&&(0,z.jsxs)(`div`,{className:`flex items-center gap-1.5 text-yellow-600 dark:text-yellow-400`,title:s(`projects.inQueue`),children:[(0,z.jsx)(I,{className:`w-3.5 h-3.5`}),(0,z.jsx)(`span`,{children:e.queue_count})]})]}),(0,z.jsx)(w,{className:`w-4 h-4 text-bambu-gray/50 group-hover:text-bambu-gray transition-colors`})]})]})]})}function W(){let{t:e}=i(),t=E(),n=o(),{showToast:a}=d(),{hasPermission:l}=P(),[f,m]=(0,L.useState)(!1),[h,g]=(0,L.useState)(),[_,b]=(0,L.useState)(`active`),[x,S]=(0,L.useState)(null),[A,ee]=(0,L.useState)(()=>localStorage.getItem(`projects-collapse-subprojects`)===`true`),[I,R]=(0,L.useState)({}),B=()=>{let e=!A;ee(e),R({}),localStorage.setItem(`projects-collapse-subprojects`,String(e))},{data:H}=s({queryKey:[`settings`],queryFn:r.getSettings}),W=k(H?.currency||`USD`),{data:G,isLoading:te}=s({queryKey:[`projects`,_===`all`?void 0:_],queryFn:()=>r.getProjects(_===`all`?void 0:_)}),{data:K}=s({queryKey:[`projects`,void 0],queryFn:()=>r.getProjects()}),q=new Map((K||[]).map(e=>[e.id,e.name])),J=G||[],Y=new Set(J.map(e=>e.id)),X=new Map;for(let e of J)if(e.parent_id!==null&&Y.has(e.parent_id)){let t=X.get(e.parent_id)||[];t.push(e),X.set(e.parent_id,t)}let Z=new Set,Q=e=>{if(!Z.has(e)){Z.add(e);for(let t of X.get(e)||[])Q(t.id)}},$=[];for(let e of J)e.parent_id!==null&&Y.has(e.parent_id)||($.push(e),Q(e.id));for(let e of J)Z.has(e.id)||($.push(e),Q(e.id));let ne=(t,n,r)=>{let i=(0,z.jsx)(U,{project:t,parentName:n===0&&t.parent_id!==null?q.get(t.parent_id):void 0,onClick:()=>pe(t),onEdit:()=>fe(t),onDelete:()=>me(t.id),hasPermission:l,t:e}),a=new Set(r).add(t.id),o=(X.get(t.id)||[]).filter(e=>!a.has(e.id));if(o.length===0)return(0,z.jsx)(`div`,{children:i},t.id);let s=I[t.id]??!A;return(0,z.jsxs)(`div`,{className:s?`col-span-full space-y-4`:`space-y-4`,children:[i,(0,z.jsxs)(`div`,{className:`ml-4 md:ml-8 pl-4 md:pl-6 border-l-2 rounded-l space-y-4`,style:{borderColor:t.color||`#6b7280`},children:[(0,z.jsxs)(`button`,{type:`button`,onClick:()=>R(e=>({...e,[t.id]:!s})),"aria-expanded":s,title:e(s?`projects.collapseSubProjects`:`projects.expandSubProjects`),className:`text-xs uppercase tracking-wide text-bambu-gray hover:text-white transition-colors flex items-center gap-1.5 max-w-full min-w-0`,children:[s?(0,z.jsx)(u,{className:`w-3.5 h-3.5 flex-shrink-0`}):(0,z.jsx)(w,{className:`w-3.5 h-3.5 flex-shrink-0`}),(0,z.jsx)(F,{className:`w-3.5 h-3.5 flex-shrink-0`}),(0,z.jsx)(`span`,{className:`truncate`,children:e(`projects.subProjectsOf`,{name:t.name})}),(0,z.jsx)(`span`,{className:`px-1.5 py-0.5 rounded-full bg-bambu-dark normal-case tracking-normal flex-shrink-0`,children:o.length})]}),s&&(0,z.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-8`,children:o.map(e=>ne(e,n+1,a))})]})]},t.id)},re=c({mutationFn:e=>r.createProject(e),onSuccess:()=>{n.invalidateQueries({queryKey:[`projects`]}),m(!1),a(e(`projects.toast.created`),`success`)},onError:e=>{a(e.message,`error`)}}),ie=c({mutationFn:({id:e,data:t})=>r.updateProject(e,t),onSuccess:()=>{n.invalidateQueries({queryKey:[`projects`]}),m(!1),g(void 0),a(e(`projects.toast.updated`),`success`)},onError:e=>{a(e.message,`error`)}}),ae=c({mutationFn:e=>r.deleteProject(e),onSuccess:()=>{S(null),a(e(`projects.toast.deleted`),`success`),setTimeout(()=>window.location.reload(),100)},onError:e=>{S(null),a(e.message,`error`)}}),oe=c({mutationFn:e=>r.importProject(e),onSuccess:()=>{n.invalidateQueries({queryKey:[`projects`]}),a(e(`projects.toast.imported`),`success`)},onError:e=>{a(e.message,`error`)}}),se=(0,L.useRef)(null),ce=async()=>{try{let t=await r.getProjects(),n=await Promise.all(t.map(async e=>await r.exportProjectJson(e.id))),i=new Blob([JSON.stringify(n,null,2)],{type:`application/json`}),o=URL.createObjectURL(i),s=document.createElement(`a`);s.href=o,s.download=`bambuddy_projects_${new Date().toISOString().split(`T`)[0]}.json`,s.click(),URL.revokeObjectURL(o),a(e(`projects.toast.exported`),`success`)}catch(e){a(e.message,`error`)}},le=()=>{se.current?.click()},ue=async t=>{let i=t.target.files?.[0];if(i){try{if(i.name.toLowerCase().endsWith(`.zip`))await r.importProjectFile(i),n.invalidateQueries({queryKey:[`projects`]}),a(e(`projects.toast.imported`),`success`);else{let t=await i.text(),n=JSON.parse(t),r=Array.isArray(n)?n:[n];for(let e of r)await oe.mutateAsync(e);r.length>1&&a(e(`projects.toast.multipleImported`,{count:r.length}),`success`)}}catch(t){a(`${e(`projects.toast.importFailed`)}: ${t.message}`,`error`)}t.target.value=``}},de=e=>{h?ie.mutate({id:h.id,data:e}):re.mutate(e)},fe=e=>{g(e),m(!0)},pe=e=>{t(`/projects/${e.id}`)},me=e=>{S(e)},he=()=>{x!==null&&ae.mutate(x)},ge=K?.reduce((e,t)=>(e[t.status]=(e[t.status]||0)+1,e.all=(e.all||0)+1,e),{})||{};return(0,z.jsxs)(`div`,{className:`p-4 md:p-8 space-y-8`,children:[(0,z.jsx)(`input`,{ref:se,type:`file`,accept:`.json,.zip`,onChange:ue,className:`hidden`}),(0,z.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-4`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,z.jsx)(N,{className:`w-7 h-7 text-bambu-green`}),e(`projects.title`)]}),(0,z.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:e(`projects.subtitle`)})]}),(0,z.jsxs)(`div`,{className:`flex gap-2`,children:[(0,z.jsxs)(v,{variant:`secondary`,onClick:le,disabled:!l(`projects:create`),title:l(`projects:create`)?e(`projects.importProject`):e(`projects.noImportPermission`),children:[(0,z.jsx)(j,{className:`w-4 h-4 mr-2`}),e(`projects.import`)]}),(0,z.jsxs)(v,{variant:`secondary`,onClick:ce,disabled:!l(`projects:read`),title:l(`projects:read`)?e(`projects.exportAll`):e(`projects.noExportPermission`),children:[(0,z.jsx)(M,{className:`w-4 h-4 mr-2`}),e(`projects.export`)]}),(0,z.jsxs)(v,{onClick:()=>m(!0),className:`sm:w-auto w-full`,disabled:!l(`projects:create`),title:l(`projects:create`)?void 0:e(`projects.noCreatePermission`),children:[(0,z.jsx)(D,{className:`w-4 h-4 mr-2`}),e(`projects.newProject`)]})]})]}),(0,z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,z.jsx)(`div`,{className:`flex gap-1 p-1 bg-bambu-dark rounded-xl w-fit`,children:[{key:`active`,label:e(`projects.statusActive`),icon:T},{key:`completed`,label:e(`projects.statusCompleted`),icon:y},{key:`archived`,label:e(`projects.statusArchived`),icon:C},{key:`all`,label:e(`common.all`),icon:N}].map(({key:e,label:t,icon:n})=>(0,z.jsxs)(`button`,{onClick:()=>b(e),className:`flex items-center gap-2 px-4 py-2 text-sm rounded-lg transition-all ${_===e?`bg-bambu-card text-white shadow-sm`:`text-bambu-gray hover:text-white`}`,children:[(0,z.jsx)(n,{className:`w-4 h-4`}),(0,z.jsx)(`span`,{children:t}),ge[e]>0&&(0,z.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded-full ${_===e?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark-tertiary`}`,children:ge[e]})]},e))}),X.size>0&&(0,z.jsxs)(`button`,{type:`button`,onClick:B,"aria-pressed":A,title:e(A?`projects.expandSubProjects`:`projects.collapseSubProjects`),className:`flex items-center gap-2 px-3 py-1.5 text-sm rounded-lg transition-colors ${A?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:text-white hover:bg-bambu-dark`}`,children:[(0,z.jsx)(F,{className:`w-4 h-4`}),e(`common.collapse`)]})]}),te?(0,z.jsx)(`div`,{className:`flex items-center justify-center py-20`,children:(0,z.jsxs)(`div`,{className:`flex flex-col items-center gap-3`,children:[(0,z.jsx)(p,{className:`w-8 h-8 animate-spin text-bambu-green`}),(0,z.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`projects.loading`)})]})}):G?.length===0?(0,z.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-20 px-4`,children:[(0,z.jsx)(`div`,{className:`p-4 bg-bambu-dark rounded-2xl mb-4`,children:(0,z.jsx)(N,{className:`w-12 h-12 text-bambu-gray/50`})}),(0,z.jsx)(`h3`,{className:`text-lg font-medium text-white mb-2`,children:_===`all`?e(`projects.noProjects`):e(`projects.noProjectsFiltered`,{status:_})}),(0,z.jsx)(`p`,{className:`text-bambu-gray text-center max-w-md mb-6`,children:_===`all`?e(`projects.createFirst`):e(`projects.noProjectsFilteredHelp`,{status:_})}),_===`all`&&(0,z.jsxs)(v,{onClick:()=>m(!0),disabled:!l(`projects:create`),title:l(`projects:create`)?void 0:e(`projects.noCreatePermission`),children:[(0,z.jsx)(D,{className:`w-4 h-4 mr-2`}),e(`projects.createFirstButton`)]})]}):(0,z.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-8`,children:$.map(e=>ne(e,0,new Set))}),x!==null&&(0,z.jsx)(O,{title:e(`projects.deleteProject`),message:e(`projects.deleteConfirm`),confirmText:e(`projects.deleteProject`),variant:`danger`,onConfirm:he,onCancel:()=>S(null)}),f&&(0,z.jsx)(V,{project:h,onClose:()=>{m(!1),g(void 0)},onSave:de,isLoading:re.isPending||ie.isPending,currencySymbol:W,t:e})]})}export{V as ProjectModal,W as ProjectsPage,F as n,I as t}; \ No newline at end of file diff --git a/static/assets/QueuePage-CjROU5dj.js b/static/assets/QueuePage-NR_JuCMy.js similarity index 54% rename from static/assets/QueuePage-CjROU5dj.js rename to static/assets/QueuePage-NR_JuCMy.js index 6587a758f..7e50696bd 100644 --- a/static/assets/QueuePage-CjROU5dj.js +++ b/static/assets/QueuePage-NR_JuCMy.js @@ -1,4 +1,4 @@ -import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,t as i,w as a}from"./client-DnySrlFv.js";import{n as o}from"./QueryClientProvider-Ce8_sN3w.js";import{t as s}from"./useQuery-BBCjCezC.js";import{t as c}from"./useMutation-B-Tr2hIP.js";import{t as l}from"./useQueries-Be6PMvSC.js";import{t as u}from"./createLucideIcon-DvBYJlWL.js";import{t as d}from"./arrow-down-Cj0DZhNf.js";import{t as f}from"./arrow-up-D-pfJ3WZ.js";import{a as p,c as m,d as h,f as g,h as _,i as v,l as y,m as b,o as x,p as S,s as ee,t as C,u as te}from"./sortable.esm-D2bGix-3.js";import{t as w}from"./calendar-BLKPnWqV.js";import{t as ne}from"./check-Ck0cMLU4.js";import{a as T,i as re,n as E,r as D}from"./info-ROUoQhJR.js";import{n as O,r as k}from"./ToastContext-BRX0SW3C.js";import{t as A}from"./coins-4u6IPkR-.js";import{t as j}from"./funnel-C3dyAMK9.js";import{t as M}from"./grip-vertical-C_1RDxRw.js";import{t as ie}from"./list-CLcpeoSz.js";import{t as ae}from"./loader-circle-BEmFtawu.js";import{t as N}from"./package-BGUevlqS.js";import{t as P}from"./pause-DFb6GX_6.js";import{t as oe}from"./play-DIDYtk2S.js";import{t as F}from"./skip-forward-BsuMfFkw.js";import{t as I}from"./timer-GUTR9dAu.js";import{t as L}from"./triangle-alert-Dt_1FcBy.js";import{t as se}from"./workflow-BgT0wW83.js";import{t as ce}from"./x-DR-Trv6U.js";import{t as le}from"./Card-Bzc64K35.js";import{t as R}from"./Button-DDr6eAFy.js";import{c as ue,o as de,u as fe,v as z}from"./date-G9KUauqz.js";import{$t as pe,A as me,At as he,Cn as ge,En as _e,Gt as B,H as ve,Jt as ye,Kt as V,Lt as be,Mn as xe,On as H,Ot as Se,Rn as Ce,Rt as we,T as U,W,Yt as Te,_t as Ee,at as De,b as Oe,cn as ke,ct as G,jn as Ae,jt as je,mn as Me,on as Ne,w as K,wt as Pe,xn as Fe,yt as Ie}from"./index-0t--Yqoi.js";import{t as Le}from"./queueItemName-UFY7kpjG.js";var Re=u(`chart-no-axes-gantt`,[[`path`,{d:`M6 5h12`,key:`fvfigv`}],[`path`,{d:`M4 12h10`,key:`oujl3d`}],[`path`,{d:`M12 19h8`,key:`baeox8`}]]),ze=u(`circle-play`,[[`path`,{d:`M9 9.003a1 1 0 0 1 1.517-.859l4.997 2.997a1 1 0 0 1 0 1.718l-4.997 2.997A1 1 0 0 1 9 14.996z`,key:`kmsa83`}],[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}]]),Be=u(`circle-stop`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`rect`,{x:`9`,y:`9`,width:`6`,height:`6`,rx:`1`,key:`1ssd4o`}]]),Ve=u(`package-open`,[[`path`,{d:`M12 22v-9`,key:`x3hkom`}],[`path`,{d:`M15.17 2.21a1.67 1.67 0 0 1 1.63 0L21 4.57a1.93 1.93 0 0 1 0 3.36L8.82 14.79a1.655 1.655 0 0 1-1.64 0L3 12.43a1.93 1.93 0 0 1 0-3.36z`,key:`2ntwy6`}],[`path`,{d:`M20 13v3.87a2.06 2.06 0 0 1-1.11 1.83l-6 3.08a1.93 1.93 0 0 1-1.78 0l-6-3.08A2.06 2.06 0 0 1 4 16.87V13`,key:`1pmm1c`}],[`path`,{d:`M21 12.43a1.93 1.93 0 0 0 0-3.36L8.83 2.2a1.64 1.64 0 0 0-1.63 0L3 4.57a1.93 1.93 0 0 0 0 3.36l12.18 6.86a1.636 1.636 0 0 0 1.63 0z`,key:`12ttoo`}]]),He=u(`snail`,[[`path`,{d:`M2 13a6 6 0 1 0 12 0 4 4 0 1 0-8 0 2 2 0 0 0 4 0`,key:`hneq2s`}],[`circle`,{cx:`10`,cy:`13`,r:`8`,key:`194lz3`}],[`path`,{d:`M2 21h12c4.4 0 8-3.6 8-8V7a2 2 0 1 0-4 0v6`,key:`ixqyt7`}],[`path`,{d:`M18 3 19.1 5.2`,key:`9tjm43`}],[`path`,{d:`M22 3 20.9 5.2`,key:`j3odrs`}]]),Ue=u(`ungroup`,[[`rect`,{width:`8`,height:`6`,x:`5`,y:`4`,rx:`1`,key:`nzclkv`}],[`rect`,{width:`8`,height:`6`,x:`11`,y:`14`,rx:`1`,key:`4tytwb`}]]),q=e(n(),1),J=t(),We=[``,`queued`,`slicing`,`dispatching`,`in_progress`,`completed`,`partial_failure`,`failed`,`cancelled`],Y=25;function Ge(){let{t:e}=a(),t=o(),{showToast:n}=O(),[i,l]=(0,q.useState)(``),[u,d]=(0,q.useState)(null),[f,p]=(0,q.useState)(``),[m,h]=(0,q.useState)(0),[g,_]=(0,q.useState)(new Set),[v,y]=(0,q.useState)(!1),{data:b}=s({queryKey:[`slicer-pipelines`],queryFn:()=>r.listSlicerPipelines()}),{data:x}=s({queryKey:[`printers`],queryFn:()=>r.getPrinters()}),S=(x??[]).reduce((e,t)=>(e[t.id]=t,e),{}),ee=f.startsWith(`p:`)?parseInt(f.slice(2),10):void 0,C=f.startsWith(`c:`)?f.slice(2):void 0,{data:te,isLoading:w}=s({queryKey:[`pipeline-runs-all`,i,u,m,f],queryFn:()=>r.listAllPipelineRuns({limit:Y,offset:m,pipelineId:u??void 0,status:i||void 0,targetPrinterId:ee,targetModelClass:C}),refetchInterval:15e3}),ne=c({mutationFn:e=>r.cancelPipelineRun(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`pipeline-runs-all`]}),n(e(`pipelineRuns.toast.cancelled`,`Run cancelled`),`success`)},onError:t=>n(t.message||e(`pipelineRuns.toast.cancelFailed`,`Cancel failed`),`error`)}),T=c({mutationFn:e=>r.retryFailedPipelineRun(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`pipeline-runs-all`]}),n(e(`pipelineRuns.toast.retryStarted`,`Retry started`),`success`)},onError:t=>n(t.message||e(`pipelineRuns.toast.retryFailed`,`Retry failed`),`error`)}),re=c({mutationFn:()=>r.clearTerminalPipelineRuns(),onSuccess:r=>{t.invalidateQueries({queryKey:[`pipeline-runs-all`]}),y(!1),h(0),n(e(`pipelineRuns.toast.cleared`,`{{n}} runs cleared`,{n:r.deleted}),`success`)},onError:t=>n(t.message||e(`pipelineRuns.toast.clearFailed`,`Clear failed`),`error`)}),E=te?.runs??[],D=te?.total??0,k=(b?.pipelines??[]).reduce((e,t)=>(e[t.id]=t,e),{}),A=e=>{_(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},M=!!(i||u!==null||f),ie=(()=>{let e=new Set,t=new Set;for(let n of b?.pipelines??[])n.target_kind===`printer_class`&&n.target_model_class?t.add(n.target_model_class):n.target_printer_id&&e.add(n.target_printer_id);return{printers:(x??[]).filter(t=>e.has(t.id)),classes:Array.from(t).sort()}})();return(0,J.jsxs)(`div`,{children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 mb-4 text-sm`,children:[(0,J.jsx)(`button`,{type:`button`,onClick:()=>t.invalidateQueries({queryKey:[`pipeline-runs-all`]}),"aria-label":e(`common.refresh`,`Refresh`),title:e(`common.refresh`,`Refresh`),className:`p-1.5 text-bambu-gray hover:text-white border border-bambu-dark-tertiary rounded`,children:(0,J.jsx)(V,{className:`w-3.5 h-3.5`})}),(0,J.jsx)(qe,{icon:(0,J.jsx)(se,{className:`w-3.5 h-3.5 text-bambu-gray`}),ariaLabel:e(`pipelineRuns.filter.pipeline`,`Pipeline`),value:u===null?``:String(u),onChange:e=>{h(0),d(e?parseInt(e,10):null)},options:[{value:``,label:e(`pipelineRuns.filter.allPipelines`,`All pipelines`)},...(b?.pipelines??[]).map(e=>({value:String(e.id),label:e.name}))]}),(0,J.jsx)(qe,{icon:(0,J.jsx)(j,{className:`w-3.5 h-3.5 text-bambu-gray`}),ariaLabel:e(`pipelineRuns.filter.status`,`Status`),value:i,onChange:e=>{h(0),l(e)},options:We.map(t=>({value:t,label:t===``?e(`pipelineRuns.filter.allStatus`,`All statuses`):e(`settings.pipelines.runs.status.${t}`,t)}))}),(ie.printers.length>0||ie.classes.length>0)&&(0,J.jsx)(qe,{icon:(0,J.jsx)(ye,{className:`w-3.5 h-3.5 text-bambu-gray`}),ariaLabel:e(`pipelineRuns.filter.target`,`Target`),value:f,onChange:e=>{h(0),p(e)},options:[{value:``,label:e(`pipelineRuns.filter.allTargets`,`All targets`)},...ie.printers.map(t=>({value:`p:${t.id}`,label:t.name,group:e(`settings.pipelines.field.targetKindSpecific`,`Specific printer`)})),...ie.classes.map(t=>({value:`c:${t}`,label:e(`library.runWithPipeline.classTarget`,`Any {{model}}`,{model:t}),group:e(`settings.pipelines.field.targetKindClass`,`Printer class`)}))]}),M&&(0,J.jsx)(`button`,{type:`button`,onClick:()=>{l(``),d(null),p(``),h(0)},className:`text-xs text-bambu-gray hover:text-white`,children:e(`pipelineRuns.filter.clear`,`Clear filters`)}),(0,J.jsxs)(`div`,{className:`ml-auto flex items-center gap-2 text-xs text-bambu-gray`,children:[!w&&D>0&&(0,J.jsx)(`span`,{children:e(`pipelineRuns.totalCount`,`{{n}} run`,{n:D,count:D})}),(0,J.jsxs)(`button`,{type:`button`,onClick:()=>y(!0),disabled:D===0,className:`flex items-center gap-1 px-2 py-1 text-red-700 dark:text-red-400 hover:bg-red-50 dark:hover:bg-red-500/10 rounded disabled:opacity-50 disabled:cursor-not-allowed`,children:[(0,J.jsx)(he,{className:`w-3 h-3`}),e(`pipelineRuns.clearLog`,`Clear log`)]})]})]}),v&&(0,J.jsx)(`div`,{className:`fixed inset-0 z-50 bg-black/60 flex items-center justify-center p-4`,onClick:()=>y(!1),role:`dialog`,"aria-modal":`true`,children:(0,J.jsxs)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-2xl w-full max-w-md p-4`,onClick:e=>e.stopPropagation(),children:[(0,J.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,J.jsx)(he,{className:`w-4 h-4 text-red-600 dark:text-red-400`}),e(`pipelineRuns.clearConfirmTitle`,`Clear log?`)]}),(0,J.jsx)(`p`,{className:`text-sm text-bambu-gray mt-2`,children:e(`pipelineRuns.clearConfirmBody`,`Delete every completed, failed, cancelled, and partial-failure pipeline run? In-flight runs are kept. This cannot be undone.`)}),(0,J.jsxs)(`div`,{className:`flex items-center justify-end gap-2 mt-4`,children:[(0,J.jsx)(`button`,{type:`button`,onClick:()=>y(!1),disabled:re.isPending,className:`px-3 py-1.5 text-sm text-bambu-gray hover:text-white`,children:e(`common.cancel`,`Cancel`)}),(0,J.jsxs)(`button`,{type:`button`,onClick:()=>re.mutate(),disabled:re.isPending,className:`px-3 py-1.5 text-sm bg-red-500 hover:bg-red-600 text-white rounded disabled:opacity-50 flex items-center gap-1`,children:[re.isPending?(0,J.jsx)(ae,{className:`w-3.5 h-3.5 animate-spin`}):(0,J.jsx)(he,{className:`w-3.5 h-3.5`}),e(`pipelineRuns.clearConfirmAction`,`Clear`)]})]})]})}),w&&(0,J.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray`,children:[(0,J.jsx)(ae,{className:`w-4 h-4 animate-spin`}),e(`pipelineRuns.loading`,`Loading…`)]}),!w&&E.length===0&&(0,J.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:M?e(`pipelineRuns.filter.noMatches`,`No runs match the current filters.`):e(`pipelineRuns.empty`,`No pipeline runs yet.`)}),!w&&E.length>0&&(0,J.jsx)(`div`,{className:`space-y-1.5`,children:E.map(e=>(0,J.jsx)(Ke,{run:e,pipeline:e.pipeline_id?k[e.pipeline_id]:void 0,printersById:S,expanded:g.has(e.id),onToggle:()=>A(e.id),onCancel:()=>ne.mutate(e.id),onRetry:()=>T.mutate(e.id),cancelling:ne.isPending,retrying:T.isPending},e.id))}),!w&&D>Y&&(0,J.jsxs)(`div`,{className:`flex items-center justify-between mt-4 text-sm`,children:[(0,J.jsx)(`button`,{type:`button`,onClick:()=>h(Math.max(0,m-Y)),disabled:m===0,className:`px-3 py-1.5 rounded border border-bambu-dark-tertiary disabled:opacity-50 text-bambu-gray hover:text-white`,children:e(`common.previous`,`Previous`)}),(0,J.jsx)(`span`,{className:`text-bambu-gray text-xs`,children:e(`pipelineRuns.pagination`,`{{start}}–{{end}} of {{total}}`,{start:m+1,end:Math.min(m+Y,D),total:D})}),(0,J.jsx)(`button`,{type:`button`,onClick:()=>h(m+Y),disabled:m+Y>=D,className:`px-3 py-1.5 rounded border border-bambu-dark-tertiary disabled:opacity-50 text-bambu-gray hover:text-white`,children:e(`common.next`,`Next`)})]})]})}function Ke({run:e,pipeline:t,printersById:n,expanded:r,onToggle:i,onCancel:o,onRetry:s,cancelling:c,retrying:l}){let{t:u}=a(),d=[`queued`,`slicing`,`dispatching`,`in_progress`].includes(e.status),f=e.status===`partial_failure`||e.status===`failed`,p=e.status===`cancelled`&&e.error_message===`Cancelled by user`,m=e.target_kind===`printer_class`&&e.target_model_class?u(`library.runWithPipeline.classTarget`,`Any {{model}}`,{model:e.target_model_class}):e.target_printer_id&&n[e.target_printer_id]?n[e.target_printer_id].name:null;return(0,J.jsxs)(`div`,{className:`rounded-md border border-bambu-dark-tertiary bg-bambu-dark/40 overflow-hidden`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2`,children:[(0,J.jsx)(`button`,{type:`button`,onClick:i,"aria-label":r?u(`common.collapse`,`Collapse`):u(`common.expand`,`Expand`),"aria-expanded":r,className:`text-bambu-gray hover:text-white flex-shrink-0`,children:r?(0,J.jsx)(T,{className:`w-4 h-4`}):(0,J.jsx)(xe,{className:`w-4 h-4`})}),(0,J.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-0.5 text-sm`,children:[(0,J.jsxs)(`span`,{className:`font-medium text-white`,children:[`#`,e.id]}),(0,J.jsx)(`span`,{className:`text-white truncate`,children:t?.name??e.pipeline_name??`—`}),(0,J.jsx)(X,{status:e.status}),m&&(0,J.jsxs)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-bambu-dark-tertiary text-bambu-gray flex items-center gap-1`,children:[(0,J.jsx)(ye,{className:`w-3 h-3`}),m]}),e.parent_run_id&&(0,J.jsx)(`span`,{className:`text-xs text-bambu-gray/70 italic`,children:u(`pipelineRuns.retryOf`,`retry of #{{n}}`,{n:e.parent_run_id})})]}),e.source_filename&&(0,J.jsxs)(`div`,{className:`mt-0.5 flex items-center gap-1.5 text-xs text-bambu-gray min-w-0`,children:[(0,J.jsx)(Fe,{className:`w-3 h-3 flex-shrink-0`}),(0,J.jsx)(`span`,{className:`truncate`,title:e.source_filename,children:e.source_filename})]}),(0,J.jsxs)(`div`,{className:`mt-0.5 text-xs text-bambu-gray/70 flex flex-wrap items-center gap-x-2`,children:[(0,J.jsx)(`span`,{children:new Date(e.created_at).toLocaleString()}),e.copies>1&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`span`,{className:`text-bambu-gray/40`,children:`·`}),(0,J.jsx)(`span`,{children:u(`pipelineRuns.copies`,`{{n}} copies`,{n:e.copies})})]}),(e.copies_completed>0||e.copies_failed>0||e.copies_cancelled>0)&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`span`,{className:`text-bambu-gray/40`,children:`·`}),(0,J.jsxs)(`span`,{children:[(0,J.jsx)(`span`,{className:`text-bambu-green`,children:e.copies_completed}),`/`,e.copies]}),e.copies_failed>0&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`span`,{className:`text-bambu-gray/40`,children:`·`}),(0,J.jsx)(`span`,{className:`text-red-700 dark:text-red-400`,children:u(`pipelineRuns.failedCount`,`{{n}} failed`,{n:e.copies_failed})})]})]})]})]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-1 flex-shrink-0`,children:[d&&(0,J.jsxs)(`button`,{type:`button`,onClick:o,disabled:c,"aria-label":u(`common.cancel`,`Cancel`),className:`text-xs px-2 py-1 text-red-700 dark:text-red-400 hover:bg-red-50 dark:hover:bg-red-500/10 rounded disabled:opacity-50 flex items-center gap-1`,children:[(0,J.jsx)(ce,{className:`w-3 h-3`}),u(`common.cancel`,`Cancel`)]}),f&&(0,J.jsxs)(`button`,{type:`button`,onClick:s,disabled:l,"aria-label":u(`pipelineRuns.retryFailed`,`Retry failed`),className:`text-xs px-2 py-1 text-bambu-green hover:bg-bambu-green/10 rounded disabled:opacity-50 flex items-center gap-1`,children:[(0,J.jsx)(B,{className:`w-3 h-3`}),u(`pipelineRuns.retryFailed`,`Retry failed`)]})]})]}),r&&(0,J.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary px-3 py-2 bg-bambu-dark/30`,children:[(0,J.jsx)(`div`,{className:`space-y-1.5`,children:e.jobs.map(e=>(0,J.jsxs)(`div`,{className:`flex items-center gap-2 text-xs`,children:[(0,J.jsx)(`span`,{className:`text-bambu-gray/60 w-14 flex-shrink-0`,children:u(`pipelineRuns.copyN`,`Copy {{n}}`,{n:e.copy_index+1})}),(0,J.jsx)(Je,{status:e.status}),e.assigned_printer_name&&(0,J.jsxs)(`span`,{className:`text-bambu-gray flex items-center gap-1 truncate`,children:[(0,J.jsx)(ye,{className:`w-3 h-3 text-bambu-gray/60`}),(0,J.jsx)(`span`,{className:`text-white truncate`,children:e.assigned_printer_name})]}),e.error_message&&(0,J.jsx)(`span`,{className:`text-red-700 dark:text-red-400 truncate`,title:e.error_message,children:e.error_message})]},e.id))}),e.error_message&&!p&&(0,J.jsx)(`div`,{className:`text-xs text-red-700 dark:text-red-400 mt-2 pt-2 border-t border-bambu-dark-tertiary`,children:e.error_message}),p&&(0,J.jsx)(`div`,{className:`text-xs text-bambu-gray/70 mt-2 pt-2 border-t border-bambu-dark-tertiary italic`,children:u(`pipelineRuns.cancelledByUser`,`Cancelled by user`)})]})]})}function X({status:e}){let{t}=a();return(0,J.jsx)(`span`,{className:`px-1.5 py-0.5 rounded text-[10px] uppercase font-semibold tracking-wide whitespace-nowrap ${{queued:`bg-slate-700 text-slate-200`,slicing:`bg-sky-700 text-sky-100`,dispatching:`bg-sky-700 text-sky-100`,in_progress:`bg-emerald-700 text-emerald-100`,completed:`bg-emerald-700 text-emerald-100`,failed:`bg-red-700 text-red-100`,partial_failure:`bg-amber-700 text-amber-100`,cancelled:`bg-rose-900 text-rose-200`}[e]}`,children:t(`settings.pipelines.runs.status.${e}`,e)})}function qe({value:e,onChange:t,options:n,icon:r,ariaLabel:i}){let[a,o]=(0,q.useState)(!1),s=(0,q.useRef)(null);(0,q.useEffect)(()=>{if(!a)return;let e=e=>{s.current&&!s.current.contains(e.target)&&o(!1)},t=e=>{e.key===`Escape`&&o(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[a]);let c=n.find(t=>t.value===e),l=[];for(let e of n){let t=l[l.length-1];t&&t.group===e.group?t.options.push(e):l.push({group:e.group,options:[e]})}return(0,J.jsxs)(`div`,{ref:s,className:`relative`,children:[(0,J.jsxs)(`button`,{type:`button`,onClick:()=>o(e=>!e),"aria-label":i,"aria-haspopup":`listbox`,"aria-expanded":a,className:`flex items-center gap-1.5 px-2 py-1 border border-bambu-dark-tertiary rounded bg-bambu-dark/40 text-xs text-white hover:border-bambu-gray/60 focus:outline-none focus:ring-1 focus:ring-bambu-green/40`,children:[r,(0,J.jsx)(`span`,{className:`truncate max-w-[14rem]`,children:c?.label??``}),(0,J.jsx)(T,{className:`w-3 h-3 text-bambu-gray transition-transform ${a?`rotate-180`:``}`})]}),a&&(0,J.jsx)(`div`,{role:`listbox`,className:`absolute left-0 top-full mt-1 z-30 min-w-full max-h-72 overflow-auto rounded border border-bambu-dark-tertiary bg-bambu-dark-secondary shadow-xl py-1`,children:l.map((n,r)=>(0,J.jsxs)(`div`,{children:[n.group&&(0,J.jsx)(`div`,{className:`px-2 pt-1.5 pb-0.5 text-[10px] uppercase tracking-wider text-bambu-gray/60`,children:n.group}),n.options.map(n=>{let r=n.value===e;return(0,J.jsxs)(`button`,{type:`button`,role:`option`,"aria-selected":r,onClick:()=>{t(n.value),o(!1)},className:`flex w-full items-center gap-1.5 text-left px-2 py-1 text-xs whitespace-nowrap ${r?`bg-bambu-dark-tertiary text-white`:`text-bambu-gray hover:bg-bambu-dark-tertiary/60 hover:text-white`}`,children:[(0,J.jsx)(ne,{className:`w-3 h-3 flex-shrink-0 ${r?`opacity-100`:`opacity-0`}`}),(0,J.jsx)(`span`,{className:`truncate`,children:n.label})]},n.value)})]},r))})]})}function Je({status:e}){let{t}=a();return(0,J.jsx)(`span`,{className:`px-1.5 py-0.5 rounded text-[10px] uppercase font-semibold tracking-wide ${{pending:`bg-slate-700 text-slate-200`,awaiting_printer:`bg-sky-700 text-sky-100`,queued:`bg-sky-700 text-sky-100`,printing:`bg-emerald-700 text-emerald-100`,completed:`bg-emerald-700 text-emerald-100`,failed:`bg-red-700 text-red-100`,cancelled:`bg-rose-900 text-rose-200`}[e]}`,children:t(`pipelineRuns.jobStatus.${e}`,e)})}function Ye(e){return e>=1e3?`${(e/1e3).toFixed(1)}kg`:`${Math.round(e)}g`}function Xe({activeCount:e,pendingCount:t,totalTime:n,totalWeight:r,historyCount:i,t:a}){return(0,J.jsx)(`div`,{className:`flex items-center gap-3 sm:gap-5 flex-wrap px-4 py-3 bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary mb-6`,children:[{icon:oe,value:e,label:a(`queue.summary.printing`),color:`text-blue-600 dark:text-blue-400`},{icon:H,value:t,label:a(`queue.summary.queued`),color:`text-yellow-600 dark:text-yellow-400`},{icon:I,value:de(n),label:a(`queue.summary.totalTime`),color:`text-bambu-green`},{icon:Pe,value:Ye(r),label:a(`queue.summary.totalWeight`),color:`text-purple-600 dark:text-purple-400`},{icon:k,value:i,label:a(`queue.summary.history`),color:`text-bambu-gray`}].map((e,t)=>(0,J.jsxs)(`div`,{className:`flex items-center gap-3`,children:[t>0&&(0,J.jsx)(`span`,{className:`hidden sm:block text-bambu-dark-tertiary`,children:`|`}),(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,J.jsx)(e.icon,{className:`w-4 h-4 ${e.color}`}),(0,J.jsx)(`span`,{className:`text-sm font-semibold text-white`,children:e.value}),(0,J.jsx)(`span`,{className:`text-xs sm:text-sm text-bambu-gray`,children:e.label})]})]},t))})}var Z={completed:{icon:k,color:`text-emerald-600 dark:text-emerald-400`,border:`border-l-emerald-500`},failed:{icon:E,color:`text-red-600 dark:text-red-400`,border:`border-l-red-500`},skipped:{icon:F,color:`text-orange-600 dark:text-orange-400`,border:`border-l-gray-500`},cancelled:{icon:_,color:`text-gray-400`,border:`border-l-gray-500`}};function Ze(e){if(!e)return null;let t=e.startsWith(`#`)?e.slice(1):e;return/^0{6,8}$/.test(t)||!/^[0-9a-fA-F]{6,8}$/.test(t)?null:`#${t.slice(0,6)}`}function Qe({item:e,onRequeue:t,onRemove:n,timeFormat:i=`system`,hasPermission:a,canModify:o,t:s}){let c=Z[e.status]||Z.cancelled,l=c.icon,u=Le(e),d=e.archive_thumbnail?r.getArchiveThumbnail(e.archive_id):e.library_file_thumbnail?r.getLibraryFileThumbnailUrl(e.library_file_id):null,f=e.completed_at||e.created_at,p=Ze(e.filament_color),m=e.filament_used_grams?Math.round(e.filament_used_grams):null,h=!!e.error_message&&(e.status===`failed`||e.status===`skipped`);return(0,J.jsxs)(`div`,{className:`px-3 py-2 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary border-l-[3px] ${c.border}`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2 sm:gap-3`,children:[(0,J.jsx)(l,{className:`w-4 h-4 shrink-0 ${c.color}`}),(0,J.jsxs)(`div`,{className:`relative shrink-0 history-thumb-hover`,children:[(0,J.jsx)(`div`,{className:`w-8 h-8 bg-bambu-dark rounded overflow-hidden`,children:d?(0,J.jsx)(`img`,{src:d,alt:``,className:`w-full h-full object-cover`}):(0,J.jsx)(`div`,{className:`w-full h-full flex items-center justify-center text-bambu-gray`,children:(0,J.jsx)(ke,{className:`w-4 h-4`})})}),d&&(0,J.jsx)(`div`,{className:`history-thumb-preview absolute z-[60] left-full top-0 ml-2 w-48 h-48 pointer-events-none opacity-0 transition-opacity`,children:(0,J.jsx)(`img`,{src:d,alt:``,className:`w-full h-full object-cover rounded-lg shadow-2xl border-2 border-bambu-dark-tertiary bg-bambu-dark`})})]}),(0,J.jsx)(`span`,{className:`text-sm text-white font-medium truncate min-w-0 flex-1`,children:u}),(0,J.jsx)(`span`,{className:`text-xs text-bambu-gray shrink-0`,title:f??void 0,children:fe(f,i,s)}),(0,J.jsxs)(`div`,{className:`flex items-center gap-0.5 shrink-0`,children:[(0,J.jsx)(R,{variant:`ghost`,size:`sm`,onClick:t,disabled:!a(`queue:create`),title:a(`queue:create`)?s(`queue.actions.requeue`):s(`queue.permissions.noRequeue`),className:`text-bambu-green hover:text-bambu-green/80 hover:bg-bambu-green/10 p-1.5`,children:(0,J.jsx)(V,{className:`w-3.5 h-3.5`})}),(0,J.jsx)(R,{variant:`ghost`,size:`sm`,onClick:n,disabled:!o(`queue`,`delete`,e.created_by_id),title:o(`queue`,`delete`,e.created_by_id)?s(`common.remove`):s(`queue.permissions.noRemove`),className:`p-1.5`,children:(0,J.jsx)(he,{className:`w-3.5 h-3.5`})})]})]}),(0,J.jsxs)(`div`,{className:`mt-1 ml-[3.25rem] flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-bambu-gray`,children:[e.printer_name&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1 shrink-0`,children:[(0,J.jsx)(ye,{className:`w-3 h-3`}),(0,J.jsx)(`span`,{className:`truncate max-w-[100px] sm:max-w-[140px]`,children:e.printer_name})]}),(p||m)&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1 shrink-0`,children:[p?(0,J.jsx)(`span`,{className:`inline-block w-2.5 h-2.5 rounded-full border border-white/15`,style:{backgroundColor:p},"aria-hidden":!0}):(0,J.jsx)(Pe,{className:`w-3 h-3`}),(0,J.jsxs)(`span`,{className:`truncate`,children:[m?`${m}g`:null,m&&e.filament_type?` ${e.filament_type}`:null,!m&&e.filament_type?e.filament_type:null]})]}),e.print_time_seconds&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1 shrink-0`,children:[(0,J.jsx)(I,{className:`w-3 h-3`}),de(e.print_time_seconds)]}),e.created_by_username&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1 shrink-0`,title:s(`queue.addedBy`,{name:e.created_by_username}),children:[(0,J.jsx)(Se,{className:`w-3 h-3`}),(0,J.jsx)(`span`,{className:`truncate max-w-[120px]`,children:e.created_by_username})]})]}),h&&(0,J.jsxs)(`div`,{className:`mt-1 ml-[3.25rem] flex items-start gap-1 text-xs text-red-700 dark:text-red-400`,children:[(0,J.jsx)(D,{className:`w-3 h-3 mt-0.5 shrink-0`}),(0,J.jsx)(`span`,{className:`break-words`,children:e.error_message})]})]})}function $e(e){return e.printer_id==null?e.target_model?`model:${e.target_model}`:`unassigned`:`printer:${e.printer_id}`}function et(e,t,n){if(n){let n=+!!e.been_jumped,r=+!!t.been_jumped;if(n!==r)return r-n;let i=e.print_time_seconds??1/0,a=t.print_time_seconds??1/0;if(i!==a)return i-a}return e.position===t.position?(e.id??0)-(t.id??0):e.position-t.position}function tt(e){return e?e.split(` | `).map(e=>e.trim()).every(e=>e.startsWith(`Busy:`)):!1}var nt=3600*1e3,rt=24,it=rt*nt,at=32,ot=40;function st(e){return e.toLocaleTimeString(void 0,{hour:`numeric`})}function ct(e){return e.toLocaleTimeString(void 0,{hour:`2-digit`,minute:`2-digit`})}function lt({queueItems:e,printers:t,printerStatuses:n,sjfEnabled:i,onItemClick:a,t:o}){let[s,c]=(0,q.useState)(()=>new Date);(0,q.useEffect)(()=>{let e=setInterval(()=>c(new Date),6e4);return()=>clearInterval(e)},[]);let[l,u]=(0,q.useState)(0),d=(0,q.useMemo)(()=>{let e=s.getTime()+l;return Math.floor(e/nt)*nt},[s,l]),f=d+it,p=s.getTime(),m=(0,q.useMemo)(()=>{let t=[],r=new Map,a=new Set,o=new Map;for(let i of e)if(i.status===`printing`){let e=i.printer_id==null?void 0:n[i.printer_id],r=z(i.started_at)||new Date,s;if(e?.remaining_time!=null&&e.remaining_time>0)s=new Date(p+e.remaining_time*60*1e3);else if(i.print_time_seconds){let t=e?.progress||0,n=Math.max(0,1-t/100);s=new Date(p+i.print_time_seconds*n*1e3)}else s=new Date(p+nt);t.push({item:i,estimatedStart:r,estimatedEnd:s,progress:e?.progress??void 0,type:`printing`});let c=$e(i);a.add(c),o.set(c,Math.max(o.get(c)??p,s.getTime()))}else if(i.status===`pending`){if(i.manual_start||i.waiting_reason&&!tt(i.waiting_reason))continue;let e=$e(i);r.has(e)||r.set(e,[]),r.get(e).push(i)}let s=Date.now()+4320*nt;for(let[e,n]of r){n.sort((e,t)=>et(e,t,i));let r=a.has(e),c=n[0]?z(n[0].scheduled_time):null,l=c&&c.getTime()<=s;if(!r&&!l)continue;let u=o.get(e)??p;for(let e of n){let n=z(e.scheduled_time);n&&n.getTime()<=s&&(u=Math.max(u,n.getTime()));let r=(e.print_time_seconds||3600)*1e3;t.push({item:e,estimatedStart:new Date(u),estimatedEnd:new Date(u+r),type:`queued`}),u+=r}}return t},[e,n,p,i]),h=(0,q.useMemo)(()=>{let e=[];for(let n of t)e.push({key:`printer:${n.id}`,label:n.name,printerId:n.id,targetModel:null});let n=new Set,r=!1;for(let t of m)if(t.item.printer_id==null)if(t.item.target_model){let r=`model:${t.item.target_model}`;n.has(r)||(n.add(r),e.push({key:r,label:`${o(`queue.filter.any`)} ${t.item.target_model}`,printerId:null,targetModel:t.item.target_model}))}else r=!0;return r&&e.push({key:`unassigned`,label:o(`queue.filter.unassigned`),printerId:null,targetModel:null}),e},[t,m,o]),g=(0,q.useMemo)(()=>{let e=new Map;for(let t of m){let n;n=t.item.printer_id==null?t.item.target_model?`model:${t.item.target_model}`:`unassigned`:`printer:${t.item.printer_id}`,e.has(n)||e.set(n,[]),e.get(n).push(t)}return e},[m]),_=(0,q.useMemo)(()=>{let e=[];for(let t=0;t<=rt;t+=2){let n=d+t*nt;e.push({ms:n,pct:t/rt*100,label:st(new Date(n))})}return e},[d]),v=(p-d)/it*100,y=v>=0&&v<=100,b=(0,q.useMemo)(()=>{let e=0;for(let t of m)e=Math.max(e,t.estimatedEnd.getTime());return e>0?new Date(e):null},[m]),x=(0,q.useRef)(null);return(0,J.jsxs)(`div`,{children:[(0,J.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-3 mb-5`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(R,{variant:`ghost`,size:`sm`,onClick:()=>u(e=>e-12*nt),className:`p-1.5`,title:o(`queue.timeline.window.back12h`),children:(0,J.jsx)(Ae,{className:`w-4 h-4`})}),(0,J.jsxs)(`span`,{className:`text-sm font-medium text-white min-w-[180px] text-center`,children:[new Date(d).toLocaleString(void 0,{weekday:`short`,month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`}),` → `,new Date(f).toLocaleTimeString(void 0,{hour:`2-digit`,minute:`2-digit`})]}),(0,J.jsx)(R,{variant:`ghost`,size:`sm`,onClick:()=>u(e=>e+12*nt),className:`p-1.5`,title:o(`queue.timeline.window.forward12h`),children:(0,J.jsx)(xe,{className:`w-4 h-4`})}),l!==0&&(0,J.jsx)(R,{variant:`ghost`,size:`sm`,onClick:()=>u(0),className:`text-xs text-bambu-green`,children:o(`queue.timeline.window.now`)})]}),b&&(0,J.jsxs)(`span`,{className:`text-xs text-bambu-gray flex items-center gap-1.5`,children:[(0,J.jsx)(H,{className:`w-3.5 h-3.5`}),o(`queue.timeline.allDoneBy`,{time:b.toLocaleString(void 0,{weekday:`short`,hour:`2-digit`,minute:`2-digit`})})]})]}),h.length>0&&m.length===0&&(0,J.jsx)(`div`,{className:`mb-4 p-3 rounded-lg border border-bambu-dark-tertiary bg-bambu-dark/40 text-xs text-bambu-gray`,children:o(`queue.timeline.nothingCommitted`)}),h.length===0?(0,J.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-16 text-bambu-gray`,children:[(0,J.jsx)(ke,{className:`w-12 h-12 mb-3 opacity-30`}),(0,J.jsx)(`p`,{className:`text-sm`,children:o(`queue.timeline.noData`)})]}):(0,J.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary overflow-hidden`,children:[(0,J.jsxs)(`div`,{className:`flex border-b border-bambu-dark-tertiary`,children:[(0,J.jsx)(`div`,{className:`w-32 sm:w-40 shrink-0 px-3 py-2 text-xs font-medium text-bambu-gray border-r border-bambu-dark-tertiary`,children:o(`queue.timeline.printerColumnHeader`)}),(0,J.jsx)(`div`,{className:`relative flex-1 h-9`,children:_.map(e=>(0,J.jsx)(`div`,{className:`absolute top-0 bottom-0 border-l border-bambu-dark-tertiary/40 text-[10px] sm:text-xs text-bambu-gray pl-1 flex items-center`,style:{left:`${e.pct}%`},children:e.label},e.ms))})]}),(0,J.jsxs)(`div`,{ref:x,className:`relative`,children:[h.map(e=>{let t=g.get(e.key)??[];return(0,J.jsxs)(`div`,{className:`flex border-b border-bambu-dark-tertiary/40 last:border-b-0`,children:[(0,J.jsxs)(`div`,{className:`w-32 sm:w-40 shrink-0 px-3 py-3 border-r border-bambu-dark-tertiary flex items-center gap-2`,children:[(0,J.jsx)(ye,{className:`w-3.5 h-3.5 shrink-0 ${e.printerId==null&&e.targetModel==null?`text-orange-600 dark:text-orange-400`:e.targetModel?`text-blue-600 dark:text-blue-400`:`text-bambu-green`}`}),(0,J.jsx)(`span`,{className:`text-sm text-white truncate`,children:e.label})]}),(0,J.jsxs)(`div`,{className:`relative flex-1`,style:{height:56},children:[_.map(e=>(0,J.jsx)(`div`,{className:`absolute top-0 bottom-0 border-l border-bambu-dark-tertiary/30`,style:{left:`${e.pct}%`}},e.ms)),(0,J.jsx)(`div`,{className:`absolute inset-0 opacity-30`,style:{backgroundImage:`repeating-linear-gradient(45deg, transparent, transparent 6px, rgba(255,255,255,0.04) 6px, rgba(255,255,255,0.04) 12px)`},"aria-hidden":!0}),t.map(e=>{let t=Math.max(d,e.estimatedStart.getTime()),n=Math.min(f,e.estimatedEnd.getTime());if(n<=d||t>=f)return null;let i=(t-d)/it*100,o=(n-t)/it*100,s=e.item.archive_name||e.item.library_file_name||`#${e.item.id}`,c=e.item.archive_thumbnail?r.getArchiveThumbnail(e.item.archive_id):e.item.library_file_thumbnail?r.getLibraryFileThumbnailUrl(e.item.library_file_id):null,l=e.type===`printing`,u=e.item.batch_id!=null;return(0,J.jsxs)(`button`,{onClick:()=>a(e.item),title:[s,`${ct(e.estimatedStart)} → ${ct(e.estimatedEnd)}`,e.item.print_time_seconds?de(e.item.print_time_seconds):null,l&&e.progress!=null?`${Math.round(e.progress)}%`:null,e.item.batch_name?`batch: ${e.item.batch_name}`:null].filter(Boolean).join(` · `),className:`absolute rounded-md transition-all hover:brightness-110 hover:z-10 overflow-hidden flex items-center gap-1.5 px-1.5 text-left ${l?`bg-blue-500/30 border border-blue-400/60`:u?`bg-cyan-500/20 border border-cyan-400/50`:`bg-bambu-green/20 border border-bambu-green/40`}`,style:{left:`${i}%`,width:`max(${at}px, ${o}%)`,top:8,height:ot},children:[c&&(0,J.jsx)(`img`,{src:c,alt:``,className:`w-7 h-7 rounded object-cover shrink-0 bg-bambu-dark`}),(0,J.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,J.jsx)(`div`,{className:`text-xs text-white font-medium truncate leading-tight`,children:s}),(0,J.jsxs)(`div`,{className:`text-[10px] text-bambu-gray truncate leading-tight`,children:[e.item.print_time_seconds?de(e.item.print_time_seconds):``,l&&e.progress!=null?` · ${Math.round(e.progress)}%`:``]})]}),l&&e.progress!=null&&(0,J.jsx)(`div`,{className:`absolute bottom-0 left-0 h-0.5 bg-blue-300`,style:{width:`${e.progress}%`},"aria-hidden":!0})]},e.item.id)})]})]},e.key)}),y&&(0,J.jsxs)(`div`,{className:`absolute top-0 bottom-0 pointer-events-none z-20 flex inset-x-0`,children:[(0,J.jsx)(`div`,{className:`w-32 sm:w-40 shrink-0`}),(0,J.jsx)(`div`,{className:`relative flex-1`,children:(0,J.jsx)(`div`,{className:`absolute top-0 bottom-0 w-0.5 bg-red-400 shadow-[0_0_8px_rgba(248,113,113,0.6)]`,style:{left:`${v}%`},children:(0,J.jsx)(`div`,{className:`absolute -top-1 -left-1 w-2.5 h-2.5 bg-red-400 rounded-full`})})})]})]})]})]})}function ut({hasPermission:e,t,focusBatchId:n=null}){let i=o(),{showToast:a}=O(),[l,u]=(0,q.useState)(n?`all`:`active`),[d,f]=(0,q.useState)(null),{data:p}=s({queryKey:[`settings`],queryFn:r.getSettings}),m=De(p?.currency||`USD`),{data:h,isLoading:g}=s({queryKey:[`batches`,l],queryFn:()=>r.getBatches(l===`all`?void 0:l)}),_=n!=null&&!!h?.some(e=>e.id===n);(0,q.useEffect)(()=>{_&&document.getElementById(`batch-${n}`)?.scrollIntoView({block:`center`})},[_,n]);let v=()=>{i.invalidateQueries({queryKey:[`batches`]}),i.invalidateQueries({queryKey:[`queue`]})},y=c({mutationFn:({id:e,plateId:t})=>r.dispatchBatch(e,t===void 0?{}:{plate_id:t,only_plate:!0}),onSuccess:e=>{v(),a(t(`queue.batchOrders.dispatched`,{name:e.name}),`success`)},onError:e=>a(e.message,`error`)}),b=c({mutationFn:e=>r.cancelBatch(e),onSuccess:()=>{v(),f(null),a(t(`queue.batchCancelled`),`success`)},onError:e=>a(e.message,`error`)}),x=e(`queue:create`),S=e(`queue:delete_all`);return(0,J.jsxs)(`div`,{children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 mb-4`,children:[(0,J.jsx)(N,{className:`w-5 h-5 text-cyan-700 dark:text-cyan-300`}),(0,J.jsx)(`h2`,{className:`text-base sm:text-lg font-semibold text-white`,children:t(`queue.batchOrders.title`)}),(0,J.jsx)(`div`,{className:`flex gap-1 ml-auto`,children:[`active`,`completed`,`cancelled`,`all`].map(e=>(0,J.jsx)(`button`,{type:`button`,onClick:()=>u(e),className:`text-xs px-2.5 py-1 rounded-full border transition-colors ${l===e?`border-bambu-green bg-bambu-green/10 text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:border-bambu-gray`}`,children:t(`queue.batchOrders.filter.${e}`)},e))})]}),g?(0,J.jsx)(`div`,{className:`text-center py-12 text-bambu-gray`,children:t(`common.loading`)}):h?.length?(0,J.jsx)(`div`,{className:`space-y-4`,children:h.map(e=>(0,J.jsx)(ft,{batch:e,currency:m,canDispatch:x,canCancel:S,isDispatching:y.isPending&&y.variables?.id===e.id,highlighted:e.id===n,onDispatch:t=>y.mutate({id:e.id,plateId:t}),onCancel:()=>f(e),t},e.id))}):(0,J.jsxs)(le,{className:`p-12 text-center border-dashed`,children:[(0,J.jsx)(N,{className:`w-16 h-16 text-bambu-gray mx-auto mb-4 opacity-50`}),(0,J.jsx)(`h3`,{className:`text-xl font-medium text-white mb-2`,children:t(`queue.batchOrders.emptyTitle`)}),(0,J.jsx)(`p`,{className:`text-bambu-gray max-w-md mx-auto`,children:t(`queue.batchOrders.emptyDescription`)})]}),d&&(0,J.jsx)(Ee,{title:t(`queue.cancelBatchConfirmTitle`),message:t(`queue.cancelBatchConfirmMessage`),confirmText:t(`queue.cancelBatch`),variant:`warning`,onConfirm:()=>b.mutate(d.id),onCancel:()=>f(null)})]})}var dt={active:`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-300`,completed:`bg-green-100 dark:bg-green-500/20 text-green-700 dark:text-green-300`,cancelled:`bg-bambu-dark-tertiary text-bambu-gray`};function ft({batch:e,currency:t,canDispatch:n,canCancel:r,isDispatching:i,onDispatch:a,onCancel:o,t:s,highlighted:c=!1}){let l=e.has_targets?e.target_count:e.completed_count+e.pending_count+e.printing_count+e.failed_count,u=l>0?Math.round(e.completed_count/l*100):0,d=e.has_targets?e.remaining_count-e.dispatchable_count:0,f=e.due_date?z(e.due_date):null,p=f!=null&&e.status===`active`&&f.getTime()0&&e.status!==`cancelled`&&n&&(0,J.jsxs)(R,{variant:`primary`,size:`sm`,onClick:()=>a(),disabled:i,children:[(0,J.jsx)(ze,{className:`w-4 h-4 mr-1`}),s(`queue.batchOrders.dispatchRemaining`,{count:e.dispatchable_count})]}),e.status===`active`&&r&&(0,J.jsxs)(R,{variant:`ghost`,size:`sm`,onClick:o,children:[(0,J.jsx)(E,{className:`w-4 h-4 mr-1`}),s(`queue.cancelBatch`)]})]})]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-3 mb-2`,children:[(0,J.jsx)(`div`,{className:`flex-1 h-2 bg-bambu-dark-tertiary rounded-full overflow-hidden`,children:(0,J.jsx)(`div`,{className:`h-full rounded-full transition-all ${e.status===`completed`?`bg-bambu-green`:`bg-blue-500`}`,style:{width:`${Math.min(100,u)}%`}})}),(0,J.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap tabular-nums`,children:s(`queue.batchProgress`,{completed:e.completed_count,total:l})})]}),(0,J.jsxs)(`div`,{className:`flex flex-wrap gap-x-4 gap-y-1 text-xs text-bambu-gray mb-1`,children:[e.printing_count>0&&(0,J.jsx)(`span`,{children:s(`queue.batchOrders.printing`,{count:e.printing_count})}),e.pending_count>0&&(0,J.jsx)(`span`,{children:s(`queue.batch.pendingCount`,{count:e.pending_count})}),e.failed_count>0&&(0,J.jsxs)(`span`,{className:`text-orange-600 dark:text-orange-400 flex items-center gap-1`,children:[(0,J.jsx)(L,{className:`w-3 h-3`}),s(`queue.batchOrders.failed`,{count:e.failed_count})]}),e.has_targets&&e.remaining_count>0&&(0,J.jsx)(`span`,{children:s(`queue.batchOrders.remaining`,{count:e.remaining_count})}),e.print_time_seconds>0&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,J.jsx)(H,{className:`w-3 h-3`}),de(e.print_time_seconds)]}),e.actual_cost!=null&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,J.jsx)(A,{className:`w-3 h-3`}),(0,J.jsx)(`span`,{children:s(`queue.batchOrders.costSoFar`,{amount:`${t} ${e.actual_cost.toFixed(2)}`})}),e.estimated_remaining_cost!=null&&e.estimated_remaining_cost>0&&(0,J.jsx)(`span`,{children:s(`queue.batchOrders.costRemaining`,{amount:`${t} ${e.estimated_remaining_cost.toFixed(2)}`})})]})]}),d>0&&e.status!==`cancelled`&&(0,J.jsxs)(`p`,{className:`flex items-start gap-1.5 text-xs text-orange-600 dark:text-orange-400 mb-1`,children:[(0,J.jsx)(L,{className:`w-3 h-3 mt-0.5 flex-shrink-0`}),(0,J.jsx)(`span`,{children:s(`queue.batchOrders.strandedNotice`,{runs:d,owed:e.remaining_count})})]}),e.has_targets&&e.plates.length>0&&(0,J.jsx)(`div`,{className:`mt-3 border-t border-bambu-dark-tertiary pt-3 space-y-1.5`,children:e.plates.map(r=>(0,J.jsx)(pt,{plate:r,batchStatus:e.status,currency:t,canDispatch:n,isDispatching:i,onDispatch:()=>a(r.plate_id),t:s},`${r.plate_id??`file`}`))})]})}function pt({plate:e,batchStatus:t,currency:n,canDispatch:r,isDispatching:i,onDispatch:a,t:o}){let s=e.plate_name||(e.plate_id==null?o(`queue.batchOrders.wholeFile`):o(`queue.plateNumber`,{index:e.plate_id}));return(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-xs`,children:[(0,J.jsx)(ke,{className:`w-3.5 h-3.5 text-bambu-gray flex-shrink-0`}),(0,J.jsx)(`span`,{className:`text-white min-w-0 truncate`,children:s}),(0,J.jsx)(`span`,{className:`text-bambu-gray tabular-nums`,children:o(`queue.batchOrders.plateProgress`,{completed:e.completed_count,target:e.quantity_target})}),e.failed_count>0&&(0,J.jsx)(`span`,{className:`text-orange-600 dark:text-orange-400`,children:o(`queue.batchOrders.failed`,{count:e.failed_count})}),e.actual_cost!=null&&(0,J.jsx)(`span`,{className:`text-bambu-gray tabular-nums`,children:`${n} ${e.actual_cost.toFixed(2)}`}),e.remaining>0&&t!==`cancelled`&&(0,J.jsxs)(`span`,{className:`ml-auto flex items-center gap-2`,children:[(0,J.jsx)(`span`,{className:`text-bambu-gray`,children:o(`queue.batchOrders.remaining`,{count:e.remaining})}),e.can_dispatch?r&&(0,J.jsx)(`button`,{type:`button`,onClick:a,disabled:i,className:`text-bambu-green hover:underline disabled:opacity-50`,children:o(`queue.batchOrders.dispatchPlate`)}):(0,J.jsx)(`span`,{className:`text-orange-600 dark:text-orange-400`,children:o(`queue.batchOrders.strandedPlate`)})]})]})}function mt(e,t){if(!e?.connected||t>=254)return;let n=t>=128,r=n?t:Math.floor(t/4),i=n?0:t%4,a=e.ams?.find(e=>e.id===r);if(W(n?a?.tray[0]:a?.tray.find(e=>e.id===i))===`physical`)return ve(r,i,n,!1)}function ht(e){return e.slotLabel?[e.slotLabel,e.spoolName||e.type,e.colorName].filter(Boolean).join(` · `):e.colorName}function gt(e,t,n=[],r,i=`Empty`){let a=t=>{let a=t.slotId,o=a>0?e.ams_mapping?.[a-1]:void 0;if(o==null||o<0)return t;let s=n.find(e=>e.globalTrayId===o);if(s)return{slotId:a,type:s.type,color:s.color,colorName:s.colorName,slotLabel:s.label,spoolName:s.spoolName,extraColors:s.extraColors,effectType:s.effectType,subtype:s.spoolSubtype};let c=mt(r,o);return c?{...t,slotLabel:c,spoolName:i,emptySlot:!0}:t},o=e.plate_id==null?t[0]:t.find(t=>t.index===e.plate_id);if(o){let t=new Map((e.filament_overrides??[]).map(e=>[e.slot_id,e]));return o.filaments.filter(e=>e.used_in_plate!==!1&&e.used_grams>0).map(e=>{let n=t.get(e.slot_id),r=n?.color??e.color,i=n?.type??e.type;return a({slotId:e.slot_id,type:i,color:r,colorName:n?.color_name?.trim()||G(r,i)})})}return e.filament_overrides?.length?e.filament_overrides.map(e=>a({slotId:e.slot_id,type:e.type,color:e.color,colorName:e.color_name?.trim()||G(e.color,e.type)})):e.filament_color?[a({slotId:1,type:e.filament_type??``,color:e.filament_color,colorName:G(e.filament_color,e.filament_type)})]:[]}function _t(e,t=!1){return t&&e>=1e3?`${(e/1e3).toFixed(1)}kg`:`${Math.round(e)}g`}function vt({status:e,waitingReason:t,printerState:n,t:r}){if(e===`pending`&&t)return(0,J.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs font-medium border text-purple-700 dark:text-purple-400 bg-purple-50 dark:bg-purple-400/10 border-purple-200 dark:border-purple-400/20`,children:[(0,J.jsx)(H,{className:`w-3.5 h-3.5`}),r(`queue.status.waiting`)]});if(e===`printing`&&n===`PAUSE`)return(0,J.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs font-medium border text-yellow-700 dark:text-yellow-400 bg-yellow-50 dark:bg-yellow-400/10 border-yellow-200 dark:border-yellow-400/20`,children:[(0,J.jsx)(P,{className:`w-3.5 h-3.5`}),r(`queue.status.paused`)]});let{icon:i,color:a,label:o}={pending:{icon:H,color:`text-status-warning bg-status-warning/10 border-status-warning/20`,label:r(`queue.status.pending`)},printing:{icon:oe,color:`text-blue-700 dark:text-blue-400 bg-blue-50 dark:bg-blue-400/10 border-blue-200 dark:border-blue-400/20`,label:r(`queue.status.printing`)},completed:{icon:k,color:`text-status-ok bg-status-ok/10 border-status-ok/20`,label:r(`queue.status.completed`)},failed:{icon:E,color:`text-status-error bg-status-error/10 border-status-error/20`,label:r(`queue.status.failed`)},skipped:{icon:F,color:`text-orange-700 dark:text-orange-400 bg-orange-50 dark:bg-orange-400/10 border-orange-200 dark:border-orange-400/20`,label:r(`queue.status.skipped`)},cancelled:{icon:ce,color:`text-gray-400 bg-gray-400/10 border-gray-400/20`,label:r(`queue.status.cancelled`)}}[e];return(0,J.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs font-medium border ${a}`,children:[(0,J.jsx)(i,{className:`w-3.5 h-3.5`}),o]})}function yt({selectedCount:e,printers:t,onSave:n,onClose:r,isSaving:i,canControlPrinter:a,hasGcodeSnippets:o,t:s}){let[c,l]=(0,q.useState)(`unchanged`),[u,d]=(0,q.useState)(`unchanged`),[f,p]=(0,q.useState)(`unchanged`),[m,h]=(0,q.useState)(`unchanged`),[g,_]=(0,q.useState)(`unchanged`),[v,y]=(0,q.useState)(`unchanged`),[b,x]=(0,q.useState)(`unchanged`),[S,ee]=(0,q.useState)(`unchanged`),[C,te]=(0,q.useState)(`unchanged`),[w,ne]=(0,q.useState)(`unchanged`),[T,re]=(0,q.useState)(`unchanged`),[E,D]=(0,q.useState)(`unchanged`),[O,k]=(0,q.useState)(`unchanged`),A=t.some(e=>e.nozzle_count===2),j=()=>{let e={};c!==`unchanged`&&(e.printer_id=c),u!==`unchanged`&&(e.manual_start=u),f!==`unchanged`&&(e.auto_off_after=f),m!==`unchanged`&&(e.require_previous_success=m),g!==`unchanged`&&(e.gcode_injection=g),v!==`unchanged`&&(e.bed_levelling=v),b!==`unchanged`&&(e.flow_cali=b),S!==`unchanged`&&(e.vibration_cali=S),C!==`unchanged`&&(e.layer_inspect=C),w!==`unchanged`&&(e.timelapse=w),T!==`unchanged`&&(e.use_ams=T),E!==`unchanged`&&(e.confirm_outcome=E),O!==`unchanged`&&(e.nozzle_offset_cali=O),n(e)},M=c!==`unchanged`||u!==`unchanged`||f!==`unchanged`||m!==`unchanged`||v!==`unchanged`||b!==`unchanged`||S!==`unchanged`||C!==`unchanged`||w!==`unchanged`||T!==`unchanged`||E!==`unchanged`||O!==`unchanged`||g!==`unchanged`;return(0,J.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center p-4 bg-black/50 backdrop-blur-sm`,children:(0,J.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-lg max-h-[90vh] overflow-y-auto`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,J.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:s(`queue.bulkEdit.title`,{count:e})}),(0,J.jsx)(`button`,{onClick:r,className:`p-1 hover:bg-bambu-dark rounded`,children:(0,J.jsx)(ce,{className:`w-5 h-5 text-bambu-gray`})})]}),(0,J.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,J.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:s(`queue.bulkEdit.description`)}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:s(`queue.bulkEdit.printer`)}),(0,J.jsxs)(`select`,{value:c===null?`null`:c===`unchanged`?`unchanged`:String(c),onChange:e=>{let t=e.target.value;l(t===`unchanged`?`unchanged`:t===`null`?null:Number(t))},className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,J.jsx)(`option`,{value:`unchanged`,children:s(`queue.bulkEdit.noChange`)}),(0,J.jsx)(`option`,{value:`null`,children:s(`queue.filter.unassigned`)}),t.map(e=>(0,J.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:s(`queue.bulkEdit.queueOptions`)}),(0,J.jsxs)(`div`,{className:`space-y-2`,children:[(0,J.jsx)(Q,{label:s(`queue.bulkEdit.staged`),value:u,onChange:d,t:s}),(0,J.jsx)(Q,{label:s(`queue.bulkEdit.autoPowerOff`),value:f,onChange:p,disabled:!a,t:s}),(0,J.jsx)(Q,{label:s(`queue.bulkEdit.requirePrevious`),value:m,onChange:h,t:s}),o&&(0,J.jsx)(Q,{label:s(`queue.bulkEdit.gcodeInjection`),value:g,onChange:_,t:s})]})]}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:s(`queue.bulkEdit.printOptions`)}),(0,J.jsxs)(`div`,{className:`space-y-2`,children:[(0,J.jsx)(bt,{label:s(`queue.bulkEdit.bedLevelling`),value:v,onChange:y,t:s}),(0,J.jsx)(bt,{label:s(`queue.bulkEdit.flowCalibration`),value:b,onChange:x,t:s}),(0,J.jsx)(Q,{label:s(`queue.bulkEdit.vibrationCalibration`),value:S,onChange:ee,t:s}),(0,J.jsx)(Q,{label:s(`queue.bulkEdit.layerInspection`),value:C,onChange:te,t:s}),(0,J.jsx)(Q,{label:s(`queue.bulkEdit.timelapse`),value:w,onChange:ne,t:s}),(0,J.jsx)(Q,{label:s(`queue.bulkEdit.useAms`),value:T,onChange:re,t:s}),(0,J.jsx)(Q,{label:s(`queue.bulkEdit.confirmOutcome`),value:E,onChange:D,t:s}),A&&(0,J.jsx)(bt,{label:s(`queue.bulkEdit.nozzleOffsetCali`),value:O,onChange:k,t:s})]})]})]}),(0,J.jsxs)(`div`,{className:`flex justify-end gap-3 p-4 border-t border-bambu-dark-tertiary`,children:[(0,J.jsx)(R,{variant:`secondary`,onClick:r,children:s(`common.cancel`)}),(0,J.jsx)(R,{onClick:j,disabled:!M||i,children:s(i?`common.saving`:`queue.bulkEdit.applyChanges`)})]})]})})}function Q({label:e,value:t,onChange:n,disabled:r,t:i}){return(0,J.jsxs)(`div`,{className:`flex items-center justify-between py-1 ${r?`opacity-50`:``}`,children:[(0,J.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e}),(0,J.jsxs)(`div`,{className:`flex items-center gap-1 bg-bambu-dark rounded-lg p-0.5`,children:[(0,J.jsx)(`button`,{onClick:()=>n(`unchanged`),disabled:r,className:`px-2 py-1 text-xs rounded ${t===`unchanged`?`bg-bambu-dark-tertiary text-white`:`text-bambu-gray hover:text-white`} disabled:cursor-not-allowed`,children:`—`}),(0,J.jsx)(`button`,{onClick:()=>n(!1),disabled:r,className:`px-2 py-1 text-xs rounded ${t===!1?`bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400`:`text-bambu-gray hover:text-white`} disabled:cursor-not-allowed`,children:i(`common.off`)}),(0,J.jsx)(`button`,{onClick:()=>n(!0),disabled:r,className:`px-2 py-1 text-xs rounded ${t===!0?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:text-white`} disabled:cursor-not-allowed`,children:i(`common.on`)})]})]})}function bt({label:e,value:t,onChange:n,t:r}){let i=[{key:`unchanged`,label:`—`,active:`bg-bambu-dark-tertiary text-white`},{key:`off`,label:r(`settings.calibrationMode_off`),active:`bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400`},{key:`auto`,label:r(`settings.calibrationMode_auto`),active:`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`},{key:`on`,label:r(`settings.calibrationMode_on`),active:`bg-bambu-green/20 text-bambu-green`}];return(0,J.jsxs)(`div`,{className:`flex items-center justify-between py-1`,children:[(0,J.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e}),(0,J.jsx)(`div`,{className:`flex items-center gap-1 bg-bambu-dark rounded-lg p-0.5`,children:i.map(({key:e,label:r,active:i})=>(0,J.jsx)(`button`,{onClick:()=>n(e),className:`px-2 py-1 text-xs rounded ${t===e?i:`text-bambu-gray hover:text-white`}`,children:r},e))})]})}function xt({item:e,position:t,onEdit:n,onCancel:i,onRemove:a,onStop:o,onRequeue:c,onStart:l,onMoveUp:u,onMoveDown:d,timeFormat:f=`system`,isSelected:m=!1,onToggleSelect:h,hasPermission:g,canModify:_,printerState:v,showEta:y=!1,etaNow:x,t:S}){let{hasAnyPermission:ee}=Ie(),C=!ee(`queue:update_all`,`queue:start_unreviewed`),te=e.printer_id!=null&&(e.ams_mapping?.some(e=>e>=0)??!1),{data:w}=s({queryKey:[`printerStatus`,e.printer_id],queryFn:()=>r.getPrinterStatus(e.printer_id),refetchInterval:v===`printing`?3e4:!1,enabled:e.printer_id!=null&&(v===`printing`||te)}),{data:E}=s({queryKey:[`printer-inventory-remain`,e.printer_id],queryFn:()=>r.getInventoryRemain(e.printer_id),enabled:te,staleTime:30*1e3}),O=(0,q.useMemo)(()=>{let e=E?.slot_materials;if(!e?.length)return;let t=new Map;return e.forEach(e=>{e.spool&&t.set(e.global_tray_id,e.spool)}),t.size>0?t:void 0},[E]),k=(0,q.useMemo)(()=>me(w,O),[w,O]),A=!!e.library_file_id&&!e.archive_id,{data:j}=s({queryKey:[`archive-plates`,e.archive_id],queryFn:()=>r.getArchivePlates(e.archive_id),enabled:!!e.archive_id&&!A&&!e.archive_deleted}),{data:ie}=s({queryKey:[`library-file-plates`,e.library_file_id],queryFn:()=>r.getLibraryFilePlates(e.library_file_id),enabled:A&&!!e.library_file_id}),ae=A?ie:j,N=ae?.plates??[],P=gt(e,N,k,w,S(`ams.empty`)),F=g(`queue:reorder`),{attributes:L,listeners:se,setNodeRef:le,transform:B,transition:ve,isDragging:be}=p({id:e.id,disabled:e.status!==`pending`||!F}),xe={transform:b.Transform.toString(B),transition:ve},we=e.status===`printing`,W=e.status===`pending`,Ee=[`completed`,`failed`,`skipped`,`cancelled`].includes(e.status),De=W&&y&&e.print_time_seconds!=null&&e.print_time_seconds>0?ue(e.print_time_seconds/60,f,S,x):null,Oe=W&&h;return(0,J.jsxs)(`div`,{ref:le,style:xe,className:` +import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,t as i,w as a}from"./client-DnySrlFv.js";import{n as o}from"./QueryClientProvider-Ce8_sN3w.js";import{t as s}from"./useQuery-BBCjCezC.js";import{t as c}from"./useMutation-B-Tr2hIP.js";import{t as l}from"./useQueries-Be6PMvSC.js";import{t as u}from"./createLucideIcon-DvBYJlWL.js";import{t as d}from"./arrow-down-Cj0DZhNf.js";import{t as f}from"./arrow-up-D-pfJ3WZ.js";import{a as p,c as m,d as h,f as g,h as _,i as v,l as y,m as b,o as x,p as S,s as ee,t as C,u as te}from"./sortable.esm-D2bGix-3.js";import{t as w}from"./calendar-BLKPnWqV.js";import{t as ne}from"./check-Ck0cMLU4.js";import{a as T,i as re,n as E,r as D}from"./info-ROUoQhJR.js";import{n as O,r as k}from"./ToastContext-BRX0SW3C.js";import{t as A}from"./coins-4u6IPkR-.js";import{t as j}from"./funnel-C3dyAMK9.js";import{t as M}from"./grip-vertical-C_1RDxRw.js";import{t as ie}from"./list-CLcpeoSz.js";import{t as ae}from"./loader-circle-BEmFtawu.js";import{t as N}from"./package-BGUevlqS.js";import{t as P}from"./pause-DFb6GX_6.js";import{t as oe}from"./play-DIDYtk2S.js";import{t as F}from"./skip-forward-BsuMfFkw.js";import{t as I}from"./timer-GUTR9dAu.js";import{t as L}from"./triangle-alert-Dt_1FcBy.js";import{t as se}from"./workflow-BgT0wW83.js";import{t as ce}from"./x-DR-Trv6U.js";import{t as le}from"./Card-Bzc64K35.js";import{t as R}from"./Button-DDr6eAFy.js";import{c as ue,o as de,u as fe,v as z}from"./date-G9KUauqz.js";import{$t as pe,A as me,At as he,Cn as ge,En as _e,Gt as B,H as ve,Jt as ye,Kt as V,Lt as be,Mn as xe,On as H,Ot as Se,Rn as Ce,Rt as we,T as U,W,Yt as Te,_t as Ee,at as De,b as Oe,cn as ke,ct as G,jn as Ae,jt as je,mn as Me,on as Ne,w as K,wt as Pe,xn as Fe,yt as Ie}from"./index-Cxa-KVmA.js";import{t as Le}from"./queueItemName-UFY7kpjG.js";var Re=u(`chart-no-axes-gantt`,[[`path`,{d:`M6 5h12`,key:`fvfigv`}],[`path`,{d:`M4 12h10`,key:`oujl3d`}],[`path`,{d:`M12 19h8`,key:`baeox8`}]]),ze=u(`circle-play`,[[`path`,{d:`M9 9.003a1 1 0 0 1 1.517-.859l4.997 2.997a1 1 0 0 1 0 1.718l-4.997 2.997A1 1 0 0 1 9 14.996z`,key:`kmsa83`}],[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}]]),Be=u(`circle-stop`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`rect`,{x:`9`,y:`9`,width:`6`,height:`6`,rx:`1`,key:`1ssd4o`}]]),Ve=u(`package-open`,[[`path`,{d:`M12 22v-9`,key:`x3hkom`}],[`path`,{d:`M15.17 2.21a1.67 1.67 0 0 1 1.63 0L21 4.57a1.93 1.93 0 0 1 0 3.36L8.82 14.79a1.655 1.655 0 0 1-1.64 0L3 12.43a1.93 1.93 0 0 1 0-3.36z`,key:`2ntwy6`}],[`path`,{d:`M20 13v3.87a2.06 2.06 0 0 1-1.11 1.83l-6 3.08a1.93 1.93 0 0 1-1.78 0l-6-3.08A2.06 2.06 0 0 1 4 16.87V13`,key:`1pmm1c`}],[`path`,{d:`M21 12.43a1.93 1.93 0 0 0 0-3.36L8.83 2.2a1.64 1.64 0 0 0-1.63 0L3 4.57a1.93 1.93 0 0 0 0 3.36l12.18 6.86a1.636 1.636 0 0 0 1.63 0z`,key:`12ttoo`}]]),He=u(`snail`,[[`path`,{d:`M2 13a6 6 0 1 0 12 0 4 4 0 1 0-8 0 2 2 0 0 0 4 0`,key:`hneq2s`}],[`circle`,{cx:`10`,cy:`13`,r:`8`,key:`194lz3`}],[`path`,{d:`M2 21h12c4.4 0 8-3.6 8-8V7a2 2 0 1 0-4 0v6`,key:`ixqyt7`}],[`path`,{d:`M18 3 19.1 5.2`,key:`9tjm43`}],[`path`,{d:`M22 3 20.9 5.2`,key:`j3odrs`}]]),Ue=u(`ungroup`,[[`rect`,{width:`8`,height:`6`,x:`5`,y:`4`,rx:`1`,key:`nzclkv`}],[`rect`,{width:`8`,height:`6`,x:`11`,y:`14`,rx:`1`,key:`4tytwb`}]]),q=e(n(),1),J=t(),We=[``,`queued`,`slicing`,`dispatching`,`in_progress`,`completed`,`partial_failure`,`failed`,`cancelled`],Y=25;function Ge(){let{t:e}=a(),t=o(),{showToast:n}=O(),[i,l]=(0,q.useState)(``),[u,d]=(0,q.useState)(null),[f,p]=(0,q.useState)(``),[m,h]=(0,q.useState)(0),[g,_]=(0,q.useState)(new Set),[v,y]=(0,q.useState)(!1),{data:b}=s({queryKey:[`slicer-pipelines`],queryFn:()=>r.listSlicerPipelines()}),{data:x}=s({queryKey:[`printers`],queryFn:()=>r.getPrinters()}),S=(x??[]).reduce((e,t)=>(e[t.id]=t,e),{}),ee=f.startsWith(`p:`)?parseInt(f.slice(2),10):void 0,C=f.startsWith(`c:`)?f.slice(2):void 0,{data:te,isLoading:w}=s({queryKey:[`pipeline-runs-all`,i,u,m,f],queryFn:()=>r.listAllPipelineRuns({limit:Y,offset:m,pipelineId:u??void 0,status:i||void 0,targetPrinterId:ee,targetModelClass:C}),refetchInterval:15e3}),ne=c({mutationFn:e=>r.cancelPipelineRun(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`pipeline-runs-all`]}),n(e(`pipelineRuns.toast.cancelled`,`Run cancelled`),`success`)},onError:t=>n(t.message||e(`pipelineRuns.toast.cancelFailed`,`Cancel failed`),`error`)}),T=c({mutationFn:e=>r.retryFailedPipelineRun(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`pipeline-runs-all`]}),n(e(`pipelineRuns.toast.retryStarted`,`Retry started`),`success`)},onError:t=>n(t.message||e(`pipelineRuns.toast.retryFailed`,`Retry failed`),`error`)}),re=c({mutationFn:()=>r.clearTerminalPipelineRuns(),onSuccess:r=>{t.invalidateQueries({queryKey:[`pipeline-runs-all`]}),y(!1),h(0),n(e(`pipelineRuns.toast.cleared`,`{{n}} runs cleared`,{n:r.deleted}),`success`)},onError:t=>n(t.message||e(`pipelineRuns.toast.clearFailed`,`Clear failed`),`error`)}),E=te?.runs??[],D=te?.total??0,k=(b?.pipelines??[]).reduce((e,t)=>(e[t.id]=t,e),{}),A=e=>{_(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},M=!!(i||u!==null||f),ie=(()=>{let e=new Set,t=new Set;for(let n of b?.pipelines??[])n.target_kind===`printer_class`&&n.target_model_class?t.add(n.target_model_class):n.target_printer_id&&e.add(n.target_printer_id);return{printers:(x??[]).filter(t=>e.has(t.id)),classes:Array.from(t).sort()}})();return(0,J.jsxs)(`div`,{children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 mb-4 text-sm`,children:[(0,J.jsx)(`button`,{type:`button`,onClick:()=>t.invalidateQueries({queryKey:[`pipeline-runs-all`]}),"aria-label":e(`common.refresh`,`Refresh`),title:e(`common.refresh`,`Refresh`),className:`p-1.5 text-bambu-gray hover:text-white border border-bambu-dark-tertiary rounded`,children:(0,J.jsx)(V,{className:`w-3.5 h-3.5`})}),(0,J.jsx)(qe,{icon:(0,J.jsx)(se,{className:`w-3.5 h-3.5 text-bambu-gray`}),ariaLabel:e(`pipelineRuns.filter.pipeline`,`Pipeline`),value:u===null?``:String(u),onChange:e=>{h(0),d(e?parseInt(e,10):null)},options:[{value:``,label:e(`pipelineRuns.filter.allPipelines`,`All pipelines`)},...(b?.pipelines??[]).map(e=>({value:String(e.id),label:e.name}))]}),(0,J.jsx)(qe,{icon:(0,J.jsx)(j,{className:`w-3.5 h-3.5 text-bambu-gray`}),ariaLabel:e(`pipelineRuns.filter.status`,`Status`),value:i,onChange:e=>{h(0),l(e)},options:We.map(t=>({value:t,label:t===``?e(`pipelineRuns.filter.allStatus`,`All statuses`):e(`settings.pipelines.runs.status.${t}`,t)}))}),(ie.printers.length>0||ie.classes.length>0)&&(0,J.jsx)(qe,{icon:(0,J.jsx)(ye,{className:`w-3.5 h-3.5 text-bambu-gray`}),ariaLabel:e(`pipelineRuns.filter.target`,`Target`),value:f,onChange:e=>{h(0),p(e)},options:[{value:``,label:e(`pipelineRuns.filter.allTargets`,`All targets`)},...ie.printers.map(t=>({value:`p:${t.id}`,label:t.name,group:e(`settings.pipelines.field.targetKindSpecific`,`Specific printer`)})),...ie.classes.map(t=>({value:`c:${t}`,label:e(`library.runWithPipeline.classTarget`,`Any {{model}}`,{model:t}),group:e(`settings.pipelines.field.targetKindClass`,`Printer class`)}))]}),M&&(0,J.jsx)(`button`,{type:`button`,onClick:()=>{l(``),d(null),p(``),h(0)},className:`text-xs text-bambu-gray hover:text-white`,children:e(`pipelineRuns.filter.clear`,`Clear filters`)}),(0,J.jsxs)(`div`,{className:`ml-auto flex items-center gap-2 text-xs text-bambu-gray`,children:[!w&&D>0&&(0,J.jsx)(`span`,{children:e(`pipelineRuns.totalCount`,`{{n}} run`,{n:D,count:D})}),(0,J.jsxs)(`button`,{type:`button`,onClick:()=>y(!0),disabled:D===0,className:`flex items-center gap-1 px-2 py-1 text-red-700 dark:text-red-400 hover:bg-red-50 dark:hover:bg-red-500/10 rounded disabled:opacity-50 disabled:cursor-not-allowed`,children:[(0,J.jsx)(he,{className:`w-3 h-3`}),e(`pipelineRuns.clearLog`,`Clear log`)]})]})]}),v&&(0,J.jsx)(`div`,{className:`fixed inset-0 z-50 bg-black/60 flex items-center justify-center p-4`,onClick:()=>y(!1),role:`dialog`,"aria-modal":`true`,children:(0,J.jsxs)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-2xl w-full max-w-md p-4`,onClick:e=>e.stopPropagation(),children:[(0,J.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,J.jsx)(he,{className:`w-4 h-4 text-red-600 dark:text-red-400`}),e(`pipelineRuns.clearConfirmTitle`,`Clear log?`)]}),(0,J.jsx)(`p`,{className:`text-sm text-bambu-gray mt-2`,children:e(`pipelineRuns.clearConfirmBody`,`Delete every completed, failed, cancelled, and partial-failure pipeline run? In-flight runs are kept. This cannot be undone.`)}),(0,J.jsxs)(`div`,{className:`flex items-center justify-end gap-2 mt-4`,children:[(0,J.jsx)(`button`,{type:`button`,onClick:()=>y(!1),disabled:re.isPending,className:`px-3 py-1.5 text-sm text-bambu-gray hover:text-white`,children:e(`common.cancel`,`Cancel`)}),(0,J.jsxs)(`button`,{type:`button`,onClick:()=>re.mutate(),disabled:re.isPending,className:`px-3 py-1.5 text-sm bg-red-500 hover:bg-red-600 text-white rounded disabled:opacity-50 flex items-center gap-1`,children:[re.isPending?(0,J.jsx)(ae,{className:`w-3.5 h-3.5 animate-spin`}):(0,J.jsx)(he,{className:`w-3.5 h-3.5`}),e(`pipelineRuns.clearConfirmAction`,`Clear`)]})]})]})}),w&&(0,J.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray`,children:[(0,J.jsx)(ae,{className:`w-4 h-4 animate-spin`}),e(`pipelineRuns.loading`,`Loading…`)]}),!w&&E.length===0&&(0,J.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:M?e(`pipelineRuns.filter.noMatches`,`No runs match the current filters.`):e(`pipelineRuns.empty`,`No pipeline runs yet.`)}),!w&&E.length>0&&(0,J.jsx)(`div`,{className:`space-y-1.5`,children:E.map(e=>(0,J.jsx)(Ke,{run:e,pipeline:e.pipeline_id?k[e.pipeline_id]:void 0,printersById:S,expanded:g.has(e.id),onToggle:()=>A(e.id),onCancel:()=>ne.mutate(e.id),onRetry:()=>T.mutate(e.id),cancelling:ne.isPending,retrying:T.isPending},e.id))}),!w&&D>Y&&(0,J.jsxs)(`div`,{className:`flex items-center justify-between mt-4 text-sm`,children:[(0,J.jsx)(`button`,{type:`button`,onClick:()=>h(Math.max(0,m-Y)),disabled:m===0,className:`px-3 py-1.5 rounded border border-bambu-dark-tertiary disabled:opacity-50 text-bambu-gray hover:text-white`,children:e(`common.previous`,`Previous`)}),(0,J.jsx)(`span`,{className:`text-bambu-gray text-xs`,children:e(`pipelineRuns.pagination`,`{{start}}–{{end}} of {{total}}`,{start:m+1,end:Math.min(m+Y,D),total:D})}),(0,J.jsx)(`button`,{type:`button`,onClick:()=>h(m+Y),disabled:m+Y>=D,className:`px-3 py-1.5 rounded border border-bambu-dark-tertiary disabled:opacity-50 text-bambu-gray hover:text-white`,children:e(`common.next`,`Next`)})]})]})}function Ke({run:e,pipeline:t,printersById:n,expanded:r,onToggle:i,onCancel:o,onRetry:s,cancelling:c,retrying:l}){let{t:u}=a(),d=[`queued`,`slicing`,`dispatching`,`in_progress`].includes(e.status),f=e.status===`partial_failure`||e.status===`failed`,p=e.status===`cancelled`&&e.error_message===`Cancelled by user`,m=e.target_kind===`printer_class`&&e.target_model_class?u(`library.runWithPipeline.classTarget`,`Any {{model}}`,{model:e.target_model_class}):e.target_printer_id&&n[e.target_printer_id]?n[e.target_printer_id].name:null;return(0,J.jsxs)(`div`,{className:`rounded-md border border-bambu-dark-tertiary bg-bambu-dark/40 overflow-hidden`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2`,children:[(0,J.jsx)(`button`,{type:`button`,onClick:i,"aria-label":r?u(`common.collapse`,`Collapse`):u(`common.expand`,`Expand`),"aria-expanded":r,className:`text-bambu-gray hover:text-white flex-shrink-0`,children:r?(0,J.jsx)(T,{className:`w-4 h-4`}):(0,J.jsx)(xe,{className:`w-4 h-4`})}),(0,J.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-0.5 text-sm`,children:[(0,J.jsxs)(`span`,{className:`font-medium text-white`,children:[`#`,e.id]}),(0,J.jsx)(`span`,{className:`text-white truncate`,children:t?.name??e.pipeline_name??`—`}),(0,J.jsx)(X,{status:e.status}),m&&(0,J.jsxs)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-bambu-dark-tertiary text-bambu-gray flex items-center gap-1`,children:[(0,J.jsx)(ye,{className:`w-3 h-3`}),m]}),e.parent_run_id&&(0,J.jsx)(`span`,{className:`text-xs text-bambu-gray/70 italic`,children:u(`pipelineRuns.retryOf`,`retry of #{{n}}`,{n:e.parent_run_id})})]}),e.source_filename&&(0,J.jsxs)(`div`,{className:`mt-0.5 flex items-center gap-1.5 text-xs text-bambu-gray min-w-0`,children:[(0,J.jsx)(Fe,{className:`w-3 h-3 flex-shrink-0`}),(0,J.jsx)(`span`,{className:`truncate`,title:e.source_filename,children:e.source_filename})]}),(0,J.jsxs)(`div`,{className:`mt-0.5 text-xs text-bambu-gray/70 flex flex-wrap items-center gap-x-2`,children:[(0,J.jsx)(`span`,{children:new Date(e.created_at).toLocaleString()}),e.copies>1&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`span`,{className:`text-bambu-gray/40`,children:`·`}),(0,J.jsx)(`span`,{children:u(`pipelineRuns.copies`,`{{n}} copies`,{n:e.copies})})]}),(e.copies_completed>0||e.copies_failed>0||e.copies_cancelled>0)&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`span`,{className:`text-bambu-gray/40`,children:`·`}),(0,J.jsxs)(`span`,{children:[(0,J.jsx)(`span`,{className:`text-bambu-green`,children:e.copies_completed}),`/`,e.copies]}),e.copies_failed>0&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`span`,{className:`text-bambu-gray/40`,children:`·`}),(0,J.jsx)(`span`,{className:`text-red-700 dark:text-red-400`,children:u(`pipelineRuns.failedCount`,`{{n}} failed`,{n:e.copies_failed})})]})]})]})]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-1 flex-shrink-0`,children:[d&&(0,J.jsxs)(`button`,{type:`button`,onClick:o,disabled:c,"aria-label":u(`common.cancel`,`Cancel`),className:`text-xs px-2 py-1 text-red-700 dark:text-red-400 hover:bg-red-50 dark:hover:bg-red-500/10 rounded disabled:opacity-50 flex items-center gap-1`,children:[(0,J.jsx)(ce,{className:`w-3 h-3`}),u(`common.cancel`,`Cancel`)]}),f&&(0,J.jsxs)(`button`,{type:`button`,onClick:s,disabled:l,"aria-label":u(`pipelineRuns.retryFailed`,`Retry failed`),className:`text-xs px-2 py-1 text-bambu-green hover:bg-bambu-green/10 rounded disabled:opacity-50 flex items-center gap-1`,children:[(0,J.jsx)(B,{className:`w-3 h-3`}),u(`pipelineRuns.retryFailed`,`Retry failed`)]})]})]}),r&&(0,J.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary px-3 py-2 bg-bambu-dark/30`,children:[(0,J.jsx)(`div`,{className:`space-y-1.5`,children:e.jobs.map(e=>(0,J.jsxs)(`div`,{className:`flex items-center gap-2 text-xs`,children:[(0,J.jsx)(`span`,{className:`text-bambu-gray/60 w-14 flex-shrink-0`,children:u(`pipelineRuns.copyN`,`Copy {{n}}`,{n:e.copy_index+1})}),(0,J.jsx)(Je,{status:e.status}),e.assigned_printer_name&&(0,J.jsxs)(`span`,{className:`text-bambu-gray flex items-center gap-1 truncate`,children:[(0,J.jsx)(ye,{className:`w-3 h-3 text-bambu-gray/60`}),(0,J.jsx)(`span`,{className:`text-white truncate`,children:e.assigned_printer_name})]}),e.error_message&&(0,J.jsx)(`span`,{className:`text-red-700 dark:text-red-400 truncate`,title:e.error_message,children:e.error_message})]},e.id))}),e.error_message&&!p&&(0,J.jsx)(`div`,{className:`text-xs text-red-700 dark:text-red-400 mt-2 pt-2 border-t border-bambu-dark-tertiary`,children:e.error_message}),p&&(0,J.jsx)(`div`,{className:`text-xs text-bambu-gray/70 mt-2 pt-2 border-t border-bambu-dark-tertiary italic`,children:u(`pipelineRuns.cancelledByUser`,`Cancelled by user`)})]})]})}function X({status:e}){let{t}=a();return(0,J.jsx)(`span`,{className:`px-1.5 py-0.5 rounded text-[10px] uppercase font-semibold tracking-wide whitespace-nowrap ${{queued:`bg-slate-700 text-slate-200`,slicing:`bg-sky-700 text-sky-100`,dispatching:`bg-sky-700 text-sky-100`,in_progress:`bg-emerald-700 text-emerald-100`,completed:`bg-emerald-700 text-emerald-100`,failed:`bg-red-700 text-red-100`,partial_failure:`bg-amber-700 text-amber-100`,cancelled:`bg-rose-900 text-rose-200`}[e]}`,children:t(`settings.pipelines.runs.status.${e}`,e)})}function qe({value:e,onChange:t,options:n,icon:r,ariaLabel:i}){let[a,o]=(0,q.useState)(!1),s=(0,q.useRef)(null);(0,q.useEffect)(()=>{if(!a)return;let e=e=>{s.current&&!s.current.contains(e.target)&&o(!1)},t=e=>{e.key===`Escape`&&o(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[a]);let c=n.find(t=>t.value===e),l=[];for(let e of n){let t=l[l.length-1];t&&t.group===e.group?t.options.push(e):l.push({group:e.group,options:[e]})}return(0,J.jsxs)(`div`,{ref:s,className:`relative`,children:[(0,J.jsxs)(`button`,{type:`button`,onClick:()=>o(e=>!e),"aria-label":i,"aria-haspopup":`listbox`,"aria-expanded":a,className:`flex items-center gap-1.5 px-2 py-1 border border-bambu-dark-tertiary rounded bg-bambu-dark/40 text-xs text-white hover:border-bambu-gray/60 focus:outline-none focus:ring-1 focus:ring-bambu-green/40`,children:[r,(0,J.jsx)(`span`,{className:`truncate max-w-[14rem]`,children:c?.label??``}),(0,J.jsx)(T,{className:`w-3 h-3 text-bambu-gray transition-transform ${a?`rotate-180`:``}`})]}),a&&(0,J.jsx)(`div`,{role:`listbox`,className:`absolute left-0 top-full mt-1 z-30 min-w-full max-h-72 overflow-auto rounded border border-bambu-dark-tertiary bg-bambu-dark-secondary shadow-xl py-1`,children:l.map((n,r)=>(0,J.jsxs)(`div`,{children:[n.group&&(0,J.jsx)(`div`,{className:`px-2 pt-1.5 pb-0.5 text-[10px] uppercase tracking-wider text-bambu-gray/60`,children:n.group}),n.options.map(n=>{let r=n.value===e;return(0,J.jsxs)(`button`,{type:`button`,role:`option`,"aria-selected":r,onClick:()=>{t(n.value),o(!1)},className:`flex w-full items-center gap-1.5 text-left px-2 py-1 text-xs whitespace-nowrap ${r?`bg-bambu-dark-tertiary text-white`:`text-bambu-gray hover:bg-bambu-dark-tertiary/60 hover:text-white`}`,children:[(0,J.jsx)(ne,{className:`w-3 h-3 flex-shrink-0 ${r?`opacity-100`:`opacity-0`}`}),(0,J.jsx)(`span`,{className:`truncate`,children:n.label})]},n.value)})]},r))})]})}function Je({status:e}){let{t}=a();return(0,J.jsx)(`span`,{className:`px-1.5 py-0.5 rounded text-[10px] uppercase font-semibold tracking-wide ${{pending:`bg-slate-700 text-slate-200`,awaiting_printer:`bg-sky-700 text-sky-100`,queued:`bg-sky-700 text-sky-100`,printing:`bg-emerald-700 text-emerald-100`,completed:`bg-emerald-700 text-emerald-100`,failed:`bg-red-700 text-red-100`,cancelled:`bg-rose-900 text-rose-200`}[e]}`,children:t(`pipelineRuns.jobStatus.${e}`,e)})}function Ye(e){return e>=1e3?`${(e/1e3).toFixed(1)}kg`:`${Math.round(e)}g`}function Xe({activeCount:e,pendingCount:t,totalTime:n,totalWeight:r,historyCount:i,t:a}){return(0,J.jsx)(`div`,{className:`flex items-center gap-3 sm:gap-5 flex-wrap px-4 py-3 bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary mb-6`,children:[{icon:oe,value:e,label:a(`queue.summary.printing`),color:`text-blue-600 dark:text-blue-400`},{icon:H,value:t,label:a(`queue.summary.queued`),color:`text-yellow-600 dark:text-yellow-400`},{icon:I,value:de(n),label:a(`queue.summary.totalTime`),color:`text-bambu-green`},{icon:Pe,value:Ye(r),label:a(`queue.summary.totalWeight`),color:`text-purple-600 dark:text-purple-400`},{icon:k,value:i,label:a(`queue.summary.history`),color:`text-bambu-gray`}].map((e,t)=>(0,J.jsxs)(`div`,{className:`flex items-center gap-3`,children:[t>0&&(0,J.jsx)(`span`,{className:`hidden sm:block text-bambu-dark-tertiary`,children:`|`}),(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,J.jsx)(e.icon,{className:`w-4 h-4 ${e.color}`}),(0,J.jsx)(`span`,{className:`text-sm font-semibold text-white`,children:e.value}),(0,J.jsx)(`span`,{className:`text-xs sm:text-sm text-bambu-gray`,children:e.label})]})]},t))})}var Z={completed:{icon:k,color:`text-emerald-600 dark:text-emerald-400`,border:`border-l-emerald-500`},failed:{icon:E,color:`text-red-600 dark:text-red-400`,border:`border-l-red-500`},skipped:{icon:F,color:`text-orange-600 dark:text-orange-400`,border:`border-l-gray-500`},cancelled:{icon:_,color:`text-gray-400`,border:`border-l-gray-500`}};function Ze(e){if(!e)return null;let t=e.startsWith(`#`)?e.slice(1):e;return/^0{6,8}$/.test(t)||!/^[0-9a-fA-F]{6,8}$/.test(t)?null:`#${t.slice(0,6)}`}function Qe({item:e,onRequeue:t,onRemove:n,timeFormat:i=`system`,hasPermission:a,canModify:o,t:s}){let c=Z[e.status]||Z.cancelled,l=c.icon,u=Le(e),d=e.archive_thumbnail?r.getArchiveThumbnail(e.archive_id):e.library_file_thumbnail?r.getLibraryFileThumbnailUrl(e.library_file_id):null,f=e.completed_at||e.created_at,p=Ze(e.filament_color),m=e.filament_used_grams?Math.round(e.filament_used_grams):null,h=!!e.error_message&&(e.status===`failed`||e.status===`skipped`);return(0,J.jsxs)(`div`,{className:`px-3 py-2 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary border-l-[3px] ${c.border}`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2 sm:gap-3`,children:[(0,J.jsx)(l,{className:`w-4 h-4 shrink-0 ${c.color}`}),(0,J.jsxs)(`div`,{className:`relative shrink-0 history-thumb-hover`,children:[(0,J.jsx)(`div`,{className:`w-8 h-8 bg-bambu-dark rounded overflow-hidden`,children:d?(0,J.jsx)(`img`,{src:d,alt:``,className:`w-full h-full object-cover`}):(0,J.jsx)(`div`,{className:`w-full h-full flex items-center justify-center text-bambu-gray`,children:(0,J.jsx)(ke,{className:`w-4 h-4`})})}),d&&(0,J.jsx)(`div`,{className:`history-thumb-preview absolute z-[60] left-full top-0 ml-2 w-48 h-48 pointer-events-none opacity-0 transition-opacity`,children:(0,J.jsx)(`img`,{src:d,alt:``,className:`w-full h-full object-cover rounded-lg shadow-2xl border-2 border-bambu-dark-tertiary bg-bambu-dark`})})]}),(0,J.jsx)(`span`,{className:`text-sm text-white font-medium truncate min-w-0 flex-1`,children:u}),(0,J.jsx)(`span`,{className:`text-xs text-bambu-gray shrink-0`,title:f??void 0,children:fe(f,i,s)}),(0,J.jsxs)(`div`,{className:`flex items-center gap-0.5 shrink-0`,children:[(0,J.jsx)(R,{variant:`ghost`,size:`sm`,onClick:t,disabled:!a(`queue:create`),title:a(`queue:create`)?s(`queue.actions.requeue`):s(`queue.permissions.noRequeue`),className:`text-bambu-green hover:text-bambu-green/80 hover:bg-bambu-green/10 p-1.5`,children:(0,J.jsx)(V,{className:`w-3.5 h-3.5`})}),(0,J.jsx)(R,{variant:`ghost`,size:`sm`,onClick:n,disabled:!o(`queue`,`delete`,e.created_by_id),title:o(`queue`,`delete`,e.created_by_id)?s(`common.remove`):s(`queue.permissions.noRemove`),className:`p-1.5`,children:(0,J.jsx)(he,{className:`w-3.5 h-3.5`})})]})]}),(0,J.jsxs)(`div`,{className:`mt-1 ml-[3.25rem] flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-bambu-gray`,children:[e.printer_name&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1 shrink-0`,children:[(0,J.jsx)(ye,{className:`w-3 h-3`}),(0,J.jsx)(`span`,{className:`truncate max-w-[100px] sm:max-w-[140px]`,children:e.printer_name})]}),(p||m)&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1 shrink-0`,children:[p?(0,J.jsx)(`span`,{className:`inline-block w-2.5 h-2.5 rounded-full border border-white/15`,style:{backgroundColor:p},"aria-hidden":!0}):(0,J.jsx)(Pe,{className:`w-3 h-3`}),(0,J.jsxs)(`span`,{className:`truncate`,children:[m?`${m}g`:null,m&&e.filament_type?` ${e.filament_type}`:null,!m&&e.filament_type?e.filament_type:null]})]}),e.print_time_seconds&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1 shrink-0`,children:[(0,J.jsx)(I,{className:`w-3 h-3`}),de(e.print_time_seconds)]}),e.created_by_username&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1 shrink-0`,title:s(`queue.addedBy`,{name:e.created_by_username}),children:[(0,J.jsx)(Se,{className:`w-3 h-3`}),(0,J.jsx)(`span`,{className:`truncate max-w-[120px]`,children:e.created_by_username})]})]}),h&&(0,J.jsxs)(`div`,{className:`mt-1 ml-[3.25rem] flex items-start gap-1 text-xs text-red-700 dark:text-red-400`,children:[(0,J.jsx)(D,{className:`w-3 h-3 mt-0.5 shrink-0`}),(0,J.jsx)(`span`,{className:`break-words`,children:e.error_message})]})]})}function $e(e){return e.printer_id==null?e.target_model?`model:${e.target_model}`:`unassigned`:`printer:${e.printer_id}`}function et(e,t,n){if(n){let n=+!!e.been_jumped,r=+!!t.been_jumped;if(n!==r)return r-n;let i=e.print_time_seconds??1/0,a=t.print_time_seconds??1/0;if(i!==a)return i-a}return e.position===t.position?(e.id??0)-(t.id??0):e.position-t.position}function tt(e){return e?e.split(` | `).map(e=>e.trim()).every(e=>e.startsWith(`Busy:`)):!1}var nt=3600*1e3,rt=24,it=rt*nt,at=32,ot=40;function st(e){return e.toLocaleTimeString(void 0,{hour:`numeric`})}function ct(e){return e.toLocaleTimeString(void 0,{hour:`2-digit`,minute:`2-digit`})}function lt({queueItems:e,printers:t,printerStatuses:n,sjfEnabled:i,onItemClick:a,t:o}){let[s,c]=(0,q.useState)(()=>new Date);(0,q.useEffect)(()=>{let e=setInterval(()=>c(new Date),6e4);return()=>clearInterval(e)},[]);let[l,u]=(0,q.useState)(0),d=(0,q.useMemo)(()=>{let e=s.getTime()+l;return Math.floor(e/nt)*nt},[s,l]),f=d+it,p=s.getTime(),m=(0,q.useMemo)(()=>{let t=[],r=new Map,a=new Set,o=new Map;for(let i of e)if(i.status===`printing`){let e=i.printer_id==null?void 0:n[i.printer_id],r=z(i.started_at)||new Date,s;if(e?.remaining_time!=null&&e.remaining_time>0)s=new Date(p+e.remaining_time*60*1e3);else if(i.print_time_seconds){let t=e?.progress||0,n=Math.max(0,1-t/100);s=new Date(p+i.print_time_seconds*n*1e3)}else s=new Date(p+nt);t.push({item:i,estimatedStart:r,estimatedEnd:s,progress:e?.progress??void 0,type:`printing`});let c=$e(i);a.add(c),o.set(c,Math.max(o.get(c)??p,s.getTime()))}else if(i.status===`pending`){if(i.manual_start||i.waiting_reason&&!tt(i.waiting_reason))continue;let e=$e(i);r.has(e)||r.set(e,[]),r.get(e).push(i)}let s=Date.now()+4320*nt;for(let[e,n]of r){n.sort((e,t)=>et(e,t,i));let r=a.has(e),c=n[0]?z(n[0].scheduled_time):null,l=c&&c.getTime()<=s;if(!r&&!l)continue;let u=o.get(e)??p;for(let e of n){let n=z(e.scheduled_time);n&&n.getTime()<=s&&(u=Math.max(u,n.getTime()));let r=(e.print_time_seconds||3600)*1e3;t.push({item:e,estimatedStart:new Date(u),estimatedEnd:new Date(u+r),type:`queued`}),u+=r}}return t},[e,n,p,i]),h=(0,q.useMemo)(()=>{let e=[];for(let n of t)e.push({key:`printer:${n.id}`,label:n.name,printerId:n.id,targetModel:null});let n=new Set,r=!1;for(let t of m)if(t.item.printer_id==null)if(t.item.target_model){let r=`model:${t.item.target_model}`;n.has(r)||(n.add(r),e.push({key:r,label:`${o(`queue.filter.any`)} ${t.item.target_model}`,printerId:null,targetModel:t.item.target_model}))}else r=!0;return r&&e.push({key:`unassigned`,label:o(`queue.filter.unassigned`),printerId:null,targetModel:null}),e},[t,m,o]),g=(0,q.useMemo)(()=>{let e=new Map;for(let t of m){let n;n=t.item.printer_id==null?t.item.target_model?`model:${t.item.target_model}`:`unassigned`:`printer:${t.item.printer_id}`,e.has(n)||e.set(n,[]),e.get(n).push(t)}return e},[m]),_=(0,q.useMemo)(()=>{let e=[];for(let t=0;t<=rt;t+=2){let n=d+t*nt;e.push({ms:n,pct:t/rt*100,label:st(new Date(n))})}return e},[d]),v=(p-d)/it*100,y=v>=0&&v<=100,b=(0,q.useMemo)(()=>{let e=0;for(let t of m)e=Math.max(e,t.estimatedEnd.getTime());return e>0?new Date(e):null},[m]),x=(0,q.useRef)(null);return(0,J.jsxs)(`div`,{children:[(0,J.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-3 mb-5`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(R,{variant:`ghost`,size:`sm`,onClick:()=>u(e=>e-12*nt),className:`p-1.5`,title:o(`queue.timeline.window.back12h`),children:(0,J.jsx)(Ae,{className:`w-4 h-4`})}),(0,J.jsxs)(`span`,{className:`text-sm font-medium text-white min-w-[180px] text-center`,children:[new Date(d).toLocaleString(void 0,{weekday:`short`,month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`}),` → `,new Date(f).toLocaleTimeString(void 0,{hour:`2-digit`,minute:`2-digit`})]}),(0,J.jsx)(R,{variant:`ghost`,size:`sm`,onClick:()=>u(e=>e+12*nt),className:`p-1.5`,title:o(`queue.timeline.window.forward12h`),children:(0,J.jsx)(xe,{className:`w-4 h-4`})}),l!==0&&(0,J.jsx)(R,{variant:`ghost`,size:`sm`,onClick:()=>u(0),className:`text-xs text-bambu-green`,children:o(`queue.timeline.window.now`)})]}),b&&(0,J.jsxs)(`span`,{className:`text-xs text-bambu-gray flex items-center gap-1.5`,children:[(0,J.jsx)(H,{className:`w-3.5 h-3.5`}),o(`queue.timeline.allDoneBy`,{time:b.toLocaleString(void 0,{weekday:`short`,hour:`2-digit`,minute:`2-digit`})})]})]}),h.length>0&&m.length===0&&(0,J.jsx)(`div`,{className:`mb-4 p-3 rounded-lg border border-bambu-dark-tertiary bg-bambu-dark/40 text-xs text-bambu-gray`,children:o(`queue.timeline.nothingCommitted`)}),h.length===0?(0,J.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-16 text-bambu-gray`,children:[(0,J.jsx)(ke,{className:`w-12 h-12 mb-3 opacity-30`}),(0,J.jsx)(`p`,{className:`text-sm`,children:o(`queue.timeline.noData`)})]}):(0,J.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary overflow-hidden`,children:[(0,J.jsxs)(`div`,{className:`flex border-b border-bambu-dark-tertiary`,children:[(0,J.jsx)(`div`,{className:`w-32 sm:w-40 shrink-0 px-3 py-2 text-xs font-medium text-bambu-gray border-r border-bambu-dark-tertiary`,children:o(`queue.timeline.printerColumnHeader`)}),(0,J.jsx)(`div`,{className:`relative flex-1 h-9`,children:_.map(e=>(0,J.jsx)(`div`,{className:`absolute top-0 bottom-0 border-l border-bambu-dark-tertiary/40 text-[10px] sm:text-xs text-bambu-gray pl-1 flex items-center`,style:{left:`${e.pct}%`},children:e.label},e.ms))})]}),(0,J.jsxs)(`div`,{ref:x,className:`relative`,children:[h.map(e=>{let t=g.get(e.key)??[];return(0,J.jsxs)(`div`,{className:`flex border-b border-bambu-dark-tertiary/40 last:border-b-0`,children:[(0,J.jsxs)(`div`,{className:`w-32 sm:w-40 shrink-0 px-3 py-3 border-r border-bambu-dark-tertiary flex items-center gap-2`,children:[(0,J.jsx)(ye,{className:`w-3.5 h-3.5 shrink-0 ${e.printerId==null&&e.targetModel==null?`text-orange-600 dark:text-orange-400`:e.targetModel?`text-blue-600 dark:text-blue-400`:`text-bambu-green`}`}),(0,J.jsx)(`span`,{className:`text-sm text-white truncate`,children:e.label})]}),(0,J.jsxs)(`div`,{className:`relative flex-1`,style:{height:56},children:[_.map(e=>(0,J.jsx)(`div`,{className:`absolute top-0 bottom-0 border-l border-bambu-dark-tertiary/30`,style:{left:`${e.pct}%`}},e.ms)),(0,J.jsx)(`div`,{className:`absolute inset-0 opacity-30`,style:{backgroundImage:`repeating-linear-gradient(45deg, transparent, transparent 6px, rgba(255,255,255,0.04) 6px, rgba(255,255,255,0.04) 12px)`},"aria-hidden":!0}),t.map(e=>{let t=Math.max(d,e.estimatedStart.getTime()),n=Math.min(f,e.estimatedEnd.getTime());if(n<=d||t>=f)return null;let i=(t-d)/it*100,o=(n-t)/it*100,s=e.item.archive_name||e.item.library_file_name||`#${e.item.id}`,c=e.item.archive_thumbnail?r.getArchiveThumbnail(e.item.archive_id):e.item.library_file_thumbnail?r.getLibraryFileThumbnailUrl(e.item.library_file_id):null,l=e.type===`printing`,u=e.item.batch_id!=null;return(0,J.jsxs)(`button`,{onClick:()=>a(e.item),title:[s,`${ct(e.estimatedStart)} → ${ct(e.estimatedEnd)}`,e.item.print_time_seconds?de(e.item.print_time_seconds):null,l&&e.progress!=null?`${Math.round(e.progress)}%`:null,e.item.batch_name?`batch: ${e.item.batch_name}`:null].filter(Boolean).join(` · `),className:`absolute rounded-md transition-all hover:brightness-110 hover:z-10 overflow-hidden flex items-center gap-1.5 px-1.5 text-left ${l?`bg-blue-500/30 border border-blue-400/60`:u?`bg-cyan-500/20 border border-cyan-400/50`:`bg-bambu-green/20 border border-bambu-green/40`}`,style:{left:`${i}%`,width:`max(${at}px, ${o}%)`,top:8,height:ot},children:[c&&(0,J.jsx)(`img`,{src:c,alt:``,className:`w-7 h-7 rounded object-cover shrink-0 bg-bambu-dark`}),(0,J.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,J.jsx)(`div`,{className:`text-xs text-white font-medium truncate leading-tight`,children:s}),(0,J.jsxs)(`div`,{className:`text-[10px] text-bambu-gray truncate leading-tight`,children:[e.item.print_time_seconds?de(e.item.print_time_seconds):``,l&&e.progress!=null?` · ${Math.round(e.progress)}%`:``]})]}),l&&e.progress!=null&&(0,J.jsx)(`div`,{className:`absolute bottom-0 left-0 h-0.5 bg-blue-300`,style:{width:`${e.progress}%`},"aria-hidden":!0})]},e.item.id)})]})]},e.key)}),y&&(0,J.jsxs)(`div`,{className:`absolute top-0 bottom-0 pointer-events-none z-20 flex inset-x-0`,children:[(0,J.jsx)(`div`,{className:`w-32 sm:w-40 shrink-0`}),(0,J.jsx)(`div`,{className:`relative flex-1`,children:(0,J.jsx)(`div`,{className:`absolute top-0 bottom-0 w-0.5 bg-red-400 shadow-[0_0_8px_rgba(248,113,113,0.6)]`,style:{left:`${v}%`},children:(0,J.jsx)(`div`,{className:`absolute -top-1 -left-1 w-2.5 h-2.5 bg-red-400 rounded-full`})})})]})]})]})]})}function ut({hasPermission:e,t,focusBatchId:n=null}){let i=o(),{showToast:a}=O(),[l,u]=(0,q.useState)(n?`all`:`active`),[d,f]=(0,q.useState)(null),{data:p}=s({queryKey:[`settings`],queryFn:r.getSettings}),m=De(p?.currency||`USD`),{data:h,isLoading:g}=s({queryKey:[`batches`,l],queryFn:()=>r.getBatches(l===`all`?void 0:l)}),_=n!=null&&!!h?.some(e=>e.id===n);(0,q.useEffect)(()=>{_&&document.getElementById(`batch-${n}`)?.scrollIntoView({block:`center`})},[_,n]);let v=()=>{i.invalidateQueries({queryKey:[`batches`]}),i.invalidateQueries({queryKey:[`queue`]})},y=c({mutationFn:({id:e,plateId:t})=>r.dispatchBatch(e,t===void 0?{}:{plate_id:t,only_plate:!0}),onSuccess:e=>{v(),a(t(`queue.batchOrders.dispatched`,{name:e.name}),`success`)},onError:e=>a(e.message,`error`)}),b=c({mutationFn:e=>r.cancelBatch(e),onSuccess:()=>{v(),f(null),a(t(`queue.batchCancelled`),`success`)},onError:e=>a(e.message,`error`)}),x=e(`queue:create`),S=e(`queue:delete_all`);return(0,J.jsxs)(`div`,{children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 mb-4`,children:[(0,J.jsx)(N,{className:`w-5 h-5 text-cyan-700 dark:text-cyan-300`}),(0,J.jsx)(`h2`,{className:`text-base sm:text-lg font-semibold text-white`,children:t(`queue.batchOrders.title`)}),(0,J.jsx)(`div`,{className:`flex gap-1 ml-auto`,children:[`active`,`completed`,`cancelled`,`all`].map(e=>(0,J.jsx)(`button`,{type:`button`,onClick:()=>u(e),className:`text-xs px-2.5 py-1 rounded-full border transition-colors ${l===e?`border-bambu-green bg-bambu-green/10 text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:border-bambu-gray`}`,children:t(`queue.batchOrders.filter.${e}`)},e))})]}),g?(0,J.jsx)(`div`,{className:`text-center py-12 text-bambu-gray`,children:t(`common.loading`)}):h?.length?(0,J.jsx)(`div`,{className:`space-y-4`,children:h.map(e=>(0,J.jsx)(ft,{batch:e,currency:m,canDispatch:x,canCancel:S,isDispatching:y.isPending&&y.variables?.id===e.id,highlighted:e.id===n,onDispatch:t=>y.mutate({id:e.id,plateId:t}),onCancel:()=>f(e),t},e.id))}):(0,J.jsxs)(le,{className:`p-12 text-center border-dashed`,children:[(0,J.jsx)(N,{className:`w-16 h-16 text-bambu-gray mx-auto mb-4 opacity-50`}),(0,J.jsx)(`h3`,{className:`text-xl font-medium text-white mb-2`,children:t(`queue.batchOrders.emptyTitle`)}),(0,J.jsx)(`p`,{className:`text-bambu-gray max-w-md mx-auto`,children:t(`queue.batchOrders.emptyDescription`)})]}),d&&(0,J.jsx)(Ee,{title:t(`queue.cancelBatchConfirmTitle`),message:t(`queue.cancelBatchConfirmMessage`),confirmText:t(`queue.cancelBatch`),variant:`warning`,onConfirm:()=>b.mutate(d.id),onCancel:()=>f(null)})]})}var dt={active:`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-300`,completed:`bg-green-100 dark:bg-green-500/20 text-green-700 dark:text-green-300`,cancelled:`bg-bambu-dark-tertiary text-bambu-gray`};function ft({batch:e,currency:t,canDispatch:n,canCancel:r,isDispatching:i,onDispatch:a,onCancel:o,t:s,highlighted:c=!1}){let l=e.has_targets?e.target_count:e.completed_count+e.pending_count+e.printing_count+e.failed_count,u=l>0?Math.round(e.completed_count/l*100):0,d=e.has_targets?e.remaining_count-e.dispatchable_count:0,f=e.due_date?z(e.due_date):null,p=f!=null&&e.status===`active`&&f.getTime()0&&e.status!==`cancelled`&&n&&(0,J.jsxs)(R,{variant:`primary`,size:`sm`,onClick:()=>a(),disabled:i,children:[(0,J.jsx)(ze,{className:`w-4 h-4 mr-1`}),s(`queue.batchOrders.dispatchRemaining`,{count:e.dispatchable_count})]}),e.status===`active`&&r&&(0,J.jsxs)(R,{variant:`ghost`,size:`sm`,onClick:o,children:[(0,J.jsx)(E,{className:`w-4 h-4 mr-1`}),s(`queue.cancelBatch`)]})]})]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-3 mb-2`,children:[(0,J.jsx)(`div`,{className:`flex-1 h-2 bg-bambu-dark-tertiary rounded-full overflow-hidden`,children:(0,J.jsx)(`div`,{className:`h-full rounded-full transition-all ${e.status===`completed`?`bg-bambu-green`:`bg-blue-500`}`,style:{width:`${Math.min(100,u)}%`}})}),(0,J.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap tabular-nums`,children:s(`queue.batchProgress`,{completed:e.completed_count,total:l})})]}),(0,J.jsxs)(`div`,{className:`flex flex-wrap gap-x-4 gap-y-1 text-xs text-bambu-gray mb-1`,children:[e.printing_count>0&&(0,J.jsx)(`span`,{children:s(`queue.batchOrders.printing`,{count:e.printing_count})}),e.pending_count>0&&(0,J.jsx)(`span`,{children:s(`queue.batch.pendingCount`,{count:e.pending_count})}),e.failed_count>0&&(0,J.jsxs)(`span`,{className:`text-orange-600 dark:text-orange-400 flex items-center gap-1`,children:[(0,J.jsx)(L,{className:`w-3 h-3`}),s(`queue.batchOrders.failed`,{count:e.failed_count})]}),e.has_targets&&e.remaining_count>0&&(0,J.jsx)(`span`,{children:s(`queue.batchOrders.remaining`,{count:e.remaining_count})}),e.print_time_seconds>0&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,J.jsx)(H,{className:`w-3 h-3`}),de(e.print_time_seconds)]}),e.actual_cost!=null&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,J.jsx)(A,{className:`w-3 h-3`}),(0,J.jsx)(`span`,{children:s(`queue.batchOrders.costSoFar`,{amount:`${t} ${e.actual_cost.toFixed(2)}`})}),e.estimated_remaining_cost!=null&&e.estimated_remaining_cost>0&&(0,J.jsx)(`span`,{children:s(`queue.batchOrders.costRemaining`,{amount:`${t} ${e.estimated_remaining_cost.toFixed(2)}`})})]})]}),d>0&&e.status!==`cancelled`&&(0,J.jsxs)(`p`,{className:`flex items-start gap-1.5 text-xs text-orange-600 dark:text-orange-400 mb-1`,children:[(0,J.jsx)(L,{className:`w-3 h-3 mt-0.5 flex-shrink-0`}),(0,J.jsx)(`span`,{children:s(`queue.batchOrders.strandedNotice`,{runs:d,owed:e.remaining_count})})]}),e.has_targets&&e.plates.length>0&&(0,J.jsx)(`div`,{className:`mt-3 border-t border-bambu-dark-tertiary pt-3 space-y-1.5`,children:e.plates.map(r=>(0,J.jsx)(pt,{plate:r,batchStatus:e.status,currency:t,canDispatch:n,isDispatching:i,onDispatch:()=>a(r.plate_id),t:s},`${r.plate_id??`file`}`))})]})}function pt({plate:e,batchStatus:t,currency:n,canDispatch:r,isDispatching:i,onDispatch:a,t:o}){let s=e.plate_name||(e.plate_id==null?o(`queue.batchOrders.wholeFile`):o(`queue.plateNumber`,{index:e.plate_id}));return(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-xs`,children:[(0,J.jsx)(ke,{className:`w-3.5 h-3.5 text-bambu-gray flex-shrink-0`}),(0,J.jsx)(`span`,{className:`text-white min-w-0 truncate`,children:s}),(0,J.jsx)(`span`,{className:`text-bambu-gray tabular-nums`,children:o(`queue.batchOrders.plateProgress`,{completed:e.completed_count,target:e.quantity_target})}),e.failed_count>0&&(0,J.jsx)(`span`,{className:`text-orange-600 dark:text-orange-400`,children:o(`queue.batchOrders.failed`,{count:e.failed_count})}),e.actual_cost!=null&&(0,J.jsx)(`span`,{className:`text-bambu-gray tabular-nums`,children:`${n} ${e.actual_cost.toFixed(2)}`}),e.remaining>0&&t!==`cancelled`&&(0,J.jsxs)(`span`,{className:`ml-auto flex items-center gap-2`,children:[(0,J.jsx)(`span`,{className:`text-bambu-gray`,children:o(`queue.batchOrders.remaining`,{count:e.remaining})}),e.can_dispatch?r&&(0,J.jsx)(`button`,{type:`button`,onClick:a,disabled:i,className:`text-bambu-green hover:underline disabled:opacity-50`,children:o(`queue.batchOrders.dispatchPlate`)}):(0,J.jsx)(`span`,{className:`text-orange-600 dark:text-orange-400`,children:o(`queue.batchOrders.strandedPlate`)})]})]})}function mt(e,t){if(!e?.connected||t>=254)return;let n=t>=128,r=n?t:Math.floor(t/4),i=n?0:t%4,a=e.ams?.find(e=>e.id===r);if(W(n?a?.tray[0]:a?.tray.find(e=>e.id===i))===`physical`)return ve(r,i,n,!1)}function ht(e,t){let n=new Map;if(!e?.length||!t?.length)return n;let r=new Set(e.filter(e=>e>=0)),i=new Map,a;for(let[e]of t){if(a!==void 0&&!r.has(e)&&!i.has(e)){let t=r.has(a)?a:i.get(a);t!==void 0&&(i.set(e,t),n.set(t,e))}a=e}return n}function gt(e){return e.slotLabel?[e.slotLabel,e.spoolName||e.type,e.colorName].filter(Boolean).join(` · `):e.colorName}function _t(e,t,n=[],r,i=`Empty`){let a=e.status===`printing`?ht(e.ams_mapping,r?.tray_change_log):new Map,o=t=>{let o=t.slotId,s=o>0?e.ams_mapping?.[o-1]:void 0;if(s==null||s<0)return t;let c=a.get(s)??s,l=n.find(e=>e.globalTrayId===c);if(l)return{slotId:o,type:l.type,color:l.color,colorName:l.colorName,slotLabel:l.label,spoolName:l.spoolName,extraColors:l.extraColors,effectType:l.effectType,subtype:l.spoolSubtype};let u=mt(r,c);return u?{...t,slotLabel:u,spoolName:i,emptySlot:!0}:t},s=e.plate_id==null?t[0]:t.find(t=>t.index===e.plate_id);if(s){let t=new Map((e.filament_overrides??[]).map(e=>[e.slot_id,e]));return s.filaments.filter(e=>e.used_in_plate!==!1&&e.used_grams>0).map(e=>{let n=t.get(e.slot_id),r=n?.color??e.color,i=n?.type??e.type;return o({slotId:e.slot_id,type:i,color:r,colorName:n?.color_name?.trim()||G(r,i)})})}return e.filament_overrides?.length?e.filament_overrides.map(e=>o({slotId:e.slot_id,type:e.type,color:e.color,colorName:e.color_name?.trim()||G(e.color,e.type)})):e.filament_color?[o({slotId:1,type:e.filament_type??``,color:e.filament_color,colorName:G(e.filament_color,e.filament_type)})]:[]}function vt(e,t=!1){return t&&e>=1e3?`${(e/1e3).toFixed(1)}kg`:`${Math.round(e)}g`}function yt({status:e,waitingReason:t,printerState:n,t:r}){if(e===`pending`&&t)return(0,J.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs font-medium border text-purple-700 dark:text-purple-400 bg-purple-50 dark:bg-purple-400/10 border-purple-200 dark:border-purple-400/20`,children:[(0,J.jsx)(H,{className:`w-3.5 h-3.5`}),r(`queue.status.waiting`)]});if(e===`printing`&&n===`PAUSE`)return(0,J.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs font-medium border text-yellow-700 dark:text-yellow-400 bg-yellow-50 dark:bg-yellow-400/10 border-yellow-200 dark:border-yellow-400/20`,children:[(0,J.jsx)(P,{className:`w-3.5 h-3.5`}),r(`queue.status.paused`)]});let{icon:i,color:a,label:o}={pending:{icon:H,color:`text-status-warning bg-status-warning/10 border-status-warning/20`,label:r(`queue.status.pending`)},printing:{icon:oe,color:`text-blue-700 dark:text-blue-400 bg-blue-50 dark:bg-blue-400/10 border-blue-200 dark:border-blue-400/20`,label:r(`queue.status.printing`)},completed:{icon:k,color:`text-status-ok bg-status-ok/10 border-status-ok/20`,label:r(`queue.status.completed`)},failed:{icon:E,color:`text-status-error bg-status-error/10 border-status-error/20`,label:r(`queue.status.failed`)},skipped:{icon:F,color:`text-orange-700 dark:text-orange-400 bg-orange-50 dark:bg-orange-400/10 border-orange-200 dark:border-orange-400/20`,label:r(`queue.status.skipped`)},cancelled:{icon:ce,color:`text-gray-400 bg-gray-400/10 border-gray-400/20`,label:r(`queue.status.cancelled`)}}[e];return(0,J.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs font-medium border ${a}`,children:[(0,J.jsx)(i,{className:`w-3.5 h-3.5`}),o]})}function bt({selectedCount:e,printers:t,onSave:n,onClose:r,isSaving:i,canControlPrinter:a,hasGcodeSnippets:o,t:s}){let[c,l]=(0,q.useState)(`unchanged`),[u,d]=(0,q.useState)(`unchanged`),[f,p]=(0,q.useState)(`unchanged`),[m,h]=(0,q.useState)(`unchanged`),[g,_]=(0,q.useState)(`unchanged`),[v,y]=(0,q.useState)(`unchanged`),[b,x]=(0,q.useState)(`unchanged`),[S,ee]=(0,q.useState)(`unchanged`),[C,te]=(0,q.useState)(`unchanged`),[w,ne]=(0,q.useState)(`unchanged`),[T,re]=(0,q.useState)(`unchanged`),[E,D]=(0,q.useState)(`unchanged`),[O,k]=(0,q.useState)(`unchanged`),A=t.some(e=>e.nozzle_count===2),j=()=>{let e={};c!==`unchanged`&&(e.printer_id=c),u!==`unchanged`&&(e.manual_start=u),f!==`unchanged`&&(e.auto_off_after=f),m!==`unchanged`&&(e.require_previous_success=m),g!==`unchanged`&&(e.gcode_injection=g),v!==`unchanged`&&(e.bed_levelling=v),b!==`unchanged`&&(e.flow_cali=b),S!==`unchanged`&&(e.vibration_cali=S),C!==`unchanged`&&(e.layer_inspect=C),w!==`unchanged`&&(e.timelapse=w),T!==`unchanged`&&(e.use_ams=T),E!==`unchanged`&&(e.confirm_outcome=E),O!==`unchanged`&&(e.nozzle_offset_cali=O),n(e)},M=c!==`unchanged`||u!==`unchanged`||f!==`unchanged`||m!==`unchanged`||v!==`unchanged`||b!==`unchanged`||S!==`unchanged`||C!==`unchanged`||w!==`unchanged`||T!==`unchanged`||E!==`unchanged`||O!==`unchanged`||g!==`unchanged`;return(0,J.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center p-4 bg-black/50 backdrop-blur-sm`,children:(0,J.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-lg max-h-[90vh] overflow-y-auto`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,J.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:s(`queue.bulkEdit.title`,{count:e})}),(0,J.jsx)(`button`,{onClick:r,className:`p-1 hover:bg-bambu-dark rounded`,children:(0,J.jsx)(ce,{className:`w-5 h-5 text-bambu-gray`})})]}),(0,J.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,J.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:s(`queue.bulkEdit.description`)}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:s(`queue.bulkEdit.printer`)}),(0,J.jsxs)(`select`,{value:c===null?`null`:c===`unchanged`?`unchanged`:String(c),onChange:e=>{let t=e.target.value;l(t===`unchanged`?`unchanged`:t===`null`?null:Number(t))},className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,J.jsx)(`option`,{value:`unchanged`,children:s(`queue.bulkEdit.noChange`)}),(0,J.jsx)(`option`,{value:`null`,children:s(`queue.filter.unassigned`)}),t.map(e=>(0,J.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:s(`queue.bulkEdit.queueOptions`)}),(0,J.jsxs)(`div`,{className:`space-y-2`,children:[(0,J.jsx)(Q,{label:s(`queue.bulkEdit.staged`),value:u,onChange:d,t:s}),(0,J.jsx)(Q,{label:s(`queue.bulkEdit.autoPowerOff`),value:f,onChange:p,disabled:!a,t:s}),(0,J.jsx)(Q,{label:s(`queue.bulkEdit.requirePrevious`),value:m,onChange:h,t:s}),o&&(0,J.jsx)(Q,{label:s(`queue.bulkEdit.gcodeInjection`),value:g,onChange:_,t:s})]})]}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:s(`queue.bulkEdit.printOptions`)}),(0,J.jsxs)(`div`,{className:`space-y-2`,children:[(0,J.jsx)(xt,{label:s(`queue.bulkEdit.bedLevelling`),value:v,onChange:y,t:s}),(0,J.jsx)(xt,{label:s(`queue.bulkEdit.flowCalibration`),value:b,onChange:x,t:s}),(0,J.jsx)(Q,{label:s(`queue.bulkEdit.vibrationCalibration`),value:S,onChange:ee,t:s}),(0,J.jsx)(Q,{label:s(`queue.bulkEdit.layerInspection`),value:C,onChange:te,t:s}),(0,J.jsx)(Q,{label:s(`queue.bulkEdit.timelapse`),value:w,onChange:ne,t:s}),(0,J.jsx)(Q,{label:s(`queue.bulkEdit.useAms`),value:T,onChange:re,t:s}),(0,J.jsx)(Q,{label:s(`queue.bulkEdit.confirmOutcome`),value:E,onChange:D,t:s}),A&&(0,J.jsx)(xt,{label:s(`queue.bulkEdit.nozzleOffsetCali`),value:O,onChange:k,t:s})]})]})]}),(0,J.jsxs)(`div`,{className:`flex justify-end gap-3 p-4 border-t border-bambu-dark-tertiary`,children:[(0,J.jsx)(R,{variant:`secondary`,onClick:r,children:s(`common.cancel`)}),(0,J.jsx)(R,{onClick:j,disabled:!M||i,children:s(i?`common.saving`:`queue.bulkEdit.applyChanges`)})]})]})})}function Q({label:e,value:t,onChange:n,disabled:r,t:i}){return(0,J.jsxs)(`div`,{className:`flex items-center justify-between py-1 ${r?`opacity-50`:``}`,children:[(0,J.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e}),(0,J.jsxs)(`div`,{className:`flex items-center gap-1 bg-bambu-dark rounded-lg p-0.5`,children:[(0,J.jsx)(`button`,{onClick:()=>n(`unchanged`),disabled:r,className:`px-2 py-1 text-xs rounded ${t===`unchanged`?`bg-bambu-dark-tertiary text-white`:`text-bambu-gray hover:text-white`} disabled:cursor-not-allowed`,children:`—`}),(0,J.jsx)(`button`,{onClick:()=>n(!1),disabled:r,className:`px-2 py-1 text-xs rounded ${t===!1?`bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400`:`text-bambu-gray hover:text-white`} disabled:cursor-not-allowed`,children:i(`common.off`)}),(0,J.jsx)(`button`,{onClick:()=>n(!0),disabled:r,className:`px-2 py-1 text-xs rounded ${t===!0?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:text-white`} disabled:cursor-not-allowed`,children:i(`common.on`)})]})]})}function xt({label:e,value:t,onChange:n,t:r}){let i=[{key:`unchanged`,label:`—`,active:`bg-bambu-dark-tertiary text-white`},{key:`off`,label:r(`settings.calibrationMode_off`),active:`bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400`},{key:`auto`,label:r(`settings.calibrationMode_auto`),active:`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`},{key:`on`,label:r(`settings.calibrationMode_on`),active:`bg-bambu-green/20 text-bambu-green`}];return(0,J.jsxs)(`div`,{className:`flex items-center justify-between py-1`,children:[(0,J.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e}),(0,J.jsx)(`div`,{className:`flex items-center gap-1 bg-bambu-dark rounded-lg p-0.5`,children:i.map(({key:e,label:r,active:i})=>(0,J.jsx)(`button`,{onClick:()=>n(e),className:`px-2 py-1 text-xs rounded ${t===e?i:`text-bambu-gray hover:text-white`}`,children:r},e))})]})}function St({item:e,position:t,onEdit:n,onCancel:i,onRemove:a,onStop:o,onRequeue:c,onStart:l,onMoveUp:u,onMoveDown:d,timeFormat:f=`system`,isSelected:m=!1,onToggleSelect:h,hasPermission:g,canModify:_,printerState:v,showEta:y=!1,etaNow:x,t:S}){let{hasAnyPermission:ee}=Ie(),C=!ee(`queue:update_all`,`queue:start_unreviewed`),te=e.printer_id!=null&&(e.ams_mapping?.some(e=>e>=0)??!1),{data:w}=s({queryKey:[`printerStatus`,e.printer_id],queryFn:()=>r.getPrinterStatus(e.printer_id),refetchInterval:v===`printing`?3e4:!1,enabled:e.printer_id!=null&&(v===`printing`||te)}),{data:E}=s({queryKey:[`printer-inventory-remain`,e.printer_id],queryFn:()=>r.getInventoryRemain(e.printer_id),enabled:te,staleTime:30*1e3}),O=(0,q.useMemo)(()=>{let e=E?.slot_materials;if(!e?.length)return;let t=new Map;return e.forEach(e=>{e.spool&&t.set(e.global_tray_id,e.spool)}),t.size>0?t:void 0},[E]),k=(0,q.useMemo)(()=>me(w,O),[w,O]),A=!!e.library_file_id&&!e.archive_id,{data:j}=s({queryKey:[`archive-plates`,e.archive_id],queryFn:()=>r.getArchivePlates(e.archive_id),enabled:!!e.archive_id&&!A&&!e.archive_deleted}),{data:ie}=s({queryKey:[`library-file-plates`,e.library_file_id],queryFn:()=>r.getLibraryFilePlates(e.library_file_id),enabled:A&&!!e.library_file_id}),ae=A?ie:j,N=ae?.plates??[],P=_t(e,N,k,w,S(`ams.empty`)),F=g(`queue:reorder`),{attributes:L,listeners:se,setNodeRef:le,transform:B,transition:ve,isDragging:be}=p({id:e.id,disabled:e.status!==`pending`||!F}),xe={transform:b.Transform.toString(B),transition:ve},we=e.status===`printing`,W=e.status===`pending`,Ee=[`completed`,`failed`,`skipped`,`cancelled`].includes(e.status),De=W&&y&&e.print_time_seconds!=null&&e.print_time_seconds>0?ue(e.print_time_seconds/60,f,S,x):null,Oe=W&&h;return(0,J.jsxs)(`div`,{ref:le,style:xe,className:` group relative bg-bambu-dark-secondary rounded-xl border transition-all duration-200 border-l-[3px] ${we?`border-l-blue-500`:W?`border-l-yellow-500`:e.status===`completed`?`border-l-emerald-500`:e.status===`failed`?`border-l-red-500`:`border-l-gray-500`} ${be?`opacity-50 scale-[1.02] shadow-xl z-50`:``} @@ -6,11 +6,11 @@ import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,t as i,w as ${m&&Oe?`sm:border-bambu-dark-tertiary border-bambu-green/40`:``} ${!m&&!we?`border-bambu-dark-tertiary hover:border-bambu-dark-tertiary/80`:``} ${Oe?`cursor-pointer sm:cursor-default`:``} - `,onClick:Oe?()=>{window.innerWidth<640&&h()}:void 0,children:[Oe&&m&&(0,J.jsx)(`div`,{className:`sm:hidden absolute left-0 top-3 bottom-3 w-1 rounded-full bg-bambu-green`}),(0,J.jsxs)(`div`,{className:`flex items-start sm:items-center gap-2 sm:gap-4 p-3 sm:p-4`,children:[W&&(u||d)&&(0,J.jsxs)(`div`,{className:`flex sm:hidden flex-col shrink-0 -my-1`,onClick:e=>e.stopPropagation(),children:[(0,J.jsx)(`button`,{type:`button`,onClick:u,disabled:!u,title:S(`queue.moveUp`),"aria-label":S(`queue.moveUp`),className:`flex items-center justify-center w-8 h-7 rounded-lg text-bambu-gray hover:text-white hover:bg-bambu-dark disabled:opacity-25 disabled:hover:bg-transparent transition-colors`,children:(0,J.jsx)(re,{className:`w-5 h-5`})}),(0,J.jsx)(`button`,{type:`button`,onClick:d,disabled:!d,title:S(`queue.moveDown`),"aria-label":S(`queue.moveDown`),className:`flex items-center justify-center w-8 h-7 rounded-lg text-bambu-gray hover:text-white hover:bg-bambu-dark disabled:opacity-25 disabled:hover:bg-transparent transition-colors`,children:(0,J.jsx)(T,{className:`w-5 h-5`})})]}),W&&h&&(0,J.jsx)(`button`,{onClick:e=>{e.stopPropagation(),h()},className:`hidden sm:flex items-center justify-center w-6 h-6 rounded border transition-colors shrink-0 ${m?`bg-bambu-green border-bambu-green text-white`:`border-white/30 bg-black/30 hover:border-bambu-green/50`}`,children:m&&(0,J.jsx)(ne,{className:`w-4 h-4`})}),W?(0,J.jsx)(`div`,{...L,...se,className:`hidden sm:flex items-center justify-center w-8 h-8 rounded-lg bg-bambu-dark cursor-grab active:cursor-grabbing hover:bg-bambu-dark-tertiary transition-colors touch-none shrink-0`,children:(0,J.jsx)(M,{className:`w-4 h-4 text-bambu-gray`})}):t===void 0?(0,J.jsx)(`div`,{className:`hidden sm:block w-8 shrink-0`}):(0,J.jsxs)(`div`,{className:`hidden sm:flex items-center justify-center w-8 h-8 rounded-lg bg-bambu-dark text-bambu-gray text-sm font-medium shrink-0`,children:[`#`,t]}),(0,J.jsx)(`div`,{className:`w-10 h-10 sm:w-14 sm:h-14 flex-shrink-0 bg-bambu-dark rounded-lg overflow-hidden`,children:e.archive_thumbnail?(0,J.jsx)(`img`,{src:e.plate_id==null?r.getArchiveThumbnail(e.archive_id):r.getArchivePlateThumbnail(e.archive_id,e.plate_id),alt:``,className:`w-full h-full object-cover`}):e.library_file_thumbnail?(0,J.jsx)(`img`,{src:e.plate_id==null?r.getLibraryFileThumbnailUrl(e.library_file_id):r.getLibraryFilePlateThumbnail(e.library_file_id,e.plate_id),alt:``,className:`w-full h-full object-cover`}):(0,J.jsx)(`div`,{className:`w-full h-full flex items-center justify-center text-bambu-gray`,children:(0,J.jsx)(ke,{className:`w-5 h-5 sm:w-6 sm:h-6`})})}),(0,J.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,J.jsxs)(`p`,{className:`text-sm sm:text-base text-white font-medium truncate`,children:[Le(e,e=>S(`common.plusNMore`,{count:e})),(ae?.is_multi_plate??!1)&&e.plate_id!==void 0&&e.plate_id!==null&&` • ${N.find(t=>t.index===e.plate_id)?.name||S(`queue.plateNumber`,{index:e.plate_id})}`]}),e.archive_id?(0,J.jsx)(Ce,{to:`/archives?highlight=${e.archive_id}`,className:`text-bambu-gray hover:text-bambu-green transition-colors flex-shrink-0`,title:S(`queue.viewArchive`),children:(0,J.jsx)(ge,{className:`w-3.5 h-3.5`})}):e.library_file_id?(0,J.jsx)(Ce,{to:`/library?highlight=${e.library_file_id}`,className:`text-bambu-gray hover:text-bambu-green transition-colors flex-shrink-0`,title:S(`queue.viewInFileManager`),children:(0,J.jsx)(ge,{className:`w-3.5 h-3.5`})}):null,e.batch_name&&(0,J.jsx)(`span`,{className:`flex-shrink-0 px-1.5 py-0.5 text-[10px] sm:text-xs bg-cyan-100 dark:bg-cyan-500/20 text-cyan-700 dark:text-cyan-300 rounded border border-cyan-300 dark:border-cyan-500/30`,children:e.batch_name})]}),(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-xs sm:text-sm text-bambu-gray`,children:[(0,J.jsxs)(`span`,{className:`flex items-center gap-1 sm:gap-1.5 ${e.printer_id===null&&!e.target_model?`text-orange-700 dark:text-orange-400`:``} ${e.target_model&&!e.printer_id?`text-blue-700 dark:text-blue-400`:``}`,children:[(0,J.jsx)(ye,{className:`w-3 h-3 sm:w-3.5 sm:h-3.5`}),(0,J.jsx)(`span`,{className:`truncate max-w-[120px] sm:max-w-none`,children:(e.variants?.length??0)>1&&!e.printer_id?`${S(`queue.filter.any`)} ${e.variants.map(e=>e.target_model).join(` / `)}${e.target_location?` @ ${e.target_location}`:``}`:e.target_model&&!e.printer_id?`${S(`queue.filter.any`)} ${e.target_model}${e.target_location?` @ ${e.target_location}`:``}${e.required_filament_types?.length?` (${e.required_filament_types.join(`, `)})`:``}`:e.printer_id===null?S(`queue.filter.unassigned`):e.printer_name||`${S(`common.printer`)} #${e.printer_id}`})]}),e.print_time_seconds&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1 sm:gap-1.5`,children:[(0,J.jsx)(I,{className:`w-3 h-3 sm:w-3.5 sm:h-3.5`}),de(e.print_time_seconds)]}),De&&(0,J.jsxs)(`span`,{"data-testid":`queue-item-eta`,className:`text-bambu-green font-medium`,title:S(`queue.time.etaIfStartedNow`),children:[`ETA `,De]}),e.filament_used_grams&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1 sm:gap-1.5`,children:[(0,J.jsx)(Pe,{className:`w-3 h-3 sm:w-3.5 sm:h-3.5`}),_t(e.filament_used_grams)]}),P.length>2?(0,J.jsxs)(`span`,{"data-testid":`queue-filament-compact`,className:`flex items-center gap-0.5 flex-shrink-0`,title:P.map(ht).join(` -`),role:`img`,"aria-label":P.map(ht).join(`, `),children:[P.map(e=>(0,J.jsx)(K,{rgba:e.color,extraColors:e.extraColors,effectType:e.effectType,subtype:e.subtype,className:`w-2.5 h-2.5 sm:w-3 sm:h-3 pointer-events-none`,effectSize:`table`},`filament-${e.slotId}`)),P.some(e=>e.emptySlot)&&(0,J.jsx)(D,{className:`w-3 h-3 ml-0.5 text-yellow-700 dark:text-yellow-400`,"aria-hidden":`true`})]}):P.map(e=>{let t=ht(e);return(0,J.jsxs)(`span`,{className:`flex items-center gap-1 sm:gap-1.5 min-w-0`,title:t,children:[(0,J.jsx)(K,{rgba:e.color,extraColors:e.extraColors,effectType:e.effectType,subtype:e.subtype,className:`w-3 h-3 sm:w-3.5 sm:h-3.5`,effectSize:`table`}),(0,J.jsx)(`span`,{className:`truncate max-w-[110px] sm:max-w-[260px]${e.emptySlot?` text-yellow-700 dark:text-yellow-400`:``}`,children:t})]},`filament-${e.slotId}`)}),(()=>{let t=U(e.bed_type);return t?(0,J.jsxs)(`span`,{className:`flex items-center gap-1 sm:gap-1.5`,title:t.label,children:[(0,J.jsx)(`img`,{src:t.icon,alt:``,className:`w-3.5 h-3.5 sm:w-4 sm:h-4 object-contain`}),(0,J.jsx)(`span`,{className:`truncate max-w-[120px]`,children:t.label})]}):null})(),e.created_by_username&&(0,J.jsxs)(`span`,{className:`hidden sm:flex items-center gap-1.5`,title:S(`queue.addedBy`,{name:e.created_by_username}),children:[(0,J.jsx)(Se,{className:`w-3.5 h-3.5`}),e.created_by_username]}),W&&!e.manual_start&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,J.jsx)(H,{className:`w-3.5 h-3.5`}),e.scheduled_time?(z(e.scheduled_time)?.getTime()??0)-Date.now()<-6e4?S?.(`queue.time.overdue`)??`Overdue`:fe(e.scheduled_time,f,S):S?.(`queue.time.whenFree`)??`When a printer is free`]})]}),(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5 sm:gap-2 mt-1.5 sm:mt-2`,children:[e.manual_start&&(0,J.jsxs)(`span`,{className:`text-[10px] sm:text-xs px-1.5 sm:px-2 py-0.5 bg-purple-50 dark:bg-purple-500/10 text-purple-700 dark:text-purple-400 rounded-full border border-purple-200 dark:border-purple-500/20 flex items-center gap-1`,children:[(0,J.jsx)(Me,{className:`w-2.5 h-2.5 sm:w-3 sm:h-3`}),S(C?`queue.badges.awaitingReview`:`queue.badges.staged`)]}),e.require_previous_success&&(0,J.jsx)(`span`,{className:`text-[10px] sm:text-xs px-1.5 sm:px-2 py-0.5 bg-orange-50 dark:bg-orange-500/10 text-orange-700 dark:text-orange-400 rounded-full border border-orange-200 dark:border-orange-500/20`,children:S(`queue.badges.requiresPrevious`)}),e.auto_off_after&&(0,J.jsxs)(`span`,{className:`text-[10px] sm:text-xs px-1.5 sm:px-2 py-0.5 bg-blue-50 dark:bg-blue-500/10 text-blue-700 dark:text-blue-400 rounded-full border border-blue-200 dark:border-blue-500/20 flex items-center gap-1`,children:[(0,J.jsx)(Te,{className:`w-2.5 h-2.5 sm:w-3 sm:h-3`}),S(`queue.badges.autoPowerOff`)]}),e.gcode_injection&&(0,J.jsxs)(`span`,{className:`text-[10px] sm:text-xs px-1.5 sm:px-2 py-0.5 bg-emerald-50 dark:bg-emerald-500/10 text-emerald-700 dark:text-emerald-400 rounded-full border border-emerald-200 dark:border-emerald-500/20 flex items-center gap-1`,children:[(0,J.jsx)(_e,{className:`w-2.5 h-2.5 sm:w-3 sm:h-3`}),S(`queue.badges.gcodeInjection`)]}),e.confirm_outcome&&(0,J.jsxs)(`span`,{title:S(`queue.badges.confirmOutcomeTitle`),className:`text-[10px] sm:text-xs px-1.5 sm:px-2 py-0.5 bg-green-50 dark:bg-green-500/10 text-green-700 dark:text-green-400 rounded-full border border-green-200 dark:border-green-500/20 flex items-center gap-1`,children:[(0,J.jsx)(je,{className:`w-2.5 h-2.5 sm:w-3 sm:h-3`}),S(`queue.badges.confirmOutcome`)]})]}),we&&w&&(()=>{let e=w.state===`RUNNING`||w.state===`PAUSE`,t=e&&w.progress||0,n=e?w.remaining_time:null,r=e?w.layer_num:null,i=e?w.total_layers:null;return(0,J.jsxs)(`div`,{className:`mt-2 sm:mt-3`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between text-xs sm:text-sm`,children:[(0,J.jsx)(`div`,{className:`flex-1 bg-bambu-dark-tertiary rounded-full h-1.5 sm:h-2 mr-3`,children:(0,J.jsx)(`div`,{className:`bg-bambu-green h-1.5 sm:h-2 rounded-full transition-all`,style:{width:`${t}%`}})}),(0,J.jsxs)(`span`,{className:`text-white`,children:[Math.round(t),`%`]})]}),(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 sm:gap-3 mt-1.5 sm:mt-2 text-[10px] sm:text-xs text-bambu-gray`,children:[n!=null&&n>0&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,J.jsx)(H,{className:`w-3 h-3`}),de(n*60)]}),(0,J.jsxs)(`span`,{className:`text-bambu-green font-medium`,title:S(`printers.estimatedCompletion`),children:[`ETA `,ue(n,f,S)]})]}),r!=null&&i!=null&&i>0&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,J.jsx)(ke,{className:`w-3 h-3`}),r,`/`,i]})]})]})})(),e.waiting_reason&&e.status===`pending`&&(0,J.jsxs)(`p`,{className:`text-[10px] sm:text-xs text-purple-700 dark:text-purple-400 mt-1.5 sm:mt-2 flex items-start gap-1`,children:[(0,J.jsx)(D,{className:`w-3 h-3 mt-0.5 flex-shrink-0`}),(0,J.jsx)(`span`,{children:e.waiting_reason})]}),e.filament_short&&e.status===`pending`&&(0,J.jsxs)(`p`,{className:`text-[10px] sm:text-xs text-yellow-700 dark:text-yellow-400 mt-1.5 sm:mt-2 flex items-start gap-1`,title:S(`queue.filamentShort.rowTooltip`),children:[(0,J.jsx)(D,{className:`w-3 h-3 mt-0.5 flex-shrink-0`}),(0,J.jsx)(`span`,{children:S(`queue.filamentShort.rowBadge`)})]}),e.archive_has_slicer_ams_mapping&&(0,J.jsxs)(`p`,{className:`text-[10px] sm:text-xs text-green-700 dark:text-green-400 mt-1.5 sm:mt-2 flex items-start gap-1`,title:S(`queue.slicerAmsMapping.rowTooltip`),children:[(0,J.jsx)(ne,{className:`w-3 h-3 mt-0.5 flex-shrink-0`}),(0,J.jsx)(`span`,{children:S(`queue.slicerAmsMapping.rowBadge`)})]}),e.error_message&&(0,J.jsxs)(`p`,{className:`text-[10px] sm:text-xs text-red-700 dark:text-red-400 mt-1.5 sm:mt-2 flex items-center gap-1`,children:[(0,J.jsx)(D,{className:`w-3 h-3`}),e.error_message]})]}),(0,J.jsxs)(`div`,{className:`flex flex-col sm:flex-row items-end sm:items-center gap-2 sm:gap-1 shrink-0`,onClick:e=>e.stopPropagation(),children:[(0,J.jsx)(vt,{status:e.status,waitingReason:e.waiting_reason,printerState:v,t:S}),(0,J.jsxs)(`div`,{className:`flex items-center gap-0.5 sm:gap-1`,children:[we&&(0,J.jsx)(R,{variant:`ghost`,size:`sm`,onClick:o,disabled:!_(`queue`,`update`,e.created_by_id),title:_(`queue`,`update`,e.created_by_id)?S(`queue.actions.stopPrint`):S(`queue.permissions.noStopPrint`),className:`text-red-600 dark:text-red-400 hover:text-red-700 dark:hover:text-red-300 hover:bg-red-50 dark:hover:bg-red-500/10 p-1.5 sm:p-2`,children:(0,J.jsx)(Be,{className:`w-4 h-4`})}),W&&(0,J.jsxs)(J.Fragment,{children:[e.manual_start&&(0,J.jsx)(R,{variant:`ghost`,size:`sm`,onClick:l,disabled:C||!_(`queue`,`update`,e.created_by_id),title:C?S(`queue.permissions.awaitingReview`):_(`queue`,`update`,e.created_by_id)?S(`queue.actions.startPrint`):S(`queue.permissions.noStartPrint`),className:`text-bambu-green hover:text-bambu-green-light hover:bg-bambu-green/10 p-1.5 sm:p-2`,children:(0,J.jsx)(oe,{className:`w-4 h-4`})}),(0,J.jsx)(R,{variant:`ghost`,size:`sm`,onClick:n,disabled:!_(`queue`,`update`,e.created_by_id),title:_(`queue`,`update`,e.created_by_id)?S(`common.edit`):S(`queue.permissions.noEdit`),className:`p-1.5 sm:p-2`,children:(0,J.jsx)(pe,{className:`w-4 h-4`})}),(0,J.jsx)(R,{variant:`ghost`,size:`sm`,onClick:i,disabled:!_(`queue`,`delete`,e.created_by_id),title:_(`queue`,`delete`,e.created_by_id)?S(`common.cancel`):S(`queue.permissions.noCancel`),className:`text-red-600 dark:text-red-400 hover:text-red-700 dark:hover:text-red-300 hover:bg-red-50 dark:hover:bg-red-500/10 p-1.5 sm:p-2`,children:(0,J.jsx)(ce,{className:`w-4 h-4`})})]}),Ee&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(R,{variant:`ghost`,size:`sm`,onClick:c,disabled:!g(`queue:create`),title:g(`queue:create`)?S(`queue.actions.requeue`):S(`queue.permissions.noRequeue`),className:`text-bambu-green hover:text-bambu-green/80 hover:bg-bambu-green/10 p-1.5 sm:p-2`,children:(0,J.jsx)(V,{className:`w-4 h-4`})}),(0,J.jsx)(R,{variant:`ghost`,size:`sm`,onClick:a,disabled:!_(`queue`,`delete`,e.created_by_id),title:_(`queue`,`delete`,e.created_by_id)?S(`common.remove`):S(`queue.permissions.noRemove`),className:`p-1.5 sm:p-2`,children:(0,J.jsx)(he,{className:`w-4 h-4`})})]})]})]})]})]})}function St(e){let{row:t,setEditItem:n,setConfirmAction:r,startMutation:i,selectedItems:a,handleToggleSelect:o,timeFormat:s,hasPermission:c,canModify:l,t:u,etaEligibleIds:d,etaNow:f,onMoveUp:p,onMoveDown:m}=e;return t.kind===`item`?(0,J.jsx)(xt,{item:t.item,onEdit:()=>n(t.item),onCancel:()=>r({type:`cancel`,item:t.item}),onRemove:()=>{},onStop:()=>{},onRequeue:()=>{},onStart:()=>i.mutate({id:t.item.id}),onMoveUp:p,onMoveDown:m,timeFormat:s,isSelected:a.includes(t.item.id),onToggleSelect:()=>o(t.item.id),hasPermission:c,canModify:l,showEta:d.has(t.item.id),etaNow:f,t:u}):(0,J.jsx)(Ct,{...e})}function Ct({row:e,collapsed:t,onToggleBatch:n,onUngroup:r,setEditItem:i,setConfirmAction:a,startMutation:o,selectedItems:s,handleToggleSelect:c,timeFormat:l,hasPermission:u,canModify:d,t:f,etaEligibleIds:m,etaNow:h,aggregateForRows:g,onMoveUp:_,onMoveDown:v,onMoveBlock:y}){let x=e,S=u(`queue:reorder`),{attributes:ee,listeners:C,setNodeRef:te,transform:w,transition:E,isDragging:D}=p({id:`batch-${x.batchId}`,disabled:!S}),O={transform:b.Transform.toString(w),transition:E},k=g([x]),A=x.items.map(e=>e.id),j=A.length>0&&A.every(e=>s.includes(e)),ie=new Set(x.items.map(e=>e.status)),ae=ie.has(`failed`)?`failed`:ie.has(`printing`)?`printing`:`pending`,P=x.items.filter(e=>e.status===`pending`).length;return(0,J.jsxs)(`div`,{ref:te,style:O,className:`bg-bambu-dark-secondary rounded-xl border border-l-[3px] border-l-cyan-400 border-bambu-dark-tertiary overflow-hidden ${D?`opacity-50 scale-[1.01] shadow-xl z-50`:``}`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2 sm:gap-3 p-3 sm:p-4`,children:[S&&(_||v)&&(0,J.jsxs)(`div`,{className:`flex sm:hidden flex-col shrink-0 -my-1`,children:[(0,J.jsx)(`button`,{type:`button`,onClick:_,disabled:!_,title:f(`queue.moveUp`),"aria-label":f(`queue.moveUp`),className:`flex items-center justify-center w-8 h-7 rounded-lg text-bambu-gray hover:text-white hover:bg-bambu-dark disabled:opacity-25 disabled:hover:bg-transparent transition-colors`,children:(0,J.jsx)(re,{className:`w-5 h-5`})}),(0,J.jsx)(`button`,{type:`button`,onClick:v,disabled:!v,title:f(`queue.moveDown`),"aria-label":f(`queue.moveDown`),className:`flex items-center justify-center w-8 h-7 rounded-lg text-bambu-gray hover:text-white hover:bg-bambu-dark disabled:opacity-25 disabled:hover:bg-transparent transition-colors`,children:(0,J.jsx)(T,{className:`w-5 h-5`})})]}),(0,J.jsx)(`button`,{onClick:e=>{e.stopPropagation(),A.forEach(e=>{(j&&s.includes(e)||!j&&!s.includes(e))&&c(e)})},className:`hidden sm:flex items-center justify-center w-6 h-6 rounded border transition-colors shrink-0 ${j?`bg-bambu-green border-bambu-green text-white`:`border-white/30 bg-black/30 hover:border-bambu-green/50`}`,title:f(j?`queue.bulkEdit.deselectAll`:`queue.bulkEdit.selectAll`),children:j&&(0,J.jsx)(ne,{className:`w-4 h-4`})}),S&&(0,J.jsx)(`div`,{...ee,...C,className:`hidden sm:flex items-center justify-center w-8 h-8 rounded-lg bg-bambu-dark cursor-grab active:cursor-grabbing hover:bg-bambu-dark-tertiary transition-colors touch-none shrink-0`,title:f(`queue.batch.dragGroup`,{defaultValue:`Drag group`}),children:(0,J.jsx)(M,{className:`w-4 h-4 text-bambu-gray`})}),(0,J.jsx)(`button`,{onClick:n,className:`flex items-center justify-center w-8 h-8 rounded-lg bg-bambu-dark hover:bg-bambu-dark-tertiary transition-colors shrink-0`,title:f(t?`queue.batch.expand`:`queue.batch.collapse`),children:t?(0,J.jsx)(xe,{className:`w-4 h-4 text-bambu-gray`}):(0,J.jsx)(T,{className:`w-4 h-4 text-bambu-gray`})}),(0,J.jsx)(`div`,{className:`w-10 h-10 sm:w-12 sm:h-12 flex-shrink-0 bg-bambu-dark rounded-lg flex items-center justify-center`,children:t?(0,J.jsx)(N,{className:`w-5 h-5 text-cyan-700 dark:text-cyan-300`}):(0,J.jsx)(Ve,{className:`w-5 h-5 text-cyan-700 dark:text-cyan-300`})}),(0,J.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,J.jsx)(`p`,{className:`text-sm sm:text-base text-white font-medium truncate`,children:x.batchName}),(0,J.jsx)(`span`,{className:`flex-shrink-0 px-1.5 py-0.5 text-[10px] sm:text-xs bg-cyan-100 dark:bg-cyan-500/15 text-cyan-700 dark:text-cyan-300 rounded border border-cyan-300 dark:border-cyan-500/30`,children:f(`queue.batch.label`,{count:k.count})})]}),(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-xs sm:text-sm text-bambu-gray`,children:[k.time>0&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1 sm:gap-1.5`,children:[(0,J.jsx)(I,{className:`w-3 h-3 sm:w-3.5 sm:h-3.5`}),de(k.time)]}),k.weight>0&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1 sm:gap-1.5`,children:[(0,J.jsx)(Pe,{className:`w-3 h-3 sm:w-3.5 sm:h-3.5`}),_t(k.weight)]}),P>0&&ae===`pending`&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1 sm:gap-1.5 text-yellow-700 dark:text-yellow-400`,children:[(0,J.jsx)(H,{className:`w-3 h-3 sm:w-3.5 sm:h-3.5`}),f(`queue.batch.pendingCount`,{count:P})]})]})]}),(0,J.jsx)(`div`,{className:`flex items-center gap-1 shrink-0`,children:r&&(0,J.jsx)(R,{variant:`ghost`,size:`sm`,onClick:r,title:f(`queue.batch.ungroup`),className:`text-cyan-700 dark:text-cyan-300 hover:text-cyan-900 dark:hover:text-cyan-200 hover:bg-cyan-50 dark:hover:bg-cyan-500/10 p-1.5 sm:p-2`,children:(0,J.jsx)(Ue,{className:`w-4 h-4`})})})]}),!t&&(0,J.jsx)(`div`,{className:`border-t border-bambu-dark-tertiary bg-black/20 p-2 sm:p-3 space-y-2`,children:x.items.map((e,t)=>(0,J.jsx)(xt,{item:e,onEdit:()=>i(e),onCancel:()=>a({type:`cancel`,item:e}),onRemove:()=>{},onStop:()=>{},onRequeue:()=>{},onStart:()=>o.mutate({id:e.id}),onMoveUp:y&&t>0?()=>y([e.id],x.items[t-1].id,!1):void 0,onMoveDown:y&&ty([e.id],x.items[t+1].id,!0):void 0,timeFormat:l,isSelected:s.includes(e.id),onToggleSelect:()=>c(e.id),hasPermission:u,canModify:d,showEta:m.has(e.id),etaNow:h,t:f},e.id))})]})}function wt({items:e,visibleCount:t,onShowMore:n,sortBy:r,sortAsc:i,onSortByChange:a,onSortAscToggle:o,onRemove:s,onRequeue:c,timeFormat:l,batchCollapsed:u,toggleBatchCollapsed:p,hasPermission:m,canModify:h,t:g}){if(e.length===0)return(0,J.jsxs)(le,{className:`p-12 text-center border-dashed`,children:[(0,J.jsx)(Ne,{className:`w-16 h-16 text-bambu-gray mx-auto mb-4 opacity-50`}),(0,J.jsx)(`h3`,{className:`text-xl font-medium text-white mb-2`,children:g(`queue.history.emptyTitle`)}),(0,J.jsx)(`p`,{className:`text-bambu-gray max-w-md mx-auto`,children:g(`queue.history.emptyDescription`)})]});let v=[],y=new Set;for(let n of e.slice(0,t))if(n.batch_id!=null){if(y.has(n.batch_id))continue;y.add(n.batch_id);let t=e.filter(e=>e.batch_id===n.batch_id);v.push({kind:`batch`,batchId:n.batch_id,batchName:n.batch_name||g(`queue.batch.defaultName`),items:t})}else v.push({kind:`item`,item:n});return(0,J.jsxs)(`div`,{children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2 mb-3 sm:mb-4`,children:[(0,J.jsxs)(`h2`,{className:`text-base sm:text-lg font-semibold text-white flex items-center gap-2`,children:[g(`queue.sections.history`),(0,J.jsxs)(`span`,{className:`text-xs sm:text-sm font-normal text-bambu-gray`,children:[`(`,g(`queue.itemCount`,{count:e.length}),`)`]})]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsxs)(`select`,{className:`px-2 sm:px-3 py-1.5 text-xs sm:text-sm bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,value:r,onChange:e=>a(e.target.value),children:[(0,J.jsx)(`option`,{value:`date`,children:g(`queue.sort.byDate`)}),(0,J.jsx)(`option`,{value:`name`,children:g(`queue.sort.byName`)}),(0,J.jsx)(`option`,{value:`printer`,children:g(`queue.sort.byPrinter`)})]}),(0,J.jsx)(R,{variant:`ghost`,size:`sm`,onClick:o,title:g(i?`queue.sort.ascendingOldest`:`queue.sort.descendingNewest`),className:`px-2`,children:i?(0,J.jsx)(f,{className:`w-4 h-4`}):(0,J.jsx)(d,{className:`w-4 h-4`})})]})]}),(0,J.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-2`,children:v.map(e=>{if(e.kind===`item`)return(0,J.jsx)(Qe,{item:e.item,onRemove:()=>s(e.item),onRequeue:()=>c(e.item),timeFormat:l,hasPermission:m,canModify:h,t:g},e.item.id);let t=u[e.batchId]??!0,n=e.items.filter(e=>e.status===`completed`).length,r=e.items.filter(e=>e.status===`failed`).length,i=e.items.filter(e=>e.status===`skipped`).length,a=e.items.filter(e=>e.status===`cancelled`).length,o=e.items.map(e=>e.completed_at||e.created_at).filter(e=>!!e).sort().at(-1);return(0,J.jsxs)(`div`,{className:`md:col-span-2 xl:col-span-3 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary border-l-[3px] border-l-cyan-400`,children:[(0,J.jsxs)(`button`,{onClick:()=>p(e.batchId),className:`w-full flex items-center gap-2 sm:gap-3 px-3 py-2 hover:bg-bambu-dark/30 transition-colors text-left`,title:g(t?`queue.batch.expand`:`queue.batch.collapse`),children:[t?(0,J.jsx)(xe,{className:`w-4 h-4 text-bambu-gray shrink-0`}):(0,J.jsx)(T,{className:`w-4 h-4 text-bambu-gray shrink-0`}),t?(0,J.jsx)(N,{className:`w-5 h-5 text-cyan-700 dark:text-cyan-300 shrink-0`}):(0,J.jsx)(Ve,{className:`w-5 h-5 text-cyan-700 dark:text-cyan-300 shrink-0`}),(0,J.jsx)(`span`,{className:`text-sm text-white font-medium truncate min-w-0 flex-1`,children:e.batchName}),(0,J.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-bambu-gray shrink-0`,children:[n>0&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1 text-emerald-700 dark:text-emerald-400`,children:[(0,J.jsx)(k,{className:`w-3 h-3`}),n]}),r>0&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1 text-red-700 dark:text-red-400`,children:[(0,J.jsx)(E,{className:`w-3 h-3`}),r]}),i>0&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1 text-orange-700 dark:text-orange-400`,children:[(0,J.jsx)(F,{className:`w-3 h-3`}),i]}),a>0&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1 text-gray-400`,children:[(0,J.jsx)(_,{className:`w-3 h-3`}),a]}),(0,J.jsx)(`span`,{title:o??void 0,children:o?fe(o,l,g):null})]})]}),!t&&(0,J.jsx)(`div`,{className:`border-t border-bambu-dark-tertiary bg-black/20 p-2 grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-2`,children:e.items.map(e=>(0,J.jsx)(Qe,{item:e,onRemove:()=>s(e),onRequeue:()=>c(e),timeFormat:l,hasPermission:m,canModify:h,t:g},e.id))})]},`batch-${e.batchId}`)})}),e.length>t&&(0,J.jsxs)(`div`,{className:`mt-4 flex flex-col items-center gap-2`,children:[(0,J.jsx)(R,{variant:`secondary`,size:`sm`,onClick:n,children:g(`queue.history.showMore`)}),(0,J.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:g(`queue.history.showingCount`,{shown:Math.min(t,e.length),total:e.length})})]})]})}var Tt=50;function $(){let{t:e}=a(),t=o(),{showToast:n}=O(),{hasPermission:u,hasAnyPermission:p,canModify:_}=Ie(),[b,ne]=(0,q.useState)(null),[T,re]=(0,q.useState)(``),[E,k]=(0,q.useState)(``),[A,j]=(0,q.useState)(!1),[M,ae]=(0,q.useState)(null),[P,oe]=(0,q.useState)(null),[F,I]=(0,q.useState)(null),[L,ue]=(0,q.useState)([]),[fe,me]=(0,q.useState)(!1),[ge,_e]=(0,q.useState)(null),[B,ve]=(0,q.useState)(()=>localStorage.getItem(`queue.historySortBy`)||`date`),[V,xe]=(0,q.useState)(()=>{let e=localStorage.getItem(`queue.historySortAsc`);return e===null?!1:e===`true`}),[Se,Ce]=(0,q.useState)(Tt),[U,W]=(0,q.useState)(()=>localStorage.getItem(`queue.pendingSortBy`)||`position`),[Te,De]=(0,q.useState)(()=>{let e=localStorage.getItem(`queue.pendingSortAsc`);return e===null?!0:e===`true`}),[ke]=(0,q.useState)(()=>{let e=Number(new URLSearchParams(window.location.search).get(`batch`));return Number.isInteger(e)&&e>0?e:null}),[G,Ae]=(0,q.useState)(()=>{let e=new URLSearchParams(window.location.search),t=e.get(`tab`);if(e.get(`batch`))return`batches`;if(t===`pipelines`||t===`history`||t===`timeline`||t===`queue`||t===`batches`)return t;let n=localStorage.getItem(`queue.activeTab`);return n===`history`||n===`timeline`||n===`pipelines`||n===`batches`?n:`queue`}),[je,Me]=(0,q.useState)(()=>localStorage.getItem(`queue.activeLayout`)===`printer`?`printer`:`position`),[K,Pe]=(0,q.useState)(()=>{try{let e=localStorage.getItem(`queue.batchCollapsed`);return e?JSON.parse(e):{}}catch{return{}}}),[Fe,Be]=(0,q.useState)(null),[Ve,Ue]=(0,q.useState)(!1),[We,Y]=(0,q.useState)(null);(0,q.useEffect)(()=>{localStorage.setItem(`queue.historySortBy`,B)},[B]),(0,q.useEffect)(()=>{localStorage.setItem(`queue.historySortAsc`,String(V))},[V]),(0,q.useEffect)(()=>{Ce(Tt)},[B,V,E]),(0,q.useEffect)(()=>{localStorage.setItem(`queue.pendingSortBy`,U)},[U]),(0,q.useEffect)(()=>{localStorage.setItem(`queue.pendingSortAsc`,String(Te))},[Te]),(0,q.useEffect)(()=>{localStorage.setItem(`queue.activeTab`,G)},[G]),(0,q.useEffect)(()=>{localStorage.setItem(`queue.activeLayout`,je)},[je]),(0,q.useEffect)(()=>{localStorage.setItem(`queue.batchCollapsed`,JSON.stringify(K))},[K]);let Ke=S(g(te,{activationConstraint:{distance:8}}),g(y,{coordinateGetter:v})),{data:X}=s({queryKey:[`settings`],queryFn:r.getSettings}),qe=X?.time_format||`system`,{data:Je}=s({queryKey:[`batches`,`active`],queryFn:()=>r.getBatches(`active`)}),Ye=Je?.length??0,{data:Z,isLoading:Ze}=s({queryKey:[`queue`,b,T],queryFn:()=>r.getQueue(b||void 0,T||void 0),refetchInterval:5e3}),{data:Qe}=s({queryKey:[`printers`],queryFn:()=>r.getPrinters()}),$e=c({mutationFn:e=>r.updateSettings({queue_shortest_first:e}),onSuccess:()=>{t.invalidateQueries({queryKey:[`settings`]})}}),tt=c({mutationFn:e=>r.cancelQueueItem(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`queue`]}),n(e(`queue.toast.cancelled`))},onError:()=>n(e(`queue.toast.cancelFailed`),`error`)}),nt=c({mutationFn:e=>r.removeFromQueue(e),onSuccess:r=>{t.invalidateQueries({queryKey:[`queue`]}),t.invalidateQueries({queryKey:[`batches`]}),n(r.deleted===!1?e(`queue.toast.keptForOrder`):e(`queue.toast.removed`))},onError:()=>n(e(`queue.toast.removeFailed`),`error`)}),rt=c({mutationFn:e=>r.stopQueueItem(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`queue`]}),n(e(`queue.toast.stopped`))},onError:()=>n(e(`queue.toast.stopFailed`),`error`)}),[it,at]=(0,q.useState)(null),[ot,st]=(0,q.useState)(null),ct=c({mutationFn:({id:e,skipFilamentCheck:t})=>r.startQueueItem(e,{skipFilamentCheck:t}),onSuccess:()=>{t.invalidateQueries({queryKey:[`queue`]}),n(e(`queue.toast.released`)),at(null),st(null)},onError:(t,r)=>{if(t instanceof i&&t.status===409&&t.code===`insufficient_filament`){let e=t.detail?.deficit??[];at({itemId:r.id,deficit:e});return}if(t instanceof i&&t.status===409&&t.code===`unmatched_filament`){let e=t.detail?.missing??[];st({itemId:r.id,missing:e});return}n(e(`queue.toast.startFailed`),`error`)}}),dt=c({mutationFn:e=>r.reorderQueue(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`queue`]})},onError:()=>n(e(`queue.toast.reorderFailed`),`error`)}),ft=c({mutationFn:async()=>{let e=Z?.filter(e=>[`completed`,`failed`,`skipped`,`cancelled`].includes(e.status))||[],t=0,n=0;for(let i of e)(await r.removeFromQueue(i.id)).deleted===!1?n+=1:t+=1;return{cleared:t,kept:n}},onSuccess:({cleared:r,kept:i})=>{t.invalidateQueries({queryKey:[`queue`]}),t.invalidateQueries({queryKey:[`batches`]}),n(i>0?`${e(`queue.toast.historyCleared`,{count:r})} ${e(`queue.toast.historyKeptForOrders`,{kept:i})}`:e(`queue.toast.historyCleared`,{count:r}))},onError:()=>n(e(`queue.toast.clearHistoryFailed`),`error`)}),pt=c({mutationFn:e=>r.bulkUpdateQueue(e),onSuccess:e=>{t.invalidateQueries({queryKey:[`queue`]}),ue([]),me(!1),n(e.message)},onError:()=>n(e(`queue.toast.updateFailed`),`error`)}),mt=c({mutationFn:async e=>{for(let t of e)await r.cancelQueueItem(t);return e.length},onSuccess:r=>{t.invalidateQueries({queryKey:[`queue`]}),ue([]),n(e(`queue.toast.bulkCancelled`,{count:r}))},onError:()=>n(e(`queue.toast.bulkCancelFailed`),`error`)}),ht=c({mutationFn:e=>r.resumeQueueAfterFailure(e),onSuccess:r=>{t.invalidateQueries({queryKey:[`queue`]}),_e(null),n(e(`queue.toast.resumedAfterFailure`,{restored:r.restored,acknowledged:r.acknowledged}))},onError:()=>n(e(`queue.toast.resumeAfterFailureFailed`),`error`)}),gt=c({mutationFn:e=>r.createBatch(e),onSuccess:r=>{t.invalidateQueries({queryKey:[`queue`]}),ue([]),Ue(!1),Pe(e=>({...e,[r.id]:!1})),n(e(`queue.toast.batchCreated`,{name:r.name}))},onError:()=>n(e(`queue.toast.batchCreateFailed`),`error`)}),vt=c({mutationFn:e=>r.ungroupBatch(e),onSuccess:r=>{t.invalidateQueries({queryKey:[`queue`]}),Y(null),n(e(`queue.toast.batchUngrouped`,{count:r.ungrouped_count}))},onError:()=>n(e(`queue.toast.batchUngroupFailed`),`error`)}),Q=e=>{ue(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},bt=(0,q.useMemo)(()=>{let e=new Set;return Qe?.forEach(t=>{t.location&&e.add(t.location)}),Z?.forEach(t=>{t.target_location&&e.add(t.target_location)}),Array.from(e).sort()},[Qe,Z]),Ct=(0,q.useCallback)(e=>E?e.target_location?e.target_location===E:e.printer_id?Qe?.find(t=>t.id===e.printer_id)?.location===E:!1:!0,[E,Qe]),$=(0,q.useMemo)(()=>{let e=Z?.filter(e=>e.status===`pending`)||[];E&&(e=e.filter(Ct));let t=e=>{if(!e.scheduled_time)return 0;let t=z(e.scheduled_time)?.getTime()??0;return t>Date.now()+4320*60*60*1e3?0:t};return X?.queue_shortest_first?[...e].sort((e,t)=>et(e,t,!0)):[...e].sort((e,n)=>{let r;if(U===`name`){let t=e.archive_name||e.library_file_name||``,i=n.archive_name||n.library_file_name||``;r=t.localeCompare(i)}else r=U===`printer`?(e.printer_name||``).localeCompare(n.printer_name||``):U===`time`?t(e)-t(n):e.position-n.position;return Te?r:-r})},[Z,U,Te,Ct,E,X?.queue_shortest_first]),Dt=()=>{let e=$.map(e=>e.id);L.length===e.length?ue([]):ue(e)},Ot=(0,q.useMemo)(()=>{let e=Z?.filter(e=>e.status===`printing`)||[];return E&&(e=e.filter(Ct)),e},[Z,E,Ct]),kt=(0,q.useMemo)(()=>{let e=new Set;if(!Z)return e;let t=new Set;Z.forEach(e=>{e.status===`printing`&&e.printer_id&&t.add(e.printer_id)});let n=e=>e.scheduled_time?(z(e.scheduled_time)?.getTime()??0)>Date.now():!1,r=(e,t)=>et(e,t,X?.queue_shortest_first??!1),i=new Map;return Z.filter(e=>e.status===`pending`&&e.printer_id!=null&&!e.manual_start&&!n(e)).sort(r).forEach(e=>{let t=i.get(e.printer_id)??[];t.push(e),i.set(e.printer_id,t)}),Z.forEach(r=>{if(r.status===`pending`&&!r.waiting_reason&&!n(r)&&!(r.print_time_seconds==null||r.print_time_seconds<=0)&&!r.require_previous_success){if(r.printer_id==null){e.add(r.id);return}if(!t.has(r.printer_id)){if(r.manual_start){e.add(r.id);return}i.get(r.printer_id)?.[0]?.id===r.id&&e.add(r.id)}}}),e},[Z,X?.queue_shortest_first]),[At,jt]=(0,q.useState)(()=>Date.now()),Mt=kt.size>0;(0,q.useEffect)(()=>{if(!Mt)return;jt(Date.now());let e=setInterval(()=>jt(Date.now()),3e4);return()=>clearInterval(e)},[Mt]);let Nt=(0,q.useMemo)(()=>{let e=new Set;return Ot.forEach(t=>{t.printer_id&&e.add(t.printer_id)}),Array.from(e)},[Ot]),Pt=l({queries:Nt.map(e=>({queryKey:[`printerStatus`,e],queryFn:()=>r.getPrinterStatus(e),refetchInterval:5e3}))}),Ft=(0,q.useMemo)(()=>{let e={};return Nt.forEach((t,n)=>{let r=Pt[n];r?.data?.state&&(e[t]=r.data.state)}),e},[Nt,Pt]),It=(0,q.useMemo)(()=>{let e={};return Nt.forEach((t,n)=>{let r=Pt[n];r?.data&&(e[t]={progress:r.data.progress??void 0,remaining_time:r.data.remaining_time??void 0,state:r.data.state??void 0})}),e},[Nt,Pt]),Lt=(0,q.useMemo)(()=>{let e=Z?.filter(e=>[`completed`,`failed`,`skipped`,`cancelled`].includes(e.status))||[];return E&&(e=e.filter(Ct)),[...e].sort((e,t)=>{let n;if(B===`name`){let r=e.archive_name||e.library_file_name||``,i=t.archive_name||t.library_file_name||``;n=r.localeCompare(i)}else n=B===`printer`?(e.printer_name||``).localeCompare(t.printer_name||``):(z(t.completed_at||t.created_at)?.getTime()??0)-(z(e.completed_at||e.created_at)?.getTime()??0);return V?-n:n})},[Z,B,V,Ct,E]),Rt=(0,q.useMemo)(()=>$.reduce((e,t)=>e+(t.print_time_seconds||0),0),[$]),zt=(0,q.useMemo)(()=>$.reduce((e,t)=>e+(t.filament_used_grams||0),0),[$]),Bt=e=>{let t=e.active.id;Be(typeof t==`number`||typeof t==`string`?t:null)},Vt=e=>{let{active:t,over:n}=e;if(Be(null),!n||t.id===n.id)return;let r,i=t.id;if(typeof i==`string`&&i.startsWith(`batch-`)){let e=Number(i.slice(6));r=$.filter(t=>t.batch_id===e).map(e=>e.id)}else{let e=i;r=L.includes(e)&&L.length>1?L.slice().sort((e,t)=>$.findIndex(t=>t.id===e)-$.findIndex(e=>e.id===t)):[e]}if(r.length===0)return;let a,o=n.id;if(typeof o==`string`&&o.startsWith(`batch-`)){let e=Number(o.slice(6));a=$.findIndex(t=>t.batch_id===e)}else a=$.findIndex(e=>e.id===o);if(a===-1)return;let s=$[a],c=$.filter(e=>!r.includes(e.id)),l=c.findIndex(e=>e.id===s.id);l===-1&&(l=a),$.findIndex(e=>e.id===r[0])$.find(t=>t.id===e)).filter(e=>!!e),...c.slice(l)].map((e,t)=>({id:e.id,position:t+1}));dt.mutate(u)},Ht=(0,q.useMemo)(()=>{let t=[],n=new Set;for(let r of $)if(r.batch_id!=null){if(n.has(r.batch_id))continue;n.add(r.batch_id);let i=$.filter(e=>e.batch_id===r.batch_id);t.push({kind:`batch`,batchId:r.batch_id,batchName:r.batch_name||e(`queue.batch.defaultName`),items:i})}else t.push({kind:`item`,item:r});return t},[$,e]),Ut=u(`queue:reorder`)&&U===`position`&&!X?.queue_shortest_first,Wt=e=>e.kind===`item`?[e.item.id]:e.items.map(e=>e.id),Gt=(e,t,n)=>{let r=$.filter(t=>!e.includes(t.id)),i=r.findIndex(e=>e.id===t);if(i===-1)return;n&&(i+=1);let a=e.map(e=>$.find(t=>t.id===e)).filter(e=>!!e),o=[...r.slice(0,i),...a,...r.slice(i)];dt.mutate(o.map((e,t)=>({id:e.id,position:t+1})))},Kt=(e,t)=>{if(!Ut)return{};let n=Wt(e[t]);return{onMoveUp:t>0?()=>Gt(n,Wt(e[t-1])[0],!1):void 0,onMoveDown:t{let r=Wt(e[t+1]);Gt(n,r[r.length-1],!0)}:void 0}},qt=(0,q.useMemo)(()=>{let e=[];for(let t of Ht)if(t.kind===`item`)e.push(t.item.id);else if(e.push(`batch-${t.batchId}`),!(K[t.batchId]??!0))for(let n of t.items)e.push(n.id);return e},[Ht,K]),Jt=(0,q.useMemo)(()=>L.length<2?!1:L.every(e=>{let t=$.find(t=>t.id===e);return t&&t.batch_id==null}),[L,$]),Yt=e=>{Pe(t=>({...t,[e]:!(t[e]??!0)}))},Xt=(0,q.useMemo)(()=>{let t=new Map,n=t=>{if(t.printer_id)return{key:`printer:${t.printer_id}`,label:t.printer_name||`Printer #${t.printer_id}`,printerId:t.printer_id,targetModel:null,isUnassigned:!1};if((t.variants?.length??0)>1){let n=t.variants.map(e=>e.target_model).join(` / `);return{key:`models:${n}`,label:`${e(`queue.filter.any`)} ${n}`,printerId:null,targetModel:null,isUnassigned:!1}}return t.target_model?{key:`model:${t.target_model}`,label:`${e(`queue.filter.any`)} ${t.target_model}`,printerId:null,targetModel:t.target_model,isUnassigned:!1}:{key:`unassigned`,label:e(`queue.filter.unassigned`),printerId:null,targetModel:null,isUnassigned:!0}};for(let e of Ht){let r=e.kind===`item`?e.item:e.items[0];if(!r)continue;let i=n(r);t.has(i.key)||t.set(i.key,{...i,rows:[]}),t.get(i.key).rows.push(e)}return Array.from(t.values()).sort((e,t)=>e.isUnassigned&&!t.isUnassigned?1:!e.isUnassigned&&t.isUnassigned?-1:e.label.localeCompare(t.label))},[Ht,e]),Zt=(0,q.useMemo)(()=>{let e=new Map;return Z?.forEach(t=>{if(t.status===`skipped`&&t.error_message===`Previous print failed or was aborted`&&t.printer_id){let n=e.get(t.printer_id);n?n.count+=1:e.set(t.printer_id,{name:t.printer_name||`Printer #${t.printer_id}`,count:1})}}),Array.from(e.entries()).map(([e,{name:t,count:n}])=>({printerId:e,printerName:t,skippedCount:n})).sort((e,t)=>e.printerName.localeCompare(t.printerName))},[Z]),Qt=e=>{let t=0,n=0,r=0;for(let i of e){let e=i.kind===`item`?[i.item]:i.items;for(let i of e)t+=1,n+=i.print_time_seconds||0,r+=i.filament_used_grams||0}return{count:t,time:n,weight:r}};return(0,J.jsxs)(`div`,{className:`p-4 md:p-8`,children:[(0,J.jsx)(`div`,{className:`flex items-center justify-between mb-6`,children:(0,J.jsxs)(`div`,{children:[(0,J.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,J.jsx)(Ne,{className:`w-7 h-7 text-bambu-green`}),e(`queue.title`)]}),(0,J.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:e(`queue.subtitle`)})]})}),(0,J.jsx)(`div`,{className:`flex gap-1 border-b border-bambu-dark-tertiary mb-6 overflow-x-auto`,children:[{id:`queue`,label:e(`queue.tabs.queue`),icon:H,count:$.length+Ot.length},{id:`batches`,label:e(`queue.tabs.batches`),icon:N,count:Ye},{id:`history`,label:e(`queue.tabs.history`),icon:Ne,count:Lt.length},{id:`timeline`,label:e(`queue.tabs.timeline`),icon:Re,count:null},{id:`pipelines`,label:e(`queue.tabs.pipelines`),icon:se,count:null}].map(({id:e,label:t,icon:n,count:r})=>(0,J.jsxs)(`button`,{onClick:()=>Ae(e),className:`px-4 py-2.5 text-sm flex items-center gap-2 border-b-2 -mb-px transition-colors whitespace-nowrap ${G===e?`text-white border-bambu-green font-medium`:`text-bambu-gray border-transparent hover:text-white`}`,children:[(0,J.jsx)(n,{className:`w-4 h-4`}),t,r!==null&&r>0&&(0,J.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded-full ${G===e?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark-tertiary text-bambu-gray`}`,children:r})]},e))}),G!==`pipelines`&&G!==`batches`&&(0,J.jsx)(Xe,{activeCount:Ot.length,pendingCount:$.length,totalTime:Rt,totalWeight:zt,historyCount:Lt.length,t:e}),G===`queue`&&Zt.length>0&&u(`queue:update_all`)&&(0,J.jsx)(`div`,{className:`mb-4 space-y-2`,children:Zt.map(({printerId:t,printerName:n,skippedCount:r})=>(0,J.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-3 bg-orange-50 dark:bg-orange-500/10 border border-orange-300 dark:border-orange-500/30 rounded-lg`,children:[(0,J.jsx)(D,{className:`w-5 h-5 text-orange-600 dark:text-orange-400 flex-shrink-0`}),(0,J.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,J.jsx)(`div`,{className:`text-sm text-orange-800 dark:text-orange-200`,children:e(`queue.resumeAfterFailure.banner`,{printer:n,count:r})}),(0,J.jsx)(`div`,{className:`text-xs text-orange-800/80 dark:text-orange-200/70 mt-0.5`,children:e(`queue.resumeAfterFailure.bannerHint`)})]}),(0,J.jsxs)(`button`,{onClick:()=>_e({printerId:t,printerName:n,skippedCount:r}),className:`flex items-center gap-1.5 px-3 py-1.5 bg-orange-100 dark:bg-orange-500/20 hover:bg-orange-200 dark:hover:bg-orange-500/30 text-orange-900 dark:text-orange-100 text-sm rounded-md border border-orange-300 dark:border-orange-500/40 transition-colors flex-shrink-0`,children:[(0,J.jsx)(ze,{className:`w-4 h-4`}),e(`queue.resumeAfterFailure.button`)]})]},t))}),G!==`pipelines`&&G!==`batches`&&(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 sm:gap-4 mb-6`,children:[(0,J.jsxs)(`select`,{className:`px-2 sm:px-3 py-2 text-sm sm:text-base bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none min-w-0 flex-1 sm:flex-none`,value:b===-1?`unassigned`:b||``,onChange:e=>{let t=e.target.value;ne(t===`unassigned`?-1:t===``?null:Number(t))},children:[(0,J.jsx)(`option`,{value:``,children:e(`queue.filter.allPrinters`)}),(0,J.jsx)(`option`,{value:`unassigned`,children:e(`queue.filter.unassigned`)}),Qe?.map(e=>(0,J.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,J.jsxs)(`select`,{className:`px-2 sm:px-3 py-2 text-sm sm:text-base bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none min-w-0 flex-1 sm:flex-none`,value:T,onChange:e=>re(e.target.value),children:[(0,J.jsx)(`option`,{value:``,children:e(`queue.filter.allStatus`)}),(0,J.jsx)(`option`,{value:`pending`,children:e(`queue.status.pending`)}),(0,J.jsx)(`option`,{value:`printing`,children:e(`queue.status.printing`)}),(0,J.jsx)(`option`,{value:`completed`,children:e(`queue.status.completed`)}),(0,J.jsx)(`option`,{value:`failed`,children:e(`queue.status.failed`)}),(0,J.jsx)(`option`,{value:`skipped`,children:e(`queue.status.skipped`)}),(0,J.jsx)(`option`,{value:`cancelled`,children:e(`queue.status.cancelled`)})]}),bt.length>0&&(0,J.jsxs)(`select`,{className:`px-2 sm:px-3 py-2 text-sm sm:text-base bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none min-w-0 flex-1 sm:flex-none`,value:E,onChange:e=>k(e.target.value),children:[(0,J.jsx)(`option`,{value:``,children:e(`queue.filter.allLocations`)}),bt.map(e=>(0,J.jsx)(`option`,{value:e,children:e},e))]}),(0,J.jsx)(`div`,{className:`hidden sm:block flex-1`}),G===`history`&&Lt.length>0&&(0,J.jsxs)(R,{className:`w-full sm:w-auto`,variant:`secondary`,size:`sm`,onClick:()=>j(!0),disabled:!u(`queue:delete_all`),title:u(`queue:delete_all`)?void 0:e(`queue.permissions.noClearHistory`),children:[(0,J.jsx)(he,{className:`w-4 h-4`}),e(`queue.clearHistory`)]})]}),G===`queue`&&(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 mb-6`,children:[(0,J.jsxs)(`div`,{className:`inline-flex items-center bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg p-0.5`,children:[(0,J.jsxs)(`button`,{className:`px-3 py-1.5 text-xs sm:text-sm rounded-md transition-colors flex items-center gap-1.5 ${je===`position`?`bg-bambu-dark-tertiary text-white`:`text-bambu-gray hover:text-white`}`,onClick:()=>Me(`position`),title:e(`queue.layout.flatList`),children:[(0,J.jsx)(ie,{className:`w-3.5 h-3.5`}),(0,J.jsx)(`span`,{className:`hidden sm:inline`,children:e(`queue.layout.flatList`)})]}),(0,J.jsxs)(`button`,{className:`px-3 py-1.5 text-xs sm:text-sm rounded-md transition-colors flex items-center gap-1.5 ${je===`printer`?`bg-bambu-dark-tertiary text-white`:`text-bambu-gray hover:text-white`}`,onClick:()=>Me(`printer`),title:e(`queue.layout.groupByPrinter`),children:[(0,J.jsx)(ye,{className:`w-3.5 h-3.5`}),(0,J.jsx)(`span`,{className:`hidden sm:inline`,children:e(`queue.layout.byPrinter`)})]})]}),(0,J.jsxs)(`button`,{onClick:()=>{let e=!(X?.queue_shortest_first??!1);$e.mutate(e)},className:`flex items-center gap-1 px-2 py-1.5 text-xs rounded-lg border transition-colors ${X?.queue_shortest_first?`bg-bambu-green/20 border-bambu-green text-bambu-green`:`bg-bambu-dark-secondary border-bambu-dark-tertiary text-bambu-gray hover:text-white hover:border-bambu-gray`}`,title:e(`queue.sjf.tooltip`,`Shortest Job First — scheduler prioritizes shorter prints`),children:[(0,J.jsx)(He,{className:`w-4 h-4`}),(0,J.jsx)(`span`,{className:`hidden sm:inline`,children:e(`queue.sjf.label`,`SJF`)}),(0,J.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full ${X?.queue_shortest_first?`bg-bambu-green`:`bg-bambu-gray`}`})]})]}),G===`pipelines`?(0,J.jsx)(Ge,{}):G===`batches`?(0,J.jsx)(ut,{hasPermission:u,t:e,focusBatchId:ke}):Ze?(0,J.jsx)(`div`,{className:`text-center py-12 text-bambu-gray`,children:e(`common.loading`)}):Z?.length===0?(0,J.jsxs)(le,{className:`p-12 text-center border-dashed`,children:[(0,J.jsx)(w,{className:`w-16 h-16 text-bambu-gray mx-auto mb-4 opacity-50`}),(0,J.jsx)(`h3`,{className:`text-xl font-medium text-white mb-2`,children:e(`queue.empty.title`)}),(0,J.jsx)(`p`,{className:`text-bambu-gray max-w-md mx-auto`,children:e(`queue.empty.description`)})]}):G===`timeline`?(0,J.jsx)(lt,{queueItems:Z||[],printers:Qe||[],printerStatuses:It,sjfEnabled:X?.queue_shortest_first??!1,onItemClick:e=>{[`completed`,`failed`,`skipped`,`cancelled`].includes(e.status)?oe(e):e.status===`pending`?ae(e):e.status===`printing`&&I({type:`stop`,item:e})},t:e}):G===`history`?(0,J.jsx)(wt,{items:Lt,collapsed:!1,visibleCount:Se,onShowMore:()=>Ce(e=>e+Tt),sortBy:B,sortAsc:V,onSortByChange:ve,onSortAscToggle:()=>xe(!V),onRemove:e=>I({type:`remove`,item:e}),onRequeue:oe,timeFormat:qe,batchCollapsed:K,toggleBatchCollapsed:Yt,hasPermission:u,canModify:_,t:e}):(0,J.jsxs)(`div`,{className:`space-y-6 sm:space-y-8`,children:[Ot.length>0&&(0,J.jsxs)(`div`,{children:[(0,J.jsxs)(`h2`,{className:`text-base sm:text-lg font-semibold text-white mb-3 sm:mb-4 flex items-center gap-2`,children:[(0,J.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-blue-400 animate-pulse`}),e(`queue.sections.currentlyPrinting`)]}),(0,J.jsx)(`div`,{className:`space-y-2 sm:space-y-3`,children:Ot.map(t=>(0,J.jsx)(xt,{item:t,onEdit:()=>{},onCancel:()=>{},onRemove:()=>{},onStop:()=>I({type:`stop`,item:t}),onRequeue:()=>{},onStart:()=>{},timeFormat:qe,hasPermission:u,canModify:_,printerState:t.printer_id?Ft[t.printer_id]:null,t:e},t.id))})]}),$.length>0&&(0,J.jsxs)(`div`,{children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2 mb-3 sm:mb-4`,children:[(0,J.jsxs)(`h2`,{className:`text-base sm:text-lg font-semibold text-white flex items-center gap-2`,children:[(0,J.jsx)(H,{className:`w-4 h-4 sm:w-5 sm:h-5 text-yellow-600 dark:text-yellow-400`}),e(`queue.sections.queued`),(0,J.jsxs)(`span`,{className:`text-xs sm:text-sm font-normal text-bambu-gray`,children:[`(`,e(`queue.itemCount`,{count:$.length}),`)`]}),(0,J.jsx)(`span`,{className:`hidden sm:inline text-xs text-bambu-gray ml-2`,title:e(`queue.reorderHint`),children:e(`queue.dragToReorder`)})]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsxs)(`select`,{className:`px-2 sm:px-3 py-1.5 text-xs sm:text-sm bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,value:U,onChange:e=>W(e.target.value),children:[(0,J.jsx)(`option`,{value:`position`,children:e(`queue.sort.byPosition`)}),(0,J.jsx)(`option`,{value:`name`,children:e(`queue.sort.byName`)}),(0,J.jsx)(`option`,{value:`printer`,children:e(`queue.sort.byPrinter`)}),(0,J.jsx)(`option`,{value:`time`,children:e(`queue.sort.bySchedule`)})]}),(0,J.jsx)(R,{variant:`ghost`,size:`sm`,onClick:()=>De(!Te),title:e(Te?`common.ascending`:`common.descending`),className:`px-2`,children:Te?(0,J.jsx)(f,{className:`w-4 h-4`}):(0,J.jsx)(d,{className:`w-4 h-4`})})]})]}),(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 sm:gap-3 mb-3 sm:mb-4 p-2 sm:p-3 bg-bambu-dark rounded-lg`,children:[(0,J.jsxs)(R,{variant:`ghost`,size:`sm`,onClick:Dt,className:`flex items-center gap-1.5 sm:gap-2 text-xs sm:text-sm`,children:[L.length===$.length&&$.length>0?(0,J.jsx)(we,{className:`w-4 h-4 text-bambu-green`}):(0,J.jsx)(be,{className:`w-4 h-4`}),L.length===$.length&&$.length>0?e(`queue.bulkEdit.deselectAll`):e(`queue.bulkEdit.selectAll`)]}),L.length>0&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`span`,{className:`text-xs sm:text-sm text-bambu-gray`,children:e(`queue.bulkEdit.selected`,{count:L.length})}),(0,J.jsx)(`div`,{className:`hidden sm:block h-4 w-px bg-bambu-dark-tertiary`}),Jt&&(0,J.jsxs)(R,{variant:`ghost`,size:`sm`,onClick:()=>Ue(!0),className:`flex items-center gap-1.5 sm:gap-2 text-xs sm:text-sm text-cyan-700 dark:text-cyan-300 hover:text-cyan-900 dark:hover:text-cyan-200`,title:e(`queue.batch.groupAsBatch`),children:[(0,J.jsx)(N,{className:`w-3.5 h-3.5 sm:w-4 sm:h-4`}),(0,J.jsx)(`span`,{className:`hidden sm:inline`,children:e(`queue.batch.groupAsBatch`)})]}),(0,J.jsxs)(R,{variant:`ghost`,size:`sm`,onClick:()=>me(!0),className:`flex items-center gap-1.5 sm:gap-2 text-xs sm:text-sm text-bambu-green hover:text-bambu-green-light`,disabled:!p(`queue:update_own`,`queue:update_all`),title:p(`queue:update_own`,`queue:update_all`)?e(`queue.bulkEdit.editSelected`):e(`queue.permissions.noEditItems`),children:[(0,J.jsx)(pe,{className:`w-3.5 h-3.5 sm:w-4 sm:h-4`}),(0,J.jsx)(`span`,{className:`hidden sm:inline`,children:e(`queue.bulkEdit.editSelected`)})]}),(0,J.jsxs)(R,{variant:`ghost`,size:`sm`,onClick:()=>mt.mutate(L),className:`flex items-center gap-1.5 sm:gap-2 text-xs sm:text-sm text-red-600 dark:text-red-400 hover:text-red-700 dark:hover:text-red-300`,disabled:mt.isPending||!p(`queue:delete_own`,`queue:delete_all`),title:p(`queue:delete_own`,`queue:delete_all`)?e(`queue.bulkEdit.cancelSelected`):e(`queue.permissions.noCancelItems`),children:[(0,J.jsx)(ce,{className:`w-3.5 h-3.5 sm:w-4 sm:h-4`}),(0,J.jsx)(`span`,{className:`hidden sm:inline`,children:e(`queue.bulkEdit.cancelSelected`)})]})]})]}),(0,J.jsxs)(ee,{sensors:Ke,collisionDetection:h,onDragStart:Bt,onDragEnd:Vt,children:[(0,J.jsx)(C,{items:qt,strategy:x,children:je===`position`?(0,J.jsx)(`div`,{className:`space-y-2 sm:space-y-3`,children:Ht.map((t,n)=>(0,J.jsx)(St,{row:t,collapsed:t.kind===`batch`?K[t.batchId]??!0:!1,onToggleBatch:t.kind===`batch`?()=>Yt(t.batchId):void 0,onUngroup:t.kind===`batch`?()=>Y(t.batchId):void 0,setEditItem:ae,setConfirmAction:I,startMutation:ct,selectedItems:L,handleToggleSelect:Q,timeFormat:qe,hasPermission:u,canModify:_,t:e,etaEligibleIds:kt,etaNow:At,aggregateForRows:Qt,...Kt(Ht,n),onMoveBlock:Ut?Gt:void 0},t.kind===`item`?`item-${t.item.id}`:`batch-${t.batchId}`))}):(0,J.jsx)(`div`,{className:`space-y-4`,children:Xt.map(t=>{let n=Qt(t.rows);return(0,J.jsxs)(`div`,{children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-3 px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-t-lg`,children:[(0,J.jsx)(ye,{className:`w-4 h-4 ${t.isUnassigned?`text-orange-600 dark:text-orange-400`:t.targetModel?`text-blue-600 dark:text-blue-400`:`text-bambu-green`}`}),(0,J.jsx)(`span`,{className:`font-semibold text-white text-sm`,children:t.label}),(0,J.jsxs)(`span`,{className:`text-xs text-bambu-gray flex flex-wrap gap-x-3`,children:[(0,J.jsx)(`span`,{children:e(`queue.itemCount`,{count:n.count})}),n.time>0&&(0,J.jsx)(`span`,{children:de(n.time)}),n.weight>0&&(0,J.jsx)(`span`,{children:_t(n.weight)})]})]}),(0,J.jsx)(`div`,{className:`bg-bambu-dark/40 border border-t-0 border-bambu-dark-tertiary rounded-b-lg p-2 space-y-2`,children:t.rows.map((n,r)=>(0,J.jsx)(St,{row:n,collapsed:n.kind===`batch`?K[n.batchId]??!0:!1,onToggleBatch:n.kind===`batch`?()=>Yt(n.batchId):void 0,onUngroup:n.kind===`batch`?()=>Y(n.batchId):void 0,setEditItem:ae,setConfirmAction:I,startMutation:ct,selectedItems:L,handleToggleSelect:Q,timeFormat:qe,hasPermission:u,canModify:_,t:e,etaEligibleIds:kt,etaNow:At,aggregateForRows:Qt,...Kt(t.rows,r),onMoveBlock:Ut?Gt:void 0},n.kind===`item`?`item-${n.item.id}`:`batch-${n.batchId}`))})]},t.key)})})}),(0,J.jsx)(m,{children:(()=>{if(Fe===null)return null;if(typeof Fe==`string`&&Fe.startsWith(`batch-`)){let t=Number(Fe.slice(6)),n=$.filter(e=>e.batch_id===t);if(n.length===0)return null;let r=n[0].batch_name||e(`queue.batch.defaultName`);return(0,J.jsxs)(`div`,{className:`flex items-center gap-3 px-3 py-2 bg-bambu-dark-secondary border-2 border-cyan-400 rounded-lg shadow-2xl`,children:[(0,J.jsx)(N,{className:`w-4 h-4 text-cyan-700 dark:text-cyan-300`}),(0,J.jsx)(`span`,{className:`text-sm text-white font-medium`,children:e(`queue.dragGhost.batch`,{defaultValue:`{{name}} ({{count}} copies)`,name:r,count:n.length})})]})}return typeof Fe==`number`&&L.includes(Fe)&&L.length>1?(0,J.jsxs)(`div`,{className:`flex items-center gap-3 px-3 py-2 bg-bambu-dark-secondary border-2 border-cyan-400 rounded-lg shadow-2xl`,children:[(0,J.jsx)(N,{className:`w-4 h-4 text-cyan-700 dark:text-cyan-300`}),(0,J.jsx)(`span`,{className:`text-sm text-white font-medium`,children:e(`queue.dragGhost.multiCount`,{count:L.length})})]}):null})()})]})]})]}),M&&(0,J.jsx)(Oe,{mode:`edit-queue-item`,archiveId:M.archive_id??void 0,libraryFileId:M.library_file_id??void 0,archiveName:Le(M,t=>e(`common.plusNMore`,{count:t})),queueItem:M,onClose:()=>ae(null)}),P&&(0,J.jsx)(Oe,{mode:`create`,archiveId:P.archive_id??void 0,libraryFileId:P.library_file_id??void 0,archiveName:Le(P,t=>e(`common.plusNMore`,{count:t})),onClose:()=>oe(null)}),it&&(0,J.jsx)(Ee,{title:e(`queue.filamentShort.confirmTitle`),message:e(`queue.filamentShort.confirmIntro`)+` + `,onClick:Oe?()=>{window.innerWidth<640&&h()}:void 0,children:[Oe&&m&&(0,J.jsx)(`div`,{className:`sm:hidden absolute left-0 top-3 bottom-3 w-1 rounded-full bg-bambu-green`}),(0,J.jsxs)(`div`,{className:`flex items-start sm:items-center gap-2 sm:gap-4 p-3 sm:p-4`,children:[W&&(u||d)&&(0,J.jsxs)(`div`,{className:`flex sm:hidden flex-col shrink-0 -my-1`,onClick:e=>e.stopPropagation(),children:[(0,J.jsx)(`button`,{type:`button`,onClick:u,disabled:!u,title:S(`queue.moveUp`),"aria-label":S(`queue.moveUp`),className:`flex items-center justify-center w-8 h-7 rounded-lg text-bambu-gray hover:text-white hover:bg-bambu-dark disabled:opacity-25 disabled:hover:bg-transparent transition-colors`,children:(0,J.jsx)(re,{className:`w-5 h-5`})}),(0,J.jsx)(`button`,{type:`button`,onClick:d,disabled:!d,title:S(`queue.moveDown`),"aria-label":S(`queue.moveDown`),className:`flex items-center justify-center w-8 h-7 rounded-lg text-bambu-gray hover:text-white hover:bg-bambu-dark disabled:opacity-25 disabled:hover:bg-transparent transition-colors`,children:(0,J.jsx)(T,{className:`w-5 h-5`})})]}),W&&h&&(0,J.jsx)(`button`,{onClick:e=>{e.stopPropagation(),h()},className:`hidden sm:flex items-center justify-center w-6 h-6 rounded border transition-colors shrink-0 ${m?`bg-bambu-green border-bambu-green text-white`:`border-white/30 bg-black/30 hover:border-bambu-green/50`}`,children:m&&(0,J.jsx)(ne,{className:`w-4 h-4`})}),W?(0,J.jsx)(`div`,{...L,...se,className:`hidden sm:flex items-center justify-center w-8 h-8 rounded-lg bg-bambu-dark cursor-grab active:cursor-grabbing hover:bg-bambu-dark-tertiary transition-colors touch-none shrink-0`,children:(0,J.jsx)(M,{className:`w-4 h-4 text-bambu-gray`})}):t===void 0?(0,J.jsx)(`div`,{className:`hidden sm:block w-8 shrink-0`}):(0,J.jsxs)(`div`,{className:`hidden sm:flex items-center justify-center w-8 h-8 rounded-lg bg-bambu-dark text-bambu-gray text-sm font-medium shrink-0`,children:[`#`,t]}),(0,J.jsx)(`div`,{className:`w-10 h-10 sm:w-14 sm:h-14 flex-shrink-0 bg-bambu-dark rounded-lg overflow-hidden`,children:e.archive_thumbnail?(0,J.jsx)(`img`,{src:e.plate_id==null?r.getArchiveThumbnail(e.archive_id):r.getArchivePlateThumbnail(e.archive_id,e.plate_id),alt:``,className:`w-full h-full object-cover`}):e.library_file_thumbnail?(0,J.jsx)(`img`,{src:e.plate_id==null?r.getLibraryFileThumbnailUrl(e.library_file_id):r.getLibraryFilePlateThumbnail(e.library_file_id,e.plate_id),alt:``,className:`w-full h-full object-cover`}):(0,J.jsx)(`div`,{className:`w-full h-full flex items-center justify-center text-bambu-gray`,children:(0,J.jsx)(ke,{className:`w-5 h-5 sm:w-6 sm:h-6`})})}),(0,J.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,J.jsxs)(`p`,{className:`text-sm sm:text-base text-white font-medium truncate`,children:[Le(e,e=>S(`common.plusNMore`,{count:e})),(ae?.is_multi_plate??!1)&&e.plate_id!==void 0&&e.plate_id!==null&&` • ${N.find(t=>t.index===e.plate_id)?.name||S(`queue.plateNumber`,{index:e.plate_id})}`]}),e.archive_id?(0,J.jsx)(Ce,{to:`/archives?highlight=${e.archive_id}`,className:`text-bambu-gray hover:text-bambu-green transition-colors flex-shrink-0`,title:S(`queue.viewArchive`),children:(0,J.jsx)(ge,{className:`w-3.5 h-3.5`})}):e.library_file_id?(0,J.jsx)(Ce,{to:`/library?highlight=${e.library_file_id}`,className:`text-bambu-gray hover:text-bambu-green transition-colors flex-shrink-0`,title:S(`queue.viewInFileManager`),children:(0,J.jsx)(ge,{className:`w-3.5 h-3.5`})}):null,e.batch_name&&(0,J.jsx)(`span`,{className:`flex-shrink-0 px-1.5 py-0.5 text-[10px] sm:text-xs bg-cyan-100 dark:bg-cyan-500/20 text-cyan-700 dark:text-cyan-300 rounded border border-cyan-300 dark:border-cyan-500/30`,children:e.batch_name})]}),(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-xs sm:text-sm text-bambu-gray`,children:[(0,J.jsxs)(`span`,{className:`flex items-center gap-1 sm:gap-1.5 ${e.printer_id===null&&!e.target_model?`text-orange-700 dark:text-orange-400`:``} ${e.target_model&&!e.printer_id?`text-blue-700 dark:text-blue-400`:``}`,children:[(0,J.jsx)(ye,{className:`w-3 h-3 sm:w-3.5 sm:h-3.5`}),(0,J.jsx)(`span`,{className:`truncate max-w-[120px] sm:max-w-none`,children:(e.variants?.length??0)>1&&!e.printer_id?`${S(`queue.filter.any`)} ${e.variants.map(e=>e.target_model).join(` / `)}${e.target_location?` @ ${e.target_location}`:``}`:e.target_model&&!e.printer_id?`${S(`queue.filter.any`)} ${e.target_model}${e.target_location?` @ ${e.target_location}`:``}${e.required_filament_types?.length?` (${e.required_filament_types.join(`, `)})`:``}`:e.printer_id===null?S(`queue.filter.unassigned`):e.printer_name||`${S(`common.printer`)} #${e.printer_id}`})]}),e.print_time_seconds&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1 sm:gap-1.5`,children:[(0,J.jsx)(I,{className:`w-3 h-3 sm:w-3.5 sm:h-3.5`}),de(e.print_time_seconds)]}),De&&(0,J.jsxs)(`span`,{"data-testid":`queue-item-eta`,className:`text-bambu-green font-medium`,title:S(`queue.time.etaIfStartedNow`),children:[`ETA `,De]}),e.filament_used_grams&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1 sm:gap-1.5`,children:[(0,J.jsx)(Pe,{className:`w-3 h-3 sm:w-3.5 sm:h-3.5`}),vt(e.filament_used_grams)]}),P.length>2?(0,J.jsxs)(`span`,{"data-testid":`queue-filament-compact`,className:`flex items-center gap-0.5 flex-shrink-0`,title:P.map(gt).join(` +`),role:`img`,"aria-label":P.map(gt).join(`, `),children:[P.map(e=>(0,J.jsx)(K,{rgba:e.color,extraColors:e.extraColors,effectType:e.effectType,subtype:e.subtype,className:`w-2.5 h-2.5 sm:w-3 sm:h-3 pointer-events-none`,effectSize:`table`},`filament-${e.slotId}`)),P.some(e=>e.emptySlot)&&(0,J.jsx)(D,{className:`w-3 h-3 ml-0.5 text-yellow-700 dark:text-yellow-400`,"aria-hidden":`true`})]}):P.map(e=>{let t=gt(e);return(0,J.jsxs)(`span`,{className:`flex items-center gap-1 sm:gap-1.5 min-w-0`,title:t,children:[(0,J.jsx)(K,{rgba:e.color,extraColors:e.extraColors,effectType:e.effectType,subtype:e.subtype,className:`w-3 h-3 sm:w-3.5 sm:h-3.5`,effectSize:`table`}),(0,J.jsx)(`span`,{className:`truncate max-w-[110px] sm:max-w-[260px]${e.emptySlot?` text-yellow-700 dark:text-yellow-400`:``}`,children:t})]},`filament-${e.slotId}`)}),(()=>{let t=U(e.bed_type);return t?(0,J.jsxs)(`span`,{className:`flex items-center gap-1 sm:gap-1.5`,title:t.label,children:[(0,J.jsx)(`img`,{src:t.icon,alt:``,className:`w-3.5 h-3.5 sm:w-4 sm:h-4 object-contain`}),(0,J.jsx)(`span`,{className:`truncate max-w-[120px]`,children:t.label})]}):null})(),e.created_by_username&&(0,J.jsxs)(`span`,{className:`hidden sm:flex items-center gap-1.5`,title:S(`queue.addedBy`,{name:e.created_by_username}),children:[(0,J.jsx)(Se,{className:`w-3.5 h-3.5`}),e.created_by_username]}),W&&!e.manual_start&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,J.jsx)(H,{className:`w-3.5 h-3.5`}),e.scheduled_time?(z(e.scheduled_time)?.getTime()??0)-Date.now()<-6e4?S?.(`queue.time.overdue`)??`Overdue`:fe(e.scheduled_time,f,S):S?.(`queue.time.whenFree`)??`When a printer is free`]})]}),(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5 sm:gap-2 mt-1.5 sm:mt-2`,children:[e.manual_start&&(0,J.jsxs)(`span`,{className:`text-[10px] sm:text-xs px-1.5 sm:px-2 py-0.5 bg-purple-50 dark:bg-purple-500/10 text-purple-700 dark:text-purple-400 rounded-full border border-purple-200 dark:border-purple-500/20 flex items-center gap-1`,children:[(0,J.jsx)(Me,{className:`w-2.5 h-2.5 sm:w-3 sm:h-3`}),S(C?`queue.badges.awaitingReview`:`queue.badges.staged`)]}),e.require_previous_success&&(0,J.jsx)(`span`,{className:`text-[10px] sm:text-xs px-1.5 sm:px-2 py-0.5 bg-orange-50 dark:bg-orange-500/10 text-orange-700 dark:text-orange-400 rounded-full border border-orange-200 dark:border-orange-500/20`,children:S(`queue.badges.requiresPrevious`)}),e.auto_off_after&&(0,J.jsxs)(`span`,{className:`text-[10px] sm:text-xs px-1.5 sm:px-2 py-0.5 bg-blue-50 dark:bg-blue-500/10 text-blue-700 dark:text-blue-400 rounded-full border border-blue-200 dark:border-blue-500/20 flex items-center gap-1`,children:[(0,J.jsx)(Te,{className:`w-2.5 h-2.5 sm:w-3 sm:h-3`}),S(`queue.badges.autoPowerOff`)]}),e.gcode_injection&&(0,J.jsxs)(`span`,{className:`text-[10px] sm:text-xs px-1.5 sm:px-2 py-0.5 bg-emerald-50 dark:bg-emerald-500/10 text-emerald-700 dark:text-emerald-400 rounded-full border border-emerald-200 dark:border-emerald-500/20 flex items-center gap-1`,children:[(0,J.jsx)(_e,{className:`w-2.5 h-2.5 sm:w-3 sm:h-3`}),S(`queue.badges.gcodeInjection`)]}),e.confirm_outcome&&(0,J.jsxs)(`span`,{title:S(`queue.badges.confirmOutcomeTitle`),className:`text-[10px] sm:text-xs px-1.5 sm:px-2 py-0.5 bg-green-50 dark:bg-green-500/10 text-green-700 dark:text-green-400 rounded-full border border-green-200 dark:border-green-500/20 flex items-center gap-1`,children:[(0,J.jsx)(je,{className:`w-2.5 h-2.5 sm:w-3 sm:h-3`}),S(`queue.badges.confirmOutcome`)]})]}),we&&w&&(()=>{let e=w.state===`RUNNING`||w.state===`PAUSE`,t=e&&w.progress||0,n=e?w.remaining_time:null,r=e?w.layer_num:null,i=e?w.total_layers:null;return(0,J.jsxs)(`div`,{className:`mt-2 sm:mt-3`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between text-xs sm:text-sm`,children:[(0,J.jsx)(`div`,{className:`flex-1 bg-bambu-dark-tertiary rounded-full h-1.5 sm:h-2 mr-3`,children:(0,J.jsx)(`div`,{className:`bg-bambu-green h-1.5 sm:h-2 rounded-full transition-all`,style:{width:`${t}%`}})}),(0,J.jsxs)(`span`,{className:`text-white`,children:[Math.round(t),`%`]})]}),(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 sm:gap-3 mt-1.5 sm:mt-2 text-[10px] sm:text-xs text-bambu-gray`,children:[n!=null&&n>0&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,J.jsx)(H,{className:`w-3 h-3`}),de(n*60)]}),(0,J.jsxs)(`span`,{className:`text-bambu-green font-medium`,title:S(`printers.estimatedCompletion`),children:[`ETA `,ue(n,f,S)]})]}),r!=null&&i!=null&&i>0&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,J.jsx)(ke,{className:`w-3 h-3`}),r,`/`,i]})]})]})})(),e.waiting_reason&&e.status===`pending`&&(0,J.jsxs)(`p`,{className:`text-[10px] sm:text-xs text-purple-700 dark:text-purple-400 mt-1.5 sm:mt-2 flex items-start gap-1`,children:[(0,J.jsx)(D,{className:`w-3 h-3 mt-0.5 flex-shrink-0`}),(0,J.jsx)(`span`,{children:e.waiting_reason})]}),e.filament_short&&e.status===`pending`&&(0,J.jsxs)(`p`,{className:`text-[10px] sm:text-xs text-yellow-700 dark:text-yellow-400 mt-1.5 sm:mt-2 flex items-start gap-1`,title:S(`queue.filamentShort.rowTooltip`),children:[(0,J.jsx)(D,{className:`w-3 h-3 mt-0.5 flex-shrink-0`}),(0,J.jsx)(`span`,{children:S(`queue.filamentShort.rowBadge`)})]}),e.archive_has_slicer_ams_mapping&&(0,J.jsxs)(`p`,{className:`text-[10px] sm:text-xs text-green-700 dark:text-green-400 mt-1.5 sm:mt-2 flex items-start gap-1`,title:S(`queue.slicerAmsMapping.rowTooltip`),children:[(0,J.jsx)(ne,{className:`w-3 h-3 mt-0.5 flex-shrink-0`}),(0,J.jsx)(`span`,{children:S(`queue.slicerAmsMapping.rowBadge`)})]}),e.error_message&&(0,J.jsxs)(`p`,{className:`text-[10px] sm:text-xs text-red-700 dark:text-red-400 mt-1.5 sm:mt-2 flex items-center gap-1`,children:[(0,J.jsx)(D,{className:`w-3 h-3`}),e.error_message]})]}),(0,J.jsxs)(`div`,{className:`flex flex-col sm:flex-row items-end sm:items-center gap-2 sm:gap-1 shrink-0`,onClick:e=>e.stopPropagation(),children:[(0,J.jsx)(yt,{status:e.status,waitingReason:e.waiting_reason,printerState:v,t:S}),(0,J.jsxs)(`div`,{className:`flex items-center gap-0.5 sm:gap-1`,children:[we&&(0,J.jsx)(R,{variant:`ghost`,size:`sm`,onClick:o,disabled:!_(`queue`,`update`,e.created_by_id),title:_(`queue`,`update`,e.created_by_id)?S(`queue.actions.stopPrint`):S(`queue.permissions.noStopPrint`),className:`text-red-600 dark:text-red-400 hover:text-red-700 dark:hover:text-red-300 hover:bg-red-50 dark:hover:bg-red-500/10 p-1.5 sm:p-2`,children:(0,J.jsx)(Be,{className:`w-4 h-4`})}),W&&(0,J.jsxs)(J.Fragment,{children:[e.manual_start&&(0,J.jsx)(R,{variant:`ghost`,size:`sm`,onClick:l,disabled:C||!_(`queue`,`update`,e.created_by_id),title:C?S(`queue.permissions.awaitingReview`):_(`queue`,`update`,e.created_by_id)?S(`queue.actions.startPrint`):S(`queue.permissions.noStartPrint`),className:`text-bambu-green hover:text-bambu-green-light hover:bg-bambu-green/10 p-1.5 sm:p-2`,children:(0,J.jsx)(oe,{className:`w-4 h-4`})}),(0,J.jsx)(R,{variant:`ghost`,size:`sm`,onClick:n,disabled:!_(`queue`,`update`,e.created_by_id),title:_(`queue`,`update`,e.created_by_id)?S(`common.edit`):S(`queue.permissions.noEdit`),className:`p-1.5 sm:p-2`,children:(0,J.jsx)(pe,{className:`w-4 h-4`})}),(0,J.jsx)(R,{variant:`ghost`,size:`sm`,onClick:i,disabled:!_(`queue`,`delete`,e.created_by_id),title:_(`queue`,`delete`,e.created_by_id)?S(`common.cancel`):S(`queue.permissions.noCancel`),className:`text-red-600 dark:text-red-400 hover:text-red-700 dark:hover:text-red-300 hover:bg-red-50 dark:hover:bg-red-500/10 p-1.5 sm:p-2`,children:(0,J.jsx)(ce,{className:`w-4 h-4`})})]}),Ee&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(R,{variant:`ghost`,size:`sm`,onClick:c,disabled:!g(`queue:create`),title:g(`queue:create`)?S(`queue.actions.requeue`):S(`queue.permissions.noRequeue`),className:`text-bambu-green hover:text-bambu-green/80 hover:bg-bambu-green/10 p-1.5 sm:p-2`,children:(0,J.jsx)(V,{className:`w-4 h-4`})}),(0,J.jsx)(R,{variant:`ghost`,size:`sm`,onClick:a,disabled:!_(`queue`,`delete`,e.created_by_id),title:_(`queue`,`delete`,e.created_by_id)?S(`common.remove`):S(`queue.permissions.noRemove`),className:`p-1.5 sm:p-2`,children:(0,J.jsx)(he,{className:`w-4 h-4`})})]})]})]})]})]})}function Ct(e){let{row:t,setEditItem:n,setConfirmAction:r,startMutation:i,selectedItems:a,handleToggleSelect:o,timeFormat:s,hasPermission:c,canModify:l,t:u,etaEligibleIds:d,etaNow:f,onMoveUp:p,onMoveDown:m}=e;return t.kind===`item`?(0,J.jsx)(St,{item:t.item,onEdit:()=>n(t.item),onCancel:()=>r({type:`cancel`,item:t.item}),onRemove:()=>{},onStop:()=>{},onRequeue:()=>{},onStart:()=>i.mutate({id:t.item.id}),onMoveUp:p,onMoveDown:m,timeFormat:s,isSelected:a.includes(t.item.id),onToggleSelect:()=>o(t.item.id),hasPermission:c,canModify:l,showEta:d.has(t.item.id),etaNow:f,t:u}):(0,J.jsx)($,{...e})}function $({row:e,collapsed:t,onToggleBatch:n,onUngroup:r,setEditItem:i,setConfirmAction:a,startMutation:o,selectedItems:s,handleToggleSelect:c,timeFormat:l,hasPermission:u,canModify:d,t:f,etaEligibleIds:m,etaNow:h,aggregateForRows:g,onMoveUp:_,onMoveDown:v,onMoveBlock:y}){let x=e,S=u(`queue:reorder`),{attributes:ee,listeners:C,setNodeRef:te,transform:w,transition:E,isDragging:D}=p({id:`batch-${x.batchId}`,disabled:!S}),O={transform:b.Transform.toString(w),transition:E},k=g([x]),A=x.items.map(e=>e.id),j=A.length>0&&A.every(e=>s.includes(e)),ie=new Set(x.items.map(e=>e.status)),ae=ie.has(`failed`)?`failed`:ie.has(`printing`)?`printing`:`pending`,P=x.items.filter(e=>e.status===`pending`).length;return(0,J.jsxs)(`div`,{ref:te,style:O,className:`bg-bambu-dark-secondary rounded-xl border border-l-[3px] border-l-cyan-400 border-bambu-dark-tertiary overflow-hidden ${D?`opacity-50 scale-[1.01] shadow-xl z-50`:``}`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2 sm:gap-3 p-3 sm:p-4`,children:[S&&(_||v)&&(0,J.jsxs)(`div`,{className:`flex sm:hidden flex-col shrink-0 -my-1`,children:[(0,J.jsx)(`button`,{type:`button`,onClick:_,disabled:!_,title:f(`queue.moveUp`),"aria-label":f(`queue.moveUp`),className:`flex items-center justify-center w-8 h-7 rounded-lg text-bambu-gray hover:text-white hover:bg-bambu-dark disabled:opacity-25 disabled:hover:bg-transparent transition-colors`,children:(0,J.jsx)(re,{className:`w-5 h-5`})}),(0,J.jsx)(`button`,{type:`button`,onClick:v,disabled:!v,title:f(`queue.moveDown`),"aria-label":f(`queue.moveDown`),className:`flex items-center justify-center w-8 h-7 rounded-lg text-bambu-gray hover:text-white hover:bg-bambu-dark disabled:opacity-25 disabled:hover:bg-transparent transition-colors`,children:(0,J.jsx)(T,{className:`w-5 h-5`})})]}),(0,J.jsx)(`button`,{onClick:e=>{e.stopPropagation(),A.forEach(e=>{(j&&s.includes(e)||!j&&!s.includes(e))&&c(e)})},className:`hidden sm:flex items-center justify-center w-6 h-6 rounded border transition-colors shrink-0 ${j?`bg-bambu-green border-bambu-green text-white`:`border-white/30 bg-black/30 hover:border-bambu-green/50`}`,title:f(j?`queue.bulkEdit.deselectAll`:`queue.bulkEdit.selectAll`),children:j&&(0,J.jsx)(ne,{className:`w-4 h-4`})}),S&&(0,J.jsx)(`div`,{...ee,...C,className:`hidden sm:flex items-center justify-center w-8 h-8 rounded-lg bg-bambu-dark cursor-grab active:cursor-grabbing hover:bg-bambu-dark-tertiary transition-colors touch-none shrink-0`,title:f(`queue.batch.dragGroup`,{defaultValue:`Drag group`}),children:(0,J.jsx)(M,{className:`w-4 h-4 text-bambu-gray`})}),(0,J.jsx)(`button`,{onClick:n,className:`flex items-center justify-center w-8 h-8 rounded-lg bg-bambu-dark hover:bg-bambu-dark-tertiary transition-colors shrink-0`,title:f(t?`queue.batch.expand`:`queue.batch.collapse`),children:t?(0,J.jsx)(xe,{className:`w-4 h-4 text-bambu-gray`}):(0,J.jsx)(T,{className:`w-4 h-4 text-bambu-gray`})}),(0,J.jsx)(`div`,{className:`w-10 h-10 sm:w-12 sm:h-12 flex-shrink-0 bg-bambu-dark rounded-lg flex items-center justify-center`,children:t?(0,J.jsx)(N,{className:`w-5 h-5 text-cyan-700 dark:text-cyan-300`}):(0,J.jsx)(Ve,{className:`w-5 h-5 text-cyan-700 dark:text-cyan-300`})}),(0,J.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,J.jsx)(`p`,{className:`text-sm sm:text-base text-white font-medium truncate`,children:x.batchName}),(0,J.jsx)(`span`,{className:`flex-shrink-0 px-1.5 py-0.5 text-[10px] sm:text-xs bg-cyan-100 dark:bg-cyan-500/15 text-cyan-700 dark:text-cyan-300 rounded border border-cyan-300 dark:border-cyan-500/30`,children:f(`queue.batch.label`,{count:k.count})})]}),(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-xs sm:text-sm text-bambu-gray`,children:[k.time>0&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1 sm:gap-1.5`,children:[(0,J.jsx)(I,{className:`w-3 h-3 sm:w-3.5 sm:h-3.5`}),de(k.time)]}),k.weight>0&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1 sm:gap-1.5`,children:[(0,J.jsx)(Pe,{className:`w-3 h-3 sm:w-3.5 sm:h-3.5`}),vt(k.weight)]}),P>0&&ae===`pending`&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1 sm:gap-1.5 text-yellow-700 dark:text-yellow-400`,children:[(0,J.jsx)(H,{className:`w-3 h-3 sm:w-3.5 sm:h-3.5`}),f(`queue.batch.pendingCount`,{count:P})]})]})]}),(0,J.jsx)(`div`,{className:`flex items-center gap-1 shrink-0`,children:r&&(0,J.jsx)(R,{variant:`ghost`,size:`sm`,onClick:r,title:f(`queue.batch.ungroup`),className:`text-cyan-700 dark:text-cyan-300 hover:text-cyan-900 dark:hover:text-cyan-200 hover:bg-cyan-50 dark:hover:bg-cyan-500/10 p-1.5 sm:p-2`,children:(0,J.jsx)(Ue,{className:`w-4 h-4`})})})]}),!t&&(0,J.jsx)(`div`,{className:`border-t border-bambu-dark-tertiary bg-black/20 p-2 sm:p-3 space-y-2`,children:x.items.map((e,t)=>(0,J.jsx)(St,{item:e,onEdit:()=>i(e),onCancel:()=>a({type:`cancel`,item:e}),onRemove:()=>{},onStop:()=>{},onRequeue:()=>{},onStart:()=>o.mutate({id:e.id}),onMoveUp:y&&t>0?()=>y([e.id],x.items[t-1].id,!1):void 0,onMoveDown:y&&ty([e.id],x.items[t+1].id,!0):void 0,timeFormat:l,isSelected:s.includes(e.id),onToggleSelect:()=>c(e.id),hasPermission:u,canModify:d,showEta:m.has(e.id),etaNow:h,t:f},e.id))})]})}function wt({items:e,visibleCount:t,onShowMore:n,sortBy:r,sortAsc:i,onSortByChange:a,onSortAscToggle:o,onRemove:s,onRequeue:c,timeFormat:l,batchCollapsed:u,toggleBatchCollapsed:p,hasPermission:m,canModify:h,t:g}){if(e.length===0)return(0,J.jsxs)(le,{className:`p-12 text-center border-dashed`,children:[(0,J.jsx)(Ne,{className:`w-16 h-16 text-bambu-gray mx-auto mb-4 opacity-50`}),(0,J.jsx)(`h3`,{className:`text-xl font-medium text-white mb-2`,children:g(`queue.history.emptyTitle`)}),(0,J.jsx)(`p`,{className:`text-bambu-gray max-w-md mx-auto`,children:g(`queue.history.emptyDescription`)})]});let v=[],y=new Set;for(let n of e.slice(0,t))if(n.batch_id!=null){if(y.has(n.batch_id))continue;y.add(n.batch_id);let t=e.filter(e=>e.batch_id===n.batch_id);v.push({kind:`batch`,batchId:n.batch_id,batchName:n.batch_name||g(`queue.batch.defaultName`),items:t})}else v.push({kind:`item`,item:n});return(0,J.jsxs)(`div`,{children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2 mb-3 sm:mb-4`,children:[(0,J.jsxs)(`h2`,{className:`text-base sm:text-lg font-semibold text-white flex items-center gap-2`,children:[g(`queue.sections.history`),(0,J.jsxs)(`span`,{className:`text-xs sm:text-sm font-normal text-bambu-gray`,children:[`(`,g(`queue.itemCount`,{count:e.length}),`)`]})]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsxs)(`select`,{className:`px-2 sm:px-3 py-1.5 text-xs sm:text-sm bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,value:r,onChange:e=>a(e.target.value),children:[(0,J.jsx)(`option`,{value:`date`,children:g(`queue.sort.byDate`)}),(0,J.jsx)(`option`,{value:`name`,children:g(`queue.sort.byName`)}),(0,J.jsx)(`option`,{value:`printer`,children:g(`queue.sort.byPrinter`)})]}),(0,J.jsx)(R,{variant:`ghost`,size:`sm`,onClick:o,title:g(i?`queue.sort.ascendingOldest`:`queue.sort.descendingNewest`),className:`px-2`,children:i?(0,J.jsx)(f,{className:`w-4 h-4`}):(0,J.jsx)(d,{className:`w-4 h-4`})})]})]}),(0,J.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-2`,children:v.map(e=>{if(e.kind===`item`)return(0,J.jsx)(Qe,{item:e.item,onRemove:()=>s(e.item),onRequeue:()=>c(e.item),timeFormat:l,hasPermission:m,canModify:h,t:g},e.item.id);let t=u[e.batchId]??!0,n=e.items.filter(e=>e.status===`completed`).length,r=e.items.filter(e=>e.status===`failed`).length,i=e.items.filter(e=>e.status===`skipped`).length,a=e.items.filter(e=>e.status===`cancelled`).length,o=e.items.map(e=>e.completed_at||e.created_at).filter(e=>!!e).sort().at(-1);return(0,J.jsxs)(`div`,{className:`md:col-span-2 xl:col-span-3 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary border-l-[3px] border-l-cyan-400`,children:[(0,J.jsxs)(`button`,{onClick:()=>p(e.batchId),className:`w-full flex items-center gap-2 sm:gap-3 px-3 py-2 hover:bg-bambu-dark/30 transition-colors text-left`,title:g(t?`queue.batch.expand`:`queue.batch.collapse`),children:[t?(0,J.jsx)(xe,{className:`w-4 h-4 text-bambu-gray shrink-0`}):(0,J.jsx)(T,{className:`w-4 h-4 text-bambu-gray shrink-0`}),t?(0,J.jsx)(N,{className:`w-5 h-5 text-cyan-700 dark:text-cyan-300 shrink-0`}):(0,J.jsx)(Ve,{className:`w-5 h-5 text-cyan-700 dark:text-cyan-300 shrink-0`}),(0,J.jsx)(`span`,{className:`text-sm text-white font-medium truncate min-w-0 flex-1`,children:e.batchName}),(0,J.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-bambu-gray shrink-0`,children:[n>0&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1 text-emerald-700 dark:text-emerald-400`,children:[(0,J.jsx)(k,{className:`w-3 h-3`}),n]}),r>0&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1 text-red-700 dark:text-red-400`,children:[(0,J.jsx)(E,{className:`w-3 h-3`}),r]}),i>0&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1 text-orange-700 dark:text-orange-400`,children:[(0,J.jsx)(F,{className:`w-3 h-3`}),i]}),a>0&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1 text-gray-400`,children:[(0,J.jsx)(_,{className:`w-3 h-3`}),a]}),(0,J.jsx)(`span`,{title:o??void 0,children:o?fe(o,l,g):null})]})]}),!t&&(0,J.jsx)(`div`,{className:`border-t border-bambu-dark-tertiary bg-black/20 p-2 grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-2`,children:e.items.map(e=>(0,J.jsx)(Qe,{item:e,onRemove:()=>s(e),onRequeue:()=>c(e),timeFormat:l,hasPermission:m,canModify:h,t:g},e.id))})]},`batch-${e.batchId}`)})}),e.length>t&&(0,J.jsxs)(`div`,{className:`mt-4 flex flex-col items-center gap-2`,children:[(0,J.jsx)(R,{variant:`secondary`,size:`sm`,onClick:n,children:g(`queue.history.showMore`)}),(0,J.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:g(`queue.history.showingCount`,{shown:Math.min(t,e.length),total:e.length})})]})]})}var Tt=50;function Et(){let{t:e}=a(),t=o(),{showToast:n}=O(),{hasPermission:u,hasAnyPermission:p,canModify:_}=Ie(),[b,ne]=(0,q.useState)(null),[T,re]=(0,q.useState)(``),[E,k]=(0,q.useState)(``),[A,j]=(0,q.useState)(!1),[M,ae]=(0,q.useState)(null),[P,oe]=(0,q.useState)(null),[F,I]=(0,q.useState)(null),[L,ue]=(0,q.useState)([]),[fe,me]=(0,q.useState)(!1),[ge,_e]=(0,q.useState)(null),[B,ve]=(0,q.useState)(()=>localStorage.getItem(`queue.historySortBy`)||`date`),[V,xe]=(0,q.useState)(()=>{let e=localStorage.getItem(`queue.historySortAsc`);return e===null?!1:e===`true`}),[Se,Ce]=(0,q.useState)(Tt),[U,W]=(0,q.useState)(()=>localStorage.getItem(`queue.pendingSortBy`)||`position`),[Te,De]=(0,q.useState)(()=>{let e=localStorage.getItem(`queue.pendingSortAsc`);return e===null?!0:e===`true`}),[ke]=(0,q.useState)(()=>{let e=Number(new URLSearchParams(window.location.search).get(`batch`));return Number.isInteger(e)&&e>0?e:null}),[G,Ae]=(0,q.useState)(()=>{let e=new URLSearchParams(window.location.search),t=e.get(`tab`);if(e.get(`batch`))return`batches`;if(t===`pipelines`||t===`history`||t===`timeline`||t===`queue`||t===`batches`)return t;let n=localStorage.getItem(`queue.activeTab`);return n===`history`||n===`timeline`||n===`pipelines`||n===`batches`?n:`queue`}),[je,Me]=(0,q.useState)(()=>localStorage.getItem(`queue.activeLayout`)===`printer`?`printer`:`position`),[K,Pe]=(0,q.useState)(()=>{try{let e=localStorage.getItem(`queue.batchCollapsed`);return e?JSON.parse(e):{}}catch{return{}}}),[Fe,Be]=(0,q.useState)(null),[Ve,Ue]=(0,q.useState)(!1),[We,Y]=(0,q.useState)(null);(0,q.useEffect)(()=>{localStorage.setItem(`queue.historySortBy`,B)},[B]),(0,q.useEffect)(()=>{localStorage.setItem(`queue.historySortAsc`,String(V))},[V]),(0,q.useEffect)(()=>{Ce(Tt)},[B,V,E]),(0,q.useEffect)(()=>{localStorage.setItem(`queue.pendingSortBy`,U)},[U]),(0,q.useEffect)(()=>{localStorage.setItem(`queue.pendingSortAsc`,String(Te))},[Te]),(0,q.useEffect)(()=>{localStorage.setItem(`queue.activeTab`,G)},[G]),(0,q.useEffect)(()=>{localStorage.setItem(`queue.activeLayout`,je)},[je]),(0,q.useEffect)(()=>{localStorage.setItem(`queue.batchCollapsed`,JSON.stringify(K))},[K]);let Ke=S(g(te,{activationConstraint:{distance:8}}),g(y,{coordinateGetter:v})),{data:X}=s({queryKey:[`settings`],queryFn:r.getSettings}),qe=X?.time_format||`system`,{data:Je}=s({queryKey:[`batches`,`active`],queryFn:()=>r.getBatches(`active`)}),Ye=Je?.length??0,{data:Z,isLoading:Ze}=s({queryKey:[`queue`,b,T],queryFn:()=>r.getQueue(b||void 0,T||void 0),refetchInterval:5e3}),{data:Qe}=s({queryKey:[`printers`],queryFn:()=>r.getPrinters()}),$e=c({mutationFn:e=>r.updateSettings({queue_shortest_first:e}),onSuccess:()=>{t.invalidateQueries({queryKey:[`settings`]})}}),tt=c({mutationFn:e=>r.cancelQueueItem(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`queue`]}),n(e(`queue.toast.cancelled`))},onError:()=>n(e(`queue.toast.cancelFailed`),`error`)}),nt=c({mutationFn:e=>r.removeFromQueue(e),onSuccess:r=>{t.invalidateQueries({queryKey:[`queue`]}),t.invalidateQueries({queryKey:[`batches`]}),n(r.deleted===!1?e(`queue.toast.keptForOrder`):e(`queue.toast.removed`))},onError:()=>n(e(`queue.toast.removeFailed`),`error`)}),rt=c({mutationFn:e=>r.stopQueueItem(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`queue`]}),n(e(`queue.toast.stopped`))},onError:()=>n(e(`queue.toast.stopFailed`),`error`)}),[it,at]=(0,q.useState)(null),[ot,st]=(0,q.useState)(null),ct=c({mutationFn:({id:e,skipFilamentCheck:t})=>r.startQueueItem(e,{skipFilamentCheck:t}),onSuccess:()=>{t.invalidateQueries({queryKey:[`queue`]}),n(e(`queue.toast.released`)),at(null),st(null)},onError:(t,r)=>{if(t instanceof i&&t.status===409&&t.code===`insufficient_filament`){let e=t.detail?.deficit??[];at({itemId:r.id,deficit:e});return}if(t instanceof i&&t.status===409&&t.code===`unmatched_filament`){let e=t.detail?.missing??[];st({itemId:r.id,missing:e});return}n(e(`queue.toast.startFailed`),`error`)}}),dt=c({mutationFn:e=>r.reorderQueue(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`queue`]})},onError:()=>n(e(`queue.toast.reorderFailed`),`error`)}),ft=c({mutationFn:async()=>{let e=Z?.filter(e=>[`completed`,`failed`,`skipped`,`cancelled`].includes(e.status))||[],t=0,n=0;for(let i of e)(await r.removeFromQueue(i.id)).deleted===!1?n+=1:t+=1;return{cleared:t,kept:n}},onSuccess:({cleared:r,kept:i})=>{t.invalidateQueries({queryKey:[`queue`]}),t.invalidateQueries({queryKey:[`batches`]}),n(i>0?`${e(`queue.toast.historyCleared`,{count:r})} ${e(`queue.toast.historyKeptForOrders`,{kept:i})}`:e(`queue.toast.historyCleared`,{count:r}))},onError:()=>n(e(`queue.toast.clearHistoryFailed`),`error`)}),pt=c({mutationFn:e=>r.bulkUpdateQueue(e),onSuccess:e=>{t.invalidateQueries({queryKey:[`queue`]}),ue([]),me(!1),n(e.message)},onError:()=>n(e(`queue.toast.updateFailed`),`error`)}),mt=c({mutationFn:async e=>{for(let t of e)await r.cancelQueueItem(t);return e.length},onSuccess:r=>{t.invalidateQueries({queryKey:[`queue`]}),ue([]),n(e(`queue.toast.bulkCancelled`,{count:r}))},onError:()=>n(e(`queue.toast.bulkCancelFailed`),`error`)}),ht=c({mutationFn:e=>r.resumeQueueAfterFailure(e),onSuccess:r=>{t.invalidateQueries({queryKey:[`queue`]}),_e(null),n(e(`queue.toast.resumedAfterFailure`,{restored:r.restored,acknowledged:r.acknowledged}))},onError:()=>n(e(`queue.toast.resumeAfterFailureFailed`),`error`)}),gt=c({mutationFn:e=>r.createBatch(e),onSuccess:r=>{t.invalidateQueries({queryKey:[`queue`]}),ue([]),Ue(!1),Pe(e=>({...e,[r.id]:!1})),n(e(`queue.toast.batchCreated`,{name:r.name}))},onError:()=>n(e(`queue.toast.batchCreateFailed`),`error`)}),_t=c({mutationFn:e=>r.ungroupBatch(e),onSuccess:r=>{t.invalidateQueries({queryKey:[`queue`]}),Y(null),n(e(`queue.toast.batchUngrouped`,{count:r.ungrouped_count}))},onError:()=>n(e(`queue.toast.batchUngroupFailed`),`error`)}),yt=e=>{ue(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},Q=(0,q.useMemo)(()=>{let e=new Set;return Qe?.forEach(t=>{t.location&&e.add(t.location)}),Z?.forEach(t=>{t.target_location&&e.add(t.target_location)}),Array.from(e).sort()},[Qe,Z]),xt=(0,q.useCallback)(e=>E?e.target_location?e.target_location===E:e.printer_id?Qe?.find(t=>t.id===e.printer_id)?.location===E:!1:!0,[E,Qe]),$=(0,q.useMemo)(()=>{let e=Z?.filter(e=>e.status===`pending`)||[];E&&(e=e.filter(xt));let t=e=>{if(!e.scheduled_time)return 0;let t=z(e.scheduled_time)?.getTime()??0;return t>Date.now()+4320*60*60*1e3?0:t};return X?.queue_shortest_first?[...e].sort((e,t)=>et(e,t,!0)):[...e].sort((e,n)=>{let r;if(U===`name`){let t=e.archive_name||e.library_file_name||``,i=n.archive_name||n.library_file_name||``;r=t.localeCompare(i)}else r=U===`printer`?(e.printer_name||``).localeCompare(n.printer_name||``):U===`time`?t(e)-t(n):e.position-n.position;return Te?r:-r})},[Z,U,Te,xt,E,X?.queue_shortest_first]),Et=()=>{let e=$.map(e=>e.id);L.length===e.length?ue([]):ue(e)},Ot=(0,q.useMemo)(()=>{let e=Z?.filter(e=>e.status===`printing`)||[];return E&&(e=e.filter(xt)),e},[Z,E,xt]),kt=(0,q.useMemo)(()=>{let e=new Set;if(!Z)return e;let t=new Set;Z.forEach(e=>{e.status===`printing`&&e.printer_id&&t.add(e.printer_id)});let n=e=>e.scheduled_time?(z(e.scheduled_time)?.getTime()??0)>Date.now():!1,r=(e,t)=>et(e,t,X?.queue_shortest_first??!1),i=new Map;return Z.filter(e=>e.status===`pending`&&e.printer_id!=null&&!e.manual_start&&!n(e)).sort(r).forEach(e=>{let t=i.get(e.printer_id)??[];t.push(e),i.set(e.printer_id,t)}),Z.forEach(r=>{if(r.status===`pending`&&!r.waiting_reason&&!n(r)&&!(r.print_time_seconds==null||r.print_time_seconds<=0)&&!r.require_previous_success){if(r.printer_id==null){e.add(r.id);return}if(!t.has(r.printer_id)){if(r.manual_start){e.add(r.id);return}i.get(r.printer_id)?.[0]?.id===r.id&&e.add(r.id)}}}),e},[Z,X?.queue_shortest_first]),[At,jt]=(0,q.useState)(()=>Date.now()),Mt=kt.size>0;(0,q.useEffect)(()=>{if(!Mt)return;jt(Date.now());let e=setInterval(()=>jt(Date.now()),3e4);return()=>clearInterval(e)},[Mt]);let Nt=(0,q.useMemo)(()=>{let e=new Set;return Ot.forEach(t=>{t.printer_id&&e.add(t.printer_id)}),Array.from(e)},[Ot]),Pt=l({queries:Nt.map(e=>({queryKey:[`printerStatus`,e],queryFn:()=>r.getPrinterStatus(e),refetchInterval:5e3}))}),Ft=(0,q.useMemo)(()=>{let e={};return Nt.forEach((t,n)=>{let r=Pt[n];r?.data?.state&&(e[t]=r.data.state)}),e},[Nt,Pt]),It=(0,q.useMemo)(()=>{let e={};return Nt.forEach((t,n)=>{let r=Pt[n];r?.data&&(e[t]={progress:r.data.progress??void 0,remaining_time:r.data.remaining_time??void 0,state:r.data.state??void 0})}),e},[Nt,Pt]),Lt=(0,q.useMemo)(()=>{let e=Z?.filter(e=>[`completed`,`failed`,`skipped`,`cancelled`].includes(e.status))||[];return E&&(e=e.filter(xt)),[...e].sort((e,t)=>{let n;if(B===`name`){let r=e.archive_name||e.library_file_name||``,i=t.archive_name||t.library_file_name||``;n=r.localeCompare(i)}else n=B===`printer`?(e.printer_name||``).localeCompare(t.printer_name||``):(z(t.completed_at||t.created_at)?.getTime()??0)-(z(e.completed_at||e.created_at)?.getTime()??0);return V?-n:n})},[Z,B,V,xt,E]),Rt=(0,q.useMemo)(()=>$.reduce((e,t)=>e+(t.print_time_seconds||0),0),[$]),zt=(0,q.useMemo)(()=>$.reduce((e,t)=>e+(t.filament_used_grams||0),0),[$]),Bt=e=>{let t=e.active.id;Be(typeof t==`number`||typeof t==`string`?t:null)},Vt=e=>{let{active:t,over:n}=e;if(Be(null),!n||t.id===n.id)return;let r,i=t.id;if(typeof i==`string`&&i.startsWith(`batch-`)){let e=Number(i.slice(6));r=$.filter(t=>t.batch_id===e).map(e=>e.id)}else{let e=i;r=L.includes(e)&&L.length>1?L.slice().sort((e,t)=>$.findIndex(t=>t.id===e)-$.findIndex(e=>e.id===t)):[e]}if(r.length===0)return;let a,o=n.id;if(typeof o==`string`&&o.startsWith(`batch-`)){let e=Number(o.slice(6));a=$.findIndex(t=>t.batch_id===e)}else a=$.findIndex(e=>e.id===o);if(a===-1)return;let s=$[a],c=$.filter(e=>!r.includes(e.id)),l=c.findIndex(e=>e.id===s.id);l===-1&&(l=a),$.findIndex(e=>e.id===r[0])$.find(t=>t.id===e)).filter(e=>!!e),...c.slice(l)].map((e,t)=>({id:e.id,position:t+1}));dt.mutate(u)},Ht=(0,q.useMemo)(()=>{let t=[],n=new Set;for(let r of $)if(r.batch_id!=null){if(n.has(r.batch_id))continue;n.add(r.batch_id);let i=$.filter(e=>e.batch_id===r.batch_id);t.push({kind:`batch`,batchId:r.batch_id,batchName:r.batch_name||e(`queue.batch.defaultName`),items:i})}else t.push({kind:`item`,item:r});return t},[$,e]),Ut=u(`queue:reorder`)&&U===`position`&&!X?.queue_shortest_first,Wt=e=>e.kind===`item`?[e.item.id]:e.items.map(e=>e.id),Gt=(e,t,n)=>{let r=$.filter(t=>!e.includes(t.id)),i=r.findIndex(e=>e.id===t);if(i===-1)return;n&&(i+=1);let a=e.map(e=>$.find(t=>t.id===e)).filter(e=>!!e),o=[...r.slice(0,i),...a,...r.slice(i)];dt.mutate(o.map((e,t)=>({id:e.id,position:t+1})))},Kt=(e,t)=>{if(!Ut)return{};let n=Wt(e[t]);return{onMoveUp:t>0?()=>Gt(n,Wt(e[t-1])[0],!1):void 0,onMoveDown:t{let r=Wt(e[t+1]);Gt(n,r[r.length-1],!0)}:void 0}},qt=(0,q.useMemo)(()=>{let e=[];for(let t of Ht)if(t.kind===`item`)e.push(t.item.id);else if(e.push(`batch-${t.batchId}`),!(K[t.batchId]??!0))for(let n of t.items)e.push(n.id);return e},[Ht,K]),Jt=(0,q.useMemo)(()=>L.length<2?!1:L.every(e=>{let t=$.find(t=>t.id===e);return t&&t.batch_id==null}),[L,$]),Yt=e=>{Pe(t=>({...t,[e]:!(t[e]??!0)}))},Xt=(0,q.useMemo)(()=>{let t=new Map,n=t=>{if(t.printer_id)return{key:`printer:${t.printer_id}`,label:t.printer_name||`Printer #${t.printer_id}`,printerId:t.printer_id,targetModel:null,isUnassigned:!1};if((t.variants?.length??0)>1){let n=t.variants.map(e=>e.target_model).join(` / `);return{key:`models:${n}`,label:`${e(`queue.filter.any`)} ${n}`,printerId:null,targetModel:null,isUnassigned:!1}}return t.target_model?{key:`model:${t.target_model}`,label:`${e(`queue.filter.any`)} ${t.target_model}`,printerId:null,targetModel:t.target_model,isUnassigned:!1}:{key:`unassigned`,label:e(`queue.filter.unassigned`),printerId:null,targetModel:null,isUnassigned:!0}};for(let e of Ht){let r=e.kind===`item`?e.item:e.items[0];if(!r)continue;let i=n(r);t.has(i.key)||t.set(i.key,{...i,rows:[]}),t.get(i.key).rows.push(e)}return Array.from(t.values()).sort((e,t)=>e.isUnassigned&&!t.isUnassigned?1:!e.isUnassigned&&t.isUnassigned?-1:e.label.localeCompare(t.label))},[Ht,e]),Zt=(0,q.useMemo)(()=>{let e=new Map;return Z?.forEach(t=>{if(t.status===`skipped`&&t.error_message===`Previous print failed or was aborted`&&t.printer_id){let n=e.get(t.printer_id);n?n.count+=1:e.set(t.printer_id,{name:t.printer_name||`Printer #${t.printer_id}`,count:1})}}),Array.from(e.entries()).map(([e,{name:t,count:n}])=>({printerId:e,printerName:t,skippedCount:n})).sort((e,t)=>e.printerName.localeCompare(t.printerName))},[Z]),Qt=e=>{let t=0,n=0,r=0;for(let i of e){let e=i.kind===`item`?[i.item]:i.items;for(let i of e)t+=1,n+=i.print_time_seconds||0,r+=i.filament_used_grams||0}return{count:t,time:n,weight:r}};return(0,J.jsxs)(`div`,{className:`p-4 md:p-8`,children:[(0,J.jsx)(`div`,{className:`flex items-center justify-between mb-6`,children:(0,J.jsxs)(`div`,{children:[(0,J.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,J.jsx)(Ne,{className:`w-7 h-7 text-bambu-green`}),e(`queue.title`)]}),(0,J.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:e(`queue.subtitle`)})]})}),(0,J.jsx)(`div`,{className:`flex gap-1 border-b border-bambu-dark-tertiary mb-6 overflow-x-auto`,children:[{id:`queue`,label:e(`queue.tabs.queue`),icon:H,count:$.length+Ot.length},{id:`batches`,label:e(`queue.tabs.batches`),icon:N,count:Ye},{id:`history`,label:e(`queue.tabs.history`),icon:Ne,count:Lt.length},{id:`timeline`,label:e(`queue.tabs.timeline`),icon:Re,count:null},{id:`pipelines`,label:e(`queue.tabs.pipelines`),icon:se,count:null}].map(({id:e,label:t,icon:n,count:r})=>(0,J.jsxs)(`button`,{onClick:()=>Ae(e),className:`px-4 py-2.5 text-sm flex items-center gap-2 border-b-2 -mb-px transition-colors whitespace-nowrap ${G===e?`text-white border-bambu-green font-medium`:`text-bambu-gray border-transparent hover:text-white`}`,children:[(0,J.jsx)(n,{className:`w-4 h-4`}),t,r!==null&&r>0&&(0,J.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded-full ${G===e?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark-tertiary text-bambu-gray`}`,children:r})]},e))}),G!==`pipelines`&&G!==`batches`&&(0,J.jsx)(Xe,{activeCount:Ot.length,pendingCount:$.length,totalTime:Rt,totalWeight:zt,historyCount:Lt.length,t:e}),G===`queue`&&Zt.length>0&&u(`queue:update_all`)&&(0,J.jsx)(`div`,{className:`mb-4 space-y-2`,children:Zt.map(({printerId:t,printerName:n,skippedCount:r})=>(0,J.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-3 bg-orange-50 dark:bg-orange-500/10 border border-orange-300 dark:border-orange-500/30 rounded-lg`,children:[(0,J.jsx)(D,{className:`w-5 h-5 text-orange-600 dark:text-orange-400 flex-shrink-0`}),(0,J.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,J.jsx)(`div`,{className:`text-sm text-orange-800 dark:text-orange-200`,children:e(`queue.resumeAfterFailure.banner`,{printer:n,count:r})}),(0,J.jsx)(`div`,{className:`text-xs text-orange-800/80 dark:text-orange-200/70 mt-0.5`,children:e(`queue.resumeAfterFailure.bannerHint`)})]}),(0,J.jsxs)(`button`,{onClick:()=>_e({printerId:t,printerName:n,skippedCount:r}),className:`flex items-center gap-1.5 px-3 py-1.5 bg-orange-100 dark:bg-orange-500/20 hover:bg-orange-200 dark:hover:bg-orange-500/30 text-orange-900 dark:text-orange-100 text-sm rounded-md border border-orange-300 dark:border-orange-500/40 transition-colors flex-shrink-0`,children:[(0,J.jsx)(ze,{className:`w-4 h-4`}),e(`queue.resumeAfterFailure.button`)]})]},t))}),G!==`pipelines`&&G!==`batches`&&(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 sm:gap-4 mb-6`,children:[(0,J.jsxs)(`select`,{className:`px-2 sm:px-3 py-2 text-sm sm:text-base bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none min-w-0 flex-1 sm:flex-none`,value:b===-1?`unassigned`:b||``,onChange:e=>{let t=e.target.value;ne(t===`unassigned`?-1:t===``?null:Number(t))},children:[(0,J.jsx)(`option`,{value:``,children:e(`queue.filter.allPrinters`)}),(0,J.jsx)(`option`,{value:`unassigned`,children:e(`queue.filter.unassigned`)}),Qe?.map(e=>(0,J.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,J.jsxs)(`select`,{className:`px-2 sm:px-3 py-2 text-sm sm:text-base bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none min-w-0 flex-1 sm:flex-none`,value:T,onChange:e=>re(e.target.value),children:[(0,J.jsx)(`option`,{value:``,children:e(`queue.filter.allStatus`)}),(0,J.jsx)(`option`,{value:`pending`,children:e(`queue.status.pending`)}),(0,J.jsx)(`option`,{value:`printing`,children:e(`queue.status.printing`)}),(0,J.jsx)(`option`,{value:`completed`,children:e(`queue.status.completed`)}),(0,J.jsx)(`option`,{value:`failed`,children:e(`queue.status.failed`)}),(0,J.jsx)(`option`,{value:`skipped`,children:e(`queue.status.skipped`)}),(0,J.jsx)(`option`,{value:`cancelled`,children:e(`queue.status.cancelled`)})]}),Q.length>0&&(0,J.jsxs)(`select`,{className:`px-2 sm:px-3 py-2 text-sm sm:text-base bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none min-w-0 flex-1 sm:flex-none`,value:E,onChange:e=>k(e.target.value),children:[(0,J.jsx)(`option`,{value:``,children:e(`queue.filter.allLocations`)}),Q.map(e=>(0,J.jsx)(`option`,{value:e,children:e},e))]}),(0,J.jsx)(`div`,{className:`hidden sm:block flex-1`}),G===`history`&&Lt.length>0&&(0,J.jsxs)(R,{className:`w-full sm:w-auto`,variant:`secondary`,size:`sm`,onClick:()=>j(!0),disabled:!u(`queue:delete_all`),title:u(`queue:delete_all`)?void 0:e(`queue.permissions.noClearHistory`),children:[(0,J.jsx)(he,{className:`w-4 h-4`}),e(`queue.clearHistory`)]})]}),G===`queue`&&(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 mb-6`,children:[(0,J.jsxs)(`div`,{className:`inline-flex items-center bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg p-0.5`,children:[(0,J.jsxs)(`button`,{className:`px-3 py-1.5 text-xs sm:text-sm rounded-md transition-colors flex items-center gap-1.5 ${je===`position`?`bg-bambu-dark-tertiary text-white`:`text-bambu-gray hover:text-white`}`,onClick:()=>Me(`position`),title:e(`queue.layout.flatList`),children:[(0,J.jsx)(ie,{className:`w-3.5 h-3.5`}),(0,J.jsx)(`span`,{className:`hidden sm:inline`,children:e(`queue.layout.flatList`)})]}),(0,J.jsxs)(`button`,{className:`px-3 py-1.5 text-xs sm:text-sm rounded-md transition-colors flex items-center gap-1.5 ${je===`printer`?`bg-bambu-dark-tertiary text-white`:`text-bambu-gray hover:text-white`}`,onClick:()=>Me(`printer`),title:e(`queue.layout.groupByPrinter`),children:[(0,J.jsx)(ye,{className:`w-3.5 h-3.5`}),(0,J.jsx)(`span`,{className:`hidden sm:inline`,children:e(`queue.layout.byPrinter`)})]})]}),(0,J.jsxs)(`button`,{onClick:()=>{let e=!(X?.queue_shortest_first??!1);$e.mutate(e)},className:`flex items-center gap-1 px-2 py-1.5 text-xs rounded-lg border transition-colors ${X?.queue_shortest_first?`bg-bambu-green/20 border-bambu-green text-bambu-green`:`bg-bambu-dark-secondary border-bambu-dark-tertiary text-bambu-gray hover:text-white hover:border-bambu-gray`}`,title:e(`queue.sjf.tooltip`,`Shortest Job First — scheduler prioritizes shorter prints`),children:[(0,J.jsx)(He,{className:`w-4 h-4`}),(0,J.jsx)(`span`,{className:`hidden sm:inline`,children:e(`queue.sjf.label`,`SJF`)}),(0,J.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full ${X?.queue_shortest_first?`bg-bambu-green`:`bg-bambu-gray`}`})]})]}),G===`pipelines`?(0,J.jsx)(Ge,{}):G===`batches`?(0,J.jsx)(ut,{hasPermission:u,t:e,focusBatchId:ke}):Ze?(0,J.jsx)(`div`,{className:`text-center py-12 text-bambu-gray`,children:e(`common.loading`)}):Z?.length===0?(0,J.jsxs)(le,{className:`p-12 text-center border-dashed`,children:[(0,J.jsx)(w,{className:`w-16 h-16 text-bambu-gray mx-auto mb-4 opacity-50`}),(0,J.jsx)(`h3`,{className:`text-xl font-medium text-white mb-2`,children:e(`queue.empty.title`)}),(0,J.jsx)(`p`,{className:`text-bambu-gray max-w-md mx-auto`,children:e(`queue.empty.description`)})]}):G===`timeline`?(0,J.jsx)(lt,{queueItems:Z||[],printers:Qe||[],printerStatuses:It,sjfEnabled:X?.queue_shortest_first??!1,onItemClick:e=>{[`completed`,`failed`,`skipped`,`cancelled`].includes(e.status)?oe(e):e.status===`pending`?ae(e):e.status===`printing`&&I({type:`stop`,item:e})},t:e}):G===`history`?(0,J.jsx)(wt,{items:Lt,collapsed:!1,visibleCount:Se,onShowMore:()=>Ce(e=>e+Tt),sortBy:B,sortAsc:V,onSortByChange:ve,onSortAscToggle:()=>xe(!V),onRemove:e=>I({type:`remove`,item:e}),onRequeue:oe,timeFormat:qe,batchCollapsed:K,toggleBatchCollapsed:Yt,hasPermission:u,canModify:_,t:e}):(0,J.jsxs)(`div`,{className:`space-y-6 sm:space-y-8`,children:[Ot.length>0&&(0,J.jsxs)(`div`,{children:[(0,J.jsxs)(`h2`,{className:`text-base sm:text-lg font-semibold text-white mb-3 sm:mb-4 flex items-center gap-2`,children:[(0,J.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-blue-400 animate-pulse`}),e(`queue.sections.currentlyPrinting`)]}),(0,J.jsx)(`div`,{className:`space-y-2 sm:space-y-3`,children:Ot.map(t=>(0,J.jsx)(St,{item:t,onEdit:()=>{},onCancel:()=>{},onRemove:()=>{},onStop:()=>I({type:`stop`,item:t}),onRequeue:()=>{},onStart:()=>{},timeFormat:qe,hasPermission:u,canModify:_,printerState:t.printer_id?Ft[t.printer_id]:null,t:e},t.id))})]}),$.length>0&&(0,J.jsxs)(`div`,{children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2 mb-3 sm:mb-4`,children:[(0,J.jsxs)(`h2`,{className:`text-base sm:text-lg font-semibold text-white flex items-center gap-2`,children:[(0,J.jsx)(H,{className:`w-4 h-4 sm:w-5 sm:h-5 text-yellow-600 dark:text-yellow-400`}),e(`queue.sections.queued`),(0,J.jsxs)(`span`,{className:`text-xs sm:text-sm font-normal text-bambu-gray`,children:[`(`,e(`queue.itemCount`,{count:$.length}),`)`]}),(0,J.jsx)(`span`,{className:`hidden sm:inline text-xs text-bambu-gray ml-2`,title:e(`queue.reorderHint`),children:e(`queue.dragToReorder`)})]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsxs)(`select`,{className:`px-2 sm:px-3 py-1.5 text-xs sm:text-sm bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,value:U,onChange:e=>W(e.target.value),children:[(0,J.jsx)(`option`,{value:`position`,children:e(`queue.sort.byPosition`)}),(0,J.jsx)(`option`,{value:`name`,children:e(`queue.sort.byName`)}),(0,J.jsx)(`option`,{value:`printer`,children:e(`queue.sort.byPrinter`)}),(0,J.jsx)(`option`,{value:`time`,children:e(`queue.sort.bySchedule`)})]}),(0,J.jsx)(R,{variant:`ghost`,size:`sm`,onClick:()=>De(!Te),title:e(Te?`common.ascending`:`common.descending`),className:`px-2`,children:Te?(0,J.jsx)(f,{className:`w-4 h-4`}):(0,J.jsx)(d,{className:`w-4 h-4`})})]})]}),(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 sm:gap-3 mb-3 sm:mb-4 p-2 sm:p-3 bg-bambu-dark rounded-lg`,children:[(0,J.jsxs)(R,{variant:`ghost`,size:`sm`,onClick:Et,className:`flex items-center gap-1.5 sm:gap-2 text-xs sm:text-sm`,children:[L.length===$.length&&$.length>0?(0,J.jsx)(we,{className:`w-4 h-4 text-bambu-green`}):(0,J.jsx)(be,{className:`w-4 h-4`}),L.length===$.length&&$.length>0?e(`queue.bulkEdit.deselectAll`):e(`queue.bulkEdit.selectAll`)]}),L.length>0&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`span`,{className:`text-xs sm:text-sm text-bambu-gray`,children:e(`queue.bulkEdit.selected`,{count:L.length})}),(0,J.jsx)(`div`,{className:`hidden sm:block h-4 w-px bg-bambu-dark-tertiary`}),Jt&&(0,J.jsxs)(R,{variant:`ghost`,size:`sm`,onClick:()=>Ue(!0),className:`flex items-center gap-1.5 sm:gap-2 text-xs sm:text-sm text-cyan-700 dark:text-cyan-300 hover:text-cyan-900 dark:hover:text-cyan-200`,title:e(`queue.batch.groupAsBatch`),children:[(0,J.jsx)(N,{className:`w-3.5 h-3.5 sm:w-4 sm:h-4`}),(0,J.jsx)(`span`,{className:`hidden sm:inline`,children:e(`queue.batch.groupAsBatch`)})]}),(0,J.jsxs)(R,{variant:`ghost`,size:`sm`,onClick:()=>me(!0),className:`flex items-center gap-1.5 sm:gap-2 text-xs sm:text-sm text-bambu-green hover:text-bambu-green-light`,disabled:!p(`queue:update_own`,`queue:update_all`),title:p(`queue:update_own`,`queue:update_all`)?e(`queue.bulkEdit.editSelected`):e(`queue.permissions.noEditItems`),children:[(0,J.jsx)(pe,{className:`w-3.5 h-3.5 sm:w-4 sm:h-4`}),(0,J.jsx)(`span`,{className:`hidden sm:inline`,children:e(`queue.bulkEdit.editSelected`)})]}),(0,J.jsxs)(R,{variant:`ghost`,size:`sm`,onClick:()=>mt.mutate(L),className:`flex items-center gap-1.5 sm:gap-2 text-xs sm:text-sm text-red-600 dark:text-red-400 hover:text-red-700 dark:hover:text-red-300`,disabled:mt.isPending||!p(`queue:delete_own`,`queue:delete_all`),title:p(`queue:delete_own`,`queue:delete_all`)?e(`queue.bulkEdit.cancelSelected`):e(`queue.permissions.noCancelItems`),children:[(0,J.jsx)(ce,{className:`w-3.5 h-3.5 sm:w-4 sm:h-4`}),(0,J.jsx)(`span`,{className:`hidden sm:inline`,children:e(`queue.bulkEdit.cancelSelected`)})]})]})]}),(0,J.jsxs)(ee,{sensors:Ke,collisionDetection:h,onDragStart:Bt,onDragEnd:Vt,children:[(0,J.jsx)(C,{items:qt,strategy:x,children:je===`position`?(0,J.jsx)(`div`,{className:`space-y-2 sm:space-y-3`,children:Ht.map((t,n)=>(0,J.jsx)(Ct,{row:t,collapsed:t.kind===`batch`?K[t.batchId]??!0:!1,onToggleBatch:t.kind===`batch`?()=>Yt(t.batchId):void 0,onUngroup:t.kind===`batch`?()=>Y(t.batchId):void 0,setEditItem:ae,setConfirmAction:I,startMutation:ct,selectedItems:L,handleToggleSelect:yt,timeFormat:qe,hasPermission:u,canModify:_,t:e,etaEligibleIds:kt,etaNow:At,aggregateForRows:Qt,...Kt(Ht,n),onMoveBlock:Ut?Gt:void 0},t.kind===`item`?`item-${t.item.id}`:`batch-${t.batchId}`))}):(0,J.jsx)(`div`,{className:`space-y-4`,children:Xt.map(t=>{let n=Qt(t.rows);return(0,J.jsxs)(`div`,{children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-3 px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-t-lg`,children:[(0,J.jsx)(ye,{className:`w-4 h-4 ${t.isUnassigned?`text-orange-600 dark:text-orange-400`:t.targetModel?`text-blue-600 dark:text-blue-400`:`text-bambu-green`}`}),(0,J.jsx)(`span`,{className:`font-semibold text-white text-sm`,children:t.label}),(0,J.jsxs)(`span`,{className:`text-xs text-bambu-gray flex flex-wrap gap-x-3`,children:[(0,J.jsx)(`span`,{children:e(`queue.itemCount`,{count:n.count})}),n.time>0&&(0,J.jsx)(`span`,{children:de(n.time)}),n.weight>0&&(0,J.jsx)(`span`,{children:vt(n.weight)})]})]}),(0,J.jsx)(`div`,{className:`bg-bambu-dark/40 border border-t-0 border-bambu-dark-tertiary rounded-b-lg p-2 space-y-2`,children:t.rows.map((n,r)=>(0,J.jsx)(Ct,{row:n,collapsed:n.kind===`batch`?K[n.batchId]??!0:!1,onToggleBatch:n.kind===`batch`?()=>Yt(n.batchId):void 0,onUngroup:n.kind===`batch`?()=>Y(n.batchId):void 0,setEditItem:ae,setConfirmAction:I,startMutation:ct,selectedItems:L,handleToggleSelect:yt,timeFormat:qe,hasPermission:u,canModify:_,t:e,etaEligibleIds:kt,etaNow:At,aggregateForRows:Qt,...Kt(t.rows,r),onMoveBlock:Ut?Gt:void 0},n.kind===`item`?`item-${n.item.id}`:`batch-${n.batchId}`))})]},t.key)})})}),(0,J.jsx)(m,{children:(()=>{if(Fe===null)return null;if(typeof Fe==`string`&&Fe.startsWith(`batch-`)){let t=Number(Fe.slice(6)),n=$.filter(e=>e.batch_id===t);if(n.length===0)return null;let r=n[0].batch_name||e(`queue.batch.defaultName`);return(0,J.jsxs)(`div`,{className:`flex items-center gap-3 px-3 py-2 bg-bambu-dark-secondary border-2 border-cyan-400 rounded-lg shadow-2xl`,children:[(0,J.jsx)(N,{className:`w-4 h-4 text-cyan-700 dark:text-cyan-300`}),(0,J.jsx)(`span`,{className:`text-sm text-white font-medium`,children:e(`queue.dragGhost.batch`,{defaultValue:`{{name}} ({{count}} copies)`,name:r,count:n.length})})]})}return typeof Fe==`number`&&L.includes(Fe)&&L.length>1?(0,J.jsxs)(`div`,{className:`flex items-center gap-3 px-3 py-2 bg-bambu-dark-secondary border-2 border-cyan-400 rounded-lg shadow-2xl`,children:[(0,J.jsx)(N,{className:`w-4 h-4 text-cyan-700 dark:text-cyan-300`}),(0,J.jsx)(`span`,{className:`text-sm text-white font-medium`,children:e(`queue.dragGhost.multiCount`,{count:L.length})})]}):null})()})]})]})]}),M&&(0,J.jsx)(Oe,{mode:`edit-queue-item`,archiveId:M.archive_id??void 0,libraryFileId:M.library_file_id??void 0,archiveName:Le(M,t=>e(`common.plusNMore`,{count:t})),queueItem:M,onClose:()=>ae(null)}),P&&(0,J.jsx)(Oe,{mode:`create`,archiveId:P.archive_id??void 0,libraryFileId:P.library_file_id??void 0,archiveName:Le(P,t=>e(`common.plusNMore`,{count:t})),onClose:()=>oe(null)}),it&&(0,J.jsx)(Ee,{title:e(`queue.filamentShort.confirmTitle`),message:e(`queue.filamentShort.confirmIntro`)+` `+it.deficit.map(t=>e(`queue.filamentShort.lineItem`,{slot:t.slot_id,required:Math.round(t.required_grams),remaining:t.remaining_grams==null?e(`queue.filamentShort.unknown`):Math.round(t.remaining_grams)})).join(` `),confirmText:e(`queue.filamentShort.printAnyway`),variant:`warning`,onConfirm:()=>{ct.mutate({id:it.itemId,skipFilamentCheck:!0})},onCancel:()=>at(null)}),ot&&(0,J.jsx)(Ee,{title:e(`queue.filamentMissing.confirmTitle`),message:e(`queue.filamentMissing.confirmIntro`)+` `+ot.missing.join(` -`),confirmText:e(`queue.filamentShort.printAnyway`),variant:`warning`,onConfirm:()=>{ct.mutate({id:ot.itemId,skipFilamentCheck:!0})},onCancel:()=>st(null)}),F&&(0,J.jsx)(Ee,{title:F.type===`cancel`?e(`queue.confirm.cancelTitle`):F.type===`stop`?e(`queue.confirm.stopTitle`):e(`queue.confirm.removeTitle`),message:F.type===`cancel`?e(`queue.confirm.cancelMessage`,{name:F.item.archive_name||F.item.library_file_name||e(`queue.confirm.thisPrint`)}):F.type===`stop`?e(`queue.confirm.stopMessage`,{name:F.item.archive_name||F.item.library_file_name||e(`queue.confirm.thisPrint`)}):e(`queue.confirm.removeMessage`,{name:F.item.archive_name||F.item.library_file_name||e(`queue.confirm.thisItem`)}),confirmText:F.type===`cancel`?e(`queue.confirm.cancelButton`):F.type===`stop`?e(`queue.confirm.stopButton`):e(`common.remove`),variant:`danger`,onConfirm:()=>{F.type===`cancel`?tt.mutate(F.item.id):F.type===`stop`?rt.mutate(F.item.id):nt.mutate(F.item.id),I(null)},onCancel:()=>I(null)}),ge&&(0,J.jsx)(Ee,{title:e(`queue.resumeAfterFailure.confirmTitle`),message:e(`queue.resumeAfterFailure.confirmMessage`,{printer:ge.printerName,count:ge.skippedCount}),confirmText:e(`queue.resumeAfterFailure.button`),variant:`warning`,onConfirm:()=>ht.mutate(ge.printerId),onCancel:()=>_e(null)}),A&&(0,J.jsx)(Ee,{title:e(`queue.confirm.clearHistoryTitle`),message:e(`queue.confirm.clearHistoryMessage`,{count:Lt.length}),confirmText:e(`queue.clearHistory`),variant:`danger`,onConfirm:()=>{ft.mutate(),j(!1)},onCancel:()=>j(!1)}),fe&&(0,J.jsx)(yt,{selectedCount:L.length,printers:Qe?.map(e=>({id:e.id,name:e.name,nozzle_count:e.nozzle_count}))||[],onSave:e=>{Object.keys(e).length>0&&pt.mutate({item_ids:L,...e})},onClose:()=>me(!1),isSaving:pt.isPending,canControlPrinter:u(`printers:control`),hasGcodeSnippets:!!X?.gcode_snippets,t:e}),Ve&&(0,J.jsx)(Et,{itemCount:L.length,isSaving:gt.isPending,defaultName:(()=>{let t=$.find(e=>L.includes(e.id)),n=(t?.archive_name||t?.library_file_name||``).replace(/\.gcode\.3mf$/i,``).replace(/\.3mf$/i,``);return n?`${n}`:e(`queue.batch.defaultName`)})(),onSave:e=>gt.mutate({name:e,item_ids:L}),onClose:()=>Ue(!1),t:e}),We!==null&&(0,J.jsx)(Ee,{title:e(`queue.batch.ungroupConfirmTitle`),message:e(`queue.batch.ungroupConfirmMessage`),confirmText:e(`queue.batch.ungroup`),variant:`warning`,onConfirm:()=>vt.mutate(We),onCancel:()=>Y(null)})]})}function Et({itemCount:e,defaultName:t,isSaving:n,onSave:r,onClose:i,t:a}){let[o,s]=(0,q.useState)(t);return(0,J.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-4`,children:(0,J.jsxs)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl p-6 w-full max-w-md`,children:[(0,J.jsxs)(`h3`,{className:`text-lg font-semibold text-white mb-2 flex items-center gap-2`,children:[(0,J.jsx)(N,{className:`w-5 h-5 text-cyan-700 dark:text-cyan-300`}),a(`queue.batch.groupAsBatch`)]}),(0,J.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4`,children:a(`queue.batch.groupAsBatchDescription`,{count:e})}),(0,J.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:a(`queue.batch.nameLabel`)}),(0,J.jsx)(`input`,{type:`text`,autoFocus:!0,value:o,onChange:e=>s(e.target.value),placeholder:a(`queue.batch.namePlaceholder`),maxLength:120,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none mb-5`}),(0,J.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,J.jsx)(R,{variant:`ghost`,size:`sm`,onClick:i,disabled:n,children:a(`common.cancel`)}),(0,J.jsx)(R,{variant:`primary`,size:`sm`,onClick:()=>{let e=o.trim();e&&r(e)},disabled:n||!o.trim(),children:a(n?`common.saving`:`queue.batch.create`)})]})]})})}export{$ as QueuePage}; \ No newline at end of file +`),confirmText:e(`queue.filamentShort.printAnyway`),variant:`warning`,onConfirm:()=>{ct.mutate({id:ot.itemId,skipFilamentCheck:!0})},onCancel:()=>st(null)}),F&&(0,J.jsx)(Ee,{title:F.type===`cancel`?e(`queue.confirm.cancelTitle`):F.type===`stop`?e(`queue.confirm.stopTitle`):e(`queue.confirm.removeTitle`),message:F.type===`cancel`?e(`queue.confirm.cancelMessage`,{name:F.item.archive_name||F.item.library_file_name||e(`queue.confirm.thisPrint`)}):F.type===`stop`?e(`queue.confirm.stopMessage`,{name:F.item.archive_name||F.item.library_file_name||e(`queue.confirm.thisPrint`)}):e(`queue.confirm.removeMessage`,{name:F.item.archive_name||F.item.library_file_name||e(`queue.confirm.thisItem`)}),confirmText:F.type===`cancel`?e(`queue.confirm.cancelButton`):F.type===`stop`?e(`queue.confirm.stopButton`):e(`common.remove`),variant:`danger`,onConfirm:()=>{F.type===`cancel`?tt.mutate(F.item.id):F.type===`stop`?rt.mutate(F.item.id):nt.mutate(F.item.id),I(null)},onCancel:()=>I(null)}),ge&&(0,J.jsx)(Ee,{title:e(`queue.resumeAfterFailure.confirmTitle`),message:e(`queue.resumeAfterFailure.confirmMessage`,{printer:ge.printerName,count:ge.skippedCount}),confirmText:e(`queue.resumeAfterFailure.button`),variant:`warning`,onConfirm:()=>ht.mutate(ge.printerId),onCancel:()=>_e(null)}),A&&(0,J.jsx)(Ee,{title:e(`queue.confirm.clearHistoryTitle`),message:e(`queue.confirm.clearHistoryMessage`,{count:Lt.length}),confirmText:e(`queue.clearHistory`),variant:`danger`,onConfirm:()=>{ft.mutate(),j(!1)},onCancel:()=>j(!1)}),fe&&(0,J.jsx)(bt,{selectedCount:L.length,printers:Qe?.map(e=>({id:e.id,name:e.name,nozzle_count:e.nozzle_count}))||[],onSave:e=>{Object.keys(e).length>0&&pt.mutate({item_ids:L,...e})},onClose:()=>me(!1),isSaving:pt.isPending,canControlPrinter:u(`printers:control`),hasGcodeSnippets:!!X?.gcode_snippets,t:e}),Ve&&(0,J.jsx)(Dt,{itemCount:L.length,isSaving:gt.isPending,defaultName:(()=>{let t=$.find(e=>L.includes(e.id)),n=(t?.archive_name||t?.library_file_name||``).replace(/\.gcode\.3mf$/i,``).replace(/\.3mf$/i,``);return n?`${n}`:e(`queue.batch.defaultName`)})(),onSave:e=>gt.mutate({name:e,item_ids:L}),onClose:()=>Ue(!1),t:e}),We!==null&&(0,J.jsx)(Ee,{title:e(`queue.batch.ungroupConfirmTitle`),message:e(`queue.batch.ungroupConfirmMessage`),confirmText:e(`queue.batch.ungroup`),variant:`warning`,onConfirm:()=>_t.mutate(We),onCancel:()=>Y(null)})]})}function Dt({itemCount:e,defaultName:t,isSaving:n,onSave:r,onClose:i,t:a}){let[o,s]=(0,q.useState)(t);return(0,J.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-4`,children:(0,J.jsxs)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl p-6 w-full max-w-md`,children:[(0,J.jsxs)(`h3`,{className:`text-lg font-semibold text-white mb-2 flex items-center gap-2`,children:[(0,J.jsx)(N,{className:`w-5 h-5 text-cyan-700 dark:text-cyan-300`}),a(`queue.batch.groupAsBatch`)]}),(0,J.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4`,children:a(`queue.batch.groupAsBatchDescription`,{count:e})}),(0,J.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:a(`queue.batch.nameLabel`)}),(0,J.jsx)(`input`,{type:`text`,autoFocus:!0,value:o,onChange:e=>s(e.target.value),placeholder:a(`queue.batch.namePlaceholder`),maxLength:120,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none mb-5`}),(0,J.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,J.jsx)(R,{variant:`ghost`,size:`sm`,onClick:i,disabled:n,children:a(`common.cancel`)}),(0,J.jsx)(R,{variant:`primary`,size:`sm`,onClick:()=>{let e=o.trim();e&&r(e)},disabled:n||!o.trim(),children:a(n?`common.saving`:`queue.batch.create`)})]})]})})}export{Et as QueuePage}; \ No newline at end of file diff --git a/static/assets/RichTextEditor-BBu-zZie.js b/static/assets/RichTextEditor-CsfJOD7X.js similarity index 99% rename from static/assets/RichTextEditor-BBu-zZie.js rename to static/assets/RichTextEditor-CsfJOD7X.js index beee92cc8..55c3623c3 100644 --- a/static/assets/RichTextEditor-BBu-zZie.js +++ b/static/assets/RichTextEditor-CsfJOD7X.js @@ -1,4 +1,4 @@ -import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,T as r,w as i}from"./client-DnySrlFv.js";import{t as a}from"./react-dom-B8Dg6xzp.js";import{t as o}from"./createLucideIcon-DvBYJlWL.js";import{t as s}from"./list-CLcpeoSz.js";import{t as c}from"./unlink-C098nwOf.js";import{on as l,sn as u}from"./index-0t--Yqoi.js";import{t as d}from"./with-selector-CsEuXInf.js";var f=o(`bold`,[[`path`,{d:`M6 12h9a4 4 0 0 1 0 8H7a1 1 0 0 1-1-1V5a1 1 0 0 1 1-1h7a4 4 0 0 1 0 8`,key:`mg9rjx`}]]),p=o(`italic`,[[`line`,{x1:`19`,x2:`10`,y1:`4`,y2:`4`,key:`15jd3p`}],[`line`,{x1:`14`,x2:`5`,y1:`20`,y2:`20`,key:`bu0au3`}],[`line`,{x1:`15`,x2:`9`,y1:`4`,y2:`20`,key:`uljnxc`}]]),m=o(`text-align-center`,[[`path`,{d:`M21 5H3`,key:`1fi0y6`}],[`path`,{d:`M17 12H7`,key:`16if0g`}],[`path`,{d:`M19 19H5`,key:`vjpgq2`}]]),h=o(`text-align-end`,[[`path`,{d:`M21 5H3`,key:`1fi0y6`}],[`path`,{d:`M21 12H9`,key:`dn1m92`}],[`path`,{d:`M21 19H7`,key:`4cu937`}]]),g=o(`text-align-start`,[[`path`,{d:`M21 5H3`,key:`1fi0y6`}],[`path`,{d:`M15 12H3`,key:`6jk70r`}],[`path`,{d:`M17 19H3`,key:`z6ezky`}]]),_=o(`underline`,[[`path`,{d:`M6 4v6a6 6 0 0 0 12 0V4`,key:`9kb039`}],[`line`,{x1:`4`,x2:`20`,y1:`20`,y2:`20`,key:`nun2al`}]]),v=e(n(),1),y=e(a(),1),b=r(),x=t(),ee=Object.defineProperty,te=(e,t)=>{let n={};for(var r in e)ee(n,r,{get:e[r],enumerable:!0});return t||ee(n,Symbol.toStringTag,{value:`Module`}),n};function S(e){this.content=e}S.prototype={constructor:S,find:function(e){for(var t=0;t>1}},S.from=function(e){if(e instanceof S)return e;var t=[];if(e)for(var n in e)t.push(n,e[n]);return new S(t)};function ne(e,t,n){for(let r=0;;r++){if(r==e.childCount||r==t.childCount)return e.childCount==t.childCount?null:n;let i=e.child(r),a=t.child(r);if(i==a){n+=i.nodeSize;continue}if(!i.sameMarkup(a))return n;if(i.isText&&i.text!=a.text){let e=i.text,t=a.text,r=0;for(;e[r]==t[r];r++)n++;return r&&r0&&a>0&&e[i-1]==t[a-1];)i--,a--,n--,r--;return i&&a&&i=56320&&e<57344}function ae(e){return e>=55296&&e<56320}var C=class e{constructor(e,t){if(this.content=e,this.size=t||0,t==null)for(let t=0;te&&n(s,r+o,i||null,a)!==!1&&s.content.size){let i=o+1;s.nodesBetween(Math.max(0,e-i),Math.min(s.content.size,t-i),n,r+i)}o=c}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,n,r){let i=``,a=!0;return this.nodesBetween(e,t,(o,s)=>{let c=o.isText?o.text.slice(Math.max(e,s)-s,t-s):o.isLeaf?r?typeof r==`function`?r(o):r:o.type.spec.leafText?o.type.spec.leafText(o):``:``;o.isBlock&&(o.isLeaf&&c||o.isTextblock)&&n&&(a?a=!1:i+=n),i+=c},0),i}append(t){if(!t.size)return this;if(!this.size)return t;let n=this.lastChild,r=t.firstChild,i=this.content.slice(),a=0;for(n.isText&&n.sameMarkup(r)&&(i[i.length-1]=n.withText(n.text+r.text),a=1);at)for(let e=0,a=0;at&&((an)&&(o=o.isText?o.cut(Math.max(0,t-a),Math.min(o.text.length,n-a)):o.cut(Math.max(0,t-a-1),Math.min(o.content.size,n-a-1))),r.push(o),i+=o.nodeSize),a=s}return new e(r,i)}cutByIndex(t,n){return t==n?e.empty:t==0&&n==this.content.length?this:new e(this.content.slice(t,n))}replaceChild(t,n){let r=this.content[t];if(r==n)return this;let i=this.content.slice(),a=this.size+n.nodeSize-r.nodeSize;return i[t]=n,new e(i,a)}addToStart(t){return new e([t].concat(this.content),this.size+t.nodeSize)}addToEnd(t){return new e(this.content.concat(t),this.size+t.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let t=0;tthis.size||e<0)throw RangeError(`Position ${e} outside of fragment (${this})`);for(let t=0,n=0;;t++){let r=this.child(t),i=n+r.nodeSize;if(i>=e)return i==e?se(t+1,i):se(t,n);n=i}}toString(){return`<`+this.toStringInner()+`>`}toStringInner(){return this.content.join(`, `)}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(t,n){if(!n)return e.empty;if(!Array.isArray(n))throw RangeError(`Invalid input for Fragment.fromJSON`);return e.fromArray(n.map(t.nodeFromJSON))}static fromArray(t){if(!t.length)return e.empty;let n,r=0;for(let e=0;ethis.type.rank&&(t||=e.slice(0,r),t.push(this),n=!0),t&&t.push(i)}return t||=e.slice(),n||t.push(this),t}removeFromSet(e){for(let t=0;te.type.rank-t.type.rank),n}};w.none=[];var le=class extends Error{},T=class e{constructor(e,t,n){this.content=e,this.openStart=t,this.openEnd=n}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(t,n){let r=de(this.content,t+this.openStart,n,this.openStart+1,this.openEnd+1);return r&&new e(r,this.openStart,this.openEnd)}removeBetween(t,n){return new e(ue(this.content,t+this.openStart,n+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart==e.openStart&&this.openEnd==e.openEnd}toString(){return this.content+`(`+this.openStart+`,`+this.openEnd+`)`}toJSON(){if(!this.content.size)return null;let e={content:this.content.toJSON()};return this.openStart>0&&(e.openStart=this.openStart),this.openEnd>0&&(e.openEnd=this.openEnd),e}static fromJSON(t,n){if(!n)return e.empty;let r=n.openStart||0,i=n.openEnd||0;if(typeof r!=`number`||typeof i!=`number`)throw RangeError(`Invalid input for Slice.fromJSON`);return new e(C.fromJSON(t,n.content),r,i)}static maxOpen(t,n=!0){let r=0,i=0;for(let e=t.firstChild;e&&!e.isLeaf&&(n||!e.type.spec.isolating);e=e.firstChild)r++;for(let e=t.lastChild;e&&!e.isLeaf&&(n||!e.type.spec.isolating);e=e.lastChild)i++;return new e(t,r,i)}};T.empty=new T(C.empty,0,0);function ue(e,t,n){let{index:r,offset:i}=e.findIndex(t),a=e.maybeChild(r),{index:o,offset:s}=e.findIndex(n);if(i==t||a.isText){if(s!=n&&!e.child(o).isText)throw RangeError(`Removing non-flat range`);return e.cut(0,t).append(e.cut(n))}if(r!=o)throw RangeError(`Removing non-flat range`);return e.replaceChild(r,a.copy(ue(a.content,t-i-1,n-i-1)))}function de(e,t,n,r,i,a){let{index:o,offset:s}=e.findIndex(t),c=e.maybeChild(o);if(s==t||c.isText)return a&&r<=0&&i<=0&&!a.canReplace(o,o,n)?null:e.cut(0,t).append(n).append(e.cut(t));let l=de(c.content,t-s-1,n,o==0?r-1:0,o==e.childCount-1?i-1:0,c);return l&&e.replaceChild(o,c.copy(l))}function fe(e,t,n){if(n.openStart>e.depth)throw new le(`Inserted content deeper than insertion position`);if(e.depth-n.openStart!=t.depth-n.openEnd)throw new le(`Inconsistent open depths`);return pe(e,t,n,0)}function pe(e,t,n,r){let i=e.index(r),a=e.node(r);if(i==t.index(r)&&r=0&&e.isText&&e.sameMarkup(t[n])?t[n]=e.withText(t[n].text+e.text):t.push(e)}function _e(e,t,n,r){let i=(t||e).node(n),a=0,o=t?t.index(n):i.childCount;e&&(a=e.index(n),e.depth>n?a++:e.textOffset&&(ge(e.nodeAfter,r),a++));for(let e=a;ei&&he(e,t,i+1),o=r.depth>i&&he(n,r,i+1),s=[];return _e(null,e,i,s),a&&o&&t.index(i)==n.index(i)?(me(a,o),ge(ve(a,ye(e,t,n,r,i+1)),s)):(a&&ge(ve(a,be(e,t,i+1)),s),_e(t,n,i,s),o&&ge(ve(o,be(n,r,i+1)),s)),_e(r,null,i,s),new C(s)}function be(e,t,n){let r=[];return _e(null,e,n,r),e.depth>n&&ge(ve(he(e,t,n+1),be(e,t,n+1)),r),_e(t,null,n,r),new C(r)}function xe(e,t){let n=t.depth-e.openStart,r=t.node(n).copy(e.content);for(let e=n-1;e>=0;e--)r=t.node(e).copy(C.from(r));return{start:r.resolveNoCache(e.openStart+n),end:r.resolveNoCache(r.content.size-e.openEnd-n)}}var Se=class e{constructor(e,t,n){this.pos=e,this.path=t,this.parentOffset=n,this.depth=t.length/3-1}resolveDepth(e){return e==null?this.depth:e<0?this.depth+e:e}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(e){return this.path[this.resolveDepth(e)*3]}index(e){return this.path[this.resolveDepth(e)*3+1]}indexAfter(e){return e=this.resolveDepth(e),this.index(e)+(e==this.depth&&!this.textOffset?0:1)}start(e){return e=this.resolveDepth(e),e==0?0:this.path[e*3-1]+1}end(e){return e=this.resolveDepth(e),this.start(e)+this.node(e).content.size}before(e){if(e=this.resolveDepth(e),!e)throw RangeError(`There is no position before the top-level node`);return e==this.depth+1?this.pos:this.path[e*3-1]}after(e){if(e=this.resolveDepth(e),!e)throw RangeError(`There is no position after the top-level node`);return e==this.depth+1?this.pos:this.path[e*3-1]+this.path[e*3].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let e=this.parent,t=this.index(this.depth);if(t==e.childCount)return null;let n=this.pos-this.path[this.path.length-1],r=e.child(t);return n?e.child(t).cut(n):r}get nodeBefore(){let e=this.index(this.depth),t=this.pos-this.path[this.path.length-1];return t?this.parent.child(e).cut(0,t):e==0?null:this.parent.child(e-1)}posAtIndex(e,t){t=this.resolveDepth(t);let n=this.path[t*3],r=t==0?0:this.path[t*3-1]+1;for(let t=0;t0;t--)if(this.start(t)<=e&&this.end(t)>=e)return t;return 0}blockRange(e=this,t){if(e.pos=0;n--)if(e.pos<=this.end(n)&&(!t||t(this.node(n))))return new Ee(this,e,n);return null}sameParent(e){return this.pos-this.parentOffset==e.pos-e.parentOffset}max(e){return e.pos>this.pos?e:this}min(e){return e.pos=0&&n<=t.content.size))throw RangeError(`Position `+n+` out of range`);let r=[],i=0,a=n;for(let e=t;;){let{index:t,offset:n}=e.content.findIndex(a),o=a-n;if(r.push(e,t,i+n),!o||(e=e.child(t),e.isText))break;a=o-1,i+=n+1}return new e(n,r,a)}static resolveCached(t,n){let r=Te.get(t);if(r)for(let e=0;ee&&this.nodesBetween(e,t,e=>(n.isInSet(e.marks)&&(r=!0),!r)),r}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let e=this.type.name;return this.content.size&&(e+=`(`+this.content.toStringInner()+`)`),Ae(this.marks,e)}contentMatchAt(e){let t=this.type.contentMatch.matchFragment(this.content,0,e);if(!t)throw Error(`Called contentMatchAt on a node with invalid content`);return t}canReplace(e,t,n=C.empty,r=0,i=n.childCount){let a=this.contentMatchAt(e).matchFragment(n,r,i),o=a&&a.matchFragment(this.content,t);if(!o||!o.validEnd)return!1;for(let e=r;ee.type.name)}`);this.content.forEach(e=>e.check())}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return this.content.size&&(e.content=this.content.toJSON()),this.marks.length&&(e.marks=this.marks.map(e=>e.toJSON())),e}static fromJSON(e,t){if(!t)throw RangeError(`Invalid input for Node.fromJSON`);let n;if(t.marks){if(!Array.isArray(t.marks))throw RangeError(`Invalid mark data for Node.fromJSON`);n=t.marks.map(e.markFromJSON)}if(t.type==`text`){if(typeof t.text!=`string`)throw RangeError(`Invalid text node in JSON`);return e.text(t.text,n)}let r=C.fromJSON(e,t.content),i=e.nodeType(t.type).create(t.attrs,r,n);return i.type.checkAttrs(i.attrs),i}};Oe.prototype.text=void 0;var ke=class e extends Oe{constructor(e,t,n,r){if(super(e,t,null,r),!n)throw RangeError(`Empty text nodes are not allowed`);this.text=n}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):Ae(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(e,t){return this.text.slice(e,t)}get nodeSize(){return this.text.length}mark(t){return t==this.marks?this:new e(this.type,this.attrs,this.text,t)}withText(t){return t==this.text?this:new e(this.type,this.attrs,t,this.marks)}cut(e=0,t=this.text.length){return e==0&&t==this.text.length?this:this.withText(this.text.slice(e,t))}eq(e){return this.sameMarkup(e)&&this.text==e.text}toJSON(){let e=super.toJSON();return e.text=this.text,e}};function Ae(e,t){for(let n=e.length-1;n>=0;n--)t=e[n].type.name+`(`+t+`)`;return t}var je=class e{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(t,n){let r=new Me(t,n);if(r.next==null)return e.empty;let i=Ne(r);r.next&&r.err(`Unexpected trailing text`);let a=Ue(Be(i));return We(a,r),a}matchType(e){for(let t=0;te.createAndFill()));for(let e=0;e=this.next.length)throw RangeError(`There's no ${e}th edge in this content match`);return this.next[e]}toString(){let e=[];function t(n){e.push(n);for(let r=0;r{let r=n+(t.validEnd?`*`:` `)+` `;for(let n=0;n`+e.indexOf(t.next[n].next);return r}).join(` +import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,T as r,w as i}from"./client-DnySrlFv.js";import{t as a}from"./react-dom-B8Dg6xzp.js";import{t as o}from"./createLucideIcon-DvBYJlWL.js";import{t as s}from"./list-CLcpeoSz.js";import{t as c}from"./unlink-C098nwOf.js";import{on as l,sn as u}from"./index-Cxa-KVmA.js";import{t as d}from"./with-selector-CsEuXInf.js";var f=o(`bold`,[[`path`,{d:`M6 12h9a4 4 0 0 1 0 8H7a1 1 0 0 1-1-1V5a1 1 0 0 1 1-1h7a4 4 0 0 1 0 8`,key:`mg9rjx`}]]),p=o(`italic`,[[`line`,{x1:`19`,x2:`10`,y1:`4`,y2:`4`,key:`15jd3p`}],[`line`,{x1:`14`,x2:`5`,y1:`20`,y2:`20`,key:`bu0au3`}],[`line`,{x1:`15`,x2:`9`,y1:`4`,y2:`20`,key:`uljnxc`}]]),m=o(`text-align-center`,[[`path`,{d:`M21 5H3`,key:`1fi0y6`}],[`path`,{d:`M17 12H7`,key:`16if0g`}],[`path`,{d:`M19 19H5`,key:`vjpgq2`}]]),h=o(`text-align-end`,[[`path`,{d:`M21 5H3`,key:`1fi0y6`}],[`path`,{d:`M21 12H9`,key:`dn1m92`}],[`path`,{d:`M21 19H7`,key:`4cu937`}]]),g=o(`text-align-start`,[[`path`,{d:`M21 5H3`,key:`1fi0y6`}],[`path`,{d:`M15 12H3`,key:`6jk70r`}],[`path`,{d:`M17 19H3`,key:`z6ezky`}]]),_=o(`underline`,[[`path`,{d:`M6 4v6a6 6 0 0 0 12 0V4`,key:`9kb039`}],[`line`,{x1:`4`,x2:`20`,y1:`20`,y2:`20`,key:`nun2al`}]]),v=e(n(),1),y=e(a(),1),b=r(),x=t(),ee=Object.defineProperty,te=(e,t)=>{let n={};for(var r in e)ee(n,r,{get:e[r],enumerable:!0});return t||ee(n,Symbol.toStringTag,{value:`Module`}),n};function S(e){this.content=e}S.prototype={constructor:S,find:function(e){for(var t=0;t>1}},S.from=function(e){if(e instanceof S)return e;var t=[];if(e)for(var n in e)t.push(n,e[n]);return new S(t)};function ne(e,t,n){for(let r=0;;r++){if(r==e.childCount||r==t.childCount)return e.childCount==t.childCount?null:n;let i=e.child(r),a=t.child(r);if(i==a){n+=i.nodeSize;continue}if(!i.sameMarkup(a))return n;if(i.isText&&i.text!=a.text){let e=i.text,t=a.text,r=0;for(;e[r]==t[r];r++)n++;return r&&r0&&a>0&&e[i-1]==t[a-1];)i--,a--,n--,r--;return i&&a&&i=56320&&e<57344}function ae(e){return e>=55296&&e<56320}var C=class e{constructor(e,t){if(this.content=e,this.size=t||0,t==null)for(let t=0;te&&n(s,r+o,i||null,a)!==!1&&s.content.size){let i=o+1;s.nodesBetween(Math.max(0,e-i),Math.min(s.content.size,t-i),n,r+i)}o=c}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,n,r){let i=``,a=!0;return this.nodesBetween(e,t,(o,s)=>{let c=o.isText?o.text.slice(Math.max(e,s)-s,t-s):o.isLeaf?r?typeof r==`function`?r(o):r:o.type.spec.leafText?o.type.spec.leafText(o):``:``;o.isBlock&&(o.isLeaf&&c||o.isTextblock)&&n&&(a?a=!1:i+=n),i+=c},0),i}append(t){if(!t.size)return this;if(!this.size)return t;let n=this.lastChild,r=t.firstChild,i=this.content.slice(),a=0;for(n.isText&&n.sameMarkup(r)&&(i[i.length-1]=n.withText(n.text+r.text),a=1);at)for(let e=0,a=0;at&&((an)&&(o=o.isText?o.cut(Math.max(0,t-a),Math.min(o.text.length,n-a)):o.cut(Math.max(0,t-a-1),Math.min(o.content.size,n-a-1))),r.push(o),i+=o.nodeSize),a=s}return new e(r,i)}cutByIndex(t,n){return t==n?e.empty:t==0&&n==this.content.length?this:new e(this.content.slice(t,n))}replaceChild(t,n){let r=this.content[t];if(r==n)return this;let i=this.content.slice(),a=this.size+n.nodeSize-r.nodeSize;return i[t]=n,new e(i,a)}addToStart(t){return new e([t].concat(this.content),this.size+t.nodeSize)}addToEnd(t){return new e(this.content.concat(t),this.size+t.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let t=0;tthis.size||e<0)throw RangeError(`Position ${e} outside of fragment (${this})`);for(let t=0,n=0;;t++){let r=this.child(t),i=n+r.nodeSize;if(i>=e)return i==e?se(t+1,i):se(t,n);n=i}}toString(){return`<`+this.toStringInner()+`>`}toStringInner(){return this.content.join(`, `)}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(t,n){if(!n)return e.empty;if(!Array.isArray(n))throw RangeError(`Invalid input for Fragment.fromJSON`);return e.fromArray(n.map(t.nodeFromJSON))}static fromArray(t){if(!t.length)return e.empty;let n,r=0;for(let e=0;ethis.type.rank&&(t||=e.slice(0,r),t.push(this),n=!0),t&&t.push(i)}return t||=e.slice(),n||t.push(this),t}removeFromSet(e){for(let t=0;te.type.rank-t.type.rank),n}};w.none=[];var le=class extends Error{},T=class e{constructor(e,t,n){this.content=e,this.openStart=t,this.openEnd=n}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(t,n){let r=de(this.content,t+this.openStart,n,this.openStart+1,this.openEnd+1);return r&&new e(r,this.openStart,this.openEnd)}removeBetween(t,n){return new e(ue(this.content,t+this.openStart,n+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart==e.openStart&&this.openEnd==e.openEnd}toString(){return this.content+`(`+this.openStart+`,`+this.openEnd+`)`}toJSON(){if(!this.content.size)return null;let e={content:this.content.toJSON()};return this.openStart>0&&(e.openStart=this.openStart),this.openEnd>0&&(e.openEnd=this.openEnd),e}static fromJSON(t,n){if(!n)return e.empty;let r=n.openStart||0,i=n.openEnd||0;if(typeof r!=`number`||typeof i!=`number`)throw RangeError(`Invalid input for Slice.fromJSON`);return new e(C.fromJSON(t,n.content),r,i)}static maxOpen(t,n=!0){let r=0,i=0;for(let e=t.firstChild;e&&!e.isLeaf&&(n||!e.type.spec.isolating);e=e.firstChild)r++;for(let e=t.lastChild;e&&!e.isLeaf&&(n||!e.type.spec.isolating);e=e.lastChild)i++;return new e(t,r,i)}};T.empty=new T(C.empty,0,0);function ue(e,t,n){let{index:r,offset:i}=e.findIndex(t),a=e.maybeChild(r),{index:o,offset:s}=e.findIndex(n);if(i==t||a.isText){if(s!=n&&!e.child(o).isText)throw RangeError(`Removing non-flat range`);return e.cut(0,t).append(e.cut(n))}if(r!=o)throw RangeError(`Removing non-flat range`);return e.replaceChild(r,a.copy(ue(a.content,t-i-1,n-i-1)))}function de(e,t,n,r,i,a){let{index:o,offset:s}=e.findIndex(t),c=e.maybeChild(o);if(s==t||c.isText)return a&&r<=0&&i<=0&&!a.canReplace(o,o,n)?null:e.cut(0,t).append(n).append(e.cut(t));let l=de(c.content,t-s-1,n,o==0?r-1:0,o==e.childCount-1?i-1:0,c);return l&&e.replaceChild(o,c.copy(l))}function fe(e,t,n){if(n.openStart>e.depth)throw new le(`Inserted content deeper than insertion position`);if(e.depth-n.openStart!=t.depth-n.openEnd)throw new le(`Inconsistent open depths`);return pe(e,t,n,0)}function pe(e,t,n,r){let i=e.index(r),a=e.node(r);if(i==t.index(r)&&r=0&&e.isText&&e.sameMarkup(t[n])?t[n]=e.withText(t[n].text+e.text):t.push(e)}function _e(e,t,n,r){let i=(t||e).node(n),a=0,o=t?t.index(n):i.childCount;e&&(a=e.index(n),e.depth>n?a++:e.textOffset&&(ge(e.nodeAfter,r),a++));for(let e=a;ei&&he(e,t,i+1),o=r.depth>i&&he(n,r,i+1),s=[];return _e(null,e,i,s),a&&o&&t.index(i)==n.index(i)?(me(a,o),ge(ve(a,ye(e,t,n,r,i+1)),s)):(a&&ge(ve(a,be(e,t,i+1)),s),_e(t,n,i,s),o&&ge(ve(o,be(n,r,i+1)),s)),_e(r,null,i,s),new C(s)}function be(e,t,n){let r=[];return _e(null,e,n,r),e.depth>n&&ge(ve(he(e,t,n+1),be(e,t,n+1)),r),_e(t,null,n,r),new C(r)}function xe(e,t){let n=t.depth-e.openStart,r=t.node(n).copy(e.content);for(let e=n-1;e>=0;e--)r=t.node(e).copy(C.from(r));return{start:r.resolveNoCache(e.openStart+n),end:r.resolveNoCache(r.content.size-e.openEnd-n)}}var Se=class e{constructor(e,t,n){this.pos=e,this.path=t,this.parentOffset=n,this.depth=t.length/3-1}resolveDepth(e){return e==null?this.depth:e<0?this.depth+e:e}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(e){return this.path[this.resolveDepth(e)*3]}index(e){return this.path[this.resolveDepth(e)*3+1]}indexAfter(e){return e=this.resolveDepth(e),this.index(e)+(e==this.depth&&!this.textOffset?0:1)}start(e){return e=this.resolveDepth(e),e==0?0:this.path[e*3-1]+1}end(e){return e=this.resolveDepth(e),this.start(e)+this.node(e).content.size}before(e){if(e=this.resolveDepth(e),!e)throw RangeError(`There is no position before the top-level node`);return e==this.depth+1?this.pos:this.path[e*3-1]}after(e){if(e=this.resolveDepth(e),!e)throw RangeError(`There is no position after the top-level node`);return e==this.depth+1?this.pos:this.path[e*3-1]+this.path[e*3].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let e=this.parent,t=this.index(this.depth);if(t==e.childCount)return null;let n=this.pos-this.path[this.path.length-1],r=e.child(t);return n?e.child(t).cut(n):r}get nodeBefore(){let e=this.index(this.depth),t=this.pos-this.path[this.path.length-1];return t?this.parent.child(e).cut(0,t):e==0?null:this.parent.child(e-1)}posAtIndex(e,t){t=this.resolveDepth(t);let n=this.path[t*3],r=t==0?0:this.path[t*3-1]+1;for(let t=0;t0;t--)if(this.start(t)<=e&&this.end(t)>=e)return t;return 0}blockRange(e=this,t){if(e.pos=0;n--)if(e.pos<=this.end(n)&&(!t||t(this.node(n))))return new Ee(this,e,n);return null}sameParent(e){return this.pos-this.parentOffset==e.pos-e.parentOffset}max(e){return e.pos>this.pos?e:this}min(e){return e.pos=0&&n<=t.content.size))throw RangeError(`Position `+n+` out of range`);let r=[],i=0,a=n;for(let e=t;;){let{index:t,offset:n}=e.content.findIndex(a),o=a-n;if(r.push(e,t,i+n),!o||(e=e.child(t),e.isText))break;a=o-1,i+=n+1}return new e(n,r,a)}static resolveCached(t,n){let r=Te.get(t);if(r)for(let e=0;ee&&this.nodesBetween(e,t,e=>(n.isInSet(e.marks)&&(r=!0),!r)),r}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let e=this.type.name;return this.content.size&&(e+=`(`+this.content.toStringInner()+`)`),Ae(this.marks,e)}contentMatchAt(e){let t=this.type.contentMatch.matchFragment(this.content,0,e);if(!t)throw Error(`Called contentMatchAt on a node with invalid content`);return t}canReplace(e,t,n=C.empty,r=0,i=n.childCount){let a=this.contentMatchAt(e).matchFragment(n,r,i),o=a&&a.matchFragment(this.content,t);if(!o||!o.validEnd)return!1;for(let e=r;ee.type.name)}`);this.content.forEach(e=>e.check())}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return this.content.size&&(e.content=this.content.toJSON()),this.marks.length&&(e.marks=this.marks.map(e=>e.toJSON())),e}static fromJSON(e,t){if(!t)throw RangeError(`Invalid input for Node.fromJSON`);let n;if(t.marks){if(!Array.isArray(t.marks))throw RangeError(`Invalid mark data for Node.fromJSON`);n=t.marks.map(e.markFromJSON)}if(t.type==`text`){if(typeof t.text!=`string`)throw RangeError(`Invalid text node in JSON`);return e.text(t.text,n)}let r=C.fromJSON(e,t.content),i=e.nodeType(t.type).create(t.attrs,r,n);return i.type.checkAttrs(i.attrs),i}};Oe.prototype.text=void 0;var ke=class e extends Oe{constructor(e,t,n,r){if(super(e,t,null,r),!n)throw RangeError(`Empty text nodes are not allowed`);this.text=n}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):Ae(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(e,t){return this.text.slice(e,t)}get nodeSize(){return this.text.length}mark(t){return t==this.marks?this:new e(this.type,this.attrs,this.text,t)}withText(t){return t==this.text?this:new e(this.type,this.attrs,t,this.marks)}cut(e=0,t=this.text.length){return e==0&&t==this.text.length?this:this.withText(this.text.slice(e,t))}eq(e){return this.sameMarkup(e)&&this.text==e.text}toJSON(){let e=super.toJSON();return e.text=this.text,e}};function Ae(e,t){for(let n=e.length-1;n>=0;n--)t=e[n].type.name+`(`+t+`)`;return t}var je=class e{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(t,n){let r=new Me(t,n);if(r.next==null)return e.empty;let i=Ne(r);r.next&&r.err(`Unexpected trailing text`);let a=Ue(Be(i));return We(a,r),a}matchType(e){for(let t=0;te.createAndFill()));for(let e=0;e=this.next.length)throw RangeError(`There's no ${e}th edge in this content match`);return this.next[e]}toString(){let e=[];function t(n){e.push(n);for(let r=0;r{let r=n+(t.validEnd?`*`:` `)+` `;for(let n=0;n`+e.indexOf(t.next[n].next);return r}).join(` `)}};je.empty=new je(!0);var Me=class{constructor(e,t){this.string=e,this.nodeTypes=t,this.inline=null,this.pos=0,this.tokens=e.split(/\s*(?=\b|\W|$)/),this.tokens[this.tokens.length-1]==``&&this.tokens.pop(),this.tokens[0]==``&&this.tokens.shift()}get next(){return this.tokens[this.pos]}eat(e){return this.next==e&&(this.pos++||!0)}err(e){throw SyntaxError(e+` (in content expression '`+this.string+`')`)}};function Ne(e){let t=[];do t.push(Pe(e));while(e.eat(`|`));return t.length==1?t[0]:{type:`choice`,exprs:t}}function Pe(e){let t=[];do t.push(Fe(e));while(e.next&&e.next!=`)`&&e.next!=`|`);return t.length==1?t[0]:{type:`seq`,exprs:t}}function Fe(e){let t=ze(e);for(;;)if(e.eat(`+`))t={type:`plus`,expr:t};else if(e.eat(`*`))t={type:`star`,expr:t};else if(e.eat(`?`))t={type:`opt`,expr:t};else if(e.eat(`{`))t=Le(e,t);else break;return t}function Ie(e){/\D/.test(e.next)&&e.err(`Expected number, got '`+e.next+`'`);let t=Number(e.next);return e.pos++,t}function Le(e,t){let n=Ie(e),r=n;return e.eat(`,`)&&(r=e.next==`}`?-1:Ie(e)),e.eat(`}`)||e.err(`Unclosed braced range`),{type:`range`,min:n,max:r,expr:t}}function Re(e,t){let n=e.nodeTypes,r=n[t];if(r)return[r];let i=[];for(let e in n){let r=n[e];r.isInGroup(t)&&i.push(r)}return i.length==0&&e.err(`No node type or group '`+t+`' found`),i}function ze(e){if(e.eat(`(`)){let t=Ne(e);return e.eat(`)`)||e.err(`Missing closing paren`),t}else if(/\W/.test(e.next))e.err(`Unexpected token '`+e.next+`'`);else{let t=Re(e,e.next).map(t=>(e.inline==null?e.inline=t.isInline:e.inline!=t.isInline&&e.err(`Mixing inline and block content`),{type:`name`,value:t}));return e.pos++,t.length==1?t[0]:{type:`choice`,exprs:t}}}function Be(e){let t=[[]];return i(a(e,0),n()),t;function n(){return t.push([])-1}function r(e,n,r){let i={term:r,to:n};return t[e].push(i),i}function i(e,t){e.forEach(e=>e.to=t)}function a(e,t){if(e.type==`choice`)return e.exprs.reduce((e,n)=>e.concat(a(n,t)),[]);if(e.type==`seq`)for(let r=0;;r++){let o=a(e.exprs[r],t);if(r==e.exprs.length-1)return o;i(o,t=n())}else if(e.type==`star`){let o=n();return r(t,o),i(a(e.expr,o),o),[r(o)]}else if(e.type==`plus`){let o=n();return i(a(e.expr,t),o),i(a(e.expr,o),o),[r(o)]}else if(e.type==`opt`)return[r(t)].concat(a(e.expr,t));else if(e.type==`range`){let o=t;for(let t=0;t{e[t].forEach(({term:t,to:n})=>{if(!t)return;let r;for(let e=0;e{r||i.push([t,r=[]]),r.indexOf(e)==-1&&r.push(e)})})});let a=t[r.join(`,`)]=new je(r.indexOf(e.length-1)>-1);for(let e=0;e-1}get whitespace(){return this.spec.whitespace||(this.spec.code?`pre`:`normal`)}hasRequiredAttrs(){for(let e in this.attrs)if(this.attrs[e].isRequired)return!0;return!1}compatibleContent(e){return this==e||this.contentMatch.compatible(e.contentMatch)}computeAttrs(e){return!e&&this.defaultAttrs?this.defaultAttrs:Ke(this.attrs,e)}create(e=null,t,n){if(this.isText)throw Error(`NodeType.create can't construct text nodes`);return new Oe(this,this.computeAttrs(e),C.from(t),w.setFrom(n))}createChecked(e=null,t,n){return t=C.from(t),this.checkContent(t),new Oe(this,this.computeAttrs(e),t,w.setFrom(n))}createAndFill(e=null,t,n){if(e=this.computeAttrs(e),t=C.from(t),t.size){let e=this.contentMatch.fillBefore(t);if(!e)return null;t=e.append(t)}let r=this.contentMatch.matchFragment(t),i=r&&r.fillBefore(C.empty,!0);return i?new Oe(this,e,t.append(i),w.setFrom(n)):null}validContent(e){let t=this.contentMatch.matchFragment(e);if(!t||!t.validEnd)return!1;for(let t=0;t-1}allowsMarks(e){if(this.markSet==null)return!0;for(let t=0;tr[t]=new e(t,n,i));let i=n.spec.topNode||`doc`;if(!r[i])throw RangeError(`Schema is missing its top node type ('`+i+`')`);if(!r.text)throw RangeError(`Every schema needs a 'text' type`);for(let e in r.text.attrs)throw RangeError(`The text node type should not have attributes`);return r}};function Xe(e,t,n){let r=n.split(`|`);return n=>{let i=n===null?`null`:typeof n;if(r.indexOf(i)<0)throw RangeError(`Expected value of type ${r} for attribute ${t} on type ${e}, got ${i}`)}}var Ze=class{constructor(e,t,n){this.hasDefault=Object.prototype.hasOwnProperty.call(n,`default`),this.default=n.default,this.validate=typeof n.validate==`string`?Xe(e,t,n.validate):n.validate}get isRequired(){return!this.hasDefault}},Qe=class e{constructor(e,t,n,r){this.name=e,this.rank=t,this.schema=n,this.spec=r,this.attrs=Je(e,r.attrs),this.excluded=null;let i=Ge(this.attrs);this.instance=i?new w(this,i):null}create(e=null){return!e&&this.instance?this.instance:new w(this,Ke(this.attrs,e))}static compile(t,n){let r=Object.create(null),i=0;return t.forEach((t,a)=>r[t]=new e(t,i++,n,a)),r}removeFromSet(e){for(var t=0;t-1}},$e=class{constructor(e){this.linebreakReplacement=null,this.cached=Object.create(null);let t=this.spec={};for(let n in e)t[n]=e[n];t.nodes=S.from(e.nodes),t.marks=S.from(e.marks||{}),this.nodes=Ye.compile(this.spec.nodes,this),this.marks=Qe.compile(this.spec.marks,this);let n=Object.create(null);for(let e in this.nodes){if(e in this.marks)throw RangeError(e+` can not be both a node and a mark`);let t=this.nodes[e],r=t.spec.content||``,i=t.spec.marks;if(t.contentMatch=n[r]||(n[r]=je.parse(r,this.nodes)),t.inlineContent=t.contentMatch.inlineContent,t.spec.linebreakReplacement){if(this.linebreakReplacement)throw RangeError(`Multiple linebreak nodes defined`);if(!t.isInline||!t.isLeaf)throw RangeError(`Linebreak replacement nodes must be inline leaf nodes`);this.linebreakReplacement=t}t.markSet=i==`_`?null:i?et(this,i.split(` `)):i==``||!t.inlineContent?[]:null}for(let e in this.marks){let t=this.marks[e],n=t.spec.excludes;t.excluded=n==null?[t]:n==``?[]:et(this,n.split(` `))}this.nodeFromJSON=e=>Oe.fromJSON(this,e),this.markFromJSON=e=>w.fromJSON(this,e),this.topNodeType=this.nodes[this.spec.topNode||`doc`],this.cached.wrappings=Object.create(null)}node(e,t=null,n,r){if(typeof e==`string`)e=this.nodeType(e);else if(!(e instanceof Ye))throw RangeError(`Invalid node type: `+e);else if(e.schema!=this)throw RangeError(`Node type from different schema used (`+e.name+`)`);return e.createChecked(t,n,r)}text(e,t){let n=this.nodes.text;return new ke(n,n.defaultAttrs,e,w.setFrom(t))}mark(e,t){return typeof e==`string`&&(e=this.marks[e]),e.create(t)}nodeType(e){let t=this.nodes[e];if(!t)throw RangeError(`Unknown node type: `+e);return t}};function et(e,t){let n=[];for(let r=0;r-1)&&n.push(o=r)}if(!o)throw SyntaxError(`Unknown mark type: '`+t[r]+`'`)}return n}function tt(e){return e.tag!=null}function nt(e){return e.style!=null}var rt=class e{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[];let n=this.matchedStyles=[];t.forEach(e=>{if(tt(e))this.tags.push(e);else if(nt(e)){let t=/[^=]*/.exec(e.style)[0];n.indexOf(t)<0&&n.push(t),this.styles.push(e)}}),this.normalizeLists=!this.tags.some(t=>{if(!/^(ul|ol)\b/.test(t.tag)||!t.node)return!1;let n=e.nodes[t.node];return n.contentMatch.matchType(n)})}parse(e,t={}){let n=new ft(this,t,!1);return n.addAll(e,w.none,t.from,t.to),n.finish()}parseSlice(e,t={}){let n=new ft(this,t,!0);return n.addAll(e,w.none,t.from,t.to),T.maxOpen(n.finish())}matchTag(e,t,n){for(let r=n?this.tags.indexOf(n)+1:0;re.length&&(a.charCodeAt(e.length)!=61||a.slice(e.length+1)!=t))){if(r.getAttrs){let e=r.getAttrs(t);if(e===!1)continue;r.attrs=e||void 0}return r}}}static schemaRules(e){let t=[];function n(e){let n=e.priority==null?50:e.priority,r=0;for(;r{n(e=ht(e)),e.mark||e.ignore||e.clearMark||(e.mark=t)})}for(let t in e.nodes){let r=e.nodes[t].spec.parseDOM;r&&r.forEach(e=>{n(e=ht(e)),e.node||e.ignore||e.mark||(e.node=t)})}return t}static fromSchema(t){return t.cached.domParser||(t.cached.domParser=new e(t,e.schemaRules(t)))}},it={address:!0,article:!0,aside:!0,blockquote:!0,body:!0,canvas:!0,dd:!0,div:!0,dl:!0,fieldset:!0,figcaption:!0,figure:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,li:!0,noscript:!0,ol:!0,output:!0,p:!0,pre:!0,section:!0,table:!0,tfoot:!0,ul:!0},at={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},ot={ol:!0,ul:!0},st=1,ct=2,lt=4;function ut(e,t,n){return t==null?e&&e.whitespace==`pre`?3:n&-5:(t?st:0)|(t===`full`?ct:0)}var dt=class{constructor(e,t,n,r,i,a){this.type=e,this.attrs=t,this.marks=n,this.solid=r,this.options=a,this.content=[],this.activeMarks=w.none,this.match=i||(a<?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(C.from(e));if(t)this.match=this.type.contentMatch.matchFragment(t);else{let t=this.type.contentMatch,n;return(n=t.findWrapping(e.type))?(this.match=t,n):null}}return this.match.findWrapping(e.type)}finish(e){if(!(this.options&st)){let e=this.content[this.content.length-1],t;if(e&&e.isText&&(t=/[ \t\r\n\u000c]+$/.exec(e.text))){let n=e;e.text.length==t[0].length?this.content.pop():this.content[this.content.length-1]=n.withText(n.text.slice(0,n.text.length-t[0].length))}}let t=C.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(C.empty,!0))),this.type?this.type.create(this.attrs,t,this.marks):t}inlineContext(e){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:e.parentNode&&!it.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}},ft=class{constructor(e,t,n){this.parser=e,this.options=t,this.isOpen=n,this.open=0,this.localPreserveWS=!1;let r=t.topNode,i,a=ut(null,t.preserveWhitespace,0)|(n?lt:0);i=r?new dt(r.type,r.attrs,w.none,!0,t.topMatch||r.type.contentMatch,a):n?new dt(null,null,w.none,!0,null,a):new dt(e.schema.topNodeType,null,w.none,!0,null,a),this.nodes=[i],this.find=t.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(e,t){e.nodeType==3?this.addTextNode(e,t):e.nodeType==1&&this.addElement(e,t)}addTextNode(e,t){let n=e.nodeValue,r=this.top,i=r.options&ct?`full`:this.localPreserveWS||(r.options&st)>0,{schema:a}=this.parser;if(i===`full`||r.inlineContext(e)||/[^ \t\r\n\u000c]/.test(n)){if(!i){if(n=n.replace(/[ \t\r\n\u000c]+/g,` `),/^[ \t\r\n\u000c]/.test(n)&&this.open==this.nodes.length-1){let t=r.content[r.content.length-1],i=e.previousSibling;(!t||i&&i.nodeName==`BR`||t.isText&&/[ \t\r\n\u000c]$/.test(t.text))&&(n=n.slice(1))}}else if(i===`full`)n=n.replace(/\r\n?/g,` `);else if(a.linebreakReplacement&&/[\r\n]/.test(n)&&this.top.findWrapping(a.linebreakReplacement.create())){let e=n.split(/\r?\n|\r/);for(let n=0;n!n.clearMark(e)):t.concat(this.parser.schema.marks[n.mark].create(n.attrs)),n.consuming===!1)e=n;else break}}return t}addElementByRule(e,t,n,r){let i,a;if(t.node)if(a=this.parser.schema.nodes[t.node],a.isLeaf)this.insertNode(a.create(t.attrs),n,e.nodeName==`BR`)||this.leafFallback(e,n);else{let e=this.enter(a,t.attrs||null,n,t.preserveWhitespace);e&&(i=!0,n=e)}else{let e=this.parser.schema.marks[t.mark];n=n.concat(e.create(t.attrs))}let o=this.top;if(a&&a.isLeaf)this.findInside(e);else if(r)this.addElement(e,n,r);else if(t.getContent)this.findInside(e),t.getContent(e,this.parser.schema).forEach(e=>this.insertNode(e,n,!1));else{let r=e;typeof t.contentElement==`string`?r=e.querySelector(t.contentElement):typeof t.contentElement==`function`?r=t.contentElement(e):t.contentElement&&(r=t.contentElement),this.findAround(e,r,!0),this.addAll(r,n),this.findAround(e,r,!1)}i&&this.sync(o)&&this.open--}addAll(e,t,n,r){let i=n||0;for(let a=n?e.childNodes[n]:e.firstChild,o=r==null?null:e.childNodes[r];a!=o;a=a.nextSibling,++i)this.findAtPoint(e,i),this.addDOM(a,t);this.findAtPoint(e,i)}findPlace(e,t,n){let r,i;for(let t=this.open,a=0;t>=0;t--){let o=this.nodes[t],s=o.findWrapping(e);if(s&&(!r||r.length>s.length+a)&&(r=s,i=o,!s.length))break;if(o.solid){if(n)break;a+=2}}if(!r)return null;this.sync(i);for(let e=0;e(a.type?a.type.allowsMarkType(t.type):gt(t.type,e))?(s=t.addToSet(s),!1):!0),this.nodes.push(new dt(e,t,s,r,null,o)),this.open++,n}closeExtra(e=!1){let t=this.nodes.length-1;if(t>this.open){for(;t>this.open;t--)this.nodes[t-1].content.push(this.nodes[t].finish(e));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(!!(this.isOpen||this.options.topOpen))}sync(e){for(let t=this.open;t>=0;t--)if(this.nodes[t]==e)return this.open=t,!0;else this.localPreserveWS&&(this.nodes[t].options|=st);return!1}get currentPos(){this.closeExtra();let e=0;for(let t=this.open;t>=0;t--){let n=this.nodes[t].content;for(let t=n.length-1;t>=0;t--)e+=n[t].nodeSize;t&&e++}return e}findAtPoint(e,t){if(this.find)for(let n=0;n-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let t=e.split(`/`),n=this.options.context,r=!this.isOpen&&(!n||n.parent.type==this.nodes[0].type),i=-(n?n.depth+1:0)+ +!r,a=(e,o)=>{for(;e>=0;e--){let s=t[e];if(s==``){if(e==t.length-1||e==0)continue;for(;o>=i;o--)if(a(e-1,o))return!0;return!1}else{let e=o>0||o==0&&r?this.nodes[o].type:n&&o>=i?n.node(o-i).type:null;if(!e||e.name!=s&&!e.isInGroup(s))return!1;o--}}return!0};return a(t.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let t=e.depth;t>=0;t--){let n=e.node(t).contentMatchAt(e.indexAfter(t)).defaultType;if(n&&n.isTextblock&&n.defaultAttrs)return n}for(let e in this.parser.schema.nodes){let t=this.parser.schema.nodes[e];if(t.isTextblock&&t.defaultAttrs)return t}}};function pt(e){for(let t=e.firstChild,n=null;t;t=t.nextSibling){let e=t.nodeType==1?t.nodeName.toLowerCase():null;e&&ot.hasOwnProperty(e)&&n?(n.appendChild(t),t=n):e==`li`?n=t:e&&(n=null)}}function mt(e,t){return(e.matches||e.msMatchesSelector||e.webkitMatchesSelector||e.mozMatchesSelector).call(e,t)}function ht(e){let t={};for(let n in e)t[n]=e[n];return t}function gt(e,t){let n=t.schema.nodes;for(let r in n){let i=n[r];if(!i.allowsMarkType(e))continue;let a=[],o=e=>{a.push(e);for(let n=0;n{if(i.length||e.marks.length){let n=0,a=0;for(;n=0;r--){let i=this.serializeMark(e.marks[r],e.isInline,t);i&&((i.contentDOM||i.dom).appendChild(n),n=i.dom)}return n}serializeMark(e,t,n={}){let r=this.marks[e.type.name];return r&&Ct(yt(n),r(e,t),null,e.attrs)}static renderSpec(e,t,n=null,r){return typeof t==`string`?{dom:e.createTextNode(t)}:Ct(e,t,n,r)}static fromSchema(t){return t.cached.domSerializer||(t.cached.domSerializer=new e(this.nodesFromSchema(t),this.marksFromSchema(t)))}static nodesFromSchema(e){let t=vt(e.nodes);return t.text||=e=>e.text,t}static marksFromSchema(e){return vt(e.marks)}};function vt(e){let t={};for(let n in e){let r=e[n].spec.toDOM;r&&(t[n]=r)}return t}function yt(e){return e.document||window.document}var bt=new WeakMap;function xt(e){let t=bt.get(e);return t===void 0&&bt.set(e,t=St(e)),t}function St(e){let t=null;function n(e){if(e&&typeof e==`object`)if(Array.isArray(e))if(typeof e[0]==`string`)t||=[],t.push(e);else for(let t=0;t-1)throw RangeError(`Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.`);let o=i.indexOf(` `);o>0&&(n=i.slice(0,o),i=i.slice(o+1));let s,c=n?e.createElementNS(n,i):e.createElement(i),l=t[1],u=1;if(l&&typeof l==`object`&&l.nodeType==null&&!Array.isArray(l)){u=2;for(let e in l)if(l[e]!=null){let t=e.indexOf(` `);t>0?c.setAttributeNS(e.slice(0,t),e.slice(t+1),l[e]):e==`style`&&c.style?c.style.cssText=l[e]:c.setAttribute(e,l[e])}}for(let i=u;iu)throw RangeError(`Content hole must be the only child of its parent node`);return{dom:c,contentDOM:c}}else if(typeof a==`string`)c.appendChild(e.createTextNode(a));else{let{dom:t,contentDOM:i}=Ct(e,a,n,r);if(c.appendChild(t),i){if(s)throw RangeError(`Multiple content holes`);s=i}}}return{dom:c,contentDOM:s}}var wt=65535,Tt=2**16;function Et(e,t){return e+t*Tt}function Dt(e){return e&wt}function Ot(e){return(e-(e&wt))/Tt}var kt=1,At=2,jt=4,Mt=8,Nt=class{constructor(e,t,n){this.pos=e,this.delInfo=t,this.recover=n}get deleted(){return(this.delInfo&Mt)>0}get deletedBefore(){return(this.delInfo&5)>0}get deletedAfter(){return(this.delInfo&6)>0}get deletedAcross(){return(this.delInfo&jt)>0}},Pt=class e{constructor(t,n=!1){if(this.ranges=t,this.inverted=n,!t.length&&e.empty)return e.empty}recover(e){let t=0,n=Dt(e);if(!this.inverted)for(let e=0;ee)break;let c=this.ranges[o+i],l=this.ranges[o+a],u=s+c;if(e<=u){let i=c?e==s?-1:e==u?1:t:t,a=s+r+(i<0?0:l);if(n)return a;let d=e==(t<0?s:u)?null:Et(o/3,e-s),f=e==s?At:e==u?kt:jt;return(t<0?e!=s:e!=u)&&(f|=Mt),new Nt(a,f,d)}r+=l-c}return n?e+r:new Nt(e+r,0,null)}touches(e,t){let n=0,r=Dt(t),i=this.inverted?2:1,a=this.inverted?1:2;for(let t=0;te)break;let s=this.ranges[t+i];if(e<=o+s&&t==r*3)return!0;n+=this.ranges[t+a]-s}return!1}forEach(e){let t=this.inverted?2:1,n=this.inverted?1:2;for(let r=0,i=0;r=0;t--){let r=e.getMirror(t);this.appendMap(e._maps[t].invert(),r!=null&&r>t?n-r-1:void 0)}}invert(){let t=new e;return t.appendMappingInverted(this),t}map(e,t=1){if(this.mirror)return this._map(e,t,!0);for(let n=this.from;nn&&t!e.isAtom||!t.type.allowsMarkType(this.mark.type)?e:e.mark(this.mark.addToSet(e.marks)),r),t.openStart,t.openEnd);return D.fromReplace(e,this.from,this.to,i)}invert(){return new zt(this.from,this.to,this.mark)}map(t){let n=t.mapResult(this.from,1),r=t.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new e(n.pos,r.pos,this.mark)}merge(t){return t instanceof e&&t.mark.eq(this.mark)&&this.from<=t.to&&this.to>=t.from?new e(Math.min(this.from,t.from),Math.max(this.to,t.to),this.mark):null}toJSON(){return{stepType:`addMark`,mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(t,n){if(typeof n.from!=`number`||typeof n.to!=`number`)throw RangeError(`Invalid input for AddMarkStep.fromJSON`);return new e(n.from,n.to,t.markFromJSON(n.mark))}};E.jsonID(`addMark`,Rt);var zt=class e extends E{constructor(e,t,n){super(),this.from=e,this.to=t,this.mark=n}apply(e){let t=e.slice(this.from,this.to),n=new T(Lt(t.content,e=>e.mark(this.mark.removeFromSet(e.marks)),e),t.openStart,t.openEnd);return D.fromReplace(e,this.from,this.to,n)}invert(){return new Rt(this.from,this.to,this.mark)}map(t){let n=t.mapResult(this.from,1),r=t.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new e(n.pos,r.pos,this.mark)}merge(t){return t instanceof e&&t.mark.eq(this.mark)&&this.from<=t.to&&this.to>=t.from?new e(Math.min(this.from,t.from),Math.max(this.to,t.to),this.mark):null}toJSON(){return{stepType:`removeMark`,mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(t,n){if(typeof n.from!=`number`||typeof n.to!=`number`)throw RangeError(`Invalid input for RemoveMarkStep.fromJSON`);return new e(n.from,n.to,t.markFromJSON(n.mark))}};E.jsonID(`removeMark`,zt);var Bt=class e extends E{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return D.fail(`No node at mark step's position`);let n=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return D.fromReplace(e,this.pos,this.pos+1,new T(C.from(n),0,+!t.isLeaf))}invert(t){let n=t.nodeAt(this.pos);if(n){let t=this.mark.addToSet(n.marks);if(t.length==n.marks.length){for(let r=0;rr.pos?null:new e(n.pos,r.pos,i,a,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:`replaceAround`,from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(t,n){if(typeof n.from!=`number`||typeof n.to!=`number`||typeof n.gapFrom!=`number`||typeof n.gapTo!=`number`||typeof n.insert!=`number`)throw RangeError(`Invalid input for ReplaceAroundStep.fromJSON`);return new e(n.from,n.to,n.gapFrom,n.gapTo,T.fromJSON(t,n.slice),n.insert,!!n.structure)}};E.jsonID(`replaceAround`,O);function Ut(e,t,n){let r=e.resolve(t),i=n-t,a=r.depth;for(;i>0&&a>0&&r.indexAfter(a)==r.node(a).childCount;)a--,i--;if(i>0){let e=r.node(a).maybeChild(r.indexAfter(a));for(;i>0;){if(!e||e.isLeaf)return!0;e=e.firstChild,i--}}return!1}function Wt(e,t,n,r){let i=[],a=[],o,s;e.doc.nodesBetween(t,n,(e,c,l)=>{if(!e.isInline)return;let u=e.marks;if(!r.isInSet(u)&&l.type.allowsMarkType(r.type)){let l=Math.max(c,t),d=Math.min(c+e.nodeSize,n),f=r.addToSet(u);for(let e=0;ee.step(t)),a.forEach(t=>e.step(t))}function Gt(e,t,n,r){let i=[],a=0;e.doc.nodesBetween(t,n,(e,o)=>{if(!e.isInline)return;a++;let s=null;if(r instanceof Qe){let t=e.marks,n;for(;n=r.isInSet(t);)(s||=[]).push(n),t=n.removeFromSet(t)}else r?r.isInSet(e.marks)&&(s=[r]):s=e.marks;if(s&&s.length){let r=Math.min(o+e.nodeSize,n);for(let e=0;ee.step(new zt(t.from,t.to,t.style)))}function Kt(e,t,n,r=n.contentMatch,i=!0){let a=e.doc.nodeAt(t),o=[],s=t+1;for(let t=0;t=0;t--)e.step(o[t])}function qt(e,t,n){return(t==0||e.canReplace(t,e.childCount))&&(n==e.childCount||e.canReplace(0,n))}function Jt(e){let t=e.parent.content.cutByIndex(e.startIndex,e.endIndex);for(let n=e.depth,r=0,i=0;;--n){let a=e.$from.node(n),o=e.$from.index(n)+r,s=e.$to.indexAfter(n)-i;if(nn;e--)t||r.index(e)>0?(t=!0,u=C.from(r.node(e).copy(u)),d++):c--;let f=C.empty,p=0;for(let e=a,t=!1;e>n;e--)t||i.after(e+1)=0;e--){if(r.size){let t=n[e].type.contentMatch.matchFragment(r);if(!t||!t.validEnd)throw RangeError(`Wrapper type given to Transform.wrap does not form valid content of its parent wrapper`)}r=C.from(n[e].type.create(n[e].attrs,r))}let i=t.start,a=t.end;e.step(new O(i,a,i,a,new T(r,0,0),n.length,!0))}function tn(e,t,n,r,i){if(!r.isTextblock)throw RangeError(`Type given to setBlockType should be a textblock`);let a=e.steps.length;e.doc.nodesBetween(t,n,(t,n)=>{let o=typeof i==`function`?i(t):i;if(t.isTextblock&&!t.hasMarkup(r,o)&&an(e.doc,e.mapping.slice(a).map(n),r)){let i=null;if(r.schema.linebreakReplacement){let e=r.whitespace==`pre`,t=!!r.contentMatch.matchType(r.schema.linebreakReplacement);e&&!t?i=!1:!e&&t&&(i=!0)}i===!1&&rn(e,t,n,a),Kt(e,e.mapping.slice(a).map(n,1),r,void 0,i===null);let s=e.mapping.slice(a),c=s.map(n,1),l=s.map(n+t.nodeSize,1);return e.step(new O(c,l,c+1,l-1,new T(C.from(r.create(o,null,t.marks)),0,0),1,!0)),i===!0&&nn(e,t,n,a),!1}})}function nn(e,t,n,r){t.forEach((i,a)=>{if(i.isText){let o,s=/\r?\n|\r/g;for(;o=s.exec(i.text);){let i=e.mapping.slice(r).map(n+1+a+o.index);e.replaceWith(i,i+1,t.type.schema.linebreakReplacement.create())}}})}function rn(e,t,n,r){t.forEach((i,a)=>{if(i.type==i.type.schema.linebreakReplacement){let i=e.mapping.slice(r).map(n+1+a);e.replaceWith(i,i+1,t.type.schema.text(` diff --git a/static/assets/SettingsPage-CF4BZl3e.js b/static/assets/SettingsPage-DCvPzv7P.js similarity index 99% rename from static/assets/SettingsPage-CF4BZl3e.js rename to static/assets/SettingsPage-DCvPzv7P.js index bcab0afc1..c8b063694 100644 --- a/static/assets/SettingsPage-CF4BZl3e.js +++ b/static/assets/SettingsPage-DCvPzv7P.js @@ -1,4 +1,4 @@ -import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,b as i,f as a,l as o,t as s,v as c,w as l}from"./client-DnySrlFv.js";import{n as u}from"./QueryClientProvider-Ce8_sN3w.js";import{t as d}from"./useQuery-BBCjCezC.js";import{t as f}from"./useMutation-B-Tr2hIP.js";import{t as p}from"./useQueries-Be6PMvSC.js";import{t as m}from"./createLucideIcon-DvBYJlWL.js";import{a as h,i as g,l as _,n as v,o as y,r as b,t as x,u as S}from"./haSensorDisplay-lPbcOxD8.js";import{t as C}from"./briefcase-Dau7xqMY.js";import{t as w}from"./calendar-BLKPnWqV.js";import{t as T}from"./check-Ck0cMLU4.js";import{a as E,i as D,n as O,r as k,t as A}from"./info-ROUoQhJR.js";import{n as ee,r as j}from"./ToastContext-BRX0SW3C.js";import{t as M}from"./cog-Dol1I0kq.js";import{t as N}from"./copy-Cu_0GKCU.js";import{t as P}from"./cpu-BKWEtc8k.js";import{t as te}from"./dollar-sign-Cj_Yhud4.js";import{t as F}from"./eye-off-6CkaxYwP.js";import{t as ne}from"./gauge-D21zgWMb.js";import{t as I}from"./grip-vertical-C_1RDxRw.js";import{t as re}from"./hard-drive-CgXAHN37.js";import{t as ie}from"./history-B4lOLL01.js";import{t as L}from"./layout-grid-DkD3u6wa.js";import{t as ae}from"./link-2-MI-QCMh8.js";import{t as R}from"./loader-circle-BEmFtawu.js";import{t as z}from"./lock-MLqgWH4Q.js";import{_ as oe,a as se,c as B,d as ce,f as le,g as ue,h as de,i as fe,l as V,m as pe,n as me,o as he,p as ge,r as _e,s as ve,t as ye,u as be,v as H}from"./locationSensorDefaults-Bb4u9P8m.js";import{c as xe,l as Se,o as Ce,t as we,u as Te}from"./CopyButton-C5In5weo.js";import{t as Ee}from"./package-BGUevlqS.js";import{t as De}from"./play-DIDYtk2S.js";import{t as Oe}from"./qr-code-CCCo2-Br.js";import{t as ke}from"./scale-CD6XdXUk.js";import{t as Ae}from"./search-0n0CBc74.js";import{t as je}from"./settings-2-Cvn837lh.js";import{t as Me}from"./shield-bODVqOJd.js";import{t as Ne}from"./skip-forward-BsuMfFkw.js";import{t as Pe}from"./smartphone-DaDGaGLT.js";import{n as Fe}from"./wind-CI8UoBMf.js";import{t as Ie}from"./triangle-alert-Dt_1FcBy.js";import{t as Le}from"./workflow-BgT0wW83.js";import{t as Re}from"./x-DR-Trv6U.js";import{i as U,n as W,r as ze,t as G}from"./Card-Bzc64K35.js";import{t as K}from"./Button-DDr6eAFy.js";import{a as Be,f as Ve,i as He,u as Ue,v as We}from"./date-G9KUauqz.js";import{t as Ge}from"./filamentSwatchHelpers-D3oXQSGk.js";import{$t as Ke,An as q,At as qe,Cn as Je,Ct as Ye,Dn as Xe,Dt as Ze,En as Qe,Et as $e,Ft as et,Gn as tt,Gt as nt,In as rt,Jt as it,Kt as at,Ln as ot,Mn as st,N as ct,On as lt,Pn as ut,Qt as dt,Rn as ft,S as pt,Sn as mt,St as ht,Tn as gt,Ut as _t,Vn as vt,Vt as yt,Wn as bt,Wt as xt,Xt as St,Yt as Ct,Zt as wt,_t as Tt,at as Et,bn as Dt,bt as Ot,c as kt,cn as At,d as jt,dn as Mt,en as Nt,f as Pt,fn as Ft,gn as It,gt as Lt,h as Rt,hn as zt,ht as Bt,in as Vt,it as Ht,kn as Ut,kt as Wt,l as Gt,ln as Kt,m as qt,nn as Jt,nt as Yt,o as Xt,on as Zt,p as Qt,pn as $t,qt as en,rn as tn,rt as nn,u as rn,vt as an,w as on,wn as sn,x as cn,xn as ln,yt as un}from"./index-0t--Yqoi.js";import{t as J}from"./Toggle-KiqA_5fU.js";import{a as dn,i as fn,n as pn,r as mn,s as hn,t as gn}from"./OverlayFrame-fLmufrTC.js";var _n=m(`arrow-right-left`,[[`path`,{d:`m16 3 4 4-4 4`,key:`1x1c3m`}],[`path`,{d:`M20 7H4`,key:`zbl0bi`}],[`path`,{d:`m8 21-4-4 4-4`,key:`h9nckh`}],[`path`,{d:`M4 17h16`,key:`g4d7ey`}]]),vn=m(`camera-off`,[[`path`,{d:`M14.564 14.558a3 3 0 1 1-4.122-4.121`,key:`1rnrzw`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M20 20H4a2 2 0 0 1-2-2V9a2 2 0 0 1 2-2h1.997a2 2 0 0 0 .819-.175`,key:`1x3arw`}],[`path`,{d:`M9.695 4.024A2 2 0 0 1 10.004 4h3.993a2 2 0 0 1 1.76 1.05l.486.9A2 2 0 0 0 18.003 7H20a2 2 0 0 1 2 2v7.344`,key:`1i84u0`}]]),yn=m(`cloud-upload`,[[`path`,{d:`M12 13v8`,key:`1l5pq0`}],[`path`,{d:`M4 14.899A7 7 0 1 1 15.71 8h1.79a4.5 4.5 0 0 1 2.5 8.242`,key:`1pljnt`}],[`path`,{d:`m8 17 4-4 4 4`,key:`1quai1`}]]),bn=m(`cylinder`,[[`ellipse`,{cx:`12`,cy:`5`,rx:`9`,ry:`3`,key:`msslwz`}],[`path`,{d:`M3 5v14a9 3 0 0 0 18 0V5`,key:`aqi0yr`}]]),xn=m(`folder-archive`,[[`circle`,{cx:`15`,cy:`19`,r:`2`,key:`u2pros`}],[`path`,{d:`M20.9 19.8A2 2 0 0 0 22 18V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2h5.1`,key:`1jj40k`}],[`path`,{d:`M15 11v-1`,key:`cntcp`}],[`path`,{d:`M15 17v-2`,key:`1279jj`}]]),Sn=m(`send`,[[`path`,{d:`M14.536 21.686a.5.5 0 0 0 .937-.024l6.5-19a.496.496 0 0 0-.635-.635l-19 6.5a.5.5 0 0 0-.024.937l7.93 3.18a2 2 0 0 1 1.112 1.11z`,key:`1ffxy3`}],[`path`,{d:`m21.854 2.147-10.94 10.939`,key:`12cjpa`}]]),Cn=m(`shield-check`,[[`path`,{d:`M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z`,key:`oel41y`}],[`path`,{d:`m9 12 2 2 4-4`,key:`dzmm74`}]]),wn=m(`shield-off`,[[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M5 5a1 1 0 0 0-1 1v7c0 5 3.5 7.5 7.67 8.94a1 1 0 0 0 .67.01c2.35-.82 4.48-1.97 5.9-3.71`,key:`1jlk70`}],[`path`,{d:`M9.309 3.652A12.252 12.252 0 0 0 11.24 2.28a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1v7a9.784 9.784 0 0 1-.08 1.264`,key:`18rp1v`}]]),Tn=m(`tags`,[[`path`,{d:`M13.172 2a2 2 0 0 1 1.414.586l6.71 6.71a2.4 2.4 0 0 1 0 3.408l-4.592 4.592a2.4 2.4 0 0 1-3.408 0l-6.71-6.71A2 2 0 0 1 6 9.172V3a1 1 0 0 1 1-1z`,key:`16rjxf`}],[`path`,{d:`M2 7v6.172a2 2 0 0 0 .586 1.414l6.71 6.71a2.4 2.4 0 0 0 3.191.193`,key:`178nd4`}],[`circle`,{cx:`10.5`,cy:`6.5`,r:`.5`,fill:`currentColor`,key:`12ikhr`}]]);function En(e){return e.length<8?`tooShort`:/[A-Z]/.test(e)?/[a-z]/.test(e)?/\d/.test(e)?/[^A-Za-z0-9]/.test(e)?null:`needsSpecial`:`needsDigit`:`needsLowercase`:`needsUppercase`}var Dn={PLA:0,PETG:0,"PETG-CF":40,ABS:45,ASA:45,PA:50,"PA-CF":55,PC:50,"PC-FR":50,TPU:0,PVA:0,default:0},On=[`PA-CF`,`PA`,`PC`,`PC-FR`,`ABS`,`ASA`,`PETG-CF`,`PETG`,`PLA`,`TPU`,`PVA`,`default`];function kn(e){if(!e)return{...Dn};try{let t=JSON.parse(e);if(t&&typeof t==`object`&&!Array.isArray(t)){let e={};for(let[n,r]of Object.entries(t)){let t=typeof r==`number`?r:Number(r);Number.isFinite(t)&&(e[n]=Math.max(0,Math.min(65,Math.round(t))))}return e.default===void 0&&(e.default=Dn.default),e}}catch{}return{...Dn}}function An(e){let t={};for(let n of On)e[n]!==void 0&&(t[n]=e[n]);for(let[n,r]of Object.entries(e))n in t||(t[n]=r);return JSON.stringify(t)}var Y=t();function jn({value:e,onChange:t,disabled:n=!1}){let{t:r}=l(),i=kn(e),a=(e,n)=>{let r=Math.max(0,Math.min(65,Math.round(n)));t(An({...i,[e]:r}))};return(0,Y.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-x-3 gap-y-1.5`,children:On.map(e=>{let t=i[e]??Dn[e]??0,o=e==="default"?r(`settings.preheatFilamentTargetsDefaultRow`,`Other / unmapped`):e;return(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Y.jsx)(`span`,{className:`text-xs ${e==="default"?`text-bambu-gray italic`:`text-bambu-gray`}`,children:o}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Y.jsx)(`input`,{type:`number`,min:0,max:65,step:1,value:t,onChange:t=>a(e,parseInt(t.target.value,10)||0),disabled:n,className:`w-16 px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-xs text-right focus:outline-none focus:border-bambu-green disabled:opacity-50`}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:`°C`})]})]},e)})})}var X=e(n(),1);function Mn(e,t,n){if(!e)return null;let r=(e[n.source]?.[t]??[]).find(e=>e.id===n.id);return r?r.name:null}var Nn={orca_cloud:`Orca Cloud`,cloud:`Bambu Cloud`,local:`Imported`,standard:`Standard`};function Pn(){let{t:e}=l(),t=u(),{showToast:n}=ee(),{data:i,isLoading:a,error:o}=d({queryKey:[`slicer-pipelines`],queryFn:()=>r.listSlicerPipelines()}),{data:s}=d({queryKey:[`slicer-presets`],queryFn:()=>r.getSlicerPresets()}),{data:c}=d({queryKey:[`printers`],queryFn:()=>r.getPrinters()}),p=f({mutationFn:({id:e,name:t,description:n,target_printer_id:i,target_kind:a,target_model_class:o,fanout_strategy:s})=>r.updateSlicerPipeline(e,{name:t,description:n,target_printer_id:i,target_kind:a,target_model_class:o,fanout_strategy:s}),onSuccess:()=>{t.invalidateQueries({queryKey:[`slicer-pipelines`]}),n(e(`settings.pipelines.toast.saved`,`Pipeline saved`),`success`)},onError:t=>{n(t.message||e(`settings.pipelines.toast.saveFailed`,`Save failed`),`error`)}}),m=f({mutationFn:e=>r.deleteSlicerPipeline(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`slicer-pipelines`]}),n(e(`settings.pipelines.toast.deleted`,`Pipeline deleted`),`success`)},onError:t=>{n(t.message||e(`settings.pipelines.toast.deleteFailed`,`Delete failed`),`error`)}}),[h,g]=(0,X.useState)(``),[_,v]=(0,X.useState)(``),y=(0,X.useMemo)(()=>i?.pipelines??[],[i?.pipelines]),b=(0,X.useMemo)(()=>{let e=new Set,t=new Set,n=!1;for(let r of y)r.target_kind===`printer_class`&&r.target_model_class?t.add(r.target_model_class):r.target_printer_id?e.add(r.target_printer_id):n=!0;return{printers:(c??[]).filter(t=>e.has(t.id)),classes:Array.from(t).sort(),anyWithoutTarget:n}},[y,c]),x=(0,X.useMemo)(()=>{let e=h.trim().toLowerCase();return y.filter(t=>{if(e&&!t.name.toLowerCase().includes(e))return!1;if(_===`none`){if(t.target_kind===`printer_class`?t.target_model_class:t.target_printer_id!==null)return!1}else if(_.startsWith(`p:`)){let e=parseInt(_.slice(2),10);if(t.target_kind===`printer_class`||t.target_printer_id!==e)return!1}else if(_.startsWith(`c:`)){let e=_.slice(2);if(t.target_kind!==`printer_class`||t.target_model_class!==e)return!1}return!0})},[y,h,_]);return(0,Y.jsxs)(G,{children:[(0,Y.jsxs)(U,{children:[(0,Y.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,Y.jsx)(Le,{className:`w-4 h-4 text-bambu-green`}),e(`settings.pipelines.title`,`Slicer Pipelines`)]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`settings.pipelines.subtitle`,`Reusable preset bundles (printer + process + filaments + bed type). Save one from the Slice dialog and apply it with a single click on the next file.`)})]}),(0,Y.jsxs)(W,{children:[a&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-bambu-gray`,children:[(0,Y.jsx)(R,{className:`w-4 h-4 animate-spin`}),e(`settings.pipelines.loading`,`Loading pipelines…`)]}),o&&(0,Y.jsx)(`div`,{className:`text-sm text-red-700 dark:text-red-400`,children:e(`settings.pipelines.loadError`,`Could not load pipelines.`)}),!a&&!o&&y.length>0&&(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 mb-3`,children:[(0,Y.jsxs)(`div`,{className:`relative flex-1 min-w-[12rem]`,children:[(0,Y.jsx)(Ae,{className:`absolute left-2 top-1/2 -translate-y-1/2 w-3.5 h-3.5 text-bambu-gray pointer-events-none`}),(0,Y.jsx)(`input`,{type:`search`,value:h,onChange:e=>g(e.target.value),placeholder:e(`settings.pipelines.searchPlaceholder`,`Search pipelines…`),"aria-label":e(`settings.pipelines.searchPlaceholder`,`Search pipelines…`),className:`w-full pl-7 pr-2 py-1 text-xs bg-bambu-dark border border-bambu-dark-tertiary rounded text-white`})]}),(0,Y.jsxs)(`select`,{value:_,onChange:e=>v(e.target.value),"aria-label":e(`settings.pipelines.filterTarget`,`Filter by target`),className:`text-xs px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white`,children:[(0,Y.jsx)(`option`,{value:``,children:e(`settings.pipelines.filter.all`,`All targets`)}),b.printers.length>0&&(0,Y.jsx)(`optgroup`,{label:e(`settings.pipelines.field.targetKindSpecific`,`Specific printer`),children:b.printers.map(e=>(0,Y.jsx)(`option`,{value:`p:${e.id}`,children:e.name},`p-${e.id}`))}),b.classes.length>0&&(0,Y.jsx)(`optgroup`,{label:e(`settings.pipelines.field.targetKindClass`,`Printer class`),children:b.classes.map(t=>(0,Y.jsx)(`option`,{value:`c:${t}`,children:e(`library.runWithPipeline.classTarget`,`Any {{model}}`,{model:t})},`c-${t}`))}),b.anyWithoutTarget&&(0,Y.jsx)(`option`,{value:`none`,children:e(`settings.pipelines.filter.noTarget`,`No target set`)})]}),(h||_)&&(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:e(`settings.pipelines.filter.count`,`{{shown}} / {{total}}`,{shown:x.length,total:y.length})})]}),!a&&!o&&y.length===0&&(0,Y.jsxs)(`div`,{className:`text-sm text-bambu-gray space-y-2`,children:[(0,Y.jsx)(`p`,{children:e(`settings.pipelines.empty.title`,`No pipelines yet.`)}),(0,Y.jsx)(`p`,{children:e(`settings.pipelines.empty.howto`,`Open the Slice dialog for any file, pick your printer / process / filaments / bed type, then click "Save as pipeline". Your saved pipelines will appear here.`)})]}),!a&&!o&&y.length>0&&x.length===0&&(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`settings.pipelines.filter.noMatches`,`No pipelines match the current filters.`)}),!a&&!o&&x.length>0&&(0,Y.jsx)(`div`,{className:`space-y-2`,children:x.map(t=>(0,Y.jsx)(Fn,{pipeline:t,presets:s,printers:c??[],onSave:e=>p.mutate({id:t.id,...e}),onDelete:()=>{confirm(e(`settings.pipelines.confirmDelete`,`Delete this pipeline? This cannot be undone.`))&&m.mutate(t.id)},saving:p.isPending,deleting:m.isPending},t.id))})]})]})}function Fn({pipeline:e,presets:t,printers:n,onSave:i,onDelete:a,saving:o,deleting:s}){let{t:c}=l(),[u,f]=(0,X.useState)(!1),[p,m]=(0,X.useState)(e.name),[h,g]=(0,X.useState)(e.description??``),[_,v]=(0,X.useState)(e.target_printer_id),[y,b]=(0,X.useState)(e.target_kind===`printer_class`?`printer_class`:`specific_printer`),[x,S]=(0,X.useState)(e.target_model_class??``),[C,w]=(0,X.useState)(e.fanout_strategy??`max_parallel`),E=Array.from(new Set(n.map(e=>e.model).filter(e=>!!e))).sort(),{data:D}=d({queryKey:[`pipeline-runs`,e.id],queryFn:()=>r.listPipelineRuns(e.id,1),enabled:!u,refetchInterval:15e3}),O=D?.runs?.[0],k=Mn(t,`printer`,e.printer_preset),A=Mn(t,`process`,e.process_preset),ee=e.filament_presets.map(e=>Mn(t,`filament`,e)),j=e.filament_presets.length>1&&e.filament_presets.every(t=>t.source===e.filament_presets[0].source&&t.id===e.filament_presets[0].id),M=t!==void 0&&(k===null||A===null||ee.some(e=>e===null)),N=e.target_printer_id?n.find(t=>t.id===e.target_printer_id):void 0,P=e.target_kind===`printer_class`,te=P?!e.target_model_class:e.target_printer_id===null;return(0,Y.jsxs)(`div`,{className:`rounded-md border border-bambu-dark-tertiary bg-bambu-dark/40 px-3 py-2`,children:[(0,Y.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,Y.jsx)(`div`,{className:`min-w-0 flex-1`,children:u?(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(`input`,{value:p,onChange:e=>m(e.target.value),"aria-label":c(`settings.pipelines.field.name`,`Pipeline name`),placeholder:c(`settings.pipelines.field.name`,`Pipeline name`),className:`w-full px-2 py-1 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded text-white`}),(0,Y.jsx)(`textarea`,{value:h,onChange:e=>g(e.target.value),"aria-label":c(`settings.pipelines.field.description`,`Description`),placeholder:c(`settings.pipelines.field.description`,`Description`),rows:2,className:`w-full px-2 py-1 text-xs bg-bambu-dark border border-bambu-dark-tertiary rounded text-white`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`text-xs text-bambu-gray block mb-1`,children:c(`settings.pipelines.field.targetKind`,`Target type`)}),(0,Y.jsxs)(`div`,{className:`flex gap-3 text-xs`,children:[(0,Y.jsxs)(`label`,{className:`flex items-center gap-1 text-white`,children:[(0,Y.jsx)(`input`,{type:`radio`,name:`target-kind-${e.id}`,value:`specific_printer`,checked:y===`specific_printer`,onChange:()=>b(`specific_printer`),"aria-label":c(`settings.pipelines.field.targetKindSpecific`,`Specific printer`)}),c(`settings.pipelines.field.targetKindSpecific`,`Specific printer`)]}),(0,Y.jsxs)(`label`,{className:`flex items-center gap-1 text-white`,children:[(0,Y.jsx)(`input`,{type:`radio`,name:`target-kind-${e.id}`,value:`printer_class`,checked:y===`printer_class`,onChange:()=>b(`printer_class`),"aria-label":c(`settings.pipelines.field.targetKindClass`,`Printer class`)}),c(`settings.pipelines.field.targetKindClass`,`Printer class`)]})]})]}),y===`specific_printer`?(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`text-xs text-bambu-gray block mb-1`,children:c(`settings.pipelines.field.targetPrinter`,`Target printer`)}),(0,Y.jsxs)(`select`,{value:_??``,onChange:e=>v(e.target.value?parseInt(e.target.value,10):null),"aria-label":c(`settings.pipelines.field.targetPrinter`,`Target printer`),className:`w-full px-2 py-1 text-xs bg-bambu-dark border border-bambu-dark-tertiary rounded text-white`,children:[(0,Y.jsx)(`option`,{value:``,children:c(`settings.pipelines.field.noTarget`,`— No target —`)}),n.map(e=>(0,Y.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}):(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`text-xs text-bambu-gray block mb-1`,children:c(`settings.pipelines.field.targetModelClass`,`Printer model`)}),(0,Y.jsxs)(`select`,{value:x,onChange:e=>S(e.target.value),"aria-label":c(`settings.pipelines.field.targetModelClass`,`Printer model`),className:`w-full px-2 py-1 text-xs bg-bambu-dark border border-bambu-dark-tertiary rounded text-white`,children:[(0,Y.jsx)(`option`,{value:``,children:c(`settings.pipelines.field.noTarget`,`— No target —`)}),E.map(e=>(0,Y.jsx)(`option`,{value:e,children:e},e))]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`text-xs text-bambu-gray block mb-1`,children:c(`settings.pipelines.field.fanoutStrategy`,`Fanout strategy`)}),(0,Y.jsxs)(`select`,{value:C,onChange:e=>w(e.target.value),"aria-label":c(`settings.pipelines.field.fanoutStrategy`,`Fanout strategy`),className:`w-full px-2 py-1 text-xs bg-bambu-dark border border-bambu-dark-tertiary rounded text-white`,children:[(0,Y.jsx)(`option`,{value:`max_parallel`,children:c(`settings.pipelines.field.fanout.max_parallel`,`Max parallel — distribute across any idle matching printer`)}),(0,Y.jsx)(`option`,{value:`round_robin`,children:c(`settings.pipelines.field.fanout.round_robin`,`Round robin — cycle through eligible printers`)}),(0,Y.jsx)(`option`,{value:`fill_one_first`,children:c(`settings.pipelines.field.fanout.fill_one_first`,`Fill one first — pin all copies to one printer`)})]})]})]})]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2 gap-y-1`,children:[(0,Y.jsx)(`h4`,{className:`text-sm font-medium text-white truncate`,children:e.name}),(0,Y.jsxs)(`span`,{className:`text-xs px-1.5 py-0.5 rounded inline-flex items-center gap-1 ${te?`bg-amber-100 dark:bg-amber-500/15 text-amber-700 dark:text-amber-400`:`bg-bambu-dark-tertiary text-bambu-gray`}`,children:[(0,Y.jsx)(it,{className:`w-3 h-3`}),te?c(`settings.pipelines.noTargetHint`,`Set a target printer to run this`):P?(0,Y.jsxs)(Y.Fragment,{children:[c(`library.runWithPipeline.classTarget`,`Any {{model}}`,{model:e.target_model_class}),e.fanout_strategy&&(0,Y.jsxs)(`span`,{className:`text-bambu-gray/60`,children:[` · `,c(`settings.pipelines.field.fanoutShort.${e.fanout_strategy}`,e.fanout_strategy)]})]}):N?.name??``]})]}),e.description&&(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:e.description})]})}),(0,Y.jsx)(`div`,{className:`flex items-center gap-1 flex-shrink-0`,children:u?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`button`,{onClick:()=>{let e=p.trim();e&&(i({name:e,description:h.trim()||null,target_kind:y,target_printer_id:y===`specific_printer`?_??0:0,target_model_class:y===`printer_class`&&x||null,fanout_strategy:C}),f(!1))},disabled:o||!p.trim(),"aria-label":c(`settings.pipelines.action.save`,`Save`),className:`p-1.5 text-bambu-green hover:bg-bambu-dark-tertiary rounded disabled:opacity-50`,children:(0,Y.jsx)(T,{className:`w-4 h-4`})}),(0,Y.jsx)(`button`,{onClick:()=>{m(e.name),g(e.description??``),v(e.target_printer_id),b(e.target_kind===`printer_class`?`printer_class`:`specific_printer`),S(e.target_model_class??``),w(e.fanout_strategy??`max_parallel`),f(!1)},"aria-label":c(`settings.pipelines.action.cancel`,`Cancel`),className:`p-1.5 text-bambu-gray hover:bg-bambu-dark-tertiary rounded`,children:(0,Y.jsx)(Re,{className:`w-4 h-4`})})]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`button`,{onClick:()=>f(!0),"aria-label":c(`settings.pipelines.action.rename`,`Rename`),className:`p-1.5 text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary rounded`,children:(0,Y.jsx)(oe,{className:`w-4 h-4`})}),(0,Y.jsx)(`button`,{onClick:a,disabled:s,"aria-label":c(`settings.pipelines.action.delete`,`Delete`),className:`p-1.5 text-bambu-gray hover:text-red-600 dark:hover:text-red-400 hover:bg-bambu-dark-tertiary rounded disabled:opacity-50`,children:(0,Y.jsx)(qe,{className:`w-4 h-4`})})]})})]}),!u&&(0,Y.jsxs)(`div`,{className:`mt-2 grid grid-cols-1 md:grid-cols-2 gap-x-4 gap-y-2 text-xs`,children:[(0,Y.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,Y.jsx)(`div`,{className:`text-[10px] uppercase tracking-wide text-bambu-gray/60`,children:c(`settings.pipelines.group.profiles`,`Profiles`)}),(0,Y.jsx)(Ln,{label:c(`settings.pipelines.slot.printer`,`Printer`),ref:e.printer_preset,name:k}),(0,Y.jsx)(Ln,{label:c(`settings.pipelines.slot.process`,`Process`),ref:e.process_preset,name:A}),e.bed_type&&(0,Y.jsxs)(`div`,{className:`text-bambu-gray`,children:[(0,Y.jsxs)(`span`,{className:`font-medium text-bambu-gray/80`,children:[c(`settings.pipelines.slot.bed`,`Bed`),`:`]}),` `,(0,Y.jsx)(`span`,{className:`text-white`,children:e.bed_type})]})]}),(0,Y.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,Y.jsxs)(`div`,{className:`text-[10px] uppercase tracking-wide text-bambu-gray/60`,children:[c(`settings.pipelines.group.filaments`,`Filaments`),e.filament_presets.length>1&&(0,Y.jsxs)(`span`,{className:`text-bambu-gray/60 normal-case ml-1`,children:[`(`,e.filament_presets.length,`)`]})]}),j?(0,Y.jsx)(Ln,{label:c(`settings.pipelines.slot.filamentAll`,`All {{n}} slots`,{n:e.filament_presets.length}),ref:e.filament_presets[0],name:ee[0]}):e.filament_presets.map((t,n)=>(0,Y.jsx)(Ln,{label:e.filament_presets.length>1?c(`settings.pipelines.slot.filamentN`,`Filament {{n}}`,{n:n+1}):c(`settings.pipelines.slot.filament`,`Filament`),ref:t,name:ee[n]},n))]})]}),!u&&O&&(0,Y.jsxs)(`div`,{className:`mt-1.5 text-xs text-bambu-gray flex items-center gap-1`,children:[(0,Y.jsxs)(`span`,{className:`font-medium text-bambu-gray/80`,children:[c(`settings.pipelines.runs.lastRun`,`Last run`),`:`]}),` `,(0,Y.jsx)(In,{status:O.status}),O.created_at&&(0,Y.jsxs)(`span`,{className:`text-bambu-gray/60`,children:[`· `,new Date(O.created_at).toLocaleString()]})]}),te&&!u&&(0,Y.jsxs)(`div`,{className:`mt-2 flex items-center gap-1.5 text-xs text-amber-700 dark:text-amber-400`,children:[(0,Y.jsx)(Ie,{className:`w-3.5 h-3.5`}),c(`settings.pipelines.noTargetWarning`,`Set a target printer before running this pipeline.`)]}),M&&!u&&(0,Y.jsxs)(`div`,{className:`mt-2 flex items-center gap-1.5 text-xs text-amber-700 dark:text-amber-400`,children:[(0,Y.jsx)(Ie,{className:`w-3.5 h-3.5`}),c(`settings.pipelines.staleWarning`,`One or more referenced presets no longer exist. Re-save this pipeline from the Slice dialog to fix.`)]})]})}function In({status:e}){let{t}=l();return(0,Y.jsx)(`span`,{className:{queued:`text-bambu-gray`,slicing:`text-blue-700 dark:text-blue-400`,dispatching:`text-blue-700 dark:text-blue-400`,in_progress:`text-bambu-green`,completed:`text-bambu-green`,failed:`text-red-700 dark:text-red-400`,partial_failure:`text-amber-700 dark:text-amber-400`,cancelled:`text-bambu-gray`}[e],children:t(`settings.pipelines.runs.status.${e}`,e)})}function Ln({label:e,ref:t,name:n}){return(0,Y.jsxs)(`div`,{className:`text-bambu-gray truncate`,children:[(0,Y.jsxs)(`span`,{className:`font-medium text-bambu-gray/80`,children:[e,`:`]}),` `,n?(0,Y.jsx)(`span`,{className:`text-white`,children:n}):(0,Y.jsxs)(`span`,{className:`text-amber-700 dark:text-amber-400`,children:[`[`,Nn[t.source],` #`,t.id,`]`]})]})}var Rn=90,zn=365;function Bn(e){if(!e)return`—`;let t=We(e);return t?t.toLocaleString():`—`}function Vn(e){let t=We(e);return t?t.getTime(){if(l.preventDefault(),!(!o.trim()||p)){m(!0),n?.(!0);try{e(await r.createLongLivedCameraToken({name:o.trim(),expires_in_days:c,scope:t??d})),s(``),u(Rn),f(t??`camera_stream`),a(i(`cameraTokens.toast.created`,`Token created`))}catch(e){a(e instanceof Error&&e.message?e.message:i(`cameraTokens.toast.createFailed`,`Failed to create token`),`error`)}finally{m(!1),n?.(!1)}}},className:`@container/token-form min-w-0 bg-bambu-dark-secondary rounded-lg p-4 mb-6 border border-bambu-dark-tertiary`,children:[(0,Y.jsx)(`h3`,{className:`text-base font-semibold text-white mb-3`,children:i(`cameraTokens.create.title`,`Create new token`)}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 gap-3 @min-[26rem]/token-form:grid-cols-2 @min-[44rem]/token-form:grid-cols-[minmax(0,1fr)_180px_140px_auto]`,children:[(0,Y.jsx)(`input`,{type:`text`,maxLength:100,required:!0,value:o,onChange:e=>s(e.target.value),placeholder:i(`cameraTokens.create.namePlaceholder`,`e.g. Home Assistant`),className:`min-w-0 w-full px-3 py-2 bg-bambu-dark rounded-md text-white border border-bambu-dark-tertiary focus:border-bambu-green focus:outline-none`,"aria-label":i(`cameraTokens.create.nameLabel`,`Token name`)}),(0,Y.jsxs)(`select`,{value:d,disabled:!!t,onChange:e=>f(e.target.value),className:`min-w-0 w-full px-3 py-2 bg-bambu-dark rounded-md text-white border border-bambu-dark-tertiary focus:border-bambu-green focus:outline-none`,"aria-label":i(`cameraTokens.create.scopeLabel`,`Scope`),children:[(0,Y.jsx)(`option`,{value:`camera_stream`,children:i(`cameraTokens.scope.camera_stream`,`Camera stream`)}),(0,Y.jsx)(`option`,{value:`camwall`,children:i(`cameraTokens.scope.camwall`,`Cam Wall`)}),(0,Y.jsx)(`option`,{value:`overlay`,children:i(`cameraTokens.scope.overlay`,`Streaming Overlay`)})]}),(0,Y.jsx)(`input`,{type:`number`,min:1,max:zn,required:!0,value:c,onChange:e=>{let t=Number(e.target.value);u(Math.min(Math.max(t,1),zn))},className:`min-w-0 w-full px-3 py-2 bg-bambu-dark rounded-md text-white border border-bambu-dark-tertiary focus:border-bambu-green focus:outline-none`,"aria-label":i(`cameraTokens.create.daysLabel`,`Days until expiry`)}),(0,Y.jsxs)(`button`,{type:`submit`,disabled:p||!o.trim(),className:`min-w-0 flex items-center justify-center gap-2 px-4 py-2 bg-bambu-green text-white rounded-md hover:bg-bambu-green/90 disabled:opacity-50 disabled:cursor-not-allowed`,children:[(0,Y.jsx)(wt,{className:`w-4 h-4`}),i(`cameraTokens.create.submit`,`Create`)]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-2`,children:d===`camwall`?i(`cameraTokens.create.hintCamWall`,`A Cam Wall token opens /camwall on a screen with no login — it can see every printer's name and state, and their camera streams. It cannot see filenames, addresses or access codes.`):d===`overlay`?i(`cameraTokens.create.hintOverlay`,`A Streaming Overlay token opens /overlay/{printerId} on a screen with no login — for OBS or any live stream. It can see one printer's camera stream plus its live print status, including the filename shown on screen. It cannot see addresses or access codes.`):i(`cameraTokens.create.hintCameraStream`,`A camera-stream token can only fetch camera streams and snapshots. Use it for Home Assistant, Frigate, or anything embedding a single camera.`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`cameraTokens.create.hint`,`Maximum lifetime is 365 days. The token value is shown only once on creation — copy it now.`)})]})}function Un({token:e,onConfirm:t,onCancel:n}){let{t:r}=l();return(0,Y.jsx)(`div`,{className:`fixed inset-0 bg-black/60 flex items-center justify-center z-50 p-4`,role:`dialog`,"aria-modal":`true`,children:(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-6 max-w-md w-full border border-red-500/40`,children:[(0,Y.jsxs)(`div`,{className:`flex items-start gap-3 mb-4`,children:[(0,Y.jsx)(Ie,{className:`w-6 h-6 text-red-600 dark:text-red-400 flex-shrink-0 mt-0.5`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:r(`cameraTokens.confirmRevoke.title`,`Revoke this token?`)}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:r(`cameraTokens.confirmRevoke.body`,`Any device using "{{name}}" will lose access immediately. This cannot be undone.`,{name:e.name})})]})]}),(0,Y.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,Y.jsx)(`button`,{type:`button`,onClick:n,className:`px-4 py-2 bg-bambu-dark-tertiary text-white rounded-md hover:bg-bambu-dark-tertiary/80`,children:r(`cameraTokens.confirmRevoke.cancel`,`Cancel`)}),(0,Y.jsx)(`button`,{type:`button`,onClick:t,className:`px-4 py-2 bg-red-500 text-white rounded-md hover:bg-red-600`,children:r(`cameraTokens.confirmRevoke.confirm`,`Revoke`)})]})]})})}function Wn({token:e,onClose:t}){let{t:n}=l(),{showToast:r}=ee(),i=e.token??``,a=e.scope===`camwall`&&i?`${window.location.origin}/camwall?token=${encodeURIComponent(i)}`:null,o=e.scope===`overlay`&&i?`${window.location.origin}/overlay/1?token=${encodeURIComponent(i)}`:null,s=async e=>{if(e)try{if(navigator.clipboard&&window.isSecureContext)await navigator.clipboard.writeText(e);else{let t=document.createElement(`textarea`);t.value=e,t.style.position=`fixed`,t.style.opacity=`0`,document.body.appendChild(t);try{t.select(),document.execCommand(`copy`)}finally{document.body.removeChild(t)}}r(n(`cameraTokens.toast.copied`,`Copied to clipboard`))}catch{r(n(`cameraTokens.toast.copyFailed`,`Copy failed — select and copy manually`),`error`)}};return(0,Y.jsx)(`div`,{className:`fixed inset-0 bg-black/60 flex items-center justify-center z-50 p-4`,children:(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-6 max-w-2xl w-full border border-bambu-green/40`,children:[(0,Y.jsxs)(`div`,{className:`flex items-start gap-3 mb-4`,children:[(0,Y.jsx)(Ie,{className:`w-6 h-6 text-yellow-600 dark:text-yellow-400 flex-shrink-0 mt-0.5`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:n(`cameraTokens.created.title`,`Token created — copy it now`)}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:n(`cameraTokens.created.warning`,`This is the only time this token will be visible. After you close this dialog you can never view it again.`)})]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 mb-4`,children:[(0,Y.jsx)(`code`,{className:`flex-1 px-3 py-2 bg-bambu-dark rounded-md text-bambu-green text-xs break-all font-mono select-all`,children:i}),(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>s(i),className:`flex items-center gap-2 px-3 py-2 bg-bambu-green text-white rounded-md hover:bg-bambu-green/90`,children:[(0,Y.jsx)(N,{className:`w-4 h-4`}),n(`cameraTokens.created.copy`,`Copy`)]})]}),a&&(0,Y.jsxs)(`div`,{className:`mb-4`,children:[(0,Y.jsx)(`p`,{className:`text-sm font-medium text-white mb-1`,children:n(`cameraTokens.created.camWallUrlTitle`,`Cam Wall URL for this display`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:n(`cameraTokens.created.camWallUrlHint`,`Open this on the screen. Anyone who can read the URL can watch the wall, so treat it like a key — revoke the token to cut the display off.`)}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`code`,{className:`flex-1 px-3 py-2 bg-bambu-dark rounded-md text-bambu-green text-xs break-all font-mono select-all`,children:a}),(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>s(a),className:`flex items-center gap-2 px-3 py-2 bg-bambu-green text-white rounded-md hover:bg-bambu-green/90`,children:[(0,Y.jsx)(N,{className:`w-4 h-4`}),n(`cameraTokens.created.copy`,`Copy`)]})]})]}),o&&(0,Y.jsxs)(`div`,{className:`mb-4`,children:[(0,Y.jsx)(`p`,{className:`text-sm font-medium text-white mb-1`,children:n(`cameraTokens.created.overlayUrlTitle`,`Overlay URL for OBS`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:n(`cameraTokens.created.overlayUrlHint`,`Add this as a Browser Source in OBS. Change the /overlay/1 number to your printer's number (from its URL on the Printers page). Anyone who can read the URL can watch the stream, so treat it like a key — revoke the token to cut it off.`)}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`code`,{className:`flex-1 px-3 py-2 bg-bambu-dark rounded-md text-bambu-green text-xs break-all font-mono select-all`,children:o}),(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>s(o),className:`flex items-center gap-2 px-3 py-2 bg-bambu-green text-white rounded-md hover:bg-bambu-green/90`,children:[(0,Y.jsx)(N,{className:`w-4 h-4`}),n(`cameraTokens.created.copy`,`Copy`)]})]})]}),(0,Y.jsx)(`div`,{className:`flex justify-end`,children:(0,Y.jsx)(`button`,{type:`button`,onClick:t,className:`px-4 py-2 bg-bambu-dark-tertiary text-white rounded-md hover:bg-bambu-dark-tertiary/80`,children:n(`cameraTokens.created.dismiss`,`I've saved it`)})})]})})}function Gn({token:e,showOwner:t,ownerLabel:n,onRevoke:r}){let{t:i}=l(),a=Vn(e.expires_at);return(0,Y.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary last:border-b-0`,children:[(0,Y.jsx)(`td`,{className:`py-3 px-3 text-white break-words max-w-64`,children:e.name}),t&&(0,Y.jsx)(`td`,{className:`py-3 px-3 text-bambu-gray`,children:n}),(0,Y.jsx)(`td`,{className:`py-3 px-3`,children:(0,Y.jsx)(`span`,{className:`rounded bg-bambu-dark-tertiary px-2 py-0.5 text-xs text-bambu-gray`,children:i(`cameraTokens.scope.${e.scope}`,e.scope)})}),(0,Y.jsxs)(`td`,{className:`py-3 px-3 text-bambu-gray font-mono text-xs`,children:[e.lookup_prefix,`…`]}),(0,Y.jsx)(`td`,{className:`py-3 px-3 text-bambu-gray`,children:Bn(e.created_at)}),(0,Y.jsxs)(`td`,{className:`py-3 px-3 ${a?`text-red-700 dark:text-red-400`:`text-bambu-gray`}`,children:[Bn(e.expires_at),a&&(0,Y.jsx)(`span`,{className:`ml-2 px-2 py-0.5 text-xs bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-300 rounded`,children:i(`cameraTokens.list.expired`,`Expired`)})]}),(0,Y.jsx)(`td`,{className:`py-3 px-3 text-bambu-gray`,children:Bn(e.last_used_at)}),(0,Y.jsx)(`td`,{className:`py-3 px-3 text-right`,children:(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>r(e.id),className:`inline-flex items-center gap-1 px-2 py-1 text-sm text-red-700 dark:text-red-400 hover:text-red-900 dark:hover:text-red-300`,title:i(`cameraTokens.list.revoke`,`Revoke`),children:[(0,Y.jsx)(qe,{className:`w-4 h-4`}),i(`cameraTokens.list.revoke`,`Revoke`)]})})]})}function Kn({tokens:e,showOwner:t,userIdToName:n,onRevoke:r,emptyMessage:i}){let{t:a}=l();return e.length===0?(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray italic`,children:i}):(0,Y.jsx)(`div`,{className:`overflow-x-auto`,children:(0,Y.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,Y.jsx)(`thead`,{className:`text-bambu-gray text-left border-b border-bambu-dark-tertiary`,children:(0,Y.jsxs)(`tr`,{children:[(0,Y.jsx)(`th`,{className:`py-2 px-3 font-medium`,children:a(`cameraTokens.list.name`,`Name`)}),t&&(0,Y.jsx)(`th`,{className:`py-2 px-3 font-medium`,children:a(`cameraTokens.list.owner`,`Owner`)}),(0,Y.jsx)(`th`,{className:`py-2 px-3 font-medium`,children:a(`cameraTokens.list.scope`,`Scope`)}),(0,Y.jsx)(`th`,{className:`py-2 px-3 font-medium`,children:a(`cameraTokens.list.prefix`,`Prefix`)}),(0,Y.jsx)(`th`,{className:`py-2 px-3 font-medium`,children:a(`cameraTokens.list.created`,`Created`)}),(0,Y.jsx)(`th`,{className:`py-2 px-3 font-medium`,children:a(`cameraTokens.list.expires`,`Expires`)}),(0,Y.jsx)(`th`,{className:`py-2 px-3 font-medium`,children:a(`cameraTokens.list.lastUsed`,`Last used`)}),(0,Y.jsx)(`th`,{className:`py-2 px-3`})]})}),(0,Y.jsx)(`tbody`,{children:e.map(e=>(0,Y.jsx)(Gn,{token:e,showOwner:t,ownerLabel:n?.get(e.user_id)??`#${e.user_id}`,onRevoke:r},e.id))})]})})}function qn(){let{t:e}=l(),{user:t,isAdmin:n}=un(),{showToast:i}=ee(),[a,o]=(0,X.useState)([]),[s,c]=(0,X.useState)([]),[u,d]=(0,X.useState)(new Map),[f,p]=(0,X.useState)(!0),[m,h]=(0,X.useState)(null),[g,_]=(0,X.useState)(null),v=async()=>{p(!0);try{if(o(await r.listMyLongLivedCameraTokens()),n){c(await r.listAllLongLivedCameraTokens());try{let e=await r.getUsersSlim();d(new Map(e.map(e=>[e.id,e.username])))}catch{d(new Map)}}}catch(t){i(t instanceof Error?t.message:e(`cameraTokens.toast.loadFailed`,`Failed to load tokens`),`error`)}finally{p(!1)}};(0,X.useEffect)(()=>{v()},[n]);let y=async e=>{let t=[...a,...s].find(t=>t.id===e);t&&_(t)},b=async()=>{if(!g)return;let t=g.id;_(null);try{await r.revokeLongLivedCameraToken(t),i(e(`cameraTokens.toast.revoked`,`Token revoked`)),await v()}catch(t){i(t instanceof Error?t.message:e(`cameraTokens.toast.revokeFailed`,`Failed to revoke token`),`error`)}},x=(0,X.useMemo)(()=>s.filter(e=>e.user_id!==t?.id),[s,t?.id]);return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4`,children:e(`cameraTokens.description`,`Long-lived tokens for embedding the camera stream into Home Assistant, Frigate, kiosks, or any other tool that needs a stable URL. Each token is camera-stream-only and can be revoked at any time.`)}),(0,Y.jsx)(Hn,{onCreated:e=>{h(e),v()}}),(0,Y.jsxs)(`div`,{className:`mb-6`,children:[(0,Y.jsx)(`h3`,{className:`text-base font-semibold text-white mb-3`,children:e(`cameraTokens.list.myTitle`,`My tokens`)}),f?(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`cameraTokens.loading`,`Loading…`)}):(0,Y.jsx)(Kn,{tokens:a,onRevoke:y,emptyMessage:e(`cameraTokens.list.empty`,`No tokens yet.`)})]}),n&&(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h3`,{className:`text-base font-semibold text-white mb-3`,children:e(`cameraTokens.list.allTitle`,`All users (admin view)`)}),(0,Y.jsx)(Kn,{tokens:x,showOwner:!0,userIdToName:u,onRevoke:y,emptyMessage:e(`cameraTokens.list.empty`,`No tokens yet.`)})]}),m&&(0,Y.jsx)(Wn,{token:m,onClose:()=>h(null)}),g&&(0,Y.jsx)(Un,{token:g,onConfirm:()=>void b(),onCancel:()=>_(null)})]})}var Jn=[`connected-apps`];function Yn(e){if(!e)return`—`;let t=We(e);return t?t.toLocaleString():`—`}async function Xn(e){if(navigator.clipboard&&window.isSecureContext){await navigator.clipboard.writeText(e);return}let t=document.createElement(`textarea`);t.value=e,t.style.position=`fixed`,t.style.opacity=`0`,document.body.appendChild(t);try{t.select(),document.execCommand(`copy`)}finally{document.body.removeChild(t)}}function Zn({label:e,value:t}){let{t:n}=l(),{showToast:r}=ee();return(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mb-1`,children:e}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`code`,{className:`flex-1 min-w-0 px-3 py-2 bg-bambu-dark rounded-md text-bambu-green text-xs break-all font-mono select-all`,children:t}),(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>Xn(t).then(()=>r(n(`connectedApps.toast.copied`)),()=>r(n(`connectedApps.toast.copyFailed`),`error`)),className:`flex items-center gap-2 px-3 py-2 bg-bambu-green text-white rounded-md hover:bg-bambu-green/90`,children:[(0,Y.jsx)(N,{className:`w-4 h-4`}),n(`connectedApps.copy`)]})]})]})}function Qn({app:e,onClose:t}){let{t:n}=l();return(0,Y.jsx)(`div`,{className:`fixed inset-0 bg-black/60 flex items-center justify-center z-50 p-4`,role:`dialog`,"aria-modal":`true`,children:(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-6 max-w-2xl w-full border border-bambu-green/40 space-y-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,Y.jsx)(Ie,{className:`w-6 h-6 text-yellow-600 dark:text-yellow-400 flex-shrink-0 mt-0.5`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:n(`connectedApps.secret.title`,{name:e.name})}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:n(`connectedApps.secret.warning`)})]})]}),(0,Y.jsx)(Zn,{label:n(`connectedApps.clientId`),value:e.client_id}),(0,Y.jsx)(Zn,{label:n(`connectedApps.clientSecret`),value:e.client_secret??``}),(0,Y.jsx)(`div`,{className:`flex justify-end`,children:(0,Y.jsx)(`button`,{type:`button`,onClick:t,className:`px-4 py-2 bg-bambu-dark-tertiary text-white rounded-md hover:bg-bambu-dark-tertiary/80`,children:n(`connectedApps.secret.dismiss`)})})]})})}function $n({title:e,body:t,confirmLabel:n,onConfirm:r,onCancel:i}){let{t:a}=l();return(0,Y.jsx)(`div`,{className:`fixed inset-0 bg-black/60 flex items-center justify-center z-50 p-4`,role:`dialog`,"aria-modal":`true`,children:(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-6 max-w-md w-full border border-red-500/40`,children:[(0,Y.jsxs)(`div`,{className:`flex items-start gap-3 mb-4`,children:[(0,Y.jsx)(Ie,{className:`w-6 h-6 text-red-600 dark:text-red-400 flex-shrink-0 mt-0.5`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:t})]})]}),(0,Y.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,Y.jsx)(`button`,{type:`button`,onClick:i,className:`px-4 py-2 bg-bambu-dark-tertiary text-white rounded-md hover:bg-bambu-dark-tertiary/80`,children:a(`connectedApps.cancel`)}),(0,Y.jsx)(`button`,{type:`button`,onClick:r,className:`px-4 py-2 bg-red-500 text-white rounded-md hover:bg-red-600`,children:n})]})]})})}function er(){let{t:e}=l(),{authEnabled:t}=un(),{showToast:n}=ee(),i=u(),[a,o]=(0,X.useState)(``),[s,c]=(0,X.useState)(``),[p,m]=(0,X.useState)(null),[h,g]=(0,X.useState)(null),{data:_=[],isLoading:v}=d({queryKey:Jn,queryFn:r.listConnectedApps,enabled:t}),y=t=>n(t instanceof Error?t.message:e(`connectedApps.toast.failed`),`error`),b=()=>i.invalidateQueries({queryKey:Jn}),x=f({mutationFn:()=>r.createConnectedApp({name:a.trim(),redirect_uri:s.trim()}),onSuccess:t=>{o(``),c(``),m(t),n(e(`connectedApps.toast.created`)),b()},onError:y}),S=f({mutationFn:e=>r.updateConnectedApp(e.id,{enabled:!e.enabled}),onSuccess:t=>{n(t.enabled?e(`connectedApps.toast.enabled`):e(`connectedApps.toast.disabled`)),b()},onError:y}),C=f({mutationFn:e=>r.rotateConnectedAppSecret(e.id),onSuccess:t=>{m(t),n(e(`connectedApps.toast.rotated`)),b()},onError:y}),w=f({mutationFn:e=>r.deleteConnectedApp(e.id),onSuccess:()=>{n(e(`connectedApps.toast.deleted`)),b()},onError:y});if(!t)return(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`connectedApps.requiresAuth`)});let T=`px-3 py-2 bg-bambu-dark rounded-md text-white border border-bambu-dark-tertiary focus:border-bambu-green focus:outline-none`;return(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`connectedApps.description`)}),(0,Y.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),a.trim()&&s.trim()&&x.mutate()},className:`grid gap-3 md:grid-cols-[minmax(0,1fr)_minmax(0,1.5fr)_auto]`,children:[(0,Y.jsx)(`input`,{type:`text`,maxLength:100,required:!0,value:a,onChange:e=>o(e.target.value),placeholder:e(`connectedApps.namePlaceholder`),"aria-label":e(`connectedApps.name`),className:T}),(0,Y.jsx)(`input`,{type:`url`,maxLength:500,required:!0,value:s,onChange:e=>c(e.target.value),placeholder:`http://orders.local:8090/auth/callback`,"aria-label":e(`connectedApps.callbackUrl`),className:T}),(0,Y.jsxs)(`button`,{type:`submit`,disabled:x.isPending||!a.trim()||!s.trim(),className:`flex items-center justify-center gap-2 px-4 py-2 bg-bambu-green text-white rounded-md hover:bg-bambu-green/90 disabled:opacity-50 disabled:cursor-not-allowed`,children:[(0,Y.jsx)(wt,{className:`w-4 h-4`}),e(`connectedApps.add`)]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:e(`connectedApps.callbackHint`)}),v?null:_.length===0?(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`connectedApps.empty`)}):(0,Y.jsx)(`div`,{className:`overflow-x-auto`,children:(0,Y.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,Y.jsx)(`thead`,{children:(0,Y.jsxs)(`tr`,{className:`text-left text-bambu-gray border-b border-bambu-dark-tertiary`,children:[(0,Y.jsx)(`th`,{className:`py-2 px-3 font-medium`,children:e(`connectedApps.name`)}),(0,Y.jsx)(`th`,{className:`py-2 px-3 font-medium`,children:e(`connectedApps.clientId`)}),(0,Y.jsx)(`th`,{className:`py-2 px-3 font-medium`,children:e(`connectedApps.callbackUrl`)}),(0,Y.jsx)(`th`,{className:`py-2 px-3 font-medium`,children:e(`connectedApps.lastUsed`)}),(0,Y.jsx)(`th`,{className:`py-2 px-3`})]})}),(0,Y.jsx)(`tbody`,{children:_.map(t=>(0,Y.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary last:border-b-0`,children:[(0,Y.jsxs)(`td`,{className:`py-3 px-3 text-white`,children:[t.name,!t.enabled&&(0,Y.jsx)(`span`,{className:`ml-2 px-2 py-0.5 text-xs rounded bg-bambu-dark-tertiary text-bambu-gray`,children:e(`connectedApps.disabledBadge`)})]}),(0,Y.jsx)(`td`,{className:`py-3 px-3 text-bambu-gray font-mono text-xs`,children:t.client_id}),(0,Y.jsx)(`td`,{className:`py-3 px-3 text-bambu-gray text-xs break-all`,children:t.redirect_uri}),(0,Y.jsx)(`td`,{className:`py-3 px-3 text-bambu-gray`,children:Yn(t.last_used_at)}),(0,Y.jsx)(`td`,{className:`py-3 px-3`,children:(0,Y.jsxs)(`div`,{className:`flex justify-end gap-3 whitespace-nowrap`,children:[(0,Y.jsx)(`button`,{type:`button`,onClick:()=>S.mutate(t),className:`text-sm text-bambu-gray hover:text-white`,children:t.enabled?e(`connectedApps.disable`):e(`connectedApps.enable`)}),(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>g({app:t,action:`rotate`}),className:`inline-flex items-center gap-1 text-sm text-bambu-gray hover:text-white`,children:[(0,Y.jsx)(at,{className:`w-4 h-4`}),e(`connectedApps.rotate`)]}),(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>g({app:t,action:`delete`}),className:`inline-flex items-center gap-1 text-sm text-red-700 dark:text-red-400 hover:text-red-900 dark:hover:text-red-300`,children:[(0,Y.jsx)(qe,{className:`w-4 h-4`}),e(`connectedApps.delete`)]})]})})]},t.id))})]})}),p&&(0,Y.jsx)(Qn,{app:p,onClose:()=>m(null)}),h&&(0,Y.jsx)($n,{title:h.action===`rotate`?e(`connectedApps.confirmRotate.title`):e(`connectedApps.confirmDelete.title`),body:h.action===`rotate`?e(`connectedApps.confirmRotate.body`,{name:h.app.name}):e(`connectedApps.confirmDelete.body`,{name:h.app.name}),confirmLabel:h.action===`rotate`?e(`connectedApps.rotate`):e(`connectedApps.delete`),onCancel:()=>g(null),onConfirm:()=>{h.action===`rotate`?C.mutate(h.app):w.mutate(h.app),g(null)}})]})}function tr({value:e,onChange:t,onBusyChange:n}){let{t:i}=l(),{showToast:a}=ee(),{authEnabled:o,hasPermission:s}=un(),c=!o||s(`settings:update`),[u,d]=(0,X.useState)(!1),[f,p]=(0,X.useState)({from:e.from||`#00ae42`,to:e.to||`#00ae42`}),m=hn(!0,null,e.logoRevision),h=async o=>{d(!0),n?.(!0);try{o?await r.uploadOverlayLogo(o):await r.deleteOverlayLogo(),t({...e,logo:o!==null,logoRevision:e.logoRevision+1})}catch(e){a(e instanceof Error?e.message:i(`streamOverlay.branding.failed`),`error`)}finally{d(!1),n?.(!1)}},g=(n,r)=>{p(e=>({...e,[n]:r})),fn(r)&&t({...e,from:e.from||`#00ae42`,to:e.to||`#00ae42`,[n]:r})};return(0,Y.jsxs)(`fieldset`,{disabled:u,className:`my-4 space-y-3 rounded-lg border border-bambu-dark-tertiary p-4`,children:[(0,Y.jsx)(`legend`,{className:`px-2 text-sm font-medium text-white`,children:i(`streamOverlay.branding.title`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`streamOverlay.branding.hint`)}),(0,Y.jsxs)(`label`,{className:`block text-sm text-bambu-gray`,children:[i(`streamOverlay.branding.upload`),(0,Y.jsx)(`input`,{type:`file`,accept:`image/png,image/webp`,disabled:!c,className:`mt-1 block w-full text-sm`,onChange:e=>{let t=e.target.files?.[0];e.target.value=``,t&&h(t)}})]}),m&&(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,Y.jsx)(`img`,{src:m,alt:i(`streamOverlay.branding.logo`),className:`h-16 max-w-40 object-contain`}),(0,Y.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-bambu-gray`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:e.logo,onChange:n=>t({...e,logo:n.target.checked})}),i(`streamOverlay.branding.logo`)]}),(0,Y.jsx)(`button`,{type:`button`,disabled:!c,onClick:()=>void h(null),className:`text-sm text-red-400 disabled:opacity-50`,children:i(`common.remove`)})]}),(0,Y.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[`from`,`to`].map(t=>(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{htmlFor:`overlay-colour-${t}`,className:`block text-sm text-bambu-gray mb-1`,children:i(`streamOverlay.branding.${t}`)}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`input`,{id:`overlay-colour-${t}`,type:`color`,value:e[t]||`#00ae42`,onChange:e=>g(t,e.target.value),className:`h-9 w-12 bg-transparent`}),(0,Y.jsx)(`input`,{"aria-label":`${i(`streamOverlay.branding.${t}`)} (hex)`,value:f[t],onChange:e=>g(t,e.target.value),"aria-invalid":!fn(f[t]),maxLength:7,spellCheck:!1,className:`w-28 rounded border border-bambu-dark-tertiary bg-bambu-dark px-2 py-1 text-white`})]})]},t))}),(0,Y.jsx)(`button`,{type:`button`,className:`text-sm text-bambu-green`,onClick:()=>{p({from:`#00ae42`,to:`#00ae42`}),t({...e,from:``,to:``})},children:i(`streamOverlay.branding.reset`)})]})}var nr=[{key:`printer`,labelKey:`streamOverlay.builder.fieldPrinter`,fallback:`Printer name`},{key:`model`,labelKey:`streamOverlay.builder.fieldModel`,fallback:`Printer model`},{key:`filename`,labelKey:`streamOverlay.builder.fieldFilename`,fallback:`File name`},{key:`status`,labelKey:`streamOverlay.builder.fieldStatus`,fallback:`Status`},{key:`progress`,labelKey:`streamOverlay.builder.fieldProgress`,fallback:`Progress bar`},{key:`layers`,labelKey:`streamOverlay.builder.fieldLayers`,fallback:`Layer count`},{key:`eta`,labelKey:`streamOverlay.builder.fieldEta`,fallback:`Time remaining and ETA`},{key:`nozzle`,labelKey:`printers.heaterHistory.nozzle`,fallback:`Nozzle`},{key:`bed`,labelKey:`printers.heaterHistory.bed`,fallback:`Bed`},{key:`chamber`,labelKey:`printers.heaterHistory.chamber`,fallback:`Chamber`}],rr=[`progress`,`layers`,`eta`,`filename`,`status`],ir=15,ar=`bambuddy.streamOverlayBuilder`,or={printerId:null,fields:rr,size:`medium`,fps:ir,artwork:`1`,backgroundTransparency:0,showCamera:!0,layout:`landscape`,logo:!1,from:``,to:``};function sr(){let e;try{e=JSON.parse(window.localStorage.getItem(ar)??`null`)}catch{return or}if(!e||typeof e!=`object`)return or;let t=e,n=(e,t,n,r)=>typeof e==`number`&&Number.isFinite(e)?Math.min(n,Math.max(t,e)):r,r=typeof t.from==`string`&&typeof t.to==`string`&&dn(t.from,t.to);return{printerId:typeof t.printerId==`number`&&Number.isSafeInteger(t.printerId)&&t.printerId>0?t.printerId:null,fields:Array.isArray(t.fields)?t.fields.filter(e=>nr.some(t=>t.key===e)):rr,size:t.size===`small`||t.size===`large`?t.size:`medium`,fps:Math.round(n(t.fps,1,30,ir)),artwork:t.artwork===`2`?`2`:`1`,backgroundTransparency:n(t.backgroundTransparency,0,100,0),showCamera:t.showCamera!==!1,layout:t.layout===`portrait`||t.layout===`both`?t.layout:`landscape`,logo:t.logo===!0,from:r?t.from:``,to:r?t.to:``}}var cr=600;function lr(e){try{return window.localStorage.setItem(ar,JSON.stringify(e)),!0}catch{return!1}}function ur({onTokenCreated:e}){let{t}=l(),{showToast:n}=ee(),{user:i,hasPermission:a}=un(),[o,s]=(0,X.useState)(!1),[c,u]=(0,X.useState)(!1),[d,f]=(0,X.useState)(!1),[p,m]=(0,X.useState)(``),h=p,[g,_]=(0,X.useState)(``),[v,y]=(0,X.useState)(!1),[b]=(0,X.useState)(sr),x=(0,X.useRef)(null),S=(0,X.useRef)(!1),C=(0,X.useRef)(null),[w,T]=(0,X.useState)([]),[E,D]=(0,X.useState)(b.printerId),[O,k]=(0,X.useState)(b.fields),[A,j]=(0,X.useState)(b.size),[M,P]=(0,X.useState)(b.fps),[te,ne]=(0,X.useState)(b.artwork),[I,re]=(0,X.useState)(b.backgroundTransparency),[ie,L]=(0,X.useState)(b.showCamera),[ae,R]=(0,X.useState)({...mn,logo:b.logo,from:b.from,to:b.to}),[z,oe]=(0,X.useState)(b.layout),[se,B]=(0,X.useState)(0),[ce,le]=(0,X.useState)(!1),[ue,de]=(0,X.useState)(!1);(0,X.useEffect)(()=>{let e=!1;return(async()=>{try{let t=await r.getPrinters();if(e)return;T(t),t.length>0&&D(e=>{let n=e===null||e===b.printerId&&!t.some(t=>t.id===e)?t[0].id:e;return n!==e&&(S.current=!0),n})}catch{}})(),()=>{e=!0}},[b.printerId]),(0,X.useEffect)(()=>{let e={printerId:E,fields:O,size:A,fps:M,artwork:te,backgroundTransparency:I,showCamera:ie,layout:z,logo:ae.logo,from:ae.from,to:ae.to},r=JSON.stringify(e);if(r===x.current)return;let i=x.current===null||S.current;x.current=r,S.current=!1,!(!lr(e)||i)&&(C.current&&clearTimeout(C.current),C.current=setTimeout(()=>{C.current=null,n(t(`settings.toast.settingsSaved`))},cr))},[E,O,A,M,te,I,ie,z,ae.logo,ae.from,ae.to,n,t]),(0,X.useEffect)(()=>()=>{C.current&&clearTimeout(C.current)},[]);let fe=()=>{D(w[0]?.id??null),k(or.fields),j(or.size),P(or.fps),ne(or.artwork),re(or.backgroundTransparency),L(or.showCamera),oe(or.layout),R(e=>({...e,logo:!1,from:``,to:``})),B(e=>e+1),de(!1)},V=(0,X.useMemo)(()=>{let e=E??1,t=new URLSearchParams,n=nr.filter(e=>O.includes(e.key)).map(e=>e.key);return t.set(`show`,n.join(`,`)),A!==`medium`&&t.set(`size`,A),M!==ir&&t.set(`fps`,String(M)),te!==`1`&&t.set(`artwork`,te),te===`2`&&I>0&&t.set(`backgroundTransparency`,String(I)),ie||t.set(`camera`,`false`),ae.logo&&t.set(`logo`,`1`),ae.from&&ae.to&&(t.set(`progressFrom`,ae.from),t.set(`progressTo`,ae.to)),h.trim()&&t.set(`token`,h.trim()),(z===`both`?[`landscape`,`portrait`]:[z]).map(n=>(n===`portrait`?t.set(`layout`,n):t.delete(`layout`),{layout:n,url:`${window.location.origin}/overlay/${e}?${t.toString()}`}))},[E,O,A,M,ie,h,te,z,ae,I]),pe=e=>{let t=new URL(e);return t.searchParams.has(`token`)&&!d&&t.searchParams.set(`token`,`****`),t.toString()},me=()=>{try{let e=new URL(g.trim()),t=/^\/overlay\/([1-9]\d*)\/?$/.exec(e.pathname);if(![`http:`,`https:`].includes(e.protocol)||e.username||e.password||!t)throw Error();let n=Number(t[1]);if(!Number.isSafeInteger(n))throw Error();let r=e.searchParams;if(r.getAll(`token`).length>1)throw Error();let i=r.has(`show`)?r.get(`show`).split(`,`).filter(e=>nr.some(t=>t.key===e)):rr,a=r.get(`size`),o=a===`small`||a===`large`?a:`medium`,s=parseInt(r.get(`fps`)||`15`,10),c=Math.min(Math.max(Number.isNaN(s)?ir:s,1),30),l=Number(r.get(`backgroundTransparency`)),u=Number.isFinite(l)?Math.min(100,Math.max(0,l)):0,d=r.get(`progressFrom`),p=r.get(`progressTo`),h=dn(d,p);D(n),oe(r.get(`layout`)===`portrait`?`portrait`:`landscape`),k(i),j(o),P(c),ne(r.get(`artwork`)===`2`?`2`:`1`),L(![`false`,`0`].includes(r.get(`camera`)??``)),re(u),R(e=>({...e,logo:r.get(`logo`)===`1`,from:h?d:``,to:h?p:``})),B(e=>e+1),m(r.get(`token`)??``),de(!1),f(!1),_(``),y(!1)}catch{y(!0)}},he=e=>{k(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},ge=async e=>{try{if(navigator.clipboard&&window.isSecureContext)await navigator.clipboard.writeText(e);else{let t=document.createElement(`textarea`);t.value=e,t.style.position=`fixed`,t.style.opacity=`0`,document.body.appendChild(t);try{if(t.select(),!document.execCommand(`copy`))throw Error()}finally{document.body.removeChild(t)}}n(t(`cameraTokens.toast.copied`,`Copied to clipboard`))}catch{n(t(`cameraTokens.toast.copyFailed`,`Copy failed — select and copy manually`),`error`)}};return(0,Y.jsxs)(`div`,{className:`@container/overlay min-w-0`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4`,children:t(`streamOverlay.builder.description`,`Build the URL for a streaming overlay — a full-screen camera view with live print data drawn over it, for OBS, a wall display, or any browser source. Pick the fields you want and copy the URL.`)}),(0,Y.jsxs)(`div`,{className:`-mt-2 mb-4 flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-bambu-gray`,children:[(0,Y.jsx)(`span`,{children:t(`streamOverlay.builder.rememberedHint`)}),(0,Y.jsx)(`button`,{type:`button`,onClick:fe,disabled:c||ce,className:`text-bambu-green hover:underline disabled:opacity-50`,children:t(`streamOverlay.builder.resetChoices`)})]}),(0,Y.jsxs)(`div`,{className:`mb-4 space-y-2`,children:[(0,Y.jsx)(`label`,{htmlFor:`overlay-builder-import`,className:`block text-sm font-medium text-white`,children:t(`streamOverlay.builder.importUrl`)}),(0,Y.jsx)(`input`,{id:`overlay-builder-import`,type:`password`,autoComplete:`new-password`,spellCheck:!1,value:g,disabled:c||ce,onChange:e=>{_(e.target.value),y(!1)},className:`w-full min-w-0 px-3 py-2 bg-bambu-dark rounded-md text-white border border-bambu-dark-tertiary`}),(0,Y.jsx)(`button`,{type:`button`,disabled:c||ce||!g.trim(),onClick:me,className:`px-3 py-2 bg-bambu-dark-tertiary text-white rounded-md disabled:opacity-50`,children:t(`streamOverlay.builder.importAction`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:t(`streamOverlay.builder.importHint`)}),v&&(0,Y.jsx)(`p`,{role:`alert`,className:`text-sm text-red-400`,children:t(`streamOverlay.builder.importError`)})]}),(0,Y.jsxs)(`div`,{className:`mb-4 space-y-2`,children:[i&&a(`camera:view`)&&(0,Y.jsx)(`button`,{type:`button`,disabled:c,onClick:()=>s(e=>!e),className:`px-3 py-2 bg-bambu-dark-tertiary text-white rounded-md`,children:t(o?`common.cancel`:`streamOverlay.builder.createToken`)}),o&&i&&a(`camera:view`)&&(0,Y.jsx)(Hn,{fixedScope:`overlay`,onSubmittingChange:u,onCreated:t=>{e?.(),t.token&&(de(!1),m(t.token),f(!1),s(!1))}})]}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 @min-[28rem]/overlay:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{htmlFor:`overlay-builder-printer`,className:`block text-sm font-medium text-white mb-1`,children:t(`streamOverlay.builder.printer`,`Printer`)}),(0,Y.jsxs)(`select`,{id:`overlay-builder-printer`,value:E??``,onChange:e=>D(Number(e.target.value)),className:`w-full px-3 py-2 bg-bambu-dark rounded-md text-white border border-bambu-dark-tertiary focus:border-bambu-green focus:outline-none`,children:[w.length===0&&(0,Y.jsx)(`option`,{value:``,children:t(`common.loading`,`Loading…`)}),E!==null&&!w.some(e=>e.id===E)&&(0,Y.jsx)(`option`,{value:E,children:E}),w.map(e=>(0,Y.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{htmlFor:`overlay-builder-size`,className:`block text-sm font-medium text-white mb-1`,children:t(`streamOverlay.builder.size`,`Text size`)}),(0,Y.jsxs)(`select`,{id:`overlay-builder-size`,value:A,onChange:e=>j(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark rounded-md text-white border border-bambu-dark-tertiary focus:border-bambu-green focus:outline-none`,children:[(0,Y.jsx)(`option`,{value:`small`,children:t(`streamOverlay.builder.sizeSmall`,`Small`)}),(0,Y.jsx)(`option`,{value:`medium`,children:t(`streamOverlay.builder.sizeMedium`,`Medium`)}),(0,Y.jsx)(`option`,{value:`large`,children:t(`streamOverlay.builder.sizeLarge`,`Large`)})]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{htmlFor:`overlay-builder-layout`,className:`block text-sm font-medium text-white mb-1`,children:t(`streamOverlay.builder.layout`)}),(0,Y.jsxs)(`select`,{id:`overlay-builder-layout`,value:z,onChange:e=>{let t=e.target.value;(t===`landscape`||t===`portrait`||t===`both`)&&oe(t)},className:`w-full px-3 py-2 bg-bambu-dark rounded-md text-white border border-bambu-dark-tertiary focus:border-bambu-green focus:outline-none`,children:[(0,Y.jsx)(`option`,{value:`landscape`,children:t(`streamOverlay.builder.landscape`)}),(0,Y.jsx)(`option`,{value:`portrait`,children:t(`streamOverlay.builder.portrait`)}),(0,Y.jsx)(`option`,{value:`both`,children:t(`streamOverlay.builder.both`)})]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{htmlFor:`overlay-builder-artwork`,className:`block text-sm font-medium text-white mb-1`,children:t(`streamOverlay.builder.artwork`,`Artwork`)}),(0,Y.jsxs)(`select`,{id:`overlay-builder-artwork`,value:te,onChange:e=>ne(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark rounded-md text-white border border-bambu-dark-tertiary focus:border-bambu-green focus:outline-none`,children:[(0,Y.jsx)(`option`,{value:`1`,children:t(`streamOverlay.builder.artworkClassic`,`Classic`)}),(0,Y.jsx)(`option`,{value:`2`,children:t(`streamOverlay.builder.artworkV2`,`Version 2`)})]})]}),te===`2`&&(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`label`,{htmlFor:`overlay-builder-background-transparency`,className:`flex justify-between gap-2 text-sm font-medium text-white mb-1`,children:[(0,Y.jsx)(`span`,{children:t(`streamOverlay.builder.backgroundTransparency`)}),(0,Y.jsxs)(`span`,{"aria-hidden":`true`,children:[I,`%`]})]}),(0,Y.jsx)(`input`,{id:`overlay-builder-background-transparency`,type:`range`,min:0,max:100,step:1,value:I,"aria-valuetext":`${I}%`,onChange:e=>re(Number(e.target.value)),className:`w-full accent-bambu-green`}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:t(`streamOverlay.builder.backgroundTransparencyHint`)})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{htmlFor:`overlay-builder-fps`,className:`block text-sm font-medium text-white mb-1`,children:t(`streamOverlay.builder.fps`,`Frame rate`)}),(0,Y.jsx)(ct,{id:`overlay-builder-fps`,min:1,max:30,value:M,onChange:P,fallback:1,className:`w-full px-3 py-2 bg-bambu-dark rounded-md text-white border border-bambu-dark-tertiary focus:border-bambu-green focus:outline-none`}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:t(`streamOverlay.builder.fpsHint`,`A1 and P1 cameras top out around 5 fps whatever you ask for.`)})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{htmlFor:`overlay-builder-manual-token`,className:`block text-sm font-medium text-white mt-3 mb-1`,children:t(`streamOverlay.builder.manualToken`)}),(0,Y.jsx)(`input`,{id:`overlay-builder-manual-token`,type:d?`text`:`password`,value:p,disabled:c,autoComplete:`new-password`,spellCheck:!1,onChange:e=>{de(!1),f(!1),m(e.target.value)},placeholder:`bblt_…`,className:`w-full min-w-0 px-3 py-2 bg-bambu-dark rounded-md text-white border border-bambu-dark-tertiary`}),(0,Y.jsx)(`button`,{type:`button`,disabled:!h,onClick:()=>f(e=>!e),className:`mt-2 text-sm text-bambu-gray disabled:opacity-50`,children:t(d?`streamOverlay.builder.hideToken`:`streamOverlay.builder.showToken`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:t(`streamOverlay.builder.credentialHint`,`Create a token above, enter an existing token, or import an overlay URL. Copy the URL before leaving: tokens are held only in memory and cannot be recovered from their stored hash.`)})]})]}),(0,Y.jsxs)(`fieldset`,{className:`mt-4`,children:[(0,Y.jsx)(`legend`,{className:`text-sm font-medium text-white mb-2`,children:t(`streamOverlay.builder.fields`,`Fields to show`)}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 gap-2 @min-[24rem]/overlay:grid-cols-2 @min-[36rem]/overlay:grid-cols-3`,children:[nr.map(e=>(0,Y.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-bambu-gray`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:O.includes(e.key),onChange:()=>he(e.key),className:`accent-bambu-green`}),t(e.labelKey,e.fallback)]},e.key)),(0,Y.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-bambu-gray`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:ie,onChange:e=>L(e.target.checked),className:`accent-bambu-green`}),t(`streamOverlay.builder.fieldCamera`,`Camera feed`)]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-2`,children:t(`streamOverlay.builder.chamberHint`,`Chamber temperature only appears on models with a real chamber sensor — P1 and A1 printers report a meaningless value, so it is left out there.`)})]}),(0,Y.jsx)(tr,{value:ae,onChange:R,onBusyChange:le},se),(0,Y.jsxs)(`div`,{className:`mt-4`,children:[V.map(({layout:e,url:n})=>(0,Y.jsxs)(`fieldset`,{className:`min-w-0 mb-3`,children:[(0,Y.jsx)(`legend`,{className:`text-sm font-medium text-white mb-1`,children:t(`streamOverlay.builder.orientationUrl`,{orientation:t(`streamOverlay.builder.${e}`)})}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:t(`streamOverlay.builder.sourceDimensions`,pn[e])}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Y.jsx)(`code`,{className:`w-full px-3 py-2 bg-bambu-dark rounded-md text-bambu-green text-xs break-all font-mono`,children:pe(n)}),(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>void ge(n),className:`flex items-center gap-2 px-3 py-2 bg-bambu-green text-white rounded-md hover:bg-bambu-green/90`,children:[(0,Y.jsx)(N,{className:`w-4 h-4`}),t(`cameraTokens.created.copy`,`Copy`)]}),(0,Y.jsxs)(`a`,{href:n,target:`_blank`,rel:`noopener noreferrer`,className:`flex items-center gap-2 px-3 py-2 bg-bambu-dark-tertiary text-white rounded-md hover:bg-bambu-dark-tertiary/80`,children:[(0,Y.jsx)(Je,{className:`w-4 h-4`}),t(`streamOverlay.builder.open`,`Open`)]})]})]},e)),h.trim()&&(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-2`,children:t(`streamOverlay.builder.tokenWarning`,`This URL contains a token — anyone who can read it can watch the stream and see the file name. Revoke the token to cut it off.`)})]}),(0,Y.jsxs)(`div`,{className:`mt-4`,children:[(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>de(e=>!e),className:`flex items-center gap-2 px-3 py-2 bg-bambu-dark-tertiary text-white rounded-md hover:bg-bambu-dark-tertiary/80 text-sm`,children:[ue?(0,Y.jsx)(F,{className:`w-4 h-4`}):(0,Y.jsx)(mt,{className:`w-4 h-4`}),ue?t(`streamOverlay.builder.hidePreview`,`Hide preview`):t(`streamOverlay.builder.showPreview`,`Show preview`)]}),ue&&(0,Y.jsx)(`div`,{className:`mt-3 flex flex-wrap items-start gap-4`,children:V.map(({layout:e,url:n})=>(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1 basis-64`,style:e===`portrait`?{maxWidth:360}:void 0,children:[(0,Y.jsx)(`p`,{className:`text-sm text-white mb-2`,children:t(`streamOverlay.builder.${e}`)}),(0,Y.jsx)(`div`,{className:`overflow-hidden rounded-md border border-bambu-dark-tertiary`,children:(0,Y.jsx)(gn,{layout:e,preview:!0,children:(0,Y.jsx)(dr,{url:n,logoRevision:ae.logoRevision,title:t(`streamOverlay.builder.orientationPreview`,{orientation:t(`streamOverlay.builder.${e}`)})})})})]},e))})]})]})}function dr({url:e,logoRevision:t,title:n}){let[r,i]=(0,X.useState)({url:e,logoRevision:t});return(0,X.useEffect)(()=>{let n=window.setTimeout(()=>i({url:e,logoRevision:t}),300);return()=>window.clearTimeout(n)},[e,t]),(0,Y.jsx)(`iframe`,{src:r.url,title:n,className:`w-full h-full border-0`},`${r.url}:${r.logoRevision}`)}function fr({plug:e,onEdit:t}){let{t:n}=l(),i=u(),{showToast:a}=ee(),[o,s]=(0,X.useState)(!1),[c,p]=(0,X.useState)(!1),[m,h]=(0,X.useState)(!1),[g,_]=(0,X.useState)(!1),{data:v,isLoading:y}=d({queryKey:[`smart-plug-status`,e.id],queryFn:()=>r.getSmartPlugStatus(e.id),refetchInterval:3e4}),{data:b}=d({queryKey:[`printers`],queryFn:r.getPrinters}),x=b?.find(t=>t.id===e.printer_id),S=f({mutationFn:t=>r.controlSmartPlug(e.id,t),onMutate:async t=>{await i.cancelQueries({queryKey:[`smart-plug-status`,e.id]});let n=i.getQueryData([`smart-plug-status`,e.id]),r=t===`on`?`ON`:t===`off`||v?.state===`ON`?`OFF`:`ON`;return i.setQueryData([`smart-plug-status`,e.id],e=>({...e,state:r})),{previousStatus:n}},onError:(t,r,o)=>{o?.previousStatus&&i.setQueryData([`smart-plug-status`,e.id],o.previousStatus),a(n(`smartPlugs.failedToTurn`,{action:r,name:e.name}),`error`)},onSettled:()=>{setTimeout(()=>{i.invalidateQueries({queryKey:[`smart-plug-status`,e.id]}),i.invalidateQueries({queryKey:[`smart-plugs`]})},1e3)}}),C=f({mutationFn:t=>r.updateSmartPlug(e.id,t),onSuccess:()=>{i.invalidateQueries({queryKey:[`smart-plugs`]}),e.printer_id&&(i.invalidateQueries({queryKey:[`smartPlugByPrinter`,e.printer_id]}),i.invalidateQueries({queryKey:[`scriptPlugsByPrinter`,e.printer_id]}))}}),T=f({mutationFn:()=>r.deleteSmartPlug(e.id),onSuccess:()=>{i.invalidateQueries({queryKey:[`smart-plugs`]}),e.printer_id&&i.invalidateQueries({queryKey:[`scriptPlugsByPrinter`,e.printer_id]})}}),E=v?.state===`ON`,D=e.plug_type===`mqtt`&&v?.energy?.power!==null&&v?.energy?.power!==void 0,O=(v?.reachable??!1)||D,k=S.isPending,A=(()=>{if(e.plug_type!==`tasmota`||!e.ip_address)return null;let t=e.ip_address;return e.username&&e.password?`http://${encodeURIComponent(e.username)}:${encodeURIComponent(e.password)}@${t}/`:`http://${t}/`})();return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(G,{className:`relative`,children:(0,Y.jsxs)(W,{className:`p-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-start justify-between gap-2 mb-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 flex-1`,children:[(0,Y.jsx)(`div`,{className:`p-2 rounded-lg flex-shrink-0 ${e.plug_type===`mqtt`?O?`bg-teal-100 dark:bg-teal-500/20`:`bg-red-100 dark:bg-red-500/20`:O?E?`bg-bambu-green/20`:`bg-bambu-dark`:`bg-red-100 dark:bg-red-500/20`}`,children:e.plug_type===`mqtt`?(0,Y.jsx)(en,{className:`w-5 h-5 ${O?`text-teal-600 dark:text-teal-400`:`text-red-600 dark:text-red-400`}`}):e.plug_type===`homeassistant`?(0,Y.jsx)(Ft,{className:`w-5 h-5 ${O?E?`text-bambu-green`:`text-bambu-gray`:`text-red-600 dark:text-red-400`}`}):e.plug_type===`rest`?(0,Y.jsx)(zt,{className:`w-5 h-5 ${O?E?`text-bambu-green`:`text-bambu-gray`:`text-red-600 dark:text-red-400`}`}):(0,Y.jsx)(dt,{className:`w-5 h-5 ${O?E?`text-bambu-green`:`text-bambu-gray`:`text-red-600 dark:text-red-400`}`})}),(0,Y.jsxs)(`div`,{className:`min-w-0`,children:[(0,Y.jsx)(`h3`,{className:`font-medium text-white truncate`,children:e.name}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray truncate`,title:e.plug_type===`mqtt`?e.mqtt_topic??void 0:e.plug_type===`homeassistant`?e.ha_entity_id??void 0:e.plug_type===`rest`?e.rest_on_url??e.rest_off_url??void 0:e.ip_address??void 0,children:e.plug_type===`mqtt`?e.mqtt_topic:e.plug_type===`homeassistant`?e.ha_entity_id:e.plug_type===`rest`?e.rest_on_url||e.rest_off_url:e.ip_address})]})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col items-end gap-1 flex-shrink-0`,children:[y?(0,Y.jsx)(R,{className:`w-4 h-4 text-bambu-gray animate-spin`}):e.plug_type===`mqtt`?(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 text-sm whitespace-nowrap`,children:[(0,Y.jsx)(`span`,{className:`px-1.5 py-0.5 bg-teal-100 dark:bg-teal-500/20 text-teal-700 dark:text-teal-400 text-[10px] font-medium rounded flex-shrink-0`,children:`MQTT`}),O&&(0,Y.jsx)(`span`,{className:`text-status-ok`,children:`✓`})]}):e.plug_type===`homeassistant`?(0,Y.jsxs)(`div`,{className:`flex items-center gap-1 text-sm`,children:[(0,Y.jsx)(`span`,{className:`px-1 py-0.5 bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400 text-[10px] font-medium rounded`,children:`HA`}),(0,Y.jsx)(`span`,{className:O?E?`text-status-ok`:`text-bambu-gray`:`text-status-error`,children:O?v?.state||`?`:n(`smartPlugs.offline`)})]}):e.plug_type===`rest`?(0,Y.jsxs)(`div`,{className:`flex items-center gap-1 text-sm`,children:[(0,Y.jsx)(`span`,{className:`px-1 py-0.5 bg-purple-100 dark:bg-purple-500/20 text-purple-700 dark:text-purple-400 text-[10px] font-medium rounded`,children:`REST`}),(0,Y.jsx)(`span`,{className:O?E?`text-status-ok`:`text-bambu-gray`:`text-status-error`,children:O?v?.state||`?`:n(`smartPlugs.offline`)})]}):O?(0,Y.jsxs)(`div`,{className:`flex items-center gap-1 text-sm`,children:[(0,Y.jsx)(ht,{className:`w-4 h-4 text-status-ok`}),(0,Y.jsx)(`span`,{className:E?`text-status-ok`:`text-bambu-gray`,children:v?.state||n(`smartPlugs.unknown`)})]}):(0,Y.jsxs)(`div`,{className:`flex items-center gap-1 text-sm text-status-error`,children:[(0,Y.jsx)(Ye,{className:`w-4 h-4`}),(0,Y.jsx)(`span`,{children:n(`smartPlugs.offline`)})]}),A&&(0,Y.jsxs)(`a`,{href:A,target:`_blank`,rel:`noopener noreferrer`,className:`flex items-center gap-1 px-2 py-0.5 bg-bambu-dark hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white text-xs rounded-full transition-colors`,title:n(`smartPlugs.openPlugAdminPage`),children:[(0,Y.jsx)(Je,{className:`w-3 h-3`}),n(`smartPlugs.admin`)]})]})]}),x&&(0,Y.jsxs)(`div`,{className:`mb-3 px-2 py-1.5 bg-bambu-dark rounded-lg`,children:[(0,Y.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[n(`smartPlugs.linkedTo`),` `]}),(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:x.name})]}),(e.power_alert_enabled||e.schedule_enabled||e.plug_type===`mqtt`)&&(0,Y.jsxs)(`div`,{className:`flex flex-wrap gap-1.5 mb-3`,children:[e.plug_type===`mqtt`&&(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 px-2 py-0.5 bg-teal-100 dark:bg-teal-500/20 text-teal-700 dark:text-teal-400 text-xs rounded-full`,children:[(0,Y.jsx)(mt,{className:`w-3 h-3`}),n(`smartPlugs.monitorOnly`)]}),e.power_alert_enabled&&(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 px-2 py-0.5 bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400 text-xs rounded-full`,children:[(0,Y.jsx)(rt,{className:`w-3 h-3`}),n(`smartPlugs.alerts`)]}),e.schedule_enabled&&(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 px-2 py-0.5 bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400 text-xs rounded-full`,children:[(0,Y.jsx)(w,{className:`w-3 h-3`}),e.schedule_on_time&&e.schedule_off_time?`${e.schedule_on_time} - ${e.schedule_off_time}`:e.schedule_on_time?n(`smartPlugs.scheduleOn`,{time:e.schedule_on_time}):n(`smartPlugs.scheduleOff`,{time:e.schedule_off_time})]})]}),e.plug_type!==`mqtt`&&(0,Y.jsxs)(`div`,{className:`flex gap-2 mb-3`,children:[(0,Y.jsxs)(K,{size:`sm`,variant:E?`primary`:`secondary`,disabled:!O||k,onClick:()=>p(!0),className:`flex-1`,children:[k?(0,Y.jsx)(R,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(Ct,{className:`w-4 h-4`}),n(`smartPlugs.on`)]}),(0,Y.jsxs)(K,{size:`sm`,variant:E?`secondary`:`primary`,disabled:!O||k,onClick:()=>h(!0),className:`flex-1`,children:[k?(0,Y.jsx)(R,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(St,{className:`w-4 h-4`}),n(`smartPlugs.off`)]})]}),e.plug_type===`mqtt`&&v?.energy&&(0,Y.jsxs)(`div`,{className:`flex gap-2 mb-3 px-3 py-2 bg-bambu-dark rounded-lg`,children:[v.energy.power!==null&&v.energy.power!==void 0&&(0,Y.jsxs)(`div`,{className:`flex-1 text-center`,children:[(0,Y.jsxs)(`p`,{className:`text-lg font-semibold text-white`,children:[Math.round(v.energy.power),`W`]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.power`)})]}),v.energy.today!==null&&v.energy.today!==void 0&&(0,Y.jsxs)(`div`,{className:`flex-1 text-center border-l border-bambu-dark-tertiary`,children:[(0,Y.jsx)(`p`,{className:`text-lg font-semibold text-white`,children:v.energy.today.toFixed(3)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.kwhToday`)})]})]}),(0,Y.jsxs)(`button`,{onClick:()=>_(!g),className:`w-full flex items-center justify-between py-2 text-sm text-bambu-gray hover:text-white transition-colors`,children:[(0,Y.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(je,{className:`w-4 h-4`}),e.plug_type===`mqtt`?n(`smartPlugs.settings`):n(`smartPlugs.automationSettings`)]}),(0,Y.jsx)(`span`,{children:g?`-`:`+`})]}),g&&(0,Y.jsxs)(`div`,{className:`pt-3 border-t border-bambu-dark-tertiary space-y-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(L,{className:`w-4 h-4 text-bambu-green`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`smartPlugs.showInSwitchbar`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.quickAccessSidebar`)})]})]}),(0,Y.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:e.show_in_switchbar,onChange:e=>C.mutate({show_in_switchbar:e.target.checked}),className:`sr-only peer`}),(0,Y.jsx)(`div`,{className:`w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green`})]})]}),e.printer_id!=null&&(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(Ct,{className:`w-4 h-4 text-bambu-green`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`smartPlugs.controlsPrinterPower`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.controlsPrinterPowerDescription`)})]})]}),(0,Y.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:e.controls_printer_power,onChange:e=>C.mutate({controls_printer_power:e.target.checked}),className:`sr-only peer`}),(0,Y.jsx)(`div`,{className:`w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green`})]})]}),e.plug_type!==`mqtt`&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`smartPlugs.enabled`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.enableAutomation`)})]}),(0,Y.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:e.enabled,onChange:e=>C.mutate({enabled:e.target.checked}),className:`sr-only peer`}),(0,Y.jsx)(`div`,{className:`w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`smartPlugs.autoOn`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.autoOnDescription`)})]}),(0,Y.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:e.auto_on,onChange:e=>C.mutate({auto_on:e.target.checked}),className:`sr-only peer`}),(0,Y.jsx)(`div`,{className:`w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`smartPlugs.autoOff`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.autoOffDescription`)})]}),(0,Y.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:e.auto_off,onChange:e=>C.mutate({auto_off:e.target.checked}),className:`sr-only peer`}),(0,Y.jsx)(`div`,{className:`w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green`})]})]}),e.auto_off&&(0,Y.jsxs)(`div`,{className:`flex items-center justify-between pl-4 border-l-2 border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`smartPlugs.autoOffPersistent`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.autoOffPersistentDescription`)})]}),(0,Y.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:e.auto_off_persistent,onChange:e=>C.mutate({auto_off_persistent:e.target.checked}),className:`sr-only peer`}),(0,Y.jsx)(`div`,{className:`w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green`})]})]}),e.auto_off&&(0,Y.jsxs)(`div`,{className:`space-y-3 pl-4 border-l-2 border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white mb-2`,children:n(`smartPlugs.turnOffDelayMode`)}),(0,Y.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Y.jsxs)(`button`,{onClick:()=>C.mutate({off_delay_mode:`time`}),className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg text-sm transition-colors ${e.off_delay_mode===`time`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,children:[(0,Y.jsx)(lt,{className:`w-4 h-4`}),n(`smartPlugs.time`)]}),(0,Y.jsxs)(`button`,{onClick:()=>C.mutate({off_delay_mode:`temperature`}),className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg text-sm transition-colors ${e.off_delay_mode===`temperature`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,children:[(0,Y.jsx)(Fe,{className:`w-4 h-4`}),n(`smartPlugs.temp`)]})]})]}),e.off_delay_mode===`time`?(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:n(`smartPlugs.delayMinutes`)}),(0,Y.jsx)(ct,{min:1,max:60,value:e.off_delay_minutes,onChange:e=>C.mutate({off_delay_minutes:e}),fallback:5,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`})]}):(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:n(`smartPlugs.tempThreshold`)}),(0,Y.jsx)(ct,{min:30,max:100,value:e.off_temp_threshold,onChange:e=>C.mutate({off_temp_threshold:e}),fallback:70,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(`smartPlugs.tempThresholdDescription`)})]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`smartPlugs.autoOffAfterDrying`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.autoOffAfterDryingDescription`)})]}),(0,Y.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:e.auto_off_after_drying,onChange:e=>C.mutate({auto_off_after_drying:e.target.checked}),className:`sr-only peer`}),(0,Y.jsx)(`div`,{className:`w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green`})]})]}),e.auto_off_after_drying&&(0,Y.jsxs)(`div`,{className:`pl-4 border-l-2 border-bambu-dark-tertiary`,children:[(0,Y.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:n(`smartPlugs.delayAfterDryingMinutes`)}),(0,Y.jsx)(ct,{min:0,max:120,value:e.off_delay_after_drying_minutes,onChange:e=>C.mutate({off_delay_after_drying_minutes:e}),fallback:10,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`})]})]}),(0,Y.jsxs)(`div`,{className:`flex gap-2 pt-2`,children:[(0,Y.jsxs)(K,{size:`sm`,variant:`secondary`,onClick:()=>t(e),className:`flex-1`,children:[(0,Y.jsx)(oe,{className:`w-4 h-4`}),n(`smartPlugs.edit`)]}),(0,Y.jsx)(K,{size:`sm`,variant:`secondary`,onClick:()=>s(!0),className:`text-red-600 dark:text-red-400 hover:text-red-700 dark:hover:text-red-300`,children:(0,Y.jsx)(qe,{className:`w-4 h-4`})})]})]})]})}),o&&(0,Y.jsx)(Tt,{title:n(`smartPlugs.deleteSmartPlug`),message:n(`smartPlugs.deleteConfirm`,{name:e.name}),confirmText:n(`smartPlugs.delete`),variant:`danger`,onConfirm:()=>{T.mutate(),s(!1)},onCancel:()=>s(!1)}),c&&(0,Y.jsx)(Tt,{title:n(`smartPlugs.turnOnSmartPlug`),message:n(`smartPlugs.turnOnConfirm`,{name:e.name}),confirmText:n(`smartPlugs.turnOn`),variant:`default`,onConfirm:()=>{S.mutate(`on`),p(!1)},onCancel:()=>p(!1)}),m&&(0,Y.jsx)(Tt,{title:n(`smartPlugs.turnOffSmartPlug`),message:n(`smartPlugs.turnOffConfirm`,{name:e.name}),confirmText:n(`smartPlugs.turnOff`),variant:`danger`,onConfirm:()=>{S.mutate(`off`),h(!1)},onCancel:()=>h(!1)})]})}function pr({plug:e,onClose:t}){let{t:n}=l(),i=u(),a=!!e,[o,s]=(0,X.useState)(e?.plug_type||`tasmota`),[c,p]=(0,X.useState)(e?.name||``),[m,h]=(0,X.useState)(e?.ip_address||``),[g,_]=(0,X.useState)(e?.username||``),[v,y]=(0,X.useState)(e?.password||``),[b,x]=(0,X.useState)(e?.ha_entity_id||``),[S,C]=(0,X.useState)(e?.mqtt_power_topic||e?.mqtt_topic||``),[w,T]=(0,X.useState)(e?.mqtt_power_path||``),[E,D]=(0,X.useState)((e?.mqtt_power_multiplier??e?.mqtt_multiplier??1).toString()),[O,k]=(0,X.useState)(e?.mqtt_energy_topic||``),[A,ee]=(0,X.useState)(e?.mqtt_energy_path||``),[M,N]=(0,X.useState)((e?.mqtt_energy_multiplier??1).toString()),[P,te]=(0,X.useState)(e?.mqtt_state_topic||``),[F,ne]=(0,X.useState)(e?.mqtt_state_path||``),[I,re]=(0,X.useState)(e?.mqtt_state_on_value||``),[ie,ae]=(0,X.useState)(e?.rest_on_url||``),[z,oe]=(0,X.useState)(e?.rest_on_body||``),[se,B]=(0,X.useState)(e?.rest_off_url||``),[ce,le]=(0,X.useState)(e?.rest_off_body||``),[ue,de]=(0,X.useState)(e?.rest_method||`POST`),[fe,V]=(0,X.useState)(e?.rest_headers||``),[pe,me]=(0,X.useState)(e?.rest_status_url||``),[he,ge]=(0,X.useState)(e?.rest_status_path||``),[_e,ve]=(0,X.useState)(e?.rest_status_on_value||``),[ye,be]=(0,X.useState)(e?.rest_power_url||``),[H,xe]=(0,X.useState)(e?.rest_power_path||``),[Se,Ce]=(0,X.useState)((e?.rest_power_multiplier??1).toString()),[we,Te]=(0,X.useState)(e?.rest_energy_url||``),[Ee,De]=(0,X.useState)(e?.rest_energy_path||``),[Oe,ke]=(0,X.useState)((e?.rest_energy_multiplier??1).toString()),[je,Me]=(0,X.useState)(e?.rest_energy_total_path||``),[Ne,Pe]=(0,X.useState)((e?.rest_energy_total_multiplier??1).toString()),[Fe,Ie]=(0,X.useState)(e?.ha_power_entity||``),[Le,U]=(0,X.useState)(e?.ha_energy_today_entity||``),[W,ze]=(0,X.useState)(e?.ha_energy_total_entity||``),[G,Be]=(0,X.useState)(``),[Ve,He]=(0,X.useState)(``),[Ue,We]=(0,X.useState)(!1),Ge=(0,X.useRef)(null),[Ke,q]=(0,X.useState)(``),[qe,Je]=(0,X.useState)(!1),Xe=(0,X.useRef)(null),[Ze,Qe]=(0,X.useState)(``),[$e,et]=(0,X.useState)(!1),tt=(0,X.useRef)(null),[nt,it]=(0,X.useState)(``),[at,ot]=(0,X.useState)(!1),st=(0,X.useRef)(null),[ct,ut]=(0,X.useState)(e?.printer_id||null),[ft,pt]=(0,X.useState)(e?.controls_printer_power??!0),[gt,vt]=(0,X.useState)(null),[yt,bt]=(0,X.useState)(null),[xt,St]=(0,X.useState)(e?.power_alert_enabled||!1),[wt,Tt]=(0,X.useState)(e?.power_alert_high?.toString()||``),[Et,Dt]=(0,X.useState)(e?.power_alert_low?.toString()||``),[Ot,kt]=(0,X.useState)(e?.schedule_enabled||!1),[At,jt]=(0,X.useState)(e?.schedule_on_time||``),[Mt,Nt]=(0,X.useState)(e?.schedule_off_time||``),[Pt,It]=(0,X.useState)(e?.show_in_switchbar||!1),[Lt,Rt]=(0,X.useState)(e?.show_on_printer_card??!0),[Bt,Vt]=(0,X.useState)(!1),[Ht,Ut]=(0,X.useState)({scanned:0,total:0}),[Wt,Gt]=(0,X.useState)([]),Kt=(0,X.useRef)(null),{data:qt}=d({queryKey:[`printers`],queryFn:r.getPrinters}),{data:Jt}=d({queryKey:[`smart-plugs`],queryFn:r.getSmartPlugs}),{data:Yt}=d({queryKey:[`settings`],queryFn:r.getSettings}),Xt=!!(Yt?.ha_enabled&&Yt?.ha_url&&Yt?.ha_token);(0,X.useEffect)(()=>{let e=setTimeout(()=>{He(G)},300);return()=>clearTimeout(e)},[G]),(0,X.useEffect)(()=>{let e=e=>{Ge.current&&!Ge.current.contains(e.target)&&We(!1),Xe.current&&!Xe.current.contains(e.target)&&Je(!1),tt.current&&!tt.current.contains(e.target)&&et(!1),st.current&&!st.current.contains(e.target)&&ot(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[]);let{data:Zt,isLoading:Qt,error:$t}=d({queryKey:[`ha-entities`,Ve],queryFn:()=>r.getHAEntities(Ve||void 0),enabled:o===`homeassistant`&&Xt,retry:!1,staleTime:0}),{data:tn}=d({queryKey:[`ha-sensor-entities`],queryFn:r.getHASensorEntities,enabled:o===`homeassistant`&&Xt,retry:!1,staleTime:0});(0,X.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,e),()=>{window.removeEventListener(`keydown`,e),Kt.current&&clearInterval(Kt.current)}},[t]);let nn=async()=>{Vt(!0),Gt([]),Ut({scanned:0,total:0}),bt(null);try{await r.startTasmotaScan();let e=async()=>{try{let e=await r.getTasmotaScanStatus();Ut({scanned:e.scanned,total:e.total}),Gt(await r.getDiscoveredTasmotaDevices()),e.running||(Vt(!1),Kt.current&&=(clearInterval(Kt.current),null))}catch(e){console.error(`Polling error:`,e)}};await e(),Kt.current=setInterval(e,500)}catch(e){Vt(!1),bt((e instanceof Error?e.message:typeof e==`string`?e:JSON.stringify(e))||n(`smartPlugs.failedToStartScan`))}},rn=async()=>{try{await r.stopTasmotaScan()}catch{}Vt(!1),Kt.current&&=(clearInterval(Kt.current),null)},an=e=>{h(e.ip_address),p(e.name),vt(null)},on=f({mutationFn:()=>r.testSmartPlugConnection(m,g||null,v||null),onSuccess:e=>{vt(e),bt(null),!c&&e.device_name&&p(e.device_name)},onError:e=>{vt(null),bt(e.message)}}),sn=f({mutationFn:e=>r.createSmartPlug(e),onSuccess:()=>{i.invalidateQueries({queryKey:[`smart-plugs`]}),i.invalidateQueries({queryKey:[`scriptPlugsByPrinter`]}),t()},onError:e=>{bt(e.message)}}),cn=f({mutationFn:t=>r.updateSmartPlug(e.id,t),onSuccess:()=>{i.invalidateQueries({queryKey:[`smart-plugs`]}),i.invalidateQueries({queryKey:[`scriptPlugsByPrinter`]}),t()},onError:e=>{bt(e.message)}}),ln=qt?.filter(t=>o===`tasmota`?!Jt?.some(n=>n.printer_id===t.id&&n.id!==e?.id&&n.plug_type===`tasmota`):!0),un=e=>{if(e.preventDefault(),bt(null),!c.trim()){bt(n(`smartPlugs.nameRequired`));return}if(o===`tasmota`&&!m.trim()){bt(`IP address is required for Tasmota plugs`);return}if(o===`homeassistant`&&!b){bt(n(`smartPlugs.entityRequired`));return}if(o===`mqtt`){let e=S.trim(),t=O.trim(),r=P.trim();if(!e&&!t&&!r){bt(n(`smartPlugs.mqttTopicRequired`));return}}if(o===`rest`&&!ie.trim()&&!se.trim()){bt(n(`smartPlugs.restUrlRequired`));return}let t={name:c.trim(),plug_type:o,ip_address:o===`tasmota`?m.trim():null,ha_entity_id:o===`homeassistant`?b:null,ha_power_entity:o===`homeassistant`&&Fe||null,ha_energy_today_entity:o===`homeassistant`&&Le||null,ha_energy_total_entity:o===`homeassistant`&&W||null,mqtt_power_topic:o===`mqtt`&&S.trim()||null,mqtt_power_path:o===`mqtt`&&w.trim()||null,mqtt_power_multiplier:o===`mqtt`&&parseFloat(E)||1,mqtt_energy_topic:o===`mqtt`&&O.trim()||null,mqtt_energy_path:o===`mqtt`&&A.trim()||null,mqtt_energy_multiplier:o===`mqtt`&&parseFloat(M)||1,mqtt_state_topic:o===`mqtt`&&P.trim()||null,mqtt_state_path:o===`mqtt`&&F.trim()||null,mqtt_state_on_value:o===`mqtt`&&I.trim()||null,rest_on_url:o===`rest`&&ie.trim()||null,rest_on_body:o===`rest`&&z.trim()||null,rest_off_url:o===`rest`&&se.trim()||null,rest_off_body:o===`rest`&&ce.trim()||null,rest_method:o===`rest`?ue:null,rest_headers:o===`rest`&&fe.trim()||null,rest_status_url:o===`rest`&&pe.trim()||null,rest_status_path:o===`rest`&&he.trim()||null,rest_status_on_value:o===`rest`&&_e.trim()||null,rest_power_url:o===`rest`&&ye.trim()||null,rest_power_path:o===`rest`&&H.trim()||null,rest_power_multiplier:o===`rest`&&parseFloat(Se)||1,rest_energy_url:o===`rest`&&we.trim()||null,rest_energy_path:o===`rest`&&Ee.trim()||null,rest_energy_multiplier:o===`rest`&&parseFloat(Oe)||1,rest_energy_total_path:o===`rest`&&je.trim()||null,rest_energy_total_multiplier:o===`rest`&&parseFloat(Ne)||1,username:o===`tasmota`&&g.trim()||null,password:o===`tasmota`&&v.trim()||null,printer_id:ct,controls_printer_power:ft,power_alert_enabled:xt,power_alert_high:wt?parseFloat(wt):null,power_alert_low:Et?parseFloat(Et):null,schedule_enabled:Ot,schedule_on_time:At||null,schedule_off_time:Mt||null,show_in_switchbar:Pt,show_on_printer_card:Lt};a?cn.mutate(t):sn.mutate(t)},J=sn.isPending||cn.isPending;return(0,Y.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:t,children:(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-md max-h-[90vh] flex flex-col`,onClick:e=>e.stopPropagation(),children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary flex-shrink-0`,children:[(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:n(a?`smartPlugs.editTitle`:`smartPlugs.addTitle`)}),(0,Y.jsx)(`button`,{onClick:t,className:`text-bambu-gray hover:text-white transition-colors`,children:(0,Y.jsx)(Re,{className:`w-5 h-5`})})]}),(0,Y.jsxs)(`form`,{onSubmit:un,className:`p-6 space-y-4 overflow-y-auto`,children:[yt&&(0,Y.jsx)(`div`,{className:`p-3 bg-red-100 dark:bg-red-500/20 border border-red-400 dark:border-red-500/50 rounded-lg text-sm text-red-700 dark:text-red-400`,children:yt}),!a&&(0,Y.jsxs)(`div`,{className:`flex gap-2 mb-2`,children:[(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>{s(`tasmota`),vt(null),bt(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2.5 rounded-lg font-medium transition-colors ${o===`tasmota`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white border border-bambu-dark-tertiary`}`,children:[(0,Y.jsx)(dt,{className:`w-4 h-4`}),`Tasmota`]}),(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>{s(`homeassistant`),vt(null),bt(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2.5 rounded-lg font-medium transition-colors ${o===`homeassistant`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white border border-bambu-dark-tertiary`}`,children:[(0,Y.jsx)(Ft,{className:`w-4 h-4`}),`HA`]}),(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>{s(`mqtt`),vt(null),bt(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2.5 rounded-lg font-medium transition-colors ${o===`mqtt`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white border border-bambu-dark-tertiary`}`,children:[(0,Y.jsx)(en,{className:`w-4 h-4`}),`MQTT`]}),(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>{s(`rest`),vt(null),bt(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2.5 rounded-lg font-medium transition-colors ${o===`rest`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white border border-bambu-dark-tertiary`}`,children:[(0,Y.jsx)(zt,{className:`w-4 h-4`}),`REST`]})]}),!a&&o===`tasmota`&&(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[Bt?(0,Y.jsxs)(K,{type:`button`,variant:`secondary`,onClick:rn,className:`w-full`,children:[(0,Y.jsx)(Re,{className:`w-4 h-4`}),n(`smartPlugs.stopScanning`)]}):(0,Y.jsxs)(K,{type:`button`,variant:`primary`,onClick:nn,className:`w-full`,children:[(0,Y.jsx)(Ae,{className:`w-4 h-4`}),n(`smartPlugs.discoverTasmota`)]}),Bt&&Ht.total>0&&(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsxs)(`div`,{className:`flex justify-between text-xs text-bambu-gray`,children:[(0,Y.jsx)(`span`,{children:n(`smartPlugs.addSmartPlug.scanningNetwork`)}),(0,Y.jsxs)(`span`,{children:[Ht.scanned,` / `,Ht.total]})]}),(0,Y.jsx)(`div`,{className:`w-full bg-bambu-dark-tertiary rounded-full h-2`,children:(0,Y.jsx)(`div`,{className:`bg-bambu-green h-2 rounded-full transition-all duration-300`,style:{width:`${Ht.scanned/Ht.total*100}%`}})})]}),Wt.length>0&&(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.foundDevices`,{count:Wt.length})}),(0,Y.jsx)(`div`,{className:`max-h-40 overflow-y-auto space-y-1`,children:Wt.map(e=>(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>an(e),className:`w-full flex items-center justify-between p-2 bg-bambu-dark hover:bg-bambu-dark-tertiary rounded-lg transition-colors text-left border border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(dt,{className:`w-4 h-4 text-bambu-green`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:e.name}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:e.ip_address})]})]}),e.state&&(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 text-xs ${e.state===`ON`?`text-bambu-green`:`text-bambu-gray`}`,children:[(0,Y.jsx)(Ct,{className:`w-3 h-3`}),e.state]})]},e.ip_address))})]}),!Bt&&Wt.length===0&&Ht.total>0&&(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray text-center py-2`,children:n(`smartPlugs.noDevicesFound`)})]}),o===`homeassistant`&&(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[!Xt&&(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`p-3 bg-yellow-100 dark:bg-yellow-500/20 border border-yellow-400 dark:border-yellow-500/50 rounded-lg text-sm text-yellow-700 dark:text-yellow-400`,children:[n(`smartPlugs.haNotConfigured`),` `,(0,Y.jsx)(`span`,{className:`font-medium`,children:n(`smartPlugs.haSettingsPath`)})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1 opacity-50`,children:n(`smartPlugs.selectEntity`)}),(0,Y.jsx)(`select`,{disabled:!0,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray cursor-not-allowed opacity-50`,children:(0,Y.jsx)(`option`,{children:n(`smartPlugs.addSmartPlug.chooseEntity`)})})]})]}),Xt&&(0,Y.jsxs)(Y.Fragment,{children:[Qt&&(0,Y.jsxs)(`div`,{className:`flex items-center justify-center py-4 text-bambu-gray`,children:[(0,Y.jsx)(R,{className:`w-5 h-5 animate-spin mr-2`}),n(`smartPlugs.loadingEntities`)]}),$t&&(0,Y.jsx)(`div`,{className:`p-3 bg-red-100 dark:bg-red-500/20 border border-red-400 dark:border-red-500/50 rounded-lg text-sm text-red-700 dark:text-red-400`,children:n(`smartPlugs.failedToLoadEntities`,{error:$t.message})}),(()=>{let t=Jt?.filter(t=>t.ha_entity_id&&t.id!==e?.id).map(e=>e.ha_entity_id)||[],r=(Zt||[]).filter(e=>!t.includes(e.entity_id)),i=Zt?.find(e=>e.entity_id===b);return(0,Y.jsxs)(`div`,{ref:Ge,className:`relative`,children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.selectEntity`)}),(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsx)(Ae,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`}),(0,Y.jsx)(`input`,{type:`text`,value:Ue?G:i?`${i.friendly_name} (${i.entity_id})`:``,onChange:e=>{Be(e.target.value),Ue||We(!0)},onFocus:()=>{We(!0),Be(``)},placeholder:n(`smartPlugs.addSmartPlug.placeholders.searchEntities`),className:`w-full pl-9 pr-8 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`}),b&&!Ue&&(0,Y.jsx)(`button`,{type:`button`,onClick:()=>{x(``),Be(``)},className:`absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-bambu-dark-tertiary rounded`,children:(0,Y.jsx)(Re,{className:`w-4 h-4 text-bambu-gray hover:text-white`})}),Qt&&(0,Y.jsx)(R,{className:`absolute right-2 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray animate-spin`})]}),Ue&&(0,Y.jsxs)(`div`,{className:`absolute z-50 w-full mt-1 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-60 overflow-y-auto`,children:[Qt&&(0,Y.jsxs)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray flex items-center gap-2`,children:[(0,Y.jsx)(R,{className:`w-4 h-4 animate-spin`}),n(`smartPlugs.loading`)]}),!Qt&&r.length===0&&(0,Y.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:Ve?n(`smartPlugs.noEntitiesMatching`,{search:Ve}):n(`smartPlugs.noEntitiesAvailable`)}),!Qt&&r.map(e=>(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>{x(e.entity_id),We(!1),Be(``),c||p(e.friendly_name)},className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary transition-colors ${e.entity_id===b?`bg-bambu-green/20 text-bambu-green`:`text-white`}`,children:[(0,Y.jsx)(`div`,{className:`font-medium`,children:e.friendly_name}),(0,Y.jsxs)(`div`,{className:`text-xs text-bambu-gray flex items-center justify-between`,children:[(0,Y.jsx)(`span`,{children:e.entity_id}),(0,Y.jsx)(`span`,{className:e.state===`on`?`text-bambu-green`:``,children:e.state})]})]},e.entity_id))]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(Ve?`smartPlugs.searchingEntities`:`smartPlugs.showingEntities`,{count:r.length})})]})})(),b&&tn&&tn.length>0&&(0,Y.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary pt-4 mt-4 space-y-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-white font-medium mb-1`,children:n(`smartPlugs.energyMonitoringOptional`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mb-3`,children:n(`smartPlugs.energyMonitoringHint`)})]}),(()=>{let e=tn.filter(e=>e.unit_of_measurement===`W`||e.unit_of_measurement===`kW`||e.unit_of_measurement===`mW`),t=Ke?e.filter(e=>e.entity_id.toLowerCase().includes(Ke.toLowerCase())||e.friendly_name.toLowerCase().includes(Ke.toLowerCase())):e,r=tn.find(e=>e.entity_id===Fe);return(0,Y.jsxs)(`div`,{ref:Xe,className:`relative`,children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.powerSensorW`)}),(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsx)(Ae,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`}),(0,Y.jsx)(`input`,{type:`text`,value:qe?Ke:r?`${r.friendly_name} (${r.state} ${r.unit_of_measurement})`:``,onChange:e=>{q(e.target.value),qe||Je(!0)},onFocus:()=>{Je(!0),q(``)},placeholder:n(`smartPlugs.addSmartPlug.placeholders.searchPowerSensors`),className:`w-full pl-9 pr-8 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`}),Fe&&!qe&&(0,Y.jsx)(`button`,{type:`button`,onClick:()=>{Ie(``),q(``)},className:`absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-bambu-dark-tertiary rounded`,children:(0,Y.jsx)(Re,{className:`w-4 h-4 text-bambu-gray hover:text-white`})})]}),qe&&(0,Y.jsxs)(`div`,{className:`absolute z-50 w-full mt-1 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-48 overflow-y-auto`,children:[(0,Y.jsx)(`button`,{type:`button`,onClick:()=>{Ie(``),Je(!1),q(``)},className:`w-full px-3 py-2 text-left text-sm text-bambu-gray hover:bg-bambu-dark-tertiary`,children:n(`smartPlugs.none`)}),t.map(e=>(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>{Ie(e.entity_id),Je(!1),q(``)},className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${e.entity_id===Fe?`bg-bambu-green/20 text-bambu-green`:`text-white`}`,children:[(0,Y.jsx)(`div`,{className:`font-medium`,children:e.friendly_name}),(0,Y.jsxs)(`div`,{className:`text-xs text-bambu-gray`,children:[e.entity_id,` • `,e.state,` `,e.unit_of_measurement]})]},e.entity_id)),t.length===0&&(0,Y.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:n(`smartPlugs.noMatchingSensors`)})]})]})})(),(()=>{let e=tn.filter(e=>e.unit_of_measurement===`kWh`||e.unit_of_measurement===`Wh`||e.unit_of_measurement===`MWh`),t=Ze?e.filter(e=>e.entity_id.toLowerCase().includes(Ze.toLowerCase())||e.friendly_name.toLowerCase().includes(Ze.toLowerCase())):e,r=tn.find(e=>e.entity_id===Le);return(0,Y.jsxs)(`div`,{ref:tt,className:`relative`,children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.energyTodayKwh`)}),(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsx)(Ae,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`}),(0,Y.jsx)(`input`,{type:`text`,value:$e?Ze:r?`${r.friendly_name} (${r.state} ${r.unit_of_measurement})`:``,onChange:e=>{Qe(e.target.value),$e||et(!0)},onFocus:()=>{et(!0),Qe(``)},placeholder:n(`smartPlugs.addSmartPlug.placeholders.searchEnergySensors`),className:`w-full pl-9 pr-8 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`}),Le&&!$e&&(0,Y.jsx)(`button`,{type:`button`,onClick:()=>{U(``),Qe(``)},className:`absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-bambu-dark-tertiary rounded`,children:(0,Y.jsx)(Re,{className:`w-4 h-4 text-bambu-gray hover:text-white`})})]}),$e&&(0,Y.jsxs)(`div`,{className:`absolute z-50 w-full mt-1 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-48 overflow-y-auto`,children:[(0,Y.jsx)(`button`,{type:`button`,onClick:()=>{U(``),et(!1),Qe(``)},className:`w-full px-3 py-2 text-left text-sm text-bambu-gray hover:bg-bambu-dark-tertiary`,children:n(`smartPlugs.none`)}),t.map(e=>(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>{U(e.entity_id),et(!1),Qe(``)},className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${e.entity_id===Le?`bg-bambu-green/20 text-bambu-green`:`text-white`}`,children:[(0,Y.jsx)(`div`,{className:`font-medium`,children:e.friendly_name}),(0,Y.jsxs)(`div`,{className:`text-xs text-bambu-gray`,children:[e.entity_id,` • `,e.state,` `,e.unit_of_measurement]})]},e.entity_id)),t.length===0&&(0,Y.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:n(`smartPlugs.noMatchingSensors`)})]})]})})(),(()=>{let e=tn.filter(e=>e.unit_of_measurement===`kWh`||e.unit_of_measurement===`Wh`||e.unit_of_measurement===`MWh`),t=nt?e.filter(e=>e.entity_id.toLowerCase().includes(nt.toLowerCase())||e.friendly_name.toLowerCase().includes(nt.toLowerCase())):e,r=tn.find(e=>e.entity_id===W);return(0,Y.jsxs)(`div`,{ref:st,className:`relative`,children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.totalEnergyKwh`)}),(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsx)(Ae,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`}),(0,Y.jsx)(`input`,{type:`text`,value:at?nt:r?`${r.friendly_name} (${r.state} ${r.unit_of_measurement})`:``,onChange:e=>{it(e.target.value),at||ot(!0)},onFocus:()=>{ot(!0),it(``)},placeholder:n(`smartPlugs.addSmartPlug.placeholders.searchEnergySensors`),className:`w-full pl-9 pr-8 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`}),W&&!at&&(0,Y.jsx)(`button`,{type:`button`,onClick:()=>{ze(``),it(``)},className:`absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-bambu-dark-tertiary rounded`,children:(0,Y.jsx)(Re,{className:`w-4 h-4 text-bambu-gray hover:text-white`})})]}),at&&(0,Y.jsxs)(`div`,{className:`absolute z-50 w-full mt-1 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-48 overflow-y-auto`,children:[(0,Y.jsx)(`button`,{type:`button`,onClick:()=>{ze(``),ot(!1),it(``)},className:`w-full px-3 py-2 text-left text-sm text-bambu-gray hover:bg-bambu-dark-tertiary`,children:n(`smartPlugs.none`)}),t.map(e=>(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>{ze(e.entity_id),ot(!1),it(``)},className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${e.entity_id===W?`bg-bambu-green/20 text-bambu-green`:`text-white`}`,children:[(0,Y.jsx)(`div`,{className:`font-medium`,children:e.friendly_name}),(0,Y.jsxs)(`div`,{className:`text-xs text-bambu-gray`,children:[e.entity_id,` • `,e.state,` `,e.unit_of_measurement]})]},e.entity_id)),t.length===0&&(0,Y.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:n(`smartPlugs.noMatchingSensors`)})]})]})})()]})]})]}),o===`mqtt`&&(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[!Yt?.mqtt_broker&&(0,Y.jsxs)(`div`,{className:`p-3 bg-yellow-100 dark:bg-yellow-500/20 border border-yellow-400 dark:border-yellow-500/50 rounded-lg text-sm text-yellow-700 dark:text-yellow-400`,children:[n(`smartPlugs.mqttNotConfigured`),` `,(0,Y.jsx)(`span`,{className:`font-medium`,children:n(`smartPlugs.mqttSettingsPath`)}),` `,n(`smartPlugs.mqttNotConfiguredSuffix`)]}),Yt?.mqtt_broker&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`div`,{className:`p-3 bg-blue-50 dark:bg-blue-500/10 border border-blue-300 dark:border-blue-500/30 rounded-lg text-sm text-blue-700 dark:text-blue-300`,children:[(0,Y.jsx)(`p`,{className:`font-medium mb-1`,children:n(`smartPlugs.monitorOnly`)}),(0,Y.jsx)(`p`,{className:`text-xs opacity-80`,children:n(`smartPlugs.mqttMonitorOnlyDescription`)})]}),(0,Y.jsxs)(`div`,{className:`space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,Y.jsx)(`p`,{className:`text-white font-medium text-sm`,children:n(`smartPlugs.powerMonitoring`)}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.topic`)}),(0,Y.jsx)(`input`,{type:`text`,value:S,onChange:e=>C(e.target.value),placeholder:`zigbee2mqtt/shelly-working-room`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.jsonPath`)}),(0,Y.jsx)(`input`,{type:`text`,value:w,onChange:e=>T(e.target.value),placeholder:`power_l1`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.multiplier`)}),(0,Y.jsx)(`input`,{type:`text`,value:E,onChange:e=>D(e.target.value),placeholder:`1`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,style:{whiteSpace:`pre-line`},children:n(`smartPlugs.mqttPowerHint`)})]}),(0,Y.jsxs)(`div`,{className:`space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`p`,{className:`text-white font-medium text-sm`,children:[n(`smartPlugs.energyMonitoring`),` `,(0,Y.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,n(`smartPlugs.optional`),`)`]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.topic`)}),(0,Y.jsx)(`input`,{type:`text`,value:O,onChange:e=>k(e.target.value),placeholder:`Same as power topic, or different`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.jsonPath`)}),(0,Y.jsx)(`input`,{type:`text`,value:A,onChange:e=>ee(e.target.value),placeholder:`energy_l1`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.multiplier`)}),(0,Y.jsx)(`input`,{type:`text`,value:M,onChange:e=>N(e.target.value),placeholder:`1`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,style:{whiteSpace:`pre-line`},children:n(`smartPlugs.mqttEnergyHint`)})]}),(0,Y.jsxs)(`div`,{className:`space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`p`,{className:`text-white font-medium text-sm`,children:[n(`smartPlugs.stateMonitoring`),` `,(0,Y.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,n(`smartPlugs.optional`),`)`]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.topic`)}),(0,Y.jsx)(`input`,{type:`text`,value:P,onChange:e=>te(e.target.value),placeholder:`Same as power topic, or different`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.jsonPath`)}),(0,Y.jsx)(`input`,{type:`text`,value:F,onChange:e=>ne(e.target.value),placeholder:`state_l1`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.onValue`)}),(0,Y.jsx)(`input`,{type:`text`,value:I,onChange:e=>re(e.target.value),placeholder:n(`smartPlugs.addSmartPlug.placeholders.mqttStateOnValue`),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,style:{whiteSpace:`pre-line`},children:n(`smartPlugs.mqttStateHint`)})]})]})]}),o===`rest`&&(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,Y.jsx)(`p`,{className:`text-white font-medium text-sm`,children:n(`smartPlugs.restControl`)}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restMethod`)}),(0,Y.jsxs)(`select`,{value:ue,onChange:e=>de(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,Y.jsx)(`option`,{value:`GET`,children:`GET`}),(0,Y.jsx)(`option`,{value:`POST`,children:`POST`}),(0,Y.jsx)(`option`,{value:`PUT`,children:`PUT`}),(0,Y.jsx)(`option`,{value:`PATCH`,children:`PATCH`})]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restOnUrl`)}),(0,Y.jsx)(`input`,{type:`text`,value:ie,onChange:e=>{ae(e.target.value),vt(null)},placeholder:`http://openhab:8080/rest/items/MyPlug`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[n(`smartPlugs.restOnBody`),` `,(0,Y.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,n(`smartPlugs.optional`),`)`]})]}),(0,Y.jsx)(`input`,{type:`text`,value:z,onChange:e=>oe(e.target.value),placeholder:n(`smartPlugs.restBodyHint`),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restOffUrl`)}),(0,Y.jsx)(`input`,{type:`text`,value:se,onChange:e=>{B(e.target.value),vt(null)},placeholder:`http://openhab:8080/rest/items/MyPlug`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[n(`smartPlugs.restOffBody`),` `,(0,Y.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,n(`smartPlugs.optional`),`)`]})]}),(0,Y.jsx)(`input`,{type:`text`,value:ce,onChange:e=>le(e.target.value),placeholder:n(`smartPlugs.restBodyHint`),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]})]}),(0,Y.jsxs)(`div`,{className:`space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`p`,{className:`text-white font-medium text-sm`,children:[n(`smartPlugs.restHeaders`),` `,(0,Y.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,n(`smartPlugs.optional`),`)`]})]}),(0,Y.jsx)(`div`,{children:(0,Y.jsx)(`textarea`,{value:fe,onChange:e=>V(e.target.value),placeholder:n(`smartPlugs.restHeadersHint`),rows:2,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none font-mono text-sm`})})]}),(0,Y.jsxs)(`div`,{className:`space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`p`,{className:`text-white font-medium text-sm`,children:[n(`smartPlugs.stateMonitoring`),` `,(0,Y.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,n(`smartPlugs.optional`),`)`]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restStatusUrl`)}),(0,Y.jsx)(`input`,{type:`text`,value:pe,onChange:e=>me(e.target.value),placeholder:n(`smartPlugs.restStatusHint`),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restStatusPath`)}),(0,Y.jsx)(`input`,{type:`text`,value:he,onChange:e=>ge(e.target.value),placeholder:n(`smartPlugs.restPathHint`),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restStatusOnValue`)}),(0,Y.jsx)(`input`,{type:`text`,value:_e,onChange:e=>ve(e.target.value),placeholder:`ON`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]})]})]}),(0,Y.jsxs)(`div`,{className:`space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`p`,{className:`text-white font-medium text-sm`,children:[n(`smartPlugs.energyMonitoring`),` `,(0,Y.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,n(`smartPlugs.optional`),`)`]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[n(`smartPlugs.restPowerUrl`),` `,(0,Y.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,n(`smartPlugs.optional`),`)`]})]}),(0,Y.jsx)(`input`,{type:`text`,value:ye,onChange:e=>be(e.target.value),placeholder:n(`smartPlugs.restPowerUrlHint`),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restPowerPath`)}),(0,Y.jsx)(`input`,{type:`text`,value:H,onChange:e=>xe(e.target.value),placeholder:n(`smartPlugs.restPathHint`),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restPowerMultiplier`)}),(0,Y.jsx)(`input`,{type:`text`,value:Se,onChange:e=>Ce(e.target.value),placeholder:`1`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[n(`smartPlugs.restEnergyUrl`),` `,(0,Y.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,n(`smartPlugs.optional`),`)`]})]}),(0,Y.jsx)(`input`,{type:`text`,value:we,onChange:e=>Te(e.target.value),placeholder:n(`smartPlugs.restEnergyUrlHint`),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restEnergyPath`)}),(0,Y.jsx)(`input`,{type:`text`,value:Ee,onChange:e=>De(e.target.value),placeholder:n(`smartPlugs.restPathHint`),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restEnergyMultiplier`)}),(0,Y.jsx)(`input`,{type:`text`,value:Oe,onChange:e=>ke(e.target.value),placeholder:`1`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.restEnergyHint`)}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restEnergyTotalPath`)}),(0,Y.jsx)(`input`,{type:`text`,value:je,onChange:e=>Me(e.target.value),placeholder:n(`smartPlugs.restEnergyTotalPathHint`),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restEnergyTotalMultiplier`)}),(0,Y.jsx)(`input`,{type:`text`,value:Ne,onChange:e=>Pe(e.target.value),placeholder:`1`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.restEnergyTotalHint`)})]}),(ie.trim()||se.trim())&&(0,Y.jsx)(`div`,{className:`flex gap-2`,children:(0,Y.jsxs)(K,{type:`button`,variant:`secondary`,onClick:async()=>{vt(null);try{let e=ie.trim()||se.trim(),t=await r.testRESTConnection(e,ue,fe.trim()||null);vt({success:t.success}),t.success||bt(t.error||n(`smartPlugs.addSmartPlug.connectionFailed`))}catch{vt({success:!1}),bt(n(`smartPlugs.addSmartPlug.connectionFailed`))}},className:`w-full`,children:[(0,Y.jsx)(ht,{className:`w-4 h-4`}),n(`smartPlugs.testConnection`)]})}),gt&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-sm ${gt.success?`text-green-700 dark:text-green-400`:`text-red-700 dark:text-red-400`}`,children:[gt.success?(0,Y.jsx)(j,{className:`w-4 h-4`}):(0,Y.jsx)(Ye,{className:`w-4 h-4`}),gt.success?n(`smartPlugs.connectionSuccess`):n(`smartPlugs.addSmartPlug.connectionFailed`)]})]}),o===`tasmota`&&(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.ipAddress`)}),(0,Y.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Y.jsx)(`input`,{type:`text`,value:m,onChange:e=>{h(e.target.value),vt(null)},placeholder:`192.168.1.100`,className:`flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,Y.jsxs)(K,{type:`button`,variant:`secondary`,onClick:()=>on.mutate(),disabled:!m.trim()||on.isPending,children:[on.isPending?(0,Y.jsx)(R,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(ht,{className:`w-4 h-4`}),n(`smartPlugs.test`)]})]})]}),o===`tasmota`&>&&(0,Y.jsx)(`div`,{className:`p-3 rounded-lg flex items-center gap-2 ${gt.success?`bg-bambu-green/20 border border-bambu-green/50 text-bambu-green`:`bg-red-100 dark:bg-red-500/20 border border-red-400 dark:border-red-500/50 text-red-700 dark:text-red-400`}`,children:gt.success?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(j,{className:`w-5 h-5`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`font-medium`,children:n(`smartPlugs.connectedResult`)}),(0,Y.jsxs)(`p`,{className:`text-sm opacity-80`,children:[gt.device_name&&n(`smartPlugs.deviceLabel`,{name:gt.device_name}),n(`smartPlugs.stateLabel`,{state:gt.state})]})]})]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(Ye,{className:`w-5 h-5`}),(0,Y.jsx)(`span`,{children:n(`smartPlugs.addSmartPlug.connectionFailed`)})]})}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.nameLabel`)}),(0,Y.jsx)(`input`,{type:`text`,value:c,onChange:e=>p(e.target.value),placeholder:n(`smartPlugs.addSmartPlug.placeholders.plugName`),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),o===`tasmota`&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.username`)}),(0,Y.jsx)(`input`,{type:`text`,value:g,onChange:e=>_(e.target.value),placeholder:`admin`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.password`)}),(0,Y.jsx)(`input`,{type:`password`,value:v,onChange:e=>y(e.target.value),placeholder:`********`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray -mt-2`,children:n(`smartPlugs.authHint`)})]}),o!==`mqtt`&&(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.linkToPrinter`)}),(0,Y.jsxs)(`select`,{value:ct??``,onChange:e=>ut(e.target.value?Number(e.target.value):null),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,Y.jsx)(`option`,{value:``,children:n(`smartPlugs.noPrinter`)}),ln?.map(e=>(0,Y.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(`smartPlugs.linkingDescription`)}),ct!==null&&(0,Y.jsxs)(`div`,{className:`flex items-center justify-between mt-3`,children:[(0,Y.jsxs)(`div`,{className:`pr-3`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`smartPlugs.controlsPrinterPower`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.controlsPrinterPowerDescription`)})]}),(0,Y.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer shrink-0`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:ft,onChange:e=>pt(e.target.checked),className:`sr-only peer`}),(0,Y.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]})]}),(0,Y.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary pt-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(rt,{className:`w-4 h-4 text-bambu-green`}),(0,Y.jsx)(`span`,{className:`text-white font-medium`,children:n(`smartPlugs.powerAlerts`)})]}),(0,Y.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:xt,onChange:e=>St(e.target.checked),className:`sr-only peer`}),(0,Y.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),xt&&(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.alertAbove`)}),(0,Y.jsx)(`input`,{type:`number`,value:wt,onChange:e=>Tt(e.target.value),placeholder:`e.g. 200`,min:`0`,max:`5000`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.alertBelow`)}),(0,Y.jsx)(`input`,{type:`number`,value:Et,onChange:e=>Dt(e.target.value),placeholder:`e.g. 10`,min:`0`,max:`5000`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.alertDescription`)})]})]}),o!==`mqtt`&&(0,Y.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary pt-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(lt,{className:`w-4 h-4 text-bambu-green`}),(0,Y.jsx)(`span`,{className:`text-white font-medium`,children:n(`smartPlugs.dailySchedule`)})]}),(0,Y.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:Ot,onChange:e=>kt(e.target.checked),className:`sr-only peer`}),(0,Y.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),Ot&&(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.turnOnAt`)}),(0,Y.jsx)(`input`,{type:`time`,value:At,onChange:e=>jt(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`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.turnOffAt`)}),(0,Y.jsx)(`input`,{type:`time`,value:Mt,onChange:e=>Nt(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`})]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.scheduleDescription`)})]})]}),(0,Y.jsx)(`div`,{className:`border-t border-bambu-dark-tertiary pt-4`,children:(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(L,{className:`w-4 h-4 text-bambu-green`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-white font-medium`,children:n(`smartPlugs.showInSwitchbar`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.quickAccessSidebar`)})]})]}),(0,Y.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:Pt,onChange:e=>It(e.target.checked),className:`sr-only peer`}),(0,Y.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]})}),o===`homeassistant`&&(0,Y.jsx)(`div`,{className:`border-t border-bambu-dark-tertiary pt-4`,children:(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(mt,{className:`w-4 h-4 text-bambu-green`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-white font-medium`,children:n(`smartPlugs.showOnPrinterCard`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.displayOnPrinterCard`)})]})]}),(0,Y.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:Lt,onChange:e=>Rt(e.target.checked),className:`sr-only peer`}),(0,Y.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]})}),(0,Y.jsxs)(`div`,{className:`flex gap-3 pt-2`,children:[(0,Y.jsx)(K,{type:`button`,variant:`secondary`,onClick:t,className:`flex-1`,children:n(`smartPlugs.cancel`)}),(0,Y.jsxs)(K,{type:`submit`,disabled:J,className:`flex-1`,children:[J?(0,Y.jsx)(R,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(_t,{className:`w-4 h-4`}),n(a?`smartPlugs.save`:`smartPlugs.add`)]})]})]})]})})}function mr({sensor:e,printers:t,onClose:n}){let{t:i}=l(),a=u(),{showToast:o}=ee(),s=!!e,[c,p]=(0,X.useState)(e?.printer_id??t[0]?.id??``),[m,h]=(0,X.useState)(e?.entity_id??``),[g,_]=(0,X.useState)(e?.kind??`binary`),[v,y]=(0,X.useState)(e?.device_class??null),[b,S]=(0,X.useState)(e?.unit??null),[C,w]=(0,X.useState)(e?.name??``),[T,E]=(0,X.useState)(e?.alert_state??``),[D,O]=(0,X.useState)(e?.alert_above?.toString()??``),[k,A]=(0,X.useState)(e?.alert_below?.toString()??``),[j,M]=(0,X.useState)(e?.show_on_printer_card??!0),[N,P]=(0,X.useState)(e?.notify_on_alert??!1),[te,F]=(0,X.useState)(e?.block_print??!1),[I,re]=(0,X.useState)(``),[ie,L]=(0,X.useState)(null);(0,X.useEffect)(()=>{let e=e=>{e.key===`Escape`&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n]);let{data:ae}=d({queryKey:[`settings`],queryFn:r.getSettings}),z=!!(ae?.ha_enabled&&ae?.ha_url&&ae?.ha_token),{data:oe,isLoading:se,error:B}=d({queryKey:[`bindableHAEntities`],queryFn:()=>r.getBindableHAEntities(),enabled:z}),ce=(0,X.useMemo)(()=>{let e=I.trim().toLowerCase(),t=oe??[];return e?t.filter(t=>t.entity_id.toLowerCase().includes(e)||t.friendly_name.toLowerCase().includes(e)):t},[oe,I]),le=e=>{h(e.entity_id),y(e.device_class),S(e.unit_of_measurement);let t=e.domain===`binary_sensor`?`binary`:`numeric`;_(t),t===`numeric`?E(``):(O(``),A(``)),C.trim()||w(e.friendly_name.slice(0,100))},ue=()=>{a.invalidateQueries({queryKey:[`haSensors`]}),a.invalidateQueries({queryKey:[`haSensorReadings`]})},de=f({mutationFn:()=>{let t={name:C.trim(),entity_id:m,kind:g,device_class:v,unit:b,alert_state:g===`binary`&&T?T:null,alert_above:g===`numeric`&&D!==``?Number(D):null,alert_below:g===`numeric`&&k!==``?Number(k):null,block_print:te,notify_on_alert:N,show_on_printer_card:j};return s?r.updateHASensor(e.id,t):r.createHASensor({...t,printer_id:Number(c)})},onSuccess:()=>{ue(),o(i(s?`haSensors.toast.updated`:`haSensors.toast.created`),`success`),n()},onError:e=>L(e.message)}),fe=f({mutationFn:()=>r.deleteHASensor(e.id),onSuccess:()=>{ue(),o(i(`haSensors.toast.deleted`),`success`),n()},onError:e=>L(e.message)}),V=g===`binary`?T!==``:D!==``||k!==``,pe=e=>{if(e.preventDefault(),L(null),!m)return L(i(`haSensors.error.pickEntity`));if(!C.trim())return L(i(`haSensors.error.nameRequired`));if(c===``)return L(i(`haSensors.error.printerRequired`));if((te||N)&&!V)return L(i(`haSensors.error.alertRequired`));de.mutate()},me=x[v??``],he=e=>{let t=me?.[e]??e;return i(`haSensors.states.${t}`,{defaultValue:t})},ge=de.isPending||fe.isPending;return(0,Y.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:n,children:(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-lg max-h-[90vh] overflow-y-auto`,onClick:e=>e.stopPropagation(),children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Y.jsx)(`div`,{className:`p-2 rounded-full bg-bambu-green/20 text-bambu-green`,children:(0,Y.jsx)(ne,{className:`w-5 h-5`})}),(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(s?`haSensors.editTitle`:`haSensors.addTitle`)})]}),(0,Y.jsx)(`button`,{onClick:n,className:`text-bambu-gray hover:text-white transition-colors`,children:(0,Y.jsx)(Re,{className:`w-5 h-5`})})]}),(0,Y.jsxs)(`form`,{onSubmit:pe,className:`p-6 space-y-4`,children:[ie&&(0,Y.jsx)(`div`,{className:`p-3 bg-red-100 dark:bg-red-500/20 border border-red-300 dark:border-red-500/50 rounded-lg text-sm text-red-700 dark:text-red-400`,children:ie}),!s&&(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`haSensors.printer`)}),(0,Y.jsx)(`select`,{value:c,onChange:e=>p(e.target.value===``?``:Number(e.target.value)),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white`,children:t.map(e=>(0,Y.jsx)(`option`,{value:e.id,children:e.name},e.id))})]}),!z&&(0,Y.jsxs)(`div`,{className:`p-3 bg-yellow-100 dark:bg-yellow-500/20 border border-yellow-400 dark:border-yellow-500/50 rounded-lg text-sm text-yellow-700 dark:text-yellow-400`,children:[i(`smartPlugs.haNotConfigured`),` `,(0,Y.jsx)(`span`,{className:`font-medium`,children:i(`smartPlugs.haSettingsPath`)})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1 ${z?``:`opacity-50`}`,children:i(`haSensors.entity`)}),B&&(0,Y.jsx)(`div`,{className:`p-3 mb-2 bg-red-100 dark:bg-red-500/20 rounded-lg text-sm text-red-700 dark:text-red-400`,children:B.message}),(0,Y.jsxs)(`div`,{className:`relative mb-2`,children:[(0,Y.jsx)(Ae,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,Y.jsx)(`input`,{type:`text`,value:I,onChange:e=>re(e.target.value),placeholder:i(`haSensors.searchPlaceholder`),disabled:!z,className:`w-full pl-9 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white disabled:opacity-50 disabled:cursor-not-allowed`})]}),(0,Y.jsxs)(`div`,{className:`max-h-44 overflow-y-auto rounded-lg border border-bambu-dark-tertiary ${z?``:`opacity-50`}`,children:[!z&&(0,Y.jsx)(`div`,{className:`p-3 text-sm text-bambu-gray`,children:i(`haSensors.noEntities`)}),z&&se&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 p-3 text-sm text-bambu-gray`,children:[(0,Y.jsx)(R,{className:`w-4 h-4 animate-spin`}),i(`common.loading`)]}),z&&!se&&ce.length===0&&(0,Y.jsx)(`div`,{className:`p-3 text-sm text-bambu-gray`,children:i(`haSensors.noEntities`)}),z&&!se&&ce.map(e=>(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>le(e),className:`w-full text-left px-3 py-2 text-sm transition-colors ${e.entity_id===m?`bg-bambu-green/20 text-bambu-green`:`text-white hover:bg-bambu-dark`}`,children:[(0,Y.jsx)(`div`,{className:`font-medium`,children:e.friendly_name}),(0,Y.jsxs)(`div`,{className:`text-xs text-bambu-gray`,children:[e.entity_id,e.state!==null&&` — ${e.state}`,e.unit_of_measurement?` ${e.unit_of_measurement}`:``]})]},e.entity_id))]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`haSensors.name`)}),(0,Y.jsx)(`input`,{type:`text`,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`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`haSensors.alertWhen`)}),g===`binary`?(0,Y.jsxs)(`select`,{value:T,onChange:e=>E(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white`,children:[(0,Y.jsx)(`option`,{value:``,children:i(`haSensors.alertNever`)}),(0,Y.jsx)(`option`,{value:`on`,children:he(`on`)}),(0,Y.jsx)(`option`,{value:`off`,children:he(`off`)})]}):(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`span`,{className:`block text-xs text-bambu-gray mb-1`,children:[i(`haSensors.alertAbove`),` `,b??``]}),(0,Y.jsx)(`input`,{type:`number`,step:`any`,value:D,onChange:e=>O(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`span`,{className:`block text-xs text-bambu-gray mb-1`,children:[i(`haSensors.alertBelow`),` `,b??``]}),(0,Y.jsx)(`input`,{type:`number`,step:`any`,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`})]})]}),(0,Y.jsx)(`p`,{className:`mt-1 text-xs text-bambu-gray`,children:i(`haSensors.alertHint`)})]}),(0,Y.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:j,onChange:e=>M(e.target.checked),className:`w-4 h-4`}),(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:i(`haSensors.showOnCard`)})]}),(0,Y.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:N,onChange:e=>P(e.target.checked),disabled:!V,className:`w-4 h-4`}),(0,Y.jsx)(`span`,{className:`text-sm ${V?`text-white`:`text-bambu-gray`}`,children:i(`haSensors.notifyOnAlert`)})]}),(0,Y.jsxs)(`label`,{className:`flex items-start gap-3 cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:te,onChange:e=>F(e.target.checked),disabled:!V,className:`w-4 h-4 mt-0.5`}),(0,Y.jsxs)(`span`,{children:[(0,Y.jsx)(`span`,{className:`block text-sm ${V?`text-white`:`text-bambu-gray`}`,children:i(`haSensors.blockPrint`)}),(0,Y.jsx)(`span`,{className:`block text-xs text-bambu-gray`,children:i(`haSensors.blockPrintHint`)})]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between pt-2`,children:[s?(0,Y.jsx)(K,{type:`button`,variant:`danger`,onClick:()=>fe.mutate(),disabled:ge,children:i(`common.delete`)}):(0,Y.jsx)(`span`,{}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(K,{type:`button`,variant:`secondary`,onClick:n,disabled:ge,children:i(`common.cancel`)}),(0,Y.jsxs)(K,{type:`submit`,disabled:ge||!z&&!s,children:[ge?(0,Y.jsx)(R,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(_t,{className:`w-4 h-4`}),i(`common.save`)]})]})]})]})]})})}function hr(e){return e===`temperature`?`temperature`:e===`humidity`?`humidity`:e===`battery`?`battery`:null}var gr={temperature:`temperature`,humidity:`humidity`,battery:`battery`};function _r(e,t,n){let r=gr[t];if(!e.toLowerCase().endsWith(r))return[];let i=e.slice(0,e.length-r.length),a=[];return Object.keys(gr).forEach(e=>{if(e===t)return;let r=`${i}${gr[e]}`.toLowerCase(),o=n.find(e=>e.entity_id.toLowerCase()===r);o&&a.push(o)}),a}function vr({sensor:e,locations:t,onClose:n}){let{t:i}=l(),a=u(),{showToast:o}=ee(),s=!!e,[c,p]=(0,X.useState)(e?.location_id??t[0]?.id??``),[m,h]=(0,X.useState)(e?.entity_id??``),[g,_]=(0,X.useState)(e?.kind??`numeric`),[v,y]=(0,X.useState)(e?.device_class??null),[b,S]=(0,X.useState)(e?.unit??null),[C,w]=(0,X.useState)(e?.name??``),T=(0,X.useRef)(e?.name??``),[E,D]=(0,X.useState)(e?.alert_state??``),[O,k]=(0,X.useState)(e?.alert_above?.toString()??``),[A,j]=(0,X.useState)(e?.alert_below?.toString()??``),[M,N]=(0,X.useState)(e?.notify_on_alert??!1),[P,te]=(0,X.useState)(e?.show_on_card??!0),[F,I]=(0,X.useState)(``),[re,ie]=(0,X.useState)(null),[L,ae]=(0,X.useState)(!1),[z,oe]=(0,X.useState)(!1),[se,B]=(0,X.useState)(null),[ce,le]=(0,X.useState)(!1),[de,fe]=(0,X.useState)([]),[V,pe]=(0,X.useState)({}),{data:me}=d({queryKey:[`settings`],queryFn:r.getSettings}),ge=!!(me?.ha_enabled&&me?.ha_url&&me?.ha_token),{data:_e,isLoading:ve,error:ye}=d({queryKey:[`bindableLocationHAEntities`],queryFn:()=>r.getBindableLocationHAEntities(),enabled:ge}),be=(0,X.useMemo)(()=>(_e??[]).filter(e=>hr(e.device_class)!==null),[_e]),{data:H}=d({queryKey:[`locationHaSensors`],queryFn:()=>r.getLocationHASensors()}),xe=be.find(e=>e.entity_id===m),Se=(0,X.useMemo)(()=>{let e=F.trim().toLowerCase(),t=be??[],n=e?t.filter(t=>t.entity_id.toLowerCase().includes(e)||t.friendly_name.toLowerCase().includes(e)):t;return!xe||n[0]?.entity_id===xe.entity_id?n:[xe,...n.filter(e=>e.entity_id!==xe.entity_id)]},[be,F,xe]),Ce=e=>{h(e.entity_id),y(e.device_class),S(e.unit_of_measurement?.slice(0,16)??null);let t=e.domain===`binary_sensor`?`binary`:`numeric`;if(_(t),t===`numeric`?D(``):(k(``),j(``)),C===T.current){let t=e.friendly_name.slice(0,100);w(t),T.current=t}if(!s){let n=hr(e.device_class);if(n){let e=he(me?.location_sensor_alert_defaults)[n];t===`numeric`&&(k(n===`battery`?``:e.alertAbove),j(e.alertBelow)),N(e.notifyOnAlert),te(e.showOnCard)}}},we=()=>{a.invalidateQueries({queryKey:[`locationHaSensors`]}),a.invalidateQueries({queryKey:[`locationHaSensorReadings`]})},Te=()=>({name:C.trim(),entity_id:m,kind:g,device_class:v,unit:b,alert_state:g===`binary`&&E?E:null,alert_above:g===`numeric`&&hr(v)!==`battery`&&O!==``?Number(O):null,alert_below:g===`numeric`&&A!==``?Number(A):null,notify_on_alert:M,show_on_card:P}),Ee=f({mutationFn:()=>{let t=Te();return s?r.updateLocationHASensor(e.id,t):r.createLocationHASensor({...t,location_id:Number(c)})},onSuccess:()=>{we(),o(i(s?`locationHaSensors.toast.updated`:`locationHaSensors.toast.created`),`success`),n()},onError:e=>ie(e.message)}),De=f({mutationFn:async()=>{let e=Number(c);await r.createLocationHASensor({...Te(),location_id:e});let t=he(me?.location_sensor_alert_defaults),n=de.filter(e=>V[e.entity_id]);for(let i of n){let n=hr(i.device_class),a=n?t[n]:null;await r.createLocationHASensor({name:i.friendly_name.slice(0,100),entity_id:i.entity_id,kind:i.domain===`binary_sensor`?`binary`:`numeric`,device_class:i.device_class,unit:i.unit_of_measurement?.slice(0,16)??null,alert_state:null,alert_above:n!==`battery`&&a&&a.alertAbove!==``?Number(a.alertAbove):null,alert_below:a&&a.alertBelow!==``?Number(a.alertBelow):null,notify_on_alert:a?.notifyOnAlert??!1,show_on_card:a?.showOnCard??P,location_id:e})}return n},onSuccess:e=>{we(),le(!1),e.length>0?o(i(`locationHaSensors.autoAdd.added`,{names:e.map(e=>e.entity_id).join(`, `)}),`success`):o(i(`locationHaSensors.toast.created`),`success`),n()},onError:e=>{we(),le(!1),ie(e.message)}}),Oe=f({mutationFn:()=>r.deleteLocationHASensor(e.id),onSuccess:()=>{we(),o(i(`locationHaSensors.toast.deleted`),`success`),n()},onError:e=>ie(e.message)}),ke=f({mutationFn:()=>r.updateLocationHASensor(se.id,Te()),onSuccess:()=>{we(),oe(!1),B(null),o(i(`locationHaSensors.toast.updated`),`success`),n()},onError:e=>{oe(!1),B(null),ie(e.message)}}),je=g===`binary`?E!==``:O!==``||A!==``,Me=e=>{if(e.preventDefault(),ie(null),!m)return ie(i(`haSensors.error.pickEntity`));if(!C.trim())return ie(i(`haSensors.error.nameRequired`));if(c===``)return ie(i(`locationHaSensors.error.locationRequired`));if(M&&!je)return ie(i(`haSensors.error.alertRequired`));if(!s){let e=(H??[]).filter(e=>e.location_id===Number(c)),t=hr(v);if(t){let n=e.find(e=>hr(e.device_class)===t);if(n){B(n),oe(!0);return}}if(e.length===0&&t){let e=_r(m,t,be);if(e.length>0){fe(e),pe(Object.fromEntries(e.map(e=>[e.entity_id,!0]))),le(!0);return}o(i(`locationHaSensors.autoAdd.noneFound`),`info`)}}Ee.mutate()},Ne=x[v??``],Pe=e=>{let t=Ne?.[e]??e;return i(`haSensors.states.${t}`,{defaultValue:t})},Fe=Ee.isPending||Oe.isPending||ke.isPending||De.isPending,Ie=t.find(e=>e.id===Number(c));return(0,X.useEffect)(()=>{let e=e=>{e.key===`Escape`&&!Fe&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n,Fe]),(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:()=>{Fe||n()},children:(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-lg max-h-[90vh] overflow-y-auto`,onClick:e=>e.stopPropagation(),children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Y.jsx)(`div`,{className:`p-2 rounded-full bg-bambu-green/20 text-bambu-green`,children:(0,Y.jsx)(ne,{className:`w-5 h-5`})}),(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(s?`locationHaSensors.editTitle`:`locationHaSensors.addTitle`)})]}),(0,Y.jsx)(`button`,{onClick:n,disabled:Fe,className:`text-bambu-gray hover:text-white transition-colors disabled:opacity-50 disabled:cursor-not-allowed`,children:(0,Y.jsx)(Re,{className:`w-5 h-5`})})]}),(0,Y.jsxs)(`form`,{onSubmit:Me,className:`p-6 space-y-4`,children:[re&&(0,Y.jsx)(`div`,{className:`p-3 bg-red-100 dark:bg-red-500/20 border border-red-300 dark:border-red-500/50 rounded-lg text-sm text-red-700 dark:text-red-400`,children:re}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`locationHaSensors.location`)}),s?(0,Y.jsx)(`div`,{className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white`,children:t.find(t=>t.id===e.location_id)?.name??i(`locationHaSensors.unknownLocation`)}):(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`select`,{value:c,onChange:e=>p(e.target.value===``?``:Number(e.target.value)),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white`,children:t.map(e=>(0,Y.jsx)(`option`,{value:e.id,children:e.name},e.id))}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>ae(!0),className:`p-2 rounded-lg bg-bambu-dark-tertiary hover:bg-bambu-gray-dark text-white transition-colors shrink-0`,title:i(`locations.add`),"aria-label":i(`locations.add`),children:(0,Y.jsx)(wt,{className:`w-4 h-4`})})]})]}),!ge&&(0,Y.jsxs)(`div`,{className:`p-3 bg-yellow-100 dark:bg-yellow-500/20 border border-yellow-400 dark:border-yellow-500/50 rounded-lg text-sm text-yellow-700 dark:text-yellow-400`,children:[i(`smartPlugs.haNotConfigured`),` `,(0,Y.jsx)(`span`,{className:`font-medium`,children:i(`smartPlugs.haSettingsPath`)})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1 ${ge?``:`opacity-50`}`,children:i(`haSensors.entity`)}),ye&&(0,Y.jsx)(`div`,{className:`p-3 mb-2 bg-red-100 dark:bg-red-500/20 rounded-lg text-sm text-red-700 dark:text-red-400`,children:ye.message}),(0,Y.jsxs)(`div`,{className:`relative mb-2`,children:[(0,Y.jsx)(Ae,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,Y.jsx)(`input`,{type:`text`,value:F,onChange:e=>I(e.target.value),placeholder:i(`haSensors.searchPlaceholder`),disabled:!ge,className:`w-full pl-9 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white disabled:opacity-50 disabled:cursor-not-allowed`})]}),(0,Y.jsxs)(`div`,{className:`max-h-44 overflow-y-auto rounded-lg border border-bambu-dark-tertiary ${ge?``:`opacity-50`}`,children:[m&&!xe&&(0,Y.jsx)(`div`,{className:`px-3 py-2 text-sm bg-bambu-green/10 text-bambu-green border-b border-bambu-dark-tertiary`,children:i(`locationHaSensors.currentlyBound`,{entity:m})}),!ge&&(0,Y.jsx)(`div`,{className:`p-3 text-sm text-bambu-gray`,children:i(`haSensors.noEntities`)}),ge&&ve&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 p-3 text-sm text-bambu-gray`,children:[(0,Y.jsx)(R,{className:`w-4 h-4 animate-spin`}),i(`common.loading`)]}),ge&&!ve&&Se.length===0&&(0,Y.jsx)(`div`,{className:`p-3 text-sm text-bambu-gray`,children:i(`haSensors.noEntities`)}),ge&&!ve&&Se.map(e=>(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>Ce(e),className:`w-full text-left px-3 py-2 text-sm transition-colors ${e.entity_id===m?`bg-bambu-green/20 text-bambu-green`:`text-white hover:bg-bambu-dark`}`,children:[(0,Y.jsx)(`div`,{className:`font-medium`,children:e.friendly_name}),(0,Y.jsxs)(`div`,{className:`text-xs text-bambu-gray`,children:[e.entity_id,e.state!==null&&` — ${e.state}`,e.unit_of_measurement?` ${e.unit_of_measurement}`:``]})]},e.entity_id))]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,htmlFor:`location-ha-sensor-name`,children:i(`haSensors.name`)}),(0,Y.jsx)(`input`,{id:`location-ha-sensor-name`,type:`text`,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`})]}),m&&(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`haSensors.alertWhen`)}),g===`binary`?(0,Y.jsxs)(`select`,{value:E,onChange:e=>D(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white`,children:[(0,Y.jsx)(`option`,{value:``,children:i(`haSensors.alertNever`)}),(0,Y.jsx)(`option`,{value:`on`,children:Pe(`on`)}),(0,Y.jsx)(`option`,{value:`off`,children:Pe(`off`)})]}):hr(v)===`battery`?(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`span`,{className:`block text-xs text-bambu-gray mb-1`,children:[i(`haSensors.alertBelow`),` `,b??``]}),(0,Y.jsx)(`input`,{type:`number`,step:`any`,value:A,onChange:e=>j(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white`})]}):(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`span`,{className:`block text-xs text-bambu-gray mb-1`,children:[i(`haSensors.alertAbove`),` `,b??``]}),(0,Y.jsx)(`input`,{type:`number`,step:`any`,value:O,onChange:e=>k(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`span`,{className:`block text-xs text-bambu-gray mb-1`,children:[i(`haSensors.alertBelow`),` `,b??``]}),(0,Y.jsx)(`input`,{type:`number`,step:`any`,value:A,onChange:e=>j(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white`})]})]}),(0,Y.jsx)(`p`,{className:`mt-1 text-xs text-bambu-gray`,children:i(`haSensors.alertHint`)})]}),(0,Y.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:P,onChange:e=>te(e.target.checked),className:`w-4 h-4`}),(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:i(`locationHaSensors.showOnCard`)})]}),(0,Y.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:M,onChange:e=>N(e.target.checked),disabled:!je,className:`w-4 h-4`}),(0,Y.jsx)(`span`,{className:`text-sm ${je?`text-white`:`text-bambu-gray`}`,children:i(`haSensors.notifyOnAlert`)})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between pt-2`,children:[s?(0,Y.jsx)(K,{type:`button`,variant:`danger`,onClick:()=>Oe.mutate(),disabled:Fe,children:i(`common.delete`)}):(0,Y.jsx)(`span`,{}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(K,{type:`button`,variant:`secondary`,onClick:n,disabled:Fe,children:i(`common.cancel`)}),(0,Y.jsxs)(K,{type:`submit`,disabled:Fe||!ge&&!s,children:[Fe?(0,Y.jsx)(R,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(_t,{className:`w-4 h-4`}),i(`common.save`)]})]})]})]})]})}),z&&se&&(0,Y.jsx)(Tt,{title:i(`locationHaSensors.overwriteConfirm.title`),message:i(`locationHaSensors.overwriteConfirm.message${hr(se.device_class)===`humidity`?`Humidity`:hr(se.device_class)===`battery`?`Battery`:`Temperature`}`,{location:Ie?.name??``,name:se.name}),variant:`warning`,overlayZIndex:`z-[110]`,isLoading:ke.isPending,onConfirm:()=>ke.mutate(),onCancel:()=>{oe(!1),B(null)}}),ce&&de.length>0&&(0,Y.jsx)(Tt,{title:i(`locationHaSensors.autoAdd.confirmTitle`),message:i(`locationHaSensors.autoAdd.confirmMessage`),overlayZIndex:`z-[110]`,isLoading:De.isPending,confirmDisabled:!de.some(e=>V[e.entity_id]),onConfirm:()=>De.mutate(),cancelText:i(`locationHaSensors.autoAdd.onlyThisOne`),onCancel:()=>{le(!1),fe([]),pe({}),Ee.mutate()},children:(0,Y.jsx)(`div`,{className:`space-y-2`,children:de.map(e=>(0,Y.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:V[e.entity_id]??!0,onChange:t=>pe(n=>({...n,[e.entity_id]:t.target.checked})),className:`w-4 h-4`}),(0,Y.jsxs)(`span`,{className:`text-sm text-white`,children:[e.friendly_name,(0,Y.jsxs)(`span`,{className:`text-bambu-gray`,children:[` — `,e.entity_id]})]})]},e.entity_id))})}),L&&(0,Y.jsx)(ue,{open:L,onClose:()=>ae(!1),onPickLocation:e=>{p(e),ae(!1)},startCreating:!0})]})}var yr=60,br=120,xr={temperature:Fe,humidity:y,battery:_},Sr={temperature:`°C`,humidity:`%`,battery:`%`};function Cr(e){return e===`temperature`?`temperature`:e===`humidity`?`humidity`:e===`battery`?`battery`:null}function wr({category:e,state:t,onChange:n}){let{t:r}=l(),i=xr[e],a=Sr[e],o=t.alertAbove!==``||t.alertBelow!==``;return(0,Y.jsxs)(`div`,{className:`p-3 border border-bambu-dark-tertiary rounded-lg space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 text-sm text-white font-medium`,children:[(0,Y.jsx)(i,{className:`w-4 h-4`}),r(`inventory.${e}`)]}),e===`battery`?(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`span`,{className:`block text-xs text-bambu-gray mb-1`,children:[r(`haSensors.alertBelow`),` `,a]}),(0,Y.jsx)(`input`,{type:`number`,step:`any`,value:t.alertBelow,onChange:e=>n({alertBelow:e.target.value}),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white`})]}):(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`span`,{className:`block text-xs text-bambu-gray mb-1`,children:[r(`haSensors.alertAbove`),` `,a]}),(0,Y.jsx)(`input`,{type:`number`,step:`any`,value:t.alertAbove,onChange:e=>n({alertAbove:e.target.value}),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`span`,{className:`block text-xs text-bambu-gray mb-1`,children:[r(`haSensors.alertBelow`),` `,a]}),(0,Y.jsx)(`input`,{type:`number`,step:`any`,value:t.alertBelow,onChange:e=>n({alertBelow:e.target.value}),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white`})]})]}),(0,Y.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:t.showOnCard,onChange:e=>n({showOnCard:e.target.checked}),className:`w-4 h-4`}),(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:r(`locationHaSensors.showOnCard`)})]}),(0,Y.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:t.notifyOnAlert,onChange:e=>n({notifyOnAlert:e.target.checked}),disabled:!o,className:`w-4 h-4`}),(0,Y.jsx)(`span`,{className:`text-sm ${o?`text-white`:`text-bambu-gray`}`,children:r(`haSensors.notifyOnAlert`)})]})]})}function Tr({onClose:e}){let{t}=l(),{showToast:n}=ee(),i=u(),[a,o]=(0,X.useState)(()=>he()),[s,c]=(0,X.useState)(()=>se()),[p,m]=(0,X.useState)(()=>me()),[h,g]=(0,X.useState)(()=>_e()),[_,v]=(0,X.useState)(()=>fe()),[y,b]=(0,X.useState)(!1),{data:x}=d({queryKey:[`settings`],queryFn:r.getSettings}),[S,C]=(0,X.useState)(br),w=(0,X.useRef)(!1),T=(0,X.useRef)(new Set);(0,X.useEffect)(()=>{if(!x||w.current)return;w.current=!0,T.current.has(`pollInterval`)||C(x.location_sensor_poll_interval);let e=he(x.location_sensor_alert_defaults);o(t=>{let n={...e};return Object.keys(n).forEach(e=>{T.current.has(e)&&(n[e]=t[e])}),n})},[x]);let E=(e,t)=>{T.current.add(e),o(n=>({...n,[e]:{...n[e],...t}}))},D=e=>{T.current.add(`pollInterval`),C(e)},O=async()=>{let e=Math.max(yr,S),t=pe({...a,battery:{...a.battery,alertAbove:``}}),n={};x&&e!==x.location_sensor_poll_interval&&(n.location_sensor_poll_interval=e),x&&t!==x.location_sensor_alert_defaults&&(n.location_sensor_alert_defaults=t),Object.keys(n).length>0&&(await r.updateSettings(n),i.invalidateQueries({queryKey:[`settings`]})),ge(a),le(s),V(p),be(h),ce(_)},k=f({mutationFn:O,onSuccess:()=>{n(t(`locationHaSensors.options.saved`),`success`),e()},onError:e=>{n(e.message||t(`locationHaSensors.options.saveFailed`),`error`)}}),A=e=>{e.preventDefault(),k.mutate()},j=f({mutationFn:async()=>{let[e,t]=await Promise.all([r.getLocationHASensors(),r.getBindableLocationHAEntities()]),n=new Map(t.map(e=>[e.entity_id,e.friendly_name])),i=e.filter(e=>Cr(e.device_class)!==null);return await Promise.all(i.map(e=>{let t=Cr(e.device_class),i=a[t],o=n.get(e.entity_id);return r.updateLocationHASensor(e.id,{...o?{name:o.slice(0,100)}:{},alert_above:t!==`battery`&&i.alertAbove!==``?Number(i.alertAbove):null,alert_below:i.alertBelow===``?null:Number(i.alertBelow),notify_on_alert:i.notifyOnAlert,show_on_card:i.showOnCard})})),await O(),i.length},onSuccess:r=>{i.invalidateQueries({queryKey:[`locationHaSensors`]}),i.invalidateQueries({queryKey:[`locationHaSensorReadings`]}),n(t(`locationHaSensors.options.resetDone`,{count:r}),`success`),b(!1),e()},onError:e=>{n(e.message||t(`locationHaSensors.options.resetFailed`),`error`),b(!1)}});return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:e,children:(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-lg max-h-[90vh] overflow-y-auto`,onClick:e=>e.stopPropagation(),children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Y.jsx)(`div`,{className:`p-2 rounded-full bg-bambu-green/20 text-bambu-green`,children:(0,Y.jsx)(je,{className:`w-5 h-5`})}),(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:t(`locationHaSensors.options.title`)})]}),(0,Y.jsx)(`button`,{onClick:e,className:`text-bambu-gray hover:text-white transition-colors`,children:(0,Y.jsx)(Re,{className:`w-5 h-5`})})]}),(0,Y.jsxs)(`form`,{onSubmit:A,className:`px-6 pb-6 pt-3 space-y-4`,children:[(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:t(`locationHaSensors.options.description`)}),(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsx)(wr,{category:`temperature`,state:a.temperature,onChange:e=>E(`temperature`,e)}),(0,Y.jsx)(wr,{category:`humidity`,state:a.humidity,onChange:e=>E(`humidity`,e)}),(0,Y.jsx)(wr,{category:`battery`,state:a.battery,onChange:e=>E(`battery`,e)})]}),(0,Y.jsxs)(`div`,{className:`p-3 border border-bambu-dark-tertiary rounded-lg space-y-3`,children:[(0,Y.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:s,onChange:e=>c(e.target.checked),className:`w-4 h-4`}),(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:t(`locationHaSensors.options.colorizeValues`)})]}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-3 gap-x-3 gap-y-1 items-end ${s?``:`opacity-50`}`,children:[(0,Y.jsx)(`label`,{className:`block text-xs text-bambu-gray`,htmlFor:`location-sensor-below-color`,children:t(`locationHaSensors.options.belowColor`)}),(0,Y.jsx)(`label`,{className:`block text-xs text-bambu-gray`,htmlFor:`location-sensor-optimal-color`,children:t(`locationHaSensors.options.optimalColor`)}),(0,Y.jsx)(`label`,{className:`block text-xs text-bambu-gray`,htmlFor:`location-sensor-above-color`,children:t(`locationHaSensors.options.aboveColor`)}),(0,Y.jsx)(`select`,{id:`location-sensor-below-color`,value:h,onChange:e=>g(e.target.value),disabled:!s,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white disabled:cursor-not-allowed`,children:ye.map(e=>(0,Y.jsx)(`option`,{value:e,children:t(`locationHaSensors.options.colors.${e}`)},e))}),(0,Y.jsx)(`select`,{id:`location-sensor-optimal-color`,value:_,onChange:e=>v(e.target.value),disabled:!s,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white disabled:cursor-not-allowed`,children:ye.map(e=>(0,Y.jsx)(`option`,{value:e,children:t(`locationHaSensors.options.colors.${e}`)},e))}),(0,Y.jsx)(`select`,{id:`location-sensor-above-color`,value:p,onChange:e=>m(e.target.value),disabled:!s,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white disabled:cursor-not-allowed`,children:ye.map(e=>(0,Y.jsx)(`option`,{value:e,children:t(`locationHaSensors.options.colors.${e}`)},e))})]})]}),(0,Y.jsx)(`div`,{className:`pt-4 mt-4 border-t border-bambu-dark-tertiary`,children:(0,Y.jsx)(`p`,{className:`text-xs font-medium text-bambu-gray uppercase tracking-wider mb-3`,children:t(`locationHaSensors.options.generalSettings`)})}),(0,Y.jsxs)(`div`,{className:`p-3 border border-bambu-dark-tertiary rounded-lg space-y-2`,children:[(0,Y.jsx)(`label`,{className:`block text-sm text-white`,htmlFor:`location-sensor-poll-interval`,children:t(`locationHaSensors.options.pollInterval`)}),(0,Y.jsx)(`input`,{id:`location-sensor-poll-interval`,type:`number`,min:yr,step:`1`,value:S,onChange:e=>D(Number(e.target.value)),onBlur:()=>D(Math.max(yr,S||br)),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white`}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:t(`locationHaSensors.options.pollIntervalHint`)})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2 pt-2`,children:[(0,Y.jsxs)(K,{type:`button`,variant:`secondary`,onClick:()=>b(!0),children:[(0,Y.jsx)(nt,{className:`w-4 h-4`}),t(`locationHaSensors.options.reset`)]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(K,{type:`button`,variant:`secondary`,onClick:e,children:t(`common.cancel`)}),(0,Y.jsxs)(K,{type:`submit`,disabled:k.isPending,children:[(0,Y.jsx)(_t,{className:`w-4 h-4`}),t(`common.save`)]})]})]})]})]})}),y&&(0,Y.jsx)(Tt,{title:t(`locationHaSensors.options.resetConfirm.title`),message:t(`locationHaSensors.options.resetConfirm.message`),confirmText:t(`locationHaSensors.options.reset`),variant:`danger`,overlayZIndex:`z-[60]`,isLoading:j.isPending,onConfirm:()=>j.mutate(),onCancel:()=>b(!1)})]})}function Er({provider:e,onEdit:t}){let{t:n}=l(),i=u(),[a,o]=(0,X.useState)(!1),[s,c]=(0,X.useState)(!1),[p,m]=(0,X.useState)(null),{data:h}=d({queryKey:[`printers`],queryFn:r.getPrinters}),g=h?.find(t=>t.id===e.printer_id),_=f({mutationFn:t=>r.updateNotificationProvider(e.id,t),onSuccess:()=>{i.invalidateQueries({queryKey:[`notification-providers`]})}}),v=f({mutationFn:()=>r.deleteNotificationProvider(e.id),onSuccess:()=>{i.invalidateQueries({queryKey:[`notification-providers`]})}}),y=f({mutationFn:()=>r.testNotificationProvider(e.id),onSuccess:e=>{m(e),i.invalidateQueries({queryKey:[`notification-providers`]})},onError:e=>{m({success:!1,message:e.message})}}),b=e=>e||``;return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(G,{className:`relative`,children:(0,Y.jsxs)(W,{className:`p-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-start justify-between ${e.enabled?`mb-3`:`mb-0`}`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Y.jsx)(`div`,{className:`p-2 rounded-lg ${e.enabled?`bg-bambu-green/20`:`bg-bambu-dark`}`,children:(0,Y.jsx)(rt,{className:`w-5 h-5 ${e.enabled?`text-bambu-green`:`text-bambu-gray`}`})}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h3`,{className:`font-medium text-white`,children:e.name}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`notifications.providerTypes.${e.provider_type}`,e.provider_type)})]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[e.last_success&&(0,Y.jsx)(`span`,{className:`text-xs text-status-ok hidden sm:inline`,children:n(`notifications.lastSuccess`,{date:He(e.last_success)})}),e.last_error&&e.last_error_at&&(!e.last_success||(We(e.last_error_at)?.getTime()||0)>(We(e.last_success)?.getTime()||0))&&(0,Y.jsx)(`span`,{className:`text-xs text-status-error`,title:e.last_error,children:n(`notifications.error`)}),(0,Y.jsx)(J,{checked:e.enabled,onChange:e=>_.mutate({enabled:e})})]})]}),e.enabled&&(0,Y.jsxs)(Y.Fragment,{children:[g&&(0,Y.jsxs)(`div`,{className:`mb-3 px-2 py-1.5 bg-bambu-dark rounded-lg`,children:[(0,Y.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[n(`notifications.printer`),` `]}),(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:g.name})]}),!g&&!e.printer_id&&(0,Y.jsx)(`div`,{className:`mb-3 px-2 py-1.5 bg-bambu-dark rounded-lg`,children:(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:n(`notifications.allPrinters`)})}),(0,Y.jsxs)(`div`,{className:`mb-3 flex flex-wrap gap-1`,children:[e.on_print_start&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400 text-xs rounded`,children:n(`notifications.start`)}),e.on_plate_not_empty&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-rose-100 dark:bg-rose-600/20 text-rose-700 dark:text-rose-300 text-xs rounded`,children:n(`notifications.plateCheck`)}),e.on_print_complete&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-bambu-green/20 text-bambu-green text-xs rounded`,children:n(`notifications.complete`)}),e.on_plate_clear_required&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400 text-xs rounded`,children:n(`notifications.plateClear`)}),e.on_print_confirm_request&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-teal-100 dark:bg-teal-500/20 text-teal-700 dark:text-teal-400 text-xs rounded`,children:n(`notifications.printConfirmRequest`)}),e.provider_type===`telegram`&&e.on_print_confirm_request&&e.telegram_verdict_mode===`reactions`&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-sky-100 dark:bg-sky-500/20 text-sky-700 dark:text-sky-400 text-xs rounded`,children:n(`notifications.telegramVerdictBadgeReactions`)}),e.provider_type===`telegram`&&e.on_print_confirm_request&&e.telegram_verdict_mode===`both`&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-sky-100 dark:bg-sky-500/20 text-sky-700 dark:text-sky-400 text-xs rounded`,children:n(`notifications.telegramVerdictBadgeBoth`)}),e.on_print_failed&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400 text-xs rounded`,children:n(`notifications.failed`)}),e.on_print_stopped&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-orange-100 dark:bg-orange-500/20 text-orange-700 dark:text-orange-400 text-xs rounded`,children:n(`notifications.stopped`)}),e.on_billing_charge_failed&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-red-100 dark:bg-red-600/20 text-red-700 dark:text-red-300 text-xs rounded`,children:n(`notifications.billingChargeFailedLabel`)}),e.on_print_progress&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400 text-xs rounded`,children:n(`notifications.progress`)}),e.on_printer_offline&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-gray-500/20 text-gray-400 text-xs rounded`,children:n(`notifications.offline`)}),e.on_printer_error&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-rose-100 dark:bg-rose-500/20 text-rose-700 dark:text-rose-400 text-xs rounded`,children:n(`notifications.error`)}),e.on_ai_failure_detection&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-fuchsia-100 dark:bg-fuchsia-500/20 text-fuchsia-700 dark:text-fuchsia-300 text-xs rounded`,children:n(`notifications.aiFailureDetection`)}),e.on_ha_sensor_alert&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-indigo-100 dark:bg-indigo-500/20 text-indigo-700 dark:text-indigo-300 text-xs rounded`,children:n(`notifications.haSensorAlert`)}),e.on_location_ha_sensor_alert&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-indigo-100 dark:bg-indigo-500/20 text-indigo-700 dark:text-indigo-300 text-xs rounded`,children:n(`notifications.locationHaSensorAlert`)}),e.on_filament_low&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-cyan-100 dark:bg-cyan-500/20 text-cyan-700 dark:text-cyan-400 text-xs rounded`,children:n(`notifications.lowFilament`)}),e.on_maintenance_due&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-purple-100 dark:bg-purple-500/20 text-purple-700 dark:text-purple-400 text-xs rounded`,children:n(`notifications.maintenance`)}),e.on_ams_humidity_high&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-blue-100 dark:bg-blue-600/20 text-blue-700 dark:text-blue-300 text-xs rounded`,children:n(`notifications.amsHumidity`)}),e.on_ams_temperature_high&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-orange-100 dark:bg-orange-600/20 text-orange-700 dark:text-orange-300 text-xs rounded`,children:n(`notifications.amsTemp`)}),e.on_ams_drying_suspended&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-rose-100 dark:bg-rose-600/20 text-rose-700 dark:text-rose-300 text-xs rounded`,children:n(`notifications.amsDryingSuspended`)}),e.on_ams_ht_humidity_high&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-cyan-100 dark:bg-cyan-600/20 text-cyan-700 dark:text-cyan-300 text-xs rounded`,children:n(`notifications.amsHtHumidity`)}),e.on_ams_ht_temperature_high&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-amber-100 dark:bg-amber-600/20 text-amber-700 dark:text-amber-300 text-xs rounded`,children:n(`notifications.amsHtTemp`)}),e.on_bed_cooled&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-teal-100 dark:bg-teal-500/20 text-teal-700 dark:text-teal-400 text-xs rounded`,children:n(`notifications.bedCooled`)}),e.on_first_layer_complete&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-emerald-100 dark:bg-emerald-600/20 text-emerald-700 dark:text-emerald-300 text-xs rounded`,children:n(`notifications.firstLayer`)}),e.on_app_message&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-sky-100 dark:bg-sky-500/20 text-sky-700 dark:text-sky-400 text-xs rounded`,children:n(`notifications.appMessagesBadge`)}),e.on_print_missing_spool_assignment&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-300 text-xs rounded`,children:n(`notifications.missingSpoolAssignmentLabel`)}),e.on_stock_reorder_alert&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-lime-100 dark:bg-lime-500/20 text-lime-700 dark:text-lime-400 text-xs rounded`,children:n(`notifications.stockReorderAlert`)}),e.on_stock_break_alert&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-red-100 dark:bg-red-600/20 text-red-700 dark:text-red-300 text-xs rounded`,children:n(`notifications.stockBreakAlert`)}),e.quiet_hours_enabled&&(0,Y.jsxs)(`span`,{className:`px-2 py-0.5 bg-indigo-100 dark:bg-indigo-500/20 text-indigo-700 dark:text-indigo-400 text-xs rounded flex items-center gap-1`,children:[(0,Y.jsx)(Jt,{className:`w-3 h-3`}),n(`notifications.quiet`)]}),e.daily_digest_enabled&&(0,Y.jsxs)(`span`,{className:`px-2 py-0.5 bg-emerald-100 dark:bg-emerald-500/20 text-emerald-700 dark:text-emerald-400 text-xs rounded flex items-center gap-1`,children:[(0,Y.jsx)(w,{className:`w-3 h-3`}),n(`notifications.digest`,{time:e.daily_digest_time})]}),e.attach_photo===!1&&(0,Y.jsxs)(`span`,{className:`px-2 py-0.5 bg-bambu-dark-tertiary text-bambu-gray text-xs rounded flex items-center gap-1`,children:[(0,Y.jsx)(vn,{className:`w-3 h-3`}),n(`notifications.noPhoto`)]})]}),(0,Y.jsx)(`div`,{className:`mb-3`,children:(0,Y.jsxs)(K,{size:`sm`,variant:`secondary`,disabled:y.isPending,onClick:()=>{m(null),y.mutate()},className:`w-full`,children:[y.isPending?(0,Y.jsx)(R,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(Sn,{className:`w-4 h-4`}),n(`notifications.sendTestNotification`)]})}),p&&(0,Y.jsxs)(`div`,{className:`mb-3 p-2 rounded-lg flex items-center gap-2 text-sm ${p.success?`bg-bambu-green/20 text-bambu-green`:`bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400`}`,children:[p.success?(0,Y.jsx)(j,{className:`w-4 h-4`}):(0,Y.jsx)(O,{className:`w-4 h-4`}),(0,Y.jsx)(`span`,{children:p.message})]})]}),(0,Y.jsxs)(`button`,{onClick:()=>c(!s),className:`w-full flex items-center justify-between py-2 text-sm text-bambu-gray hover:text-white transition-colors ${e.enabled?`border-t border-bambu-dark-tertiary`:`mt-2 border-t border-bambu-dark-tertiary`}`,children:[(0,Y.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(je,{className:`w-4 h-4`}),n(`notifications.eventSettings`)]}),s?(0,Y.jsx)(D,{className:`w-4 h-4`}):(0,Y.jsx)(E,{className:`w-4 h-4`})]}),s&&(0,Y.jsxs)(`div`,{className:`pt-3 border-t border-bambu-dark-tertiary space-y-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.enabled`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.sendFromProvider`)})]}),(0,Y.jsx)(J,{checked:e.enabled,onChange:e=>_.mutate({enabled:e})})]}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide`,children:n(`notifications.printEvents`)}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.printStarted`)}),(0,Y.jsx)(J,{checked:e.on_print_start,onChange:e=>_.mutate({on_print_start:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.plateNotEmpty`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.plateNotEmptyDescription`)})]}),(0,Y.jsx)(J,{checked:e.on_plate_not_empty??!0,onChange:e=>_.mutate({on_plate_not_empty:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.printCompleted`)}),(0,Y.jsx)(J,{checked:e.on_print_complete,onChange:e=>_.mutate({on_print_complete:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.plateClearRequired`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.plateClearRequiredDescription`)})]}),(0,Y.jsx)(J,{checked:e.on_plate_clear_required??!1,onChange:e=>_.mutate({on_plate_clear_required:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.printConfirmRequest`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.printConfirmRequestDescription`)})]}),(0,Y.jsx)(J,{checked:e.on_print_confirm_request??!0,onChange:e=>_.mutate({on_print_confirm_request:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.bedCooledLabel`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.bedCooledDescription`)})]}),(0,Y.jsx)(J,{checked:e.on_bed_cooled??!1,onChange:e=>_.mutate({on_bed_cooled:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.firstLayerCompleteLabel`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.firstLayerCompleteDescription`)})]}),(0,Y.jsx)(J,{checked:e.on_first_layer_complete??!1,onChange:e=>_.mutate({on_first_layer_complete:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.missingSpoolAssignmentLabel`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.missingSpoolAssignmentDescription`)})]}),(0,Y.jsx)(J,{checked:e.on_print_missing_spool_assignment??!1,onChange:e=>_.mutate({on_print_missing_spool_assignment:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.printFailed`)}),(0,Y.jsx)(J,{checked:e.on_print_failed,onChange:e=>_.mutate({on_print_failed:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.printStopped`)}),(0,Y.jsx)(J,{checked:e.on_print_stopped,onChange:e=>_.mutate({on_print_stopped:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.billingChargeFailedLabel`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.billingChargeFailedDescription`)})]}),(0,Y.jsx)(J,{checked:e.on_billing_charge_failed??!0,onChange:e=>_.mutate({on_billing_charge_failed:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.progressMilestones`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.progressMilestonesDescription`)})]}),(0,Y.jsx)(J,{checked:e.on_print_progress,onChange:e=>_.mutate({on_print_progress:e})})]})]}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide`,children:n(`notifications.printerStatus`)}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.printerOffline`)}),(0,Y.jsx)(J,{checked:e.on_printer_offline,onChange:e=>_.mutate({on_printer_offline:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.printerError`)}),(0,Y.jsx)(J,{checked:e.on_printer_error,onChange:e=>_.mutate({on_printer_error:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.aiFailureDetection`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.aiFailureDetectionDescription`)})]}),(0,Y.jsx)(J,{checked:e.on_ai_failure_detection??!1,onChange:e=>_.mutate({on_ai_failure_detection:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.haSensorAlert`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.haSensorAlertDescription`)})]}),(0,Y.jsx)(J,{checked:e.on_ha_sensor_alert??!1,onChange:e=>_.mutate({on_ha_sensor_alert:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.locationHaSensorAlert`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.locationHaSensorAlertDescription`)})]}),(0,Y.jsx)(J,{checked:e.on_location_ha_sensor_alert??!1,onChange:e=>_.mutate({on_location_ha_sensor_alert:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.lowFilamentLabel`)}),(0,Y.jsx)(J,{checked:e.on_filament_low,onChange:e=>_.mutate({on_filament_low:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.maintenanceDue`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.maintenanceDueDescription`)})]}),(0,Y.jsx)(J,{checked:e.on_maintenance_due??!1,onChange:e=>_.mutate({on_maintenance_due:e})})]})]}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide`,children:n(`notifications.amsAlarms`)}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.amsHumidityHigh`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.amsHumidityHighDescription`)})]}),(0,Y.jsx)(J,{checked:e.on_ams_humidity_high??!1,onChange:e=>_.mutate({on_ams_humidity_high:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.amsTemperatureHigh`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.amsTemperatureHighDescription`)})]}),(0,Y.jsx)(J,{checked:e.on_ams_temperature_high??!1,onChange:e=>_.mutate({on_ams_temperature_high:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.amsDryingSuspendedTitle`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.amsDryingSuspendedDescription`)})]}),(0,Y.jsx)(J,{checked:e.on_ams_drying_suspended??!1,onChange:e=>_.mutate({on_ams_drying_suspended:e})})]})]}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide`,children:n(`notifications.amsHtAlarms`)}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.amsHtHumidityHigh`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.amsHtHumidityHighDescription`)})]}),(0,Y.jsx)(J,{checked:e.on_ams_ht_humidity_high??!1,onChange:e=>_.mutate({on_ams_ht_humidity_high:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.amsHtTemperatureHigh`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.amsHtTemperatureHighDescription`)})]}),(0,Y.jsx)(J,{checked:e.on_ams_ht_temperature_high??!1,onChange:e=>_.mutate({on_ams_ht_temperature_high:e})})]})]}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide`,children:n(`notifications.inventoryAlerts`)}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.stockReorderAlert`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.stockReorderAlertDescription`)})]}),(0,Y.jsx)(J,{checked:e.on_stock_reorder_alert??!1,onChange:e=>_.mutate({on_stock_reorder_alert:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.stockBreakAlert`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.stockBreakAlertDescription`)})]}),(0,Y.jsx)(J,{checked:e.on_stock_break_alert??!1,onChange:e=>_.mutate({on_stock_break_alert:e})})]})]}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide`,children:n(`notifications.printQueue`)}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.jobAdded`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.jobAddedDescription`)})]}),(0,Y.jsx)(J,{checked:e.on_queue_job_added??!1,onChange:e=>_.mutate({on_queue_job_added:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.jobAssigned`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.jobAssignedDescription`)})]}),(0,Y.jsx)(J,{checked:e.on_queue_job_assigned??!1,onChange:e=>_.mutate({on_queue_job_assigned:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.jobStarted`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.jobStartedDescription`)})]}),(0,Y.jsx)(J,{checked:e.on_queue_job_started??!1,onChange:e=>_.mutate({on_queue_job_started:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.jobWaiting`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.jobWaitingDescription`)})]}),(0,Y.jsx)(J,{checked:e.on_queue_job_waiting??!0,onChange:e=>_.mutate({on_queue_job_waiting:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.jobSkipped`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.jobSkippedDescription`)})]}),(0,Y.jsx)(J,{checked:e.on_queue_job_skipped??!0,onChange:e=>_.mutate({on_queue_job_skipped:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.jobFailed`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.jobFailedDescription`)})]}),(0,Y.jsx)(J,{checked:e.on_queue_job_failed??!0,onChange:e=>_.mutate({on_queue_job_failed:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.queueComplete`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.queueCompleteDescription`)})]}),(0,Y.jsx)(J,{checked:e.on_queue_completed??!1,onChange:e=>_.mutate({on_queue_completed:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.appMessages`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.appMessagesDescription`)})]}),(0,Y.jsx)(J,{checked:e.on_app_message??!1,onChange:e=>_.mutate({on_app_message:e})})]})]}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(Jt,{className:`w-4 h-4 text-purple-600 dark:text-purple-400`}),(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.quietHours`)})]}),(0,Y.jsx)(J,{checked:e.quiet_hours_enabled,onChange:e=>_.mutate({quiet_hours_enabled:e})})]}),e.quiet_hours_enabled&&(0,Y.jsxs)(`div`,{className:`pl-4 border-l-2 border-bambu-dark-tertiary space-y-2`,children:[(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.noNotificationsDuring`)}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(lt,{className:`w-4 h-4 text-bambu-gray`}),(0,Y.jsxs)(`span`,{className:`text-sm text-white`,children:[b(e.quiet_hours_start)||`22:00`,` - `,b(e.quiet_hours_end)||`07:00`]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.editProviderToChangeQuietHours`)})]})]}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(w,{className:`w-4 h-4 text-emerald-600 dark:text-emerald-400`}),(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.dailyDigest`)})]}),(0,Y.jsx)(J,{checked:e.daily_digest_enabled,onChange:e=>_.mutate({daily_digest_enabled:e})})]}),e.daily_digest_enabled&&(0,Y.jsxs)(`div`,{className:`pl-4 border-l-2 border-bambu-dark-tertiary space-y-2`,children:[(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.batchNotifications`)}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(lt,{className:`w-4 h-4 text-bambu-gray`}),(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.sendAt`,{time:b(e.daily_digest_time)||`08:00`})})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.editProviderToChangeDigestTime`)})]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(ut,{className:`w-4 h-4 text-bambu-gray`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.attachPhotoLabel`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.attachPhotoDescription`)})]})]}),(0,Y.jsx)(J,{checked:e.attach_photo??!0,onChange:e=>_.mutate({attach_photo:e})})]}),(0,Y.jsxs)(`div`,{className:`flex gap-2 pt-2`,children:[(0,Y.jsxs)(K,{size:`sm`,variant:`secondary`,onClick:()=>t(e),className:`flex-1`,children:[(0,Y.jsx)(oe,{className:`w-4 h-4`}),n(`notifications.edit`)]}),(0,Y.jsx)(K,{size:`sm`,variant:`secondary`,onClick:()=>o(!0),className:`text-red-700 dark:text-red-400 hover:text-red-800 dark:hover:text-red-300`,children:(0,Y.jsx)(qe,{className:`w-4 h-4`})})]})]})]})}),a&&(0,Y.jsx)(Tt,{title:n(`notifications.deleteProvider`),message:n(`notifications.deleteConfirm`,{name:e.name}),confirmText:n(`notifications.delete`),variant:`danger`,onConfirm:()=>{v.mutate(),o(!1)},onCancel:()=>o(!1)})]})}var Dr=[`email`,`telegram`,`discord`,`ntfy`,`pushover`,`bark`,`gotify`,`callmebot`,`webhook`,`homeassistant`];function Or({provider:e,onClose:t}){let{t:n,i18n:i}=l(),a=u(),o=!!e,[s,c]=(0,X.useState)(e?.name||``),[p,m]=(0,X.useState)(e?.provider_type||`email`),[h,g]=(0,X.useState)(e?.printer_id||null),[_,v]=(0,X.useState)(e?.attach_photo??!0),[y,b]=(0,X.useState)(e?.quiet_hours_enabled||!1),[x,S]=(0,X.useState)(e?.quiet_hours_start||`22:00`),[C,w]=(0,X.useState)(e?.quiet_hours_end||`07:00`),[T,E]=(0,X.useState)(e?.daily_digest_enabled||!1),[D,k]=(0,X.useState)(e?.daily_digest_time||`08:00`),[A,ee]=(0,X.useState)(e?.on_print_start??!1),[M,N]=(0,X.useState)(e?.on_print_complete??!0),[P,te]=(0,X.useState)(e?.on_print_failed??!0),[F,ne]=(0,X.useState)(e?.on_print_stopped??!0),[I,re]=(0,X.useState)(e?.on_print_progress??!1),[ie,L]=(0,X.useState)(e?.on_billing_charge_failed??!0),[ae,z]=(0,X.useState)(e?.on_printer_offline??!1),[oe,se]=(0,X.useState)(e?.on_printer_error??!1),[B,ce]=(0,X.useState)(e?.on_ai_failure_detection??!1),[le,ue]=(0,X.useState)(e?.on_filament_low??!1),[de,fe]=(0,X.useState)(e?.on_maintenance_due??!1),[V,pe]=(0,X.useState)(e?.on_stock_reorder_alert??!1),[me,he]=(0,X.useState)(e?.on_stock_break_alert??!1),[ge,_e]=(0,X.useState)(e?.on_plate_clear_required??!1),[ve,ye]=(0,X.useState)(e?.on_print_confirm_request??!0),[be,H]=(0,X.useState)(e?.telegram_verdict_mode??`buttons`),[xe,Se]=(0,X.useState)(e?.on_bed_cooled??!1),[Ce,we]=(0,X.useState)(e?.on_ha_sensor_alert??!1),[Te,Ee]=(0,X.useState)(e?.on_location_ha_sensor_alert??!1),[De,Oe]=(0,X.useState)(e?.on_first_layer_complete??!1),[ke,Ae]=(0,X.useState)(e?.on_app_message??!1),[je,Me]=(0,X.useState)(e?.config?Object.fromEntries(Object.entries(e.config).filter(([e])=>e!==`event_priorities`).map(([e,t])=>[e,String(t)])):{}),[Ne,Pe]=(0,X.useState)((()=>{let t=e?.config?.event_priorities;if(!t||typeof t!=`object`)return{};let n={};for(let[e,r]of Object.entries(t)){let t=Number(r);Number.isInteger(t)&&t>=1&&t<=5&&(n[e]=t)}return n})()),[Fe,Ie]=(0,X.useState)(null),[Le,U]=(0,X.useState)(null),{data:W}=d({queryKey:[`printers`],queryFn:r.getPrinters});(0,X.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]);let ze=f({mutationFn:()=>r.testNotificationConfig({provider_type:p,config:je,attach_photo:_}),onSuccess:e=>{Ie(e),U(null)},onError:e=>{Ie({success:!1,message:e.message})}}),G=f({mutationFn:e=>r.createNotificationProvider(e),onSuccess:()=>{a.invalidateQueries({queryKey:[`notification-providers`]}),t()},onError:e=>{U(e.message)}}),Be=f({mutationFn:t=>r.updateNotificationProvider(e.id,t),onSuccess:()=>{a.invalidateQueries({queryKey:[`notification-providers`]}),t()},onError:e=>{U(e.message)}}),Ve=e=>{if(e.preventDefault(),U(null),!s.trim()){U(n(`notifications.nameRequired`));return}let t=We(p);for(let e of t)if(!je[e.key]?.trim()){U(n(`notifications.fieldRequired`,{field:e.label}));return}if(p===`homeassistant`&&je.data?.trim()){let e;try{e=JSON.parse(je.data)}catch{U(n(`notifications.haDataInvalid`));return}if(typeof e!=`object`||!e||Array.isArray(e)){U(n(`notifications.haDataInvalid`));return}}if(p===`telegram`&&je.message_thread_id?.trim()&&!/^\d+$/.test(je.message_thread_id.trim())){U(n(`notifications.telegramThreadIdInvalid`));return}let r=(p===`ntfy`||p===`gotify`)&&Object.keys(Ne).length>0?{...je,event_priorities:Ne}:je,i={name:s.trim(),provider_type:p,config:r,printer_id:h,attach_photo:_,quiet_hours_enabled:y,quiet_hours_start:y?x:null,quiet_hours_end:y?C:null,daily_digest_enabled:T,daily_digest_time:T?D:null,on_print_start:A,on_print_complete:M,on_print_failed:P,on_print_stopped:F,on_print_progress:I,on_billing_charge_failed:ie,on_printer_offline:ae,on_printer_error:oe,on_ai_failure_detection:B,on_filament_low:le,on_maintenance_due:de,on_stock_reorder_alert:V,on_stock_break_alert:me,on_plate_clear_required:ge,on_print_confirm_request:ve,telegram_verdict_mode:p===`telegram`?be:`buttons`,on_bed_cooled:xe,on_ha_sensor_alert:Ce,on_location_ha_sensor_alert:Te,on_first_layer_complete:De,on_app_message:ke};o?Be.mutate(i):G.mutate(i)},He=G.isPending||Be.isPending,Ue=e=>{switch(e){case`callmebot`:return[{key:`phone`,label:`Phone Number`,placeholder:`+1234567890`,type:`text`,required:!0},{key:`apikey`,label:`API Key`,placeholder:`Your CallMeBot API key`,type:`text`,required:!0}];case`ntfy`:return[{key:`server`,label:`Server URL`,placeholder:`https://ntfy.sh`,type:`text`,required:!1},{key:`topic`,label:`Topic`,placeholder:`my-bambuddy`,type:`text`,required:!0},{key:`auth_token`,label:`Auth Token`,placeholder:`Optional authentication`,type:`password`,required:!1}];case`pushover`:return[{key:`user_key`,label:`User Key`,placeholder:`Your Pushover user key`,type:`text`,required:!0},{key:`app_token`,label:`App Token`,placeholder:`Your Pushover app token`,type:`text`,required:!0},{key:`priority`,label:`Priority`,placeholder:`0 (normal)`,type:`number`,required:!1},{key:`retry`,label:n(`notifications.pushoverRetry`),placeholder:`60`,type:`number`,required:!1,showIf:e=>e.priority===`2`},{key:`expire`,label:n(`notifications.pushoverExpire`),placeholder:`3600`,type:`number`,required:!1,showIf:e=>e.priority===`2`}];case`telegram`:return[{key:`bot_token`,label:`Bot Token`,placeholder:`Bot token from @BotFather`,type:`password`,required:!0},{key:`chat_id`,label:`Chat ID`,placeholder:`Your chat or group ID`,type:`text`,required:!0},{key:`message_thread_id`,label:n(`notifications.telegramThreadId`),placeholder:`123`,type:`number`,required:!1,help:n(`notifications.telegramThreadIdHelp`)}];case`email`:return[{key:`smtp_server`,label:`SMTP Server`,placeholder:`smtp.gmail.com`,type:`text`,required:!0},{key:`smtp_port`,label:`SMTP Port`,placeholder:`587`,type:`number`,required:!1},{key:`security`,label:`Security`,type:`select`,required:!1,options:[{value:`starttls`,label:`STARTTLS (Port 587)`},{value:`ssl`,label:`SSL/TLS (Port 465)`},{value:`none`,label:`None (Port 25)`}]},{key:`auth_enabled`,label:`Authentication`,type:`select`,required:!1,options:[{value:`true`,label:`Enabled`},{value:`false`,label:`Disabled`}]},{key:`username`,label:`Username`,placeholder:`your@email.com`,type:`text`,required:!1},{key:`password`,label:`Password`,placeholder:`App password`,type:`password`,required:!1},{key:`from_email`,label:`From Email`,placeholder:`your@email.com`,type:`text`,required:!0},{key:`to_email`,label:`To Email`,placeholder:`recipient@email.com`,type:`text`,required:!0}];case`discord`:return[{key:`webhook_url`,label:`Webhook URL`,placeholder:`https://discord.com/api/webhooks/...`,type:`text`,required:!0}];case`webhook`:return[{key:`webhook_url`,label:`Webhook URL`,placeholder:`https://example.com/webhook`,type:`text`,required:!0},{key:`payload_format`,label:`Payload Format`,type:`select`,required:!1,options:[{value:`generic`,label:`Generic JSON`},{value:`slack`,label:`Slack / Mattermost`}]},{key:`auth_header`,label:`Authorization`,placeholder:`Bearer token (optional)`,type:`password`,required:!1},{key:`field_title`,label:`Title Field Name`,placeholder:`title`,type:`text`,required:!1,showIf:e=>e.payload_format!==`slack`},{key:`field_message`,label:`Message Field Name`,placeholder:`message`,type:`text`,required:!1,showIf:e=>e.payload_format!==`slack`}];case`homeassistant`:return[{key:`service`,label:`Home Assistant Service`,placeholder:`notify.mobile_app_myphone`,type:`text`,required:!1,help:n(`notifications.haServiceHelp`)},{key:`data`,label:`Data (JSON, optional)`,placeholder:`{"priority": "high", "ttl": 0, "channel": "3D Printing"}`,type:`textarea`,required:!1}];case`bark`:return[{key:`device_key`,label:`Device Key`,placeholder:`Your Bark device key`,type:`text`,required:!0},{key:`server`,label:`Server URL`,placeholder:`https://api.day.app`,type:`text`,required:!1},{key:`group`,label:`Group`,placeholder:`Bambuddy`,type:`text`,required:!1},{key:`sound`,label:`Sound`,placeholder:`minuet`,type:`text`,required:!1},{key:`level`,label:`Interruption Level`,type:`select`,required:!1,options:[{value:``,label:`Default`},{value:`active`,label:`Active`},{value:`timeSensitive`,label:`Time Sensitive`},{value:`critical`,label:`Critical (bypasses Silent/Focus)`},{value:`passive`,label:`Passive (no sound)`}]}];case`gotify`:return[{key:`server`,label:`Server URL`,placeholder:`https://gotify.example.com`,type:`text`,required:!0},{key:`app_token`,label:`App Token`,placeholder:`Token of a Gotify application`,type:`password`,required:!0}];default:return[]}},We=e=>Ue(e).filter(e=>e.required),Ge=Ue(p);return(0,Y.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4 overflow-y-auto`,onClick:t,children:(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-lg my-8 max-h-[90vh] overflow-y-auto`,onClick:e=>e.stopPropagation(),children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:n(o?`notifications.editTitle`:`notifications.addTitle`)}),(0,Y.jsx)(`button`,{onClick:t,className:`text-bambu-gray hover:text-white transition-colors`,children:(0,Y.jsx)(Re,{className:`w-5 h-5`})})]}),(0,Y.jsxs)(`form`,{onSubmit:Ve,className:`p-6 space-y-4`,children:[Le&&(0,Y.jsx)(`div`,{className:`p-3 bg-red-100 dark:bg-red-500/20 border border-red-300 dark:border-red-500/50 rounded-lg text-sm text-red-700 dark:text-red-400`,children:Le}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`notifications.nameLabel`)}),(0,Y.jsx)(`input`,{type:`text`,value:s,onChange:e=>c(e.target.value),placeholder:n(`notifications.namePlaceholder`),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`notifications.providerTypeLabel`)}),(0,Y.jsx)(`select`,{value:p,onChange:e=>{m(e.target.value),Me({}),Ie(null)},disabled:o,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none disabled:opacity-50`,children:Dr.map(e=>({value:e,label:n(`notifications.providerTypes.${e}`,e)})).sort((e,t)=>e.label.localeCompare(t.label,i.language,{sensitivity:`base`})).map(({value:e,label:t})=>(0,Y.jsx)(`option`,{value:e,children:t},e))}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(`notifications.providerDescriptions.${p}`,``)})]}),(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`notifications.configuration`)}),Ge.filter(e=>!(`showIf`in e)||e.showIf?.(je)!==!1).map(e=>(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[e.label,` `,e.required&&`*`]}),e.type===`select`&&`options`in e&&e.options?(0,Y.jsx)(`select`,{value:je[e.key]||e.options[0]?.value||``,onChange:t=>{Me({...je,[e.key]:t.target.value}),Ie(null)},className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:e.options.map(e=>(0,Y.jsx)(`option`,{value:e.value,children:e.label},e.value))}):e.type===`textarea`?(0,Y.jsx)(`textarea`,{value:je[e.key]||``,onChange:t=>{Me({...je,[e.key]:t.target.value}),Ie(null)},placeholder:e.placeholder,rows:3,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none font-mono text-sm`}):(0,Y.jsx)(`input`,{type:e.type,value:je[e.key]||``,onChange:t=>{Me({...je,[e.key]:t.target.value}),Ie(null)},placeholder:e.placeholder,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),`help`in e&&e.help&&(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e.help})]},e.key)),p===`telegram`&&(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{htmlFor:`telegram-verdict-mode`,className:`block text-sm text-bambu-gray mb-1`,children:n(`notifications.telegramVerdictMode`)}),(0,Y.jsxs)(`select`,{id:`telegram-verdict-mode`,value:be,onChange:e=>H(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`,children:[(0,Y.jsx)(`option`,{value:`buttons`,children:n(`notifications.telegramVerdictModeButtons`)}),(0,Y.jsx)(`option`,{value:`reactions`,children:n(`notifications.telegramVerdictModeReactions`)}),(0,Y.jsx)(`option`,{value:`both`,children:n(`notifications.telegramVerdictModeBoth`)})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(`notifications.telegramVerdictModeHelp`)})]})]}),(0,Y.jsx)(`div`,{className:`flex gap-2`,children:(0,Y.jsxs)(K,{type:`button`,variant:`secondary`,onClick:()=>{Ie(null),ze.mutate()},disabled:ze.isPending||We(p).length>0&&!je[We(p)[0]?.key],className:`flex-1`,children:[ze.isPending?(0,Y.jsx)(R,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(Sn,{className:`w-4 h-4`}),n(`notifications.testConfiguration`)]})}),Fe&&(0,Y.jsx)(`div`,{className:`p-3 rounded-lg flex items-center gap-2 ${Fe.success?`bg-bambu-green/20 border border-bambu-green/50 text-bambu-green`:`bg-red-100 dark:bg-red-500/20 border border-red-300 dark:border-red-500/50 text-red-700 dark:text-red-400`}`,children:Fe.success?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(j,{className:`w-5 h-5`}),(0,Y.jsx)(`span`,{children:Fe.message})]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(O,{className:`w-5 h-5`}),(0,Y.jsx)(`span`,{children:Fe.message})]})}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`notifications.printerFilter`)}),(0,Y.jsxs)(`select`,{value:h??``,onChange:e=>g(e.target.value?Number(e.target.value):null),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,Y.jsx)(`option`,{value:``,children:n(`notifications.allPrinters`)}),W?.map(e=>(0,Y.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(`notifications.onlyFromPrinter`)})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`text-sm text-white`,children:n(`notifications.attachPhotoLabel`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.attachPhotoDescription`)})]}),(0,Y.jsx)(J,{checked:_,onChange:v})]}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`label`,{className:`text-sm text-white`,children:n(`notifications.quietHoursDnd`)}),(0,Y.jsx)(J,{checked:y,onChange:b})]}),y&&(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:n(`notifications.quietStart`)}),(0,Y.jsx)(`input`,{type:`time`,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 focus:border-bambu-green focus:outline-none`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:n(`notifications.quietEnd`)}),(0,Y.jsx)(`input`,{type:`time`,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 focus:border-bambu-green focus:outline-none`})]})]})]}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`text-sm text-white`,children:n(`notifications.dailyDigestLabel`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.batchNotifications`)})]}),(0,Y.jsx)(J,{checked:T,onChange:E})]}),T&&(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:n(`notifications.sendDigestAt`)}),(0,Y.jsx)(`input`,{type:`time`,value:D,onChange:e=>k(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`}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(`notifications.digestCollected`)})]})]}),(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`notifications.notificationEvents`)}),(0,Y.jsxs)(`div`,{className:`space-y-2 p-3 bg-bambu-dark rounded-lg`,children:[(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide mb-2`,children:n(`notifications.printEvents`)}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.start`)}),(0,Y.jsx)(J,{checked:A,onChange:ee})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.complete`)}),(0,Y.jsx)(J,{checked:M,onChange:N})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.failed`)}),(0,Y.jsx)(J,{checked:P,onChange:te})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.stopped`)}),(0,Y.jsx)(J,{checked:F,onChange:ne})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between col-span-2`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.progress`)}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1`,children:n(`notifications.progressPercent`)})]}),(0,Y.jsx)(J,{checked:I,onChange:re})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between col-span-2`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.billingChargeFailedLabel`)}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1`,children:n(`notifications.billingChargeFailedDescription`)})]}),(0,Y.jsx)(J,{checked:ie,onChange:L})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between col-span-2`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.plateClearRequired`)}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1`,children:n(`notifications.plateClearRequiredDescription`)})]}),(0,Y.jsx)(J,{checked:ge,onChange:_e})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between col-span-2`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.printConfirmRequest`)}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1`,children:n(`notifications.printConfirmRequestDescription`)})]}),(0,Y.jsx)(J,{checked:ve,onChange:ye})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between col-span-2`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.bedCooled`)}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1`,children:n(`notifications.bedCooledAfterPrint`)})]}),(0,Y.jsx)(J,{checked:xe,onChange:Se})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between col-span-2`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.firstLayerCompleteLabel`)}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1`,children:n(`notifications.firstLayerCompleteDescription`)})]}),(0,Y.jsx)(J,{checked:De,onChange:Oe})]})]})]}),(0,Y.jsxs)(`div`,{className:`space-y-2 p-3 bg-bambu-dark rounded-lg`,children:[(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide mb-2`,children:n(`notifications.printerStatus`)}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.offline`)}),(0,Y.jsx)(J,{checked:ae,onChange:z})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between col-span-2`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.haSensorAlert`)}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1`,children:n(`notifications.haSensorAlertDescription`)})]}),(0,Y.jsx)(J,{checked:Ce,onChange:we})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between col-span-2`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.locationHaSensorAlert`)}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1`,children:n(`notifications.locationHaSensorAlertDescription`)})]}),(0,Y.jsx)(J,{checked:Te,onChange:Ee})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.error`)}),(0,Y.jsx)(J,{checked:oe,onChange:se})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.aiFailureDetection`)}),(0,Y.jsx)(J,{checked:B,onChange:ce})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.lowFilament`)}),(0,Y.jsx)(J,{checked:le,onChange:ue})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.maintenance`)}),(0,Y.jsx)(J,{checked:de,onChange:fe})]})]})]}),(0,Y.jsxs)(`div`,{className:`space-y-2 p-3 bg-bambu-dark rounded-lg`,children:[(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide mb-2`,children:n(`notifications.inventoryAlerts`)}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 gap-2`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.stockReorderAlert`)}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1`,children:n(`notifications.stockReorderAlertDescription`)})]}),(0,Y.jsx)(J,{checked:V,onChange:pe})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.stockBreakAlert`)}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1`,children:n(`notifications.stockBreakAlertDescription`)})]}),(0,Y.jsx)(J,{checked:me,onChange:he})]})]})]}),(0,Y.jsxs)(`div`,{className:`space-y-2 p-3 bg-bambu-dark rounded-lg`,children:[(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide mb-2`,children:n(`notifications.connectedApps`)}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.appMessages`)}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1`,children:n(`notifications.appMessagesDescription`)})]}),(0,Y.jsx)(J,{checked:ke,onChange:Ae})]})]}),(p===`ntfy`||p===`gotify`)&&(()=>{let e=[];return A&&e.push({key:`on_print_start`,label:n(`notifications.start`)}),M&&e.push({key:`on_print_complete`,label:n(`notifications.complete`)}),P&&e.push({key:`on_print_failed`,label:n(`notifications.failed`)}),F&&e.push({key:`on_print_stopped`,label:n(`notifications.stopped`)}),I&&e.push({key:`on_print_progress`,label:n(`notifications.progress`)}),ie&&e.push({key:`on_billing_charge_failed`,label:n(`notifications.billingChargeFailedLabel`)}),ge&&e.push({key:`on_plate_clear_required`,label:n(`notifications.plateClearRequired`)}),ve&&e.push({key:`on_print_confirm_request`,label:n(`notifications.printConfirmRequest`)}),xe&&e.push({key:`on_bed_cooled`,label:n(`notifications.bedCooled`)}),De&&e.push({key:`on_first_layer_complete`,label:n(`notifications.firstLayerCompleteLabel`)}),ae&&e.push({key:`on_printer_offline`,label:n(`notifications.offline`)}),oe&&e.push({key:`on_printer_error`,label:n(`notifications.error`)}),Ce&&e.push({key:`on_ha_sensor_alert`,label:n(`notifications.haSensorAlert`)}),Te&&e.push({key:`on_location_ha_sensor_alert`,label:n(`notifications.locationHaSensorAlert`)}),B&&e.push({key:`on_ai_failure_detection`,label:n(`notifications.aiFailureDetection`)}),le&&e.push({key:`on_filament_low`,label:n(`notifications.lowFilament`)}),de&&e.push({key:`on_maintenance_due`,label:n(`notifications.maintenance`)}),V&&e.push({key:`on_stock_reorder_alert`,label:n(`notifications.stockReorderAlert`)}),me&&e.push({key:`on_stock_break_alert`,label:n(`notifications.stockBreakAlert`)}),e.length===0?null:(0,Y.jsxs)(`div`,{className:`space-y-2 p-3 bg-bambu-dark rounded-lg`,children:[(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide mb-1`,children:n(p===`gotify`?`notifications.eventPriority.sectionTitleGotify`:`notifications.eventPriority.sectionTitle`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:n(p===`gotify`?`notifications.eventPriority.helpGotify`:`notifications.eventPriority.helpNtfy`)}),(0,Y.jsx)(`div`,{className:`space-y-2`,children:e.map(e=>(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:e.label}),(0,Y.jsxs)(`select`,{value:Ne[e.key]??3,onChange:t=>{let n=Number(t.target.value);Pe(t=>({...t,[e.key]:n}))},className:`px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-sm text-white focus:border-bambu-green focus:outline-none`,children:[(0,Y.jsx)(`option`,{value:1,children:n(`notifications.eventPriority.min`)}),(0,Y.jsx)(`option`,{value:2,children:n(`notifications.eventPriority.low`)}),(0,Y.jsx)(`option`,{value:3,children:n(`notifications.eventPriority.default`)}),(0,Y.jsx)(`option`,{value:4,children:n(`notifications.eventPriority.high`)}),(0,Y.jsx)(`option`,{value:5,children:n(`notifications.eventPriority.urgent`)})]})]},e.key))})]})})()]}),(0,Y.jsxs)(`div`,{className:`flex gap-3 pt-2`,children:[(0,Y.jsx)(K,{type:`button`,variant:`secondary`,onClick:t,className:`flex-1`,children:n(`notifications.cancel`)}),(0,Y.jsxs)(K,{type:`submit`,disabled:He,className:`flex-1`,children:[He?(0,Y.jsx)(R,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(_t,{className:`w-4 h-4`}),n(o?`notifications.save`:`notifications.add`)]})]})]})]})})}function kr({template:e,onClose:t}){let{t:n}=l(),i=u(),a=(0,X.useRef)(null),[o,s]=(0,X.useState)(e.title_template),[c,p]=(0,X.useState)(e.body_template),[m,h]=(0,X.useState)(null),[g,_]=(0,X.useState)(!0),{data:v}=d({queryKey:[`template-variables`],queryFn:r.getTemplateVariables}),y=v?.find(t=>t.event_type===e.event_type),{data:b,isLoading:x}=d({queryKey:[`template-preview`,e.event_type,o,c],queryFn:()=>r.previewTemplate({event_type:e.event_type,title_template:o,body_template:c}),enabled:g&&o.length>0&&c.length>0});(0,X.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]);let S=f({mutationFn:t=>r.updateNotificationTemplate(e.id,t),onSuccess:()=>{i.invalidateQueries({queryKey:[`notification-templates`]}),t()},onError:e=>{h(e.message)}}),C=f({mutationFn:()=>r.resetNotificationTemplate(e.id),onSuccess:e=>{s(e.title_template),p(e.body_template),i.invalidateQueries({queryKey:[`notification-templates`]})},onError:e=>{h(e.message)}}),w=e=>{if(e.preventDefault(),h(null),!o.trim()){h(n(`notifications.titleRequired`));return}if(!c.trim()){h(n(`notifications.bodyRequired`));return}S.mutate({title_template:o,body_template:c})},T=e=>{let t=a.current;if(!t)return;let n=t.selectionStart,r=t.selectionEnd,i=c,o=i.substring(0,n),s=i.substring(r);p(o+`{${e}}`+s),setTimeout(()=>{t.focus();let r=n+e.length+2;t.setSelectionRange(r,r)},0)},E=o!==e.title_template||c!==e.body_template;return(0,Y.jsx)(`div`,{className:`fixed inset-0 bg-black/80 flex items-center justify-center z-50 p-4`,children:(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-2xl max-h-[90vh] flex flex-col`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary shrink-0`,children:[(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:n(`notifications.editTemplate`,{name:e.name})}),(0,Y.jsx)(`button`,{onClick:t,className:`p-1 hover:bg-bambu-dark-tertiary rounded transition-colors`,children:(0,Y.jsx)(Re,{className:`w-5 h-5 text-bambu-gray`})})]}),(0,Y.jsxs)(`form`,{onSubmit:w,className:`flex-1 overflow-y-auto p-4 space-y-4`,children:[m&&(0,Y.jsx)(`div`,{className:`p-3 bg-red-100 dark:bg-red-500/20 border border-red-300 dark:border-red-500/50 rounded text-red-700 dark:text-red-400 text-sm`,children:m}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:n(`notifications.titleLabel`)}),(0,Y.jsx)(`input`,{type:`text`,value:o,onChange:e=>s(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white focus:outline-none focus:ring-1 focus:ring-bambu-green`,placeholder:n(`notifications.titlePlaceholder`)})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:n(`notifications.bodyLabel`)}),(0,Y.jsx)(`textarea`,{ref:a,value:c,onChange:e=>p(e.target.value),rows:4,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white focus:outline-none focus:ring-1 focus:ring-bambu-green font-mono text-sm resize-none`,placeholder:n(`notifications.bodyPlaceholder`)})]}),y&&(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-2`,children:n(`notifications.availableVariables`)}),(0,Y.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:y.variables.map(e=>(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>T(e),className:`inline-flex items-center gap-1 px-2 py-1 bg-bambu-dark hover:bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-xs text-bambu-gray hover:text-white transition-colors`,children:[(0,Y.jsx)(wt,{className:`w-3 h-3`}),e]},e))}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray/60 mt-1`,children:n(`notifications.clickToInsert`)})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,Y.jsxs)(`label`,{className:`text-sm font-medium text-bambu-gray flex items-center gap-2`,children:[(0,Y.jsx)(mt,{className:`w-4 h-4`}),n(`notifications.livePreview`)]}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>_(!g),className:`text-xs text-bambu-green hover:text-bambu-green-light`,children:n(g?`notifications.hide`:`notifications.show`)})]}),g&&(0,Y.jsx)(`div`,{className:`bg-bambu-dark border border-bambu-dark-tertiary rounded p-3 space-y-2`,children:x?(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray text-sm`,children:[(0,Y.jsx)(R,{className:`w-4 h-4 animate-spin`}),n(`notifications.loadingPreview`)]}):b?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:n(`notifications.titlePreview`)}),(0,Y.jsx)(`div`,{className:`text-white font-medium`,children:b.title})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:n(`notifications.bodyPreview`)}),(0,Y.jsx)(`div`,{className:`text-white whitespace-pre-wrap text-sm`,children:b.body})]}),y?.supports_photo&&(0,Y.jsxs)(`div`,{className:`pt-2 mt-2 border-t border-bambu-dark-tertiary/60 flex items-center gap-3`,children:[(0,Y.jsx)(`img`,{src:`/img/screenshot-desktop.png`,alt:n(`notifications.photoPreview`),className:`w-24 h-14 object-cover rounded border border-bambu-dark-tertiary shrink-0`}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:e.event_type.startsWith(`user_`)?n(`notifications.photoPreviewNoteEmailOnly`):y.variables.includes(`finish_photo_url`)?n(`notifications.photoPreviewNoteWithEmail`):n(`notifications.photoPreviewNote`)})]})]}):(0,Y.jsx)(`div`,{className:`text-bambu-gray text-sm`,children:n(`notifications.enterTemplateContent`)})})]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-t border-bambu-dark-tertiary shrink-0`,children:[(0,Y.jsxs)(K,{type:`button`,variant:`ghost`,onClick:()=>C.mutate(),disabled:C.isPending,className:`text-orange-600 dark:text-orange-400 hover:text-orange-700 dark:hover:text-orange-300`,children:[C.isPending?(0,Y.jsx)(R,{className:`w-4 h-4 animate-spin mr-2`}):(0,Y.jsx)(nt,{className:`w-4 h-4 mr-2`}),n(`notifications.resetToDefault`)]}),(0,Y.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Y.jsx)(K,{type:`button`,variant:`secondary`,onClick:t,children:n(`notifications.cancel`)}),(0,Y.jsxs)(K,{onClick:w,disabled:S.isPending||!E,children:[S.isPending?(0,Y.jsx)(R,{className:`w-4 h-4 animate-spin mr-2`}):(0,Y.jsx)(_t,{className:`w-4 h-4 mr-2`}),n(`notifications.save`)]})]})]})]})})}var Ar={print_start:`text-blue-700 dark:text-blue-400`,print_complete:`text-bambu-green`,print_failed:`text-red-700 dark:text-red-400`,print_stopped:`text-orange-700 dark:text-orange-400`,print_progress:`text-yellow-700 dark:text-yellow-400`,printer_offline:`text-gray-400`,printer_error:`text-rose-700 dark:text-rose-400`,filament_low:`text-cyan-700 dark:text-cyan-400`,maintenance_due:`text-purple-700 dark:text-purple-400`,test:`text-bambu-gray`};function jr({onClose:e}){let{t}=l(),n=u(),{showToast:i}=ee(),[a,o]=(0,X.useState)(7),[s,c]=(0,X.useState)(null),[p,m]=(0,X.useState)(!1),{data:h}=d({queryKey:[`settings`],queryFn:r.getSettings}),g=h?.time_format||`system`,{data:_,isLoading:v,refetch:y,isRefetching:b}=d({queryKey:[`notification-logs`,a,p],queryFn:()=>r.getNotificationLogs({days:a,limit:100,success:p?!1:void 0})}),{data:x}=d({queryKey:[`notification-log-stats`,a],queryFn:()=>r.getNotificationLogStats(a)}),S=f({mutationFn:()=>r.clearNotificationLogs(30),onSuccess:e=>{i(e.message,`success`),n.invalidateQueries({queryKey:[`notification-logs`]}),n.invalidateQueries({queryKey:[`notification-log-stats`]})},onError:e=>{i(`Failed to clear logs: ${e.message}`,`error`)}}),C=e=>{let n=We(e);if(!n)return``;let r=new Date().getTime()-n.getTime();return r<6e4?t(`notifications.justNow`):r<36e5?`${Math.floor(r/6e4)}m ago`:r<864e5?`${Math.floor(r/36e5)}h ago`:n.toLocaleDateString()+` `+Ve(n,g)};return(0,Y.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,children:(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg w-full max-w-3xl max-h-[85vh] flex flex-col`,children:[(0,Y.jsxs)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Y.jsx)(ie,{className:`w-5 h-5 text-bambu-green`}),(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:t(`notifications.notificationLog`)})]}),(0,Y.jsx)(`button`,{onClick:e,className:`text-bambu-gray hover:text-white transition-colors`,children:`×`})]}),x&&(0,Y.jsx)(`div`,{className:`px-4 py-3 border-b border-bambu-dark-tertiary bg-bambu-dark/50`,children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-6 text-sm`,children:[(0,Y.jsxs)(`span`,{className:`text-bambu-gray`,children:[t(`notifications.statsSummary`,{days:a}),` `,(0,Y.jsx)(`span`,{className:`text-white font-medium`,children:x.total}),` `,t(`notifications.statsNotifications`)]}),(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 text-bambu-green`,children:[(0,Y.jsx)(j,{className:`w-4 h-4`}),t(`notifications.statsSent`,{count:x.success_count})]}),x.failure_count>0&&(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 text-red-700 dark:text-red-400`,children:[(0,Y.jsx)(O,{className:`w-4 h-4`}),t(`notifications.statsFailed`,{count:x.failure_count})]})]})}),(0,Y.jsxs)(`div`,{className:`px-4 py-3 border-b border-bambu-dark-tertiary flex items-center gap-4`,children:[(0,Y.jsxs)(`select`,{value:a,onChange:e=>o(Number(e.target.value)),className:`px-3 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:outline-none focus:ring-1 focus:ring-bambu-green`,children:[(0,Y.jsx)(`option`,{value:1,children:t(`notifications.last24Hours`)}),(0,Y.jsx)(`option`,{value:7,children:t(`notifications.last7Days`)}),(0,Y.jsx)(`option`,{value:30,children:t(`notifications.last30Days`)}),(0,Y.jsx)(`option`,{value:90,children:t(`notifications.last90Days`)})]}),(0,Y.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-bambu-gray cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:p,onChange:e=>m(e.target.checked),className:`rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),t(`notifications.showFailedOnly`)]}),(0,Y.jsx)(`div`,{className:`flex-1`}),(0,Y.jsxs)(K,{size:`sm`,variant:`secondary`,onClick:()=>y(),disabled:b,children:[b?(0,Y.jsx)(R,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(at,{className:`w-4 h-4`}),t(`notifications.refresh`)]}),(0,Y.jsxs)(K,{size:`sm`,variant:`secondary`,onClick:()=>S.mutate(),disabled:S.isPending,className:`text-red-700 dark:text-red-400 hover:text-red-800 dark:hover:text-red-300`,children:[S.isPending?(0,Y.jsx)(R,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(qe,{className:`w-4 h-4`}),t(`notifications.clearOld`)]})]}),(0,Y.jsx)(`div`,{className:`flex-1 overflow-y-auto p-4`,children:v?(0,Y.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,Y.jsx)(R,{className:`w-6 h-6 text-bambu-green animate-spin`})}):_&&_.length>0?(0,Y.jsx)(`div`,{className:`space-y-2`,children:_.map(e=>(0,Y.jsx)(Mr,{log:e,isExpanded:s===e.id,onToggle:()=>c(s===e.id?null:e.id),formatDate:C,formatFullDate:e=>Be(e,g)},e.id))}):(0,Y.jsxs)(`div`,{className:`text-center py-12 text-bambu-gray`,children:[(0,Y.jsx)(ie,{className:`w-12 h-12 mx-auto mb-3 opacity-30`}),(0,Y.jsx)(`p`,{className:`text-sm`,children:t(p?`notifications.noFailedNotifications`:`notifications.noNotificationsLogged`)})]})})]})})}function Mr({log:e,isExpanded:t,onToggle:n,formatDate:r,formatFullDate:i}){let{t:a}=l();return(0,Y.jsxs)(`div`,{className:`border rounded-lg overflow-hidden transition-colors ${e.success?`border-bambu-dark-tertiary bg-bambu-dark/30`:`border-red-500/30 bg-red-500/5`}`,children:[(0,Y.jsxs)(`button`,{className:`w-full px-3 py-2 flex items-center gap-3 text-left hover:bg-bambu-dark/50 transition-colors`,onClick:n,children:[e.success?(0,Y.jsx)(j,{className:`w-4 h-4 text-bambu-green shrink-0`}):(0,Y.jsx)(O,{className:`w-4 h-4 text-red-600 dark:text-red-400 shrink-0`}),(0,Y.jsx)(`span`,{className:`text-xs font-medium ${Ar[e.event_type]||`text-bambu-gray`}`,children:a(`notifications.eventTypes.${e.event_type}`,e.event_type)}),(0,Y.jsx)(`span`,{className:`text-sm text-white truncate flex-1`,children:e.provider_name||a(`notifications.unknownProvider`)}),e.printer_name&&(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:e.printer_name}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray shrink-0`,children:r(e.created_at)}),t?(0,Y.jsx)(D,{className:`w-4 h-4 text-bambu-gray shrink-0`}):(0,Y.jsx)(E,{className:`w-4 h-4 text-bambu-gray shrink-0`})]}),t&&(0,Y.jsxs)(`div`,{className:`px-3 py-2 border-t border-bambu-dark-tertiary bg-bambu-dark/20 space-y-2`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mb-1`,children:a(`notifications.logTitle`)}),(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:e.title})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mb-1`,children:a(`notifications.logMessage`)}),(0,Y.jsx)(`p`,{className:`text-sm text-white whitespace-pre-wrap`,children:e.message})]}),!e.success&&e.error_message&&(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-xs text-red-700 dark:text-red-400 mb-1`,children:a(`notifications.logError`)}),(0,Y.jsx)(`p`,{className:`text-sm text-red-700 dark:text-red-300`,children:e.error_message})]}),(0,Y.jsxs)(`div`,{className:`flex gap-4 text-xs text-bambu-gray pt-1`,children:[(0,Y.jsx)(`span`,{children:a(`notifications.logProvider`,{type:e.provider_type})}),(0,Y.jsx)(`span`,{children:a(`notifications.logTime`,{time:i(e.created_at)})})]})]})]})}var Nr=Object.defineProperty,Pr=Object.getOwnPropertySymbols,Fr=Object.prototype.hasOwnProperty,Ir=Object.prototype.propertyIsEnumerable,Lr=(e,t,n)=>t in e?Nr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Rr=(e,t)=>{for(var n in t||={})Fr.call(t,n)&&Lr(e,n,t[n]);if(Pr)for(var n of Pr(t))Ir.call(t,n)&&Lr(e,n,t[n]);return e},zr=(e,t)=>{var n={};for(var r in e)Fr.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&Pr)for(var r of Pr(e))t.indexOf(r)<0&&Ir.call(e,r)&&(n[r]=e[r]);return n},Br;(e=>{let t=class t{constructor(e,n,r,a){if(this.version=e,this.errorCorrectionLevel=n,this.modules=[],this.isFunction=[],et.MAX_VERSION)throw RangeError(`Version value out of range`);if(a<-1||a>7)throw RangeError(`Mask value out of range`);this.size=e*4+17;let o=[];for(let e=0;e7)throw RangeError(`Invalid value`);let u,d;for(u=a;;u++){let n=t.getNumDataCodewords(u,r)*8,i=o.getTotalBits(e,u);if(i<=n){d=i;break}if(u>=s)throw RangeError(`Data too long`)}for(let e of[t.Ecc.MEDIUM,t.Ecc.QUARTILE,t.Ecc.HIGH])l&&d<=t.getNumDataCodewords(u,e)*8&&(r=e);let f=[];for(let t of e){n(t.mode.modeBits,4,f),n(t.numChars,t.mode.numCharCountBits(u),f);for(let e of t.getData())f.push(e)}i(f.length==d);let p=t.getNumDataCodewords(u,r)*8;i(f.length<=p),n(0,Math.min(4,p-f.length),f),n(0,(8-f.length%8)%8,f),i(f.length%8==0);for(let e=236;f.lengthm[t>>>3]|=e<<7-(t&7)),new t(u,r,m,c)}getModule(e,t){return 0<=e&&e>>9)*1335;let a=(t<<10|n)^21522;i(a>>>15==0);for(let e=0;e<=5;e++)this.setFunctionModule(8,e,r(a,e));this.setFunctionModule(8,7,r(a,6)),this.setFunctionModule(8,8,r(a,7)),this.setFunctionModule(7,8,r(a,8));for(let e=9;e<15;e++)this.setFunctionModule(14-e,8,r(a,e));for(let e=0;e<8;e++)this.setFunctionModule(this.size-1-e,8,r(a,e));for(let e=8;e<15;e++)this.setFunctionModule(8,this.size-15+e,r(a,e));this.setFunctionModule(8,this.size-8,!0)}drawVersion(){if(this.version<7)return;let e=this.version;for(let t=0;t<12;t++)e=e<<1^(e>>>11)*7973;let t=this.version<<12|e;i(t>>>18==0);for(let e=0;e<18;e++){let n=r(t,e),i=this.size-11+e%3,a=Math.floor(e/3);this.setFunctionModule(i,a,n),this.setFunctionModule(a,i,n)}}drawFinderPattern(e,t){for(let n=-4;n<=4;n++)for(let r=-4;r<=4;r++){let i=Math.max(Math.abs(r),Math.abs(n)),a=e+r,o=t+n;0<=a&&a{(e!=l-o||n>=c)&&f.push(t[e])});return i(f.length==s),f}drawCodewords(e){if(e.length!=Math.floor(t.getNumRawDataModules(this.version)/8))throw RangeError(`Invalid argument`);let n=0;for(let t=this.size-1;t>=1;t-=2){t==6&&(t=5);for(let i=0;i>>3],7-(n&7)),n++)}}i(n==e.length*8)}applyMask(e){if(e<0||e>7)throw RangeError(`Mask value out of range`);for(let t=0;t5&&e++):(this.finderPenaltyAddHistory(i,a),r||(e+=this.finderPenaltyCountPatterns(a)*t.PENALTY_N3),r=this.modules[n][o],i=1);e+=this.finderPenaltyTerminateAndCount(r,i,a)*t.PENALTY_N3}for(let n=0;n5&&e++):(this.finderPenaltyAddHistory(i,a),r||(e+=this.finderPenaltyCountPatterns(a)*t.PENALTY_N3),r=this.modules[o][n],i=1);e+=this.finderPenaltyTerminateAndCount(r,i,a)*t.PENALTY_N3}for(let n=0;ne+ +!!t,n);let r=this.size*this.size,a=Math.ceil(Math.abs(n*20-r*10)/r)-1;return i(0<=a&&a<=9),e+=a*t.PENALTY_N4,i(0<=e&&e<=2568888),e}getAlignmentPatternPositions(){if(this.version==1)return[];{let e=Math.floor(this.version/7)+2,t=this.version==32?26:Math.ceil((this.version*4+4)/(e*2-2))*2,n=[6];for(let r=this.size-7;n.lengtht.MAX_VERSION)throw RangeError(`Version number out of range`);let n=(16*e+128)*e+64;if(e>=2){let t=Math.floor(e/7)+2;n-=(25*t-10)*t-55,e>=7&&(n-=36)}return i(208<=n&&n<=29648),n}static getNumDataCodewords(e,n){return Math.floor(t.getNumRawDataModules(e)/8)-t.ECC_CODEWORDS_PER_BLOCK[n.ordinal][e]*t.NUM_ERROR_CORRECTION_BLOCKS[n.ordinal][e]}static reedSolomonComputeDivisor(e){if(e<1||e>255)throw RangeError(`Degree out of range`);let n=[];for(let t=0;t0);for(let i of e){let e=i^r.shift();r.push(0),n.forEach((n,i)=>r[i]^=t.reedSolomonMultiply(n,e))}return r}static reedSolomonMultiply(e,t){if(e>>>8||t>>>8)throw RangeError(`Byte out of range`);let n=0;for(let r=7;r>=0;r--)n=n<<1^(n>>>7)*285,n^=(t>>>r&1)*e;return i(n>>>8==0),n}finderPenaltyCountPatterns(e){let t=e[1];i(t<=this.size*3);let n=t>0&&e[2]==t&&e[3]==t*3&&e[4]==t&&e[5]==t;return(n&&e[0]>=t*4&&e[6]>=t?1:0)+(n&&e[6]>=t*4&&e[0]>=t?1:0)}finderPenaltyTerminateAndCount(e,t,n){return e&&(this.finderPenaltyAddHistory(t,n),t=0),t+=this.size,this.finderPenaltyAddHistory(t,n),this.finderPenaltyCountPatterns(n)}finderPenaltyAddHistory(e,t){t[0]==0&&(e+=this.size),t.pop(),t.unshift(e)}};t.MIN_VERSION=1,t.MAX_VERSION=40,t.PENALTY_N1=3,t.PENALTY_N2=3,t.PENALTY_N3=40,t.PENALTY_N4=10,t.ECC_CODEWORDS_PER_BLOCK=[[-1,7,10,15,20,26,18,20,24,30,18,20,24,26,30,22,24,28,30,28,28,28,28,30,30,26,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,10,16,26,18,24,16,18,22,22,26,30,22,22,24,24,28,28,26,26,26,26,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28],[-1,13,22,18,26,18,24,18,22,20,24,28,26,24,20,30,24,28,28,26,30,28,30,30,30,30,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,17,28,22,16,22,28,26,26,24,28,24,28,22,24,24,30,28,28,26,28,30,24,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30]],t.NUM_ERROR_CORRECTION_BLOCKS=[[-1,1,1,1,1,1,2,2,2,2,4,4,4,4,4,6,6,6,6,7,8,8,9,9,10,12,12,12,13,14,15,16,17,18,19,19,20,21,22,24,25],[-1,1,1,1,2,2,4,4,4,5,5,5,8,9,9,10,10,11,13,14,16,17,17,18,20,21,23,25,26,28,29,31,33,35,37,38,40,43,45,47,49],[-1,1,1,2,2,4,4,6,6,8,8,8,10,12,16,12,17,16,18,21,20,23,23,25,27,29,34,34,35,38,40,43,45,48,51,53,56,59,62,65,68],[-1,1,1,2,4,4,4,5,6,8,8,11,11,16,16,18,16,19,21,25,25,25,34,30,32,35,37,40,42,45,48,51,54,57,60,63,66,70,74,77,81]],e.QrCode=t;function n(e,t,n){if(t<0||t>31||e>>>t)throw RangeError(`Value out of range`);for(let r=t-1;r>=0;r--)n.push(e>>>r&1)}function r(e,t){return(e>>>t&1)!=0}function i(e){if(!e)throw Error(`Assertion error`)}let a=class e{constructor(e,t,n){if(this.mode=e,this.numChars=t,this.bitData=n,t<0)throw RangeError(`Invalid argument`);this.bitData=n.slice()}static makeBytes(t){let r=[];for(let e of t)n(e,8,r);return new e(e.Mode.BYTE,t.length,r)}static makeNumeric(t){if(!e.isNumeric(t))throw RangeError(`String contains non-numeric characters`);let r=[];for(let e=0;e=1<{(e=>{let t=class{constructor(e,t){this.ordinal=e,this.formatBits=t}};t.LOW=new t(0,1),t.MEDIUM=new t(1,0),t.QUARTILE=new t(2,3),t.HIGH=new t(3,2),e.Ecc=t})(e.QrCode||={})})(Br||={}),(e=>{(e=>{let t=class{constructor(e,t){this.modeBits=e,this.numBitsCharCount=t}numCharCountBits(e){return this.numBitsCharCount[Math.floor((e+7)/17)]}};t.NUMERIC=new t(1,[10,12,14]),t.ALPHANUMERIC=new t(2,[9,11,13]),t.BYTE=new t(4,[8,16,16]),t.KANJI=new t(8,[8,10,12]),t.ECI=new t(7,[0,0,0]),e.Mode=t})(e.QrSegment||={})})(Br||={});var Vr=Br,Z={L:Vr.QrCode.Ecc.LOW,M:Vr.QrCode.Ecc.MEDIUM,Q:Vr.QrCode.Ecc.QUARTILE,H:Vr.QrCode.Ecc.HIGH},Hr=128,Ur=`L`,Wr=`#FFFFFF`,Gr=`#000000`,Kr=!1,qr=1,Jr=4,Yr=0,Xr=.1;function Zr(e,t=0){let n=[];return e.forEach(function(e,r){let i=null;e.forEach(function(a,o){if(!a&&i!==null){n.push(`M${i+t} ${r+t}h${o-i}v1H${i+t}z`),i=null;return}if(o===e.length-1){if(!a)return;i===null?n.push(`M${o+t},${r+t} h1v1H${o+t}z`):n.push(`M${i+t},${r+t} h${o+1-i}v1H${i+t}z`);return}a&&i===null&&(i=o)})}),n.join(``)}function Qr(e,t){return e.slice().map((e,n)=>n=t.y+t.h?e:e.map((e,n)=>n=t.x+t.w?e:!1))}function $r(e,t,n,r){if(r==null)return null;let i=e.length+n*2,a=Math.floor(t*Xr),o=i/t,s=(r.width||a)*o,c=(r.height||a)*o,l=r.x==null?e.length/2-s/2:r.x*o,u=r.y==null?e.length/2-c/2:r.y*o,d=r.opacity==null?1:r.opacity,f=null;if(r.excavate){let e=Math.floor(l),t=Math.floor(u);f={x:e,y:t,w:Math.ceil(s+l-e),h:Math.ceil(c+u-t)}}let p=r.crossOrigin;return{x:l,y:u,h:c,w:s,excavation:f,opacity:d,crossOrigin:p}}function ei(e,t){return t==null?e?Jr:Yr:Math.max(Math.floor(t),0)}function ti({value:e,level:t,minVersion:n,includeMargin:r,marginSize:i,imageSettings:a,size:o,boostLevel:s}){let c=X.useMemo(()=>{let r=(Array.isArray(e)?e:[e]).reduce((e,t)=>(e.push(...Vr.QrSegment.makeSegments(t)),e),[]);return Vr.QrCode.encodeSegments(r,Z[t],n,void 0,void 0,s)},[e,t,n,s]),{cells:l,margin:u,numCells:d,calculatedImageSettings:f}=X.useMemo(()=>{let e=c.getModules(),t=ei(r,i);return{cells:e,margin:t,numCells:e.length+t*2,calculatedImageSettings:$r(e,o,t,a)}},[c,o,a,r,i]);return{qrcode:c,margin:u,cells:l,numCells:d,calculatedImageSettings:f}}var ni=function(){try{new Path2D().addPath(new Path2D)}catch{return!1}return!0}(),ri=X.forwardRef(function(e,t){let n=e,{value:r,size:i=Hr,level:a=Ur,bgColor:o=Wr,fgColor:s=Gr,includeMargin:c=Kr,minVersion:l=qr,boostLevel:u,marginSize:d,imageSettings:f}=n,p=zr(n,[`value`,`size`,`level`,`bgColor`,`fgColor`,`includeMargin`,`minVersion`,`boostLevel`,`marginSize`,`imageSettings`]),{style:m}=p,h=zr(p,[`style`]),g=f?.src,_=X.useRef(null),v=X.useRef(null),y=X.useCallback(e=>{_.current=e,typeof t==`function`?t(e):t&&(t.current=e)},[t]),[b,x]=X.useState(!1),{margin:S,cells:C,numCells:w,calculatedImageSettings:T}=ti({value:r,level:a,minVersion:l,boostLevel:u,includeMargin:c,marginSize:d,imageSettings:f,size:i});X.useEffect(()=>{if(_.current!=null){let e=_.current,t=e.getContext(`2d`);if(!t)return;let n=C,r=v.current,a=T!=null&&r!==null&&r.complete&&r.naturalHeight!==0&&r.naturalWidth!==0;a&&T.excavation!=null&&(n=Qr(C,T.excavation));let c=window.devicePixelRatio||1;e.height=e.width=i*c;let l=i/w*c;t.scale(l,l),t.fillStyle=o,t.fillRect(0,0,w,w),t.fillStyle=s,ni?t.fill(new Path2D(Zr(n,S))):C.forEach(function(e,n){e.forEach(function(e,r){e&&t.fillRect(r+S,n+S,1,1)})}),T&&(t.globalAlpha=T.opacity),a&&t.drawImage(r,T.x+S,T.y+S,T.w,T.h)}}),X.useEffect(()=>{x(!1)},[g]);let E=Rr({height:i,width:i},m),D=null;return g!=null&&(D=X.createElement(`img`,{src:g,key:g,style:{display:`none`},onLoad:()=>{x(!0)},ref:v,crossOrigin:T?.crossOrigin})),X.createElement(X.Fragment,null,X.createElement(`canvas`,Rr({style:E,height:i,width:i,ref:y,role:`img`},h)),D)});ri.displayName=`QRCodeCanvas`;var ii=X.forwardRef(function(e,t){let n=e,{value:r,size:i=Hr,level:a=Ur,bgColor:o=Wr,fgColor:s=Gr,includeMargin:c=Kr,minVersion:l=qr,boostLevel:u,title:d,marginSize:f,imageSettings:p}=n,m=zr(n,[`value`,`size`,`level`,`bgColor`,`fgColor`,`includeMargin`,`minVersion`,`boostLevel`,`title`,`marginSize`,`imageSettings`]),{margin:h,cells:g,numCells:_,calculatedImageSettings:v}=ti({value:r,level:a,minVersion:l,boostLevel:u,includeMargin:c,marginSize:f,imageSettings:p,size:i}),y=g,b=null;p!=null&&v!=null&&(v.excavation!=null&&(y=Qr(g,v.excavation)),b=X.createElement(`image`,{href:p.src,height:v.h,width:v.w,x:v.x+h,y:v.y+h,preserveAspectRatio:`none`,opacity:v.opacity,crossOrigin:v.crossOrigin}));let x=Zr(y,h);return X.createElement(`svg`,Rr({height:i,width:i,viewBox:`0 0 ${_} ${_}`,ref:t,role:`img`},m),!!d&&X.createElement(`title`,null,d),X.createElement(`path`,{fill:o,d:`M0,0 h${_}v${_}H0z`,shapeRendering:`crispEdges`}),X.createElement(`path`,{fill:s,d:x,shapeRendering:`crispEdges`}),b)});ii.displayName=`QRCodeSVG`;function ai(e,t){return`bambuddy://config?v=1&url=${encodeURIComponent(e)}&key=${encodeURIComponent(t)}`}function oi({apiKey:e,baseUrl:t,onClose:n}){let{t:r}=l(),i=ai(t??window.location.origin,e);return(0,X.useEffect)(()=>{let e=e=>{e.key===`Escape`&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n]),(0,Y.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:n,children:(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-sm`,onClick:e=>e.stopPropagation(),children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:r(`settings.apiKeyQrTitle`)}),(0,Y.jsx)(`button`,{onClick:n,className:`text-bambu-gray hover:text-white transition-colors`,"aria-label":r(`common.close`),children:(0,Y.jsx)(Re,{className:`w-5 h-5`})})]}),(0,Y.jsxs)(`div`,{className:`p-6 flex flex-col items-center`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4 text-center`,children:r(`settings.apiKeyQrCaption`)}),(0,Y.jsx)(`div`,{className:`bg-white p-4 rounded-lg mb-4`,children:(0,Y.jsx)(ii,{value:i,size:256})}),(0,Y.jsxs)(`div`,{className:`flex items-start gap-2 text-xs text-amber-700 dark:text-amber-400 mb-4`,children:[(0,Y.jsx)(Ie,{className:`w-4 h-4 flex-shrink-0 mt-0.5`}),(0,Y.jsx)(`span`,{children:r(`settings.apiKeyQrWarning`)})]}),(0,Y.jsx)(K,{onClick:n,className:`w-full`,children:r(`common.close`)})]})]})})}var si=300,ci=2;function li({onSuccess:e}){let{t}=l(),n=u(),[i,a]=(0,X.useState)(``),[o,s]=(0,X.useState)(``),[c,p]=(0,X.useState)(null),[m,h]=(0,X.useState)(null);(0,X.useEffect)(()=>{let e=i.trim();if(e.lengths(e),si);return()=>clearTimeout(t)},[i]),(0,X.useEffect)(()=>{p(null),h(null)},[o]);let g=d({queryKey:[`ldap-search`,o],queryFn:()=>r.searchLDAPDirectory(o),enabled:o.length>=ci,staleTime:3e4}),_=f({mutationFn:e=>r.provisionLDAPUser(e),onSuccess:t=>{n.invalidateQueries({queryKey:[`users`]}),e(t)},onError:e=>{h(e.message||t(`users.modal.ldapErrorProvision`))}}),v=(0,X.useMemo)(()=>g.data?.find(e=>e.dn===c)??null,[g.data,c]),y=i.trim().length>0&&i.trim().length=ci,x=!!g.data&&g.data.length>0,S=!b&&!!g.data&&g.data.length===0&&o.length>=ci;return(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:t(`users.modal.ldapSearchLabel`)}),(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsx)(Ae,{className:`w-4 h-4 text-bambu-gray absolute left-3 top-1/2 -translate-y-1/2`}),(0,Y.jsx)(`input`,{type:`text`,value:i,onChange:e=>a(e.target.value),className:`w-full pl-9 pr-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:t(`users.modal.ldapSearchPlaceholder`),autoComplete:`off`})]}),y&&(0,Y.jsx)(`p`,{className:`mt-1 text-xs text-bambu-gray`,children:t(`users.modal.ldapMinChars`)})]}),(0,Y.jsxs)(`div`,{className:`min-h-[8rem] max-h-64 overflow-y-auto bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg`,children:[b&&(0,Y.jsxs)(`div`,{className:`flex items-center justify-center py-8 text-bambu-gray`,children:[(0,Y.jsx)(R,{className:`w-4 h-4 animate-spin mr-2`}),(0,Y.jsx)(`span`,{children:t(`users.modal.ldapSearching`)})]}),S&&(0,Y.jsx)(`div`,{className:`flex items-center justify-center py-8 text-bambu-gray text-sm`,children:t(`users.modal.ldapNoResults`)}),g.isError&&(0,Y.jsx)(`div`,{className:`px-3 py-4 text-sm text-red-700 dark:text-red-400`,children:g.error instanceof Error?g.error.message:t(`users.modal.ldapSearchError`)}),!b&&x&&(0,Y.jsx)(`ul`,{className:`divide-y divide-bambu-dark-tertiary`,children:g.data.map(e=>(0,Y.jsx)(ui,{result:e,selected:c===e.dn,onSelect:()=>p(e.dn)},e.dn))}),!b&&!g.data&&!g.isError&&(0,Y.jsx)(`div`,{className:`flex items-center justify-center py-8 text-bambu-gray text-sm`,children:t(`users.modal.ldapTypeToSearch`)})]}),v&&(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary/50 border border-bambu-green/20 rounded-lg p-3 space-y-1`,children:[(0,Y.jsxs)(`p`,{className:`text-sm text-white`,children:[(0,Y.jsxs)(`span`,{className:`text-bambu-gray`,children:[t(`users.modal.ldapSelectedLabel`),`: `]}),(0,Y.jsx)(`span`,{className:`font-medium`,children:v.username}),v.display_name&&(0,Y.jsxs)(`span`,{className:`text-bambu-gray`,children:[` — `,v.display_name]})]}),v.email&&(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:v.email}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray break-all`,children:v.dn})]}),m&&(0,Y.jsx)(`div`,{className:`bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30 rounded-lg p-3`,children:(0,Y.jsx)(`p`,{className:`text-sm text-red-700 dark:text-red-400`,children:m})}),(0,Y.jsx)(`div`,{className:`flex justify-end`,children:(0,Y.jsx)(K,{onClick:()=>{!v||v.already_provisioned||(h(null),_.mutate(v.username))},disabled:!v||v.already_provisioned||_.isPending,children:_.isPending?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(R,{className:`w-4 h-4 animate-spin`}),t(`users.modal.ldapProvisioning`)]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(wt,{className:`w-4 h-4`}),t(`users.modal.ldapProvision`)]})})})]})}function ui({result:e,selected:t,onSelect:n}){let{t:r}=l(),i=e.already_provisioned;return(0,Y.jsx)(`li`,{children:(0,Y.jsxs)(`button`,{type:`button`,onClick:n,disabled:i,className:`w-full text-left px-3 py-2 flex items-center gap-3 transition-colors ${i?`opacity-50 cursor-not-allowed`:t?`bg-bambu-green/10`:`hover:bg-bambu-dark-tertiary`}`,children:[(0,Y.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Y.jsxs)(`p`,{className:`text-sm text-white truncate`,children:[(0,Y.jsx)(`span`,{className:`font-medium`,children:e.username}),e.display_name&&(0,Y.jsxs)(`span`,{className:`text-bambu-gray`,children:[` — `,e.display_name]})]}),e.email&&(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray truncate`,children:e.email})]}),i&&(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 text-xs text-bambu-gray whitespace-nowrap`,children:[(0,Y.jsx)(q,{className:`w-3.5 h-3.5`}),r(`users.modal.ldapAlreadyProvisioned`)]})]})})}function di({formData:e,setFormData:t,groups:n,onClose:r,onCreate:i,isCreating:a,isCreateButtonDisabled:o,ldapEnabled:s=!1,onLdapProvisioned:c}){let{t:u}=l(),[d,f]=(0,X.useState)(`local`);(0,X.useEffect)(()=>{let e=e=>{e.key===`Escape`&&r()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[r]);let p=n=>{t({...e,group_ids:e.group_ids.includes(n)?e.group_ids.filter(e=>e!==n):[...e.group_ids,n]})};return(0,Y.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:r,children:(0,Y.jsxs)(G,{className:`w-full max-w-md`,onClick:e=>e.stopPropagation(),children:[(0,Y.jsx)(U,{children:(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(Ze,{className:`w-5 h-5 text-bambu-green`}),(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:u(`users.modal.createUser`)})]}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray ml-7`,children:u(`users.modal.advancedAuthSubtitle`)||`with Advanced Authentication`})]}),(0,Y.jsx)(K,{variant:`ghost`,size:`sm`,onClick:r,children:(0,Y.jsx)(Re,{className:`w-5 h-5`})})]})}),(0,Y.jsxs)(W,{children:[s&&(0,Y.jsxs)(`div`,{className:`mb-4 flex items-center gap-1 p-1 bg-bambu-dark-secondary rounded-lg`,role:`tablist`,"aria-label":u(`users.modal.tabsAriaLabel`),children:[(0,Y.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":d===`local`,onClick:()=>f(`local`),className:`flex-1 px-3 py-2 text-sm rounded-md transition-colors ${d===`local`?`bg-bambu-green/15 text-bambu-green`:`text-bambu-gray hover:text-white`}`,children:u(`users.modal.localTab`)}),(0,Y.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":d===`ldap`,onClick:()=>f(`ldap`),className:`flex-1 px-3 py-2 text-sm rounded-md transition-colors ${d===`ldap`?`bg-bambu-green/15 text-bambu-green`:`text-bambu-gray hover:text-white`}`,children:u(`users.modal.ldapTab`)})]}),d===`ldap`&&s?(0,Y.jsx)(li,{onSuccess:e=>{c?.(e)}}):(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:[u(`users.form.username`),` `,(0,Y.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:`*`})]}),(0,Y.jsx)(`input`,{type:`text`,value:e.username,onChange:n=>t({...e,username:n.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:u(`users.form.usernamePlaceholder`),autoComplete:`username`,required:!0})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:[u(`users.form.email`)||`Email`,` `,(0,Y.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:`*`})]}),(0,Y.jsx)(`input`,{type:`email`,value:e.email,onChange:n=>t({...e,email:n.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:u(`users.form.emailPlaceholder`)||`user@example.com`,required:!0})]}),(0,Y.jsx)(`div`,{className:`bg-bambu-dark-secondary/50 border border-bambu-green/20 rounded-lg p-3`,children:(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:u(`users.form.autoGeneratedPassword`)||`A secure password will be automatically generated and emailed to the user.`})}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:u(`users.form.groups`)}),(0,Y.jsxs)(`div`,{className:`space-y-2 max-h-40 overflow-y-auto p-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg`,children:[n.map(t=>(0,Y.jsxs)(`label`,{className:`flex items-center gap-3 px-2 py-1.5 rounded hover:bg-bambu-dark-tertiary cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:e.group_ids.includes(t.id),onChange:()=>p(t.id),className:`w-4 h-4 rounded border-bambu-gray text-bambu-green focus:ring-bambu-green focus:ring-offset-0 bg-bambu-dark`}),(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:t.name}),t.is_system&&(0,Y.jsxs)(`span`,{className:`text-xs text-yellow-700 dark:text-yellow-400`,children:[`(`,u(`users.system`),`)`]})]},t.id)),n.length===0&&(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:u(`users.noGroupsAvailable`)})]})]})]}),(0,Y.jsxs)(`div`,{className:`mt-6 flex justify-end gap-3`,children:[(0,Y.jsx)(K,{variant:`secondary`,onClick:r,children:u(`users.modal.cancel`)}),d===`local`&&(0,Y.jsx)(K,{onClick:i,disabled:o,children:a?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(R,{className:`w-4 h-4 animate-spin`}),u(`users.modal.creating`)]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(wt,{className:`w-4 h-4`}),u(`users.modal.createUser`)]})})]})]})]})})}function fi(){let{t:e}=l(),t=u(),{showToast:n}=ee(),[i,a]=(0,X.useState)(!1),[o,c]=(0,X.useState)(``),[p,m]=(0,X.useState)(`auto`),[h,g]=(0,X.useState)(!1),[_,v]=(0,X.useState)(!0),[y,b]=(0,X.useState)(!0),[x,S]=(0,X.useState)(`all`),[C,w]=(0,X.useState)(!1),[D,O]=(0,X.useState)(!1),[k,j]=(0,X.useState)(!1),[M,N]=(0,X.useState)(!1),[P,te]=(0,X.useState)(null),{data:F,isLoading:ne}=d({queryKey:[`spoolman-settings`],queryFn:r.getSpoolmanSettings}),{data:I,isLoading:re,refetch:ie}=d({queryKey:[`spoolman-status`],queryFn:r.getSpoolmanStatus,refetchInterval:3e4}),{data:L}=d({queryKey:[`printers`],queryFn:r.getPrinters});(0,X.useEffect)(()=>{F&&(a(F.spoolman_enabled===`true`),c(F.spoolman_url||``),m(F.spoolman_sync_mode||`auto`),g(F.spoolman_disable_weight_sync===`true`),v(F.spoolman_report_partial_usage!==`false`),b(F.auto_add_unknown_rfid!==`false`),w(!0))},[F]),(0,X.useEffect)(()=>{if(!(!C||!F)&&(F.spoolman_enabled===`true`!==i||(F.spoolman_url||``)!==o||(F.spoolman_sync_mode||`auto`)!==p||F.spoolman_disable_weight_sync===`true`!==h||F.spoolman_report_partial_usage!==`false`!==_||F.auto_add_unknown_rfid!==`false`!==y)){let e=setTimeout(()=>{z.mutate()},500);return()=>clearTimeout(e)}},[i,o,p,h,_,y,C]);let z=f({mutationFn:()=>r.updateSpoolmanSettings({spoolman_enabled:i?`true`:`false`,spoolman_url:o,spoolman_sync_mode:p,spoolman_disable_weight_sync:h?`true`:`false`,spoolman_report_partial_usage:_?`true`:`false`,auto_add_unknown_rfid:y?`true`:`false`}),onSuccess:()=>{t.invalidateQueries({queryKey:[`spoolman-settings`]}),t.invalidateQueries({queryKey:[`spoolman-status`]}),t.invalidateQueries({queryKey:[`spool-assignments`]}),t.invalidateQueries({queryKey:[`settings`]}),t.invalidateQueries({queryKey:[`spoolman-inventory-filaments`]}),n(e(`settings.toast.settingsSaved`))},onError:()=>{n(e(`settings.toast.saveFailed`),`error`)}}),oe=f({mutationFn:r.connectSpoolman,onSuccess:()=>{ie()},onError:()=>{n(e(`settings.toast.saveFailed`),`error`)}}),se=f({mutationFn:r.syncAllPrintersAms,onSuccess:t=>{n(e(`settings.spoolmanAmsSyncSuccess`,{synced:t.synced_count,skipped:0}),`success`)},onError:()=>{n(e(`settings.toast.saveFailed`),`error`)}}),B=f({mutationFn:e=>r.syncPrinterAms(e),onSuccess:t=>{n(e(`settings.spoolmanAmsSyncSuccess`,{synced:t.synced_count,skipped:0}),`success`)},onError:()=>{n(e(`settings.toast.saveFailed`),`error`)}}),ce=()=>{x===`all`?se.mutate():B.mutate(x)},le=f({mutationFn:r.syncWeightsFromAms,onSuccess:r=>{t.invalidateQueries({queryKey:[`spools`]}),t.invalidateQueries({queryKey:[`inventory-spools`]}),n(e(`settings.amsSyncSuccess`,{synced:r.synced,skipped:r.skipped}),`success`),j(!1)},onError:()=>{n(e(`settings.amsSyncError`),`error`),j(!1)}}),ue=f({mutationFn:r.syncSpoolmanAmsWeights,onSuccess:r=>{t.invalidateQueries({queryKey:[`spoolman-inventory-spools`]}),n(e(`settings.spoolmanAmsSyncSuccess`,{synced:r.synced,skipped:r.skipped}),`success`),N(!1)},onError:t=>{t instanceof s&&t.status===503?n(e(`settings.spoolmanAmsSyncErrorUnreachable`),`error`):t instanceof s&&t.status===400?n(e(`settings.spoolmanAmsSyncErrorNotConfigured`),`error`):n(e(`settings.spoolmanAmsSyncError`),`error`),N(!1)}}),de=f({mutationFn:e=>r.migrateSpoolmanTags(e),onSuccess:r=>{te(r),r.dry_run||(t.invalidateQueries({queryKey:[`spoolman-inventory-spools`]}),n(e(`settings.nativeTagsMoved`,{count:r.moved.length}),`success`))},onError:()=>{n(e(`settings.nativeTagsError`),`error`)}}),fe=se.isPending||B.isPending,V=x===`all`?se.data:B.data,pe=x===`all`?se.isSuccess:B.isSuccess;return ne?(0,Y.jsxs)(G,{id:`card-spoolman`,children:[(0,Y.jsx)(U,{children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(gt,{className:`w-5 h-5 text-bambu-green`}),(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`settings.filamentTracking`)})]})}),(0,Y.jsx)(W,{children:(0,Y.jsx)(`div`,{className:`flex justify-center py-8`,children:(0,Y.jsx)(R,{className:`w-6 h-6 text-bambu-green animate-spin`})})})]}):(0,Y.jsxs)(G,{id:`card-spoolman`,children:[(0,Y.jsx)(U,{children:(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(gt,{className:`w-5 h-5 text-bambu-green`}),(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`settings.filamentTracking`)})]}),z.isPending&&(0,Y.jsx)(R,{className:`w-4 h-4 text-bambu-green animate-spin`})]})}),(0,Y.jsxs)(W,{className:`space-y-4`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`settings.filamentTrackingDesc`)}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>a(!1),className:`p-3 rounded-lg border-2 text-left transition-colors ${i?`border-bambu-dark-tertiary bg-bambu-dark hover:border-bambu-gray/50`:`border-bambu-green bg-bambu-green/10`}`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 mb-1.5`,children:[(0,Y.jsx)(Ee,{className:`w-4 h-4 ${i?`text-bambu-gray`:`text-bambu-green`}`}),(0,Y.jsx)(`span`,{className:`text-sm font-medium ${i?`text-bambu-gray`:`text-white`}`,children:e(`settings.trackingModeBuiltIn`)})]}),(0,Y.jsx)(`p`,{className:`text-xs ${i?`text-bambu-gray/60`:`text-bambu-gray`}`,children:e(`settings.trackingModeBuiltInDesc`)}),!i&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-1 mt-2`,children:[(0,Y.jsx)(T,{className:`w-3 h-3 text-bambu-green`}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-green`,children:e(`common.enabled`)})]})]}),(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>a(!0),className:`p-3 rounded-lg border-2 text-left transition-colors ${i?`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary bg-bambu-dark hover:border-bambu-gray/50`}`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 mb-1.5`,children:[(0,Y.jsx)(Je,{className:`w-4 h-4 ${i?`text-bambu-green`:`text-bambu-gray`}`}),(0,Y.jsx)(`span`,{className:`text-sm font-medium ${i?`text-white`:`text-bambu-gray`}`,children:`Spoolman`})]}),(0,Y.jsx)(`p`,{className:`text-xs ${i?`text-bambu-gray`:`text-bambu-gray/60`}`,children:e(`settings.trackingModeSpoolmanDesc`)}),i&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-1 mt-2`,children:[(0,Y.jsx)(T,{className:`w-3 h-3 text-bambu-green`}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-green`,children:e(`common.enabled`)})]})]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between pt-2 border-t border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{className:`pr-4`,children:[(0,Y.jsx)(`p`,{className:`text-white`,children:e(`settings.autoAddUnknownRfid`)}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`settings.autoAddUnknownRfidDesc`)})]}),(0,Y.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:y,onChange:e=>b(e.target.checked),className:`sr-only peer`}),(0,Y.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),!i&&(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsx)(`div`,{className:`p-3 bg-bambu-green/5 border border-bambu-green/20 rounded-lg`,children:(0,Y.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Y.jsx)(A,{className:`w-4 h-4 text-bambu-green flex-shrink-0 mt-0.5`}),(0,Y.jsx)(`div`,{className:`text-xs text-bambu-gray`,children:(0,Y.jsxs)(`ul`,{className:`list-disc list-inside space-y-0.5`,children:[(0,Y.jsx)(`li`,{children:e(`settings.builtInFeatureRfid`)}),(0,Y.jsx)(`li`,{children:e(`settings.builtInFeatureUsage`)}),(0,Y.jsx)(`li`,{children:e(`settings.builtInFeatureCatalog`)}),(0,Y.jsx)(`li`,{children:e(`settings.builtInFeatureThirdParty`)})]})})]})}),(0,Y.jsxs)(K,{variant:`secondary`,size:`sm`,onClick:()=>j(!0),disabled:le.isPending,children:[le.isPending?(0,Y.jsx)(R,{className:`w-4 h-4 mr-2 animate-spin`}):(0,Y.jsx)(at,{className:`w-4 h-4 mr-2`}),e(`settings.amsSyncButton`)]})]}),i&&(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[(0,Y.jsx)(`div`,{className:`p-3 bg-blue-50 dark:bg-blue-500/10 border border-blue-300 dark:border-blue-500/30 rounded-lg`,children:(0,Y.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Y.jsx)(A,{className:`w-4 h-4 text-blue-600 dark:text-blue-400 flex-shrink-0 mt-0.5`}),(0,Y.jsxs)(`div`,{className:`text-xs text-blue-700 dark:text-blue-300`,children:[(0,Y.jsx)(`p`,{className:`font-medium mb-1`,children:e(`settings.howSyncWorks`)}),(0,Y.jsxs)(`ul`,{className:`list-disc list-inside space-y-0.5 text-blue-700/90 dark:text-blue-300/80`,children:[(0,Y.jsx)(`li`,{children:e(`settings.syncInfoRfidOnly`)}),(0,Y.jsx)(`li`,{children:e(`settings.syncInfoAutoCreate`)}),(0,Y.jsx)(`li`,{children:e(`settings.syncInfoThirdPartySkipped`)})]}),(0,Y.jsx)(`p`,{className:`font-medium mt-2 mb-1`,children:e(`settings.linkingExistingSpools`)}),(0,Y.jsx)(`p`,{className:`text-blue-700/90 dark:text-blue-300/80`,children:e(`settings.linkingExistingSpoolsDesc`)})]})]})}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:e(`settings.spoolmanUrl`)}),(0,Y.jsx)(`input`,{type:`text`,placeholder:`http://192.168.1.100:7912`,value:o,onChange:e=>c(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray/50 focus:border-bambu-green focus:outline-none`}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`settings.spoolmanUrlHint`)})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:e(`settings.syncMode`)}),(0,Y.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 focus:border-bambu-green focus:outline-none`,children:[(0,Y.jsx)(`option`,{value:`auto`,children:e(`settings.syncModeAuto`)}),(0,Y.jsx)(`option`,{value:`manual`,children:e(`settings.syncModeManual`)})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(p===`auto`?`settings.syncModeAutoDesc`:`settings.syncModeManualDesc`)})]}),p===`auto`&&(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-white`,children:e(`spoolman.disableWeightSync`)}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`spoolman.disableWeightSyncDesc`)})]}),(0,Y.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:h,onChange:e=>g(e.target.checked),className:`sr-only peer`}),(0,Y.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),h&&(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-white`,children:e(`spoolman.reportPartialUsage`)}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`spoolman.reportPartialUsageDesc`)})]}),(0,Y.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:_,onChange:e=>v(e.target.checked),className:`sr-only peer`}),(0,Y.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,Y.jsxs)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[e(`settings.status`),`:`]}),re?(0,Y.jsx)(R,{className:`w-4 h-4 text-bambu-gray animate-spin`}):I?.connected?(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 text-sm text-green-500`,children:[(0,Y.jsx)(T,{className:`w-4 h-4`}),e(`settings.spoolmanConnected`)]}):(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 text-sm text-red-500`,children:[(0,Y.jsx)(Re,{className:`w-4 h-4`}),e(`settings.spoolmanDisconnected`)]})]}),(0,Y.jsx)(`div`,{className:`flex gap-2`,children:!I?.connected&&(0,Y.jsxs)(K,{size:`sm`,onClick:()=>oe.mutate(),disabled:oe.isPending||!o,children:[oe.isPending?(0,Y.jsx)(R,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(ae,{className:`w-4 h-4`}),e(`settings.connect`)]})})]}),oe.isError&&(0,Y.jsx)(`div`,{className:`mb-3 p-2 bg-red-100 dark:bg-red-500/20 border border-red-300 dark:border-red-500/50 rounded text-sm text-red-700 dark:text-red-400`,children:oe.error.message}),I?.connected&&(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:e(`settings.syncAmsData`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:e(`settings.syncAmsDataDesc`)})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsxs)(`div`,{className:`relative flex-1`,children:[(0,Y.jsxs)(`select`,{value:x,onChange:e=>S(e.target.value===`all`?`all`:Number(e.target.value)),className:`w-full px-3 py-2 pr-8 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:[(0,Y.jsx)(`option`,{value:`all`,children:e(`settings.allPrinters`)}),L?.map(e=>(0,Y.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,Y.jsx)(E,{className:`absolute right-2 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]}),(0,Y.jsxs)(K,{variant:`secondary`,size:`sm`,onClick:ce,disabled:fe,children:[fe?(0,Y.jsx)(R,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(at,{className:`w-4 h-4`}),e(`spoolman.sync`)]})]})]}),I?.connected&&(0,Y.jsx)(`div`,{className:`mt-4 pt-4 border-t border-bambu-dark-tertiary`,children:(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:e(`settings.spoolmanAmsSyncButton`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:e(`settings.spoolmanAmsSyncMessage`)})]}),(0,Y.jsxs)(K,{variant:`secondary`,size:`sm`,onClick:()=>N(!0),disabled:ue.isPending,children:[ue.isPending?(0,Y.jsx)(R,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(at,{className:`w-4 h-4`}),ue.isPending?e(`settings.spoolmanAmsSyncing`):e(`settings.spoolmanAmsSyncButton`)]})]})}),I?.connected&&I.native_tags&&(0,Y.jsxs)(`div`,{className:`mt-4 pt-4 border-t border-bambu-dark-tertiary space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`pr-4`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:e(`settings.nativeTagsTitle`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:e(`settings.nativeTagsDesc`)})]}),(0,Y.jsxs)(K,{variant:`secondary`,size:`sm`,onClick:()=>de.mutate(!0),disabled:de.isPending,className:`flex-shrink-0 whitespace-nowrap`,children:[de.isPending&&de.variables?(0,Y.jsx)(R,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(Tn,{className:`w-4 h-4`}),e(`settings.nativeTagsCheck`)]})]}),P&&(0,Y.jsxs)(`div`,{className:`p-2 bg-bambu-dark border border-bambu-dark-tertiary rounded text-sm space-y-2`,children:[(0,Y.jsxs)(`dl`,{className:`grid grid-cols-[1fr_auto] gap-x-4 gap-y-0.5 text-xs`,children:[(0,Y.jsx)(`dt`,{className:`text-bambu-gray`,children:e(`settings.nativeTagsToMove`)}),(0,Y.jsx)(`dd`,{className:`text-white text-right`,children:P.dry_run?P.moved.length:0}),(0,Y.jsx)(`dt`,{className:`text-bambu-gray`,children:e(`settings.nativeTagsAlready`)}),(0,Y.jsx)(`dd`,{className:`text-white text-right`,children:P.already+(P.dry_run?0:P.moved.length)}),(0,Y.jsx)(`dt`,{className:`text-bambu-gray`,children:e(`settings.nativeTagsSlotIds`)}),(0,Y.jsx)(`dd`,{className:`text-white text-right`,children:P.slot_ids}),(0,Y.jsx)(`dt`,{className:`text-bambu-gray`,children:e(`settings.nativeTagsConflicts`)}),(0,Y.jsx)(`dd`,{className:`text-white text-right`,children:P.conflicts.length})]}),P.conflicts.length>0&&(0,Y.jsx)(`ul`,{className:`p-2 bg-amber-50 dark:bg-amber-500/10 border border-amber-300 dark:border-amber-500/30 rounded text-xs text-amber-700 dark:text-amber-400 space-y-0.5`,children:P.conflicts.map(t=>(0,Y.jsxs)(`li`,{className:`flex items-start gap-1.5`,children:[(0,Y.jsx)(Ie,{className:`w-3.5 h-3.5 flex-shrink-0 mt-px`}),(0,Y.jsx)(`span`,{children:t.holder>0?e(`settings.nativeTagsConflictSpool`,{spool:t.spool_id,tag:t.tag,holder:t.holder}):e(`settings.nativeTagsConflictElsewhere`,{spool:t.spool_id,tag:t.tag})})]},`${t.spool_id}-${t.tag}`))}),P.dry_run&&P.moved.length>0?(0,Y.jsxs)(K,{size:`sm`,onClick:()=>de.mutate(!1),disabled:de.isPending,children:[de.isPending&&!de.variables?(0,Y.jsx)(R,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(Tn,{className:`w-4 h-4`}),e(`settings.nativeTagsMove`)]}):P.conflicts.length===0&&(0,Y.jsxs)(`p`,{className:`flex items-center gap-1 text-xs text-green-600 dark:text-green-400`,children:[(0,Y.jsx)(T,{className:`w-3.5 h-3.5`}),e(`settings.nativeTagsNothing`)]})]})]}),pe&&V&&(0,Y.jsxs)(`div`,{className:`mt-3 space-y-2`,children:[(0,Y.jsx)(`div`,{className:`p-2 rounded text-sm ${V.success?`bg-green-100 dark:bg-green-500/20 border border-green-300 dark:border-green-500/50 text-green-700 dark:text-green-400`:`bg-yellow-100 dark:bg-yellow-500/20 border border-yellow-300 dark:border-yellow-500/50 text-yellow-700 dark:text-yellow-400`}`,children:V.success?`Synced ${V.synced_count} spool${V.synced_count===1?``:`s`} successfully`:`Synced ${V.synced_count} spool${V.synced_count===1?``:`s`} with ${V.errors.length} error${V.errors.length===1?``:`s`}`}),V.skipped_count>0&&(0,Y.jsxs)(`div`,{className:`p-2 bg-amber-50 dark:bg-amber-500/10 border border-amber-300 dark:border-amber-500/30 rounded text-sm`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between text-amber-700 dark:text-amber-400 mb-1`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(Ie,{className:`w-3.5 h-3.5`}),(0,Y.jsxs)(`span`,{className:`font-medium`,children:[V.skipped_count,` spool`,V.skipped_count===1?``:`s`,` skipped`]})]}),V.skipped_count>5&&(0,Y.jsx)(`button`,{onClick:()=>O(!D),className:`text-xs text-amber-700 dark:text-amber-400 hover:text-amber-800 dark:hover:text-amber-300 underline`,children:D?`Show less`:`Show all`})]}),(0,Y.jsxs)(`ul`,{className:`text-xs text-amber-700/90 dark:text-amber-300/80 space-y-0.5`,children:[(D?V.skipped:V.skipped.slice(0,5)).map((e,t)=>(0,Y.jsxs)(`li`,{className:`flex items-center gap-2`,children:[e.color&&(0,Y.jsx)(`span`,{className:`w-3 h-3 rounded-full border border-black/20`,style:{backgroundColor:`#${e.color}`}}),(0,Y.jsx)(`span`,{children:e.location}),(0,Y.jsxs)(`span`,{className:`text-amber-700/70 dark:text-amber-300/60`,children:[`- `,e.reason]})]},t)),!D&&V.skipped_count>5&&(0,Y.jsxs)(`li`,{className:`text-amber-700/70 dark:text-amber-300/60 italic`,children:[`...and `,V.skipped_count-5,` more`]})]})]}),V.errors.length>0&&(0,Y.jsxs)(`div`,{className:`p-2 bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30 rounded text-sm`,children:[(0,Y.jsx)(`div`,{className:`text-red-700 dark:text-red-400 font-medium mb-1`,children:`Errors:`}),(0,Y.jsx)(`ul`,{className:`text-xs text-red-700/90 dark:text-red-300/80 space-y-0.5`,children:V.errors.map((e,t)=>(0,Y.jsx)(`li`,{children:e},t))})]})]})]})]})]}),k&&(0,Y.jsx)(Tt,{title:e(`settings.amsSyncTitle`),message:e(`settings.amsSyncMessage`),confirmText:e(`settings.amsSyncButton`),variant:`warning`,isLoading:le.isPending,loadingText:e(`settings.amsSyncing`),onConfirm:()=>le.mutate(),onCancel:()=>j(!1)}),M&&(0,Y.jsx)(Tt,{title:e(`settings.spoolmanAmsSyncTitle`),message:e(`settings.spoolmanAmsSyncMessage`),confirmText:e(`settings.spoolmanAmsSyncButton`),variant:`warning`,isLoading:ue.isPending,loadingText:e(`settings.spoolmanAmsSyncing`),onConfirm:()=>ue.mutate(),onCancel:()=>N(!1)})]})}function pi(){let{t:e}=l(),{showToast:t}=ee(),[n,i]=(0,X.useState)([]),[a,o]=(0,X.useState)(!0),[s,c]=(0,X.useState)(``),u=(0,X.useRef)(null),[d,f]=(0,X.useState)(!1),[p,m]=(0,X.useState)(null),[h,g]=(0,X.useState)(``),[_,v]=(0,X.useState)(``),[y,b]=(0,X.useState)(!1),[x,S]=(0,X.useState)(new Set),[C,w]=(0,X.useState)(!1),[E,D]=(0,X.useState)(null),[O,k]=(0,X.useState)(!1),A=(0,X.useCallback)(async()=>{try{i(await r.getSpoolCatalog())}catch(n){console.error(`SpoolCatalogSettings.loadCatalog failed:`,n),t(e(`settings.catalog.loadFailed`),`error`)}finally{o(!1)}},[t,e]);(0,X.useEffect)(()=>{A()},[A]);let j=n.filter(e=>e.name.toLowerCase().includes(s.toLowerCase())),M=async()=>{if(!h.trim()||!_){t(e(`settings.catalog.nameWeightRequired`),`error`);return}b(!0);try{let n=await r.addCatalogEntry({name:h.trim(),weight:parseInt(_)});i(e=>[...e,n].sort((e,t)=>e.name.localeCompare(t.name))),f(!1),g(``),v(``),t(e(`settings.catalog.entryAdded`),`success`)}catch(n){console.error(`SpoolCatalogSettings.handleAdd failed:`,n),t(e(`settings.catalog.addFailed`),`error`)}finally{b(!1)}},N=e=>{m(e.id),g(e.name),v(e.weight.toString())},P=()=>{m(null),g(``),v(``)},te=async n=>{if(!h.trim()||!_){t(e(`settings.catalog.nameWeightRequired`),`error`);return}b(!0);try{let a=await r.updateCatalogEntry(n,{name:h.trim(),weight:parseInt(_)});i(e=>e.map(e=>e.id===n?a:e).sort((e,t)=>e.name.localeCompare(t.name))),m(null),g(``),v(``),t(e(`settings.catalog.entryUpdated`),`success`)}catch(n){console.error(`SpoolCatalogSettings.handleUpdate failed:`,n),t(e(`settings.catalog.updateFailed`),`error`)}finally{b(!1)}},F=async()=>{if(E)try{await r.deleteCatalogEntry(E.id),i(e=>e.filter(e=>e.id!==E.id)),t(e(`settings.catalog.entryDeleted`),`success`)}catch(n){console.error(`SpoolCatalogSettings.handleDelete failed:`,n),t(e(`settings.catalog.deleteFailed`),`error`)}finally{D(null)}},ne=async()=>{k(!1),o(!0);try{await r.resetSpoolCatalog(),await A(),t(e(`settings.catalog.resetSuccess`),`success`)}catch(n){console.error(`SpoolCatalogSettings.handleReset failed:`,n),t(e(`settings.catalog.resetFailed`),`error`),o(!1)}},I=e=>{S(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};return(0,Y.jsxs)(G,{id:`card-spool-catalog`,children:[(0,Y.jsxs)(U,{children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,Y.jsx)(gt,{className:`w-5 h-5 text-bambu-gray`}),(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`settings.catalog.spoolCatalog`)}),(0,Y.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[`(`,n.length,`)`]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,Y.jsxs)(`button`,{onClick:()=>{let r=n.map(({name:e,weight:t})=>({name:e,weight:t})),i=new Blob([JSON.stringify(r,null,2)],{type:`application/json`}),a=URL.createObjectURL(i),o=document.createElement(`a`);o.href=a,o.download=`spool-catalog.json`,document.body.appendChild(o),o.click(),document.body.removeChild(o),URL.revokeObjectURL(a),t(e(`settings.catalog.exported`,{count:n.length}),`success`)},className:`px-3 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white transition-colors flex items-center gap-1.5`,title:e(`settings.catalog.exportTooltip`),children:[(0,Y.jsx)(sn,{className:`w-4 h-4`}),(0,Y.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.export`)})]}),(0,Y.jsxs)(`button`,{onClick:()=>u.current?.click(),className:`px-3 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white transition-colors flex items-center gap-1.5`,title:e(`settings.catalog.importTooltip`),children:[(0,Y.jsx)(Wt,{className:`w-4 h-4`}),(0,Y.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.import`)})]}),(0,Y.jsx)(`input`,{ref:u,type:`file`,accept:`.json`,className:`hidden`,onChange:async a=>{let o=a.target.files?.[0];if(o){try{let a=await o.text(),s=JSON.parse(a);if(!Array.isArray(s))throw Error(`Invalid format`);let c=0,l=0;for(let e of s){if(!e.name||typeof e.weight!=`number`){l++;continue}if(n.some(t=>t.name.toLowerCase()===e.name.toLowerCase())){l++;continue}try{let t=await r.addCatalogEntry({name:e.name,weight:e.weight});i(e=>[...e,t].sort((e,t)=>e.name.localeCompare(t.name))),c++}catch(e){console.error(`SpoolCatalogSettings import item failed:`,e),l++}}t(e(`settings.catalog.imported`,{added:c,skipped:l}),`success`)}catch(n){console.error(`SpoolCatalogSettings.handleImport failed:`,n),t(e(`settings.catalog.importFailed`),`error`)}u.current&&(u.current.value=``)}}}),(0,Y.jsxs)(`button`,{onClick:()=>k(!0),className:`px-3 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white transition-colors flex items-center gap-1.5`,title:e(`settings.catalog.resetTooltip`),children:[(0,Y.jsx)(nt,{className:`w-4 h-4`}),(0,Y.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.reset`)})]}),(0,Y.jsxs)(`button`,{onClick:()=>f(!0),className:`px-3 py-1.5 text-sm bg-bambu-green text-white rounded-lg hover:bg-bambu-green/80 transition-colors flex items-center gap-1.5`,children:[(0,Y.jsx)(wt,{className:`w-4 h-4`}),(0,Y.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.add`)})]})]}),x.size>0&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 mt-2 px-3 py-2 bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30 rounded-lg`,children:[(0,Y.jsx)(`span`,{className:`text-sm text-red-700 dark:text-red-400`,children:e(`settings.catalog.selectedCount`,{count:x.size})}),(0,Y.jsxs)(`button`,{onClick:()=>w(!0),className:`ml-auto px-3 py-1.5 text-sm bg-red-500 text-white rounded-lg hover:bg-red-600 transition-colors flex items-center gap-1.5`,children:[(0,Y.jsx)(qe,{className:`w-4 h-4`}),e(`settings.catalog.deleteSelected`)]}),(0,Y.jsx)(`button`,{onClick:()=>S(new Set),className:`px-3 py-1.5 text-sm text-bambu-gray hover:text-white transition-colors`,children:e(`common.cancel`)})]})]}),(0,Y.jsxs)(W,{className:`space-y-4`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`settings.catalog.spoolCatalogDescription`)}),(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsx)(Ae,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,Y.jsx)(`input`,{type:`text`,className:`w-full pl-10 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`,placeholder:e(`settings.catalog.searchCatalog`),value:s,onChange:e=>c(e.target.value)})]}),d&&(0,Y.jsxs)(`div`,{className:`p-4 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,Y.jsx)(`h3`,{className:`text-sm font-medium text-white mb-3`,children:e(`settings.catalog.addNewEntry`)}),(0,Y.jsxs)(`div`,{className:`flex gap-2 items-center`,children:[(0,Y.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,Y.jsx)(`input`,{type:`text`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`,placeholder:e(`settings.catalog.namePlaceholder`),value:h,onChange:e=>g(e.target.value)})}),(0,Y.jsx)(`input`,{type:`number`,className:`w-20 px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white text-center focus:border-bambu-green focus:outline-none`,placeholder:`g`,value:_,onChange:e=>v(e.target.value)}),(0,Y.jsx)(`span`,{className:`text-bambu-gray shrink-0`,children:`g`}),(0,Y.jsxs)(`button`,{onClick:M,disabled:y,className:`px-3 py-2 bg-bambu-green text-white rounded-lg hover:bg-bambu-green/80 flex items-center gap-1 shrink-0`,children:[y?(0,Y.jsx)(R,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(T,{className:`w-4 h-4`}),e(`common.add`)]}),(0,Y.jsx)(`button`,{onClick:()=>{f(!1),g(``),v(``)},className:`p-2 rounded-lg text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary`,children:(0,Y.jsx)(Re,{className:`w-4 h-4`})})]})]}),a?(0,Y.jsxs)(`div`,{className:`flex items-center justify-center py-8 text-bambu-gray`,children:[(0,Y.jsx)(R,{className:`w-5 h-5 animate-spin mr-2`}),e(`common.loading`)]}):(0,Y.jsx)(`div`,{className:`max-h-[600px] overflow-y-auto border border-bambu-dark-tertiary rounded-lg`,children:(0,Y.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,Y.jsx)(`thead`,{className:`bg-bambu-dark sticky top-0`,children:(0,Y.jsxs)(`tr`,{children:[(0,Y.jsx)(`th`,{className:`px-2 py-2 w-10`,children:(0,Y.jsx)(`input`,{type:`checkbox`,checked:j.length>0&&x.size===j.length,onChange:()=>{x.size===j.length?S(new Set):S(new Set(j.map(e=>e.id)))},className:`w-4 h-4 accent-bambu-green cursor-pointer`})}),(0,Y.jsx)(`th`,{className:`px-4 py-2 text-left text-bambu-gray font-medium`,children:e(`common.name`)}),(0,Y.jsx)(`th`,{className:`px-4 py-2 text-right text-bambu-gray font-medium w-24`,children:e(`settings.catalog.weight`)}),(0,Y.jsx)(`th`,{className:`px-4 py-2 text-center text-bambu-gray font-medium w-20`,children:e(`settings.catalog.type`)}),(0,Y.jsx)(`th`,{className:`px-4 py-2 w-24`})]})}),(0,Y.jsx)(`tbody`,{children:j.length===0?(0,Y.jsx)(`tr`,{children:(0,Y.jsx)(`td`,{colSpan:5,className:`px-4 py-8 text-center text-bambu-gray`,children:e(s?`settings.catalog.noMatch`:`settings.catalog.empty`)})}):j.map(t=>(0,Y.jsx)(`tr`,{className:`border-t border-bambu-dark-tertiary hover:bg-bambu-dark ${x.has(t.id)?`bg-bambu-dark`:``}`,children:p===t.id?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`td`,{className:`px-2 py-2`,children:(0,Y.jsx)(`input`,{type:`checkbox`,checked:x.has(t.id),onChange:()=>I(t.id),className:`w-4 h-4 accent-bambu-green cursor-pointer`})}),(0,Y.jsx)(`td`,{className:`px-4 py-2`,children:(0,Y.jsx)(`input`,{type:`text`,className:`w-full px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white focus:border-bambu-green focus:outline-none`,value:h,onChange:e=>g(e.target.value)})}),(0,Y.jsx)(`td`,{className:`px-4 py-2`,children:(0,Y.jsx)(`input`,{type:`number`,className:`w-full px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-right focus:border-bambu-green focus:outline-none`,value:_,onChange:e=>v(e.target.value)})}),(0,Y.jsx)(`td`,{className:`px-4 py-2 text-center`,children:(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:`-`})}),(0,Y.jsx)(`td`,{className:`px-4 py-2`,children:(0,Y.jsxs)(`div`,{className:`flex justify-end gap-1`,children:[(0,Y.jsx)(`button`,{onClick:()=>te(t.id),disabled:y,className:`p-1.5 rounded hover:bg-green-500/20 text-green-500`,children:y?(0,Y.jsx)(R,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(T,{className:`w-4 h-4`})}),(0,Y.jsx)(`button`,{onClick:P,className:`p-1.5 rounded hover:bg-bambu-dark-tertiary text-bambu-gray`,children:(0,Y.jsx)(Re,{className:`w-4 h-4`})})]})})]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`td`,{className:`px-2 py-2`,children:(0,Y.jsx)(`input`,{type:`checkbox`,checked:x.has(t.id),onChange:()=>I(t.id),className:`w-4 h-4 accent-bambu-green cursor-pointer`})}),(0,Y.jsx)(`td`,{className:`px-4 py-2 text-white`,children:t.name}),(0,Y.jsxs)(`td`,{className:`px-4 py-2 text-right font-mono text-white`,children:[t.weight,`g`]}),(0,Y.jsx)(`td`,{className:`px-4 py-2 text-center`,children:t.is_default?(0,Y.jsx)(`span`,{className:`text-xs px-2 py-0.5 rounded bg-bambu-dark-tertiary text-bambu-gray`,children:e(`settings.catalog.default`)}):(0,Y.jsx)(`span`,{className:`text-xs px-2 py-0.5 rounded bg-bambu-green/20 text-bambu-green`,children:e(`settings.catalog.custom`)})}),(0,Y.jsx)(`td`,{className:`px-4 py-2`,children:(0,Y.jsxs)(`div`,{className:`flex justify-end gap-1`,children:[(0,Y.jsx)(`button`,{onClick:()=>N(t),className:`p-1.5 rounded hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white`,children:(0,Y.jsx)(Ke,{className:`w-4 h-4`})}),(0,Y.jsx)(`button`,{onClick:()=>D(t),className:`p-1.5 rounded bg-red-500/10 hover:bg-red-500/20 text-red-500`,children:(0,Y.jsx)(qe,{className:`w-4 h-4`})})]})})]})},t.id))})]})})]}),E&&(0,Y.jsx)(Tt,{title:e(`settings.catalog.deleteEntry`),message:e(`settings.catalog.deleteConfirm`,{name:E.name}),confirmText:e(`common.delete`),variant:`danger`,onConfirm:F,onCancel:()=>D(null)}),C&&(0,Y.jsx)(Tt,{title:e(`settings.catalog.deleteSelected`),message:e(`settings.catalog.bulkDeleteConfirm`,{count:x.size}),confirmText:e(`common.delete`),variant:`danger`,onConfirm:async()=>{if(w(!1),x.size!==0)try{let n=await r.bulkDeleteCatalogEntries([...x]);i(e=>e.filter(e=>!x.has(e.id))),S(new Set),t(e(`settings.catalog.bulkDeleted`,{count:n.deleted}),`success`)}catch(n){console.error(`SpoolCatalogSettings.handleBulkDelete failed:`,n),t(e(`settings.catalog.bulkDeleteFailed`),`error`)}},onCancel:()=>w(!1)}),O&&(0,Y.jsx)(Tt,{title:e(`settings.catalog.resetCatalog`),message:e(`settings.catalog.resetConfirm`),confirmText:e(`common.reset`),variant:`danger`,onConfirm:ne,onCancel:()=>k(!1)})]})}function mi(){let{t:e}=l(),{showToast:t}=ee(),[n,i]=(0,X.useState)([]),[a,s]=(0,X.useState)(!0),[c,u]=(0,X.useState)(``),[d,f]=(0,X.useState)(``),p=(0,X.useRef)(null),[m,h]=(0,X.useState)(!1),[g,_]=(0,X.useState)(null),[v,y]=(0,X.useState)(``),[b,x]=(0,X.useState)(``),[S,C]=(0,X.useState)(`#FFFFFF`),[w,E]=(0,X.useState)(``),[D,O]=(0,X.useState)(``),[k,A]=(0,X.useState)(``),[j,M]=(0,X.useState)(!1),[N,P]=(0,X.useState)(new Set),[te,F]=(0,X.useState)(!1),[ne,I]=(0,X.useState)(!1),[re,ie]=(0,X.useState)(null),[L,ae]=(0,X.useState)(null),[z,oe]=(0,X.useState)(!1),se=(0,X.useCallback)(async()=>{try{i(await r.getColorCatalog())}catch{t(e(`settings.colorCatalog.loadFailed`),`error`)}finally{s(!1)}},[t,e]);(0,X.useEffect)(()=>{se()},[se]);let B=[...new Set(n.map(e=>e.manufacturer))].sort(),ce=n.filter(e=>{let t=c===``||e.manufacturer.toLowerCase().includes(c.toLowerCase())||e.color_name.toLowerCase().includes(c.toLowerCase())||(e.material?.toLowerCase().includes(c.toLowerCase())??!1),n=d===``||e.manufacturer===d;return t&&n}),le=()=>{y(``),x(``),C(`#FFFFFF`),E(``),O(``),A(``)},ue=async()=>{if(!v.trim()||!b.trim()||!S){t(e(`settings.colorCatalog.fieldsRequired`),`error`);return}M(!0);try{let n=await r.addColorEntry({manufacturer:v.trim(),color_name:b.trim(),hex_color:S,material:w.trim()||null,extra_colors:D.trim()||null,effect_type:k.trim()||null});i(e=>[...e,n].sort((e,t)=>e.manufacturer.localeCompare(t.manufacturer)||(e.material||``).localeCompare(t.material||``)||e.color_name.localeCompare(t.color_name))),h(!1),le(),t(e(`settings.colorCatalog.colorAdded`),`success`)}catch{t(e(`settings.colorCatalog.addFailed`),`error`)}finally{M(!1)}},de=e=>{_(e.id),y(e.manufacturer),x(e.color_name),C(e.hex_color),E(e.material||``),O(e.extra_colors||``),A(e.effect_type||``)},fe=()=>{_(null),le()},V=async n=>{if(!v.trim()||!b.trim()||!S){t(e(`settings.colorCatalog.fieldsRequired`),`error`);return}M(!0);try{let a=await r.updateColorEntry(n,{manufacturer:v.trim(),color_name:b.trim(),hex_color:S,material:w.trim()||null,extra_colors:D.trim()||null,effect_type:k.trim()||null});i(e=>e.map(e=>e.id===n?a:e).sort((e,t)=>e.manufacturer.localeCompare(t.manufacturer)||(e.material||``).localeCompare(t.material||``)||e.color_name.localeCompare(t.color_name))),_(null),le(),t(e(`settings.colorCatalog.colorUpdated`),`success`)}catch{t(e(`settings.colorCatalog.updateFailed`),`error`)}finally{M(!1)}},pe=async()=>{if(L)try{await r.deleteColorEntry(L.id),i(e=>e.filter(e=>e.id!==L.id)),t(e(`settings.colorCatalog.colorDeleted`),`success`)}catch{t(e(`settings.colorCatalog.deleteFailed`),`error`)}finally{ae(null)}},me=async()=>{oe(!1),s(!0);try{await r.resetColorCatalog(),await se(),t(e(`settings.colorCatalog.resetSuccess`),`success`)}catch{t(e(`settings.colorCatalog.resetFailed`),`error`),s(!1)}},he=async()=>{I(!0),ie(null);try{let n={},r=o();r&&(n.Authorization=`Bearer ${r}`);let i=await fetch(`/api/v1/inventory/colors/sync`,{method:`POST`,headers:n});if(!i.ok)throw Error(`Failed to start sync`);let a=i.body?.getReader();if(!a)throw Error(`No response body`);let s=new TextDecoder,c=``;for(;;){let{done:n,value:r}=await a.read();if(n)break;c+=s.decode(r,{stream:!0});let i=c.split(` +import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,b as i,f as a,l as o,t as s,v as c,w as l}from"./client-DnySrlFv.js";import{n as u}from"./QueryClientProvider-Ce8_sN3w.js";import{t as d}from"./useQuery-BBCjCezC.js";import{t as f}from"./useMutation-B-Tr2hIP.js";import{t as p}from"./useQueries-Be6PMvSC.js";import{t as m}from"./createLucideIcon-DvBYJlWL.js";import{a as h,i as g,l as _,n as v,o as y,r as b,t as x,u as S}from"./haSensorDisplay-lPbcOxD8.js";import{t as C}from"./briefcase-Dau7xqMY.js";import{t as w}from"./calendar-BLKPnWqV.js";import{t as T}from"./check-Ck0cMLU4.js";import{a as E,i as D,n as O,r as k,t as A}from"./info-ROUoQhJR.js";import{n as ee,r as j}from"./ToastContext-BRX0SW3C.js";import{t as M}from"./cog-Dol1I0kq.js";import{t as N}from"./copy-Cu_0GKCU.js";import{t as P}from"./cpu-BKWEtc8k.js";import{t as te}from"./dollar-sign-Cj_Yhud4.js";import{t as F}from"./eye-off-6CkaxYwP.js";import{t as ne}from"./gauge-D21zgWMb.js";import{t as I}from"./grip-vertical-C_1RDxRw.js";import{t as re}from"./hard-drive-CgXAHN37.js";import{t as ie}from"./history-B4lOLL01.js";import{t as L}from"./layout-grid-DkD3u6wa.js";import{t as ae}from"./link-2-MI-QCMh8.js";import{t as R}from"./loader-circle-BEmFtawu.js";import{t as z}from"./lock-MLqgWH4Q.js";import{_ as oe,a as se,c as B,d as ce,f as le,g as ue,h as de,i as fe,l as V,m as pe,n as me,o as he,p as ge,r as _e,s as ve,t as ye,u as be,v as H}from"./locationSensorDefaults-DcLWzMwe.js";import{c as xe,l as Se,o as Ce,t as we,u as Te}from"./CopyButton-C5In5weo.js";import{t as Ee}from"./package-BGUevlqS.js";import{t as De}from"./play-DIDYtk2S.js";import{t as Oe}from"./qr-code-CCCo2-Br.js";import{t as ke}from"./scale-CD6XdXUk.js";import{t as Ae}from"./search-0n0CBc74.js";import{t as je}from"./settings-2-Cvn837lh.js";import{t as Me}from"./shield-bODVqOJd.js";import{t as Ne}from"./skip-forward-BsuMfFkw.js";import{t as Pe}from"./smartphone-DaDGaGLT.js";import{n as Fe}from"./wind-CI8UoBMf.js";import{t as Ie}from"./triangle-alert-Dt_1FcBy.js";import{t as Le}from"./workflow-BgT0wW83.js";import{t as Re}from"./x-DR-Trv6U.js";import{i as U,n as W,r as ze,t as G}from"./Card-Bzc64K35.js";import{t as K}from"./Button-DDr6eAFy.js";import{a as Be,f as Ve,i as He,u as Ue,v as We}from"./date-G9KUauqz.js";import{t as Ge}from"./filamentSwatchHelpers-D3oXQSGk.js";import{$t as Ke,An as q,At as qe,Cn as Je,Ct as Ye,Dn as Xe,Dt as Ze,En as Qe,Et as $e,Ft as et,Gn as tt,Gt as nt,In as rt,Jt as it,Kt as at,Ln as ot,Mn as st,N as ct,On as lt,Pn as ut,Qt as dt,Rn as ft,S as pt,Sn as mt,St as ht,Tn as gt,Ut as _t,Vn as vt,Vt as yt,Wn as bt,Wt as xt,Xt as St,Yt as Ct,Zt as wt,_t as Tt,at as Et,bn as Dt,bt as Ot,c as kt,cn as At,d as jt,dn as Mt,en as Nt,f as Pt,fn as Ft,gn as It,gt as Lt,h as Rt,hn as zt,ht as Bt,in as Vt,it as Ht,kn as Ut,kt as Wt,l as Gt,ln as Kt,m as qt,nn as Jt,nt as Yt,o as Xt,on as Zt,p as Qt,pn as $t,qt as en,rn as tn,rt as nn,u as rn,vt as an,w as on,wn as sn,x as cn,xn as ln,yt as un}from"./index-Cxa-KVmA.js";import{t as J}from"./Toggle-KiqA_5fU.js";import{a as dn,i as fn,n as pn,r as mn,s as hn,t as gn}from"./OverlayFrame-fLmufrTC.js";var _n=m(`arrow-right-left`,[[`path`,{d:`m16 3 4 4-4 4`,key:`1x1c3m`}],[`path`,{d:`M20 7H4`,key:`zbl0bi`}],[`path`,{d:`m8 21-4-4 4-4`,key:`h9nckh`}],[`path`,{d:`M4 17h16`,key:`g4d7ey`}]]),vn=m(`camera-off`,[[`path`,{d:`M14.564 14.558a3 3 0 1 1-4.122-4.121`,key:`1rnrzw`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M20 20H4a2 2 0 0 1-2-2V9a2 2 0 0 1 2-2h1.997a2 2 0 0 0 .819-.175`,key:`1x3arw`}],[`path`,{d:`M9.695 4.024A2 2 0 0 1 10.004 4h3.993a2 2 0 0 1 1.76 1.05l.486.9A2 2 0 0 0 18.003 7H20a2 2 0 0 1 2 2v7.344`,key:`1i84u0`}]]),yn=m(`cloud-upload`,[[`path`,{d:`M12 13v8`,key:`1l5pq0`}],[`path`,{d:`M4 14.899A7 7 0 1 1 15.71 8h1.79a4.5 4.5 0 0 1 2.5 8.242`,key:`1pljnt`}],[`path`,{d:`m8 17 4-4 4 4`,key:`1quai1`}]]),bn=m(`cylinder`,[[`ellipse`,{cx:`12`,cy:`5`,rx:`9`,ry:`3`,key:`msslwz`}],[`path`,{d:`M3 5v14a9 3 0 0 0 18 0V5`,key:`aqi0yr`}]]),xn=m(`folder-archive`,[[`circle`,{cx:`15`,cy:`19`,r:`2`,key:`u2pros`}],[`path`,{d:`M20.9 19.8A2 2 0 0 0 22 18V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2h5.1`,key:`1jj40k`}],[`path`,{d:`M15 11v-1`,key:`cntcp`}],[`path`,{d:`M15 17v-2`,key:`1279jj`}]]),Sn=m(`send`,[[`path`,{d:`M14.536 21.686a.5.5 0 0 0 .937-.024l6.5-19a.496.496 0 0 0-.635-.635l-19 6.5a.5.5 0 0 0-.024.937l7.93 3.18a2 2 0 0 1 1.112 1.11z`,key:`1ffxy3`}],[`path`,{d:`m21.854 2.147-10.94 10.939`,key:`12cjpa`}]]),Cn=m(`shield-check`,[[`path`,{d:`M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z`,key:`oel41y`}],[`path`,{d:`m9 12 2 2 4-4`,key:`dzmm74`}]]),wn=m(`shield-off`,[[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M5 5a1 1 0 0 0-1 1v7c0 5 3.5 7.5 7.67 8.94a1 1 0 0 0 .67.01c2.35-.82 4.48-1.97 5.9-3.71`,key:`1jlk70`}],[`path`,{d:`M9.309 3.652A12.252 12.252 0 0 0 11.24 2.28a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1v7a9.784 9.784 0 0 1-.08 1.264`,key:`18rp1v`}]]),Tn=m(`tags`,[[`path`,{d:`M13.172 2a2 2 0 0 1 1.414.586l6.71 6.71a2.4 2.4 0 0 1 0 3.408l-4.592 4.592a2.4 2.4 0 0 1-3.408 0l-6.71-6.71A2 2 0 0 1 6 9.172V3a1 1 0 0 1 1-1z`,key:`16rjxf`}],[`path`,{d:`M2 7v6.172a2 2 0 0 0 .586 1.414l6.71 6.71a2.4 2.4 0 0 0 3.191.193`,key:`178nd4`}],[`circle`,{cx:`10.5`,cy:`6.5`,r:`.5`,fill:`currentColor`,key:`12ikhr`}]]);function En(e){return e.length<8?`tooShort`:/[A-Z]/.test(e)?/[a-z]/.test(e)?/\d/.test(e)?/[^A-Za-z0-9]/.test(e)?null:`needsSpecial`:`needsDigit`:`needsLowercase`:`needsUppercase`}var Dn={PLA:0,PETG:0,"PETG-CF":40,ABS:45,ASA:45,PA:50,"PA-CF":55,PC:50,"PC-FR":50,TPU:0,PVA:0,default:0},On=[`PA-CF`,`PA`,`PC`,`PC-FR`,`ABS`,`ASA`,`PETG-CF`,`PETG`,`PLA`,`TPU`,`PVA`,`default`];function kn(e){if(!e)return{...Dn};try{let t=JSON.parse(e);if(t&&typeof t==`object`&&!Array.isArray(t)){let e={};for(let[n,r]of Object.entries(t)){let t=typeof r==`number`?r:Number(r);Number.isFinite(t)&&(e[n]=Math.max(0,Math.min(65,Math.round(t))))}return e.default===void 0&&(e.default=Dn.default),e}}catch{}return{...Dn}}function An(e){let t={};for(let n of On)e[n]!==void 0&&(t[n]=e[n]);for(let[n,r]of Object.entries(e))n in t||(t[n]=r);return JSON.stringify(t)}var Y=t();function jn({value:e,onChange:t,disabled:n=!1}){let{t:r}=l(),i=kn(e),a=(e,n)=>{let r=Math.max(0,Math.min(65,Math.round(n)));t(An({...i,[e]:r}))};return(0,Y.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-x-3 gap-y-1.5`,children:On.map(e=>{let t=i[e]??Dn[e]??0,o=e==="default"?r(`settings.preheatFilamentTargetsDefaultRow`,`Other / unmapped`):e;return(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Y.jsx)(`span`,{className:`text-xs ${e==="default"?`text-bambu-gray italic`:`text-bambu-gray`}`,children:o}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Y.jsx)(`input`,{type:`number`,min:0,max:65,step:1,value:t,onChange:t=>a(e,parseInt(t.target.value,10)||0),disabled:n,className:`w-16 px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-xs text-right focus:outline-none focus:border-bambu-green disabled:opacity-50`}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:`°C`})]})]},e)})})}var X=e(n(),1);function Mn(e,t,n){if(!e)return null;let r=(e[n.source]?.[t]??[]).find(e=>e.id===n.id);return r?r.name:null}var Nn={orca_cloud:`Orca Cloud`,cloud:`Bambu Cloud`,local:`Imported`,standard:`Standard`};function Pn(){let{t:e}=l(),t=u(),{showToast:n}=ee(),{data:i,isLoading:a,error:o}=d({queryKey:[`slicer-pipelines`],queryFn:()=>r.listSlicerPipelines()}),{data:s}=d({queryKey:[`slicer-presets`],queryFn:()=>r.getSlicerPresets()}),{data:c}=d({queryKey:[`printers`],queryFn:()=>r.getPrinters()}),p=f({mutationFn:({id:e,name:t,description:n,target_printer_id:i,target_kind:a,target_model_class:o,fanout_strategy:s})=>r.updateSlicerPipeline(e,{name:t,description:n,target_printer_id:i,target_kind:a,target_model_class:o,fanout_strategy:s}),onSuccess:()=>{t.invalidateQueries({queryKey:[`slicer-pipelines`]}),n(e(`settings.pipelines.toast.saved`,`Pipeline saved`),`success`)},onError:t=>{n(t.message||e(`settings.pipelines.toast.saveFailed`,`Save failed`),`error`)}}),m=f({mutationFn:e=>r.deleteSlicerPipeline(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`slicer-pipelines`]}),n(e(`settings.pipelines.toast.deleted`,`Pipeline deleted`),`success`)},onError:t=>{n(t.message||e(`settings.pipelines.toast.deleteFailed`,`Delete failed`),`error`)}}),[h,g]=(0,X.useState)(``),[_,v]=(0,X.useState)(``),y=(0,X.useMemo)(()=>i?.pipelines??[],[i?.pipelines]),b=(0,X.useMemo)(()=>{let e=new Set,t=new Set,n=!1;for(let r of y)r.target_kind===`printer_class`&&r.target_model_class?t.add(r.target_model_class):r.target_printer_id?e.add(r.target_printer_id):n=!0;return{printers:(c??[]).filter(t=>e.has(t.id)),classes:Array.from(t).sort(),anyWithoutTarget:n}},[y,c]),x=(0,X.useMemo)(()=>{let e=h.trim().toLowerCase();return y.filter(t=>{if(e&&!t.name.toLowerCase().includes(e))return!1;if(_===`none`){if(t.target_kind===`printer_class`?t.target_model_class:t.target_printer_id!==null)return!1}else if(_.startsWith(`p:`)){let e=parseInt(_.slice(2),10);if(t.target_kind===`printer_class`||t.target_printer_id!==e)return!1}else if(_.startsWith(`c:`)){let e=_.slice(2);if(t.target_kind!==`printer_class`||t.target_model_class!==e)return!1}return!0})},[y,h,_]);return(0,Y.jsxs)(G,{children:[(0,Y.jsxs)(U,{children:[(0,Y.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,Y.jsx)(Le,{className:`w-4 h-4 text-bambu-green`}),e(`settings.pipelines.title`,`Slicer Pipelines`)]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`settings.pipelines.subtitle`,`Reusable preset bundles (printer + process + filaments + bed type). Save one from the Slice dialog and apply it with a single click on the next file.`)})]}),(0,Y.jsxs)(W,{children:[a&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-bambu-gray`,children:[(0,Y.jsx)(R,{className:`w-4 h-4 animate-spin`}),e(`settings.pipelines.loading`,`Loading pipelines…`)]}),o&&(0,Y.jsx)(`div`,{className:`text-sm text-red-700 dark:text-red-400`,children:e(`settings.pipelines.loadError`,`Could not load pipelines.`)}),!a&&!o&&y.length>0&&(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 mb-3`,children:[(0,Y.jsxs)(`div`,{className:`relative flex-1 min-w-[12rem]`,children:[(0,Y.jsx)(Ae,{className:`absolute left-2 top-1/2 -translate-y-1/2 w-3.5 h-3.5 text-bambu-gray pointer-events-none`}),(0,Y.jsx)(`input`,{type:`search`,value:h,onChange:e=>g(e.target.value),placeholder:e(`settings.pipelines.searchPlaceholder`,`Search pipelines…`),"aria-label":e(`settings.pipelines.searchPlaceholder`,`Search pipelines…`),className:`w-full pl-7 pr-2 py-1 text-xs bg-bambu-dark border border-bambu-dark-tertiary rounded text-white`})]}),(0,Y.jsxs)(`select`,{value:_,onChange:e=>v(e.target.value),"aria-label":e(`settings.pipelines.filterTarget`,`Filter by target`),className:`text-xs px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white`,children:[(0,Y.jsx)(`option`,{value:``,children:e(`settings.pipelines.filter.all`,`All targets`)}),b.printers.length>0&&(0,Y.jsx)(`optgroup`,{label:e(`settings.pipelines.field.targetKindSpecific`,`Specific printer`),children:b.printers.map(e=>(0,Y.jsx)(`option`,{value:`p:${e.id}`,children:e.name},`p-${e.id}`))}),b.classes.length>0&&(0,Y.jsx)(`optgroup`,{label:e(`settings.pipelines.field.targetKindClass`,`Printer class`),children:b.classes.map(t=>(0,Y.jsx)(`option`,{value:`c:${t}`,children:e(`library.runWithPipeline.classTarget`,`Any {{model}}`,{model:t})},`c-${t}`))}),b.anyWithoutTarget&&(0,Y.jsx)(`option`,{value:`none`,children:e(`settings.pipelines.filter.noTarget`,`No target set`)})]}),(h||_)&&(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:e(`settings.pipelines.filter.count`,`{{shown}} / {{total}}`,{shown:x.length,total:y.length})})]}),!a&&!o&&y.length===0&&(0,Y.jsxs)(`div`,{className:`text-sm text-bambu-gray space-y-2`,children:[(0,Y.jsx)(`p`,{children:e(`settings.pipelines.empty.title`,`No pipelines yet.`)}),(0,Y.jsx)(`p`,{children:e(`settings.pipelines.empty.howto`,`Open the Slice dialog for any file, pick your printer / process / filaments / bed type, then click "Save as pipeline". Your saved pipelines will appear here.`)})]}),!a&&!o&&y.length>0&&x.length===0&&(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`settings.pipelines.filter.noMatches`,`No pipelines match the current filters.`)}),!a&&!o&&x.length>0&&(0,Y.jsx)(`div`,{className:`space-y-2`,children:x.map(t=>(0,Y.jsx)(Fn,{pipeline:t,presets:s,printers:c??[],onSave:e=>p.mutate({id:t.id,...e}),onDelete:()=>{confirm(e(`settings.pipelines.confirmDelete`,`Delete this pipeline? This cannot be undone.`))&&m.mutate(t.id)},saving:p.isPending,deleting:m.isPending},t.id))})]})]})}function Fn({pipeline:e,presets:t,printers:n,onSave:i,onDelete:a,saving:o,deleting:s}){let{t:c}=l(),[u,f]=(0,X.useState)(!1),[p,m]=(0,X.useState)(e.name),[h,g]=(0,X.useState)(e.description??``),[_,v]=(0,X.useState)(e.target_printer_id),[y,b]=(0,X.useState)(e.target_kind===`printer_class`?`printer_class`:`specific_printer`),[x,S]=(0,X.useState)(e.target_model_class??``),[C,w]=(0,X.useState)(e.fanout_strategy??`max_parallel`),E=Array.from(new Set(n.map(e=>e.model).filter(e=>!!e))).sort(),{data:D}=d({queryKey:[`pipeline-runs`,e.id],queryFn:()=>r.listPipelineRuns(e.id,1),enabled:!u,refetchInterval:15e3}),O=D?.runs?.[0],k=Mn(t,`printer`,e.printer_preset),A=Mn(t,`process`,e.process_preset),ee=e.filament_presets.map(e=>Mn(t,`filament`,e)),j=e.filament_presets.length>1&&e.filament_presets.every(t=>t.source===e.filament_presets[0].source&&t.id===e.filament_presets[0].id),M=t!==void 0&&(k===null||A===null||ee.some(e=>e===null)),N=e.target_printer_id?n.find(t=>t.id===e.target_printer_id):void 0,P=e.target_kind===`printer_class`,te=P?!e.target_model_class:e.target_printer_id===null;return(0,Y.jsxs)(`div`,{className:`rounded-md border border-bambu-dark-tertiary bg-bambu-dark/40 px-3 py-2`,children:[(0,Y.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,Y.jsx)(`div`,{className:`min-w-0 flex-1`,children:u?(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(`input`,{value:p,onChange:e=>m(e.target.value),"aria-label":c(`settings.pipelines.field.name`,`Pipeline name`),placeholder:c(`settings.pipelines.field.name`,`Pipeline name`),className:`w-full px-2 py-1 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded text-white`}),(0,Y.jsx)(`textarea`,{value:h,onChange:e=>g(e.target.value),"aria-label":c(`settings.pipelines.field.description`,`Description`),placeholder:c(`settings.pipelines.field.description`,`Description`),rows:2,className:`w-full px-2 py-1 text-xs bg-bambu-dark border border-bambu-dark-tertiary rounded text-white`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`text-xs text-bambu-gray block mb-1`,children:c(`settings.pipelines.field.targetKind`,`Target type`)}),(0,Y.jsxs)(`div`,{className:`flex gap-3 text-xs`,children:[(0,Y.jsxs)(`label`,{className:`flex items-center gap-1 text-white`,children:[(0,Y.jsx)(`input`,{type:`radio`,name:`target-kind-${e.id}`,value:`specific_printer`,checked:y===`specific_printer`,onChange:()=>b(`specific_printer`),"aria-label":c(`settings.pipelines.field.targetKindSpecific`,`Specific printer`)}),c(`settings.pipelines.field.targetKindSpecific`,`Specific printer`)]}),(0,Y.jsxs)(`label`,{className:`flex items-center gap-1 text-white`,children:[(0,Y.jsx)(`input`,{type:`radio`,name:`target-kind-${e.id}`,value:`printer_class`,checked:y===`printer_class`,onChange:()=>b(`printer_class`),"aria-label":c(`settings.pipelines.field.targetKindClass`,`Printer class`)}),c(`settings.pipelines.field.targetKindClass`,`Printer class`)]})]})]}),y===`specific_printer`?(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`text-xs text-bambu-gray block mb-1`,children:c(`settings.pipelines.field.targetPrinter`,`Target printer`)}),(0,Y.jsxs)(`select`,{value:_??``,onChange:e=>v(e.target.value?parseInt(e.target.value,10):null),"aria-label":c(`settings.pipelines.field.targetPrinter`,`Target printer`),className:`w-full px-2 py-1 text-xs bg-bambu-dark border border-bambu-dark-tertiary rounded text-white`,children:[(0,Y.jsx)(`option`,{value:``,children:c(`settings.pipelines.field.noTarget`,`— No target —`)}),n.map(e=>(0,Y.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}):(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`text-xs text-bambu-gray block mb-1`,children:c(`settings.pipelines.field.targetModelClass`,`Printer model`)}),(0,Y.jsxs)(`select`,{value:x,onChange:e=>S(e.target.value),"aria-label":c(`settings.pipelines.field.targetModelClass`,`Printer model`),className:`w-full px-2 py-1 text-xs bg-bambu-dark border border-bambu-dark-tertiary rounded text-white`,children:[(0,Y.jsx)(`option`,{value:``,children:c(`settings.pipelines.field.noTarget`,`— No target —`)}),E.map(e=>(0,Y.jsx)(`option`,{value:e,children:e},e))]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`text-xs text-bambu-gray block mb-1`,children:c(`settings.pipelines.field.fanoutStrategy`,`Fanout strategy`)}),(0,Y.jsxs)(`select`,{value:C,onChange:e=>w(e.target.value),"aria-label":c(`settings.pipelines.field.fanoutStrategy`,`Fanout strategy`),className:`w-full px-2 py-1 text-xs bg-bambu-dark border border-bambu-dark-tertiary rounded text-white`,children:[(0,Y.jsx)(`option`,{value:`max_parallel`,children:c(`settings.pipelines.field.fanout.max_parallel`,`Max parallel — distribute across any idle matching printer`)}),(0,Y.jsx)(`option`,{value:`round_robin`,children:c(`settings.pipelines.field.fanout.round_robin`,`Round robin — cycle through eligible printers`)}),(0,Y.jsx)(`option`,{value:`fill_one_first`,children:c(`settings.pipelines.field.fanout.fill_one_first`,`Fill one first — pin all copies to one printer`)})]})]})]})]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2 gap-y-1`,children:[(0,Y.jsx)(`h4`,{className:`text-sm font-medium text-white truncate`,children:e.name}),(0,Y.jsxs)(`span`,{className:`text-xs px-1.5 py-0.5 rounded inline-flex items-center gap-1 ${te?`bg-amber-100 dark:bg-amber-500/15 text-amber-700 dark:text-amber-400`:`bg-bambu-dark-tertiary text-bambu-gray`}`,children:[(0,Y.jsx)(it,{className:`w-3 h-3`}),te?c(`settings.pipelines.noTargetHint`,`Set a target printer to run this`):P?(0,Y.jsxs)(Y.Fragment,{children:[c(`library.runWithPipeline.classTarget`,`Any {{model}}`,{model:e.target_model_class}),e.fanout_strategy&&(0,Y.jsxs)(`span`,{className:`text-bambu-gray/60`,children:[` · `,c(`settings.pipelines.field.fanoutShort.${e.fanout_strategy}`,e.fanout_strategy)]})]}):N?.name??``]})]}),e.description&&(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:e.description})]})}),(0,Y.jsx)(`div`,{className:`flex items-center gap-1 flex-shrink-0`,children:u?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`button`,{onClick:()=>{let e=p.trim();e&&(i({name:e,description:h.trim()||null,target_kind:y,target_printer_id:y===`specific_printer`?_??0:0,target_model_class:y===`printer_class`&&x||null,fanout_strategy:C}),f(!1))},disabled:o||!p.trim(),"aria-label":c(`settings.pipelines.action.save`,`Save`),className:`p-1.5 text-bambu-green hover:bg-bambu-dark-tertiary rounded disabled:opacity-50`,children:(0,Y.jsx)(T,{className:`w-4 h-4`})}),(0,Y.jsx)(`button`,{onClick:()=>{m(e.name),g(e.description??``),v(e.target_printer_id),b(e.target_kind===`printer_class`?`printer_class`:`specific_printer`),S(e.target_model_class??``),w(e.fanout_strategy??`max_parallel`),f(!1)},"aria-label":c(`settings.pipelines.action.cancel`,`Cancel`),className:`p-1.5 text-bambu-gray hover:bg-bambu-dark-tertiary rounded`,children:(0,Y.jsx)(Re,{className:`w-4 h-4`})})]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`button`,{onClick:()=>f(!0),"aria-label":c(`settings.pipelines.action.rename`,`Rename`),className:`p-1.5 text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary rounded`,children:(0,Y.jsx)(oe,{className:`w-4 h-4`})}),(0,Y.jsx)(`button`,{onClick:a,disabled:s,"aria-label":c(`settings.pipelines.action.delete`,`Delete`),className:`p-1.5 text-bambu-gray hover:text-red-600 dark:hover:text-red-400 hover:bg-bambu-dark-tertiary rounded disabled:opacity-50`,children:(0,Y.jsx)(qe,{className:`w-4 h-4`})})]})})]}),!u&&(0,Y.jsxs)(`div`,{className:`mt-2 grid grid-cols-1 md:grid-cols-2 gap-x-4 gap-y-2 text-xs`,children:[(0,Y.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,Y.jsx)(`div`,{className:`text-[10px] uppercase tracking-wide text-bambu-gray/60`,children:c(`settings.pipelines.group.profiles`,`Profiles`)}),(0,Y.jsx)(Ln,{label:c(`settings.pipelines.slot.printer`,`Printer`),ref:e.printer_preset,name:k}),(0,Y.jsx)(Ln,{label:c(`settings.pipelines.slot.process`,`Process`),ref:e.process_preset,name:A}),e.bed_type&&(0,Y.jsxs)(`div`,{className:`text-bambu-gray`,children:[(0,Y.jsxs)(`span`,{className:`font-medium text-bambu-gray/80`,children:[c(`settings.pipelines.slot.bed`,`Bed`),`:`]}),` `,(0,Y.jsx)(`span`,{className:`text-white`,children:e.bed_type})]})]}),(0,Y.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,Y.jsxs)(`div`,{className:`text-[10px] uppercase tracking-wide text-bambu-gray/60`,children:[c(`settings.pipelines.group.filaments`,`Filaments`),e.filament_presets.length>1&&(0,Y.jsxs)(`span`,{className:`text-bambu-gray/60 normal-case ml-1`,children:[`(`,e.filament_presets.length,`)`]})]}),j?(0,Y.jsx)(Ln,{label:c(`settings.pipelines.slot.filamentAll`,`All {{n}} slots`,{n:e.filament_presets.length}),ref:e.filament_presets[0],name:ee[0]}):e.filament_presets.map((t,n)=>(0,Y.jsx)(Ln,{label:e.filament_presets.length>1?c(`settings.pipelines.slot.filamentN`,`Filament {{n}}`,{n:n+1}):c(`settings.pipelines.slot.filament`,`Filament`),ref:t,name:ee[n]},n))]})]}),!u&&O&&(0,Y.jsxs)(`div`,{className:`mt-1.5 text-xs text-bambu-gray flex items-center gap-1`,children:[(0,Y.jsxs)(`span`,{className:`font-medium text-bambu-gray/80`,children:[c(`settings.pipelines.runs.lastRun`,`Last run`),`:`]}),` `,(0,Y.jsx)(In,{status:O.status}),O.created_at&&(0,Y.jsxs)(`span`,{className:`text-bambu-gray/60`,children:[`· `,new Date(O.created_at).toLocaleString()]})]}),te&&!u&&(0,Y.jsxs)(`div`,{className:`mt-2 flex items-center gap-1.5 text-xs text-amber-700 dark:text-amber-400`,children:[(0,Y.jsx)(Ie,{className:`w-3.5 h-3.5`}),c(`settings.pipelines.noTargetWarning`,`Set a target printer before running this pipeline.`)]}),M&&!u&&(0,Y.jsxs)(`div`,{className:`mt-2 flex items-center gap-1.5 text-xs text-amber-700 dark:text-amber-400`,children:[(0,Y.jsx)(Ie,{className:`w-3.5 h-3.5`}),c(`settings.pipelines.staleWarning`,`One or more referenced presets no longer exist. Re-save this pipeline from the Slice dialog to fix.`)]})]})}function In({status:e}){let{t}=l();return(0,Y.jsx)(`span`,{className:{queued:`text-bambu-gray`,slicing:`text-blue-700 dark:text-blue-400`,dispatching:`text-blue-700 dark:text-blue-400`,in_progress:`text-bambu-green`,completed:`text-bambu-green`,failed:`text-red-700 dark:text-red-400`,partial_failure:`text-amber-700 dark:text-amber-400`,cancelled:`text-bambu-gray`}[e],children:t(`settings.pipelines.runs.status.${e}`,e)})}function Ln({label:e,ref:t,name:n}){return(0,Y.jsxs)(`div`,{className:`text-bambu-gray truncate`,children:[(0,Y.jsxs)(`span`,{className:`font-medium text-bambu-gray/80`,children:[e,`:`]}),` `,n?(0,Y.jsx)(`span`,{className:`text-white`,children:n}):(0,Y.jsxs)(`span`,{className:`text-amber-700 dark:text-amber-400`,children:[`[`,Nn[t.source],` #`,t.id,`]`]})]})}var Rn=90,zn=365;function Bn(e){if(!e)return`—`;let t=We(e);return t?t.toLocaleString():`—`}function Vn(e){let t=We(e);return t?t.getTime(){if(l.preventDefault(),!(!o.trim()||p)){m(!0),n?.(!0);try{e(await r.createLongLivedCameraToken({name:o.trim(),expires_in_days:c,scope:t??d})),s(``),u(Rn),f(t??`camera_stream`),a(i(`cameraTokens.toast.created`,`Token created`))}catch(e){a(e instanceof Error&&e.message?e.message:i(`cameraTokens.toast.createFailed`,`Failed to create token`),`error`)}finally{m(!1),n?.(!1)}}},className:`@container/token-form min-w-0 bg-bambu-dark-secondary rounded-lg p-4 mb-6 border border-bambu-dark-tertiary`,children:[(0,Y.jsx)(`h3`,{className:`text-base font-semibold text-white mb-3`,children:i(`cameraTokens.create.title`,`Create new token`)}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 gap-3 @min-[26rem]/token-form:grid-cols-2 @min-[44rem]/token-form:grid-cols-[minmax(0,1fr)_180px_140px_auto]`,children:[(0,Y.jsx)(`input`,{type:`text`,maxLength:100,required:!0,value:o,onChange:e=>s(e.target.value),placeholder:i(`cameraTokens.create.namePlaceholder`,`e.g. Home Assistant`),className:`min-w-0 w-full px-3 py-2 bg-bambu-dark rounded-md text-white border border-bambu-dark-tertiary focus:border-bambu-green focus:outline-none`,"aria-label":i(`cameraTokens.create.nameLabel`,`Token name`)}),(0,Y.jsxs)(`select`,{value:d,disabled:!!t,onChange:e=>f(e.target.value),className:`min-w-0 w-full px-3 py-2 bg-bambu-dark rounded-md text-white border border-bambu-dark-tertiary focus:border-bambu-green focus:outline-none`,"aria-label":i(`cameraTokens.create.scopeLabel`,`Scope`),children:[(0,Y.jsx)(`option`,{value:`camera_stream`,children:i(`cameraTokens.scope.camera_stream`,`Camera stream`)}),(0,Y.jsx)(`option`,{value:`camwall`,children:i(`cameraTokens.scope.camwall`,`Cam Wall`)}),(0,Y.jsx)(`option`,{value:`overlay`,children:i(`cameraTokens.scope.overlay`,`Streaming Overlay`)})]}),(0,Y.jsx)(`input`,{type:`number`,min:1,max:zn,required:!0,value:c,onChange:e=>{let t=Number(e.target.value);u(Math.min(Math.max(t,1),zn))},className:`min-w-0 w-full px-3 py-2 bg-bambu-dark rounded-md text-white border border-bambu-dark-tertiary focus:border-bambu-green focus:outline-none`,"aria-label":i(`cameraTokens.create.daysLabel`,`Days until expiry`)}),(0,Y.jsxs)(`button`,{type:`submit`,disabled:p||!o.trim(),className:`min-w-0 flex items-center justify-center gap-2 px-4 py-2 bg-bambu-green text-white rounded-md hover:bg-bambu-green/90 disabled:opacity-50 disabled:cursor-not-allowed`,children:[(0,Y.jsx)(wt,{className:`w-4 h-4`}),i(`cameraTokens.create.submit`,`Create`)]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-2`,children:d===`camwall`?i(`cameraTokens.create.hintCamWall`,`A Cam Wall token opens /camwall on a screen with no login — it can see every printer's name and state, and their camera streams. It cannot see filenames, addresses or access codes.`):d===`overlay`?i(`cameraTokens.create.hintOverlay`,`A Streaming Overlay token opens /overlay/{printerId} on a screen with no login — for OBS or any live stream. It can see one printer's camera stream plus its live print status, including the filename shown on screen. It cannot see addresses or access codes.`):i(`cameraTokens.create.hintCameraStream`,`A camera-stream token can only fetch camera streams and snapshots. Use it for Home Assistant, Frigate, or anything embedding a single camera.`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`cameraTokens.create.hint`,`Maximum lifetime is 365 days. The token value is shown only once on creation — copy it now.`)})]})}function Un({token:e,onConfirm:t,onCancel:n}){let{t:r}=l();return(0,Y.jsx)(`div`,{className:`fixed inset-0 bg-black/60 flex items-center justify-center z-50 p-4`,role:`dialog`,"aria-modal":`true`,children:(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-6 max-w-md w-full border border-red-500/40`,children:[(0,Y.jsxs)(`div`,{className:`flex items-start gap-3 mb-4`,children:[(0,Y.jsx)(Ie,{className:`w-6 h-6 text-red-600 dark:text-red-400 flex-shrink-0 mt-0.5`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:r(`cameraTokens.confirmRevoke.title`,`Revoke this token?`)}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:r(`cameraTokens.confirmRevoke.body`,`Any device using "{{name}}" will lose access immediately. This cannot be undone.`,{name:e.name})})]})]}),(0,Y.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,Y.jsx)(`button`,{type:`button`,onClick:n,className:`px-4 py-2 bg-bambu-dark-tertiary text-white rounded-md hover:bg-bambu-dark-tertiary/80`,children:r(`cameraTokens.confirmRevoke.cancel`,`Cancel`)}),(0,Y.jsx)(`button`,{type:`button`,onClick:t,className:`px-4 py-2 bg-red-500 text-white rounded-md hover:bg-red-600`,children:r(`cameraTokens.confirmRevoke.confirm`,`Revoke`)})]})]})})}function Wn({token:e,onClose:t}){let{t:n}=l(),{showToast:r}=ee(),i=e.token??``,a=e.scope===`camwall`&&i?`${window.location.origin}/camwall?token=${encodeURIComponent(i)}`:null,o=e.scope===`overlay`&&i?`${window.location.origin}/overlay/1?token=${encodeURIComponent(i)}`:null,s=async e=>{if(e)try{if(navigator.clipboard&&window.isSecureContext)await navigator.clipboard.writeText(e);else{let t=document.createElement(`textarea`);t.value=e,t.style.position=`fixed`,t.style.opacity=`0`,document.body.appendChild(t);try{t.select(),document.execCommand(`copy`)}finally{document.body.removeChild(t)}}r(n(`cameraTokens.toast.copied`,`Copied to clipboard`))}catch{r(n(`cameraTokens.toast.copyFailed`,`Copy failed — select and copy manually`),`error`)}};return(0,Y.jsx)(`div`,{className:`fixed inset-0 bg-black/60 flex items-center justify-center z-50 p-4`,children:(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-6 max-w-2xl w-full border border-bambu-green/40`,children:[(0,Y.jsxs)(`div`,{className:`flex items-start gap-3 mb-4`,children:[(0,Y.jsx)(Ie,{className:`w-6 h-6 text-yellow-600 dark:text-yellow-400 flex-shrink-0 mt-0.5`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:n(`cameraTokens.created.title`,`Token created — copy it now`)}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:n(`cameraTokens.created.warning`,`This is the only time this token will be visible. After you close this dialog you can never view it again.`)})]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 mb-4`,children:[(0,Y.jsx)(`code`,{className:`flex-1 px-3 py-2 bg-bambu-dark rounded-md text-bambu-green text-xs break-all font-mono select-all`,children:i}),(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>s(i),className:`flex items-center gap-2 px-3 py-2 bg-bambu-green text-white rounded-md hover:bg-bambu-green/90`,children:[(0,Y.jsx)(N,{className:`w-4 h-4`}),n(`cameraTokens.created.copy`,`Copy`)]})]}),a&&(0,Y.jsxs)(`div`,{className:`mb-4`,children:[(0,Y.jsx)(`p`,{className:`text-sm font-medium text-white mb-1`,children:n(`cameraTokens.created.camWallUrlTitle`,`Cam Wall URL for this display`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:n(`cameraTokens.created.camWallUrlHint`,`Open this on the screen. Anyone who can read the URL can watch the wall, so treat it like a key — revoke the token to cut the display off.`)}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`code`,{className:`flex-1 px-3 py-2 bg-bambu-dark rounded-md text-bambu-green text-xs break-all font-mono select-all`,children:a}),(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>s(a),className:`flex items-center gap-2 px-3 py-2 bg-bambu-green text-white rounded-md hover:bg-bambu-green/90`,children:[(0,Y.jsx)(N,{className:`w-4 h-4`}),n(`cameraTokens.created.copy`,`Copy`)]})]})]}),o&&(0,Y.jsxs)(`div`,{className:`mb-4`,children:[(0,Y.jsx)(`p`,{className:`text-sm font-medium text-white mb-1`,children:n(`cameraTokens.created.overlayUrlTitle`,`Overlay URL for OBS`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:n(`cameraTokens.created.overlayUrlHint`,`Add this as a Browser Source in OBS. Change the /overlay/1 number to your printer's number (from its URL on the Printers page). Anyone who can read the URL can watch the stream, so treat it like a key — revoke the token to cut it off.`)}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`code`,{className:`flex-1 px-3 py-2 bg-bambu-dark rounded-md text-bambu-green text-xs break-all font-mono select-all`,children:o}),(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>s(o),className:`flex items-center gap-2 px-3 py-2 bg-bambu-green text-white rounded-md hover:bg-bambu-green/90`,children:[(0,Y.jsx)(N,{className:`w-4 h-4`}),n(`cameraTokens.created.copy`,`Copy`)]})]})]}),(0,Y.jsx)(`div`,{className:`flex justify-end`,children:(0,Y.jsx)(`button`,{type:`button`,onClick:t,className:`px-4 py-2 bg-bambu-dark-tertiary text-white rounded-md hover:bg-bambu-dark-tertiary/80`,children:n(`cameraTokens.created.dismiss`,`I've saved it`)})})]})})}function Gn({token:e,showOwner:t,ownerLabel:n,onRevoke:r}){let{t:i}=l(),a=Vn(e.expires_at);return(0,Y.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary last:border-b-0`,children:[(0,Y.jsx)(`td`,{className:`py-3 px-3 text-white break-words max-w-64`,children:e.name}),t&&(0,Y.jsx)(`td`,{className:`py-3 px-3 text-bambu-gray`,children:n}),(0,Y.jsx)(`td`,{className:`py-3 px-3`,children:(0,Y.jsx)(`span`,{className:`rounded bg-bambu-dark-tertiary px-2 py-0.5 text-xs text-bambu-gray`,children:i(`cameraTokens.scope.${e.scope}`,e.scope)})}),(0,Y.jsxs)(`td`,{className:`py-3 px-3 text-bambu-gray font-mono text-xs`,children:[e.lookup_prefix,`…`]}),(0,Y.jsx)(`td`,{className:`py-3 px-3 text-bambu-gray`,children:Bn(e.created_at)}),(0,Y.jsxs)(`td`,{className:`py-3 px-3 ${a?`text-red-700 dark:text-red-400`:`text-bambu-gray`}`,children:[Bn(e.expires_at),a&&(0,Y.jsx)(`span`,{className:`ml-2 px-2 py-0.5 text-xs bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-300 rounded`,children:i(`cameraTokens.list.expired`,`Expired`)})]}),(0,Y.jsx)(`td`,{className:`py-3 px-3 text-bambu-gray`,children:Bn(e.last_used_at)}),(0,Y.jsx)(`td`,{className:`py-3 px-3 text-right`,children:(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>r(e.id),className:`inline-flex items-center gap-1 px-2 py-1 text-sm text-red-700 dark:text-red-400 hover:text-red-900 dark:hover:text-red-300`,title:i(`cameraTokens.list.revoke`,`Revoke`),children:[(0,Y.jsx)(qe,{className:`w-4 h-4`}),i(`cameraTokens.list.revoke`,`Revoke`)]})})]})}function Kn({tokens:e,showOwner:t,userIdToName:n,onRevoke:r,emptyMessage:i}){let{t:a}=l();return e.length===0?(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray italic`,children:i}):(0,Y.jsx)(`div`,{className:`overflow-x-auto`,children:(0,Y.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,Y.jsx)(`thead`,{className:`text-bambu-gray text-left border-b border-bambu-dark-tertiary`,children:(0,Y.jsxs)(`tr`,{children:[(0,Y.jsx)(`th`,{className:`py-2 px-3 font-medium`,children:a(`cameraTokens.list.name`,`Name`)}),t&&(0,Y.jsx)(`th`,{className:`py-2 px-3 font-medium`,children:a(`cameraTokens.list.owner`,`Owner`)}),(0,Y.jsx)(`th`,{className:`py-2 px-3 font-medium`,children:a(`cameraTokens.list.scope`,`Scope`)}),(0,Y.jsx)(`th`,{className:`py-2 px-3 font-medium`,children:a(`cameraTokens.list.prefix`,`Prefix`)}),(0,Y.jsx)(`th`,{className:`py-2 px-3 font-medium`,children:a(`cameraTokens.list.created`,`Created`)}),(0,Y.jsx)(`th`,{className:`py-2 px-3 font-medium`,children:a(`cameraTokens.list.expires`,`Expires`)}),(0,Y.jsx)(`th`,{className:`py-2 px-3 font-medium`,children:a(`cameraTokens.list.lastUsed`,`Last used`)}),(0,Y.jsx)(`th`,{className:`py-2 px-3`})]})}),(0,Y.jsx)(`tbody`,{children:e.map(e=>(0,Y.jsx)(Gn,{token:e,showOwner:t,ownerLabel:n?.get(e.user_id)??`#${e.user_id}`,onRevoke:r},e.id))})]})})}function qn(){let{t:e}=l(),{user:t,isAdmin:n}=un(),{showToast:i}=ee(),[a,o]=(0,X.useState)([]),[s,c]=(0,X.useState)([]),[u,d]=(0,X.useState)(new Map),[f,p]=(0,X.useState)(!0),[m,h]=(0,X.useState)(null),[g,_]=(0,X.useState)(null),v=async()=>{p(!0);try{if(o(await r.listMyLongLivedCameraTokens()),n){c(await r.listAllLongLivedCameraTokens());try{let e=await r.getUsersSlim();d(new Map(e.map(e=>[e.id,e.username])))}catch{d(new Map)}}}catch(t){i(t instanceof Error?t.message:e(`cameraTokens.toast.loadFailed`,`Failed to load tokens`),`error`)}finally{p(!1)}};(0,X.useEffect)(()=>{v()},[n]);let y=async e=>{let t=[...a,...s].find(t=>t.id===e);t&&_(t)},b=async()=>{if(!g)return;let t=g.id;_(null);try{await r.revokeLongLivedCameraToken(t),i(e(`cameraTokens.toast.revoked`,`Token revoked`)),await v()}catch(t){i(t instanceof Error?t.message:e(`cameraTokens.toast.revokeFailed`,`Failed to revoke token`),`error`)}},x=(0,X.useMemo)(()=>s.filter(e=>e.user_id!==t?.id),[s,t?.id]);return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4`,children:e(`cameraTokens.description`,`Long-lived tokens for embedding the camera stream into Home Assistant, Frigate, kiosks, or any other tool that needs a stable URL. Each token is camera-stream-only and can be revoked at any time.`)}),(0,Y.jsx)(Hn,{onCreated:e=>{h(e),v()}}),(0,Y.jsxs)(`div`,{className:`mb-6`,children:[(0,Y.jsx)(`h3`,{className:`text-base font-semibold text-white mb-3`,children:e(`cameraTokens.list.myTitle`,`My tokens`)}),f?(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`cameraTokens.loading`,`Loading…`)}):(0,Y.jsx)(Kn,{tokens:a,onRevoke:y,emptyMessage:e(`cameraTokens.list.empty`,`No tokens yet.`)})]}),n&&(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h3`,{className:`text-base font-semibold text-white mb-3`,children:e(`cameraTokens.list.allTitle`,`All users (admin view)`)}),(0,Y.jsx)(Kn,{tokens:x,showOwner:!0,userIdToName:u,onRevoke:y,emptyMessage:e(`cameraTokens.list.empty`,`No tokens yet.`)})]}),m&&(0,Y.jsx)(Wn,{token:m,onClose:()=>h(null)}),g&&(0,Y.jsx)(Un,{token:g,onConfirm:()=>void b(),onCancel:()=>_(null)})]})}var Jn=[`connected-apps`];function Yn(e){if(!e)return`—`;let t=We(e);return t?t.toLocaleString():`—`}async function Xn(e){if(navigator.clipboard&&window.isSecureContext){await navigator.clipboard.writeText(e);return}let t=document.createElement(`textarea`);t.value=e,t.style.position=`fixed`,t.style.opacity=`0`,document.body.appendChild(t);try{t.select(),document.execCommand(`copy`)}finally{document.body.removeChild(t)}}function Zn({label:e,value:t}){let{t:n}=l(),{showToast:r}=ee();return(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mb-1`,children:e}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`code`,{className:`flex-1 min-w-0 px-3 py-2 bg-bambu-dark rounded-md text-bambu-green text-xs break-all font-mono select-all`,children:t}),(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>Xn(t).then(()=>r(n(`connectedApps.toast.copied`)),()=>r(n(`connectedApps.toast.copyFailed`),`error`)),className:`flex items-center gap-2 px-3 py-2 bg-bambu-green text-white rounded-md hover:bg-bambu-green/90`,children:[(0,Y.jsx)(N,{className:`w-4 h-4`}),n(`connectedApps.copy`)]})]})]})}function Qn({app:e,onClose:t}){let{t:n}=l();return(0,Y.jsx)(`div`,{className:`fixed inset-0 bg-black/60 flex items-center justify-center z-50 p-4`,role:`dialog`,"aria-modal":`true`,children:(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-6 max-w-2xl w-full border border-bambu-green/40 space-y-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,Y.jsx)(Ie,{className:`w-6 h-6 text-yellow-600 dark:text-yellow-400 flex-shrink-0 mt-0.5`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:n(`connectedApps.secret.title`,{name:e.name})}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:n(`connectedApps.secret.warning`)})]})]}),(0,Y.jsx)(Zn,{label:n(`connectedApps.clientId`),value:e.client_id}),(0,Y.jsx)(Zn,{label:n(`connectedApps.clientSecret`),value:e.client_secret??``}),(0,Y.jsx)(`div`,{className:`flex justify-end`,children:(0,Y.jsx)(`button`,{type:`button`,onClick:t,className:`px-4 py-2 bg-bambu-dark-tertiary text-white rounded-md hover:bg-bambu-dark-tertiary/80`,children:n(`connectedApps.secret.dismiss`)})})]})})}function $n({title:e,body:t,confirmLabel:n,onConfirm:r,onCancel:i}){let{t:a}=l();return(0,Y.jsx)(`div`,{className:`fixed inset-0 bg-black/60 flex items-center justify-center z-50 p-4`,role:`dialog`,"aria-modal":`true`,children:(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-6 max-w-md w-full border border-red-500/40`,children:[(0,Y.jsxs)(`div`,{className:`flex items-start gap-3 mb-4`,children:[(0,Y.jsx)(Ie,{className:`w-6 h-6 text-red-600 dark:text-red-400 flex-shrink-0 mt-0.5`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:t})]})]}),(0,Y.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,Y.jsx)(`button`,{type:`button`,onClick:i,className:`px-4 py-2 bg-bambu-dark-tertiary text-white rounded-md hover:bg-bambu-dark-tertiary/80`,children:a(`connectedApps.cancel`)}),(0,Y.jsx)(`button`,{type:`button`,onClick:r,className:`px-4 py-2 bg-red-500 text-white rounded-md hover:bg-red-600`,children:n})]})]})})}function er(){let{t:e}=l(),{authEnabled:t}=un(),{showToast:n}=ee(),i=u(),[a,o]=(0,X.useState)(``),[s,c]=(0,X.useState)(``),[p,m]=(0,X.useState)(null),[h,g]=(0,X.useState)(null),{data:_=[],isLoading:v}=d({queryKey:Jn,queryFn:r.listConnectedApps,enabled:t}),y=t=>n(t instanceof Error?t.message:e(`connectedApps.toast.failed`),`error`),b=()=>i.invalidateQueries({queryKey:Jn}),x=f({mutationFn:()=>r.createConnectedApp({name:a.trim(),redirect_uri:s.trim()}),onSuccess:t=>{o(``),c(``),m(t),n(e(`connectedApps.toast.created`)),b()},onError:y}),S=f({mutationFn:e=>r.updateConnectedApp(e.id,{enabled:!e.enabled}),onSuccess:t=>{n(t.enabled?e(`connectedApps.toast.enabled`):e(`connectedApps.toast.disabled`)),b()},onError:y}),C=f({mutationFn:e=>r.rotateConnectedAppSecret(e.id),onSuccess:t=>{m(t),n(e(`connectedApps.toast.rotated`)),b()},onError:y}),w=f({mutationFn:e=>r.deleteConnectedApp(e.id),onSuccess:()=>{n(e(`connectedApps.toast.deleted`)),b()},onError:y});if(!t)return(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`connectedApps.requiresAuth`)});let T=`px-3 py-2 bg-bambu-dark rounded-md text-white border border-bambu-dark-tertiary focus:border-bambu-green focus:outline-none`;return(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`connectedApps.description`)}),(0,Y.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),a.trim()&&s.trim()&&x.mutate()},className:`grid gap-3 md:grid-cols-[minmax(0,1fr)_minmax(0,1.5fr)_auto]`,children:[(0,Y.jsx)(`input`,{type:`text`,maxLength:100,required:!0,value:a,onChange:e=>o(e.target.value),placeholder:e(`connectedApps.namePlaceholder`),"aria-label":e(`connectedApps.name`),className:T}),(0,Y.jsx)(`input`,{type:`url`,maxLength:500,required:!0,value:s,onChange:e=>c(e.target.value),placeholder:`http://orders.local:8090/auth/callback`,"aria-label":e(`connectedApps.callbackUrl`),className:T}),(0,Y.jsxs)(`button`,{type:`submit`,disabled:x.isPending||!a.trim()||!s.trim(),className:`flex items-center justify-center gap-2 px-4 py-2 bg-bambu-green text-white rounded-md hover:bg-bambu-green/90 disabled:opacity-50 disabled:cursor-not-allowed`,children:[(0,Y.jsx)(wt,{className:`w-4 h-4`}),e(`connectedApps.add`)]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:e(`connectedApps.callbackHint`)}),v?null:_.length===0?(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`connectedApps.empty`)}):(0,Y.jsx)(`div`,{className:`overflow-x-auto`,children:(0,Y.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,Y.jsx)(`thead`,{children:(0,Y.jsxs)(`tr`,{className:`text-left text-bambu-gray border-b border-bambu-dark-tertiary`,children:[(0,Y.jsx)(`th`,{className:`py-2 px-3 font-medium`,children:e(`connectedApps.name`)}),(0,Y.jsx)(`th`,{className:`py-2 px-3 font-medium`,children:e(`connectedApps.clientId`)}),(0,Y.jsx)(`th`,{className:`py-2 px-3 font-medium`,children:e(`connectedApps.callbackUrl`)}),(0,Y.jsx)(`th`,{className:`py-2 px-3 font-medium`,children:e(`connectedApps.lastUsed`)}),(0,Y.jsx)(`th`,{className:`py-2 px-3`})]})}),(0,Y.jsx)(`tbody`,{children:_.map(t=>(0,Y.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary last:border-b-0`,children:[(0,Y.jsxs)(`td`,{className:`py-3 px-3 text-white`,children:[t.name,!t.enabled&&(0,Y.jsx)(`span`,{className:`ml-2 px-2 py-0.5 text-xs rounded bg-bambu-dark-tertiary text-bambu-gray`,children:e(`connectedApps.disabledBadge`)})]}),(0,Y.jsx)(`td`,{className:`py-3 px-3 text-bambu-gray font-mono text-xs`,children:t.client_id}),(0,Y.jsx)(`td`,{className:`py-3 px-3 text-bambu-gray text-xs break-all`,children:t.redirect_uri}),(0,Y.jsx)(`td`,{className:`py-3 px-3 text-bambu-gray`,children:Yn(t.last_used_at)}),(0,Y.jsx)(`td`,{className:`py-3 px-3`,children:(0,Y.jsxs)(`div`,{className:`flex justify-end gap-3 whitespace-nowrap`,children:[(0,Y.jsx)(`button`,{type:`button`,onClick:()=>S.mutate(t),className:`text-sm text-bambu-gray hover:text-white`,children:t.enabled?e(`connectedApps.disable`):e(`connectedApps.enable`)}),(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>g({app:t,action:`rotate`}),className:`inline-flex items-center gap-1 text-sm text-bambu-gray hover:text-white`,children:[(0,Y.jsx)(at,{className:`w-4 h-4`}),e(`connectedApps.rotate`)]}),(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>g({app:t,action:`delete`}),className:`inline-flex items-center gap-1 text-sm text-red-700 dark:text-red-400 hover:text-red-900 dark:hover:text-red-300`,children:[(0,Y.jsx)(qe,{className:`w-4 h-4`}),e(`connectedApps.delete`)]})]})})]},t.id))})]})}),p&&(0,Y.jsx)(Qn,{app:p,onClose:()=>m(null)}),h&&(0,Y.jsx)($n,{title:h.action===`rotate`?e(`connectedApps.confirmRotate.title`):e(`connectedApps.confirmDelete.title`),body:h.action===`rotate`?e(`connectedApps.confirmRotate.body`,{name:h.app.name}):e(`connectedApps.confirmDelete.body`,{name:h.app.name}),confirmLabel:h.action===`rotate`?e(`connectedApps.rotate`):e(`connectedApps.delete`),onCancel:()=>g(null),onConfirm:()=>{h.action===`rotate`?C.mutate(h.app):w.mutate(h.app),g(null)}})]})}function tr({value:e,onChange:t,onBusyChange:n}){let{t:i}=l(),{showToast:a}=ee(),{authEnabled:o,hasPermission:s}=un(),c=!o||s(`settings:update`),[u,d]=(0,X.useState)(!1),[f,p]=(0,X.useState)({from:e.from||`#00ae42`,to:e.to||`#00ae42`}),m=hn(!0,null,e.logoRevision),h=async o=>{d(!0),n?.(!0);try{o?await r.uploadOverlayLogo(o):await r.deleteOverlayLogo(),t({...e,logo:o!==null,logoRevision:e.logoRevision+1})}catch(e){a(e instanceof Error?e.message:i(`streamOverlay.branding.failed`),`error`)}finally{d(!1),n?.(!1)}},g=(n,r)=>{p(e=>({...e,[n]:r})),fn(r)&&t({...e,from:e.from||`#00ae42`,to:e.to||`#00ae42`,[n]:r})};return(0,Y.jsxs)(`fieldset`,{disabled:u,className:`my-4 space-y-3 rounded-lg border border-bambu-dark-tertiary p-4`,children:[(0,Y.jsx)(`legend`,{className:`px-2 text-sm font-medium text-white`,children:i(`streamOverlay.branding.title`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`streamOverlay.branding.hint`)}),(0,Y.jsxs)(`label`,{className:`block text-sm text-bambu-gray`,children:[i(`streamOverlay.branding.upload`),(0,Y.jsx)(`input`,{type:`file`,accept:`image/png,image/webp`,disabled:!c,className:`mt-1 block w-full text-sm`,onChange:e=>{let t=e.target.files?.[0];e.target.value=``,t&&h(t)}})]}),m&&(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,Y.jsx)(`img`,{src:m,alt:i(`streamOverlay.branding.logo`),className:`h-16 max-w-40 object-contain`}),(0,Y.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-bambu-gray`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:e.logo,onChange:n=>t({...e,logo:n.target.checked})}),i(`streamOverlay.branding.logo`)]}),(0,Y.jsx)(`button`,{type:`button`,disabled:!c,onClick:()=>void h(null),className:`text-sm text-red-400 disabled:opacity-50`,children:i(`common.remove`)})]}),(0,Y.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[`from`,`to`].map(t=>(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{htmlFor:`overlay-colour-${t}`,className:`block text-sm text-bambu-gray mb-1`,children:i(`streamOverlay.branding.${t}`)}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`input`,{id:`overlay-colour-${t}`,type:`color`,value:e[t]||`#00ae42`,onChange:e=>g(t,e.target.value),className:`h-9 w-12 bg-transparent`}),(0,Y.jsx)(`input`,{"aria-label":`${i(`streamOverlay.branding.${t}`)} (hex)`,value:f[t],onChange:e=>g(t,e.target.value),"aria-invalid":!fn(f[t]),maxLength:7,spellCheck:!1,className:`w-28 rounded border border-bambu-dark-tertiary bg-bambu-dark px-2 py-1 text-white`})]})]},t))}),(0,Y.jsx)(`button`,{type:`button`,className:`text-sm text-bambu-green`,onClick:()=>{p({from:`#00ae42`,to:`#00ae42`}),t({...e,from:``,to:``})},children:i(`streamOverlay.branding.reset`)})]})}var nr=[{key:`printer`,labelKey:`streamOverlay.builder.fieldPrinter`,fallback:`Printer name`},{key:`model`,labelKey:`streamOverlay.builder.fieldModel`,fallback:`Printer model`},{key:`filename`,labelKey:`streamOverlay.builder.fieldFilename`,fallback:`File name`},{key:`status`,labelKey:`streamOverlay.builder.fieldStatus`,fallback:`Status`},{key:`progress`,labelKey:`streamOverlay.builder.fieldProgress`,fallback:`Progress bar`},{key:`layers`,labelKey:`streamOverlay.builder.fieldLayers`,fallback:`Layer count`},{key:`eta`,labelKey:`streamOverlay.builder.fieldEta`,fallback:`Time remaining and ETA`},{key:`nozzle`,labelKey:`printers.heaterHistory.nozzle`,fallback:`Nozzle`},{key:`bed`,labelKey:`printers.heaterHistory.bed`,fallback:`Bed`},{key:`chamber`,labelKey:`printers.heaterHistory.chamber`,fallback:`Chamber`}],rr=[`progress`,`layers`,`eta`,`filename`,`status`],ir=15,ar=`bambuddy.streamOverlayBuilder`,or={printerId:null,fields:rr,size:`medium`,fps:ir,artwork:`1`,backgroundTransparency:0,showCamera:!0,layout:`landscape`,logo:!1,from:``,to:``};function sr(){let e;try{e=JSON.parse(window.localStorage.getItem(ar)??`null`)}catch{return or}if(!e||typeof e!=`object`)return or;let t=e,n=(e,t,n,r)=>typeof e==`number`&&Number.isFinite(e)?Math.min(n,Math.max(t,e)):r,r=typeof t.from==`string`&&typeof t.to==`string`&&dn(t.from,t.to);return{printerId:typeof t.printerId==`number`&&Number.isSafeInteger(t.printerId)&&t.printerId>0?t.printerId:null,fields:Array.isArray(t.fields)?t.fields.filter(e=>nr.some(t=>t.key===e)):rr,size:t.size===`small`||t.size===`large`?t.size:`medium`,fps:Math.round(n(t.fps,1,30,ir)),artwork:t.artwork===`2`?`2`:`1`,backgroundTransparency:n(t.backgroundTransparency,0,100,0),showCamera:t.showCamera!==!1,layout:t.layout===`portrait`||t.layout===`both`?t.layout:`landscape`,logo:t.logo===!0,from:r?t.from:``,to:r?t.to:``}}var cr=600;function lr(e){try{return window.localStorage.setItem(ar,JSON.stringify(e)),!0}catch{return!1}}function ur({onTokenCreated:e}){let{t}=l(),{showToast:n}=ee(),{user:i,hasPermission:a}=un(),[o,s]=(0,X.useState)(!1),[c,u]=(0,X.useState)(!1),[d,f]=(0,X.useState)(!1),[p,m]=(0,X.useState)(``),h=p,[g,_]=(0,X.useState)(``),[v,y]=(0,X.useState)(!1),[b]=(0,X.useState)(sr),x=(0,X.useRef)(null),S=(0,X.useRef)(!1),C=(0,X.useRef)(null),[w,T]=(0,X.useState)([]),[E,D]=(0,X.useState)(b.printerId),[O,k]=(0,X.useState)(b.fields),[A,j]=(0,X.useState)(b.size),[M,P]=(0,X.useState)(b.fps),[te,ne]=(0,X.useState)(b.artwork),[I,re]=(0,X.useState)(b.backgroundTransparency),[ie,L]=(0,X.useState)(b.showCamera),[ae,R]=(0,X.useState)({...mn,logo:b.logo,from:b.from,to:b.to}),[z,oe]=(0,X.useState)(b.layout),[se,B]=(0,X.useState)(0),[ce,le]=(0,X.useState)(!1),[ue,de]=(0,X.useState)(!1);(0,X.useEffect)(()=>{let e=!1;return(async()=>{try{let t=await r.getPrinters();if(e)return;T(t),t.length>0&&D(e=>{let n=e===null||e===b.printerId&&!t.some(t=>t.id===e)?t[0].id:e;return n!==e&&(S.current=!0),n})}catch{}})(),()=>{e=!0}},[b.printerId]),(0,X.useEffect)(()=>{let e={printerId:E,fields:O,size:A,fps:M,artwork:te,backgroundTransparency:I,showCamera:ie,layout:z,logo:ae.logo,from:ae.from,to:ae.to},r=JSON.stringify(e);if(r===x.current)return;let i=x.current===null||S.current;x.current=r,S.current=!1,!(!lr(e)||i)&&(C.current&&clearTimeout(C.current),C.current=setTimeout(()=>{C.current=null,n(t(`settings.toast.settingsSaved`))},cr))},[E,O,A,M,te,I,ie,z,ae.logo,ae.from,ae.to,n,t]),(0,X.useEffect)(()=>()=>{C.current&&clearTimeout(C.current)},[]);let fe=()=>{D(w[0]?.id??null),k(or.fields),j(or.size),P(or.fps),ne(or.artwork),re(or.backgroundTransparency),L(or.showCamera),oe(or.layout),R(e=>({...e,logo:!1,from:``,to:``})),B(e=>e+1),de(!1)},V=(0,X.useMemo)(()=>{let e=E??1,t=new URLSearchParams,n=nr.filter(e=>O.includes(e.key)).map(e=>e.key);return t.set(`show`,n.join(`,`)),A!==`medium`&&t.set(`size`,A),M!==ir&&t.set(`fps`,String(M)),te!==`1`&&t.set(`artwork`,te),te===`2`&&I>0&&t.set(`backgroundTransparency`,String(I)),ie||t.set(`camera`,`false`),ae.logo&&t.set(`logo`,`1`),ae.from&&ae.to&&(t.set(`progressFrom`,ae.from),t.set(`progressTo`,ae.to)),h.trim()&&t.set(`token`,h.trim()),(z===`both`?[`landscape`,`portrait`]:[z]).map(n=>(n===`portrait`?t.set(`layout`,n):t.delete(`layout`),{layout:n,url:`${window.location.origin}/overlay/${e}?${t.toString()}`}))},[E,O,A,M,ie,h,te,z,ae,I]),pe=e=>{let t=new URL(e);return t.searchParams.has(`token`)&&!d&&t.searchParams.set(`token`,`****`),t.toString()},me=()=>{try{let e=new URL(g.trim()),t=/^\/overlay\/([1-9]\d*)\/?$/.exec(e.pathname);if(![`http:`,`https:`].includes(e.protocol)||e.username||e.password||!t)throw Error();let n=Number(t[1]);if(!Number.isSafeInteger(n))throw Error();let r=e.searchParams;if(r.getAll(`token`).length>1)throw Error();let i=r.has(`show`)?r.get(`show`).split(`,`).filter(e=>nr.some(t=>t.key===e)):rr,a=r.get(`size`),o=a===`small`||a===`large`?a:`medium`,s=parseInt(r.get(`fps`)||`15`,10),c=Math.min(Math.max(Number.isNaN(s)?ir:s,1),30),l=Number(r.get(`backgroundTransparency`)),u=Number.isFinite(l)?Math.min(100,Math.max(0,l)):0,d=r.get(`progressFrom`),p=r.get(`progressTo`),h=dn(d,p);D(n),oe(r.get(`layout`)===`portrait`?`portrait`:`landscape`),k(i),j(o),P(c),ne(r.get(`artwork`)===`2`?`2`:`1`),L(![`false`,`0`].includes(r.get(`camera`)??``)),re(u),R(e=>({...e,logo:r.get(`logo`)===`1`,from:h?d:``,to:h?p:``})),B(e=>e+1),m(r.get(`token`)??``),de(!1),f(!1),_(``),y(!1)}catch{y(!0)}},he=e=>{k(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},ge=async e=>{try{if(navigator.clipboard&&window.isSecureContext)await navigator.clipboard.writeText(e);else{let t=document.createElement(`textarea`);t.value=e,t.style.position=`fixed`,t.style.opacity=`0`,document.body.appendChild(t);try{if(t.select(),!document.execCommand(`copy`))throw Error()}finally{document.body.removeChild(t)}}n(t(`cameraTokens.toast.copied`,`Copied to clipboard`))}catch{n(t(`cameraTokens.toast.copyFailed`,`Copy failed — select and copy manually`),`error`)}};return(0,Y.jsxs)(`div`,{className:`@container/overlay min-w-0`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4`,children:t(`streamOverlay.builder.description`,`Build the URL for a streaming overlay — a full-screen camera view with live print data drawn over it, for OBS, a wall display, or any browser source. Pick the fields you want and copy the URL.`)}),(0,Y.jsxs)(`div`,{className:`-mt-2 mb-4 flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-bambu-gray`,children:[(0,Y.jsx)(`span`,{children:t(`streamOverlay.builder.rememberedHint`)}),(0,Y.jsx)(`button`,{type:`button`,onClick:fe,disabled:c||ce,className:`text-bambu-green hover:underline disabled:opacity-50`,children:t(`streamOverlay.builder.resetChoices`)})]}),(0,Y.jsxs)(`div`,{className:`mb-4 space-y-2`,children:[(0,Y.jsx)(`label`,{htmlFor:`overlay-builder-import`,className:`block text-sm font-medium text-white`,children:t(`streamOverlay.builder.importUrl`)}),(0,Y.jsx)(`input`,{id:`overlay-builder-import`,type:`password`,autoComplete:`new-password`,spellCheck:!1,value:g,disabled:c||ce,onChange:e=>{_(e.target.value),y(!1)},className:`w-full min-w-0 px-3 py-2 bg-bambu-dark rounded-md text-white border border-bambu-dark-tertiary`}),(0,Y.jsx)(`button`,{type:`button`,disabled:c||ce||!g.trim(),onClick:me,className:`px-3 py-2 bg-bambu-dark-tertiary text-white rounded-md disabled:opacity-50`,children:t(`streamOverlay.builder.importAction`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:t(`streamOverlay.builder.importHint`)}),v&&(0,Y.jsx)(`p`,{role:`alert`,className:`text-sm text-red-400`,children:t(`streamOverlay.builder.importError`)})]}),(0,Y.jsxs)(`div`,{className:`mb-4 space-y-2`,children:[i&&a(`camera:view`)&&(0,Y.jsx)(`button`,{type:`button`,disabled:c,onClick:()=>s(e=>!e),className:`px-3 py-2 bg-bambu-dark-tertiary text-white rounded-md`,children:t(o?`common.cancel`:`streamOverlay.builder.createToken`)}),o&&i&&a(`camera:view`)&&(0,Y.jsx)(Hn,{fixedScope:`overlay`,onSubmittingChange:u,onCreated:t=>{e?.(),t.token&&(de(!1),m(t.token),f(!1),s(!1))}})]}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 @min-[28rem]/overlay:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{htmlFor:`overlay-builder-printer`,className:`block text-sm font-medium text-white mb-1`,children:t(`streamOverlay.builder.printer`,`Printer`)}),(0,Y.jsxs)(`select`,{id:`overlay-builder-printer`,value:E??``,onChange:e=>D(Number(e.target.value)),className:`w-full px-3 py-2 bg-bambu-dark rounded-md text-white border border-bambu-dark-tertiary focus:border-bambu-green focus:outline-none`,children:[w.length===0&&(0,Y.jsx)(`option`,{value:``,children:t(`common.loading`,`Loading…`)}),E!==null&&!w.some(e=>e.id===E)&&(0,Y.jsx)(`option`,{value:E,children:E}),w.map(e=>(0,Y.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{htmlFor:`overlay-builder-size`,className:`block text-sm font-medium text-white mb-1`,children:t(`streamOverlay.builder.size`,`Text size`)}),(0,Y.jsxs)(`select`,{id:`overlay-builder-size`,value:A,onChange:e=>j(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark rounded-md text-white border border-bambu-dark-tertiary focus:border-bambu-green focus:outline-none`,children:[(0,Y.jsx)(`option`,{value:`small`,children:t(`streamOverlay.builder.sizeSmall`,`Small`)}),(0,Y.jsx)(`option`,{value:`medium`,children:t(`streamOverlay.builder.sizeMedium`,`Medium`)}),(0,Y.jsx)(`option`,{value:`large`,children:t(`streamOverlay.builder.sizeLarge`,`Large`)})]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{htmlFor:`overlay-builder-layout`,className:`block text-sm font-medium text-white mb-1`,children:t(`streamOverlay.builder.layout`)}),(0,Y.jsxs)(`select`,{id:`overlay-builder-layout`,value:z,onChange:e=>{let t=e.target.value;(t===`landscape`||t===`portrait`||t===`both`)&&oe(t)},className:`w-full px-3 py-2 bg-bambu-dark rounded-md text-white border border-bambu-dark-tertiary focus:border-bambu-green focus:outline-none`,children:[(0,Y.jsx)(`option`,{value:`landscape`,children:t(`streamOverlay.builder.landscape`)}),(0,Y.jsx)(`option`,{value:`portrait`,children:t(`streamOverlay.builder.portrait`)}),(0,Y.jsx)(`option`,{value:`both`,children:t(`streamOverlay.builder.both`)})]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{htmlFor:`overlay-builder-artwork`,className:`block text-sm font-medium text-white mb-1`,children:t(`streamOverlay.builder.artwork`,`Artwork`)}),(0,Y.jsxs)(`select`,{id:`overlay-builder-artwork`,value:te,onChange:e=>ne(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark rounded-md text-white border border-bambu-dark-tertiary focus:border-bambu-green focus:outline-none`,children:[(0,Y.jsx)(`option`,{value:`1`,children:t(`streamOverlay.builder.artworkClassic`,`Classic`)}),(0,Y.jsx)(`option`,{value:`2`,children:t(`streamOverlay.builder.artworkV2`,`Version 2`)})]})]}),te===`2`&&(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`label`,{htmlFor:`overlay-builder-background-transparency`,className:`flex justify-between gap-2 text-sm font-medium text-white mb-1`,children:[(0,Y.jsx)(`span`,{children:t(`streamOverlay.builder.backgroundTransparency`)}),(0,Y.jsxs)(`span`,{"aria-hidden":`true`,children:[I,`%`]})]}),(0,Y.jsx)(`input`,{id:`overlay-builder-background-transparency`,type:`range`,min:0,max:100,step:1,value:I,"aria-valuetext":`${I}%`,onChange:e=>re(Number(e.target.value)),className:`w-full accent-bambu-green`}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:t(`streamOverlay.builder.backgroundTransparencyHint`)})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{htmlFor:`overlay-builder-fps`,className:`block text-sm font-medium text-white mb-1`,children:t(`streamOverlay.builder.fps`,`Frame rate`)}),(0,Y.jsx)(ct,{id:`overlay-builder-fps`,min:1,max:30,value:M,onChange:P,fallback:1,className:`w-full px-3 py-2 bg-bambu-dark rounded-md text-white border border-bambu-dark-tertiary focus:border-bambu-green focus:outline-none`}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:t(`streamOverlay.builder.fpsHint`,`A1 and P1 cameras top out around 5 fps whatever you ask for.`)})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{htmlFor:`overlay-builder-manual-token`,className:`block text-sm font-medium text-white mt-3 mb-1`,children:t(`streamOverlay.builder.manualToken`)}),(0,Y.jsx)(`input`,{id:`overlay-builder-manual-token`,type:d?`text`:`password`,value:p,disabled:c,autoComplete:`new-password`,spellCheck:!1,onChange:e=>{de(!1),f(!1),m(e.target.value)},placeholder:`bblt_…`,className:`w-full min-w-0 px-3 py-2 bg-bambu-dark rounded-md text-white border border-bambu-dark-tertiary`}),(0,Y.jsx)(`button`,{type:`button`,disabled:!h,onClick:()=>f(e=>!e),className:`mt-2 text-sm text-bambu-gray disabled:opacity-50`,children:t(d?`streamOverlay.builder.hideToken`:`streamOverlay.builder.showToken`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:t(`streamOverlay.builder.credentialHint`,`Create a token above, enter an existing token, or import an overlay URL. Copy the URL before leaving: tokens are held only in memory and cannot be recovered from their stored hash.`)})]})]}),(0,Y.jsxs)(`fieldset`,{className:`mt-4`,children:[(0,Y.jsx)(`legend`,{className:`text-sm font-medium text-white mb-2`,children:t(`streamOverlay.builder.fields`,`Fields to show`)}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 gap-2 @min-[24rem]/overlay:grid-cols-2 @min-[36rem]/overlay:grid-cols-3`,children:[nr.map(e=>(0,Y.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-bambu-gray`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:O.includes(e.key),onChange:()=>he(e.key),className:`accent-bambu-green`}),t(e.labelKey,e.fallback)]},e.key)),(0,Y.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-bambu-gray`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:ie,onChange:e=>L(e.target.checked),className:`accent-bambu-green`}),t(`streamOverlay.builder.fieldCamera`,`Camera feed`)]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-2`,children:t(`streamOverlay.builder.chamberHint`,`Chamber temperature only appears on models with a real chamber sensor — P1 and A1 printers report a meaningless value, so it is left out there.`)})]}),(0,Y.jsx)(tr,{value:ae,onChange:R,onBusyChange:le},se),(0,Y.jsxs)(`div`,{className:`mt-4`,children:[V.map(({layout:e,url:n})=>(0,Y.jsxs)(`fieldset`,{className:`min-w-0 mb-3`,children:[(0,Y.jsx)(`legend`,{className:`text-sm font-medium text-white mb-1`,children:t(`streamOverlay.builder.orientationUrl`,{orientation:t(`streamOverlay.builder.${e}`)})}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:t(`streamOverlay.builder.sourceDimensions`,pn[e])}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Y.jsx)(`code`,{className:`w-full px-3 py-2 bg-bambu-dark rounded-md text-bambu-green text-xs break-all font-mono`,children:pe(n)}),(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>void ge(n),className:`flex items-center gap-2 px-3 py-2 bg-bambu-green text-white rounded-md hover:bg-bambu-green/90`,children:[(0,Y.jsx)(N,{className:`w-4 h-4`}),t(`cameraTokens.created.copy`,`Copy`)]}),(0,Y.jsxs)(`a`,{href:n,target:`_blank`,rel:`noopener noreferrer`,className:`flex items-center gap-2 px-3 py-2 bg-bambu-dark-tertiary text-white rounded-md hover:bg-bambu-dark-tertiary/80`,children:[(0,Y.jsx)(Je,{className:`w-4 h-4`}),t(`streamOverlay.builder.open`,`Open`)]})]})]},e)),h.trim()&&(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-2`,children:t(`streamOverlay.builder.tokenWarning`,`This URL contains a token — anyone who can read it can watch the stream and see the file name. Revoke the token to cut it off.`)})]}),(0,Y.jsxs)(`div`,{className:`mt-4`,children:[(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>de(e=>!e),className:`flex items-center gap-2 px-3 py-2 bg-bambu-dark-tertiary text-white rounded-md hover:bg-bambu-dark-tertiary/80 text-sm`,children:[ue?(0,Y.jsx)(F,{className:`w-4 h-4`}):(0,Y.jsx)(mt,{className:`w-4 h-4`}),ue?t(`streamOverlay.builder.hidePreview`,`Hide preview`):t(`streamOverlay.builder.showPreview`,`Show preview`)]}),ue&&(0,Y.jsx)(`div`,{className:`mt-3 flex flex-wrap items-start gap-4`,children:V.map(({layout:e,url:n})=>(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1 basis-64`,style:e===`portrait`?{maxWidth:360}:void 0,children:[(0,Y.jsx)(`p`,{className:`text-sm text-white mb-2`,children:t(`streamOverlay.builder.${e}`)}),(0,Y.jsx)(`div`,{className:`overflow-hidden rounded-md border border-bambu-dark-tertiary`,children:(0,Y.jsx)(gn,{layout:e,preview:!0,children:(0,Y.jsx)(dr,{url:n,logoRevision:ae.logoRevision,title:t(`streamOverlay.builder.orientationPreview`,{orientation:t(`streamOverlay.builder.${e}`)})})})})]},e))})]})]})}function dr({url:e,logoRevision:t,title:n}){let[r,i]=(0,X.useState)({url:e,logoRevision:t});return(0,X.useEffect)(()=>{let n=window.setTimeout(()=>i({url:e,logoRevision:t}),300);return()=>window.clearTimeout(n)},[e,t]),(0,Y.jsx)(`iframe`,{src:r.url,title:n,className:`w-full h-full border-0`},`${r.url}:${r.logoRevision}`)}function fr({plug:e,onEdit:t}){let{t:n}=l(),i=u(),{showToast:a}=ee(),[o,s]=(0,X.useState)(!1),[c,p]=(0,X.useState)(!1),[m,h]=(0,X.useState)(!1),[g,_]=(0,X.useState)(!1),{data:v,isLoading:y}=d({queryKey:[`smart-plug-status`,e.id],queryFn:()=>r.getSmartPlugStatus(e.id),refetchInterval:3e4}),{data:b}=d({queryKey:[`printers`],queryFn:r.getPrinters}),x=b?.find(t=>t.id===e.printer_id),S=f({mutationFn:t=>r.controlSmartPlug(e.id,t),onMutate:async t=>{await i.cancelQueries({queryKey:[`smart-plug-status`,e.id]});let n=i.getQueryData([`smart-plug-status`,e.id]),r=t===`on`?`ON`:t===`off`||v?.state===`ON`?`OFF`:`ON`;return i.setQueryData([`smart-plug-status`,e.id],e=>({...e,state:r})),{previousStatus:n}},onError:(t,r,o)=>{o?.previousStatus&&i.setQueryData([`smart-plug-status`,e.id],o.previousStatus),a(n(`smartPlugs.failedToTurn`,{action:r,name:e.name}),`error`)},onSettled:()=>{setTimeout(()=>{i.invalidateQueries({queryKey:[`smart-plug-status`,e.id]}),i.invalidateQueries({queryKey:[`smart-plugs`]})},1e3)}}),C=f({mutationFn:t=>r.updateSmartPlug(e.id,t),onSuccess:()=>{i.invalidateQueries({queryKey:[`smart-plugs`]}),e.printer_id&&(i.invalidateQueries({queryKey:[`smartPlugByPrinter`,e.printer_id]}),i.invalidateQueries({queryKey:[`scriptPlugsByPrinter`,e.printer_id]}))}}),T=f({mutationFn:()=>r.deleteSmartPlug(e.id),onSuccess:()=>{i.invalidateQueries({queryKey:[`smart-plugs`]}),e.printer_id&&i.invalidateQueries({queryKey:[`scriptPlugsByPrinter`,e.printer_id]})}}),E=v?.state===`ON`,D=e.plug_type===`mqtt`&&v?.energy?.power!==null&&v?.energy?.power!==void 0,O=(v?.reachable??!1)||D,k=S.isPending,A=(()=>{if(e.plug_type!==`tasmota`||!e.ip_address)return null;let t=e.ip_address;return e.username&&e.password?`http://${encodeURIComponent(e.username)}:${encodeURIComponent(e.password)}@${t}/`:`http://${t}/`})();return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(G,{className:`relative`,children:(0,Y.jsxs)(W,{className:`p-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-start justify-between gap-2 mb-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 flex-1`,children:[(0,Y.jsx)(`div`,{className:`p-2 rounded-lg flex-shrink-0 ${e.plug_type===`mqtt`?O?`bg-teal-100 dark:bg-teal-500/20`:`bg-red-100 dark:bg-red-500/20`:O?E?`bg-bambu-green/20`:`bg-bambu-dark`:`bg-red-100 dark:bg-red-500/20`}`,children:e.plug_type===`mqtt`?(0,Y.jsx)(en,{className:`w-5 h-5 ${O?`text-teal-600 dark:text-teal-400`:`text-red-600 dark:text-red-400`}`}):e.plug_type===`homeassistant`?(0,Y.jsx)(Ft,{className:`w-5 h-5 ${O?E?`text-bambu-green`:`text-bambu-gray`:`text-red-600 dark:text-red-400`}`}):e.plug_type===`rest`?(0,Y.jsx)(zt,{className:`w-5 h-5 ${O?E?`text-bambu-green`:`text-bambu-gray`:`text-red-600 dark:text-red-400`}`}):(0,Y.jsx)(dt,{className:`w-5 h-5 ${O?E?`text-bambu-green`:`text-bambu-gray`:`text-red-600 dark:text-red-400`}`})}),(0,Y.jsxs)(`div`,{className:`min-w-0`,children:[(0,Y.jsx)(`h3`,{className:`font-medium text-white truncate`,children:e.name}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray truncate`,title:e.plug_type===`mqtt`?e.mqtt_topic??void 0:e.plug_type===`homeassistant`?e.ha_entity_id??void 0:e.plug_type===`rest`?e.rest_on_url??e.rest_off_url??void 0:e.ip_address??void 0,children:e.plug_type===`mqtt`?e.mqtt_topic:e.plug_type===`homeassistant`?e.ha_entity_id:e.plug_type===`rest`?e.rest_on_url||e.rest_off_url:e.ip_address})]})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col items-end gap-1 flex-shrink-0`,children:[y?(0,Y.jsx)(R,{className:`w-4 h-4 text-bambu-gray animate-spin`}):e.plug_type===`mqtt`?(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 text-sm whitespace-nowrap`,children:[(0,Y.jsx)(`span`,{className:`px-1.5 py-0.5 bg-teal-100 dark:bg-teal-500/20 text-teal-700 dark:text-teal-400 text-[10px] font-medium rounded flex-shrink-0`,children:`MQTT`}),O&&(0,Y.jsx)(`span`,{className:`text-status-ok`,children:`✓`})]}):e.plug_type===`homeassistant`?(0,Y.jsxs)(`div`,{className:`flex items-center gap-1 text-sm`,children:[(0,Y.jsx)(`span`,{className:`px-1 py-0.5 bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400 text-[10px] font-medium rounded`,children:`HA`}),(0,Y.jsx)(`span`,{className:O?E?`text-status-ok`:`text-bambu-gray`:`text-status-error`,children:O?v?.state||`?`:n(`smartPlugs.offline`)})]}):e.plug_type===`rest`?(0,Y.jsxs)(`div`,{className:`flex items-center gap-1 text-sm`,children:[(0,Y.jsx)(`span`,{className:`px-1 py-0.5 bg-purple-100 dark:bg-purple-500/20 text-purple-700 dark:text-purple-400 text-[10px] font-medium rounded`,children:`REST`}),(0,Y.jsx)(`span`,{className:O?E?`text-status-ok`:`text-bambu-gray`:`text-status-error`,children:O?v?.state||`?`:n(`smartPlugs.offline`)})]}):O?(0,Y.jsxs)(`div`,{className:`flex items-center gap-1 text-sm`,children:[(0,Y.jsx)(ht,{className:`w-4 h-4 text-status-ok`}),(0,Y.jsx)(`span`,{className:E?`text-status-ok`:`text-bambu-gray`,children:v?.state||n(`smartPlugs.unknown`)})]}):(0,Y.jsxs)(`div`,{className:`flex items-center gap-1 text-sm text-status-error`,children:[(0,Y.jsx)(Ye,{className:`w-4 h-4`}),(0,Y.jsx)(`span`,{children:n(`smartPlugs.offline`)})]}),A&&(0,Y.jsxs)(`a`,{href:A,target:`_blank`,rel:`noopener noreferrer`,className:`flex items-center gap-1 px-2 py-0.5 bg-bambu-dark hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white text-xs rounded-full transition-colors`,title:n(`smartPlugs.openPlugAdminPage`),children:[(0,Y.jsx)(Je,{className:`w-3 h-3`}),n(`smartPlugs.admin`)]})]})]}),x&&(0,Y.jsxs)(`div`,{className:`mb-3 px-2 py-1.5 bg-bambu-dark rounded-lg`,children:[(0,Y.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[n(`smartPlugs.linkedTo`),` `]}),(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:x.name})]}),(e.power_alert_enabled||e.schedule_enabled||e.plug_type===`mqtt`)&&(0,Y.jsxs)(`div`,{className:`flex flex-wrap gap-1.5 mb-3`,children:[e.plug_type===`mqtt`&&(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 px-2 py-0.5 bg-teal-100 dark:bg-teal-500/20 text-teal-700 dark:text-teal-400 text-xs rounded-full`,children:[(0,Y.jsx)(mt,{className:`w-3 h-3`}),n(`smartPlugs.monitorOnly`)]}),e.power_alert_enabled&&(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 px-2 py-0.5 bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400 text-xs rounded-full`,children:[(0,Y.jsx)(rt,{className:`w-3 h-3`}),n(`smartPlugs.alerts`)]}),e.schedule_enabled&&(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 px-2 py-0.5 bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400 text-xs rounded-full`,children:[(0,Y.jsx)(w,{className:`w-3 h-3`}),e.schedule_on_time&&e.schedule_off_time?`${e.schedule_on_time} - ${e.schedule_off_time}`:e.schedule_on_time?n(`smartPlugs.scheduleOn`,{time:e.schedule_on_time}):n(`smartPlugs.scheduleOff`,{time:e.schedule_off_time})]})]}),e.plug_type!==`mqtt`&&(0,Y.jsxs)(`div`,{className:`flex gap-2 mb-3`,children:[(0,Y.jsxs)(K,{size:`sm`,variant:E?`primary`:`secondary`,disabled:!O||k,onClick:()=>p(!0),className:`flex-1`,children:[k?(0,Y.jsx)(R,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(Ct,{className:`w-4 h-4`}),n(`smartPlugs.on`)]}),(0,Y.jsxs)(K,{size:`sm`,variant:E?`secondary`:`primary`,disabled:!O||k,onClick:()=>h(!0),className:`flex-1`,children:[k?(0,Y.jsx)(R,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(St,{className:`w-4 h-4`}),n(`smartPlugs.off`)]})]}),e.plug_type===`mqtt`&&v?.energy&&(0,Y.jsxs)(`div`,{className:`flex gap-2 mb-3 px-3 py-2 bg-bambu-dark rounded-lg`,children:[v.energy.power!==null&&v.energy.power!==void 0&&(0,Y.jsxs)(`div`,{className:`flex-1 text-center`,children:[(0,Y.jsxs)(`p`,{className:`text-lg font-semibold text-white`,children:[Math.round(v.energy.power),`W`]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.power`)})]}),v.energy.today!==null&&v.energy.today!==void 0&&(0,Y.jsxs)(`div`,{className:`flex-1 text-center border-l border-bambu-dark-tertiary`,children:[(0,Y.jsx)(`p`,{className:`text-lg font-semibold text-white`,children:v.energy.today.toFixed(3)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.kwhToday`)})]})]}),(0,Y.jsxs)(`button`,{onClick:()=>_(!g),className:`w-full flex items-center justify-between py-2 text-sm text-bambu-gray hover:text-white transition-colors`,children:[(0,Y.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(je,{className:`w-4 h-4`}),e.plug_type===`mqtt`?n(`smartPlugs.settings`):n(`smartPlugs.automationSettings`)]}),(0,Y.jsx)(`span`,{children:g?`-`:`+`})]}),g&&(0,Y.jsxs)(`div`,{className:`pt-3 border-t border-bambu-dark-tertiary space-y-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(L,{className:`w-4 h-4 text-bambu-green`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`smartPlugs.showInSwitchbar`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.quickAccessSidebar`)})]})]}),(0,Y.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:e.show_in_switchbar,onChange:e=>C.mutate({show_in_switchbar:e.target.checked}),className:`sr-only peer`}),(0,Y.jsx)(`div`,{className:`w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green`})]})]}),e.printer_id!=null&&(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(Ct,{className:`w-4 h-4 text-bambu-green`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`smartPlugs.controlsPrinterPower`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.controlsPrinterPowerDescription`)})]})]}),(0,Y.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:e.controls_printer_power,onChange:e=>C.mutate({controls_printer_power:e.target.checked}),className:`sr-only peer`}),(0,Y.jsx)(`div`,{className:`w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green`})]})]}),e.plug_type!==`mqtt`&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`smartPlugs.enabled`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.enableAutomation`)})]}),(0,Y.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:e.enabled,onChange:e=>C.mutate({enabled:e.target.checked}),className:`sr-only peer`}),(0,Y.jsx)(`div`,{className:`w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`smartPlugs.autoOn`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.autoOnDescription`)})]}),(0,Y.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:e.auto_on,onChange:e=>C.mutate({auto_on:e.target.checked}),className:`sr-only peer`}),(0,Y.jsx)(`div`,{className:`w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`smartPlugs.autoOff`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.autoOffDescription`)})]}),(0,Y.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:e.auto_off,onChange:e=>C.mutate({auto_off:e.target.checked}),className:`sr-only peer`}),(0,Y.jsx)(`div`,{className:`w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green`})]})]}),e.auto_off&&(0,Y.jsxs)(`div`,{className:`flex items-center justify-between pl-4 border-l-2 border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`smartPlugs.autoOffPersistent`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.autoOffPersistentDescription`)})]}),(0,Y.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:e.auto_off_persistent,onChange:e=>C.mutate({auto_off_persistent:e.target.checked}),className:`sr-only peer`}),(0,Y.jsx)(`div`,{className:`w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green`})]})]}),e.auto_off&&(0,Y.jsxs)(`div`,{className:`space-y-3 pl-4 border-l-2 border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white mb-2`,children:n(`smartPlugs.turnOffDelayMode`)}),(0,Y.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Y.jsxs)(`button`,{onClick:()=>C.mutate({off_delay_mode:`time`}),className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg text-sm transition-colors ${e.off_delay_mode===`time`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,children:[(0,Y.jsx)(lt,{className:`w-4 h-4`}),n(`smartPlugs.time`)]}),(0,Y.jsxs)(`button`,{onClick:()=>C.mutate({off_delay_mode:`temperature`}),className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg text-sm transition-colors ${e.off_delay_mode===`temperature`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,children:[(0,Y.jsx)(Fe,{className:`w-4 h-4`}),n(`smartPlugs.temp`)]})]})]}),e.off_delay_mode===`time`?(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:n(`smartPlugs.delayMinutes`)}),(0,Y.jsx)(ct,{min:1,max:60,value:e.off_delay_minutes,onChange:e=>C.mutate({off_delay_minutes:e}),fallback:5,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`})]}):(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:n(`smartPlugs.tempThreshold`)}),(0,Y.jsx)(ct,{min:30,max:100,value:e.off_temp_threshold,onChange:e=>C.mutate({off_temp_threshold:e}),fallback:70,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(`smartPlugs.tempThresholdDescription`)})]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`smartPlugs.autoOffAfterDrying`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.autoOffAfterDryingDescription`)})]}),(0,Y.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:e.auto_off_after_drying,onChange:e=>C.mutate({auto_off_after_drying:e.target.checked}),className:`sr-only peer`}),(0,Y.jsx)(`div`,{className:`w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green`})]})]}),e.auto_off_after_drying&&(0,Y.jsxs)(`div`,{className:`pl-4 border-l-2 border-bambu-dark-tertiary`,children:[(0,Y.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:n(`smartPlugs.delayAfterDryingMinutes`)}),(0,Y.jsx)(ct,{min:0,max:120,value:e.off_delay_after_drying_minutes,onChange:e=>C.mutate({off_delay_after_drying_minutes:e}),fallback:10,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`})]})]}),(0,Y.jsxs)(`div`,{className:`flex gap-2 pt-2`,children:[(0,Y.jsxs)(K,{size:`sm`,variant:`secondary`,onClick:()=>t(e),className:`flex-1`,children:[(0,Y.jsx)(oe,{className:`w-4 h-4`}),n(`smartPlugs.edit`)]}),(0,Y.jsx)(K,{size:`sm`,variant:`secondary`,onClick:()=>s(!0),className:`text-red-600 dark:text-red-400 hover:text-red-700 dark:hover:text-red-300`,children:(0,Y.jsx)(qe,{className:`w-4 h-4`})})]})]})]})}),o&&(0,Y.jsx)(Tt,{title:n(`smartPlugs.deleteSmartPlug`),message:n(`smartPlugs.deleteConfirm`,{name:e.name}),confirmText:n(`smartPlugs.delete`),variant:`danger`,onConfirm:()=>{T.mutate(),s(!1)},onCancel:()=>s(!1)}),c&&(0,Y.jsx)(Tt,{title:n(`smartPlugs.turnOnSmartPlug`),message:n(`smartPlugs.turnOnConfirm`,{name:e.name}),confirmText:n(`smartPlugs.turnOn`),variant:`default`,onConfirm:()=>{S.mutate(`on`),p(!1)},onCancel:()=>p(!1)}),m&&(0,Y.jsx)(Tt,{title:n(`smartPlugs.turnOffSmartPlug`),message:n(`smartPlugs.turnOffConfirm`,{name:e.name}),confirmText:n(`smartPlugs.turnOff`),variant:`danger`,onConfirm:()=>{S.mutate(`off`),h(!1)},onCancel:()=>h(!1)})]})}function pr({plug:e,onClose:t}){let{t:n}=l(),i=u(),a=!!e,[o,s]=(0,X.useState)(e?.plug_type||`tasmota`),[c,p]=(0,X.useState)(e?.name||``),[m,h]=(0,X.useState)(e?.ip_address||``),[g,_]=(0,X.useState)(e?.username||``),[v,y]=(0,X.useState)(e?.password||``),[b,x]=(0,X.useState)(e?.ha_entity_id||``),[S,C]=(0,X.useState)(e?.mqtt_power_topic||e?.mqtt_topic||``),[w,T]=(0,X.useState)(e?.mqtt_power_path||``),[E,D]=(0,X.useState)((e?.mqtt_power_multiplier??e?.mqtt_multiplier??1).toString()),[O,k]=(0,X.useState)(e?.mqtt_energy_topic||``),[A,ee]=(0,X.useState)(e?.mqtt_energy_path||``),[M,N]=(0,X.useState)((e?.mqtt_energy_multiplier??1).toString()),[P,te]=(0,X.useState)(e?.mqtt_state_topic||``),[F,ne]=(0,X.useState)(e?.mqtt_state_path||``),[I,re]=(0,X.useState)(e?.mqtt_state_on_value||``),[ie,ae]=(0,X.useState)(e?.rest_on_url||``),[z,oe]=(0,X.useState)(e?.rest_on_body||``),[se,B]=(0,X.useState)(e?.rest_off_url||``),[ce,le]=(0,X.useState)(e?.rest_off_body||``),[ue,de]=(0,X.useState)(e?.rest_method||`POST`),[fe,V]=(0,X.useState)(e?.rest_headers||``),[pe,me]=(0,X.useState)(e?.rest_status_url||``),[he,ge]=(0,X.useState)(e?.rest_status_path||``),[_e,ve]=(0,X.useState)(e?.rest_status_on_value||``),[ye,be]=(0,X.useState)(e?.rest_power_url||``),[H,xe]=(0,X.useState)(e?.rest_power_path||``),[Se,Ce]=(0,X.useState)((e?.rest_power_multiplier??1).toString()),[we,Te]=(0,X.useState)(e?.rest_energy_url||``),[Ee,De]=(0,X.useState)(e?.rest_energy_path||``),[Oe,ke]=(0,X.useState)((e?.rest_energy_multiplier??1).toString()),[je,Me]=(0,X.useState)(e?.rest_energy_total_path||``),[Ne,Pe]=(0,X.useState)((e?.rest_energy_total_multiplier??1).toString()),[Fe,Ie]=(0,X.useState)(e?.ha_power_entity||``),[Le,U]=(0,X.useState)(e?.ha_energy_today_entity||``),[W,ze]=(0,X.useState)(e?.ha_energy_total_entity||``),[G,Be]=(0,X.useState)(``),[Ve,He]=(0,X.useState)(``),[Ue,We]=(0,X.useState)(!1),Ge=(0,X.useRef)(null),[Ke,q]=(0,X.useState)(``),[qe,Je]=(0,X.useState)(!1),Xe=(0,X.useRef)(null),[Ze,Qe]=(0,X.useState)(``),[$e,et]=(0,X.useState)(!1),tt=(0,X.useRef)(null),[nt,it]=(0,X.useState)(``),[at,ot]=(0,X.useState)(!1),st=(0,X.useRef)(null),[ct,ut]=(0,X.useState)(e?.printer_id||null),[ft,pt]=(0,X.useState)(e?.controls_printer_power??!0),[gt,vt]=(0,X.useState)(null),[yt,bt]=(0,X.useState)(null),[xt,St]=(0,X.useState)(e?.power_alert_enabled||!1),[wt,Tt]=(0,X.useState)(e?.power_alert_high?.toString()||``),[Et,Dt]=(0,X.useState)(e?.power_alert_low?.toString()||``),[Ot,kt]=(0,X.useState)(e?.schedule_enabled||!1),[At,jt]=(0,X.useState)(e?.schedule_on_time||``),[Mt,Nt]=(0,X.useState)(e?.schedule_off_time||``),[Pt,It]=(0,X.useState)(e?.show_in_switchbar||!1),[Lt,Rt]=(0,X.useState)(e?.show_on_printer_card??!0),[Bt,Vt]=(0,X.useState)(!1),[Ht,Ut]=(0,X.useState)({scanned:0,total:0}),[Wt,Gt]=(0,X.useState)([]),Kt=(0,X.useRef)(null),{data:qt}=d({queryKey:[`printers`],queryFn:r.getPrinters}),{data:Jt}=d({queryKey:[`smart-plugs`],queryFn:r.getSmartPlugs}),{data:Yt}=d({queryKey:[`settings`],queryFn:r.getSettings}),Xt=!!(Yt?.ha_enabled&&Yt?.ha_url&&Yt?.ha_token);(0,X.useEffect)(()=>{let e=setTimeout(()=>{He(G)},300);return()=>clearTimeout(e)},[G]),(0,X.useEffect)(()=>{let e=e=>{Ge.current&&!Ge.current.contains(e.target)&&We(!1),Xe.current&&!Xe.current.contains(e.target)&&Je(!1),tt.current&&!tt.current.contains(e.target)&&et(!1),st.current&&!st.current.contains(e.target)&&ot(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[]);let{data:Zt,isLoading:Qt,error:$t}=d({queryKey:[`ha-entities`,Ve],queryFn:()=>r.getHAEntities(Ve||void 0),enabled:o===`homeassistant`&&Xt,retry:!1,staleTime:0}),{data:tn}=d({queryKey:[`ha-sensor-entities`],queryFn:r.getHASensorEntities,enabled:o===`homeassistant`&&Xt,retry:!1,staleTime:0});(0,X.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,e),()=>{window.removeEventListener(`keydown`,e),Kt.current&&clearInterval(Kt.current)}},[t]);let nn=async()=>{Vt(!0),Gt([]),Ut({scanned:0,total:0}),bt(null);try{await r.startTasmotaScan();let e=async()=>{try{let e=await r.getTasmotaScanStatus();Ut({scanned:e.scanned,total:e.total}),Gt(await r.getDiscoveredTasmotaDevices()),e.running||(Vt(!1),Kt.current&&=(clearInterval(Kt.current),null))}catch(e){console.error(`Polling error:`,e)}};await e(),Kt.current=setInterval(e,500)}catch(e){Vt(!1),bt((e instanceof Error?e.message:typeof e==`string`?e:JSON.stringify(e))||n(`smartPlugs.failedToStartScan`))}},rn=async()=>{try{await r.stopTasmotaScan()}catch{}Vt(!1),Kt.current&&=(clearInterval(Kt.current),null)},an=e=>{h(e.ip_address),p(e.name),vt(null)},on=f({mutationFn:()=>r.testSmartPlugConnection(m,g||null,v||null),onSuccess:e=>{vt(e),bt(null),!c&&e.device_name&&p(e.device_name)},onError:e=>{vt(null),bt(e.message)}}),sn=f({mutationFn:e=>r.createSmartPlug(e),onSuccess:()=>{i.invalidateQueries({queryKey:[`smart-plugs`]}),i.invalidateQueries({queryKey:[`scriptPlugsByPrinter`]}),t()},onError:e=>{bt(e.message)}}),cn=f({mutationFn:t=>r.updateSmartPlug(e.id,t),onSuccess:()=>{i.invalidateQueries({queryKey:[`smart-plugs`]}),i.invalidateQueries({queryKey:[`scriptPlugsByPrinter`]}),t()},onError:e=>{bt(e.message)}}),ln=qt?.filter(t=>o===`tasmota`?!Jt?.some(n=>n.printer_id===t.id&&n.id!==e?.id&&n.plug_type===`tasmota`):!0),un=e=>{if(e.preventDefault(),bt(null),!c.trim()){bt(n(`smartPlugs.nameRequired`));return}if(o===`tasmota`&&!m.trim()){bt(`IP address is required for Tasmota plugs`);return}if(o===`homeassistant`&&!b){bt(n(`smartPlugs.entityRequired`));return}if(o===`mqtt`){let e=S.trim(),t=O.trim(),r=P.trim();if(!e&&!t&&!r){bt(n(`smartPlugs.mqttTopicRequired`));return}}if(o===`rest`&&!ie.trim()&&!se.trim()){bt(n(`smartPlugs.restUrlRequired`));return}let t={name:c.trim(),plug_type:o,ip_address:o===`tasmota`?m.trim():null,ha_entity_id:o===`homeassistant`?b:null,ha_power_entity:o===`homeassistant`&&Fe||null,ha_energy_today_entity:o===`homeassistant`&&Le||null,ha_energy_total_entity:o===`homeassistant`&&W||null,mqtt_power_topic:o===`mqtt`&&S.trim()||null,mqtt_power_path:o===`mqtt`&&w.trim()||null,mqtt_power_multiplier:o===`mqtt`&&parseFloat(E)||1,mqtt_energy_topic:o===`mqtt`&&O.trim()||null,mqtt_energy_path:o===`mqtt`&&A.trim()||null,mqtt_energy_multiplier:o===`mqtt`&&parseFloat(M)||1,mqtt_state_topic:o===`mqtt`&&P.trim()||null,mqtt_state_path:o===`mqtt`&&F.trim()||null,mqtt_state_on_value:o===`mqtt`&&I.trim()||null,rest_on_url:o===`rest`&&ie.trim()||null,rest_on_body:o===`rest`&&z.trim()||null,rest_off_url:o===`rest`&&se.trim()||null,rest_off_body:o===`rest`&&ce.trim()||null,rest_method:o===`rest`?ue:null,rest_headers:o===`rest`&&fe.trim()||null,rest_status_url:o===`rest`&&pe.trim()||null,rest_status_path:o===`rest`&&he.trim()||null,rest_status_on_value:o===`rest`&&_e.trim()||null,rest_power_url:o===`rest`&&ye.trim()||null,rest_power_path:o===`rest`&&H.trim()||null,rest_power_multiplier:o===`rest`&&parseFloat(Se)||1,rest_energy_url:o===`rest`&&we.trim()||null,rest_energy_path:o===`rest`&&Ee.trim()||null,rest_energy_multiplier:o===`rest`&&parseFloat(Oe)||1,rest_energy_total_path:o===`rest`&&je.trim()||null,rest_energy_total_multiplier:o===`rest`&&parseFloat(Ne)||1,username:o===`tasmota`&&g.trim()||null,password:o===`tasmota`&&v.trim()||null,printer_id:ct,controls_printer_power:ft,power_alert_enabled:xt,power_alert_high:wt?parseFloat(wt):null,power_alert_low:Et?parseFloat(Et):null,schedule_enabled:Ot,schedule_on_time:At||null,schedule_off_time:Mt||null,show_in_switchbar:Pt,show_on_printer_card:Lt};a?cn.mutate(t):sn.mutate(t)},J=sn.isPending||cn.isPending;return(0,Y.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:t,children:(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-md max-h-[90vh] flex flex-col`,onClick:e=>e.stopPropagation(),children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary flex-shrink-0`,children:[(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:n(a?`smartPlugs.editTitle`:`smartPlugs.addTitle`)}),(0,Y.jsx)(`button`,{onClick:t,className:`text-bambu-gray hover:text-white transition-colors`,children:(0,Y.jsx)(Re,{className:`w-5 h-5`})})]}),(0,Y.jsxs)(`form`,{onSubmit:un,className:`p-6 space-y-4 overflow-y-auto`,children:[yt&&(0,Y.jsx)(`div`,{className:`p-3 bg-red-100 dark:bg-red-500/20 border border-red-400 dark:border-red-500/50 rounded-lg text-sm text-red-700 dark:text-red-400`,children:yt}),!a&&(0,Y.jsxs)(`div`,{className:`flex gap-2 mb-2`,children:[(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>{s(`tasmota`),vt(null),bt(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2.5 rounded-lg font-medium transition-colors ${o===`tasmota`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white border border-bambu-dark-tertiary`}`,children:[(0,Y.jsx)(dt,{className:`w-4 h-4`}),`Tasmota`]}),(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>{s(`homeassistant`),vt(null),bt(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2.5 rounded-lg font-medium transition-colors ${o===`homeassistant`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white border border-bambu-dark-tertiary`}`,children:[(0,Y.jsx)(Ft,{className:`w-4 h-4`}),`HA`]}),(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>{s(`mqtt`),vt(null),bt(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2.5 rounded-lg font-medium transition-colors ${o===`mqtt`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white border border-bambu-dark-tertiary`}`,children:[(0,Y.jsx)(en,{className:`w-4 h-4`}),`MQTT`]}),(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>{s(`rest`),vt(null),bt(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2.5 rounded-lg font-medium transition-colors ${o===`rest`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white border border-bambu-dark-tertiary`}`,children:[(0,Y.jsx)(zt,{className:`w-4 h-4`}),`REST`]})]}),!a&&o===`tasmota`&&(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[Bt?(0,Y.jsxs)(K,{type:`button`,variant:`secondary`,onClick:rn,className:`w-full`,children:[(0,Y.jsx)(Re,{className:`w-4 h-4`}),n(`smartPlugs.stopScanning`)]}):(0,Y.jsxs)(K,{type:`button`,variant:`primary`,onClick:nn,className:`w-full`,children:[(0,Y.jsx)(Ae,{className:`w-4 h-4`}),n(`smartPlugs.discoverTasmota`)]}),Bt&&Ht.total>0&&(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsxs)(`div`,{className:`flex justify-between text-xs text-bambu-gray`,children:[(0,Y.jsx)(`span`,{children:n(`smartPlugs.addSmartPlug.scanningNetwork`)}),(0,Y.jsxs)(`span`,{children:[Ht.scanned,` / `,Ht.total]})]}),(0,Y.jsx)(`div`,{className:`w-full bg-bambu-dark-tertiary rounded-full h-2`,children:(0,Y.jsx)(`div`,{className:`bg-bambu-green h-2 rounded-full transition-all duration-300`,style:{width:`${Ht.scanned/Ht.total*100}%`}})})]}),Wt.length>0&&(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.foundDevices`,{count:Wt.length})}),(0,Y.jsx)(`div`,{className:`max-h-40 overflow-y-auto space-y-1`,children:Wt.map(e=>(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>an(e),className:`w-full flex items-center justify-between p-2 bg-bambu-dark hover:bg-bambu-dark-tertiary rounded-lg transition-colors text-left border border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(dt,{className:`w-4 h-4 text-bambu-green`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:e.name}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:e.ip_address})]})]}),e.state&&(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 text-xs ${e.state===`ON`?`text-bambu-green`:`text-bambu-gray`}`,children:[(0,Y.jsx)(Ct,{className:`w-3 h-3`}),e.state]})]},e.ip_address))})]}),!Bt&&Wt.length===0&&Ht.total>0&&(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray text-center py-2`,children:n(`smartPlugs.noDevicesFound`)})]}),o===`homeassistant`&&(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[!Xt&&(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`p-3 bg-yellow-100 dark:bg-yellow-500/20 border border-yellow-400 dark:border-yellow-500/50 rounded-lg text-sm text-yellow-700 dark:text-yellow-400`,children:[n(`smartPlugs.haNotConfigured`),` `,(0,Y.jsx)(`span`,{className:`font-medium`,children:n(`smartPlugs.haSettingsPath`)})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1 opacity-50`,children:n(`smartPlugs.selectEntity`)}),(0,Y.jsx)(`select`,{disabled:!0,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray cursor-not-allowed opacity-50`,children:(0,Y.jsx)(`option`,{children:n(`smartPlugs.addSmartPlug.chooseEntity`)})})]})]}),Xt&&(0,Y.jsxs)(Y.Fragment,{children:[Qt&&(0,Y.jsxs)(`div`,{className:`flex items-center justify-center py-4 text-bambu-gray`,children:[(0,Y.jsx)(R,{className:`w-5 h-5 animate-spin mr-2`}),n(`smartPlugs.loadingEntities`)]}),$t&&(0,Y.jsx)(`div`,{className:`p-3 bg-red-100 dark:bg-red-500/20 border border-red-400 dark:border-red-500/50 rounded-lg text-sm text-red-700 dark:text-red-400`,children:n(`smartPlugs.failedToLoadEntities`,{error:$t.message})}),(()=>{let t=Jt?.filter(t=>t.ha_entity_id&&t.id!==e?.id).map(e=>e.ha_entity_id)||[],r=(Zt||[]).filter(e=>!t.includes(e.entity_id)),i=Zt?.find(e=>e.entity_id===b);return(0,Y.jsxs)(`div`,{ref:Ge,className:`relative`,children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.selectEntity`)}),(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsx)(Ae,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`}),(0,Y.jsx)(`input`,{type:`text`,value:Ue?G:i?`${i.friendly_name} (${i.entity_id})`:``,onChange:e=>{Be(e.target.value),Ue||We(!0)},onFocus:()=>{We(!0),Be(``)},placeholder:n(`smartPlugs.addSmartPlug.placeholders.searchEntities`),className:`w-full pl-9 pr-8 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`}),b&&!Ue&&(0,Y.jsx)(`button`,{type:`button`,onClick:()=>{x(``),Be(``)},className:`absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-bambu-dark-tertiary rounded`,children:(0,Y.jsx)(Re,{className:`w-4 h-4 text-bambu-gray hover:text-white`})}),Qt&&(0,Y.jsx)(R,{className:`absolute right-2 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray animate-spin`})]}),Ue&&(0,Y.jsxs)(`div`,{className:`absolute z-50 w-full mt-1 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-60 overflow-y-auto`,children:[Qt&&(0,Y.jsxs)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray flex items-center gap-2`,children:[(0,Y.jsx)(R,{className:`w-4 h-4 animate-spin`}),n(`smartPlugs.loading`)]}),!Qt&&r.length===0&&(0,Y.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:Ve?n(`smartPlugs.noEntitiesMatching`,{search:Ve}):n(`smartPlugs.noEntitiesAvailable`)}),!Qt&&r.map(e=>(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>{x(e.entity_id),We(!1),Be(``),c||p(e.friendly_name)},className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary transition-colors ${e.entity_id===b?`bg-bambu-green/20 text-bambu-green`:`text-white`}`,children:[(0,Y.jsx)(`div`,{className:`font-medium`,children:e.friendly_name}),(0,Y.jsxs)(`div`,{className:`text-xs text-bambu-gray flex items-center justify-between`,children:[(0,Y.jsx)(`span`,{children:e.entity_id}),(0,Y.jsx)(`span`,{className:e.state===`on`?`text-bambu-green`:``,children:e.state})]})]},e.entity_id))]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(Ve?`smartPlugs.searchingEntities`:`smartPlugs.showingEntities`,{count:r.length})})]})})(),b&&tn&&tn.length>0&&(0,Y.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary pt-4 mt-4 space-y-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-white font-medium mb-1`,children:n(`smartPlugs.energyMonitoringOptional`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mb-3`,children:n(`smartPlugs.energyMonitoringHint`)})]}),(()=>{let e=tn.filter(e=>e.unit_of_measurement===`W`||e.unit_of_measurement===`kW`||e.unit_of_measurement===`mW`),t=Ke?e.filter(e=>e.entity_id.toLowerCase().includes(Ke.toLowerCase())||e.friendly_name.toLowerCase().includes(Ke.toLowerCase())):e,r=tn.find(e=>e.entity_id===Fe);return(0,Y.jsxs)(`div`,{ref:Xe,className:`relative`,children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.powerSensorW`)}),(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsx)(Ae,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`}),(0,Y.jsx)(`input`,{type:`text`,value:qe?Ke:r?`${r.friendly_name} (${r.state} ${r.unit_of_measurement})`:``,onChange:e=>{q(e.target.value),qe||Je(!0)},onFocus:()=>{Je(!0),q(``)},placeholder:n(`smartPlugs.addSmartPlug.placeholders.searchPowerSensors`),className:`w-full pl-9 pr-8 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`}),Fe&&!qe&&(0,Y.jsx)(`button`,{type:`button`,onClick:()=>{Ie(``),q(``)},className:`absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-bambu-dark-tertiary rounded`,children:(0,Y.jsx)(Re,{className:`w-4 h-4 text-bambu-gray hover:text-white`})})]}),qe&&(0,Y.jsxs)(`div`,{className:`absolute z-50 w-full mt-1 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-48 overflow-y-auto`,children:[(0,Y.jsx)(`button`,{type:`button`,onClick:()=>{Ie(``),Je(!1),q(``)},className:`w-full px-3 py-2 text-left text-sm text-bambu-gray hover:bg-bambu-dark-tertiary`,children:n(`smartPlugs.none`)}),t.map(e=>(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>{Ie(e.entity_id),Je(!1),q(``)},className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${e.entity_id===Fe?`bg-bambu-green/20 text-bambu-green`:`text-white`}`,children:[(0,Y.jsx)(`div`,{className:`font-medium`,children:e.friendly_name}),(0,Y.jsxs)(`div`,{className:`text-xs text-bambu-gray`,children:[e.entity_id,` • `,e.state,` `,e.unit_of_measurement]})]},e.entity_id)),t.length===0&&(0,Y.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:n(`smartPlugs.noMatchingSensors`)})]})]})})(),(()=>{let e=tn.filter(e=>e.unit_of_measurement===`kWh`||e.unit_of_measurement===`Wh`||e.unit_of_measurement===`MWh`),t=Ze?e.filter(e=>e.entity_id.toLowerCase().includes(Ze.toLowerCase())||e.friendly_name.toLowerCase().includes(Ze.toLowerCase())):e,r=tn.find(e=>e.entity_id===Le);return(0,Y.jsxs)(`div`,{ref:tt,className:`relative`,children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.energyTodayKwh`)}),(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsx)(Ae,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`}),(0,Y.jsx)(`input`,{type:`text`,value:$e?Ze:r?`${r.friendly_name} (${r.state} ${r.unit_of_measurement})`:``,onChange:e=>{Qe(e.target.value),$e||et(!0)},onFocus:()=>{et(!0),Qe(``)},placeholder:n(`smartPlugs.addSmartPlug.placeholders.searchEnergySensors`),className:`w-full pl-9 pr-8 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`}),Le&&!$e&&(0,Y.jsx)(`button`,{type:`button`,onClick:()=>{U(``),Qe(``)},className:`absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-bambu-dark-tertiary rounded`,children:(0,Y.jsx)(Re,{className:`w-4 h-4 text-bambu-gray hover:text-white`})})]}),$e&&(0,Y.jsxs)(`div`,{className:`absolute z-50 w-full mt-1 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-48 overflow-y-auto`,children:[(0,Y.jsx)(`button`,{type:`button`,onClick:()=>{U(``),et(!1),Qe(``)},className:`w-full px-3 py-2 text-left text-sm text-bambu-gray hover:bg-bambu-dark-tertiary`,children:n(`smartPlugs.none`)}),t.map(e=>(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>{U(e.entity_id),et(!1),Qe(``)},className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${e.entity_id===Le?`bg-bambu-green/20 text-bambu-green`:`text-white`}`,children:[(0,Y.jsx)(`div`,{className:`font-medium`,children:e.friendly_name}),(0,Y.jsxs)(`div`,{className:`text-xs text-bambu-gray`,children:[e.entity_id,` • `,e.state,` `,e.unit_of_measurement]})]},e.entity_id)),t.length===0&&(0,Y.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:n(`smartPlugs.noMatchingSensors`)})]})]})})(),(()=>{let e=tn.filter(e=>e.unit_of_measurement===`kWh`||e.unit_of_measurement===`Wh`||e.unit_of_measurement===`MWh`),t=nt?e.filter(e=>e.entity_id.toLowerCase().includes(nt.toLowerCase())||e.friendly_name.toLowerCase().includes(nt.toLowerCase())):e,r=tn.find(e=>e.entity_id===W);return(0,Y.jsxs)(`div`,{ref:st,className:`relative`,children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.totalEnergyKwh`)}),(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsx)(Ae,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`}),(0,Y.jsx)(`input`,{type:`text`,value:at?nt:r?`${r.friendly_name} (${r.state} ${r.unit_of_measurement})`:``,onChange:e=>{it(e.target.value),at||ot(!0)},onFocus:()=>{ot(!0),it(``)},placeholder:n(`smartPlugs.addSmartPlug.placeholders.searchEnergySensors`),className:`w-full pl-9 pr-8 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`}),W&&!at&&(0,Y.jsx)(`button`,{type:`button`,onClick:()=>{ze(``),it(``)},className:`absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-bambu-dark-tertiary rounded`,children:(0,Y.jsx)(Re,{className:`w-4 h-4 text-bambu-gray hover:text-white`})})]}),at&&(0,Y.jsxs)(`div`,{className:`absolute z-50 w-full mt-1 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-48 overflow-y-auto`,children:[(0,Y.jsx)(`button`,{type:`button`,onClick:()=>{ze(``),ot(!1),it(``)},className:`w-full px-3 py-2 text-left text-sm text-bambu-gray hover:bg-bambu-dark-tertiary`,children:n(`smartPlugs.none`)}),t.map(e=>(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>{ze(e.entity_id),ot(!1),it(``)},className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${e.entity_id===W?`bg-bambu-green/20 text-bambu-green`:`text-white`}`,children:[(0,Y.jsx)(`div`,{className:`font-medium`,children:e.friendly_name}),(0,Y.jsxs)(`div`,{className:`text-xs text-bambu-gray`,children:[e.entity_id,` • `,e.state,` `,e.unit_of_measurement]})]},e.entity_id)),t.length===0&&(0,Y.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:n(`smartPlugs.noMatchingSensors`)})]})]})})()]})]})]}),o===`mqtt`&&(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[!Yt?.mqtt_broker&&(0,Y.jsxs)(`div`,{className:`p-3 bg-yellow-100 dark:bg-yellow-500/20 border border-yellow-400 dark:border-yellow-500/50 rounded-lg text-sm text-yellow-700 dark:text-yellow-400`,children:[n(`smartPlugs.mqttNotConfigured`),` `,(0,Y.jsx)(`span`,{className:`font-medium`,children:n(`smartPlugs.mqttSettingsPath`)}),` `,n(`smartPlugs.mqttNotConfiguredSuffix`)]}),Yt?.mqtt_broker&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`div`,{className:`p-3 bg-blue-50 dark:bg-blue-500/10 border border-blue-300 dark:border-blue-500/30 rounded-lg text-sm text-blue-700 dark:text-blue-300`,children:[(0,Y.jsx)(`p`,{className:`font-medium mb-1`,children:n(`smartPlugs.monitorOnly`)}),(0,Y.jsx)(`p`,{className:`text-xs opacity-80`,children:n(`smartPlugs.mqttMonitorOnlyDescription`)})]}),(0,Y.jsxs)(`div`,{className:`space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,Y.jsx)(`p`,{className:`text-white font-medium text-sm`,children:n(`smartPlugs.powerMonitoring`)}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.topic`)}),(0,Y.jsx)(`input`,{type:`text`,value:S,onChange:e=>C(e.target.value),placeholder:`zigbee2mqtt/shelly-working-room`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.jsonPath`)}),(0,Y.jsx)(`input`,{type:`text`,value:w,onChange:e=>T(e.target.value),placeholder:`power_l1`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.multiplier`)}),(0,Y.jsx)(`input`,{type:`text`,value:E,onChange:e=>D(e.target.value),placeholder:`1`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,style:{whiteSpace:`pre-line`},children:n(`smartPlugs.mqttPowerHint`)})]}),(0,Y.jsxs)(`div`,{className:`space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`p`,{className:`text-white font-medium text-sm`,children:[n(`smartPlugs.energyMonitoring`),` `,(0,Y.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,n(`smartPlugs.optional`),`)`]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.topic`)}),(0,Y.jsx)(`input`,{type:`text`,value:O,onChange:e=>k(e.target.value),placeholder:`Same as power topic, or different`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.jsonPath`)}),(0,Y.jsx)(`input`,{type:`text`,value:A,onChange:e=>ee(e.target.value),placeholder:`energy_l1`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.multiplier`)}),(0,Y.jsx)(`input`,{type:`text`,value:M,onChange:e=>N(e.target.value),placeholder:`1`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,style:{whiteSpace:`pre-line`},children:n(`smartPlugs.mqttEnergyHint`)})]}),(0,Y.jsxs)(`div`,{className:`space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`p`,{className:`text-white font-medium text-sm`,children:[n(`smartPlugs.stateMonitoring`),` `,(0,Y.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,n(`smartPlugs.optional`),`)`]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.topic`)}),(0,Y.jsx)(`input`,{type:`text`,value:P,onChange:e=>te(e.target.value),placeholder:`Same as power topic, or different`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.jsonPath`)}),(0,Y.jsx)(`input`,{type:`text`,value:F,onChange:e=>ne(e.target.value),placeholder:`state_l1`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.onValue`)}),(0,Y.jsx)(`input`,{type:`text`,value:I,onChange:e=>re(e.target.value),placeholder:n(`smartPlugs.addSmartPlug.placeholders.mqttStateOnValue`),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,style:{whiteSpace:`pre-line`},children:n(`smartPlugs.mqttStateHint`)})]})]})]}),o===`rest`&&(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,Y.jsx)(`p`,{className:`text-white font-medium text-sm`,children:n(`smartPlugs.restControl`)}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restMethod`)}),(0,Y.jsxs)(`select`,{value:ue,onChange:e=>de(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,Y.jsx)(`option`,{value:`GET`,children:`GET`}),(0,Y.jsx)(`option`,{value:`POST`,children:`POST`}),(0,Y.jsx)(`option`,{value:`PUT`,children:`PUT`}),(0,Y.jsx)(`option`,{value:`PATCH`,children:`PATCH`})]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restOnUrl`)}),(0,Y.jsx)(`input`,{type:`text`,value:ie,onChange:e=>{ae(e.target.value),vt(null)},placeholder:`http://openhab:8080/rest/items/MyPlug`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[n(`smartPlugs.restOnBody`),` `,(0,Y.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,n(`smartPlugs.optional`),`)`]})]}),(0,Y.jsx)(`input`,{type:`text`,value:z,onChange:e=>oe(e.target.value),placeholder:n(`smartPlugs.restBodyHint`),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restOffUrl`)}),(0,Y.jsx)(`input`,{type:`text`,value:se,onChange:e=>{B(e.target.value),vt(null)},placeholder:`http://openhab:8080/rest/items/MyPlug`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[n(`smartPlugs.restOffBody`),` `,(0,Y.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,n(`smartPlugs.optional`),`)`]})]}),(0,Y.jsx)(`input`,{type:`text`,value:ce,onChange:e=>le(e.target.value),placeholder:n(`smartPlugs.restBodyHint`),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]})]}),(0,Y.jsxs)(`div`,{className:`space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`p`,{className:`text-white font-medium text-sm`,children:[n(`smartPlugs.restHeaders`),` `,(0,Y.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,n(`smartPlugs.optional`),`)`]})]}),(0,Y.jsx)(`div`,{children:(0,Y.jsx)(`textarea`,{value:fe,onChange:e=>V(e.target.value),placeholder:n(`smartPlugs.restHeadersHint`),rows:2,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none font-mono text-sm`})})]}),(0,Y.jsxs)(`div`,{className:`space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`p`,{className:`text-white font-medium text-sm`,children:[n(`smartPlugs.stateMonitoring`),` `,(0,Y.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,n(`smartPlugs.optional`),`)`]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restStatusUrl`)}),(0,Y.jsx)(`input`,{type:`text`,value:pe,onChange:e=>me(e.target.value),placeholder:n(`smartPlugs.restStatusHint`),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restStatusPath`)}),(0,Y.jsx)(`input`,{type:`text`,value:he,onChange:e=>ge(e.target.value),placeholder:n(`smartPlugs.restPathHint`),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restStatusOnValue`)}),(0,Y.jsx)(`input`,{type:`text`,value:_e,onChange:e=>ve(e.target.value),placeholder:`ON`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]})]})]}),(0,Y.jsxs)(`div`,{className:`space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`p`,{className:`text-white font-medium text-sm`,children:[n(`smartPlugs.energyMonitoring`),` `,(0,Y.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,n(`smartPlugs.optional`),`)`]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[n(`smartPlugs.restPowerUrl`),` `,(0,Y.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,n(`smartPlugs.optional`),`)`]})]}),(0,Y.jsx)(`input`,{type:`text`,value:ye,onChange:e=>be(e.target.value),placeholder:n(`smartPlugs.restPowerUrlHint`),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restPowerPath`)}),(0,Y.jsx)(`input`,{type:`text`,value:H,onChange:e=>xe(e.target.value),placeholder:n(`smartPlugs.restPathHint`),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restPowerMultiplier`)}),(0,Y.jsx)(`input`,{type:`text`,value:Se,onChange:e=>Ce(e.target.value),placeholder:`1`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[n(`smartPlugs.restEnergyUrl`),` `,(0,Y.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,n(`smartPlugs.optional`),`)`]})]}),(0,Y.jsx)(`input`,{type:`text`,value:we,onChange:e=>Te(e.target.value),placeholder:n(`smartPlugs.restEnergyUrlHint`),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restEnergyPath`)}),(0,Y.jsx)(`input`,{type:`text`,value:Ee,onChange:e=>De(e.target.value),placeholder:n(`smartPlugs.restPathHint`),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restEnergyMultiplier`)}),(0,Y.jsx)(`input`,{type:`text`,value:Oe,onChange:e=>ke(e.target.value),placeholder:`1`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.restEnergyHint`)}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restEnergyTotalPath`)}),(0,Y.jsx)(`input`,{type:`text`,value:je,onChange:e=>Me(e.target.value),placeholder:n(`smartPlugs.restEnergyTotalPathHint`),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restEnergyTotalMultiplier`)}),(0,Y.jsx)(`input`,{type:`text`,value:Ne,onChange:e=>Pe(e.target.value),placeholder:`1`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.restEnergyTotalHint`)})]}),(ie.trim()||se.trim())&&(0,Y.jsx)(`div`,{className:`flex gap-2`,children:(0,Y.jsxs)(K,{type:`button`,variant:`secondary`,onClick:async()=>{vt(null);try{let e=ie.trim()||se.trim(),t=await r.testRESTConnection(e,ue,fe.trim()||null);vt({success:t.success}),t.success||bt(t.error||n(`smartPlugs.addSmartPlug.connectionFailed`))}catch{vt({success:!1}),bt(n(`smartPlugs.addSmartPlug.connectionFailed`))}},className:`w-full`,children:[(0,Y.jsx)(ht,{className:`w-4 h-4`}),n(`smartPlugs.testConnection`)]})}),gt&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-sm ${gt.success?`text-green-700 dark:text-green-400`:`text-red-700 dark:text-red-400`}`,children:[gt.success?(0,Y.jsx)(j,{className:`w-4 h-4`}):(0,Y.jsx)(Ye,{className:`w-4 h-4`}),gt.success?n(`smartPlugs.connectionSuccess`):n(`smartPlugs.addSmartPlug.connectionFailed`)]})]}),o===`tasmota`&&(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.ipAddress`)}),(0,Y.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Y.jsx)(`input`,{type:`text`,value:m,onChange:e=>{h(e.target.value),vt(null)},placeholder:`192.168.1.100`,className:`flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,Y.jsxs)(K,{type:`button`,variant:`secondary`,onClick:()=>on.mutate(),disabled:!m.trim()||on.isPending,children:[on.isPending?(0,Y.jsx)(R,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(ht,{className:`w-4 h-4`}),n(`smartPlugs.test`)]})]})]}),o===`tasmota`&>&&(0,Y.jsx)(`div`,{className:`p-3 rounded-lg flex items-center gap-2 ${gt.success?`bg-bambu-green/20 border border-bambu-green/50 text-bambu-green`:`bg-red-100 dark:bg-red-500/20 border border-red-400 dark:border-red-500/50 text-red-700 dark:text-red-400`}`,children:gt.success?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(j,{className:`w-5 h-5`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`font-medium`,children:n(`smartPlugs.connectedResult`)}),(0,Y.jsxs)(`p`,{className:`text-sm opacity-80`,children:[gt.device_name&&n(`smartPlugs.deviceLabel`,{name:gt.device_name}),n(`smartPlugs.stateLabel`,{state:gt.state})]})]})]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(Ye,{className:`w-5 h-5`}),(0,Y.jsx)(`span`,{children:n(`smartPlugs.addSmartPlug.connectionFailed`)})]})}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.nameLabel`)}),(0,Y.jsx)(`input`,{type:`text`,value:c,onChange:e=>p(e.target.value),placeholder:n(`smartPlugs.addSmartPlug.placeholders.plugName`),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),o===`tasmota`&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.username`)}),(0,Y.jsx)(`input`,{type:`text`,value:g,onChange:e=>_(e.target.value),placeholder:`admin`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.password`)}),(0,Y.jsx)(`input`,{type:`password`,value:v,onChange:e=>y(e.target.value),placeholder:`********`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray -mt-2`,children:n(`smartPlugs.authHint`)})]}),o!==`mqtt`&&(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.linkToPrinter`)}),(0,Y.jsxs)(`select`,{value:ct??``,onChange:e=>ut(e.target.value?Number(e.target.value):null),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,Y.jsx)(`option`,{value:``,children:n(`smartPlugs.noPrinter`)}),ln?.map(e=>(0,Y.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(`smartPlugs.linkingDescription`)}),ct!==null&&(0,Y.jsxs)(`div`,{className:`flex items-center justify-between mt-3`,children:[(0,Y.jsxs)(`div`,{className:`pr-3`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`smartPlugs.controlsPrinterPower`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.controlsPrinterPowerDescription`)})]}),(0,Y.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer shrink-0`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:ft,onChange:e=>pt(e.target.checked),className:`sr-only peer`}),(0,Y.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]})]}),(0,Y.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary pt-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(rt,{className:`w-4 h-4 text-bambu-green`}),(0,Y.jsx)(`span`,{className:`text-white font-medium`,children:n(`smartPlugs.powerAlerts`)})]}),(0,Y.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:xt,onChange:e=>St(e.target.checked),className:`sr-only peer`}),(0,Y.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),xt&&(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.alertAbove`)}),(0,Y.jsx)(`input`,{type:`number`,value:wt,onChange:e=>Tt(e.target.value),placeholder:`e.g. 200`,min:`0`,max:`5000`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.alertBelow`)}),(0,Y.jsx)(`input`,{type:`number`,value:Et,onChange:e=>Dt(e.target.value),placeholder:`e.g. 10`,min:`0`,max:`5000`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.alertDescription`)})]})]}),o!==`mqtt`&&(0,Y.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary pt-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(lt,{className:`w-4 h-4 text-bambu-green`}),(0,Y.jsx)(`span`,{className:`text-white font-medium`,children:n(`smartPlugs.dailySchedule`)})]}),(0,Y.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:Ot,onChange:e=>kt(e.target.checked),className:`sr-only peer`}),(0,Y.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),Ot&&(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.turnOnAt`)}),(0,Y.jsx)(`input`,{type:`time`,value:At,onChange:e=>jt(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`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.turnOffAt`)}),(0,Y.jsx)(`input`,{type:`time`,value:Mt,onChange:e=>Nt(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`})]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.scheduleDescription`)})]})]}),(0,Y.jsx)(`div`,{className:`border-t border-bambu-dark-tertiary pt-4`,children:(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(L,{className:`w-4 h-4 text-bambu-green`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-white font-medium`,children:n(`smartPlugs.showInSwitchbar`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.quickAccessSidebar`)})]})]}),(0,Y.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:Pt,onChange:e=>It(e.target.checked),className:`sr-only peer`}),(0,Y.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]})}),o===`homeassistant`&&(0,Y.jsx)(`div`,{className:`border-t border-bambu-dark-tertiary pt-4`,children:(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(mt,{className:`w-4 h-4 text-bambu-green`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-white font-medium`,children:n(`smartPlugs.showOnPrinterCard`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.displayOnPrinterCard`)})]})]}),(0,Y.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:Lt,onChange:e=>Rt(e.target.checked),className:`sr-only peer`}),(0,Y.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]})}),(0,Y.jsxs)(`div`,{className:`flex gap-3 pt-2`,children:[(0,Y.jsx)(K,{type:`button`,variant:`secondary`,onClick:t,className:`flex-1`,children:n(`smartPlugs.cancel`)}),(0,Y.jsxs)(K,{type:`submit`,disabled:J,className:`flex-1`,children:[J?(0,Y.jsx)(R,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(_t,{className:`w-4 h-4`}),n(a?`smartPlugs.save`:`smartPlugs.add`)]})]})]})]})})}function mr({sensor:e,printers:t,onClose:n}){let{t:i}=l(),a=u(),{showToast:o}=ee(),s=!!e,[c,p]=(0,X.useState)(e?.printer_id??t[0]?.id??``),[m,h]=(0,X.useState)(e?.entity_id??``),[g,_]=(0,X.useState)(e?.kind??`binary`),[v,y]=(0,X.useState)(e?.device_class??null),[b,S]=(0,X.useState)(e?.unit??null),[C,w]=(0,X.useState)(e?.name??``),[T,E]=(0,X.useState)(e?.alert_state??``),[D,O]=(0,X.useState)(e?.alert_above?.toString()??``),[k,A]=(0,X.useState)(e?.alert_below?.toString()??``),[j,M]=(0,X.useState)(e?.show_on_printer_card??!0),[N,P]=(0,X.useState)(e?.notify_on_alert??!1),[te,F]=(0,X.useState)(e?.block_print??!1),[I,re]=(0,X.useState)(``),[ie,L]=(0,X.useState)(null);(0,X.useEffect)(()=>{let e=e=>{e.key===`Escape`&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n]);let{data:ae}=d({queryKey:[`settings`],queryFn:r.getSettings}),z=!!(ae?.ha_enabled&&ae?.ha_url&&ae?.ha_token),{data:oe,isLoading:se,error:B}=d({queryKey:[`bindableHAEntities`],queryFn:()=>r.getBindableHAEntities(),enabled:z}),ce=(0,X.useMemo)(()=>{let e=I.trim().toLowerCase(),t=oe??[];return e?t.filter(t=>t.entity_id.toLowerCase().includes(e)||t.friendly_name.toLowerCase().includes(e)):t},[oe,I]),le=e=>{h(e.entity_id),y(e.device_class),S(e.unit_of_measurement);let t=e.domain===`binary_sensor`?`binary`:`numeric`;_(t),t===`numeric`?E(``):(O(``),A(``)),C.trim()||w(e.friendly_name.slice(0,100))},ue=()=>{a.invalidateQueries({queryKey:[`haSensors`]}),a.invalidateQueries({queryKey:[`haSensorReadings`]})},de=f({mutationFn:()=>{let t={name:C.trim(),entity_id:m,kind:g,device_class:v,unit:b,alert_state:g===`binary`&&T?T:null,alert_above:g===`numeric`&&D!==``?Number(D):null,alert_below:g===`numeric`&&k!==``?Number(k):null,block_print:te,notify_on_alert:N,show_on_printer_card:j};return s?r.updateHASensor(e.id,t):r.createHASensor({...t,printer_id:Number(c)})},onSuccess:()=>{ue(),o(i(s?`haSensors.toast.updated`:`haSensors.toast.created`),`success`),n()},onError:e=>L(e.message)}),fe=f({mutationFn:()=>r.deleteHASensor(e.id),onSuccess:()=>{ue(),o(i(`haSensors.toast.deleted`),`success`),n()},onError:e=>L(e.message)}),V=g===`binary`?T!==``:D!==``||k!==``,pe=e=>{if(e.preventDefault(),L(null),!m)return L(i(`haSensors.error.pickEntity`));if(!C.trim())return L(i(`haSensors.error.nameRequired`));if(c===``)return L(i(`haSensors.error.printerRequired`));if((te||N)&&!V)return L(i(`haSensors.error.alertRequired`));de.mutate()},me=x[v??``],he=e=>{let t=me?.[e]??e;return i(`haSensors.states.${t}`,{defaultValue:t})},ge=de.isPending||fe.isPending;return(0,Y.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:n,children:(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-lg max-h-[90vh] overflow-y-auto`,onClick:e=>e.stopPropagation(),children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Y.jsx)(`div`,{className:`p-2 rounded-full bg-bambu-green/20 text-bambu-green`,children:(0,Y.jsx)(ne,{className:`w-5 h-5`})}),(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(s?`haSensors.editTitle`:`haSensors.addTitle`)})]}),(0,Y.jsx)(`button`,{onClick:n,className:`text-bambu-gray hover:text-white transition-colors`,children:(0,Y.jsx)(Re,{className:`w-5 h-5`})})]}),(0,Y.jsxs)(`form`,{onSubmit:pe,className:`p-6 space-y-4`,children:[ie&&(0,Y.jsx)(`div`,{className:`p-3 bg-red-100 dark:bg-red-500/20 border border-red-300 dark:border-red-500/50 rounded-lg text-sm text-red-700 dark:text-red-400`,children:ie}),!s&&(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`haSensors.printer`)}),(0,Y.jsx)(`select`,{value:c,onChange:e=>p(e.target.value===``?``:Number(e.target.value)),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white`,children:t.map(e=>(0,Y.jsx)(`option`,{value:e.id,children:e.name},e.id))})]}),!z&&(0,Y.jsxs)(`div`,{className:`p-3 bg-yellow-100 dark:bg-yellow-500/20 border border-yellow-400 dark:border-yellow-500/50 rounded-lg text-sm text-yellow-700 dark:text-yellow-400`,children:[i(`smartPlugs.haNotConfigured`),` `,(0,Y.jsx)(`span`,{className:`font-medium`,children:i(`smartPlugs.haSettingsPath`)})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1 ${z?``:`opacity-50`}`,children:i(`haSensors.entity`)}),B&&(0,Y.jsx)(`div`,{className:`p-3 mb-2 bg-red-100 dark:bg-red-500/20 rounded-lg text-sm text-red-700 dark:text-red-400`,children:B.message}),(0,Y.jsxs)(`div`,{className:`relative mb-2`,children:[(0,Y.jsx)(Ae,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,Y.jsx)(`input`,{type:`text`,value:I,onChange:e=>re(e.target.value),placeholder:i(`haSensors.searchPlaceholder`),disabled:!z,className:`w-full pl-9 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white disabled:opacity-50 disabled:cursor-not-allowed`})]}),(0,Y.jsxs)(`div`,{className:`max-h-44 overflow-y-auto rounded-lg border border-bambu-dark-tertiary ${z?``:`opacity-50`}`,children:[!z&&(0,Y.jsx)(`div`,{className:`p-3 text-sm text-bambu-gray`,children:i(`haSensors.noEntities`)}),z&&se&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 p-3 text-sm text-bambu-gray`,children:[(0,Y.jsx)(R,{className:`w-4 h-4 animate-spin`}),i(`common.loading`)]}),z&&!se&&ce.length===0&&(0,Y.jsx)(`div`,{className:`p-3 text-sm text-bambu-gray`,children:i(`haSensors.noEntities`)}),z&&!se&&ce.map(e=>(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>le(e),className:`w-full text-left px-3 py-2 text-sm transition-colors ${e.entity_id===m?`bg-bambu-green/20 text-bambu-green`:`text-white hover:bg-bambu-dark`}`,children:[(0,Y.jsx)(`div`,{className:`font-medium`,children:e.friendly_name}),(0,Y.jsxs)(`div`,{className:`text-xs text-bambu-gray`,children:[e.entity_id,e.state!==null&&` — ${e.state}`,e.unit_of_measurement?` ${e.unit_of_measurement}`:``]})]},e.entity_id))]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`haSensors.name`)}),(0,Y.jsx)(`input`,{type:`text`,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`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`haSensors.alertWhen`)}),g===`binary`?(0,Y.jsxs)(`select`,{value:T,onChange:e=>E(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white`,children:[(0,Y.jsx)(`option`,{value:``,children:i(`haSensors.alertNever`)}),(0,Y.jsx)(`option`,{value:`on`,children:he(`on`)}),(0,Y.jsx)(`option`,{value:`off`,children:he(`off`)})]}):(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`span`,{className:`block text-xs text-bambu-gray mb-1`,children:[i(`haSensors.alertAbove`),` `,b??``]}),(0,Y.jsx)(`input`,{type:`number`,step:`any`,value:D,onChange:e=>O(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`span`,{className:`block text-xs text-bambu-gray mb-1`,children:[i(`haSensors.alertBelow`),` `,b??``]}),(0,Y.jsx)(`input`,{type:`number`,step:`any`,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`})]})]}),(0,Y.jsx)(`p`,{className:`mt-1 text-xs text-bambu-gray`,children:i(`haSensors.alertHint`)})]}),(0,Y.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:j,onChange:e=>M(e.target.checked),className:`w-4 h-4`}),(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:i(`haSensors.showOnCard`)})]}),(0,Y.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:N,onChange:e=>P(e.target.checked),disabled:!V,className:`w-4 h-4`}),(0,Y.jsx)(`span`,{className:`text-sm ${V?`text-white`:`text-bambu-gray`}`,children:i(`haSensors.notifyOnAlert`)})]}),(0,Y.jsxs)(`label`,{className:`flex items-start gap-3 cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:te,onChange:e=>F(e.target.checked),disabled:!V,className:`w-4 h-4 mt-0.5`}),(0,Y.jsxs)(`span`,{children:[(0,Y.jsx)(`span`,{className:`block text-sm ${V?`text-white`:`text-bambu-gray`}`,children:i(`haSensors.blockPrint`)}),(0,Y.jsx)(`span`,{className:`block text-xs text-bambu-gray`,children:i(`haSensors.blockPrintHint`)})]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between pt-2`,children:[s?(0,Y.jsx)(K,{type:`button`,variant:`danger`,onClick:()=>fe.mutate(),disabled:ge,children:i(`common.delete`)}):(0,Y.jsx)(`span`,{}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(K,{type:`button`,variant:`secondary`,onClick:n,disabled:ge,children:i(`common.cancel`)}),(0,Y.jsxs)(K,{type:`submit`,disabled:ge||!z&&!s,children:[ge?(0,Y.jsx)(R,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(_t,{className:`w-4 h-4`}),i(`common.save`)]})]})]})]})]})})}function hr(e){return e===`temperature`?`temperature`:e===`humidity`?`humidity`:e===`battery`?`battery`:null}var gr={temperature:`temperature`,humidity:`humidity`,battery:`battery`};function _r(e,t,n){let r=gr[t];if(!e.toLowerCase().endsWith(r))return[];let i=e.slice(0,e.length-r.length),a=[];return Object.keys(gr).forEach(e=>{if(e===t)return;let r=`${i}${gr[e]}`.toLowerCase(),o=n.find(e=>e.entity_id.toLowerCase()===r);o&&a.push(o)}),a}function vr({sensor:e,locations:t,onClose:n}){let{t:i}=l(),a=u(),{showToast:o}=ee(),s=!!e,[c,p]=(0,X.useState)(e?.location_id??t[0]?.id??``),[m,h]=(0,X.useState)(e?.entity_id??``),[g,_]=(0,X.useState)(e?.kind??`numeric`),[v,y]=(0,X.useState)(e?.device_class??null),[b,S]=(0,X.useState)(e?.unit??null),[C,w]=(0,X.useState)(e?.name??``),T=(0,X.useRef)(e?.name??``),[E,D]=(0,X.useState)(e?.alert_state??``),[O,k]=(0,X.useState)(e?.alert_above?.toString()??``),[A,j]=(0,X.useState)(e?.alert_below?.toString()??``),[M,N]=(0,X.useState)(e?.notify_on_alert??!1),[P,te]=(0,X.useState)(e?.show_on_card??!0),[F,I]=(0,X.useState)(``),[re,ie]=(0,X.useState)(null),[L,ae]=(0,X.useState)(!1),[z,oe]=(0,X.useState)(!1),[se,B]=(0,X.useState)(null),[ce,le]=(0,X.useState)(!1),[de,fe]=(0,X.useState)([]),[V,pe]=(0,X.useState)({}),{data:me}=d({queryKey:[`settings`],queryFn:r.getSettings}),ge=!!(me?.ha_enabled&&me?.ha_url&&me?.ha_token),{data:_e,isLoading:ve,error:ye}=d({queryKey:[`bindableLocationHAEntities`],queryFn:()=>r.getBindableLocationHAEntities(),enabled:ge}),be=(0,X.useMemo)(()=>(_e??[]).filter(e=>hr(e.device_class)!==null),[_e]),{data:H}=d({queryKey:[`locationHaSensors`],queryFn:()=>r.getLocationHASensors()}),xe=be.find(e=>e.entity_id===m),Se=(0,X.useMemo)(()=>{let e=F.trim().toLowerCase(),t=be??[],n=e?t.filter(t=>t.entity_id.toLowerCase().includes(e)||t.friendly_name.toLowerCase().includes(e)):t;return!xe||n[0]?.entity_id===xe.entity_id?n:[xe,...n.filter(e=>e.entity_id!==xe.entity_id)]},[be,F,xe]),Ce=e=>{h(e.entity_id),y(e.device_class),S(e.unit_of_measurement?.slice(0,16)??null);let t=e.domain===`binary_sensor`?`binary`:`numeric`;if(_(t),t===`numeric`?D(``):(k(``),j(``)),C===T.current){let t=e.friendly_name.slice(0,100);w(t),T.current=t}if(!s){let n=hr(e.device_class);if(n){let e=he(me?.location_sensor_alert_defaults)[n];t===`numeric`&&(k(n===`battery`?``:e.alertAbove),j(e.alertBelow)),N(e.notifyOnAlert),te(e.showOnCard)}}},we=()=>{a.invalidateQueries({queryKey:[`locationHaSensors`]}),a.invalidateQueries({queryKey:[`locationHaSensorReadings`]})},Te=()=>({name:C.trim(),entity_id:m,kind:g,device_class:v,unit:b,alert_state:g===`binary`&&E?E:null,alert_above:g===`numeric`&&hr(v)!==`battery`&&O!==``?Number(O):null,alert_below:g===`numeric`&&A!==``?Number(A):null,notify_on_alert:M,show_on_card:P}),Ee=f({mutationFn:()=>{let t=Te();return s?r.updateLocationHASensor(e.id,t):r.createLocationHASensor({...t,location_id:Number(c)})},onSuccess:()=>{we(),o(i(s?`locationHaSensors.toast.updated`:`locationHaSensors.toast.created`),`success`),n()},onError:e=>ie(e.message)}),De=f({mutationFn:async()=>{let e=Number(c);await r.createLocationHASensor({...Te(),location_id:e});let t=he(me?.location_sensor_alert_defaults),n=de.filter(e=>V[e.entity_id]);for(let i of n){let n=hr(i.device_class),a=n?t[n]:null;await r.createLocationHASensor({name:i.friendly_name.slice(0,100),entity_id:i.entity_id,kind:i.domain===`binary_sensor`?`binary`:`numeric`,device_class:i.device_class,unit:i.unit_of_measurement?.slice(0,16)??null,alert_state:null,alert_above:n!==`battery`&&a&&a.alertAbove!==``?Number(a.alertAbove):null,alert_below:a&&a.alertBelow!==``?Number(a.alertBelow):null,notify_on_alert:a?.notifyOnAlert??!1,show_on_card:a?.showOnCard??P,location_id:e})}return n},onSuccess:e=>{we(),le(!1),e.length>0?o(i(`locationHaSensors.autoAdd.added`,{names:e.map(e=>e.entity_id).join(`, `)}),`success`):o(i(`locationHaSensors.toast.created`),`success`),n()},onError:e=>{we(),le(!1),ie(e.message)}}),Oe=f({mutationFn:()=>r.deleteLocationHASensor(e.id),onSuccess:()=>{we(),o(i(`locationHaSensors.toast.deleted`),`success`),n()},onError:e=>ie(e.message)}),ke=f({mutationFn:()=>r.updateLocationHASensor(se.id,Te()),onSuccess:()=>{we(),oe(!1),B(null),o(i(`locationHaSensors.toast.updated`),`success`),n()},onError:e=>{oe(!1),B(null),ie(e.message)}}),je=g===`binary`?E!==``:O!==``||A!==``,Me=e=>{if(e.preventDefault(),ie(null),!m)return ie(i(`haSensors.error.pickEntity`));if(!C.trim())return ie(i(`haSensors.error.nameRequired`));if(c===``)return ie(i(`locationHaSensors.error.locationRequired`));if(M&&!je)return ie(i(`haSensors.error.alertRequired`));if(!s){let e=(H??[]).filter(e=>e.location_id===Number(c)),t=hr(v);if(t){let n=e.find(e=>hr(e.device_class)===t);if(n){B(n),oe(!0);return}}if(e.length===0&&t){let e=_r(m,t,be);if(e.length>0){fe(e),pe(Object.fromEntries(e.map(e=>[e.entity_id,!0]))),le(!0);return}o(i(`locationHaSensors.autoAdd.noneFound`),`info`)}}Ee.mutate()},Ne=x[v??``],Pe=e=>{let t=Ne?.[e]??e;return i(`haSensors.states.${t}`,{defaultValue:t})},Fe=Ee.isPending||Oe.isPending||ke.isPending||De.isPending,Ie=t.find(e=>e.id===Number(c));return(0,X.useEffect)(()=>{let e=e=>{e.key===`Escape`&&!Fe&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n,Fe]),(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:()=>{Fe||n()},children:(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-lg max-h-[90vh] overflow-y-auto`,onClick:e=>e.stopPropagation(),children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Y.jsx)(`div`,{className:`p-2 rounded-full bg-bambu-green/20 text-bambu-green`,children:(0,Y.jsx)(ne,{className:`w-5 h-5`})}),(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(s?`locationHaSensors.editTitle`:`locationHaSensors.addTitle`)})]}),(0,Y.jsx)(`button`,{onClick:n,disabled:Fe,className:`text-bambu-gray hover:text-white transition-colors disabled:opacity-50 disabled:cursor-not-allowed`,children:(0,Y.jsx)(Re,{className:`w-5 h-5`})})]}),(0,Y.jsxs)(`form`,{onSubmit:Me,className:`p-6 space-y-4`,children:[re&&(0,Y.jsx)(`div`,{className:`p-3 bg-red-100 dark:bg-red-500/20 border border-red-300 dark:border-red-500/50 rounded-lg text-sm text-red-700 dark:text-red-400`,children:re}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`locationHaSensors.location`)}),s?(0,Y.jsx)(`div`,{className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white`,children:t.find(t=>t.id===e.location_id)?.name??i(`locationHaSensors.unknownLocation`)}):(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`select`,{value:c,onChange:e=>p(e.target.value===``?``:Number(e.target.value)),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white`,children:t.map(e=>(0,Y.jsx)(`option`,{value:e.id,children:e.name},e.id))}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>ae(!0),className:`p-2 rounded-lg bg-bambu-dark-tertiary hover:bg-bambu-gray-dark text-white transition-colors shrink-0`,title:i(`locations.add`),"aria-label":i(`locations.add`),children:(0,Y.jsx)(wt,{className:`w-4 h-4`})})]})]}),!ge&&(0,Y.jsxs)(`div`,{className:`p-3 bg-yellow-100 dark:bg-yellow-500/20 border border-yellow-400 dark:border-yellow-500/50 rounded-lg text-sm text-yellow-700 dark:text-yellow-400`,children:[i(`smartPlugs.haNotConfigured`),` `,(0,Y.jsx)(`span`,{className:`font-medium`,children:i(`smartPlugs.haSettingsPath`)})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1 ${ge?``:`opacity-50`}`,children:i(`haSensors.entity`)}),ye&&(0,Y.jsx)(`div`,{className:`p-3 mb-2 bg-red-100 dark:bg-red-500/20 rounded-lg text-sm text-red-700 dark:text-red-400`,children:ye.message}),(0,Y.jsxs)(`div`,{className:`relative mb-2`,children:[(0,Y.jsx)(Ae,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,Y.jsx)(`input`,{type:`text`,value:F,onChange:e=>I(e.target.value),placeholder:i(`haSensors.searchPlaceholder`),disabled:!ge,className:`w-full pl-9 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white disabled:opacity-50 disabled:cursor-not-allowed`})]}),(0,Y.jsxs)(`div`,{className:`max-h-44 overflow-y-auto rounded-lg border border-bambu-dark-tertiary ${ge?``:`opacity-50`}`,children:[m&&!xe&&(0,Y.jsx)(`div`,{className:`px-3 py-2 text-sm bg-bambu-green/10 text-bambu-green border-b border-bambu-dark-tertiary`,children:i(`locationHaSensors.currentlyBound`,{entity:m})}),!ge&&(0,Y.jsx)(`div`,{className:`p-3 text-sm text-bambu-gray`,children:i(`haSensors.noEntities`)}),ge&&ve&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 p-3 text-sm text-bambu-gray`,children:[(0,Y.jsx)(R,{className:`w-4 h-4 animate-spin`}),i(`common.loading`)]}),ge&&!ve&&Se.length===0&&(0,Y.jsx)(`div`,{className:`p-3 text-sm text-bambu-gray`,children:i(`haSensors.noEntities`)}),ge&&!ve&&Se.map(e=>(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>Ce(e),className:`w-full text-left px-3 py-2 text-sm transition-colors ${e.entity_id===m?`bg-bambu-green/20 text-bambu-green`:`text-white hover:bg-bambu-dark`}`,children:[(0,Y.jsx)(`div`,{className:`font-medium`,children:e.friendly_name}),(0,Y.jsxs)(`div`,{className:`text-xs text-bambu-gray`,children:[e.entity_id,e.state!==null&&` — ${e.state}`,e.unit_of_measurement?` ${e.unit_of_measurement}`:``]})]},e.entity_id))]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,htmlFor:`location-ha-sensor-name`,children:i(`haSensors.name`)}),(0,Y.jsx)(`input`,{id:`location-ha-sensor-name`,type:`text`,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`})]}),m&&(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`haSensors.alertWhen`)}),g===`binary`?(0,Y.jsxs)(`select`,{value:E,onChange:e=>D(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white`,children:[(0,Y.jsx)(`option`,{value:``,children:i(`haSensors.alertNever`)}),(0,Y.jsx)(`option`,{value:`on`,children:Pe(`on`)}),(0,Y.jsx)(`option`,{value:`off`,children:Pe(`off`)})]}):hr(v)===`battery`?(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`span`,{className:`block text-xs text-bambu-gray mb-1`,children:[i(`haSensors.alertBelow`),` `,b??``]}),(0,Y.jsx)(`input`,{type:`number`,step:`any`,value:A,onChange:e=>j(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white`})]}):(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`span`,{className:`block text-xs text-bambu-gray mb-1`,children:[i(`haSensors.alertAbove`),` `,b??``]}),(0,Y.jsx)(`input`,{type:`number`,step:`any`,value:O,onChange:e=>k(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`span`,{className:`block text-xs text-bambu-gray mb-1`,children:[i(`haSensors.alertBelow`),` `,b??``]}),(0,Y.jsx)(`input`,{type:`number`,step:`any`,value:A,onChange:e=>j(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white`})]})]}),(0,Y.jsx)(`p`,{className:`mt-1 text-xs text-bambu-gray`,children:i(`haSensors.alertHint`)})]}),(0,Y.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:P,onChange:e=>te(e.target.checked),className:`w-4 h-4`}),(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:i(`locationHaSensors.showOnCard`)})]}),(0,Y.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:M,onChange:e=>N(e.target.checked),disabled:!je,className:`w-4 h-4`}),(0,Y.jsx)(`span`,{className:`text-sm ${je?`text-white`:`text-bambu-gray`}`,children:i(`haSensors.notifyOnAlert`)})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between pt-2`,children:[s?(0,Y.jsx)(K,{type:`button`,variant:`danger`,onClick:()=>Oe.mutate(),disabled:Fe,children:i(`common.delete`)}):(0,Y.jsx)(`span`,{}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(K,{type:`button`,variant:`secondary`,onClick:n,disabled:Fe,children:i(`common.cancel`)}),(0,Y.jsxs)(K,{type:`submit`,disabled:Fe||!ge&&!s,children:[Fe?(0,Y.jsx)(R,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(_t,{className:`w-4 h-4`}),i(`common.save`)]})]})]})]})]})}),z&&se&&(0,Y.jsx)(Tt,{title:i(`locationHaSensors.overwriteConfirm.title`),message:i(`locationHaSensors.overwriteConfirm.message${hr(se.device_class)===`humidity`?`Humidity`:hr(se.device_class)===`battery`?`Battery`:`Temperature`}`,{location:Ie?.name??``,name:se.name}),variant:`warning`,overlayZIndex:`z-[110]`,isLoading:ke.isPending,onConfirm:()=>ke.mutate(),onCancel:()=>{oe(!1),B(null)}}),ce&&de.length>0&&(0,Y.jsx)(Tt,{title:i(`locationHaSensors.autoAdd.confirmTitle`),message:i(`locationHaSensors.autoAdd.confirmMessage`),overlayZIndex:`z-[110]`,isLoading:De.isPending,confirmDisabled:!de.some(e=>V[e.entity_id]),onConfirm:()=>De.mutate(),cancelText:i(`locationHaSensors.autoAdd.onlyThisOne`),onCancel:()=>{le(!1),fe([]),pe({}),Ee.mutate()},children:(0,Y.jsx)(`div`,{className:`space-y-2`,children:de.map(e=>(0,Y.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:V[e.entity_id]??!0,onChange:t=>pe(n=>({...n,[e.entity_id]:t.target.checked})),className:`w-4 h-4`}),(0,Y.jsxs)(`span`,{className:`text-sm text-white`,children:[e.friendly_name,(0,Y.jsxs)(`span`,{className:`text-bambu-gray`,children:[` — `,e.entity_id]})]})]},e.entity_id))})}),L&&(0,Y.jsx)(ue,{open:L,onClose:()=>ae(!1),onPickLocation:e=>{p(e),ae(!1)},startCreating:!0})]})}var yr=60,br=120,xr={temperature:Fe,humidity:y,battery:_},Sr={temperature:`°C`,humidity:`%`,battery:`%`};function Cr(e){return e===`temperature`?`temperature`:e===`humidity`?`humidity`:e===`battery`?`battery`:null}function wr({category:e,state:t,onChange:n}){let{t:r}=l(),i=xr[e],a=Sr[e],o=t.alertAbove!==``||t.alertBelow!==``;return(0,Y.jsxs)(`div`,{className:`p-3 border border-bambu-dark-tertiary rounded-lg space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 text-sm text-white font-medium`,children:[(0,Y.jsx)(i,{className:`w-4 h-4`}),r(`inventory.${e}`)]}),e===`battery`?(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`span`,{className:`block text-xs text-bambu-gray mb-1`,children:[r(`haSensors.alertBelow`),` `,a]}),(0,Y.jsx)(`input`,{type:`number`,step:`any`,value:t.alertBelow,onChange:e=>n({alertBelow:e.target.value}),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white`})]}):(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`span`,{className:`block text-xs text-bambu-gray mb-1`,children:[r(`haSensors.alertAbove`),` `,a]}),(0,Y.jsx)(`input`,{type:`number`,step:`any`,value:t.alertAbove,onChange:e=>n({alertAbove:e.target.value}),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`span`,{className:`block text-xs text-bambu-gray mb-1`,children:[r(`haSensors.alertBelow`),` `,a]}),(0,Y.jsx)(`input`,{type:`number`,step:`any`,value:t.alertBelow,onChange:e=>n({alertBelow:e.target.value}),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white`})]})]}),(0,Y.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:t.showOnCard,onChange:e=>n({showOnCard:e.target.checked}),className:`w-4 h-4`}),(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:r(`locationHaSensors.showOnCard`)})]}),(0,Y.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:t.notifyOnAlert,onChange:e=>n({notifyOnAlert:e.target.checked}),disabled:!o,className:`w-4 h-4`}),(0,Y.jsx)(`span`,{className:`text-sm ${o?`text-white`:`text-bambu-gray`}`,children:r(`haSensors.notifyOnAlert`)})]})]})}function Tr({onClose:e}){let{t}=l(),{showToast:n}=ee(),i=u(),[a,o]=(0,X.useState)(()=>he()),[s,c]=(0,X.useState)(()=>se()),[p,m]=(0,X.useState)(()=>me()),[h,g]=(0,X.useState)(()=>_e()),[_,v]=(0,X.useState)(()=>fe()),[y,b]=(0,X.useState)(!1),{data:x}=d({queryKey:[`settings`],queryFn:r.getSettings}),[S,C]=(0,X.useState)(br),w=(0,X.useRef)(!1),T=(0,X.useRef)(new Set);(0,X.useEffect)(()=>{if(!x||w.current)return;w.current=!0,T.current.has(`pollInterval`)||C(x.location_sensor_poll_interval);let e=he(x.location_sensor_alert_defaults);o(t=>{let n={...e};return Object.keys(n).forEach(e=>{T.current.has(e)&&(n[e]=t[e])}),n})},[x]);let E=(e,t)=>{T.current.add(e),o(n=>({...n,[e]:{...n[e],...t}}))},D=e=>{T.current.add(`pollInterval`),C(e)},O=async()=>{let e=Math.max(yr,S),t=pe({...a,battery:{...a.battery,alertAbove:``}}),n={};x&&e!==x.location_sensor_poll_interval&&(n.location_sensor_poll_interval=e),x&&t!==x.location_sensor_alert_defaults&&(n.location_sensor_alert_defaults=t),Object.keys(n).length>0&&(await r.updateSettings(n),i.invalidateQueries({queryKey:[`settings`]})),ge(a),le(s),V(p),be(h),ce(_)},k=f({mutationFn:O,onSuccess:()=>{n(t(`locationHaSensors.options.saved`),`success`),e()},onError:e=>{n(e.message||t(`locationHaSensors.options.saveFailed`),`error`)}}),A=e=>{e.preventDefault(),k.mutate()},j=f({mutationFn:async()=>{let[e,t]=await Promise.all([r.getLocationHASensors(),r.getBindableLocationHAEntities()]),n=new Map(t.map(e=>[e.entity_id,e.friendly_name])),i=e.filter(e=>Cr(e.device_class)!==null);return await Promise.all(i.map(e=>{let t=Cr(e.device_class),i=a[t],o=n.get(e.entity_id);return r.updateLocationHASensor(e.id,{...o?{name:o.slice(0,100)}:{},alert_above:t!==`battery`&&i.alertAbove!==``?Number(i.alertAbove):null,alert_below:i.alertBelow===``?null:Number(i.alertBelow),notify_on_alert:i.notifyOnAlert,show_on_card:i.showOnCard})})),await O(),i.length},onSuccess:r=>{i.invalidateQueries({queryKey:[`locationHaSensors`]}),i.invalidateQueries({queryKey:[`locationHaSensorReadings`]}),n(t(`locationHaSensors.options.resetDone`,{count:r}),`success`),b(!1),e()},onError:e=>{n(e.message||t(`locationHaSensors.options.resetFailed`),`error`),b(!1)}});return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:e,children:(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-lg max-h-[90vh] overflow-y-auto`,onClick:e=>e.stopPropagation(),children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Y.jsx)(`div`,{className:`p-2 rounded-full bg-bambu-green/20 text-bambu-green`,children:(0,Y.jsx)(je,{className:`w-5 h-5`})}),(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:t(`locationHaSensors.options.title`)})]}),(0,Y.jsx)(`button`,{onClick:e,className:`text-bambu-gray hover:text-white transition-colors`,children:(0,Y.jsx)(Re,{className:`w-5 h-5`})})]}),(0,Y.jsxs)(`form`,{onSubmit:A,className:`px-6 pb-6 pt-3 space-y-4`,children:[(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:t(`locationHaSensors.options.description`)}),(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsx)(wr,{category:`temperature`,state:a.temperature,onChange:e=>E(`temperature`,e)}),(0,Y.jsx)(wr,{category:`humidity`,state:a.humidity,onChange:e=>E(`humidity`,e)}),(0,Y.jsx)(wr,{category:`battery`,state:a.battery,onChange:e=>E(`battery`,e)})]}),(0,Y.jsxs)(`div`,{className:`p-3 border border-bambu-dark-tertiary rounded-lg space-y-3`,children:[(0,Y.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:s,onChange:e=>c(e.target.checked),className:`w-4 h-4`}),(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:t(`locationHaSensors.options.colorizeValues`)})]}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-3 gap-x-3 gap-y-1 items-end ${s?``:`opacity-50`}`,children:[(0,Y.jsx)(`label`,{className:`block text-xs text-bambu-gray`,htmlFor:`location-sensor-below-color`,children:t(`locationHaSensors.options.belowColor`)}),(0,Y.jsx)(`label`,{className:`block text-xs text-bambu-gray`,htmlFor:`location-sensor-optimal-color`,children:t(`locationHaSensors.options.optimalColor`)}),(0,Y.jsx)(`label`,{className:`block text-xs text-bambu-gray`,htmlFor:`location-sensor-above-color`,children:t(`locationHaSensors.options.aboveColor`)}),(0,Y.jsx)(`select`,{id:`location-sensor-below-color`,value:h,onChange:e=>g(e.target.value),disabled:!s,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white disabled:cursor-not-allowed`,children:ye.map(e=>(0,Y.jsx)(`option`,{value:e,children:t(`locationHaSensors.options.colors.${e}`)},e))}),(0,Y.jsx)(`select`,{id:`location-sensor-optimal-color`,value:_,onChange:e=>v(e.target.value),disabled:!s,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white disabled:cursor-not-allowed`,children:ye.map(e=>(0,Y.jsx)(`option`,{value:e,children:t(`locationHaSensors.options.colors.${e}`)},e))}),(0,Y.jsx)(`select`,{id:`location-sensor-above-color`,value:p,onChange:e=>m(e.target.value),disabled:!s,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white disabled:cursor-not-allowed`,children:ye.map(e=>(0,Y.jsx)(`option`,{value:e,children:t(`locationHaSensors.options.colors.${e}`)},e))})]})]}),(0,Y.jsx)(`div`,{className:`pt-4 mt-4 border-t border-bambu-dark-tertiary`,children:(0,Y.jsx)(`p`,{className:`text-xs font-medium text-bambu-gray uppercase tracking-wider mb-3`,children:t(`locationHaSensors.options.generalSettings`)})}),(0,Y.jsxs)(`div`,{className:`p-3 border border-bambu-dark-tertiary rounded-lg space-y-2`,children:[(0,Y.jsx)(`label`,{className:`block text-sm text-white`,htmlFor:`location-sensor-poll-interval`,children:t(`locationHaSensors.options.pollInterval`)}),(0,Y.jsx)(`input`,{id:`location-sensor-poll-interval`,type:`number`,min:yr,step:`1`,value:S,onChange:e=>D(Number(e.target.value)),onBlur:()=>D(Math.max(yr,S||br)),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white`}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:t(`locationHaSensors.options.pollIntervalHint`)})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2 pt-2`,children:[(0,Y.jsxs)(K,{type:`button`,variant:`secondary`,onClick:()=>b(!0),children:[(0,Y.jsx)(nt,{className:`w-4 h-4`}),t(`locationHaSensors.options.reset`)]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(K,{type:`button`,variant:`secondary`,onClick:e,children:t(`common.cancel`)}),(0,Y.jsxs)(K,{type:`submit`,disabled:k.isPending,children:[(0,Y.jsx)(_t,{className:`w-4 h-4`}),t(`common.save`)]})]})]})]})]})}),y&&(0,Y.jsx)(Tt,{title:t(`locationHaSensors.options.resetConfirm.title`),message:t(`locationHaSensors.options.resetConfirm.message`),confirmText:t(`locationHaSensors.options.reset`),variant:`danger`,overlayZIndex:`z-[60]`,isLoading:j.isPending,onConfirm:()=>j.mutate(),onCancel:()=>b(!1)})]})}function Er({provider:e,onEdit:t}){let{t:n}=l(),i=u(),[a,o]=(0,X.useState)(!1),[s,c]=(0,X.useState)(!1),[p,m]=(0,X.useState)(null),{data:h}=d({queryKey:[`printers`],queryFn:r.getPrinters}),g=h?.find(t=>t.id===e.printer_id),_=f({mutationFn:t=>r.updateNotificationProvider(e.id,t),onSuccess:()=>{i.invalidateQueries({queryKey:[`notification-providers`]})}}),v=f({mutationFn:()=>r.deleteNotificationProvider(e.id),onSuccess:()=>{i.invalidateQueries({queryKey:[`notification-providers`]})}}),y=f({mutationFn:()=>r.testNotificationProvider(e.id),onSuccess:e=>{m(e),i.invalidateQueries({queryKey:[`notification-providers`]})},onError:e=>{m({success:!1,message:e.message})}}),b=e=>e||``;return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(G,{className:`relative`,children:(0,Y.jsxs)(W,{className:`p-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-start justify-between ${e.enabled?`mb-3`:`mb-0`}`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Y.jsx)(`div`,{className:`p-2 rounded-lg ${e.enabled?`bg-bambu-green/20`:`bg-bambu-dark`}`,children:(0,Y.jsx)(rt,{className:`w-5 h-5 ${e.enabled?`text-bambu-green`:`text-bambu-gray`}`})}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h3`,{className:`font-medium text-white`,children:e.name}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`notifications.providerTypes.${e.provider_type}`,e.provider_type)})]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[e.last_success&&(0,Y.jsx)(`span`,{className:`text-xs text-status-ok hidden sm:inline`,children:n(`notifications.lastSuccess`,{date:He(e.last_success)})}),e.last_error&&e.last_error_at&&(!e.last_success||(We(e.last_error_at)?.getTime()||0)>(We(e.last_success)?.getTime()||0))&&(0,Y.jsx)(`span`,{className:`text-xs text-status-error`,title:e.last_error,children:n(`notifications.error`)}),(0,Y.jsx)(J,{checked:e.enabled,onChange:e=>_.mutate({enabled:e})})]})]}),e.enabled&&(0,Y.jsxs)(Y.Fragment,{children:[g&&(0,Y.jsxs)(`div`,{className:`mb-3 px-2 py-1.5 bg-bambu-dark rounded-lg`,children:[(0,Y.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[n(`notifications.printer`),` `]}),(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:g.name})]}),!g&&!e.printer_id&&(0,Y.jsx)(`div`,{className:`mb-3 px-2 py-1.5 bg-bambu-dark rounded-lg`,children:(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:n(`notifications.allPrinters`)})}),(0,Y.jsxs)(`div`,{className:`mb-3 flex flex-wrap gap-1`,children:[e.on_print_start&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400 text-xs rounded`,children:n(`notifications.start`)}),e.on_plate_not_empty&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-rose-100 dark:bg-rose-600/20 text-rose-700 dark:text-rose-300 text-xs rounded`,children:n(`notifications.plateCheck`)}),e.on_print_complete&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-bambu-green/20 text-bambu-green text-xs rounded`,children:n(`notifications.complete`)}),e.on_plate_clear_required&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400 text-xs rounded`,children:n(`notifications.plateClear`)}),e.on_print_confirm_request&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-teal-100 dark:bg-teal-500/20 text-teal-700 dark:text-teal-400 text-xs rounded`,children:n(`notifications.printConfirmRequest`)}),e.provider_type===`telegram`&&e.on_print_confirm_request&&e.telegram_verdict_mode===`reactions`&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-sky-100 dark:bg-sky-500/20 text-sky-700 dark:text-sky-400 text-xs rounded`,children:n(`notifications.telegramVerdictBadgeReactions`)}),e.provider_type===`telegram`&&e.on_print_confirm_request&&e.telegram_verdict_mode===`both`&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-sky-100 dark:bg-sky-500/20 text-sky-700 dark:text-sky-400 text-xs rounded`,children:n(`notifications.telegramVerdictBadgeBoth`)}),e.on_print_failed&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400 text-xs rounded`,children:n(`notifications.failed`)}),e.on_print_stopped&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-orange-100 dark:bg-orange-500/20 text-orange-700 dark:text-orange-400 text-xs rounded`,children:n(`notifications.stopped`)}),e.on_billing_charge_failed&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-red-100 dark:bg-red-600/20 text-red-700 dark:text-red-300 text-xs rounded`,children:n(`notifications.billingChargeFailedLabel`)}),e.on_print_progress&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400 text-xs rounded`,children:n(`notifications.progress`)}),e.on_printer_offline&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-gray-500/20 text-gray-400 text-xs rounded`,children:n(`notifications.offline`)}),e.on_printer_error&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-rose-100 dark:bg-rose-500/20 text-rose-700 dark:text-rose-400 text-xs rounded`,children:n(`notifications.error`)}),e.on_ai_failure_detection&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-fuchsia-100 dark:bg-fuchsia-500/20 text-fuchsia-700 dark:text-fuchsia-300 text-xs rounded`,children:n(`notifications.aiFailureDetection`)}),e.on_ha_sensor_alert&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-indigo-100 dark:bg-indigo-500/20 text-indigo-700 dark:text-indigo-300 text-xs rounded`,children:n(`notifications.haSensorAlert`)}),e.on_location_ha_sensor_alert&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-indigo-100 dark:bg-indigo-500/20 text-indigo-700 dark:text-indigo-300 text-xs rounded`,children:n(`notifications.locationHaSensorAlert`)}),e.on_filament_low&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-cyan-100 dark:bg-cyan-500/20 text-cyan-700 dark:text-cyan-400 text-xs rounded`,children:n(`notifications.lowFilament`)}),e.on_maintenance_due&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-purple-100 dark:bg-purple-500/20 text-purple-700 dark:text-purple-400 text-xs rounded`,children:n(`notifications.maintenance`)}),e.on_ams_humidity_high&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-blue-100 dark:bg-blue-600/20 text-blue-700 dark:text-blue-300 text-xs rounded`,children:n(`notifications.amsHumidity`)}),e.on_ams_temperature_high&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-orange-100 dark:bg-orange-600/20 text-orange-700 dark:text-orange-300 text-xs rounded`,children:n(`notifications.amsTemp`)}),e.on_ams_drying_suspended&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-rose-100 dark:bg-rose-600/20 text-rose-700 dark:text-rose-300 text-xs rounded`,children:n(`notifications.amsDryingSuspended`)}),e.on_ams_ht_humidity_high&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-cyan-100 dark:bg-cyan-600/20 text-cyan-700 dark:text-cyan-300 text-xs rounded`,children:n(`notifications.amsHtHumidity`)}),e.on_ams_ht_temperature_high&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-amber-100 dark:bg-amber-600/20 text-amber-700 dark:text-amber-300 text-xs rounded`,children:n(`notifications.amsHtTemp`)}),e.on_bed_cooled&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-teal-100 dark:bg-teal-500/20 text-teal-700 dark:text-teal-400 text-xs rounded`,children:n(`notifications.bedCooled`)}),e.on_first_layer_complete&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-emerald-100 dark:bg-emerald-600/20 text-emerald-700 dark:text-emerald-300 text-xs rounded`,children:n(`notifications.firstLayer`)}),e.on_app_message&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-sky-100 dark:bg-sky-500/20 text-sky-700 dark:text-sky-400 text-xs rounded`,children:n(`notifications.appMessagesBadge`)}),e.on_print_missing_spool_assignment&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-300 text-xs rounded`,children:n(`notifications.missingSpoolAssignmentLabel`)}),e.on_stock_reorder_alert&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-lime-100 dark:bg-lime-500/20 text-lime-700 dark:text-lime-400 text-xs rounded`,children:n(`notifications.stockReorderAlert`)}),e.on_stock_break_alert&&(0,Y.jsx)(`span`,{className:`px-2 py-0.5 bg-red-100 dark:bg-red-600/20 text-red-700 dark:text-red-300 text-xs rounded`,children:n(`notifications.stockBreakAlert`)}),e.quiet_hours_enabled&&(0,Y.jsxs)(`span`,{className:`px-2 py-0.5 bg-indigo-100 dark:bg-indigo-500/20 text-indigo-700 dark:text-indigo-400 text-xs rounded flex items-center gap-1`,children:[(0,Y.jsx)(Jt,{className:`w-3 h-3`}),n(`notifications.quiet`)]}),e.daily_digest_enabled&&(0,Y.jsxs)(`span`,{className:`px-2 py-0.5 bg-emerald-100 dark:bg-emerald-500/20 text-emerald-700 dark:text-emerald-400 text-xs rounded flex items-center gap-1`,children:[(0,Y.jsx)(w,{className:`w-3 h-3`}),n(`notifications.digest`,{time:e.daily_digest_time})]}),e.attach_photo===!1&&(0,Y.jsxs)(`span`,{className:`px-2 py-0.5 bg-bambu-dark-tertiary text-bambu-gray text-xs rounded flex items-center gap-1`,children:[(0,Y.jsx)(vn,{className:`w-3 h-3`}),n(`notifications.noPhoto`)]})]}),(0,Y.jsx)(`div`,{className:`mb-3`,children:(0,Y.jsxs)(K,{size:`sm`,variant:`secondary`,disabled:y.isPending,onClick:()=>{m(null),y.mutate()},className:`w-full`,children:[y.isPending?(0,Y.jsx)(R,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(Sn,{className:`w-4 h-4`}),n(`notifications.sendTestNotification`)]})}),p&&(0,Y.jsxs)(`div`,{className:`mb-3 p-2 rounded-lg flex items-center gap-2 text-sm ${p.success?`bg-bambu-green/20 text-bambu-green`:`bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400`}`,children:[p.success?(0,Y.jsx)(j,{className:`w-4 h-4`}):(0,Y.jsx)(O,{className:`w-4 h-4`}),(0,Y.jsx)(`span`,{children:p.message})]})]}),(0,Y.jsxs)(`button`,{onClick:()=>c(!s),className:`w-full flex items-center justify-between py-2 text-sm text-bambu-gray hover:text-white transition-colors ${e.enabled?`border-t border-bambu-dark-tertiary`:`mt-2 border-t border-bambu-dark-tertiary`}`,children:[(0,Y.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(je,{className:`w-4 h-4`}),n(`notifications.eventSettings`)]}),s?(0,Y.jsx)(D,{className:`w-4 h-4`}):(0,Y.jsx)(E,{className:`w-4 h-4`})]}),s&&(0,Y.jsxs)(`div`,{className:`pt-3 border-t border-bambu-dark-tertiary space-y-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.enabled`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.sendFromProvider`)})]}),(0,Y.jsx)(J,{checked:e.enabled,onChange:e=>_.mutate({enabled:e})})]}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide`,children:n(`notifications.printEvents`)}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.printStarted`)}),(0,Y.jsx)(J,{checked:e.on_print_start,onChange:e=>_.mutate({on_print_start:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.plateNotEmpty`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.plateNotEmptyDescription`)})]}),(0,Y.jsx)(J,{checked:e.on_plate_not_empty??!0,onChange:e=>_.mutate({on_plate_not_empty:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.printCompleted`)}),(0,Y.jsx)(J,{checked:e.on_print_complete,onChange:e=>_.mutate({on_print_complete:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.plateClearRequired`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.plateClearRequiredDescription`)})]}),(0,Y.jsx)(J,{checked:e.on_plate_clear_required??!1,onChange:e=>_.mutate({on_plate_clear_required:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.printConfirmRequest`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.printConfirmRequestDescription`)})]}),(0,Y.jsx)(J,{checked:e.on_print_confirm_request??!0,onChange:e=>_.mutate({on_print_confirm_request:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.bedCooledLabel`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.bedCooledDescription`)})]}),(0,Y.jsx)(J,{checked:e.on_bed_cooled??!1,onChange:e=>_.mutate({on_bed_cooled:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.firstLayerCompleteLabel`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.firstLayerCompleteDescription`)})]}),(0,Y.jsx)(J,{checked:e.on_first_layer_complete??!1,onChange:e=>_.mutate({on_first_layer_complete:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.missingSpoolAssignmentLabel`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.missingSpoolAssignmentDescription`)})]}),(0,Y.jsx)(J,{checked:e.on_print_missing_spool_assignment??!1,onChange:e=>_.mutate({on_print_missing_spool_assignment:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.printFailed`)}),(0,Y.jsx)(J,{checked:e.on_print_failed,onChange:e=>_.mutate({on_print_failed:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.printStopped`)}),(0,Y.jsx)(J,{checked:e.on_print_stopped,onChange:e=>_.mutate({on_print_stopped:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.billingChargeFailedLabel`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.billingChargeFailedDescription`)})]}),(0,Y.jsx)(J,{checked:e.on_billing_charge_failed??!0,onChange:e=>_.mutate({on_billing_charge_failed:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.progressMilestones`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.progressMilestonesDescription`)})]}),(0,Y.jsx)(J,{checked:e.on_print_progress,onChange:e=>_.mutate({on_print_progress:e})})]})]}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide`,children:n(`notifications.printerStatus`)}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.printerOffline`)}),(0,Y.jsx)(J,{checked:e.on_printer_offline,onChange:e=>_.mutate({on_printer_offline:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.printerError`)}),(0,Y.jsx)(J,{checked:e.on_printer_error,onChange:e=>_.mutate({on_printer_error:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.aiFailureDetection`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.aiFailureDetectionDescription`)})]}),(0,Y.jsx)(J,{checked:e.on_ai_failure_detection??!1,onChange:e=>_.mutate({on_ai_failure_detection:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.haSensorAlert`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.haSensorAlertDescription`)})]}),(0,Y.jsx)(J,{checked:e.on_ha_sensor_alert??!1,onChange:e=>_.mutate({on_ha_sensor_alert:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.locationHaSensorAlert`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.locationHaSensorAlertDescription`)})]}),(0,Y.jsx)(J,{checked:e.on_location_ha_sensor_alert??!1,onChange:e=>_.mutate({on_location_ha_sensor_alert:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.lowFilamentLabel`)}),(0,Y.jsx)(J,{checked:e.on_filament_low,onChange:e=>_.mutate({on_filament_low:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.maintenanceDue`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.maintenanceDueDescription`)})]}),(0,Y.jsx)(J,{checked:e.on_maintenance_due??!1,onChange:e=>_.mutate({on_maintenance_due:e})})]})]}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide`,children:n(`notifications.amsAlarms`)}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.amsHumidityHigh`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.amsHumidityHighDescription`)})]}),(0,Y.jsx)(J,{checked:e.on_ams_humidity_high??!1,onChange:e=>_.mutate({on_ams_humidity_high:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.amsTemperatureHigh`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.amsTemperatureHighDescription`)})]}),(0,Y.jsx)(J,{checked:e.on_ams_temperature_high??!1,onChange:e=>_.mutate({on_ams_temperature_high:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.amsDryingSuspendedTitle`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.amsDryingSuspendedDescription`)})]}),(0,Y.jsx)(J,{checked:e.on_ams_drying_suspended??!1,onChange:e=>_.mutate({on_ams_drying_suspended:e})})]})]}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide`,children:n(`notifications.amsHtAlarms`)}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.amsHtHumidityHigh`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.amsHtHumidityHighDescription`)})]}),(0,Y.jsx)(J,{checked:e.on_ams_ht_humidity_high??!1,onChange:e=>_.mutate({on_ams_ht_humidity_high:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.amsHtTemperatureHigh`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.amsHtTemperatureHighDescription`)})]}),(0,Y.jsx)(J,{checked:e.on_ams_ht_temperature_high??!1,onChange:e=>_.mutate({on_ams_ht_temperature_high:e})})]})]}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide`,children:n(`notifications.inventoryAlerts`)}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.stockReorderAlert`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.stockReorderAlertDescription`)})]}),(0,Y.jsx)(J,{checked:e.on_stock_reorder_alert??!1,onChange:e=>_.mutate({on_stock_reorder_alert:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.stockBreakAlert`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.stockBreakAlertDescription`)})]}),(0,Y.jsx)(J,{checked:e.on_stock_break_alert??!1,onChange:e=>_.mutate({on_stock_break_alert:e})})]})]}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide`,children:n(`notifications.printQueue`)}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.jobAdded`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.jobAddedDescription`)})]}),(0,Y.jsx)(J,{checked:e.on_queue_job_added??!1,onChange:e=>_.mutate({on_queue_job_added:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.jobAssigned`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.jobAssignedDescription`)})]}),(0,Y.jsx)(J,{checked:e.on_queue_job_assigned??!1,onChange:e=>_.mutate({on_queue_job_assigned:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.jobStarted`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.jobStartedDescription`)})]}),(0,Y.jsx)(J,{checked:e.on_queue_job_started??!1,onChange:e=>_.mutate({on_queue_job_started:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.jobWaiting`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.jobWaitingDescription`)})]}),(0,Y.jsx)(J,{checked:e.on_queue_job_waiting??!0,onChange:e=>_.mutate({on_queue_job_waiting:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.jobSkipped`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.jobSkippedDescription`)})]}),(0,Y.jsx)(J,{checked:e.on_queue_job_skipped??!0,onChange:e=>_.mutate({on_queue_job_skipped:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.jobFailed`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.jobFailedDescription`)})]}),(0,Y.jsx)(J,{checked:e.on_queue_job_failed??!0,onChange:e=>_.mutate({on_queue_job_failed:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.queueComplete`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.queueCompleteDescription`)})]}),(0,Y.jsx)(J,{checked:e.on_queue_completed??!1,onChange:e=>_.mutate({on_queue_completed:e})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.appMessages`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.appMessagesDescription`)})]}),(0,Y.jsx)(J,{checked:e.on_app_message??!1,onChange:e=>_.mutate({on_app_message:e})})]})]}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(Jt,{className:`w-4 h-4 text-purple-600 dark:text-purple-400`}),(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.quietHours`)})]}),(0,Y.jsx)(J,{checked:e.quiet_hours_enabled,onChange:e=>_.mutate({quiet_hours_enabled:e})})]}),e.quiet_hours_enabled&&(0,Y.jsxs)(`div`,{className:`pl-4 border-l-2 border-bambu-dark-tertiary space-y-2`,children:[(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.noNotificationsDuring`)}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(lt,{className:`w-4 h-4 text-bambu-gray`}),(0,Y.jsxs)(`span`,{className:`text-sm text-white`,children:[b(e.quiet_hours_start)||`22:00`,` - `,b(e.quiet_hours_end)||`07:00`]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.editProviderToChangeQuietHours`)})]})]}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(w,{className:`w-4 h-4 text-emerald-600 dark:text-emerald-400`}),(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.dailyDigest`)})]}),(0,Y.jsx)(J,{checked:e.daily_digest_enabled,onChange:e=>_.mutate({daily_digest_enabled:e})})]}),e.daily_digest_enabled&&(0,Y.jsxs)(`div`,{className:`pl-4 border-l-2 border-bambu-dark-tertiary space-y-2`,children:[(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.batchNotifications`)}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(lt,{className:`w-4 h-4 text-bambu-gray`}),(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.sendAt`,{time:b(e.daily_digest_time)||`08:00`})})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.editProviderToChangeDigestTime`)})]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(ut,{className:`w-4 h-4 text-bambu-gray`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.attachPhotoLabel`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.attachPhotoDescription`)})]})]}),(0,Y.jsx)(J,{checked:e.attach_photo??!0,onChange:e=>_.mutate({attach_photo:e})})]}),(0,Y.jsxs)(`div`,{className:`flex gap-2 pt-2`,children:[(0,Y.jsxs)(K,{size:`sm`,variant:`secondary`,onClick:()=>t(e),className:`flex-1`,children:[(0,Y.jsx)(oe,{className:`w-4 h-4`}),n(`notifications.edit`)]}),(0,Y.jsx)(K,{size:`sm`,variant:`secondary`,onClick:()=>o(!0),className:`text-red-700 dark:text-red-400 hover:text-red-800 dark:hover:text-red-300`,children:(0,Y.jsx)(qe,{className:`w-4 h-4`})})]})]})]})}),a&&(0,Y.jsx)(Tt,{title:n(`notifications.deleteProvider`),message:n(`notifications.deleteConfirm`,{name:e.name}),confirmText:n(`notifications.delete`),variant:`danger`,onConfirm:()=>{v.mutate(),o(!1)},onCancel:()=>o(!1)})]})}var Dr=[`email`,`telegram`,`discord`,`ntfy`,`pushover`,`bark`,`gotify`,`callmebot`,`webhook`,`homeassistant`];function Or({provider:e,onClose:t}){let{t:n,i18n:i}=l(),a=u(),o=!!e,[s,c]=(0,X.useState)(e?.name||``),[p,m]=(0,X.useState)(e?.provider_type||`email`),[h,g]=(0,X.useState)(e?.printer_id||null),[_,v]=(0,X.useState)(e?.attach_photo??!0),[y,b]=(0,X.useState)(e?.quiet_hours_enabled||!1),[x,S]=(0,X.useState)(e?.quiet_hours_start||`22:00`),[C,w]=(0,X.useState)(e?.quiet_hours_end||`07:00`),[T,E]=(0,X.useState)(e?.daily_digest_enabled||!1),[D,k]=(0,X.useState)(e?.daily_digest_time||`08:00`),[A,ee]=(0,X.useState)(e?.on_print_start??!1),[M,N]=(0,X.useState)(e?.on_print_complete??!0),[P,te]=(0,X.useState)(e?.on_print_failed??!0),[F,ne]=(0,X.useState)(e?.on_print_stopped??!0),[I,re]=(0,X.useState)(e?.on_print_progress??!1),[ie,L]=(0,X.useState)(e?.on_billing_charge_failed??!0),[ae,z]=(0,X.useState)(e?.on_printer_offline??!1),[oe,se]=(0,X.useState)(e?.on_printer_error??!1),[B,ce]=(0,X.useState)(e?.on_ai_failure_detection??!1),[le,ue]=(0,X.useState)(e?.on_filament_low??!1),[de,fe]=(0,X.useState)(e?.on_maintenance_due??!1),[V,pe]=(0,X.useState)(e?.on_stock_reorder_alert??!1),[me,he]=(0,X.useState)(e?.on_stock_break_alert??!1),[ge,_e]=(0,X.useState)(e?.on_plate_clear_required??!1),[ve,ye]=(0,X.useState)(e?.on_print_confirm_request??!0),[be,H]=(0,X.useState)(e?.telegram_verdict_mode??`buttons`),[xe,Se]=(0,X.useState)(e?.on_bed_cooled??!1),[Ce,we]=(0,X.useState)(e?.on_ha_sensor_alert??!1),[Te,Ee]=(0,X.useState)(e?.on_location_ha_sensor_alert??!1),[De,Oe]=(0,X.useState)(e?.on_first_layer_complete??!1),[ke,Ae]=(0,X.useState)(e?.on_app_message??!1),[je,Me]=(0,X.useState)(e?.config?Object.fromEntries(Object.entries(e.config).filter(([e])=>e!==`event_priorities`).map(([e,t])=>[e,String(t)])):{}),[Ne,Pe]=(0,X.useState)((()=>{let t=e?.config?.event_priorities;if(!t||typeof t!=`object`)return{};let n={};for(let[e,r]of Object.entries(t)){let t=Number(r);Number.isInteger(t)&&t>=1&&t<=5&&(n[e]=t)}return n})()),[Fe,Ie]=(0,X.useState)(null),[Le,U]=(0,X.useState)(null),{data:W}=d({queryKey:[`printers`],queryFn:r.getPrinters});(0,X.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]);let ze=f({mutationFn:()=>r.testNotificationConfig({provider_type:p,config:je,attach_photo:_}),onSuccess:e=>{Ie(e),U(null)},onError:e=>{Ie({success:!1,message:e.message})}}),G=f({mutationFn:e=>r.createNotificationProvider(e),onSuccess:()=>{a.invalidateQueries({queryKey:[`notification-providers`]}),t()},onError:e=>{U(e.message)}}),Be=f({mutationFn:t=>r.updateNotificationProvider(e.id,t),onSuccess:()=>{a.invalidateQueries({queryKey:[`notification-providers`]}),t()},onError:e=>{U(e.message)}}),Ve=e=>{if(e.preventDefault(),U(null),!s.trim()){U(n(`notifications.nameRequired`));return}let t=We(p);for(let e of t)if(!je[e.key]?.trim()){U(n(`notifications.fieldRequired`,{field:e.label}));return}if(p===`homeassistant`&&je.data?.trim()){let e;try{e=JSON.parse(je.data)}catch{U(n(`notifications.haDataInvalid`));return}if(typeof e!=`object`||!e||Array.isArray(e)){U(n(`notifications.haDataInvalid`));return}}if(p===`telegram`&&je.message_thread_id?.trim()&&!/^\d+$/.test(je.message_thread_id.trim())){U(n(`notifications.telegramThreadIdInvalid`));return}let r=(p===`ntfy`||p===`gotify`)&&Object.keys(Ne).length>0?{...je,event_priorities:Ne}:je,i={name:s.trim(),provider_type:p,config:r,printer_id:h,attach_photo:_,quiet_hours_enabled:y,quiet_hours_start:y?x:null,quiet_hours_end:y?C:null,daily_digest_enabled:T,daily_digest_time:T?D:null,on_print_start:A,on_print_complete:M,on_print_failed:P,on_print_stopped:F,on_print_progress:I,on_billing_charge_failed:ie,on_printer_offline:ae,on_printer_error:oe,on_ai_failure_detection:B,on_filament_low:le,on_maintenance_due:de,on_stock_reorder_alert:V,on_stock_break_alert:me,on_plate_clear_required:ge,on_print_confirm_request:ve,telegram_verdict_mode:p===`telegram`?be:`buttons`,on_bed_cooled:xe,on_ha_sensor_alert:Ce,on_location_ha_sensor_alert:Te,on_first_layer_complete:De,on_app_message:ke};o?Be.mutate(i):G.mutate(i)},He=G.isPending||Be.isPending,Ue=e=>{switch(e){case`callmebot`:return[{key:`phone`,label:`Phone Number`,placeholder:`+1234567890`,type:`text`,required:!0},{key:`apikey`,label:`API Key`,placeholder:`Your CallMeBot API key`,type:`text`,required:!0}];case`ntfy`:return[{key:`server`,label:`Server URL`,placeholder:`https://ntfy.sh`,type:`text`,required:!1},{key:`topic`,label:`Topic`,placeholder:`my-bambuddy`,type:`text`,required:!0},{key:`auth_token`,label:`Auth Token`,placeholder:`Optional authentication`,type:`password`,required:!1}];case`pushover`:return[{key:`user_key`,label:`User Key`,placeholder:`Your Pushover user key`,type:`text`,required:!0},{key:`app_token`,label:`App Token`,placeholder:`Your Pushover app token`,type:`text`,required:!0},{key:`priority`,label:`Priority`,placeholder:`0 (normal)`,type:`number`,required:!1},{key:`retry`,label:n(`notifications.pushoverRetry`),placeholder:`60`,type:`number`,required:!1,showIf:e=>e.priority===`2`},{key:`expire`,label:n(`notifications.pushoverExpire`),placeholder:`3600`,type:`number`,required:!1,showIf:e=>e.priority===`2`}];case`telegram`:return[{key:`bot_token`,label:`Bot Token`,placeholder:`Bot token from @BotFather`,type:`password`,required:!0},{key:`chat_id`,label:`Chat ID`,placeholder:`Your chat or group ID`,type:`text`,required:!0},{key:`message_thread_id`,label:n(`notifications.telegramThreadId`),placeholder:`123`,type:`number`,required:!1,help:n(`notifications.telegramThreadIdHelp`)}];case`email`:return[{key:`smtp_server`,label:`SMTP Server`,placeholder:`smtp.gmail.com`,type:`text`,required:!0},{key:`smtp_port`,label:`SMTP Port`,placeholder:`587`,type:`number`,required:!1},{key:`security`,label:`Security`,type:`select`,required:!1,options:[{value:`starttls`,label:`STARTTLS (Port 587)`},{value:`ssl`,label:`SSL/TLS (Port 465)`},{value:`none`,label:`None (Port 25)`}]},{key:`auth_enabled`,label:`Authentication`,type:`select`,required:!1,options:[{value:`true`,label:`Enabled`},{value:`false`,label:`Disabled`}]},{key:`username`,label:`Username`,placeholder:`your@email.com`,type:`text`,required:!1},{key:`password`,label:`Password`,placeholder:`App password`,type:`password`,required:!1},{key:`from_email`,label:`From Email`,placeholder:`your@email.com`,type:`text`,required:!0},{key:`to_email`,label:`To Email`,placeholder:`recipient@email.com`,type:`text`,required:!0}];case`discord`:return[{key:`webhook_url`,label:`Webhook URL`,placeholder:`https://discord.com/api/webhooks/...`,type:`text`,required:!0}];case`webhook`:return[{key:`webhook_url`,label:`Webhook URL`,placeholder:`https://example.com/webhook`,type:`text`,required:!0},{key:`payload_format`,label:`Payload Format`,type:`select`,required:!1,options:[{value:`generic`,label:`Generic JSON`},{value:`slack`,label:`Slack / Mattermost`}]},{key:`auth_header`,label:`Authorization`,placeholder:`Bearer token (optional)`,type:`password`,required:!1},{key:`field_title`,label:`Title Field Name`,placeholder:`title`,type:`text`,required:!1,showIf:e=>e.payload_format!==`slack`},{key:`field_message`,label:`Message Field Name`,placeholder:`message`,type:`text`,required:!1,showIf:e=>e.payload_format!==`slack`}];case`homeassistant`:return[{key:`service`,label:`Home Assistant Service`,placeholder:`notify.mobile_app_myphone`,type:`text`,required:!1,help:n(`notifications.haServiceHelp`)},{key:`data`,label:`Data (JSON, optional)`,placeholder:`{"priority": "high", "ttl": 0, "channel": "3D Printing"}`,type:`textarea`,required:!1}];case`bark`:return[{key:`device_key`,label:`Device Key`,placeholder:`Your Bark device key`,type:`text`,required:!0},{key:`server`,label:`Server URL`,placeholder:`https://api.day.app`,type:`text`,required:!1},{key:`group`,label:`Group`,placeholder:`Bambuddy`,type:`text`,required:!1},{key:`sound`,label:`Sound`,placeholder:`minuet`,type:`text`,required:!1},{key:`level`,label:`Interruption Level`,type:`select`,required:!1,options:[{value:``,label:`Default`},{value:`active`,label:`Active`},{value:`timeSensitive`,label:`Time Sensitive`},{value:`critical`,label:`Critical (bypasses Silent/Focus)`},{value:`passive`,label:`Passive (no sound)`}]}];case`gotify`:return[{key:`server`,label:`Server URL`,placeholder:`https://gotify.example.com`,type:`text`,required:!0},{key:`app_token`,label:`App Token`,placeholder:`Token of a Gotify application`,type:`password`,required:!0}];default:return[]}},We=e=>Ue(e).filter(e=>e.required),Ge=Ue(p);return(0,Y.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4 overflow-y-auto`,onClick:t,children:(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-lg my-8 max-h-[90vh] overflow-y-auto`,onClick:e=>e.stopPropagation(),children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:n(o?`notifications.editTitle`:`notifications.addTitle`)}),(0,Y.jsx)(`button`,{onClick:t,className:`text-bambu-gray hover:text-white transition-colors`,children:(0,Y.jsx)(Re,{className:`w-5 h-5`})})]}),(0,Y.jsxs)(`form`,{onSubmit:Ve,className:`p-6 space-y-4`,children:[Le&&(0,Y.jsx)(`div`,{className:`p-3 bg-red-100 dark:bg-red-500/20 border border-red-300 dark:border-red-500/50 rounded-lg text-sm text-red-700 dark:text-red-400`,children:Le}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`notifications.nameLabel`)}),(0,Y.jsx)(`input`,{type:`text`,value:s,onChange:e=>c(e.target.value),placeholder:n(`notifications.namePlaceholder`),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`notifications.providerTypeLabel`)}),(0,Y.jsx)(`select`,{value:p,onChange:e=>{m(e.target.value),Me({}),Ie(null)},disabled:o,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none disabled:opacity-50`,children:Dr.map(e=>({value:e,label:n(`notifications.providerTypes.${e}`,e)})).sort((e,t)=>e.label.localeCompare(t.label,i.language,{sensitivity:`base`})).map(({value:e,label:t})=>(0,Y.jsx)(`option`,{value:e,children:t},e))}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(`notifications.providerDescriptions.${p}`,``)})]}),(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`notifications.configuration`)}),Ge.filter(e=>!(`showIf`in e)||e.showIf?.(je)!==!1).map(e=>(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[e.label,` `,e.required&&`*`]}),e.type===`select`&&`options`in e&&e.options?(0,Y.jsx)(`select`,{value:je[e.key]||e.options[0]?.value||``,onChange:t=>{Me({...je,[e.key]:t.target.value}),Ie(null)},className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:e.options.map(e=>(0,Y.jsx)(`option`,{value:e.value,children:e.label},e.value))}):e.type===`textarea`?(0,Y.jsx)(`textarea`,{value:je[e.key]||``,onChange:t=>{Me({...je,[e.key]:t.target.value}),Ie(null)},placeholder:e.placeholder,rows:3,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none font-mono text-sm`}):(0,Y.jsx)(`input`,{type:e.type,value:je[e.key]||``,onChange:t=>{Me({...je,[e.key]:t.target.value}),Ie(null)},placeholder:e.placeholder,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),`help`in e&&e.help&&(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e.help})]},e.key)),p===`telegram`&&(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{htmlFor:`telegram-verdict-mode`,className:`block text-sm text-bambu-gray mb-1`,children:n(`notifications.telegramVerdictMode`)}),(0,Y.jsxs)(`select`,{id:`telegram-verdict-mode`,value:be,onChange:e=>H(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`,children:[(0,Y.jsx)(`option`,{value:`buttons`,children:n(`notifications.telegramVerdictModeButtons`)}),(0,Y.jsx)(`option`,{value:`reactions`,children:n(`notifications.telegramVerdictModeReactions`)}),(0,Y.jsx)(`option`,{value:`both`,children:n(`notifications.telegramVerdictModeBoth`)})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(`notifications.telegramVerdictModeHelp`)})]})]}),(0,Y.jsx)(`div`,{className:`flex gap-2`,children:(0,Y.jsxs)(K,{type:`button`,variant:`secondary`,onClick:()=>{Ie(null),ze.mutate()},disabled:ze.isPending||We(p).length>0&&!je[We(p)[0]?.key],className:`flex-1`,children:[ze.isPending?(0,Y.jsx)(R,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(Sn,{className:`w-4 h-4`}),n(`notifications.testConfiguration`)]})}),Fe&&(0,Y.jsx)(`div`,{className:`p-3 rounded-lg flex items-center gap-2 ${Fe.success?`bg-bambu-green/20 border border-bambu-green/50 text-bambu-green`:`bg-red-100 dark:bg-red-500/20 border border-red-300 dark:border-red-500/50 text-red-700 dark:text-red-400`}`,children:Fe.success?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(j,{className:`w-5 h-5`}),(0,Y.jsx)(`span`,{children:Fe.message})]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(O,{className:`w-5 h-5`}),(0,Y.jsx)(`span`,{children:Fe.message})]})}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`notifications.printerFilter`)}),(0,Y.jsxs)(`select`,{value:h??``,onChange:e=>g(e.target.value?Number(e.target.value):null),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,Y.jsx)(`option`,{value:``,children:n(`notifications.allPrinters`)}),W?.map(e=>(0,Y.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(`notifications.onlyFromPrinter`)})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`text-sm text-white`,children:n(`notifications.attachPhotoLabel`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.attachPhotoDescription`)})]}),(0,Y.jsx)(J,{checked:_,onChange:v})]}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`label`,{className:`text-sm text-white`,children:n(`notifications.quietHoursDnd`)}),(0,Y.jsx)(J,{checked:y,onChange:b})]}),y&&(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:n(`notifications.quietStart`)}),(0,Y.jsx)(`input`,{type:`time`,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 focus:border-bambu-green focus:outline-none`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:n(`notifications.quietEnd`)}),(0,Y.jsx)(`input`,{type:`time`,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 focus:border-bambu-green focus:outline-none`})]})]})]}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`text-sm text-white`,children:n(`notifications.dailyDigestLabel`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.batchNotifications`)})]}),(0,Y.jsx)(J,{checked:T,onChange:E})]}),T&&(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:n(`notifications.sendDigestAt`)}),(0,Y.jsx)(`input`,{type:`time`,value:D,onChange:e=>k(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`}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(`notifications.digestCollected`)})]})]}),(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`notifications.notificationEvents`)}),(0,Y.jsxs)(`div`,{className:`space-y-2 p-3 bg-bambu-dark rounded-lg`,children:[(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide mb-2`,children:n(`notifications.printEvents`)}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.start`)}),(0,Y.jsx)(J,{checked:A,onChange:ee})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.complete`)}),(0,Y.jsx)(J,{checked:M,onChange:N})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.failed`)}),(0,Y.jsx)(J,{checked:P,onChange:te})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.stopped`)}),(0,Y.jsx)(J,{checked:F,onChange:ne})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between col-span-2`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.progress`)}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1`,children:n(`notifications.progressPercent`)})]}),(0,Y.jsx)(J,{checked:I,onChange:re})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between col-span-2`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.billingChargeFailedLabel`)}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1`,children:n(`notifications.billingChargeFailedDescription`)})]}),(0,Y.jsx)(J,{checked:ie,onChange:L})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between col-span-2`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.plateClearRequired`)}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1`,children:n(`notifications.plateClearRequiredDescription`)})]}),(0,Y.jsx)(J,{checked:ge,onChange:_e})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between col-span-2`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.printConfirmRequest`)}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1`,children:n(`notifications.printConfirmRequestDescription`)})]}),(0,Y.jsx)(J,{checked:ve,onChange:ye})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between col-span-2`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.bedCooled`)}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1`,children:n(`notifications.bedCooledAfterPrint`)})]}),(0,Y.jsx)(J,{checked:xe,onChange:Se})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between col-span-2`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.firstLayerCompleteLabel`)}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1`,children:n(`notifications.firstLayerCompleteDescription`)})]}),(0,Y.jsx)(J,{checked:De,onChange:Oe})]})]})]}),(0,Y.jsxs)(`div`,{className:`space-y-2 p-3 bg-bambu-dark rounded-lg`,children:[(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide mb-2`,children:n(`notifications.printerStatus`)}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.offline`)}),(0,Y.jsx)(J,{checked:ae,onChange:z})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between col-span-2`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.haSensorAlert`)}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1`,children:n(`notifications.haSensorAlertDescription`)})]}),(0,Y.jsx)(J,{checked:Ce,onChange:we})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between col-span-2`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.locationHaSensorAlert`)}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1`,children:n(`notifications.locationHaSensorAlertDescription`)})]}),(0,Y.jsx)(J,{checked:Te,onChange:Ee})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.error`)}),(0,Y.jsx)(J,{checked:oe,onChange:se})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.aiFailureDetection`)}),(0,Y.jsx)(J,{checked:B,onChange:ce})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.lowFilament`)}),(0,Y.jsx)(J,{checked:le,onChange:ue})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.maintenance`)}),(0,Y.jsx)(J,{checked:de,onChange:fe})]})]})]}),(0,Y.jsxs)(`div`,{className:`space-y-2 p-3 bg-bambu-dark rounded-lg`,children:[(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide mb-2`,children:n(`notifications.inventoryAlerts`)}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 gap-2`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.stockReorderAlert`)}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1`,children:n(`notifications.stockReorderAlertDescription`)})]}),(0,Y.jsx)(J,{checked:V,onChange:pe})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.stockBreakAlert`)}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1`,children:n(`notifications.stockBreakAlertDescription`)})]}),(0,Y.jsx)(J,{checked:me,onChange:he})]})]})]}),(0,Y.jsxs)(`div`,{className:`space-y-2 p-3 bg-bambu-dark rounded-lg`,children:[(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide mb-2`,children:n(`notifications.connectedApps`)}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.appMessages`)}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1`,children:n(`notifications.appMessagesDescription`)})]}),(0,Y.jsx)(J,{checked:ke,onChange:Ae})]})]}),(p===`ntfy`||p===`gotify`)&&(()=>{let e=[];return A&&e.push({key:`on_print_start`,label:n(`notifications.start`)}),M&&e.push({key:`on_print_complete`,label:n(`notifications.complete`)}),P&&e.push({key:`on_print_failed`,label:n(`notifications.failed`)}),F&&e.push({key:`on_print_stopped`,label:n(`notifications.stopped`)}),I&&e.push({key:`on_print_progress`,label:n(`notifications.progress`)}),ie&&e.push({key:`on_billing_charge_failed`,label:n(`notifications.billingChargeFailedLabel`)}),ge&&e.push({key:`on_plate_clear_required`,label:n(`notifications.plateClearRequired`)}),ve&&e.push({key:`on_print_confirm_request`,label:n(`notifications.printConfirmRequest`)}),xe&&e.push({key:`on_bed_cooled`,label:n(`notifications.bedCooled`)}),De&&e.push({key:`on_first_layer_complete`,label:n(`notifications.firstLayerCompleteLabel`)}),ae&&e.push({key:`on_printer_offline`,label:n(`notifications.offline`)}),oe&&e.push({key:`on_printer_error`,label:n(`notifications.error`)}),Ce&&e.push({key:`on_ha_sensor_alert`,label:n(`notifications.haSensorAlert`)}),Te&&e.push({key:`on_location_ha_sensor_alert`,label:n(`notifications.locationHaSensorAlert`)}),B&&e.push({key:`on_ai_failure_detection`,label:n(`notifications.aiFailureDetection`)}),le&&e.push({key:`on_filament_low`,label:n(`notifications.lowFilament`)}),de&&e.push({key:`on_maintenance_due`,label:n(`notifications.maintenance`)}),V&&e.push({key:`on_stock_reorder_alert`,label:n(`notifications.stockReorderAlert`)}),me&&e.push({key:`on_stock_break_alert`,label:n(`notifications.stockBreakAlert`)}),e.length===0?null:(0,Y.jsxs)(`div`,{className:`space-y-2 p-3 bg-bambu-dark rounded-lg`,children:[(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide mb-1`,children:n(p===`gotify`?`notifications.eventPriority.sectionTitleGotify`:`notifications.eventPriority.sectionTitle`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:n(p===`gotify`?`notifications.eventPriority.helpGotify`:`notifications.eventPriority.helpNtfy`)}),(0,Y.jsx)(`div`,{className:`space-y-2`,children:e.map(e=>(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:e.label}),(0,Y.jsxs)(`select`,{value:Ne[e.key]??3,onChange:t=>{let n=Number(t.target.value);Pe(t=>({...t,[e.key]:n}))},className:`px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-sm text-white focus:border-bambu-green focus:outline-none`,children:[(0,Y.jsx)(`option`,{value:1,children:n(`notifications.eventPriority.min`)}),(0,Y.jsx)(`option`,{value:2,children:n(`notifications.eventPriority.low`)}),(0,Y.jsx)(`option`,{value:3,children:n(`notifications.eventPriority.default`)}),(0,Y.jsx)(`option`,{value:4,children:n(`notifications.eventPriority.high`)}),(0,Y.jsx)(`option`,{value:5,children:n(`notifications.eventPriority.urgent`)})]})]},e.key))})]})})()]}),(0,Y.jsxs)(`div`,{className:`flex gap-3 pt-2`,children:[(0,Y.jsx)(K,{type:`button`,variant:`secondary`,onClick:t,className:`flex-1`,children:n(`notifications.cancel`)}),(0,Y.jsxs)(K,{type:`submit`,disabled:He,className:`flex-1`,children:[He?(0,Y.jsx)(R,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(_t,{className:`w-4 h-4`}),n(o?`notifications.save`:`notifications.add`)]})]})]})]})})}function kr({template:e,onClose:t}){let{t:n}=l(),i=u(),a=(0,X.useRef)(null),[o,s]=(0,X.useState)(e.title_template),[c,p]=(0,X.useState)(e.body_template),[m,h]=(0,X.useState)(null),[g,_]=(0,X.useState)(!0),{data:v}=d({queryKey:[`template-variables`],queryFn:r.getTemplateVariables}),y=v?.find(t=>t.event_type===e.event_type),{data:b,isLoading:x}=d({queryKey:[`template-preview`,e.event_type,o,c],queryFn:()=>r.previewTemplate({event_type:e.event_type,title_template:o,body_template:c}),enabled:g&&o.length>0&&c.length>0});(0,X.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]);let S=f({mutationFn:t=>r.updateNotificationTemplate(e.id,t),onSuccess:()=>{i.invalidateQueries({queryKey:[`notification-templates`]}),t()},onError:e=>{h(e.message)}}),C=f({mutationFn:()=>r.resetNotificationTemplate(e.id),onSuccess:e=>{s(e.title_template),p(e.body_template),i.invalidateQueries({queryKey:[`notification-templates`]})},onError:e=>{h(e.message)}}),w=e=>{if(e.preventDefault(),h(null),!o.trim()){h(n(`notifications.titleRequired`));return}if(!c.trim()){h(n(`notifications.bodyRequired`));return}S.mutate({title_template:o,body_template:c})},T=e=>{let t=a.current;if(!t)return;let n=t.selectionStart,r=t.selectionEnd,i=c,o=i.substring(0,n),s=i.substring(r);p(o+`{${e}}`+s),setTimeout(()=>{t.focus();let r=n+e.length+2;t.setSelectionRange(r,r)},0)},E=o!==e.title_template||c!==e.body_template;return(0,Y.jsx)(`div`,{className:`fixed inset-0 bg-black/80 flex items-center justify-center z-50 p-4`,children:(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-2xl max-h-[90vh] flex flex-col`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary shrink-0`,children:[(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:n(`notifications.editTemplate`,{name:e.name})}),(0,Y.jsx)(`button`,{onClick:t,className:`p-1 hover:bg-bambu-dark-tertiary rounded transition-colors`,children:(0,Y.jsx)(Re,{className:`w-5 h-5 text-bambu-gray`})})]}),(0,Y.jsxs)(`form`,{onSubmit:w,className:`flex-1 overflow-y-auto p-4 space-y-4`,children:[m&&(0,Y.jsx)(`div`,{className:`p-3 bg-red-100 dark:bg-red-500/20 border border-red-300 dark:border-red-500/50 rounded text-red-700 dark:text-red-400 text-sm`,children:m}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:n(`notifications.titleLabel`)}),(0,Y.jsx)(`input`,{type:`text`,value:o,onChange:e=>s(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white focus:outline-none focus:ring-1 focus:ring-bambu-green`,placeholder:n(`notifications.titlePlaceholder`)})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:n(`notifications.bodyLabel`)}),(0,Y.jsx)(`textarea`,{ref:a,value:c,onChange:e=>p(e.target.value),rows:4,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white focus:outline-none focus:ring-1 focus:ring-bambu-green font-mono text-sm resize-none`,placeholder:n(`notifications.bodyPlaceholder`)})]}),y&&(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-2`,children:n(`notifications.availableVariables`)}),(0,Y.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:y.variables.map(e=>(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>T(e),className:`inline-flex items-center gap-1 px-2 py-1 bg-bambu-dark hover:bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-xs text-bambu-gray hover:text-white transition-colors`,children:[(0,Y.jsx)(wt,{className:`w-3 h-3`}),e]},e))}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray/60 mt-1`,children:n(`notifications.clickToInsert`)})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,Y.jsxs)(`label`,{className:`text-sm font-medium text-bambu-gray flex items-center gap-2`,children:[(0,Y.jsx)(mt,{className:`w-4 h-4`}),n(`notifications.livePreview`)]}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>_(!g),className:`text-xs text-bambu-green hover:text-bambu-green-light`,children:n(g?`notifications.hide`:`notifications.show`)})]}),g&&(0,Y.jsx)(`div`,{className:`bg-bambu-dark border border-bambu-dark-tertiary rounded p-3 space-y-2`,children:x?(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray text-sm`,children:[(0,Y.jsx)(R,{className:`w-4 h-4 animate-spin`}),n(`notifications.loadingPreview`)]}):b?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:n(`notifications.titlePreview`)}),(0,Y.jsx)(`div`,{className:`text-white font-medium`,children:b.title})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:n(`notifications.bodyPreview`)}),(0,Y.jsx)(`div`,{className:`text-white whitespace-pre-wrap text-sm`,children:b.body})]}),y?.supports_photo&&(0,Y.jsxs)(`div`,{className:`pt-2 mt-2 border-t border-bambu-dark-tertiary/60 flex items-center gap-3`,children:[(0,Y.jsx)(`img`,{src:`/img/screenshot-desktop.png`,alt:n(`notifications.photoPreview`),className:`w-24 h-14 object-cover rounded border border-bambu-dark-tertiary shrink-0`}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:e.event_type.startsWith(`user_`)?n(`notifications.photoPreviewNoteEmailOnly`):y.variables.includes(`finish_photo_url`)?n(`notifications.photoPreviewNoteWithEmail`):n(`notifications.photoPreviewNote`)})]})]}):(0,Y.jsx)(`div`,{className:`text-bambu-gray text-sm`,children:n(`notifications.enterTemplateContent`)})})]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-t border-bambu-dark-tertiary shrink-0`,children:[(0,Y.jsxs)(K,{type:`button`,variant:`ghost`,onClick:()=>C.mutate(),disabled:C.isPending,className:`text-orange-600 dark:text-orange-400 hover:text-orange-700 dark:hover:text-orange-300`,children:[C.isPending?(0,Y.jsx)(R,{className:`w-4 h-4 animate-spin mr-2`}):(0,Y.jsx)(nt,{className:`w-4 h-4 mr-2`}),n(`notifications.resetToDefault`)]}),(0,Y.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Y.jsx)(K,{type:`button`,variant:`secondary`,onClick:t,children:n(`notifications.cancel`)}),(0,Y.jsxs)(K,{onClick:w,disabled:S.isPending||!E,children:[S.isPending?(0,Y.jsx)(R,{className:`w-4 h-4 animate-spin mr-2`}):(0,Y.jsx)(_t,{className:`w-4 h-4 mr-2`}),n(`notifications.save`)]})]})]})]})})}var Ar={print_start:`text-blue-700 dark:text-blue-400`,print_complete:`text-bambu-green`,print_failed:`text-red-700 dark:text-red-400`,print_stopped:`text-orange-700 dark:text-orange-400`,print_progress:`text-yellow-700 dark:text-yellow-400`,printer_offline:`text-gray-400`,printer_error:`text-rose-700 dark:text-rose-400`,filament_low:`text-cyan-700 dark:text-cyan-400`,maintenance_due:`text-purple-700 dark:text-purple-400`,test:`text-bambu-gray`};function jr({onClose:e}){let{t}=l(),n=u(),{showToast:i}=ee(),[a,o]=(0,X.useState)(7),[s,c]=(0,X.useState)(null),[p,m]=(0,X.useState)(!1),{data:h}=d({queryKey:[`settings`],queryFn:r.getSettings}),g=h?.time_format||`system`,{data:_,isLoading:v,refetch:y,isRefetching:b}=d({queryKey:[`notification-logs`,a,p],queryFn:()=>r.getNotificationLogs({days:a,limit:100,success:p?!1:void 0})}),{data:x}=d({queryKey:[`notification-log-stats`,a],queryFn:()=>r.getNotificationLogStats(a)}),S=f({mutationFn:()=>r.clearNotificationLogs(30),onSuccess:e=>{i(e.message,`success`),n.invalidateQueries({queryKey:[`notification-logs`]}),n.invalidateQueries({queryKey:[`notification-log-stats`]})},onError:e=>{i(`Failed to clear logs: ${e.message}`,`error`)}}),C=e=>{let n=We(e);if(!n)return``;let r=new Date().getTime()-n.getTime();return r<6e4?t(`notifications.justNow`):r<36e5?`${Math.floor(r/6e4)}m ago`:r<864e5?`${Math.floor(r/36e5)}h ago`:n.toLocaleDateString()+` `+Ve(n,g)};return(0,Y.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,children:(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg w-full max-w-3xl max-h-[85vh] flex flex-col`,children:[(0,Y.jsxs)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Y.jsx)(ie,{className:`w-5 h-5 text-bambu-green`}),(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:t(`notifications.notificationLog`)})]}),(0,Y.jsx)(`button`,{onClick:e,className:`text-bambu-gray hover:text-white transition-colors`,children:`×`})]}),x&&(0,Y.jsx)(`div`,{className:`px-4 py-3 border-b border-bambu-dark-tertiary bg-bambu-dark/50`,children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-6 text-sm`,children:[(0,Y.jsxs)(`span`,{className:`text-bambu-gray`,children:[t(`notifications.statsSummary`,{days:a}),` `,(0,Y.jsx)(`span`,{className:`text-white font-medium`,children:x.total}),` `,t(`notifications.statsNotifications`)]}),(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 text-bambu-green`,children:[(0,Y.jsx)(j,{className:`w-4 h-4`}),t(`notifications.statsSent`,{count:x.success_count})]}),x.failure_count>0&&(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 text-red-700 dark:text-red-400`,children:[(0,Y.jsx)(O,{className:`w-4 h-4`}),t(`notifications.statsFailed`,{count:x.failure_count})]})]})}),(0,Y.jsxs)(`div`,{className:`px-4 py-3 border-b border-bambu-dark-tertiary flex items-center gap-4`,children:[(0,Y.jsxs)(`select`,{value:a,onChange:e=>o(Number(e.target.value)),className:`px-3 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:outline-none focus:ring-1 focus:ring-bambu-green`,children:[(0,Y.jsx)(`option`,{value:1,children:t(`notifications.last24Hours`)}),(0,Y.jsx)(`option`,{value:7,children:t(`notifications.last7Days`)}),(0,Y.jsx)(`option`,{value:30,children:t(`notifications.last30Days`)}),(0,Y.jsx)(`option`,{value:90,children:t(`notifications.last90Days`)})]}),(0,Y.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-bambu-gray cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:p,onChange:e=>m(e.target.checked),className:`rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),t(`notifications.showFailedOnly`)]}),(0,Y.jsx)(`div`,{className:`flex-1`}),(0,Y.jsxs)(K,{size:`sm`,variant:`secondary`,onClick:()=>y(),disabled:b,children:[b?(0,Y.jsx)(R,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(at,{className:`w-4 h-4`}),t(`notifications.refresh`)]}),(0,Y.jsxs)(K,{size:`sm`,variant:`secondary`,onClick:()=>S.mutate(),disabled:S.isPending,className:`text-red-700 dark:text-red-400 hover:text-red-800 dark:hover:text-red-300`,children:[S.isPending?(0,Y.jsx)(R,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(qe,{className:`w-4 h-4`}),t(`notifications.clearOld`)]})]}),(0,Y.jsx)(`div`,{className:`flex-1 overflow-y-auto p-4`,children:v?(0,Y.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,Y.jsx)(R,{className:`w-6 h-6 text-bambu-green animate-spin`})}):_&&_.length>0?(0,Y.jsx)(`div`,{className:`space-y-2`,children:_.map(e=>(0,Y.jsx)(Mr,{log:e,isExpanded:s===e.id,onToggle:()=>c(s===e.id?null:e.id),formatDate:C,formatFullDate:e=>Be(e,g)},e.id))}):(0,Y.jsxs)(`div`,{className:`text-center py-12 text-bambu-gray`,children:[(0,Y.jsx)(ie,{className:`w-12 h-12 mx-auto mb-3 opacity-30`}),(0,Y.jsx)(`p`,{className:`text-sm`,children:t(p?`notifications.noFailedNotifications`:`notifications.noNotificationsLogged`)})]})})]})})}function Mr({log:e,isExpanded:t,onToggle:n,formatDate:r,formatFullDate:i}){let{t:a}=l();return(0,Y.jsxs)(`div`,{className:`border rounded-lg overflow-hidden transition-colors ${e.success?`border-bambu-dark-tertiary bg-bambu-dark/30`:`border-red-500/30 bg-red-500/5`}`,children:[(0,Y.jsxs)(`button`,{className:`w-full px-3 py-2 flex items-center gap-3 text-left hover:bg-bambu-dark/50 transition-colors`,onClick:n,children:[e.success?(0,Y.jsx)(j,{className:`w-4 h-4 text-bambu-green shrink-0`}):(0,Y.jsx)(O,{className:`w-4 h-4 text-red-600 dark:text-red-400 shrink-0`}),(0,Y.jsx)(`span`,{className:`text-xs font-medium ${Ar[e.event_type]||`text-bambu-gray`}`,children:a(`notifications.eventTypes.${e.event_type}`,e.event_type)}),(0,Y.jsx)(`span`,{className:`text-sm text-white truncate flex-1`,children:e.provider_name||a(`notifications.unknownProvider`)}),e.printer_name&&(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:e.printer_name}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray shrink-0`,children:r(e.created_at)}),t?(0,Y.jsx)(D,{className:`w-4 h-4 text-bambu-gray shrink-0`}):(0,Y.jsx)(E,{className:`w-4 h-4 text-bambu-gray shrink-0`})]}),t&&(0,Y.jsxs)(`div`,{className:`px-3 py-2 border-t border-bambu-dark-tertiary bg-bambu-dark/20 space-y-2`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mb-1`,children:a(`notifications.logTitle`)}),(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:e.title})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mb-1`,children:a(`notifications.logMessage`)}),(0,Y.jsx)(`p`,{className:`text-sm text-white whitespace-pre-wrap`,children:e.message})]}),!e.success&&e.error_message&&(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-xs text-red-700 dark:text-red-400 mb-1`,children:a(`notifications.logError`)}),(0,Y.jsx)(`p`,{className:`text-sm text-red-700 dark:text-red-300`,children:e.error_message})]}),(0,Y.jsxs)(`div`,{className:`flex gap-4 text-xs text-bambu-gray pt-1`,children:[(0,Y.jsx)(`span`,{children:a(`notifications.logProvider`,{type:e.provider_type})}),(0,Y.jsx)(`span`,{children:a(`notifications.logTime`,{time:i(e.created_at)})})]})]})]})}var Nr=Object.defineProperty,Pr=Object.getOwnPropertySymbols,Fr=Object.prototype.hasOwnProperty,Ir=Object.prototype.propertyIsEnumerable,Lr=(e,t,n)=>t in e?Nr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Rr=(e,t)=>{for(var n in t||={})Fr.call(t,n)&&Lr(e,n,t[n]);if(Pr)for(var n of Pr(t))Ir.call(t,n)&&Lr(e,n,t[n]);return e},zr=(e,t)=>{var n={};for(var r in e)Fr.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&Pr)for(var r of Pr(e))t.indexOf(r)<0&&Ir.call(e,r)&&(n[r]=e[r]);return n},Br;(e=>{let t=class t{constructor(e,n,r,a){if(this.version=e,this.errorCorrectionLevel=n,this.modules=[],this.isFunction=[],et.MAX_VERSION)throw RangeError(`Version value out of range`);if(a<-1||a>7)throw RangeError(`Mask value out of range`);this.size=e*4+17;let o=[];for(let e=0;e7)throw RangeError(`Invalid value`);let u,d;for(u=a;;u++){let n=t.getNumDataCodewords(u,r)*8,i=o.getTotalBits(e,u);if(i<=n){d=i;break}if(u>=s)throw RangeError(`Data too long`)}for(let e of[t.Ecc.MEDIUM,t.Ecc.QUARTILE,t.Ecc.HIGH])l&&d<=t.getNumDataCodewords(u,e)*8&&(r=e);let f=[];for(let t of e){n(t.mode.modeBits,4,f),n(t.numChars,t.mode.numCharCountBits(u),f);for(let e of t.getData())f.push(e)}i(f.length==d);let p=t.getNumDataCodewords(u,r)*8;i(f.length<=p),n(0,Math.min(4,p-f.length),f),n(0,(8-f.length%8)%8,f),i(f.length%8==0);for(let e=236;f.lengthm[t>>>3]|=e<<7-(t&7)),new t(u,r,m,c)}getModule(e,t){return 0<=e&&e>>9)*1335;let a=(t<<10|n)^21522;i(a>>>15==0);for(let e=0;e<=5;e++)this.setFunctionModule(8,e,r(a,e));this.setFunctionModule(8,7,r(a,6)),this.setFunctionModule(8,8,r(a,7)),this.setFunctionModule(7,8,r(a,8));for(let e=9;e<15;e++)this.setFunctionModule(14-e,8,r(a,e));for(let e=0;e<8;e++)this.setFunctionModule(this.size-1-e,8,r(a,e));for(let e=8;e<15;e++)this.setFunctionModule(8,this.size-15+e,r(a,e));this.setFunctionModule(8,this.size-8,!0)}drawVersion(){if(this.version<7)return;let e=this.version;for(let t=0;t<12;t++)e=e<<1^(e>>>11)*7973;let t=this.version<<12|e;i(t>>>18==0);for(let e=0;e<18;e++){let n=r(t,e),i=this.size-11+e%3,a=Math.floor(e/3);this.setFunctionModule(i,a,n),this.setFunctionModule(a,i,n)}}drawFinderPattern(e,t){for(let n=-4;n<=4;n++)for(let r=-4;r<=4;r++){let i=Math.max(Math.abs(r),Math.abs(n)),a=e+r,o=t+n;0<=a&&a{(e!=l-o||n>=c)&&f.push(t[e])});return i(f.length==s),f}drawCodewords(e){if(e.length!=Math.floor(t.getNumRawDataModules(this.version)/8))throw RangeError(`Invalid argument`);let n=0;for(let t=this.size-1;t>=1;t-=2){t==6&&(t=5);for(let i=0;i>>3],7-(n&7)),n++)}}i(n==e.length*8)}applyMask(e){if(e<0||e>7)throw RangeError(`Mask value out of range`);for(let t=0;t5&&e++):(this.finderPenaltyAddHistory(i,a),r||(e+=this.finderPenaltyCountPatterns(a)*t.PENALTY_N3),r=this.modules[n][o],i=1);e+=this.finderPenaltyTerminateAndCount(r,i,a)*t.PENALTY_N3}for(let n=0;n5&&e++):(this.finderPenaltyAddHistory(i,a),r||(e+=this.finderPenaltyCountPatterns(a)*t.PENALTY_N3),r=this.modules[o][n],i=1);e+=this.finderPenaltyTerminateAndCount(r,i,a)*t.PENALTY_N3}for(let n=0;ne+ +!!t,n);let r=this.size*this.size,a=Math.ceil(Math.abs(n*20-r*10)/r)-1;return i(0<=a&&a<=9),e+=a*t.PENALTY_N4,i(0<=e&&e<=2568888),e}getAlignmentPatternPositions(){if(this.version==1)return[];{let e=Math.floor(this.version/7)+2,t=this.version==32?26:Math.ceil((this.version*4+4)/(e*2-2))*2,n=[6];for(let r=this.size-7;n.lengtht.MAX_VERSION)throw RangeError(`Version number out of range`);let n=(16*e+128)*e+64;if(e>=2){let t=Math.floor(e/7)+2;n-=(25*t-10)*t-55,e>=7&&(n-=36)}return i(208<=n&&n<=29648),n}static getNumDataCodewords(e,n){return Math.floor(t.getNumRawDataModules(e)/8)-t.ECC_CODEWORDS_PER_BLOCK[n.ordinal][e]*t.NUM_ERROR_CORRECTION_BLOCKS[n.ordinal][e]}static reedSolomonComputeDivisor(e){if(e<1||e>255)throw RangeError(`Degree out of range`);let n=[];for(let t=0;t0);for(let i of e){let e=i^r.shift();r.push(0),n.forEach((n,i)=>r[i]^=t.reedSolomonMultiply(n,e))}return r}static reedSolomonMultiply(e,t){if(e>>>8||t>>>8)throw RangeError(`Byte out of range`);let n=0;for(let r=7;r>=0;r--)n=n<<1^(n>>>7)*285,n^=(t>>>r&1)*e;return i(n>>>8==0),n}finderPenaltyCountPatterns(e){let t=e[1];i(t<=this.size*3);let n=t>0&&e[2]==t&&e[3]==t*3&&e[4]==t&&e[5]==t;return(n&&e[0]>=t*4&&e[6]>=t?1:0)+(n&&e[6]>=t*4&&e[0]>=t?1:0)}finderPenaltyTerminateAndCount(e,t,n){return e&&(this.finderPenaltyAddHistory(t,n),t=0),t+=this.size,this.finderPenaltyAddHistory(t,n),this.finderPenaltyCountPatterns(n)}finderPenaltyAddHistory(e,t){t[0]==0&&(e+=this.size),t.pop(),t.unshift(e)}};t.MIN_VERSION=1,t.MAX_VERSION=40,t.PENALTY_N1=3,t.PENALTY_N2=3,t.PENALTY_N3=40,t.PENALTY_N4=10,t.ECC_CODEWORDS_PER_BLOCK=[[-1,7,10,15,20,26,18,20,24,30,18,20,24,26,30,22,24,28,30,28,28,28,28,30,30,26,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,10,16,26,18,24,16,18,22,22,26,30,22,22,24,24,28,28,26,26,26,26,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28],[-1,13,22,18,26,18,24,18,22,20,24,28,26,24,20,30,24,28,28,26,30,28,30,30,30,30,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,17,28,22,16,22,28,26,26,24,28,24,28,22,24,24,30,28,28,26,28,30,24,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30]],t.NUM_ERROR_CORRECTION_BLOCKS=[[-1,1,1,1,1,1,2,2,2,2,4,4,4,4,4,6,6,6,6,7,8,8,9,9,10,12,12,12,13,14,15,16,17,18,19,19,20,21,22,24,25],[-1,1,1,1,2,2,4,4,4,5,5,5,8,9,9,10,10,11,13,14,16,17,17,18,20,21,23,25,26,28,29,31,33,35,37,38,40,43,45,47,49],[-1,1,1,2,2,4,4,6,6,8,8,8,10,12,16,12,17,16,18,21,20,23,23,25,27,29,34,34,35,38,40,43,45,48,51,53,56,59,62,65,68],[-1,1,1,2,4,4,4,5,6,8,8,11,11,16,16,18,16,19,21,25,25,25,34,30,32,35,37,40,42,45,48,51,54,57,60,63,66,70,74,77,81]],e.QrCode=t;function n(e,t,n){if(t<0||t>31||e>>>t)throw RangeError(`Value out of range`);for(let r=t-1;r>=0;r--)n.push(e>>>r&1)}function r(e,t){return(e>>>t&1)!=0}function i(e){if(!e)throw Error(`Assertion error`)}let a=class e{constructor(e,t,n){if(this.mode=e,this.numChars=t,this.bitData=n,t<0)throw RangeError(`Invalid argument`);this.bitData=n.slice()}static makeBytes(t){let r=[];for(let e of t)n(e,8,r);return new e(e.Mode.BYTE,t.length,r)}static makeNumeric(t){if(!e.isNumeric(t))throw RangeError(`String contains non-numeric characters`);let r=[];for(let e=0;e=1<{(e=>{let t=class{constructor(e,t){this.ordinal=e,this.formatBits=t}};t.LOW=new t(0,1),t.MEDIUM=new t(1,0),t.QUARTILE=new t(2,3),t.HIGH=new t(3,2),e.Ecc=t})(e.QrCode||={})})(Br||={}),(e=>{(e=>{let t=class{constructor(e,t){this.modeBits=e,this.numBitsCharCount=t}numCharCountBits(e){return this.numBitsCharCount[Math.floor((e+7)/17)]}};t.NUMERIC=new t(1,[10,12,14]),t.ALPHANUMERIC=new t(2,[9,11,13]),t.BYTE=new t(4,[8,16,16]),t.KANJI=new t(8,[8,10,12]),t.ECI=new t(7,[0,0,0]),e.Mode=t})(e.QrSegment||={})})(Br||={});var Vr=Br,Z={L:Vr.QrCode.Ecc.LOW,M:Vr.QrCode.Ecc.MEDIUM,Q:Vr.QrCode.Ecc.QUARTILE,H:Vr.QrCode.Ecc.HIGH},Hr=128,Ur=`L`,Wr=`#FFFFFF`,Gr=`#000000`,Kr=!1,qr=1,Jr=4,Yr=0,Xr=.1;function Zr(e,t=0){let n=[];return e.forEach(function(e,r){let i=null;e.forEach(function(a,o){if(!a&&i!==null){n.push(`M${i+t} ${r+t}h${o-i}v1H${i+t}z`),i=null;return}if(o===e.length-1){if(!a)return;i===null?n.push(`M${o+t},${r+t} h1v1H${o+t}z`):n.push(`M${i+t},${r+t} h${o+1-i}v1H${i+t}z`);return}a&&i===null&&(i=o)})}),n.join(``)}function Qr(e,t){return e.slice().map((e,n)=>n=t.y+t.h?e:e.map((e,n)=>n=t.x+t.w?e:!1))}function $r(e,t,n,r){if(r==null)return null;let i=e.length+n*2,a=Math.floor(t*Xr),o=i/t,s=(r.width||a)*o,c=(r.height||a)*o,l=r.x==null?e.length/2-s/2:r.x*o,u=r.y==null?e.length/2-c/2:r.y*o,d=r.opacity==null?1:r.opacity,f=null;if(r.excavate){let e=Math.floor(l),t=Math.floor(u);f={x:e,y:t,w:Math.ceil(s+l-e),h:Math.ceil(c+u-t)}}let p=r.crossOrigin;return{x:l,y:u,h:c,w:s,excavation:f,opacity:d,crossOrigin:p}}function ei(e,t){return t==null?e?Jr:Yr:Math.max(Math.floor(t),0)}function ti({value:e,level:t,minVersion:n,includeMargin:r,marginSize:i,imageSettings:a,size:o,boostLevel:s}){let c=X.useMemo(()=>{let r=(Array.isArray(e)?e:[e]).reduce((e,t)=>(e.push(...Vr.QrSegment.makeSegments(t)),e),[]);return Vr.QrCode.encodeSegments(r,Z[t],n,void 0,void 0,s)},[e,t,n,s]),{cells:l,margin:u,numCells:d,calculatedImageSettings:f}=X.useMemo(()=>{let e=c.getModules(),t=ei(r,i);return{cells:e,margin:t,numCells:e.length+t*2,calculatedImageSettings:$r(e,o,t,a)}},[c,o,a,r,i]);return{qrcode:c,margin:u,cells:l,numCells:d,calculatedImageSettings:f}}var ni=function(){try{new Path2D().addPath(new Path2D)}catch{return!1}return!0}(),ri=X.forwardRef(function(e,t){let n=e,{value:r,size:i=Hr,level:a=Ur,bgColor:o=Wr,fgColor:s=Gr,includeMargin:c=Kr,minVersion:l=qr,boostLevel:u,marginSize:d,imageSettings:f}=n,p=zr(n,[`value`,`size`,`level`,`bgColor`,`fgColor`,`includeMargin`,`minVersion`,`boostLevel`,`marginSize`,`imageSettings`]),{style:m}=p,h=zr(p,[`style`]),g=f?.src,_=X.useRef(null),v=X.useRef(null),y=X.useCallback(e=>{_.current=e,typeof t==`function`?t(e):t&&(t.current=e)},[t]),[b,x]=X.useState(!1),{margin:S,cells:C,numCells:w,calculatedImageSettings:T}=ti({value:r,level:a,minVersion:l,boostLevel:u,includeMargin:c,marginSize:d,imageSettings:f,size:i});X.useEffect(()=>{if(_.current!=null){let e=_.current,t=e.getContext(`2d`);if(!t)return;let n=C,r=v.current,a=T!=null&&r!==null&&r.complete&&r.naturalHeight!==0&&r.naturalWidth!==0;a&&T.excavation!=null&&(n=Qr(C,T.excavation));let c=window.devicePixelRatio||1;e.height=e.width=i*c;let l=i/w*c;t.scale(l,l),t.fillStyle=o,t.fillRect(0,0,w,w),t.fillStyle=s,ni?t.fill(new Path2D(Zr(n,S))):C.forEach(function(e,n){e.forEach(function(e,r){e&&t.fillRect(r+S,n+S,1,1)})}),T&&(t.globalAlpha=T.opacity),a&&t.drawImage(r,T.x+S,T.y+S,T.w,T.h)}}),X.useEffect(()=>{x(!1)},[g]);let E=Rr({height:i,width:i},m),D=null;return g!=null&&(D=X.createElement(`img`,{src:g,key:g,style:{display:`none`},onLoad:()=>{x(!0)},ref:v,crossOrigin:T?.crossOrigin})),X.createElement(X.Fragment,null,X.createElement(`canvas`,Rr({style:E,height:i,width:i,ref:y,role:`img`},h)),D)});ri.displayName=`QRCodeCanvas`;var ii=X.forwardRef(function(e,t){let n=e,{value:r,size:i=Hr,level:a=Ur,bgColor:o=Wr,fgColor:s=Gr,includeMargin:c=Kr,minVersion:l=qr,boostLevel:u,title:d,marginSize:f,imageSettings:p}=n,m=zr(n,[`value`,`size`,`level`,`bgColor`,`fgColor`,`includeMargin`,`minVersion`,`boostLevel`,`title`,`marginSize`,`imageSettings`]),{margin:h,cells:g,numCells:_,calculatedImageSettings:v}=ti({value:r,level:a,minVersion:l,boostLevel:u,includeMargin:c,marginSize:f,imageSettings:p,size:i}),y=g,b=null;p!=null&&v!=null&&(v.excavation!=null&&(y=Qr(g,v.excavation)),b=X.createElement(`image`,{href:p.src,height:v.h,width:v.w,x:v.x+h,y:v.y+h,preserveAspectRatio:`none`,opacity:v.opacity,crossOrigin:v.crossOrigin}));let x=Zr(y,h);return X.createElement(`svg`,Rr({height:i,width:i,viewBox:`0 0 ${_} ${_}`,ref:t,role:`img`},m),!!d&&X.createElement(`title`,null,d),X.createElement(`path`,{fill:o,d:`M0,0 h${_}v${_}H0z`,shapeRendering:`crispEdges`}),X.createElement(`path`,{fill:s,d:x,shapeRendering:`crispEdges`}),b)});ii.displayName=`QRCodeSVG`;function ai(e,t){return`bambuddy://config?v=1&url=${encodeURIComponent(e)}&key=${encodeURIComponent(t)}`}function oi({apiKey:e,baseUrl:t,onClose:n}){let{t:r}=l(),i=ai(t??window.location.origin,e);return(0,X.useEffect)(()=>{let e=e=>{e.key===`Escape`&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n]),(0,Y.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:n,children:(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-sm`,onClick:e=>e.stopPropagation(),children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:r(`settings.apiKeyQrTitle`)}),(0,Y.jsx)(`button`,{onClick:n,className:`text-bambu-gray hover:text-white transition-colors`,"aria-label":r(`common.close`),children:(0,Y.jsx)(Re,{className:`w-5 h-5`})})]}),(0,Y.jsxs)(`div`,{className:`p-6 flex flex-col items-center`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4 text-center`,children:r(`settings.apiKeyQrCaption`)}),(0,Y.jsx)(`div`,{className:`bg-white p-4 rounded-lg mb-4`,children:(0,Y.jsx)(ii,{value:i,size:256})}),(0,Y.jsxs)(`div`,{className:`flex items-start gap-2 text-xs text-amber-700 dark:text-amber-400 mb-4`,children:[(0,Y.jsx)(Ie,{className:`w-4 h-4 flex-shrink-0 mt-0.5`}),(0,Y.jsx)(`span`,{children:r(`settings.apiKeyQrWarning`)})]}),(0,Y.jsx)(K,{onClick:n,className:`w-full`,children:r(`common.close`)})]})]})})}var si=300,ci=2;function li({onSuccess:e}){let{t}=l(),n=u(),[i,a]=(0,X.useState)(``),[o,s]=(0,X.useState)(``),[c,p]=(0,X.useState)(null),[m,h]=(0,X.useState)(null);(0,X.useEffect)(()=>{let e=i.trim();if(e.lengths(e),si);return()=>clearTimeout(t)},[i]),(0,X.useEffect)(()=>{p(null),h(null)},[o]);let g=d({queryKey:[`ldap-search`,o],queryFn:()=>r.searchLDAPDirectory(o),enabled:o.length>=ci,staleTime:3e4}),_=f({mutationFn:e=>r.provisionLDAPUser(e),onSuccess:t=>{n.invalidateQueries({queryKey:[`users`]}),e(t)},onError:e=>{h(e.message||t(`users.modal.ldapErrorProvision`))}}),v=(0,X.useMemo)(()=>g.data?.find(e=>e.dn===c)??null,[g.data,c]),y=i.trim().length>0&&i.trim().length=ci,x=!!g.data&&g.data.length>0,S=!b&&!!g.data&&g.data.length===0&&o.length>=ci;return(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:t(`users.modal.ldapSearchLabel`)}),(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsx)(Ae,{className:`w-4 h-4 text-bambu-gray absolute left-3 top-1/2 -translate-y-1/2`}),(0,Y.jsx)(`input`,{type:`text`,value:i,onChange:e=>a(e.target.value),className:`w-full pl-9 pr-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:t(`users.modal.ldapSearchPlaceholder`),autoComplete:`off`})]}),y&&(0,Y.jsx)(`p`,{className:`mt-1 text-xs text-bambu-gray`,children:t(`users.modal.ldapMinChars`)})]}),(0,Y.jsxs)(`div`,{className:`min-h-[8rem] max-h-64 overflow-y-auto bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg`,children:[b&&(0,Y.jsxs)(`div`,{className:`flex items-center justify-center py-8 text-bambu-gray`,children:[(0,Y.jsx)(R,{className:`w-4 h-4 animate-spin mr-2`}),(0,Y.jsx)(`span`,{children:t(`users.modal.ldapSearching`)})]}),S&&(0,Y.jsx)(`div`,{className:`flex items-center justify-center py-8 text-bambu-gray text-sm`,children:t(`users.modal.ldapNoResults`)}),g.isError&&(0,Y.jsx)(`div`,{className:`px-3 py-4 text-sm text-red-700 dark:text-red-400`,children:g.error instanceof Error?g.error.message:t(`users.modal.ldapSearchError`)}),!b&&x&&(0,Y.jsx)(`ul`,{className:`divide-y divide-bambu-dark-tertiary`,children:g.data.map(e=>(0,Y.jsx)(ui,{result:e,selected:c===e.dn,onSelect:()=>p(e.dn)},e.dn))}),!b&&!g.data&&!g.isError&&(0,Y.jsx)(`div`,{className:`flex items-center justify-center py-8 text-bambu-gray text-sm`,children:t(`users.modal.ldapTypeToSearch`)})]}),v&&(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary/50 border border-bambu-green/20 rounded-lg p-3 space-y-1`,children:[(0,Y.jsxs)(`p`,{className:`text-sm text-white`,children:[(0,Y.jsxs)(`span`,{className:`text-bambu-gray`,children:[t(`users.modal.ldapSelectedLabel`),`: `]}),(0,Y.jsx)(`span`,{className:`font-medium`,children:v.username}),v.display_name&&(0,Y.jsxs)(`span`,{className:`text-bambu-gray`,children:[` — `,v.display_name]})]}),v.email&&(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:v.email}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray break-all`,children:v.dn})]}),m&&(0,Y.jsx)(`div`,{className:`bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30 rounded-lg p-3`,children:(0,Y.jsx)(`p`,{className:`text-sm text-red-700 dark:text-red-400`,children:m})}),(0,Y.jsx)(`div`,{className:`flex justify-end`,children:(0,Y.jsx)(K,{onClick:()=>{!v||v.already_provisioned||(h(null),_.mutate(v.username))},disabled:!v||v.already_provisioned||_.isPending,children:_.isPending?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(R,{className:`w-4 h-4 animate-spin`}),t(`users.modal.ldapProvisioning`)]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(wt,{className:`w-4 h-4`}),t(`users.modal.ldapProvision`)]})})})]})}function ui({result:e,selected:t,onSelect:n}){let{t:r}=l(),i=e.already_provisioned;return(0,Y.jsx)(`li`,{children:(0,Y.jsxs)(`button`,{type:`button`,onClick:n,disabled:i,className:`w-full text-left px-3 py-2 flex items-center gap-3 transition-colors ${i?`opacity-50 cursor-not-allowed`:t?`bg-bambu-green/10`:`hover:bg-bambu-dark-tertiary`}`,children:[(0,Y.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Y.jsxs)(`p`,{className:`text-sm text-white truncate`,children:[(0,Y.jsx)(`span`,{className:`font-medium`,children:e.username}),e.display_name&&(0,Y.jsxs)(`span`,{className:`text-bambu-gray`,children:[` — `,e.display_name]})]}),e.email&&(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray truncate`,children:e.email})]}),i&&(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 text-xs text-bambu-gray whitespace-nowrap`,children:[(0,Y.jsx)(q,{className:`w-3.5 h-3.5`}),r(`users.modal.ldapAlreadyProvisioned`)]})]})})}function di({formData:e,setFormData:t,groups:n,onClose:r,onCreate:i,isCreating:a,isCreateButtonDisabled:o,ldapEnabled:s=!1,onLdapProvisioned:c}){let{t:u}=l(),[d,f]=(0,X.useState)(`local`);(0,X.useEffect)(()=>{let e=e=>{e.key===`Escape`&&r()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[r]);let p=n=>{t({...e,group_ids:e.group_ids.includes(n)?e.group_ids.filter(e=>e!==n):[...e.group_ids,n]})};return(0,Y.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:r,children:(0,Y.jsxs)(G,{className:`w-full max-w-md`,onClick:e=>e.stopPropagation(),children:[(0,Y.jsx)(U,{children:(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(Ze,{className:`w-5 h-5 text-bambu-green`}),(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:u(`users.modal.createUser`)})]}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray ml-7`,children:u(`users.modal.advancedAuthSubtitle`)||`with Advanced Authentication`})]}),(0,Y.jsx)(K,{variant:`ghost`,size:`sm`,onClick:r,children:(0,Y.jsx)(Re,{className:`w-5 h-5`})})]})}),(0,Y.jsxs)(W,{children:[s&&(0,Y.jsxs)(`div`,{className:`mb-4 flex items-center gap-1 p-1 bg-bambu-dark-secondary rounded-lg`,role:`tablist`,"aria-label":u(`users.modal.tabsAriaLabel`),children:[(0,Y.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":d===`local`,onClick:()=>f(`local`),className:`flex-1 px-3 py-2 text-sm rounded-md transition-colors ${d===`local`?`bg-bambu-green/15 text-bambu-green`:`text-bambu-gray hover:text-white`}`,children:u(`users.modal.localTab`)}),(0,Y.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":d===`ldap`,onClick:()=>f(`ldap`),className:`flex-1 px-3 py-2 text-sm rounded-md transition-colors ${d===`ldap`?`bg-bambu-green/15 text-bambu-green`:`text-bambu-gray hover:text-white`}`,children:u(`users.modal.ldapTab`)})]}),d===`ldap`&&s?(0,Y.jsx)(li,{onSuccess:e=>{c?.(e)}}):(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:[u(`users.form.username`),` `,(0,Y.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:`*`})]}),(0,Y.jsx)(`input`,{type:`text`,value:e.username,onChange:n=>t({...e,username:n.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:u(`users.form.usernamePlaceholder`),autoComplete:`username`,required:!0})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:[u(`users.form.email`)||`Email`,` `,(0,Y.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:`*`})]}),(0,Y.jsx)(`input`,{type:`email`,value:e.email,onChange:n=>t({...e,email:n.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:u(`users.form.emailPlaceholder`)||`user@example.com`,required:!0})]}),(0,Y.jsx)(`div`,{className:`bg-bambu-dark-secondary/50 border border-bambu-green/20 rounded-lg p-3`,children:(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:u(`users.form.autoGeneratedPassword`)||`A secure password will be automatically generated and emailed to the user.`})}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:u(`users.form.groups`)}),(0,Y.jsxs)(`div`,{className:`space-y-2 max-h-40 overflow-y-auto p-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg`,children:[n.map(t=>(0,Y.jsxs)(`label`,{className:`flex items-center gap-3 px-2 py-1.5 rounded hover:bg-bambu-dark-tertiary cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:e.group_ids.includes(t.id),onChange:()=>p(t.id),className:`w-4 h-4 rounded border-bambu-gray text-bambu-green focus:ring-bambu-green focus:ring-offset-0 bg-bambu-dark`}),(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:t.name}),t.is_system&&(0,Y.jsxs)(`span`,{className:`text-xs text-yellow-700 dark:text-yellow-400`,children:[`(`,u(`users.system`),`)`]})]},t.id)),n.length===0&&(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:u(`users.noGroupsAvailable`)})]})]})]}),(0,Y.jsxs)(`div`,{className:`mt-6 flex justify-end gap-3`,children:[(0,Y.jsx)(K,{variant:`secondary`,onClick:r,children:u(`users.modal.cancel`)}),d===`local`&&(0,Y.jsx)(K,{onClick:i,disabled:o,children:a?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(R,{className:`w-4 h-4 animate-spin`}),u(`users.modal.creating`)]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(wt,{className:`w-4 h-4`}),u(`users.modal.createUser`)]})})]})]})]})})}function fi(){let{t:e}=l(),t=u(),{showToast:n}=ee(),[i,a]=(0,X.useState)(!1),[o,c]=(0,X.useState)(``),[p,m]=(0,X.useState)(`auto`),[h,g]=(0,X.useState)(!1),[_,v]=(0,X.useState)(!0),[y,b]=(0,X.useState)(!0),[x,S]=(0,X.useState)(`all`),[C,w]=(0,X.useState)(!1),[D,O]=(0,X.useState)(!1),[k,j]=(0,X.useState)(!1),[M,N]=(0,X.useState)(!1),[P,te]=(0,X.useState)(null),{data:F,isLoading:ne}=d({queryKey:[`spoolman-settings`],queryFn:r.getSpoolmanSettings}),{data:I,isLoading:re,refetch:ie}=d({queryKey:[`spoolman-status`],queryFn:r.getSpoolmanStatus,refetchInterval:3e4}),{data:L}=d({queryKey:[`printers`],queryFn:r.getPrinters});(0,X.useEffect)(()=>{F&&(a(F.spoolman_enabled===`true`),c(F.spoolman_url||``),m(F.spoolman_sync_mode||`auto`),g(F.spoolman_disable_weight_sync===`true`),v(F.spoolman_report_partial_usage!==`false`),b(F.auto_add_unknown_rfid!==`false`),w(!0))},[F]),(0,X.useEffect)(()=>{if(!(!C||!F)&&(F.spoolman_enabled===`true`!==i||(F.spoolman_url||``)!==o||(F.spoolman_sync_mode||`auto`)!==p||F.spoolman_disable_weight_sync===`true`!==h||F.spoolman_report_partial_usage!==`false`!==_||F.auto_add_unknown_rfid!==`false`!==y)){let e=setTimeout(()=>{z.mutate()},500);return()=>clearTimeout(e)}},[i,o,p,h,_,y,C]);let z=f({mutationFn:()=>r.updateSpoolmanSettings({spoolman_enabled:i?`true`:`false`,spoolman_url:o,spoolman_sync_mode:p,spoolman_disable_weight_sync:h?`true`:`false`,spoolman_report_partial_usage:_?`true`:`false`,auto_add_unknown_rfid:y?`true`:`false`}),onSuccess:()=>{t.invalidateQueries({queryKey:[`spoolman-settings`]}),t.invalidateQueries({queryKey:[`spoolman-status`]}),t.invalidateQueries({queryKey:[`spool-assignments`]}),t.invalidateQueries({queryKey:[`settings`]}),t.invalidateQueries({queryKey:[`spoolman-inventory-filaments`]}),n(e(`settings.toast.settingsSaved`))},onError:()=>{n(e(`settings.toast.saveFailed`),`error`)}}),oe=f({mutationFn:r.connectSpoolman,onSuccess:()=>{ie()},onError:()=>{n(e(`settings.toast.saveFailed`),`error`)}}),se=f({mutationFn:r.syncAllPrintersAms,onSuccess:t=>{n(e(`settings.spoolmanAmsSyncSuccess`,{synced:t.synced_count,skipped:0}),`success`)},onError:()=>{n(e(`settings.toast.saveFailed`),`error`)}}),B=f({mutationFn:e=>r.syncPrinterAms(e),onSuccess:t=>{n(e(`settings.spoolmanAmsSyncSuccess`,{synced:t.synced_count,skipped:0}),`success`)},onError:()=>{n(e(`settings.toast.saveFailed`),`error`)}}),ce=()=>{x===`all`?se.mutate():B.mutate(x)},le=f({mutationFn:r.syncWeightsFromAms,onSuccess:r=>{t.invalidateQueries({queryKey:[`spools`]}),t.invalidateQueries({queryKey:[`inventory-spools`]}),n(e(`settings.amsSyncSuccess`,{synced:r.synced,skipped:r.skipped}),`success`),j(!1)},onError:()=>{n(e(`settings.amsSyncError`),`error`),j(!1)}}),ue=f({mutationFn:r.syncSpoolmanAmsWeights,onSuccess:r=>{t.invalidateQueries({queryKey:[`spoolman-inventory-spools`]}),n(e(`settings.spoolmanAmsSyncSuccess`,{synced:r.synced,skipped:r.skipped}),`success`),N(!1)},onError:t=>{t instanceof s&&t.status===503?n(e(`settings.spoolmanAmsSyncErrorUnreachable`),`error`):t instanceof s&&t.status===400?n(e(`settings.spoolmanAmsSyncErrorNotConfigured`),`error`):n(e(`settings.spoolmanAmsSyncError`),`error`),N(!1)}}),de=f({mutationFn:e=>r.migrateSpoolmanTags(e),onSuccess:r=>{te(r),r.dry_run||(t.invalidateQueries({queryKey:[`spoolman-inventory-spools`]}),n(e(`settings.nativeTagsMoved`,{count:r.moved.length}),`success`))},onError:()=>{n(e(`settings.nativeTagsError`),`error`)}}),fe=se.isPending||B.isPending,V=x===`all`?se.data:B.data,pe=x===`all`?se.isSuccess:B.isSuccess;return ne?(0,Y.jsxs)(G,{id:`card-spoolman`,children:[(0,Y.jsx)(U,{children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(gt,{className:`w-5 h-5 text-bambu-green`}),(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`settings.filamentTracking`)})]})}),(0,Y.jsx)(W,{children:(0,Y.jsx)(`div`,{className:`flex justify-center py-8`,children:(0,Y.jsx)(R,{className:`w-6 h-6 text-bambu-green animate-spin`})})})]}):(0,Y.jsxs)(G,{id:`card-spoolman`,children:[(0,Y.jsx)(U,{children:(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(gt,{className:`w-5 h-5 text-bambu-green`}),(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`settings.filamentTracking`)})]}),z.isPending&&(0,Y.jsx)(R,{className:`w-4 h-4 text-bambu-green animate-spin`})]})}),(0,Y.jsxs)(W,{className:`space-y-4`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`settings.filamentTrackingDesc`)}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>a(!1),className:`p-3 rounded-lg border-2 text-left transition-colors ${i?`border-bambu-dark-tertiary bg-bambu-dark hover:border-bambu-gray/50`:`border-bambu-green bg-bambu-green/10`}`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 mb-1.5`,children:[(0,Y.jsx)(Ee,{className:`w-4 h-4 ${i?`text-bambu-gray`:`text-bambu-green`}`}),(0,Y.jsx)(`span`,{className:`text-sm font-medium ${i?`text-bambu-gray`:`text-white`}`,children:e(`settings.trackingModeBuiltIn`)})]}),(0,Y.jsx)(`p`,{className:`text-xs ${i?`text-bambu-gray/60`:`text-bambu-gray`}`,children:e(`settings.trackingModeBuiltInDesc`)}),!i&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-1 mt-2`,children:[(0,Y.jsx)(T,{className:`w-3 h-3 text-bambu-green`}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-green`,children:e(`common.enabled`)})]})]}),(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>a(!0),className:`p-3 rounded-lg border-2 text-left transition-colors ${i?`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary bg-bambu-dark hover:border-bambu-gray/50`}`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 mb-1.5`,children:[(0,Y.jsx)(Je,{className:`w-4 h-4 ${i?`text-bambu-green`:`text-bambu-gray`}`}),(0,Y.jsx)(`span`,{className:`text-sm font-medium ${i?`text-white`:`text-bambu-gray`}`,children:`Spoolman`})]}),(0,Y.jsx)(`p`,{className:`text-xs ${i?`text-bambu-gray`:`text-bambu-gray/60`}`,children:e(`settings.trackingModeSpoolmanDesc`)}),i&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-1 mt-2`,children:[(0,Y.jsx)(T,{className:`w-3 h-3 text-bambu-green`}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-green`,children:e(`common.enabled`)})]})]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between pt-2 border-t border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{className:`pr-4`,children:[(0,Y.jsx)(`p`,{className:`text-white`,children:e(`settings.autoAddUnknownRfid`)}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`settings.autoAddUnknownRfidDesc`)})]}),(0,Y.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:y,onChange:e=>b(e.target.checked),className:`sr-only peer`}),(0,Y.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),!i&&(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsx)(`div`,{className:`p-3 bg-bambu-green/5 border border-bambu-green/20 rounded-lg`,children:(0,Y.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Y.jsx)(A,{className:`w-4 h-4 text-bambu-green flex-shrink-0 mt-0.5`}),(0,Y.jsx)(`div`,{className:`text-xs text-bambu-gray`,children:(0,Y.jsxs)(`ul`,{className:`list-disc list-inside space-y-0.5`,children:[(0,Y.jsx)(`li`,{children:e(`settings.builtInFeatureRfid`)}),(0,Y.jsx)(`li`,{children:e(`settings.builtInFeatureUsage`)}),(0,Y.jsx)(`li`,{children:e(`settings.builtInFeatureCatalog`)}),(0,Y.jsx)(`li`,{children:e(`settings.builtInFeatureThirdParty`)})]})})]})}),(0,Y.jsxs)(K,{variant:`secondary`,size:`sm`,onClick:()=>j(!0),disabled:le.isPending,children:[le.isPending?(0,Y.jsx)(R,{className:`w-4 h-4 mr-2 animate-spin`}):(0,Y.jsx)(at,{className:`w-4 h-4 mr-2`}),e(`settings.amsSyncButton`)]})]}),i&&(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[(0,Y.jsx)(`div`,{className:`p-3 bg-blue-50 dark:bg-blue-500/10 border border-blue-300 dark:border-blue-500/30 rounded-lg`,children:(0,Y.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Y.jsx)(A,{className:`w-4 h-4 text-blue-600 dark:text-blue-400 flex-shrink-0 mt-0.5`}),(0,Y.jsxs)(`div`,{className:`text-xs text-blue-700 dark:text-blue-300`,children:[(0,Y.jsx)(`p`,{className:`font-medium mb-1`,children:e(`settings.howSyncWorks`)}),(0,Y.jsxs)(`ul`,{className:`list-disc list-inside space-y-0.5 text-blue-700/90 dark:text-blue-300/80`,children:[(0,Y.jsx)(`li`,{children:e(`settings.syncInfoRfidOnly`)}),(0,Y.jsx)(`li`,{children:e(`settings.syncInfoAutoCreate`)}),(0,Y.jsx)(`li`,{children:e(`settings.syncInfoThirdPartySkipped`)})]}),(0,Y.jsx)(`p`,{className:`font-medium mt-2 mb-1`,children:e(`settings.linkingExistingSpools`)}),(0,Y.jsx)(`p`,{className:`text-blue-700/90 dark:text-blue-300/80`,children:e(`settings.linkingExistingSpoolsDesc`)})]})]})}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:e(`settings.spoolmanUrl`)}),(0,Y.jsx)(`input`,{type:`text`,placeholder:`http://192.168.1.100:7912`,value:o,onChange:e=>c(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray/50 focus:border-bambu-green focus:outline-none`}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`settings.spoolmanUrlHint`)})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:e(`settings.syncMode`)}),(0,Y.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 focus:border-bambu-green focus:outline-none`,children:[(0,Y.jsx)(`option`,{value:`auto`,children:e(`settings.syncModeAuto`)}),(0,Y.jsx)(`option`,{value:`manual`,children:e(`settings.syncModeManual`)})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(p===`auto`?`settings.syncModeAutoDesc`:`settings.syncModeManualDesc`)})]}),p===`auto`&&(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-white`,children:e(`spoolman.disableWeightSync`)}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`spoolman.disableWeightSyncDesc`)})]}),(0,Y.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:h,onChange:e=>g(e.target.checked),className:`sr-only peer`}),(0,Y.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),h&&(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-white`,children:e(`spoolman.reportPartialUsage`)}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`spoolman.reportPartialUsageDesc`)})]}),(0,Y.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:_,onChange:e=>v(e.target.checked),className:`sr-only peer`}),(0,Y.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,Y.jsxs)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[e(`settings.status`),`:`]}),re?(0,Y.jsx)(R,{className:`w-4 h-4 text-bambu-gray animate-spin`}):I?.connected?(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 text-sm text-green-500`,children:[(0,Y.jsx)(T,{className:`w-4 h-4`}),e(`settings.spoolmanConnected`)]}):(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 text-sm text-red-500`,children:[(0,Y.jsx)(Re,{className:`w-4 h-4`}),e(`settings.spoolmanDisconnected`)]})]}),(0,Y.jsx)(`div`,{className:`flex gap-2`,children:!I?.connected&&(0,Y.jsxs)(K,{size:`sm`,onClick:()=>oe.mutate(),disabled:oe.isPending||!o,children:[oe.isPending?(0,Y.jsx)(R,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(ae,{className:`w-4 h-4`}),e(`settings.connect`)]})})]}),oe.isError&&(0,Y.jsx)(`div`,{className:`mb-3 p-2 bg-red-100 dark:bg-red-500/20 border border-red-300 dark:border-red-500/50 rounded text-sm text-red-700 dark:text-red-400`,children:oe.error.message}),I?.connected&&(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:e(`settings.syncAmsData`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:e(`settings.syncAmsDataDesc`)})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsxs)(`div`,{className:`relative flex-1`,children:[(0,Y.jsxs)(`select`,{value:x,onChange:e=>S(e.target.value===`all`?`all`:Number(e.target.value)),className:`w-full px-3 py-2 pr-8 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:[(0,Y.jsx)(`option`,{value:`all`,children:e(`settings.allPrinters`)}),L?.map(e=>(0,Y.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,Y.jsx)(E,{className:`absolute right-2 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]}),(0,Y.jsxs)(K,{variant:`secondary`,size:`sm`,onClick:ce,disabled:fe,children:[fe?(0,Y.jsx)(R,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(at,{className:`w-4 h-4`}),e(`spoolman.sync`)]})]})]}),I?.connected&&(0,Y.jsx)(`div`,{className:`mt-4 pt-4 border-t border-bambu-dark-tertiary`,children:(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:e(`settings.spoolmanAmsSyncButton`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:e(`settings.spoolmanAmsSyncMessage`)})]}),(0,Y.jsxs)(K,{variant:`secondary`,size:`sm`,onClick:()=>N(!0),disabled:ue.isPending,children:[ue.isPending?(0,Y.jsx)(R,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(at,{className:`w-4 h-4`}),ue.isPending?e(`settings.spoolmanAmsSyncing`):e(`settings.spoolmanAmsSyncButton`)]})]})}),I?.connected&&I.native_tags&&(0,Y.jsxs)(`div`,{className:`mt-4 pt-4 border-t border-bambu-dark-tertiary space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`pr-4`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-white`,children:e(`settings.nativeTagsTitle`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:e(`settings.nativeTagsDesc`)})]}),(0,Y.jsxs)(K,{variant:`secondary`,size:`sm`,onClick:()=>de.mutate(!0),disabled:de.isPending,className:`flex-shrink-0 whitespace-nowrap`,children:[de.isPending&&de.variables?(0,Y.jsx)(R,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(Tn,{className:`w-4 h-4`}),e(`settings.nativeTagsCheck`)]})]}),P&&(0,Y.jsxs)(`div`,{className:`p-2 bg-bambu-dark border border-bambu-dark-tertiary rounded text-sm space-y-2`,children:[(0,Y.jsxs)(`dl`,{className:`grid grid-cols-[1fr_auto] gap-x-4 gap-y-0.5 text-xs`,children:[(0,Y.jsx)(`dt`,{className:`text-bambu-gray`,children:e(`settings.nativeTagsToMove`)}),(0,Y.jsx)(`dd`,{className:`text-white text-right`,children:P.dry_run?P.moved.length:0}),(0,Y.jsx)(`dt`,{className:`text-bambu-gray`,children:e(`settings.nativeTagsAlready`)}),(0,Y.jsx)(`dd`,{className:`text-white text-right`,children:P.already+(P.dry_run?0:P.moved.length)}),(0,Y.jsx)(`dt`,{className:`text-bambu-gray`,children:e(`settings.nativeTagsSlotIds`)}),(0,Y.jsx)(`dd`,{className:`text-white text-right`,children:P.slot_ids}),(0,Y.jsx)(`dt`,{className:`text-bambu-gray`,children:e(`settings.nativeTagsConflicts`)}),(0,Y.jsx)(`dd`,{className:`text-white text-right`,children:P.conflicts.length})]}),P.conflicts.length>0&&(0,Y.jsx)(`ul`,{className:`p-2 bg-amber-50 dark:bg-amber-500/10 border border-amber-300 dark:border-amber-500/30 rounded text-xs text-amber-700 dark:text-amber-400 space-y-0.5`,children:P.conflicts.map(t=>(0,Y.jsxs)(`li`,{className:`flex items-start gap-1.5`,children:[(0,Y.jsx)(Ie,{className:`w-3.5 h-3.5 flex-shrink-0 mt-px`}),(0,Y.jsx)(`span`,{children:t.holder>0?e(`settings.nativeTagsConflictSpool`,{spool:t.spool_id,tag:t.tag,holder:t.holder}):e(`settings.nativeTagsConflictElsewhere`,{spool:t.spool_id,tag:t.tag})})]},`${t.spool_id}-${t.tag}`))}),P.dry_run&&P.moved.length>0?(0,Y.jsxs)(K,{size:`sm`,onClick:()=>de.mutate(!1),disabled:de.isPending,children:[de.isPending&&!de.variables?(0,Y.jsx)(R,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(Tn,{className:`w-4 h-4`}),e(`settings.nativeTagsMove`)]}):P.conflicts.length===0&&(0,Y.jsxs)(`p`,{className:`flex items-center gap-1 text-xs text-green-600 dark:text-green-400`,children:[(0,Y.jsx)(T,{className:`w-3.5 h-3.5`}),e(`settings.nativeTagsNothing`)]})]})]}),pe&&V&&(0,Y.jsxs)(`div`,{className:`mt-3 space-y-2`,children:[(0,Y.jsx)(`div`,{className:`p-2 rounded text-sm ${V.success?`bg-green-100 dark:bg-green-500/20 border border-green-300 dark:border-green-500/50 text-green-700 dark:text-green-400`:`bg-yellow-100 dark:bg-yellow-500/20 border border-yellow-300 dark:border-yellow-500/50 text-yellow-700 dark:text-yellow-400`}`,children:V.success?`Synced ${V.synced_count} spool${V.synced_count===1?``:`s`} successfully`:`Synced ${V.synced_count} spool${V.synced_count===1?``:`s`} with ${V.errors.length} error${V.errors.length===1?``:`s`}`}),V.skipped_count>0&&(0,Y.jsxs)(`div`,{className:`p-2 bg-amber-50 dark:bg-amber-500/10 border border-amber-300 dark:border-amber-500/30 rounded text-sm`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between text-amber-700 dark:text-amber-400 mb-1`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(Ie,{className:`w-3.5 h-3.5`}),(0,Y.jsxs)(`span`,{className:`font-medium`,children:[V.skipped_count,` spool`,V.skipped_count===1?``:`s`,` skipped`]})]}),V.skipped_count>5&&(0,Y.jsx)(`button`,{onClick:()=>O(!D),className:`text-xs text-amber-700 dark:text-amber-400 hover:text-amber-800 dark:hover:text-amber-300 underline`,children:D?`Show less`:`Show all`})]}),(0,Y.jsxs)(`ul`,{className:`text-xs text-amber-700/90 dark:text-amber-300/80 space-y-0.5`,children:[(D?V.skipped:V.skipped.slice(0,5)).map((e,t)=>(0,Y.jsxs)(`li`,{className:`flex items-center gap-2`,children:[e.color&&(0,Y.jsx)(`span`,{className:`w-3 h-3 rounded-full border border-black/20`,style:{backgroundColor:`#${e.color}`}}),(0,Y.jsx)(`span`,{children:e.location}),(0,Y.jsxs)(`span`,{className:`text-amber-700/70 dark:text-amber-300/60`,children:[`- `,e.reason]})]},t)),!D&&V.skipped_count>5&&(0,Y.jsxs)(`li`,{className:`text-amber-700/70 dark:text-amber-300/60 italic`,children:[`...and `,V.skipped_count-5,` more`]})]})]}),V.errors.length>0&&(0,Y.jsxs)(`div`,{className:`p-2 bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30 rounded text-sm`,children:[(0,Y.jsx)(`div`,{className:`text-red-700 dark:text-red-400 font-medium mb-1`,children:`Errors:`}),(0,Y.jsx)(`ul`,{className:`text-xs text-red-700/90 dark:text-red-300/80 space-y-0.5`,children:V.errors.map((e,t)=>(0,Y.jsx)(`li`,{children:e},t))})]})]})]})]})]}),k&&(0,Y.jsx)(Tt,{title:e(`settings.amsSyncTitle`),message:e(`settings.amsSyncMessage`),confirmText:e(`settings.amsSyncButton`),variant:`warning`,isLoading:le.isPending,loadingText:e(`settings.amsSyncing`),onConfirm:()=>le.mutate(),onCancel:()=>j(!1)}),M&&(0,Y.jsx)(Tt,{title:e(`settings.spoolmanAmsSyncTitle`),message:e(`settings.spoolmanAmsSyncMessage`),confirmText:e(`settings.spoolmanAmsSyncButton`),variant:`warning`,isLoading:ue.isPending,loadingText:e(`settings.spoolmanAmsSyncing`),onConfirm:()=>ue.mutate(),onCancel:()=>N(!1)})]})}function pi(){let{t:e}=l(),{showToast:t}=ee(),[n,i]=(0,X.useState)([]),[a,o]=(0,X.useState)(!0),[s,c]=(0,X.useState)(``),u=(0,X.useRef)(null),[d,f]=(0,X.useState)(!1),[p,m]=(0,X.useState)(null),[h,g]=(0,X.useState)(``),[_,v]=(0,X.useState)(``),[y,b]=(0,X.useState)(!1),[x,S]=(0,X.useState)(new Set),[C,w]=(0,X.useState)(!1),[E,D]=(0,X.useState)(null),[O,k]=(0,X.useState)(!1),A=(0,X.useCallback)(async()=>{try{i(await r.getSpoolCatalog())}catch(n){console.error(`SpoolCatalogSettings.loadCatalog failed:`,n),t(e(`settings.catalog.loadFailed`),`error`)}finally{o(!1)}},[t,e]);(0,X.useEffect)(()=>{A()},[A]);let j=n.filter(e=>e.name.toLowerCase().includes(s.toLowerCase())),M=async()=>{if(!h.trim()||!_){t(e(`settings.catalog.nameWeightRequired`),`error`);return}b(!0);try{let n=await r.addCatalogEntry({name:h.trim(),weight:parseInt(_)});i(e=>[...e,n].sort((e,t)=>e.name.localeCompare(t.name))),f(!1),g(``),v(``),t(e(`settings.catalog.entryAdded`),`success`)}catch(n){console.error(`SpoolCatalogSettings.handleAdd failed:`,n),t(e(`settings.catalog.addFailed`),`error`)}finally{b(!1)}},N=e=>{m(e.id),g(e.name),v(e.weight.toString())},P=()=>{m(null),g(``),v(``)},te=async n=>{if(!h.trim()||!_){t(e(`settings.catalog.nameWeightRequired`),`error`);return}b(!0);try{let a=await r.updateCatalogEntry(n,{name:h.trim(),weight:parseInt(_)});i(e=>e.map(e=>e.id===n?a:e).sort((e,t)=>e.name.localeCompare(t.name))),m(null),g(``),v(``),t(e(`settings.catalog.entryUpdated`),`success`)}catch(n){console.error(`SpoolCatalogSettings.handleUpdate failed:`,n),t(e(`settings.catalog.updateFailed`),`error`)}finally{b(!1)}},F=async()=>{if(E)try{await r.deleteCatalogEntry(E.id),i(e=>e.filter(e=>e.id!==E.id)),t(e(`settings.catalog.entryDeleted`),`success`)}catch(n){console.error(`SpoolCatalogSettings.handleDelete failed:`,n),t(e(`settings.catalog.deleteFailed`),`error`)}finally{D(null)}},ne=async()=>{k(!1),o(!0);try{await r.resetSpoolCatalog(),await A(),t(e(`settings.catalog.resetSuccess`),`success`)}catch(n){console.error(`SpoolCatalogSettings.handleReset failed:`,n),t(e(`settings.catalog.resetFailed`),`error`),o(!1)}},I=e=>{S(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};return(0,Y.jsxs)(G,{id:`card-spool-catalog`,children:[(0,Y.jsxs)(U,{children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,Y.jsx)(gt,{className:`w-5 h-5 text-bambu-gray`}),(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`settings.catalog.spoolCatalog`)}),(0,Y.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[`(`,n.length,`)`]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,Y.jsxs)(`button`,{onClick:()=>{let r=n.map(({name:e,weight:t})=>({name:e,weight:t})),i=new Blob([JSON.stringify(r,null,2)],{type:`application/json`}),a=URL.createObjectURL(i),o=document.createElement(`a`);o.href=a,o.download=`spool-catalog.json`,document.body.appendChild(o),o.click(),document.body.removeChild(o),URL.revokeObjectURL(a),t(e(`settings.catalog.exported`,{count:n.length}),`success`)},className:`px-3 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white transition-colors flex items-center gap-1.5`,title:e(`settings.catalog.exportTooltip`),children:[(0,Y.jsx)(sn,{className:`w-4 h-4`}),(0,Y.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.export`)})]}),(0,Y.jsxs)(`button`,{onClick:()=>u.current?.click(),className:`px-3 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white transition-colors flex items-center gap-1.5`,title:e(`settings.catalog.importTooltip`),children:[(0,Y.jsx)(Wt,{className:`w-4 h-4`}),(0,Y.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.import`)})]}),(0,Y.jsx)(`input`,{ref:u,type:`file`,accept:`.json`,className:`hidden`,onChange:async a=>{let o=a.target.files?.[0];if(o){try{let a=await o.text(),s=JSON.parse(a);if(!Array.isArray(s))throw Error(`Invalid format`);let c=0,l=0;for(let e of s){if(!e.name||typeof e.weight!=`number`){l++;continue}if(n.some(t=>t.name.toLowerCase()===e.name.toLowerCase())){l++;continue}try{let t=await r.addCatalogEntry({name:e.name,weight:e.weight});i(e=>[...e,t].sort((e,t)=>e.name.localeCompare(t.name))),c++}catch(e){console.error(`SpoolCatalogSettings import item failed:`,e),l++}}t(e(`settings.catalog.imported`,{added:c,skipped:l}),`success`)}catch(n){console.error(`SpoolCatalogSettings.handleImport failed:`,n),t(e(`settings.catalog.importFailed`),`error`)}u.current&&(u.current.value=``)}}}),(0,Y.jsxs)(`button`,{onClick:()=>k(!0),className:`px-3 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white transition-colors flex items-center gap-1.5`,title:e(`settings.catalog.resetTooltip`),children:[(0,Y.jsx)(nt,{className:`w-4 h-4`}),(0,Y.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.reset`)})]}),(0,Y.jsxs)(`button`,{onClick:()=>f(!0),className:`px-3 py-1.5 text-sm bg-bambu-green text-white rounded-lg hover:bg-bambu-green/80 transition-colors flex items-center gap-1.5`,children:[(0,Y.jsx)(wt,{className:`w-4 h-4`}),(0,Y.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.add`)})]})]}),x.size>0&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 mt-2 px-3 py-2 bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30 rounded-lg`,children:[(0,Y.jsx)(`span`,{className:`text-sm text-red-700 dark:text-red-400`,children:e(`settings.catalog.selectedCount`,{count:x.size})}),(0,Y.jsxs)(`button`,{onClick:()=>w(!0),className:`ml-auto px-3 py-1.5 text-sm bg-red-500 text-white rounded-lg hover:bg-red-600 transition-colors flex items-center gap-1.5`,children:[(0,Y.jsx)(qe,{className:`w-4 h-4`}),e(`settings.catalog.deleteSelected`)]}),(0,Y.jsx)(`button`,{onClick:()=>S(new Set),className:`px-3 py-1.5 text-sm text-bambu-gray hover:text-white transition-colors`,children:e(`common.cancel`)})]})]}),(0,Y.jsxs)(W,{className:`space-y-4`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`settings.catalog.spoolCatalogDescription`)}),(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsx)(Ae,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,Y.jsx)(`input`,{type:`text`,className:`w-full pl-10 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`,placeholder:e(`settings.catalog.searchCatalog`),value:s,onChange:e=>c(e.target.value)})]}),d&&(0,Y.jsxs)(`div`,{className:`p-4 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,Y.jsx)(`h3`,{className:`text-sm font-medium text-white mb-3`,children:e(`settings.catalog.addNewEntry`)}),(0,Y.jsxs)(`div`,{className:`flex gap-2 items-center`,children:[(0,Y.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,Y.jsx)(`input`,{type:`text`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`,placeholder:e(`settings.catalog.namePlaceholder`),value:h,onChange:e=>g(e.target.value)})}),(0,Y.jsx)(`input`,{type:`number`,className:`w-20 px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white text-center focus:border-bambu-green focus:outline-none`,placeholder:`g`,value:_,onChange:e=>v(e.target.value)}),(0,Y.jsx)(`span`,{className:`text-bambu-gray shrink-0`,children:`g`}),(0,Y.jsxs)(`button`,{onClick:M,disabled:y,className:`px-3 py-2 bg-bambu-green text-white rounded-lg hover:bg-bambu-green/80 flex items-center gap-1 shrink-0`,children:[y?(0,Y.jsx)(R,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(T,{className:`w-4 h-4`}),e(`common.add`)]}),(0,Y.jsx)(`button`,{onClick:()=>{f(!1),g(``),v(``)},className:`p-2 rounded-lg text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary`,children:(0,Y.jsx)(Re,{className:`w-4 h-4`})})]})]}),a?(0,Y.jsxs)(`div`,{className:`flex items-center justify-center py-8 text-bambu-gray`,children:[(0,Y.jsx)(R,{className:`w-5 h-5 animate-spin mr-2`}),e(`common.loading`)]}):(0,Y.jsx)(`div`,{className:`max-h-[600px] overflow-y-auto border border-bambu-dark-tertiary rounded-lg`,children:(0,Y.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,Y.jsx)(`thead`,{className:`bg-bambu-dark sticky top-0`,children:(0,Y.jsxs)(`tr`,{children:[(0,Y.jsx)(`th`,{className:`px-2 py-2 w-10`,children:(0,Y.jsx)(`input`,{type:`checkbox`,checked:j.length>0&&x.size===j.length,onChange:()=>{x.size===j.length?S(new Set):S(new Set(j.map(e=>e.id)))},className:`w-4 h-4 accent-bambu-green cursor-pointer`})}),(0,Y.jsx)(`th`,{className:`px-4 py-2 text-left text-bambu-gray font-medium`,children:e(`common.name`)}),(0,Y.jsx)(`th`,{className:`px-4 py-2 text-right text-bambu-gray font-medium w-24`,children:e(`settings.catalog.weight`)}),(0,Y.jsx)(`th`,{className:`px-4 py-2 text-center text-bambu-gray font-medium w-20`,children:e(`settings.catalog.type`)}),(0,Y.jsx)(`th`,{className:`px-4 py-2 w-24`})]})}),(0,Y.jsx)(`tbody`,{children:j.length===0?(0,Y.jsx)(`tr`,{children:(0,Y.jsx)(`td`,{colSpan:5,className:`px-4 py-8 text-center text-bambu-gray`,children:e(s?`settings.catalog.noMatch`:`settings.catalog.empty`)})}):j.map(t=>(0,Y.jsx)(`tr`,{className:`border-t border-bambu-dark-tertiary hover:bg-bambu-dark ${x.has(t.id)?`bg-bambu-dark`:``}`,children:p===t.id?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`td`,{className:`px-2 py-2`,children:(0,Y.jsx)(`input`,{type:`checkbox`,checked:x.has(t.id),onChange:()=>I(t.id),className:`w-4 h-4 accent-bambu-green cursor-pointer`})}),(0,Y.jsx)(`td`,{className:`px-4 py-2`,children:(0,Y.jsx)(`input`,{type:`text`,className:`w-full px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white focus:border-bambu-green focus:outline-none`,value:h,onChange:e=>g(e.target.value)})}),(0,Y.jsx)(`td`,{className:`px-4 py-2`,children:(0,Y.jsx)(`input`,{type:`number`,className:`w-full px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-right focus:border-bambu-green focus:outline-none`,value:_,onChange:e=>v(e.target.value)})}),(0,Y.jsx)(`td`,{className:`px-4 py-2 text-center`,children:(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:`-`})}),(0,Y.jsx)(`td`,{className:`px-4 py-2`,children:(0,Y.jsxs)(`div`,{className:`flex justify-end gap-1`,children:[(0,Y.jsx)(`button`,{onClick:()=>te(t.id),disabled:y,className:`p-1.5 rounded hover:bg-green-500/20 text-green-500`,children:y?(0,Y.jsx)(R,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(T,{className:`w-4 h-4`})}),(0,Y.jsx)(`button`,{onClick:P,className:`p-1.5 rounded hover:bg-bambu-dark-tertiary text-bambu-gray`,children:(0,Y.jsx)(Re,{className:`w-4 h-4`})})]})})]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`td`,{className:`px-2 py-2`,children:(0,Y.jsx)(`input`,{type:`checkbox`,checked:x.has(t.id),onChange:()=>I(t.id),className:`w-4 h-4 accent-bambu-green cursor-pointer`})}),(0,Y.jsx)(`td`,{className:`px-4 py-2 text-white`,children:t.name}),(0,Y.jsxs)(`td`,{className:`px-4 py-2 text-right font-mono text-white`,children:[t.weight,`g`]}),(0,Y.jsx)(`td`,{className:`px-4 py-2 text-center`,children:t.is_default?(0,Y.jsx)(`span`,{className:`text-xs px-2 py-0.5 rounded bg-bambu-dark-tertiary text-bambu-gray`,children:e(`settings.catalog.default`)}):(0,Y.jsx)(`span`,{className:`text-xs px-2 py-0.5 rounded bg-bambu-green/20 text-bambu-green`,children:e(`settings.catalog.custom`)})}),(0,Y.jsx)(`td`,{className:`px-4 py-2`,children:(0,Y.jsxs)(`div`,{className:`flex justify-end gap-1`,children:[(0,Y.jsx)(`button`,{onClick:()=>N(t),className:`p-1.5 rounded hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white`,children:(0,Y.jsx)(Ke,{className:`w-4 h-4`})}),(0,Y.jsx)(`button`,{onClick:()=>D(t),className:`p-1.5 rounded bg-red-500/10 hover:bg-red-500/20 text-red-500`,children:(0,Y.jsx)(qe,{className:`w-4 h-4`})})]})})]})},t.id))})]})})]}),E&&(0,Y.jsx)(Tt,{title:e(`settings.catalog.deleteEntry`),message:e(`settings.catalog.deleteConfirm`,{name:E.name}),confirmText:e(`common.delete`),variant:`danger`,onConfirm:F,onCancel:()=>D(null)}),C&&(0,Y.jsx)(Tt,{title:e(`settings.catalog.deleteSelected`),message:e(`settings.catalog.bulkDeleteConfirm`,{count:x.size}),confirmText:e(`common.delete`),variant:`danger`,onConfirm:async()=>{if(w(!1),x.size!==0)try{let n=await r.bulkDeleteCatalogEntries([...x]);i(e=>e.filter(e=>!x.has(e.id))),S(new Set),t(e(`settings.catalog.bulkDeleted`,{count:n.deleted}),`success`)}catch(n){console.error(`SpoolCatalogSettings.handleBulkDelete failed:`,n),t(e(`settings.catalog.bulkDeleteFailed`),`error`)}},onCancel:()=>w(!1)}),O&&(0,Y.jsx)(Tt,{title:e(`settings.catalog.resetCatalog`),message:e(`settings.catalog.resetConfirm`),confirmText:e(`common.reset`),variant:`danger`,onConfirm:ne,onCancel:()=>k(!1)})]})}function mi(){let{t:e}=l(),{showToast:t}=ee(),[n,i]=(0,X.useState)([]),[a,s]=(0,X.useState)(!0),[c,u]=(0,X.useState)(``),[d,f]=(0,X.useState)(``),p=(0,X.useRef)(null),[m,h]=(0,X.useState)(!1),[g,_]=(0,X.useState)(null),[v,y]=(0,X.useState)(``),[b,x]=(0,X.useState)(``),[S,C]=(0,X.useState)(`#FFFFFF`),[w,E]=(0,X.useState)(``),[D,O]=(0,X.useState)(``),[k,A]=(0,X.useState)(``),[j,M]=(0,X.useState)(!1),[N,P]=(0,X.useState)(new Set),[te,F]=(0,X.useState)(!1),[ne,I]=(0,X.useState)(!1),[re,ie]=(0,X.useState)(null),[L,ae]=(0,X.useState)(null),[z,oe]=(0,X.useState)(!1),se=(0,X.useCallback)(async()=>{try{i(await r.getColorCatalog())}catch{t(e(`settings.colorCatalog.loadFailed`),`error`)}finally{s(!1)}},[t,e]);(0,X.useEffect)(()=>{se()},[se]);let B=[...new Set(n.map(e=>e.manufacturer))].sort(),ce=n.filter(e=>{let t=c===``||e.manufacturer.toLowerCase().includes(c.toLowerCase())||e.color_name.toLowerCase().includes(c.toLowerCase())||(e.material?.toLowerCase().includes(c.toLowerCase())??!1),n=d===``||e.manufacturer===d;return t&&n}),le=()=>{y(``),x(``),C(`#FFFFFF`),E(``),O(``),A(``)},ue=async()=>{if(!v.trim()||!b.trim()||!S){t(e(`settings.colorCatalog.fieldsRequired`),`error`);return}M(!0);try{let n=await r.addColorEntry({manufacturer:v.trim(),color_name:b.trim(),hex_color:S,material:w.trim()||null,extra_colors:D.trim()||null,effect_type:k.trim()||null});i(e=>[...e,n].sort((e,t)=>e.manufacturer.localeCompare(t.manufacturer)||(e.material||``).localeCompare(t.material||``)||e.color_name.localeCompare(t.color_name))),h(!1),le(),t(e(`settings.colorCatalog.colorAdded`),`success`)}catch{t(e(`settings.colorCatalog.addFailed`),`error`)}finally{M(!1)}},de=e=>{_(e.id),y(e.manufacturer),x(e.color_name),C(e.hex_color),E(e.material||``),O(e.extra_colors||``),A(e.effect_type||``)},fe=()=>{_(null),le()},V=async n=>{if(!v.trim()||!b.trim()||!S){t(e(`settings.colorCatalog.fieldsRequired`),`error`);return}M(!0);try{let a=await r.updateColorEntry(n,{manufacturer:v.trim(),color_name:b.trim(),hex_color:S,material:w.trim()||null,extra_colors:D.trim()||null,effect_type:k.trim()||null});i(e=>e.map(e=>e.id===n?a:e).sort((e,t)=>e.manufacturer.localeCompare(t.manufacturer)||(e.material||``).localeCompare(t.material||``)||e.color_name.localeCompare(t.color_name))),_(null),le(),t(e(`settings.colorCatalog.colorUpdated`),`success`)}catch{t(e(`settings.colorCatalog.updateFailed`),`error`)}finally{M(!1)}},pe=async()=>{if(L)try{await r.deleteColorEntry(L.id),i(e=>e.filter(e=>e.id!==L.id)),t(e(`settings.colorCatalog.colorDeleted`),`success`)}catch{t(e(`settings.colorCatalog.deleteFailed`),`error`)}finally{ae(null)}},me=async()=>{oe(!1),s(!0);try{await r.resetColorCatalog(),await se(),t(e(`settings.colorCatalog.resetSuccess`),`success`)}catch{t(e(`settings.colorCatalog.resetFailed`),`error`),s(!1)}},he=async()=>{I(!0),ie(null);try{let n={},r=o();r&&(n.Authorization=`Bearer ${r}`);let i=await fetch(`/api/v1/inventory/colors/sync`,{method:`POST`,headers:n});if(!i.ok)throw Error(`Failed to start sync`);let a=i.body?.getReader();if(!a)throw Error(`No response body`);let s=new TextDecoder,c=``;for(;;){let{done:n,value:r}=await a.read();if(n)break;c+=s.decode(r,{stream:!0});let i=c.split(` `);c=i.pop()||``;for(let n of i)if(n.startsWith(`data: `))try{let r=JSON.parse(n.slice(6));r.type===`progress`?ie({fetched:r.total_fetched,total:r.total_available}):r.type===`complete`?r.added===0?t(e(`settings.colorCatalog.syncUpToDate`,{count:r.total_fetched}),`success`):t(e(`settings.colorCatalog.syncComplete`,{added:r.added,skipped:r.skipped}),`success`):r.type===`error`&&t(`${e(`settings.colorCatalog.syncError`)}: ${r.error}`,`error`)}catch{}}await se()}catch{t(e(`settings.colorCatalog.syncFailed`),`error`)}finally{I(!1),ie(null)}},ge=e=>{P(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};return(0,Y.jsxs)(G,{id:`card-color-catalog`,children:[(0,Y.jsxs)(U,{children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,Y.jsx)(Nt,{className:`w-5 h-5 text-bambu-gray`}),(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`settings.colorCatalog.title`)}),(0,Y.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[`(`,n.length,`)`]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,Y.jsxs)(`button`,{onClick:()=>{let r=n.map(({manufacturer:e,color_name:t,hex_color:n,material:r,extra_colors:i,effect_type:a})=>({manufacturer:e,color_name:t,hex_color:n,material:r,extra_colors:i,effect_type:a})),i=new Blob([JSON.stringify(r,null,2)],{type:`application/json`}),a=URL.createObjectURL(i),o=document.createElement(`a`);o.href=a,o.download=`color-catalog.json`,document.body.appendChild(o),o.click(),document.body.removeChild(o),URL.revokeObjectURL(a),t(e(`settings.colorCatalog.exported`,{count:n.length}),`success`)},className:`px-3 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white transition-colors flex items-center gap-1.5`,children:[(0,Y.jsx)(sn,{className:`w-4 h-4`}),(0,Y.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.export`)})]}),(0,Y.jsxs)(`button`,{onClick:()=>p.current?.click(),className:`px-3 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white transition-colors flex items-center gap-1.5`,children:[(0,Y.jsx)(Wt,{className:`w-4 h-4`}),(0,Y.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.import`)})]}),(0,Y.jsx)(`input`,{ref:p,type:`file`,accept:`.json`,className:`hidden`,onChange:async a=>{let o=a.target.files?.[0];if(o){try{let a=await o.text(),s=JSON.parse(a);if(!Array.isArray(s))throw Error(`Invalid format`);let c=0,l=0;for(let e of s){if(!e.manufacturer||!e.color_name||!e.hex_color){l++;continue}if(n.some(t=>t.manufacturer.toLowerCase()===e.manufacturer.toLowerCase()&&t.color_name.toLowerCase()===e.color_name.toLowerCase()&&(t.material||``).toLowerCase()===(e.material||``).toLowerCase())){l++;continue}try{let t=await r.addColorEntry({manufacturer:e.manufacturer,color_name:e.color_name,hex_color:e.hex_color,material:e.material||null,extra_colors:e.extra_colors||null,effect_type:e.effect_type||null});i(e=>[...e,t].sort((e,t)=>e.manufacturer.localeCompare(t.manufacturer)||(e.material||``).localeCompare(t.material||``)||e.color_name.localeCompare(t.color_name))),c++}catch{l++}}t(e(`settings.colorCatalog.imported`,{added:c,skipped:l}),`success`)}catch{t(e(`settings.colorCatalog.importFailed`),`error`)}p.current&&(p.current.value=``)}}}),(0,Y.jsxs)(`button`,{onClick:he,disabled:ne,className:`px-3 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white transition-colors flex items-center gap-1.5`,title:e(`settings.colorCatalog.syncTooltip`),children:[ne?(0,Y.jsx)(R,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(Xe,{className:`w-4 h-4`}),(0,Y.jsx)(`span`,{className:`hidden sm:inline`,children:ne?re?`${Math.min(re.fetched,re.total)} / ${re.total}`:e(`settings.colorCatalog.starting`):e(`settings.colorCatalog.sync`)})]}),(0,Y.jsxs)(`button`,{onClick:()=>oe(!0),className:`px-3 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white transition-colors flex items-center gap-1.5`,children:[(0,Y.jsx)(nt,{className:`w-4 h-4`}),(0,Y.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.reset`)})]}),(0,Y.jsxs)(`button`,{onClick:()=>h(!0),className:`px-3 py-1.5 text-sm bg-bambu-green text-white rounded-lg hover:bg-bambu-green/80 transition-colors flex items-center gap-1.5`,children:[(0,Y.jsx)(wt,{className:`w-4 h-4`}),(0,Y.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.add`)})]})]}),N.size>0&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 mt-2 px-3 py-2 bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30 rounded-lg`,children:[(0,Y.jsx)(`span`,{className:`text-sm text-red-700 dark:text-red-400`,children:e(`settings.colorCatalog.selectedCount`,{count:N.size})}),(0,Y.jsxs)(`button`,{onClick:()=>F(!0),className:`ml-auto px-3 py-1.5 text-sm bg-red-500 text-white rounded-lg hover:bg-red-600 transition-colors flex items-center gap-1.5`,children:[(0,Y.jsx)(qe,{className:`w-4 h-4`}),e(`settings.colorCatalog.deleteSelected`)]}),(0,Y.jsx)(`button`,{onClick:()=>P(new Set),className:`px-3 py-1.5 text-sm text-bambu-gray hover:text-white transition-colors`,children:e(`common.cancel`)})]})]}),(0,Y.jsxs)(W,{className:`space-y-4`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`settings.colorCatalog.description`)}),(0,Y.jsxs)(`div`,{className:`flex gap-2 flex-wrap`,children:[(0,Y.jsxs)(`div`,{className:`relative flex-1 min-w-[200px]`,children:[(0,Y.jsx)(Ae,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,Y.jsx)(`input`,{type:`text`,className:`w-full pl-10 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`,placeholder:e(`settings.colorCatalog.searchColors`),value:c,onChange:e=>u(e.target.value)})]}),(0,Y.jsxs)(`select`,{className:`px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,value:d,onChange:e=>f(e.target.value),children:[(0,Y.jsx)(`option`,{value:``,children:e(`settings.colorCatalog.allManufacturers`)}),B.map(e=>(0,Y.jsx)(`option`,{value:e,children:e},e))]})]}),m&&(0,Y.jsxs)(`div`,{className:`p-4 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,Y.jsx)(`h3`,{className:`text-sm font-medium text-white mb-3`,children:e(`settings.colorCatalog.addNewColor`)}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-5 gap-2 items-end`,children:[(0,Y.jsx)(`input`,{type:`text`,className:`px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`,placeholder:e(`settings.colorCatalog.manufacturer`),value:v,onChange:e=>y(e.target.value)}),(0,Y.jsx)(`input`,{type:`text`,className:`px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`,placeholder:e(`settings.colorCatalog.colorName`),value:b,onChange:e=>x(e.target.value)}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`input`,{type:`color`,className:`w-20 h-10 rounded cursor-pointer border border-bambu-dark-tertiary`,value:S,onChange:e=>C(e.target.value)}),(0,Y.jsx)(`input`,{type:`text`,className:`w-32 px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`,placeholder:`#FFFFFF`,value:S,onChange:e=>C(e.target.value)})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Y.jsx)(`input`,{type:`text`,className:`flex-1 max-w-lg min-w-[200px] px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`,placeholder:e(`settings.colorCatalog.materialOptional`),value:w,onChange:e=>E(e.target.value)}),(0,Y.jsxs)(`button`,{onClick:ue,disabled:j,className:`w-24 px-3 py-2 bg-bambu-green text-white rounded-lg hover:bg-bambu-green/80 flex items-center justify-center gap-3`,children:[j?(0,Y.jsx)(R,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(T,{className:`w-4 h-4`}),e(`common.add`)]}),(0,Y.jsx)(`button`,{onClick:()=>{h(!1),le()},className:`p-2 ml-2 rounded-lg text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary`,children:(0,Y.jsx)(Re,{className:`w-4 h-4`})})]})]}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-2 mt-2`,children:[(0,Y.jsx)(`input`,{type:`text`,className:`px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white text-sm font-mono placeholder-bambu-gray focus:border-bambu-green focus:outline-none`,placeholder:e(`inventory.extraColorsPlaceholder`),value:D,onChange:e=>O(e.target.value)}),(0,Y.jsx)(`select`,{className:`px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,value:k,onChange:e=>A(e.target.value),children:Ge.map(t=>(0,Y.jsx)(`option`,{value:t.value,children:e(t.labelKey)},t.value||`none`))})]})]}),(c||d)&&(0,Y.jsx)(`div`,{className:`text-xs text-bambu-gray`,children:e(`settings.colorCatalog.showing`,{filtered:ce.length,total:n.length})}),a?(0,Y.jsxs)(`div`,{className:`flex items-center justify-center py-8 text-bambu-gray`,children:[(0,Y.jsx)(R,{className:`w-5 h-5 animate-spin mr-2`}),e(`common.loading`)]}):(0,Y.jsx)(`div`,{className:`max-h-[600px] overflow-auto border border-bambu-dark-tertiary rounded-lg`,children:(0,Y.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,Y.jsx)(`thead`,{className:`bg-bambu-dark sticky top-0`,children:(0,Y.jsxs)(`tr`,{children:[(0,Y.jsx)(`th`,{className:`px-2 py-2 w-10`,children:(0,Y.jsx)(`input`,{type:`checkbox`,checked:ce.length>0&&N.size===ce.length,onChange:()=>{N.size===ce.length?P(new Set):P(new Set(ce.map(e=>e.id)))},className:`w-4 h-4 accent-bambu-green cursor-pointer`})}),(0,Y.jsx)(`th`,{className:`px-3 py-2 text-left text-bambu-gray font-medium w-12`}),(0,Y.jsx)(`th`,{className:`px-3 py-2 text-left text-bambu-gray font-medium`,children:e(`settings.colorCatalog.manufacturer`)}),(0,Y.jsx)(`th`,{className:`px-3 py-2 text-left text-bambu-gray font-medium`,children:e(`inventory.material`)}),(0,Y.jsx)(`th`,{className:`px-3 py-2 text-left text-bambu-gray font-medium`,children:e(`settings.colorCatalog.colorName`)}),(0,Y.jsx)(`th`,{className:`px-3 py-2 text-left text-bambu-gray font-medium w-24`,children:e(`settings.colorCatalog.hex`)}),(0,Y.jsx)(`th`,{className:`px-3 py-2 w-16`})]})}),(0,Y.jsx)(`tbody`,{children:ce.length===0?(0,Y.jsx)(`tr`,{children:(0,Y.jsx)(`td`,{colSpan:7,className:`px-3 py-8 text-center text-bambu-gray`,children:e(c||d?`settings.colorCatalog.noMatch`:`settings.colorCatalog.empty`)})}):ce.map(t=>(0,Y.jsxs)(X.Fragment,{children:[(0,Y.jsx)(`tr`,{className:`border-t border-bambu-dark-tertiary hover:bg-bambu-dark ${N.has(t.id)?`bg-bambu-dark`:``}`,children:g===t.id?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`td`,{className:`px-2 py-2`,children:(0,Y.jsx)(`input`,{type:`checkbox`,checked:N.has(t.id),onChange:()=>ge(t.id),className:`w-4 h-4 accent-bambu-green cursor-pointer`})}),(0,Y.jsx)(`td`,{className:`px-3 py-2`,children:(0,Y.jsx)(`input`,{type:`color`,className:`w-8 h-8 rounded cursor-pointer border border-bambu-dark-tertiary`,value:S,onChange:e=>C(e.target.value)})}),(0,Y.jsx)(`td`,{className:`px-3 py-2`,children:(0,Y.jsx)(`input`,{type:`text`,className:`w-full px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`,value:v,onChange:e=>y(e.target.value)})}),(0,Y.jsx)(`td`,{className:`px-3 py-2`,children:(0,Y.jsx)(`input`,{type:`text`,className:`w-full px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`,value:w,onChange:e=>E(e.target.value)})}),(0,Y.jsx)(`td`,{className:`px-3 py-2`,children:(0,Y.jsx)(`input`,{type:`text`,className:`w-full px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`,value:b,onChange:e=>x(e.target.value)})}),(0,Y.jsx)(`td`,{className:`px-3 py-2`,children:(0,Y.jsx)(`input`,{type:`text`,className:`w-full px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`,value:S,onChange:e=>C(e.target.value)})}),(0,Y.jsx)(`td`,{className:`px-3 py-2`,children:(0,Y.jsxs)(`div`,{className:`flex justify-end gap-1`,children:[(0,Y.jsx)(`button`,{onClick:()=>V(t.id),disabled:j,className:`p-1.5 rounded hover:bg-green-500/20 text-green-500`,children:j?(0,Y.jsx)(R,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(T,{className:`w-4 h-4`})}),(0,Y.jsx)(`button`,{onClick:fe,className:`p-1.5 rounded hover:bg-bambu-dark-tertiary text-bambu-gray`,children:(0,Y.jsx)(Re,{className:`w-4 h-4`})})]})})]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`td`,{className:`px-2 py-2`,children:(0,Y.jsx)(`input`,{type:`checkbox`,checked:N.has(t.id),onChange:()=>ge(t.id),className:`w-4 h-4 accent-bambu-green cursor-pointer`})}),(0,Y.jsx)(`td`,{className:`px-3 py-2`,children:(0,Y.jsx)(on,{rgba:t.hex_color.replace(/^#/,``)+(t.hex_color.length===7?`FF`:``),extraColors:t.extra_colors,effectType:t.effect_type,className:`w-8 h-8`,shape:`square`,title:t.hex_color,effectSize:`table`})}),(0,Y.jsx)(`td`,{className:`px-3 py-2 text-white`,children:t.manufacturer}),(0,Y.jsx)(`td`,{className:`px-3 py-2 text-bambu-gray`,children:t.material||`-`}),(0,Y.jsx)(`td`,{className:`px-3 py-2 text-white`,children:t.color_name}),(0,Y.jsx)(`td`,{className:`px-3 py-2 font-mono text-xs text-bambu-gray`,children:t.hex_color}),(0,Y.jsx)(`td`,{className:`px-3 py-2`,children:(0,Y.jsxs)(`div`,{className:`flex justify-end gap-1`,children:[(0,Y.jsx)(`button`,{onClick:()=>de(t),className:`p-1.5 rounded hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white`,children:(0,Y.jsx)(Ke,{className:`w-4 h-4`})}),(0,Y.jsx)(`button`,{onClick:()=>ae(t),className:`p-1.5 rounded bg-red-500/10 hover:bg-red-500/20 text-red-500`,children:(0,Y.jsx)(qe,{className:`w-4 h-4`})})]})})]})}),g===t.id&&(0,Y.jsxs)(`tr`,{className:`border-t border-bambu-dark-tertiary/50 bg-bambu-dark`,children:[(0,Y.jsx)(`td`,{colSpan:2}),(0,Y.jsx)(`td`,{className:`px-3 py-2`,colSpan:2,children:(0,Y.jsx)(`input`,{type:`text`,className:`w-full px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm font-mono focus:border-bambu-green focus:outline-none`,placeholder:e(`inventory.extraColorsPlaceholder`),value:D,onChange:e=>O(e.target.value)})}),(0,Y.jsx)(`td`,{className:`px-3 py-2`,colSpan:2,children:(0,Y.jsx)(`select`,{className:`w-full px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`,value:k,onChange:e=>A(e.target.value),children:Ge.map(t=>(0,Y.jsx)(`option`,{value:t.value,children:e(t.labelKey)},t.value||`none`))})}),(0,Y.jsx)(`td`,{})]})]},t.id))})]})})]}),L&&(0,Y.jsx)(Tt,{title:e(`settings.colorCatalog.deleteColor`),message:e(`settings.colorCatalog.deleteConfirm`,{name:`${L.manufacturer} - ${L.color_name}`}),confirmText:e(`common.delete`),variant:`danger`,onConfirm:pe,onCancel:()=>ae(null)}),te&&(0,Y.jsx)(Tt,{title:e(`settings.colorCatalog.deleteSelected`),message:e(`settings.colorCatalog.bulkDeleteConfirm`,{count:N.size}),confirmText:e(`common.delete`),variant:`danger`,onConfirm:async()=>{if(F(!1),N.size!==0)try{let n=await r.bulkDeleteColorEntries([...N]);i(e=>e.filter(e=>!N.has(e.id))),P(new Set),t(e(`settings.colorCatalog.bulkDeleted`,{count:n.deleted}),`success`)}catch{t(e(`settings.colorCatalog.bulkDeleteFailed`),`error`)}},onCancel:()=>F(!1)}),z&&(0,Y.jsx)(Tt,{title:e(`settings.colorCatalog.resetCatalog`),message:e(`settings.colorCatalog.resetConfirm`),confirmText:e(`common.reset`),variant:`danger`,onConfirm:me,onCancel:()=>oe(!1)})]})}function hi({link:e,onClose:t}){let{t:n}=l(),i=u(),a=!!e,o=(0,X.useRef)(null),[s,c]=(0,X.useState)(e?.name||``),[d,p]=(0,X.useState)(e?.url||``),[m,h]=(0,X.useState)(e?.icon||`link`),[g,_]=(0,X.useState)(e?.open_in_new_tab||!1),[v,y]=(0,X.useState)(!!e?.custom_icon),[b,x]=(0,X.useState)(e?.custom_icon?r.getExternalLinkIconUrl(e.id):null),[S,C]=(0,X.useState)(null),[w,T]=(0,X.useState)(null);(0,X.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]);let E=f({mutationFn:async e=>{let t=await r.createExternalLink(e);return S?await r.uploadExternalLinkIcon(t.id,S):t},onSuccess:()=>{i.invalidateQueries({queryKey:[`external-links`]}),t()},onError:e=>{T(e.message)}}),D=f({mutationFn:async t=>{let n=await r.updateExternalLink(e.id,t);return S?n=await r.uploadExternalLinkIcon(e.id,S):!v&&e?.custom_icon&&(n=await r.deleteExternalLinkIcon(e.id)),n},onSuccess:()=>{i.invalidateQueries({queryKey:[`external-links`]}),t()},onError:e=>{T(e.message)}}),O=e=>{let t=e.target.files?.[0];if(t){if(![`image/png`,`image/jpeg`,`image/gif`,`image/svg+xml`,`image/webp`,`image/x-icon`].includes(t.type)){T(`Please select a valid image file (PNG, JPG, GIF, SVG, WebP, or ICO)`);return}if(t.size>1024*1024){T(`Image file must be less than 1MB`);return}C(t),y(!0);let e=new FileReader;e.onload=e=>{x(e.target?.result)},e.readAsDataURL(t)}},k=()=>{C(null),x(null),y(!1),o.current&&(o.current.value=``)},A=e=>{if(e.preventDefault(),T(null),!s.trim()){T(`Name is required`);return}if(!d.trim()){T(`URL is required`);return}if(!d.startsWith(`http://`)&&!d.startsWith(`https://`)){T(`URL must start with http:// or https://`);return}let t={name:s.trim(),url:d.trim(),icon:m,open_in_new_tab:g};a?D.mutate(t):E.mutate(t)},ee=E.isPending||D.isPending,j=Lt(m);return(0,Y.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:t,children:(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-md`,onClick:e=>e.stopPropagation(),children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Y.jsx)(`div`,{className:`p-2 rounded-full bg-bambu-green/20 text-bambu-green`,children:v&&b?(0,Y.jsx)(`img`,{src:b,alt:``,className:`w-5 h-5 rounded`}):(0,Y.jsx)(j,{className:`w-5 h-5`})}),(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:a?`Edit Link`:`Add External Link`})]}),(0,Y.jsx)(`button`,{onClick:t,className:`text-bambu-gray hover:text-white transition-colors`,children:(0,Y.jsx)(Re,{className:`w-5 h-5`})})]}),(0,Y.jsxs)(`form`,{onSubmit:A,className:`p-6 space-y-4`,children:[w&&(0,Y.jsx)(`div`,{className:`p-3 bg-red-100 dark:bg-red-500/20 border border-red-300 dark:border-red-500/50 rounded-lg text-sm text-red-700 dark:text-red-400`,children:w}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:`Name *`}),(0,Y.jsx)(`input`,{type:`text`,value:s,onChange:e=>c(e.target.value),placeholder:`My Link`,maxLength:50,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:`URL *`}),(0,Y.jsx)(`input`,{type:`text`,value:d,onChange:e=>p(e.target.value),placeholder:`https://example.com`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`label`,{className:`text-sm text-bambu-gray`,children:n(`externalLinks.openInNewTab`)}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>_(!g),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors ${g?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,children:(0,Y.jsx)(`span`,{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${g?`translate-x-6`:`translate-x-1`}`})})]}),(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray`,children:`Icon`}),(0,Y.jsxs)(`div`,{className:`p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:`Custom Icon`}),(0,Y.jsx)(`input`,{ref:o,type:`file`,accept:`image/png,image/jpeg,image/gif,image/svg+xml,image/webp,image/x-icon`,className:`hidden`,onChange:O}),v&&b?(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`img`,{src:b,alt:`Custom icon`,className:`w-8 h-8 rounded border border-bambu-dark-tertiary`}),(0,Y.jsx)(`button`,{type:`button`,onClick:k,className:`p-1 text-red-700 dark:text-red-400 hover:text-red-800 dark:hover:text-red-300 transition-colors`,title:`Remove custom icon`,children:(0,Y.jsx)(qe,{className:`w-4 h-4`})})]}):(0,Y.jsxs)(K,{type:`button`,variant:`secondary`,size:`sm`,onClick:()=>o.current?.click(),children:[(0,Y.jsx)(Wt,{className:`w-4 h-4`}),`Upload`]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:`PNG, JPG, GIF, SVG, WebP, or ICO. Max 1MB.`})]}),!v&&(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray block mb-2`,children:`Or choose a preset icon`}),(0,Y.jsx)(Bt,{value:m,onChange:h})]})]}),(0,Y.jsxs)(`div`,{className:`flex gap-3 pt-2`,children:[(0,Y.jsx)(K,{type:`button`,variant:`secondary`,onClick:t,className:`flex-1`,children:`Cancel`}),(0,Y.jsxs)(K,{type:`submit`,disabled:ee,className:`flex-1`,children:[ee?(0,Y.jsx)(R,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(_t,{className:`w-4 h-4`}),a?`Save`:`Add`]})]})]})]})})}function gi(){let{t:e}=l(),t=u(),{authEnabled:n,hasPermission:i}=un(),{showToast:a}=ee(),[o,s]=(0,X.useState)(!1),[c,p]=(0,X.useState)(null),[m,h]=(0,X.useState)(null),[g,_]=(0,X.useState)(null),[v,y]=(0,X.useState)(null),[b,x]=(0,X.useState)(jt),[S,C]=(0,X.useState)(()=>Pt(kt.map(e=>e.id))),{data:w,isLoading:T}=d({queryKey:[`external-links`],queryFn:r.getExternalLinks}),E=f({mutationFn:e=>r.deleteExternalLink(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`external-links`]})}}),{data:D}=d({queryKey:[`settings`],queryFn:r.getSettings,enabled:n&&i(`settings:update`)}),O=f({mutationFn:e=>r.updateSettings({default_sidebar_order:e}),onSuccess:(n,r)=>{t.invalidateQueries({queryKey:[`settings`]}),t.invalidateQueries({queryKey:[`default-sidebar-order`]}),a(e(r?`settings.sidebarDefaultSet`:`settings.sidebarDefaultCleared`),`success`)},onError:()=>{a(e(`settings.sidebarDefaultFailed`),`error`)}}),k=(0,X.useMemo)(()=>{let e=new Map(kt.map(e=>[e.id,e])),t=new Map((w||[]).map(e=>[`ext-${e.id}`,e])),n=[],r=new Set,i=i=>{if(r.has(i))return;let a=e.get(i);if(a){n.push({type:`system`,id:i,navItem:a}),r.add(i);return}let o=t.get(i);o&&(n.push({type:`external`,id:i,link:o}),r.add(i))};return S.forEach(i),kt.forEach(e=>i(e.id)),(w||[]).forEach(e=>i(`ext-${e.id}`)),n},[w,S]),A=e=>{C(e),qt(e)},j=(e,t)=>{_(t),e.dataTransfer.effectAllowed=`move`,e.dataTransfer.setData(`text/plain`,t)},M=(e,t)=>{e.preventDefault(),e.dataTransfer.dropEffect=`move`,y(t)},N=(e,t)=>{if(e.preventDefault(),g===null||g===t){_(null),y(null);return}let n=k.map(e=>e.id),r=n.indexOf(g),i=n.indexOf(t);if(r===-1||i===-1){_(null),y(null);return}n.splice(r,1),n.splice(i,0,g),A(n),_(null),y(null)},P=()=>{_(null),y(null)},te=e=>{h(e)},ne=()=>{m&&(E.mutate(m.id),h(null))},re=()=>{let e=[...kt.map(e=>e.id),...(w||[]).map(e=>`ext-${e.id}`)];x([]),C(e),Qt([]),qt(e)},ie=e=>{let t=k.map(e=>e.id);O.mutate(e?JSON.stringify({order:t,hiddenSystemItemIds:b}):``)},L=e=>{if(e===`settings`)return;let t=b.includes(e)?b.filter(t=>t!==e):[...b,e];x(t),Qt(t)},z=n&&i(`settings:update`),oe=!!D?.default_sidebar_order;return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(G,{id:`card-sidebar-links`,children:[(0,Y.jsx)(U,{children:(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-y-2 gap-x-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(ae,{className:`w-5 h-5 text-bambu-green`}),(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`externalLinks.sidebarLayout`)})]}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[z&&(0,Y.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-bambu-gray`,children:[(0,Y.jsx)(`span`,{children:e(`settings.setDefault`)}),(0,Y.jsx)(J,{checked:oe,onChange:ie,disabled:O.isPending})]}),(0,Y.jsxs)(K,{variant:`secondary`,size:`sm`,onClick:re,className:`whitespace-nowrap`,children:[(0,Y.jsx)(nt,{className:`w-4 h-4`}),e(`settings.reset`)]}),(0,Y.jsxs)(K,{size:`sm`,onClick:()=>s(!0),className:`whitespace-nowrap`,children:[(0,Y.jsx)(wt,{className:`w-4 h-4`}),`Add Link`]})]})]})}),(0,Y.jsxs)(W,{children:[(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4`,children:e(`externalLinks.sidebarLayoutDescription`)}),T?(0,Y.jsx)(`div`,{className:`flex justify-center py-8`,children:(0,Y.jsx)(R,{className:`w-6 h-6 text-bambu-green animate-spin`})}):(0,Y.jsx)(`div`,{className:`space-y-2`,children:k.map(t=>{let n=t.type===`system`&&b.includes(t.id),i=t.id===`settings`;if(t.type===`system`){let r=t.navItem.icon;return(0,Y.jsxs)(`div`,{draggable:!0,onDragStart:e=>j(e,t.id),onDragOver:e=>M(e,t.id),onDragLeave:()=>y(null),onDrop:e=>N(e,t.id),onDragEnd:P,className:`relative flex items-center gap-3 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary transition-colors ${g===t.id?`opacity-50`:n?`opacity-60`:``} ${v===t.id&&g!==t.id?`before:absolute before:left-3 before:right-3 before:top-0 before:h-0.5 before:bg-bambu-green`:``}`,children:[(0,Y.jsx)(I,{className:`w-6 h-6 md:w-4 md:h-4 text-bambu-gray cursor-grab flex-shrink-0`}),(0,Y.jsx)(`div`,{className:`p-2 rounded-lg bg-bambu-dark-tertiary text-bambu-gray`,children:(0,Y.jsx)(r,{className:`w-4 h-4`})}),(0,Y.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Y.jsx)(`span`,{className:`text-white font-medium truncate block`,children:e(t.navItem.labelKey)}),(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray truncate block`,children:e(i?`externalLinks.requiredInSidebar`:n?`externalLinks.hiddenFromSidebar`:`externalLinks.visibleInSidebar`)})]}),(0,Y.jsx)(`button`,{onClick:()=>L(t.id),disabled:i,className:`p-2 rounded-lg hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white transition-colors flex-shrink-0 disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:bg-transparent disabled:hover:text-bambu-gray`,title:e(i?`externalLinks.settingsCannotBeHidden`:n?`externalLinks.showPage`:`externalLinks.hidePage`),"aria-label":e(i?`externalLinks.settingsCannotBeHidden`:n?`externalLinks.showPage`:`externalLinks.hidePage`),children:n?(0,Y.jsx)(F,{className:`w-4 h-4`}):(0,Y.jsx)(mt,{className:`w-4 h-4`})})]},t.id)}let a=t.link,o=Lt(a.icon);return(0,Y.jsxs)(`div`,{draggable:!0,onDragStart:e=>j(e,t.id),onDragOver:e=>M(e,t.id),onDragLeave:()=>y(null),onDrop:e=>N(e,t.id),onDragEnd:P,className:`relative flex items-center gap-3 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary transition-colors ${g===t.id?`opacity-50`:``} ${v===t.id&&g!==t.id?`before:absolute before:left-3 before:right-3 before:top-0 before:h-0.5 before:bg-bambu-green`:``}`,children:[(0,Y.jsx)(I,{className:`w-6 h-6 md:w-4 md:h-4 text-bambu-gray cursor-grab flex-shrink-0`}),(0,Y.jsx)(`div`,{className:`p-2 rounded-lg bg-bambu-dark-tertiary text-bambu-gray`,children:a.custom_icon?(0,Y.jsx)(`img`,{src:r.getExternalLinkIconUrl(a.id),alt:``,className:`w-4 h-4`}):(0,Y.jsx)(o,{className:`w-4 h-4`})}),(0,Y.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{className:`text-white font-medium truncate`,children:a.name}),(0,Y.jsx)(Je,{className:`w-3 h-3 text-bambu-gray flex-shrink-0`})]}),(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray truncate block`,children:a.url})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1 flex-shrink-0`,children:[(0,Y.jsx)(`button`,{onClick:()=>p(a),className:`p-2 rounded-lg hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white transition-colors`,title:e(`common.edit`),children:(0,Y.jsx)(Ke,{className:`w-4 h-4`})}),(0,Y.jsx)(`button`,{onClick:()=>te(a),disabled:E.isPending,className:`p-2 rounded-lg hover:bg-red-100 dark:hover:bg-red-500/20 text-bambu-gray hover:text-red-900 dark:hover:text-red-400 transition-colors disabled:opacity-50`,title:e(`externalLinks.deleteLink`),children:(0,Y.jsx)(qe,{className:`w-4 h-4`})})]})]},t.id)})})]})]}),(o||c)&&(0,Y.jsx)(hi,{link:c,onClose:()=>{s(!1),p(null)}}),m&&(0,Y.jsx)(Tt,{title:`Delete Link`,message:`Are you sure you want to delete "${m.name}"? This action cannot be undone.`,confirmText:`Delete`,cancelText:`Cancel`,variant:`danger`,onConfirm:ne,onCancel:()=>h(null)})]})}async function _i(e){if(navigator.clipboard&&window.isSecureContext)try{return await navigator.clipboard.writeText(e),!0}catch{}let t=document.createElement(`textarea`);t.value=e,t.style.position=`fixed`,t.style.opacity=`0`,document.body.appendChild(t);try{return t.select(),document.execCommand(`copy`)}catch{return!1}finally{t.parentNode&&t.parentNode.removeChild(t)}}function vi(e,t,n=`text/plain`){let r=new Blob([e],{type:n}),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=t,document.body.appendChild(a),a.click(),a.remove(),URL.revokeObjectURL(i)}function yi({status:e}){return e===`pass`?(0,Y.jsx)(q,{className:`w-5 h-5 text-bambu-green flex-shrink-0`}):e===`fail`?(0,Y.jsx)(O,{className:`w-5 h-5 text-red-600 dark:text-red-400 flex-shrink-0`}):e===`warn`?(0,Y.jsx)(Ie,{className:`w-5 h-5 text-amber-600 dark:text-amber-400 flex-shrink-0`}):(0,Y.jsx)(Ut,{className:`w-5 h-5 text-bambu-gray flex-shrink-0`})}function bi({vpId:e,vpName:t,onClose:n}){let{t:r}=l(),i=f({mutationFn:()=>a.diagnose(e)});(0,X.useEffect)(()=>{i.mutate()},[]),(0,X.useEffect)(()=>{let e=e=>{e.key===`Escape`&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n]);let o=i.data,s=o?.overall===`ok`?`bg-bambu-green/10 border-bambu-green/30 text-bambu-green`:o?.overall===`warnings`?`bg-amber-50 dark:bg-amber-500/10 border-amber-300 dark:border-amber-500/30 text-amber-700 dark:text-amber-300`:`bg-red-50 dark:bg-red-500/10 border-red-300 dark:border-red-500/30 text-red-700 dark:text-red-300`;return(0,Y.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:n,children:(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-lg flex flex-col max-h-[85vh]`,onClick:e=>e.stopPropagation(),children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,Y.jsx)(et,{className:`w-5 h-5 text-bambu-green flex-shrink-0`}),(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white truncate`,children:r(`vpDiagnostic.title`,{name:t})})]}),(0,Y.jsx)(`button`,{onClick:n,className:`text-bambu-gray hover:text-white transition-colors`,title:r(`common.close`),children:(0,Y.jsx)(Re,{className:`w-5 h-5`})})]}),(0,Y.jsxs)(`div`,{className:`p-6 space-y-4 overflow-y-auto`,children:[i.isPending&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray`,children:[(0,Y.jsx)(R,{className:`w-4 h-4 animate-spin`}),(0,Y.jsx)(`span`,{children:r(`vpDiagnostic.running`)})]}),i.isError&&(0,Y.jsx)(`div`,{className:`rounded-lg bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30 px-4 py-3 text-sm text-red-700 dark:text-red-300`,children:r(`vpDiagnostic.runFailed`,{error:i.error.message})}),o&&(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[(0,Y.jsx)(`ol`,{className:`space-y-2`,children:o.checks.map(e=>{let t=r(`vpDiagnostic.check.${e.id}.${e.status}`,{...e.params,defaultValue:``});return(0,Y.jsxs)(`li`,{className:`flex items-start gap-3 bg-bambu-dark rounded-lg px-4 py-2.5 ${e.status===`skip`?`opacity-60`:``}`,children:[(0,Y.jsx)(`div`,{className:`mt-0.5`,children:(0,Y.jsx)(yi,{status:e.status})}),(0,Y.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Y.jsx)(`div`,{className:`text-sm text-white`,children:r(`vpDiagnostic.check.${e.id}.title`,e.params)}),t&&(0,Y.jsx)(`div`,{className:`text-xs text-bambu-gray mt-0.5`,children:t})]})]},e.id)})}),(0,Y.jsx)(`div`,{className:`rounded-lg border px-4 py-3 text-sm ${s}`,children:r(`vpDiagnostic.overall.${o.overall}`)})]})]}),(0,Y.jsxs)(`div`,{className:`px-6 py-4 border-t border-bambu-dark-tertiary flex justify-end gap-2`,children:[(0,Y.jsx)(`button`,{onClick:()=>i.mutate(),disabled:i.isPending,className:`px-4 py-2 bg-bambu-dark hover:bg-bambu-dark-tertiary disabled:opacity-50 text-white text-sm rounded-lg transition-colors`,children:r(`vpDiagnostic.retry`)}),(0,Y.jsx)(`button`,{onClick:n,className:`px-4 py-2 bg-bambu-green hover:bg-bambu-green/90 text-white text-sm rounded-lg transition-colors`,children:r(`common.close`)})]})]})})}var xi={archive:`archive`,review:`review`,queue:`queue`,proxy:`proxy`};function Si(e){return e===`immediate`?`archive`:e===`print_queue`||e===`queue`?`queue`:e===`archive`||e===`review`||e===`proxy`?e:`archive`}function Ci({printer:e,models:t}){let{t:n}=l(),i=u(),{showToast:o}=ee(),[s,c]=(0,X.useState)(!0),[p,m]=(0,X.useState)(e.enabled),[h,g]=(0,X.useState)(e.name),[_,v]=(0,X.useState)(``),[y,b]=(0,X.useState)(Si(e.mode)),[x,S]=(0,X.useState)(e.target_printer_id),[C,w]=(0,X.useState)(e.bind_ip||``),[D,O]=(0,X.useState)(e.remote_interface_ip||``),[k,j]=(0,X.useState)(e.model||``),[M,P]=(0,X.useState)(e.auto_dispatch??!0),[te,ne]=(0,X.useState)(e.queue_force_color_match??!1),[I,re]=(0,X.useState)(e.save_ams_mapping??!1),[ie,L]=(0,X.useState)(e.gcode_injection??!1),[ae,z]=(0,X.useState)(e.tailscale_disabled??!0),[oe,se]=(0,X.useState)(!1),[B,ce]=(0,X.useState)(null),[le,ue]=(0,X.useState)(!1),[de,fe]=(0,X.useState)(!1),[V,pe]=(0,X.useState)(!1),{data:me}=d({queryKey:[`tailscale-status`],queryFn:a.getTailscaleStatus,enabled:!ae,staleTime:6e4}),he=me?.available?me.fqdn:``,ge=me?.available?me.tailscale_ips?.[0]??``:``,_e=async e=>{e.stopPropagation();let t=he;t&&(await _i(t)?(pe(!0),o(n(`printers.copied`)),setTimeout(()=>pe(!1),2e3)):o(n(`virtualPrinter.toast.copyFailed`),`error`))};(0,X.useEffect)(()=>{B||(m(e.enabled),b(Si(e.mode)),g(e.name),S(e.target_printer_id),w(e.bind_ip||``),O(e.remote_interface_ip||``),j(e.model||``),P(e.auto_dispatch??!0),ne(e.queue_force_color_match??!1),re(e.save_ams_mapping??!1),L(e.gcode_injection??!1),z(e.tailscale_disabled??!0))},[e,B]);let{data:ve}=d({queryKey:[`printers`],queryFn:r.getPrinters}),{data:ye}=d({queryKey:[`network-interfaces`],queryFn:()=>r.getNetworkInterfaces().then(e=>e.interfaces)}),be=f({mutationFn:t=>a.update(e.id,t),onSuccess:()=>{i.invalidateQueries({queryKey:[`virtual-printers`]}),o(n(`virtualPrinter.toast.updated`)),ce(null)},onError:t=>{o(t.message||n(`virtualPrinter.toast.failedToUpdate`),`error`),m(e.enabled),b(Si(e.mode)),S(e.target_printer_id),w(e.bind_ip||``),z(e.tailscale_disabled??!0),ne(e.queue_force_color_match??!1),re(e.save_ams_mapping??!1),L(e.gcode_injection??!1),ce(null)}}),H=f({mutationFn:()=>a.remove(e.id),onSuccess:()=>{i.invalidateQueries({queryKey:[`virtual-printers`]}),o(n(`virtualPrinter.toast.deleted`)),ue(!1)},onError:e=>{o(e.message||n(`virtualPrinter.toast.failedToDelete`),`error`),ue(!1)}}),xe=t=>{t.stopPropagation();let r=!p;if(r){if(!C){o(n(`virtualPrinter.toast.bindIpRequired`),`error`);return}if(y===`proxy`){if(!x){o(n(`virtualPrinter.toast.targetPrinterRequired`),`error`);return}}else if(!_&&!e.access_code_set){o(n(`virtualPrinter.toast.accessCodeRequired`),`error`);return}}m(r),ce(`toggle`),be.mutate({enabled:r})},Se=()=>{h.trim()&&(ce(`name`),be.mutate({name:h.trim()}))},Ce=()=>{if(!_){o(n(`virtualPrinter.toast.accessCodeEmpty`),`error`);return}if(_.length!==8){o(n(`virtualPrinter.toast.accessCodeLength`),`error`);return}ce(`accessCode`),be.mutate({access_code:_}),v(``)},we=e=>{b(e),ce(`mode`),be.mutate({mode:e})},Te=e=>{j(e),ce(`model`),be.mutate({model:e})},Ee=e=>{let t=Ae?.access_code,r=ve?.find(t=>t.id===e)?.access_code;S(e),ce(`targetPrinter`),be.mutate({target_printer_id:e},{onSuccess:()=>{t&&r&&t!==r&&o(n(`virtualPrinter.toast.targetCodeChangedRebind`),`info`)}})},De=e=>{O(e),ce(`remoteInterface`),be.mutate({remote_interface_ip:e})},Oe=e.status?.running||!1,ke=n(`virtualPrinter.mode.${xi[y]||`archive`}`),Ae=ve?.find(e=>e.id===x),je=Ae?.name,Me=!!x,Ne=Me?Ae?.access_code??``:``;return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(G,{className:`overflow-hidden`,children:[(0,Y.jsxs)(`div`,{className:`px-4 py-3 flex items-center gap-3 cursor-pointer select-none`,onClick:()=>c(!s),children:[(0,Y.jsx)(`button`,{className:`text-bambu-gray flex-shrink-0`,children:s?(0,Y.jsx)(E,{className:`w-4 h-4`}):(0,Y.jsx)(st,{className:`w-4 h-4`})}),(0,Y.jsx)(`span`,{className:`w-2 h-2 rounded-full flex-shrink-0 ${Oe?`bg-green-400 animate-pulse`:`bg-gray-500`}`}),(0,Y.jsxs)(`div`,{className:`flex-1 min-w-0 flex flex-wrap items-center gap-x-3 gap-y-1`,children:[(0,Y.jsx)(`span`,{className:`text-white font-medium truncate max-w-full`,children:e.name}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray flex-shrink-0`,children:ke}),e.model_name&&(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray flex-shrink-0`,children:e.model_name}),je&&(0,Y.jsxs)(`span`,{className:`text-xs text-bambu-gray truncate max-w-full`,children:[y===`proxy`&&(0,Y.jsx)(_n,{className:`w-3 h-3 inline mr-1`}),je]}),C&&(0,Y.jsx)(`span`,{className:`text-[10px] text-bambu-gray flex-shrink-0 font-mono`,children:C}),D&&(0,Y.jsx)(`span`,{className:`text-[10px] text-bambu-gray flex-shrink-0 font-mono`,children:D})]}),(0,Y.jsx)(`div`,{className:`ml-auto flex items-center gap-2 flex-shrink-0`,onClick:e=>e.stopPropagation(),children:(0,Y.jsx)(`button`,{onClick:xe,disabled:B===`toggle`,className:`relative w-10 h-5 rounded-full transition-colors ${p?`bg-bambu-green`:`bg-bambu-dark-tertiary`} ${B===`toggle`?`opacity-50`:``}`,children:(0,Y.jsx)(`span`,{className:`absolute top-0.5 left-0.5 w-4 h-4 bg-white rounded-full transition-transform ${p?`translate-x-5`:``}`})})})]}),s&&(0,Y.jsxs)(W,{className:`pt-0 space-y-4`,children:[(0,Y.jsx)(`div`,{className:`border-t border-bambu-dark-tertiary`}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`input`,{type:`text`,value:h,onChange:e=>g(e.target.value),onBlur:Se,onKeyDown:e=>e.key===`Enter`&&Se(),className:`flex-1 text-sm text-white bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-1.5 focus:border-bambu-green focus:outline-none`}),(0,Y.jsx)(`button`,{onClick:()=>fe(!0),className:`p-1.5 text-bambu-gray hover:text-bambu-green transition-colors flex-shrink-0`,title:n(`vpDiagnostic.runButton`),children:(0,Y.jsx)(et,{className:`w-4 h-4`})}),(0,Y.jsx)(`button`,{onClick:()=>ue(!0),className:`p-1.5 text-bambu-gray hover:text-red-600 dark:hover:text-red-400 transition-colors flex-shrink-0`,title:n(`common.delete`),children:(0,Y.jsx)(qe,{className:`w-4 h-4`})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 -mt-2`,children:[he&&(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 text-green-700/80 dark:text-green-400/70 min-w-0`,children:[(0,Y.jsx)(Cn,{className:`w-3.5 h-3.5 flex-shrink-0`}),(0,Y.jsx)(`span`,{className:`font-mono text-xs truncate`,children:ge?`${ge} (${he})`:he}),(0,Y.jsx)(`button`,{onClick:_e,className:`p-0.5 rounded hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white transition-colors flex-shrink-0`,title:n(V?`printers.copied`:`printers.copyToClipboard`),children:V?(0,Y.jsx)(T,{className:`w-3.5 h-3.5 text-bambu-green`}):(0,Y.jsx)(N,{className:`w-3.5 h-3.5`})})]}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray font-mono ml-auto flex-shrink-0`,children:e.serial})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`text-white text-sm font-medium mb-2`,children:n(`virtualPrinter.mode.title`)}),(0,Y.jsx)(`div`,{className:`grid grid-cols-2 gap-2`,children:[`archive`,`review`,`queue`,`proxy`].map(e=>(0,Y.jsxs)(`button`,{onClick:()=>we(e),disabled:B===`mode`,className:`p-2 rounded-lg border text-left transition-colors ${y===e?e===`proxy`?`border-blue-500 bg-blue-500/10`:`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 text-white text-xs font-medium`,children:[e===`proxy`&&(0,Y.jsx)(_n,{className:`w-3 h-3`}),n(`virtualPrinter.mode.${xi[e]}`)]}),(0,Y.jsx)(`div`,{className:`text-[10px] text-bambu-gray`,children:n(`virtualPrinter.mode.${xi[e]}Desc`)})]},e))})]}),y===`queue`&&(0,Y.jsx)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,Y.jsxs)(`div`,{className:`min-w-0`,children:[(0,Y.jsx)(`div`,{className:`text-white text-sm font-medium`,children:n(`virtualPrinter.autoDispatch.title`)}),(0,Y.jsx)(`div`,{className:`text-[10px] text-bambu-gray`,children:n(`virtualPrinter.autoDispatch.description`)})]}),(0,Y.jsx)(`button`,{onClick:()=>{let e=!M;P(e),ce(`autoDispatch`),be.mutate({auto_dispatch:e})},disabled:B===`autoDispatch`,className:`relative w-10 h-5 rounded-full transition-colors flex-shrink-0 ${M?`bg-bambu-green`:`bg-bambu-dark-tertiary`} ${B===`autoDispatch`?`opacity-50`:``}`,children:(0,Y.jsx)(`span`,{className:`absolute top-0.5 left-0.5 w-4 h-4 bg-white rounded-full transition-transform ${M?`translate-x-5`:``}`})})]})}),y===`queue`&&(0,Y.jsx)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,Y.jsxs)(`div`,{className:`min-w-0`,children:[(0,Y.jsx)(`div`,{className:`text-white text-sm font-medium`,children:n(`virtualPrinter.queueForceColorMatch.title`)}),(0,Y.jsx)(`div`,{className:`text-[10px] text-bambu-gray`,children:n(`virtualPrinter.queueForceColorMatch.description`)})]}),(0,Y.jsx)(`button`,{onClick:()=>{let e=!te;ne(e),ce(`queueForceColorMatch`),be.mutate({queue_force_color_match:e})},disabled:B===`queueForceColorMatch`,className:`relative w-10 h-5 rounded-full transition-colors flex-shrink-0 ${te?`bg-bambu-green`:`bg-bambu-dark-tertiary`} ${B===`queueForceColorMatch`?`opacity-50`:``}`,children:(0,Y.jsx)(`span`,{className:`absolute top-0.5 left-0.5 w-4 h-4 bg-white rounded-full transition-transform ${te?`translate-x-5`:``}`})})]})}),y===`queue`&&(0,Y.jsx)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,Y.jsxs)(`div`,{className:`min-w-0`,children:[(0,Y.jsx)(`div`,{className:`text-white text-sm font-medium`,children:n(`virtualPrinter.saveAmsMapping.title`)}),(0,Y.jsx)(`div`,{className:`text-[10px] text-bambu-gray`,children:n(`virtualPrinter.saveAmsMapping.description`)})]}),(0,Y.jsx)(`button`,{onClick:()=>{let e=!I;re(e),ce(`saveAmsMapping`),be.mutate({save_ams_mapping:e})},disabled:B===`saveAmsMapping`,className:`relative w-10 h-5 rounded-full transition-colors flex-shrink-0 ${I?`bg-bambu-green`:`bg-bambu-dark-tertiary`} ${B===`saveAmsMapping`?`opacity-50`:``}`,children:(0,Y.jsx)(`span`,{className:`absolute top-0.5 left-0.5 w-4 h-4 bg-white rounded-full transition-transform ${I?`translate-x-5`:``}`})})]})}),y===`queue`&&(0,Y.jsx)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,Y.jsxs)(`div`,{className:`min-w-0`,children:[(0,Y.jsx)(`div`,{className:`text-white text-sm font-medium`,children:n(`virtualPrinter.gcodeInjection.title`)}),(0,Y.jsx)(`div`,{className:`text-[10px] text-bambu-gray`,children:n(`virtualPrinter.gcodeInjection.description`)})]}),(0,Y.jsx)(`button`,{onClick:()=>{let e=!ie;L(e),ce(`gcodeInjection`),be.mutate({gcode_injection:e})},disabled:B===`gcodeInjection`,className:`relative w-10 h-5 rounded-full transition-colors flex-shrink-0 ${ie?`bg-bambu-green`:`bg-bambu-dark-tertiary`} ${B===`gcodeInjection`?`opacity-50`:``}`,children:(0,Y.jsx)(`span`,{className:`absolute top-0.5 left-0.5 w-4 h-4 bg-white rounded-full transition-transform ${ie?`translate-x-5`:``}`})})]})}),(0,Y.jsx)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,Y.jsxs)(`div`,{className:`min-w-0`,children:[(0,Y.jsx)(`div`,{className:`text-white text-sm font-medium`,children:n(`virtualPrinter.tailscaleDisabled.title`)}),(0,Y.jsx)(`div`,{className:`text-[10px] text-bambu-gray`,children:n(`virtualPrinter.tailscaleDisabled.description`)})]}),(0,Y.jsx)(`button`,{onClick:()=>{let e=!ae;z(e),ce(`tailscaleDisabled`),be.mutate({tailscale_disabled:e})},disabled:B===`tailscaleDisabled`,className:`relative w-10 h-5 rounded-full transition-colors shrink-0 ${ae?`bg-bambu-dark-tertiary`:`bg-bambu-green`} ${B===`tailscaleDisabled`?`opacity-50`:``}`,children:(0,Y.jsx)(`span`,{className:`absolute top-0.5 left-0.5 w-4 h-4 bg-white rounded-full transition-transform ${ae?``:`translate-x-5`}`})})]})}),y!==`proxy`&&(0,Y.jsxs)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:[(0,Y.jsx)(`div`,{className:`text-white text-sm font-medium mb-1`,children:n(`virtualPrinter.model.title`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:n(`virtualPrinter.model.description`)}),(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsx)(`select`,{value:k,onChange:e=>Te(e.target.value),disabled:B===`model`,className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-1.5 text-white text-sm appearance-none cursor-pointer disabled:opacity-50 pr-10`,children:Object.entries(t).map(([e,t])=>(0,Y.jsxs)(`option`,{value:e,children:[t,` (`,e,`)`]},e))}),(0,Y.jsx)(E,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]})]}),y===`proxy`&&(0,Y.jsx)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:(0,Y.jsxs)(`div`,{className:`flex items-start gap-2 p-2 rounded bg-blue-50 border border-blue-300 dark:bg-blue-500/10 dark:border-blue-500/30`,children:[(0,Y.jsx)(A,{className:`w-4 h-4 text-blue-600 dark:text-blue-400 flex-shrink-0 mt-0.5`}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`virtualPrinter.proxy.accessCodeHint`)})]})}),y!==`proxy`&&(0,Y.jsxs)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,Y.jsx)(`div`,{className:`text-white text-sm font-medium`,children:n(`virtualPrinter.accessCode.title`)}),Me?(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 text-xs text-blue-700 dark:text-blue-400`,children:[(0,Y.jsx)(A,{className:`w-3 h-3`}),n(`virtualPrinter.accessCode.inheritedFromTarget`)]}):e.access_code_set?(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 text-xs text-green-700 dark:text-green-400`,children:[(0,Y.jsx)(T,{className:`w-3 h-3`}),n(`virtualPrinter.accessCode.isSet`)]}):(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 text-xs text-yellow-700 dark:text-yellow-400`,children:[(0,Y.jsx)(Ie,{className:`w-3 h-3`}),n(`virtualPrinter.accessCode.notSet`)]})]}),Me?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsx)(`input`,{type:oe?`text`:`password`,value:Ne,readOnly:!0,"aria-label":n(`virtualPrinter.accessCode.title`),className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-1.5 text-white text-sm pr-10 font-mono opacity-90 cursor-default`}),(0,Y.jsx)(`button`,{onClick:()=>se(!oe),className:`absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white`,"aria-label":n(oe?`virtualPrinter.accessCode.hide`:`virtualPrinter.accessCode.reveal`),children:oe?(0,Y.jsx)(F,{className:`w-4 h-4`}):(0,Y.jsx)(mt,{className:`w-4 h-4`})})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(`virtualPrinter.accessCode.derivedFromTargetHint`)})]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Y.jsxs)(`div`,{className:`relative flex-1`,children:[(0,Y.jsx)(`input`,{type:oe?`text`:`password`,value:_,onChange:e=>v(e.target.value),placeholder:e.access_code_set?n(`virtualPrinter.accessCode.placeholderChange`):n(`virtualPrinter.accessCode.placeholder`),maxLength:8,className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-1.5 text-white text-sm placeholder-bambu-gray pr-10 font-mono`}),(0,Y.jsx)(`button`,{onClick:()=>se(!oe),className:`absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white`,children:oe?(0,Y.jsx)(F,{className:`w-4 h-4`}):(0,Y.jsx)(mt,{className:`w-4 h-4`})})]}),(0,Y.jsx)(K,{onClick:Ce,disabled:!_||B===`accessCode`,variant:`primary`,children:B===`accessCode`?(0,Y.jsx)(R,{className:`w-4 h-4 animate-spin`}):n(`common.save`)})]}),_&&(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:(0,Y.jsx)(`span`,{className:_.length===8?`text-green-700 dark:text-green-400`:`text-yellow-700 dark:text-yellow-400`,children:n(`virtualPrinter.accessCode.charCount`,{count:_.length})})})]})]}),(0,Y.jsxs)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:[(0,Y.jsx)(`div`,{className:`text-white text-sm font-medium mb-2`,children:n(`virtualPrinter.targetPrinter.title`)}),(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsxs)(`select`,{value:x??``,onChange:e=>{let t=parseInt(e.target.value,10);isNaN(t)||Ee(t)},disabled:B===`targetPrinter`,className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-1.5 text-white text-sm appearance-none cursor-pointer disabled:opacity-50 pr-10`,children:[(0,Y.jsx)(`option`,{value:``,children:n(`virtualPrinter.targetPrinter.placeholder`)}),ve?.map(e=>(0,Y.jsxs)(`option`,{value:e.id,children:[e.name,` (`,e.ip_address,`)`]},e.id))]}),(0,Y.jsx)(E,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]})]}),(0,Y.jsxs)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:[(0,Y.jsx)(`div`,{className:`text-white text-sm font-medium mb-1`,children:n(`virtualPrinter.bindIp.title`)}),(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsxs)(`select`,{value:C,onChange:e=>{w(e.target.value),ce(`bindIp`),be.mutate({bind_ip:e.target.value})},disabled:B===`bindIp`,className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-1.5 text-white text-sm appearance-none cursor-pointer disabled:opacity-50 pr-10`,children:[(0,Y.jsx)(`option`,{value:``,children:n(`virtualPrinter.bindIp.placeholder`)}),ye?.map(e=>(0,Y.jsxs)(`option`,{value:e.ip,children:[e.name,` (`,e.ip,`)`,e.is_alias?` [alias]`:``,` - `,e.subnet]},e.ip))]}),(0,Y.jsx)(E,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(`virtualPrinter.bindIp.hint`)})]}),(0,Y.jsxs)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,Y.jsx)(`div`,{className:`text-white text-sm font-medium`,children:n(`virtualPrinter.remoteInterface.title`)}),D?(0,Y.jsx)(`span`,{className:`flex items-center gap-1 text-xs text-green-700 dark:text-green-400`,children:(0,Y.jsx)(T,{className:`w-3 h-3`})}):(0,Y.jsx)(`span`,{className:`flex items-center gap-1 text-xs text-bambu-gray`,title:n(`virtualPrinter.remoteInterface.optional`),children:(0,Y.jsx)(A,{className:`w-3 h-3`})})]}),(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsxs)(`select`,{value:D,onChange:e=>De(e.target.value),disabled:B===`remoteInterface`,className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-1.5 text-white text-sm appearance-none cursor-pointer disabled:opacity-50 pr-10`,children:[(0,Y.jsx)(`option`,{value:``,children:n(`virtualPrinter.remoteInterface.placeholder`)}),ye?.map(e=>(0,Y.jsxs)(`option`,{value:e.ip,children:[e.name,` (`,e.ip,`) - `,e.subnet]},e.ip))]}),(0,Y.jsx)(E,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]})]})]})]}),le&&(0,Y.jsx)(Tt,{title:n(`virtualPrinter.deleteConfirm.title`),message:n(`virtualPrinter.deleteConfirm.message`,{name:e.name}),variant:`danger`,confirmText:n(`common.delete`),isLoading:H.isPending,onConfirm:()=>H.mutate(),onCancel:()=>ue(!1)}),de&&(0,Y.jsx)(bi,{vpId:e.id,vpName:e.name,onClose:()=>fe(!1)})]})}var wi={archive:`archive`,review:`review`,queue:`queue`,proxy:`proxy`};function Ti({onClose:e}){let{t}=l(),n=u(),{showToast:i}=ee(),[o,s]=(0,X.useState)(``),[c,p]=(0,X.useState)(`archive`),[m,h]=(0,X.useState)(null),{data:g}=d({queryKey:[`printers`],queryFn:r.getPrinters}),_=f({mutationFn:()=>a.create({name:o.trim()||`Bambuddy`,mode:c,target_printer_id:c===`proxy`?m??void 0:void 0}),onSuccess:()=>{n.invalidateQueries({queryKey:[`virtual-printers`]}),i(t(`virtualPrinter.toast.created`)),e()},onError:e=>{i(e.message||t(`virtualPrinter.toast.failedToCreate`),`error`)}});return(0,Y.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,onClick:e,children:(0,Y.jsx)(G,{className:`w-full max-w-md`,onClick:e=>e.stopPropagation(),children:(0,Y.jsxs)(W,{className:`p-6 space-y-4`,children:[(0,Y.jsx)(`h3`,{className:`text-lg font-semibold text-white`,children:t(`virtualPrinter.addDialog.title`)}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`text-sm text-white font-medium block mb-1`,children:t(`virtualPrinter.addDialog.name`)}),(0,Y.jsx)(`input`,{type:`text`,value:o,onChange:e=>s(e.target.value),placeholder:`Bambuddy`,className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-2 text-white text-sm placeholder-bambu-gray`,autoFocus:!0})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`text-sm text-white font-medium block mb-1`,children:t(`virtualPrinter.mode.title`)}),(0,Y.jsx)(`div`,{className:`grid grid-cols-2 gap-2`,children:[`archive`,`review`,`queue`,`proxy`].map(e=>(0,Y.jsxs)(`button`,{onClick:()=>p(e),className:`p-2 rounded-lg border text-left transition-colors ${c===e?e===`proxy`?`border-blue-500 bg-blue-500/10`:`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 text-white text-xs font-medium`,children:[e===`proxy`&&(0,Y.jsx)(_n,{className:`w-3 h-3`}),t(`virtualPrinter.mode.${wi[e]}`)]}),(0,Y.jsx)(`div`,{className:`text-[10px] text-bambu-gray`,children:t(`virtualPrinter.mode.${wi[e]}Desc`)})]},e))})]}),c===`proxy`&&(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`text-sm text-white font-medium block mb-1`,children:t(`virtualPrinter.targetPrinter.title`)}),(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsxs)(`select`,{value:m??``,onChange:e=>{let t=parseInt(e.target.value,10);h(isNaN(t)?null:t)},className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-2 text-white text-sm appearance-none cursor-pointer pr-10`,children:[(0,Y.jsx)(`option`,{value:``,children:t(`virtualPrinter.targetPrinter.placeholder`)}),g?.map(e=>(0,Y.jsxs)(`option`,{value:e.id,children:[e.name,` (`,e.ip_address,`)`]},e.id))]}),(0,Y.jsx)(E,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:t(`virtualPrinter.addDialog.hint`)}),(0,Y.jsxs)(`div`,{className:`flex gap-3 pt-2`,children:[(0,Y.jsx)(K,{variant:`secondary`,onClick:e,className:`flex-1`,disabled:_.isPending,children:t(`common.cancel`)}),(0,Y.jsx)(K,{variant:`primary`,onClick:()=>_.mutate(),className:`flex-1`,disabled:_.isPending,children:_.isPending?(0,Y.jsx)(R,{className:`w-4 h-4 animate-spin`}):t(`virtualPrinter.addDialog.create`)})]})]})})})}function Ei(){let{t:e}=l(),t=u(),{showToast:n}=ee(),[r,o]=(0,X.useState)(!1),{data:s,isLoading:c}=d({queryKey:[`virtual-printers`],queryFn:a.list,refetchInterval:1e4}),{data:p}=d({queryKey:[`virtual-printer-settings`],queryFn:i.getSettings}),m=f({mutationFn:e=>i.updateSettings({archive_name_source:e}),onSuccess:()=>{t.invalidateQueries({queryKey:[`virtual-printer-settings`]}),n(e(`virtualPrinter.toast.updated`))},onError:t=>{n(t.message||e(`virtualPrinter.toast.failedToUpdate`),`error`)}}),h=p?.archive_name_source===`filename`,{data:g}=d({queryKey:[`vp-ca-certificate`],queryFn:a.getCaCertificate,staleTime:1/0}),[_,v]=(0,X.useState)(!1),y=async()=>{g&&(await _i(g.pem)?(v(!0),n(e(`virtualPrinter.caCert.copied`)),setTimeout(()=>v(!1),2e3)):n(e(`virtualPrinter.toast.copyFailed`),`error`))},b=()=>{g&&vi(g.pem,`bambuddy-virtual-printer-ca.crt`,`application/x-pem-file`)};if(c)return(0,Y.jsx)(G,{children:(0,Y.jsx)(W,{className:`py-8 flex justify-center`,children:(0,Y.jsx)(R,{className:`w-6 h-6 animate-spin text-bambu-green`})})});let x=s?.printers||[],S=s?.models||{};return(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-3 gap-4 items-stretch`,children:[(0,Y.jsx)(G,{className:`border-l-4 border-l-yellow-500`,children:(0,Y.jsx)(W,{className:`py-3 px-4`,children:(0,Y.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Y.jsx)(Ie,{className:`w-4 h-4 text-yellow-500 flex-shrink-0 mt-0.5`}),(0,Y.jsxs)(`div`,{className:`text-xs`,children:[(0,Y.jsx)(`p`,{className:`text-white font-medium`,children:e(`virtualPrinter.setupRequired.title`)}),(0,Y.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:e(`virtualPrinter.setupRequired.description`)}),(0,Y.jsxs)(`a`,{href:`https://wiki.bambuddy.cool/features/virtual-printer/`,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-1.5 mt-2 px-3 py-1.5 bg-yellow-100 dark:bg-yellow-500/20 border border-yellow-500/50 rounded text-yellow-700 dark:text-yellow-400 hover:bg-yellow-500/30 transition-colors text-xs`,children:[(0,Y.jsx)(Je,{className:`w-3 h-3`}),e(`virtualPrinter.setupRequired.readGuide`)]})]})]})})}),(0,Y.jsx)(G,{className:`lg:col-span-2`,children:(0,Y.jsx)(W,{className:`py-3 px-4`,children:(0,Y.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Y.jsx)(A,{className:`w-4 h-4 text-blue-600 dark:text-blue-400 flex-shrink-0 mt-0.5`}),(0,Y.jsxs)(`div`,{className:`text-xs text-bambu-gray`,children:[(0,Y.jsx)(`p`,{className:`text-white font-medium mb-1`,children:e(`virtualPrinter.howItWorks.title`)}),(0,Y.jsxs)(`ul`,{className:`space-y-1 list-disc list-inside`,children:[(0,Y.jsx)(`li`,{children:e(`virtualPrinter.howItWorks.step1`)}),(0,Y.jsx)(`li`,{children:e(`virtualPrinter.howItWorks.step2`)}),(0,Y.jsx)(`li`,{children:e(`virtualPrinter.howItWorks.step3`)})]})]})]})})})]}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-4 items-stretch`,children:[(0,Y.jsx)(G,{children:(0,Y.jsx)(W,{className:`py-3 px-4`,children:(0,Y.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,Y.jsx)(Cn,{className:`w-4 h-4 text-bambu-green flex-shrink-0 mt-1`}),(0,Y.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-white font-medium`,children:e(`virtualPrinter.caCert.title`)}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[(0,Y.jsxs)(`button`,{onClick:y,disabled:!g,className:`inline-flex items-center gap-1.5 px-2.5 py-1 text-xs rounded bg-bambu-dark-secondary border border-bambu-dark-tertiary text-white hover:border-bambu-gray disabled:opacity-50 transition-colors`,children:[_?(0,Y.jsx)(T,{className:`w-3.5 h-3.5 text-bambu-green`}):(0,Y.jsx)(N,{className:`w-3.5 h-3.5`}),e(_?`virtualPrinter.caCert.copied`:`virtualPrinter.caCert.copy`)]}),(0,Y.jsxs)(`button`,{onClick:b,disabled:!g,className:`inline-flex items-center gap-1.5 px-2.5 py-1 text-xs rounded bg-bambu-dark-secondary border border-bambu-dark-tertiary text-white hover:border-bambu-gray disabled:opacity-50 transition-colors`,children:[(0,Y.jsx)(sn,{className:`w-3.5 h-3.5`}),e(`virtualPrinter.caCert.download`)]})]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`virtualPrinter.caCert.description`)}),g&&(0,Y.jsxs)(`p`,{className:`text-[10px] text-bambu-gray font-mono mt-1 truncate`,title:g.fingerprint_sha256,children:[e(`virtualPrinter.caCert.fingerprint`),`: `,g.fingerprint_sha256]})]})]})})}),(0,Y.jsx)(G,{children:(0,Y.jsx)(W,{className:`py-3 px-4`,children:(0,Y.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,Y.jsx)(ln,{className:`w-4 h-4 text-bambu-green flex-shrink-0 mt-1`}),(0,Y.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-white font-medium`,children:e(`virtualPrinter.archiveNameSource.title`)}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[(0,Y.jsx)(`span`,{className:`text-xs ${h?`text-bambu-gray`:`text-white`}`,children:e(`virtualPrinter.archiveNameSource.metadata`)}),(0,Y.jsx)(J,{checked:h,onChange:e=>m.mutate(e?`filename`:`metadata`),disabled:m.isPending}),(0,Y.jsx)(`span`,{className:`text-xs ${h?`text-white`:`text-bambu-gray`}`,children:e(`virtualPrinter.archiveNameSource.filename`)})]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`virtualPrinter.archiveNameSource.description`)})]})]})})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(it,{className:`w-5 h-5 text-bambu-green`}),(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`virtualPrinter.list.title`)}),(0,Y.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[`(`,x.length,`)`]})]}),(0,Y.jsxs)(K,{variant:`primary`,onClick:()=>o(!0),children:[(0,Y.jsx)(wt,{className:`w-4 h-4 mr-1`}),e(`virtualPrinter.list.add`)]})]}),x.length===0?(0,Y.jsx)(G,{children:(0,Y.jsxs)(W,{className:`py-8 text-center`,children:[(0,Y.jsx)(it,{className:`w-12 h-12 text-bambu-gray mx-auto mb-3`}),(0,Y.jsx)(`p`,{className:`text-bambu-gray mb-4`,children:e(`virtualPrinter.list.empty`)}),(0,Y.jsxs)(K,{variant:`primary`,onClick:()=>o(!0),children:[(0,Y.jsx)(wt,{className:`w-4 h-4 mr-1`}),e(`virtualPrinter.list.addFirst`)]})]})}):(0,Y.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-4 items-start`,children:x.map(e=>(0,Y.jsx)(Ci,{printer:e,models:S},e.id))}),r&&(0,Y.jsx)(Ti,{onClose:()=>o(!1)})]})}function Di(e){if(e<60)return`${e}s`;let t=Math.floor(e/60);if(t<60)return`${t}m`;let n=Math.floor(t/60),r=t%60;if(n<24)return r?`${n}h ${r}m`:`${n}h`;let i=Math.floor(n/24),a=n%24;return a?`${i}d ${a}h`:`${i}d`}function Oi(e){return e==null?`—`:e>=1024?`${(e/1024).toFixed(1)} GB`:`${Math.round(e)} MB`}function ki({device:e,onUnregister:t,isDeleting:n}){let{t:r}=l(),{showToast:i}=ee(),a=e.system_stats,o=a?.memory,s=a?.disk,u=e.online,[d,f]=(0,X.useState)(null),[p,m]=(0,X.useState)(null),h=async t=>{m(t);try{t===`update`?await c.triggerUpdate(e.device_id):await c.systemCommand(e.device_id,t),i(r(`settings.spoolbuddy.commandQueued`),`success`)}catch(e){i(e instanceof Error?e.message:r(`settings.spoolbuddy.commandError`),`error`)}finally{m(null),f(null)}},g=[{key:`update`,label:r(`settings.spoolbuddy.update`),icon:sn},{key:`restart_browser`,label:r(`settings.spoolbuddy.restartBrowser`),icon:tn},{key:`restart_daemon`,label:r(`settings.spoolbuddy.restartDaemon`),icon:at},{key:`reboot`,label:r(`settings.spoolbuddy.reboot`),icon:xt},{key:`shutdown`,label:r(`settings.spoolbuddy.shutdown`),icon:Ct,variant:`danger`}],_={update:r(`settings.spoolbuddy.updateConfirmTitle`),restart_browser:r(`settings.spoolbuddy.restartBrowserConfirmTitle`),restart_daemon:r(`settings.spoolbuddy.restartDaemonConfirmTitle`),reboot:r(`settings.spoolbuddy.rebootConfirmTitle`),shutdown:r(`settings.spoolbuddy.shutdownConfirmTitle`)},v={update:r(`settings.spoolbuddy.updateConfirmBody`,{hostname:e.hostname}),restart_browser:r(`settings.spoolbuddy.restartBrowserConfirmBody`,{hostname:e.hostname}),restart_daemon:r(`settings.spoolbuddy.restartDaemonConfirmBody`,{hostname:e.hostname}),reboot:r(`settings.spoolbuddy.rebootConfirmBody`,{hostname:e.hostname}),shutdown:r(`settings.spoolbuddy.shutdownConfirmBody`,{hostname:e.hostname})};return(0,Y.jsxs)(G,{children:[(0,Y.jsx)(U,{children:(0,Y.jsxs)(`div`,{className:`flex items-start justify-between gap-3 flex-wrap`,children:[(0,Y.jsxs)(`div`,{className:`min-w-0`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`h3`,{className:`text-base font-semibold text-white truncate`,children:e.hostname}),(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium ${u?`bg-green-500/15 text-green-400 border border-green-500/40`:`bg-gray-500/15 text-gray-400 border border-gray-500/40`}`,children:[u?(0,Y.jsx)(ht,{className:`w-3 h-3`}):(0,Y.jsx)(Ye,{className:`w-3 h-3`}),r(u?`settings.spoolbuddy.online`:`settings.spoolbuddy.offline`)]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray font-mono mt-1 truncate`,children:e.device_id})]}),(0,Y.jsxs)(K,{variant:`danger`,size:`sm`,onClick:()=>t(e),disabled:n,"aria-label":r(`settings.spoolbuddy.unregister`),children:[(0,Y.jsx)(qe,{className:`w-3.5 h-3.5`}),(0,Y.jsx)(`span`,{className:`hidden sm:inline`,children:r(`settings.spoolbuddy.unregister`)})]})]})}),(0,Y.jsxs)(W,{className:`space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 sm:grid-cols-4 gap-3 text-xs`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`text-bambu-gray`,children:r(`settings.spoolbuddy.ipAddress`)}),(0,Y.jsx)(`div`,{className:`text-white font-mono`,children:e.ip_address})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`text-bambu-gray`,children:r(`settings.spoolbuddy.firmware`)}),(0,Y.jsx)(`div`,{className:`text-white`,children:e.firmware_version??`—`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`div`,{className:`text-bambu-gray flex items-center gap-1`,children:[(0,Y.jsx)(lt,{className:`w-3 h-3`}),r(`settings.spoolbuddy.lastSeen`)]}),(0,Y.jsx)(`div`,{className:`text-white`,children:e.last_seen?Ue(e.last_seen):r(`settings.spoolbuddy.never`)})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`text-bambu-gray`,children:r(`settings.spoolbuddy.daemonUptime`)}),(0,Y.jsx)(`div`,{className:`text-white`,children:Di(e.uptime_s)})]})]}),(0,Y.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:g.map(({key:e,label:t,icon:n,variant:r})=>(0,Y.jsxs)(K,{variant:r??`secondary`,size:`sm`,onClick:()=>f(e),disabled:!u||p!==null,"aria-label":t,children:[p===e?(0,Y.jsx)(R,{className:`w-3.5 h-3.5 animate-spin`}):(0,Y.jsx)(n,{className:`w-3.5 h-3.5`}),(0,Y.jsx)(`span`,{children:t})]},e))}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-3 text-xs flex-wrap`,children:[(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 text-bambu-gray`,children:[e.nfc_ok?(0,Y.jsx)(q,{className:`w-3.5 h-3.5 text-green-400`}):(0,Y.jsx)(O,{className:`w-3.5 h-3.5 text-red-400`}),r(`settings.spoolbuddy.nfc`),e.nfc_reader_type&&(0,Y.jsxs)(`span`,{className:`text-bambu-gray/70`,children:[`(`,e.nfc_reader_type,`)`]})]}),(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 text-bambu-gray`,children:[e.scale_ok?(0,Y.jsx)(q,{className:`w-3.5 h-3.5 text-green-400`}):(0,Y.jsx)(O,{className:`w-3.5 h-3.5 text-red-400`}),r(`settings.spoolbuddy.scale`)]})]}),a&&(0,Y.jsxs)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-3 text-xs`,children:[a.cpu_temp_c!==void 0&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(Fe,{className:`w-3.5 h-3.5 text-bambu-gray`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`text-bambu-gray`,children:r(`settings.spoolbuddy.cpuTemp`)}),(0,Y.jsxs)(`div`,{className:`text-white`,children:[a.cpu_temp_c.toFixed(1),`°C`]})]})]}),a.load_avg&&a.load_avg.length>0&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(S,{className:`w-3.5 h-3.5 text-bambu-gray`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`text-bambu-gray`,children:r(`settings.spoolbuddy.cpuLoad`)}),(0,Y.jsxs)(`div`,{className:`text-white`,children:[a.load_avg[0].toFixed(2),a.cpu_count?` / ${a.cpu_count} (${Math.round(a.load_avg[0]/a.cpu_count*100)}%)`:``]})]})]}),o&&o.percent!==void 0&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(P,{className:`w-3.5 h-3.5 text-bambu-gray`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`text-bambu-gray`,children:r(`settings.spoolbuddy.memory`)}),(0,Y.jsxs)(`div`,{className:`text-white`,children:[o.percent.toFixed(0),`% (`,Oi(o.used_mb),` / `,Oi(o.total_mb),`)`]})]})]}),s&&s.percent!==void 0&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(re,{className:`w-3.5 h-3.5 text-bambu-gray`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`text-bambu-gray`,children:r(`settings.spoolbuddy.disk`)}),(0,Y.jsxs)(`div`,{className:`text-white`,children:[s.percent.toFixed(0),`% (`,s.used_gb?.toFixed(1),` / `,s.total_gb?.toFixed(1),` GB)`]})]})]}),a.system_uptime_s!==void 0&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(lt,{className:`w-3.5 h-3.5 text-bambu-gray`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`text-bambu-gray`,children:r(`settings.spoolbuddy.systemUptime`)}),(0,Y.jsx)(`div`,{className:`text-white`,children:Di(a.system_uptime_s)})]})]})]}),a.os&&(0,Y.jsx)(`div`,{className:`mt-3 text-xs text-bambu-gray font-mono truncate`,children:[a.os.os,a.os.kernel,a.os.arch,a.os.python&&`Python ${a.os.python}`].filter(Boolean).join(` · `)})]})]}),d&&(0,Y.jsx)(Tt,{variant:d===`shutdown`||d===`reboot`?`danger`:`default`,title:_[d],message:v[d],confirmText:r(`settings.spoolbuddy.commandConfirm`),isLoading:p!==null,onConfirm:()=>h(d),onCancel:()=>f(null)})]})}function Ai(){let{t:e}=l(),t=u(),{showToast:n}=ee(),[r,i]=(0,X.useState)(null),{data:a=[],isLoading:o}=d({queryKey:[`spoolbuddy-devices`],queryFn:()=>c.getDevices(),refetchInterval:15e3}),s=f({mutationFn:e=>c.deleteDevice(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`spoolbuddy-devices`]}),n(e(`settings.spoolbuddy.unregisterSuccess`),`success`),i(null)},onError:t=>{n(t.message||e(`settings.spoolbuddy.unregisterError`),`error`)}});if(o)return(0,Y.jsx)(G,{children:(0,Y.jsx)(W,{className:`py-8 flex justify-center`,children:(0,Y.jsx)(R,{className:`w-6 h-6 animate-spin text-bambu-green`})})});let p=a.length>1;return(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[(0,Y.jsx)(G,{children:(0,Y.jsx)(W,{className:`py-3 px-4`,children:(0,Y.jsxs)(`div`,{className:`flex items-start gap-2 text-xs`,children:[(0,Y.jsx)(A,{className:`w-4 h-4 text-blue-400 flex-shrink-0 mt-0.5`}),(0,Y.jsxs)(`div`,{className:`text-bambu-gray`,children:[(0,Y.jsx)(`p`,{className:`text-white font-medium mb-1`,children:e(`settings.spoolbuddy.infoTitle`)}),(0,Y.jsx)(`p`,{children:e(`settings.spoolbuddy.infoBody`)})]})]})})}),p&&(0,Y.jsx)(G,{className:`border-l-4 border-l-yellow-500`,children:(0,Y.jsx)(W,{className:`py-3 px-4`,children:(0,Y.jsxs)(`div`,{className:`flex items-start gap-2 text-xs`,children:[(0,Y.jsx)(Ie,{className:`w-4 h-4 text-yellow-500 flex-shrink-0 mt-0.5`}),(0,Y.jsxs)(`div`,{className:`text-bambu-gray`,children:[(0,Y.jsx)(`p`,{className:`text-white font-medium mb-1`,children:e(`settings.spoolbuddy.duplicatesTitle`,{count:a.length})}),(0,Y.jsx)(`p`,{children:e(`settings.spoolbuddy.duplicatesBody`)})]})]})})}),a.length===0?(0,Y.jsx)(G,{children:(0,Y.jsx)(W,{className:`py-8 text-center text-bambu-gray text-sm`,children:e(`settings.spoolbuddy.empty`)})}):(0,Y.jsx)(`div`,{className:`space-y-3`,children:a.map(e=>(0,Y.jsx)(ki,{device:e,onUnregister:i,isDeleting:s.isPending&&s.variables===e.device_id},e.id))}),r&&(0,Y.jsx)(Tt,{variant:`danger`,title:e(`settings.spoolbuddy.confirmTitle`),message:e(`settings.spoolbuddy.confirmBody`,{hostname:r.hostname,deviceId:r.device_id}),confirmText:e(`settings.spoolbuddy.unregister`),isLoading:s.isPending,onConfirm:()=>s.mutate(r.device_id),onCancel:()=>i(null)})]})}function ji(e,t,n,r,i){return n?e(`backup.restoreFromGit.${t}.${n}`,{...r??{},defaultValue:i??n}):i}var Mi=[{id:`archives`,labelKey:`backup.printArchives`,icon:(0,Y.jsx)(ot,{className:`w-4 h-4`})},{id:`spools`,labelKey:`backup.spoolInventory`,icon:(0,Y.jsx)(Nt,{className:`w-4 h-4`})},{id:`settings`,labelKey:`backup.appSettings`,icon:(0,Y.jsx)(yt,{className:`w-4 h-4`})},{id:`kprofiles`,labelKey:`backup.kProfiles`,icon:(0,Y.jsx)(Fe,{className:`w-4 h-4`})}],Ni=Object.fromEntries(Mi.map(e=>[e.id,e.labelKey])),Pi=`HEAD`;function Fi({onClose:e}){let{t}=l(),n=u(),[i,a]=(0,X.useState)(Pi),[o,s]=(0,X.useState)({}),[c,p]=(0,X.useState)(!1),[m,h]=(0,X.useState)(!1),[g,_]=(0,X.useState)(null),v=d({queryKey:[`github-backup-commits`],queryFn:()=>r.getGitHubBackupCommits(20)}),y=d({queryKey:[`github-restore-preview`,i],queryFn:()=>r.getGitHubRestorePreview(i)}),b=y.data?.success?y.data.ref:i,x=(0,X.useMemo)(()=>{let e={};return y.data?.categories?.forEach(n=>{e[n.category]={available:n.available,itemCount:n.item_count,detail:ji(t,`details`,n.detail_code,n.detail_params,n.detail)}}),e},[y.data,t]),S=(0,X.useMemo)(()=>Mi.filter(e=>o[e.id]&&x[e.id]?.available).map(e=>e.id),[o,x]),C=S.length,w=!c&&S.includes(`kprofiles`),T=f({mutationFn:()=>r.restoreFromGitHub({ref:b,categories:S,overwrite_existing:c}),onSuccess:e=>{h(!1);let t=Object.keys(e.results??{}).length>0;(e.success||t)&&(_(e),n.invalidateQueries({queryKey:[`spools`]}),n.invalidateQueries({queryKey:[`archives`]}),n.invalidateQueries({queryKey:[`settings`]})),n.invalidateQueries({queryKey:[`github-backup-logs`]}),n.invalidateQueries({queryKey:[`github-backup-status`]})},onError:()=>h(!1)}),E=T.isPending,D=!!(g&&`settings`in g.results),O=(0,X.useCallback)(()=>{if(D){window.location.reload();return}e()},[D,e]);(0,X.useEffect)(()=>{let e=e=>{e.key===`Escape`&&!E&&!m&&O()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[O,E,m]),(0,X.useEffect)(()=>{if(!E)return;let e=e=>{e.preventDefault(),e.returnValue=``};return window.addEventListener(`beforeunload`,e),()=>window.removeEventListener(`beforeunload`,e)},[E]),(0,X.useEffect)(()=>{y.data&&s(e=>{let t={};return Mi.forEach(n=>{t[n.id]=!!e[n.id]&&!!x[n.id]?.available}),t})},[y.data,x]);let k=v.data?.commits??[],ee=(e,t,n)=>{let r=(t||``).split(` `)[0],i=n?new Date(n).toLocaleString():``;return`${e.slice(0,7)} — ${i}${r?` — ${r}`:``}`},j=e=>e.isError?e.error?.message||t(`backup.restoreFromGit.loadFailed`):null,M=j(y)??(y.data&&!y.data.success?y.data.message:null),N=j(v)??(v.data&&!v.data.success?v.data.message:null);return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,onClick:E?void 0:O,children:(0,Y.jsx)(G,{className:`w-full max-w-lg`,onClick:e=>e.stopPropagation(),children:(0,Y.jsxs)(W,{className:`p-0`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Y.jsx)(`div`,{className:`p-2 rounded-full bg-bambu-green/20 text-bambu-green`,children:(0,Y.jsx)(nt,{className:`w-5 h-5`})}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h3`,{className:`text-lg font-semibold text-white`,children:t(`backup.restoreFromGit.title`)}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:t(`backup.restoreFromGit.subtitle`)})]})]}),(0,Y.jsx)(`button`,{onClick:O,disabled:E,"aria-label":t(`common.close`),className:`p-2 hover:bg-bambu-dark-tertiary rounded-lg transition-colors disabled:opacity-50`,children:(0,Y.jsx)(Re,{className:`w-5 h-5`})})]}),g?(0,Y.jsxs)(`div`,{className:`p-4 space-y-3 max-h-[400px] overflow-y-auto`,children:[(0,Y.jsxs)(`div`,{className:`flex items-start gap-2 text-sm`,children:[g.success?(0,Y.jsx)(q,{className:`w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0`}):(0,Y.jsx)(Ie,{className:`w-4 h-4 text-yellow-500 mt-0.5 flex-shrink-0`}),(0,Y.jsx)(`span`,{className:`text-white`,children:g.message})]}),!g.success&&(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:t(`backup.restoreFromGit.partialHint`)}),Object.entries(g.results).map(([e,n])=>(0,Y.jsxs)(`div`,{className:`p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`span`,{className:`text-sm font-medium text-white`,children:Ni[e]?t(Ni[e]):e}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:t(`backup.restoreFromGit.tally`,{restored:n.restored,skipped:n.skipped,failed:n.failed})})]}),n.notes.length>0&&(0,Y.jsx)(`ul`,{className:`mt-2 space-y-1`,children:n.notes.map(e=>(0,Y.jsxs)(`li`,{className:`text-xs text-bambu-gray flex items-start gap-1.5`,children:[(0,Y.jsx)(A,{className:`w-3 h-3 mt-0.5 flex-shrink-0`}),(0,Y.jsx)(`span`,{children:ji(t,`notes`,e.code,e.params,e.message)})]},`${e.code}:${JSON.stringify(e.params)}`))})]},e)),(0,Y.jsx)(`div`,{className:`p-3 rounded-lg bg-yellow-50 dark:bg-yellow-500/10 border border-yellow-300 dark:border-yellow-500/30`,children:(0,Y.jsx)(`p`,{className:`text-xs text-yellow-700 dark:text-yellow-200`,children:t(`backup.restoreFromGit.reloadHint`)})})]}):(0,Y.jsxs)(`div`,{className:`p-4 space-y-4 max-h-[400px] overflow-y-auto ${E?`opacity-50 pointer-events-none`:``}`,children:[T.isError&&(0,Y.jsx)(`div`,{className:`p-3 rounded-lg bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30`,children:(0,Y.jsx)(`p`,{className:`text-sm text-red-700 dark:text-red-400`,children:T.error?.message||t(`backup.restoreFromGit.failed`)})}),T.data&&!T.data.success&&(0,Y.jsx)(`div`,{className:`p-3 rounded-lg bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30`,children:(0,Y.jsx)(`p`,{className:`text-sm text-red-700 dark:text-red-400`,children:T.data.message})}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{htmlFor:`restore-commit`,className:`block text-sm font-medium text-white mb-1`,children:t(`backup.restoreFromGit.commitLabel`)}),(0,Y.jsxs)(`select`,{id:`restore-commit`,value:i,onChange:e=>{a(e.target.value),T.reset()},disabled:E||v.isLoading,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`,children:[(0,Y.jsx)(`option`,{value:Pi,children:t(`backup.restoreFromGit.latestCommit`)}),k.map(e=>(0,Y.jsx)(`option`,{value:e.sha,children:ee(e.sha,e.message,e.date)},e.sha))]}),N&&(0,Y.jsx)(`p`,{className:`mt-1 text-xs text-red-500 dark:text-red-400`,children:N})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm font-medium text-white mb-2`,children:t(`backup.restoreFromGit.categoriesLabel`)}),y.isLoading?(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-bambu-gray p-3`,children:[(0,Y.jsx)(R,{className:`w-4 h-4 animate-spin`}),t(`backup.restoreFromGit.inspecting`)]}):M?(0,Y.jsx)(`div`,{className:`p-3 rounded-lg bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30`,children:(0,Y.jsx)(`p`,{className:`text-sm text-red-700 dark:text-red-400`,children:M})}):(0,Y.jsx)(`div`,{className:`space-y-2`,children:Mi.map(e=>{let n=x[e.id],r=!!n?.available,i=!!o[e.id]&&r;return(0,Y.jsxs)(`label`,{className:`flex items-center gap-3 p-3 rounded-lg transition-colors ${r?`cursor-pointer`:`cursor-not-allowed opacity-50`} ${i?`bg-bambu-green/10 border border-bambu-green/30`:`bg-bambu-dark hover:bg-bambu-dark-tertiary border border-transparent`}`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:i,disabled:!r||E,onChange:()=>s(t=>({...t,[e.id]:!t[e.id]})),className:`w-4 h-4 rounded border-bambu-gray bg-bambu-dark text-bambu-green focus:ring-bambu-green focus:ring-offset-0`}),(0,Y.jsx)(`div`,{className:i?`text-bambu-green`:`text-bambu-gray`,children:e.icon}),(0,Y.jsxs)(`div`,{className:`flex-1`,children:[(0,Y.jsxs)(`div`,{className:`text-white text-sm font-medium`,children:[t(e.labelKey),r&&n?.itemCount?(0,Y.jsx)(`span`,{className:`ml-2 text-xs text-bambu-gray`,children:t(`backup.restoreFromGit.itemCount`,{count:n.itemCount})}):null]}),n?.detail&&(0,Y.jsx)(`div`,{className:`text-xs text-bambu-gray`,children:n.detail}),e.id===`kprofiles`&&i&&w&&(0,Y.jsx)(`div`,{className:`text-xs text-yellow-700 dark:text-yellow-200`,children:t(`backup.restoreFromGit.kprofilesOverwriteCaveat`)})]})]},e.id)})})]}),(0,Y.jsx)(`div`,{className:`p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary`,children:(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm font-medium text-white`,children:t(`backup.restoreFromGit.overwriteLabel`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:t(c?`backup.restoreFromGit.overwriteOn`:`backup.restoreFromGit.overwriteOff`)})]}),(0,Y.jsx)(J,{checked:c,onChange:p,disabled:E})]})})]}),(0,Y.jsx)(`div`,{className:`flex items-center justify-between p-4 border-t border-bambu-dark-tertiary`,children:g?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`span`,{}),(0,Y.jsxs)(`div`,{className:`flex gap-3`,children:[(0,Y.jsx)(K,{variant:`secondary`,onClick:O,children:t(`common.close`)}),(0,Y.jsx)(K,{onClick:()=>window.location.reload(),className:`bg-bambu-green hover:bg-bambu-green-dark`,children:t(`backup.reloadNow`)})]})]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:t(`backup.restoreFromGit.selectedCount`,{count:C})}),(0,Y.jsxs)(`div`,{className:`flex gap-3`,children:[(0,Y.jsx)(K,{variant:`secondary`,onClick:O,disabled:E,children:t(`common.cancel`)}),(0,Y.jsx)(K,{onClick:()=>h(!0),disabled:C===0||E,className:`bg-bambu-green hover:bg-bambu-green-dark disabled:opacity-50 disabled:cursor-not-allowed min-w-[100px]`,children:E?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(R,{className:`w-4 h-4 mr-2 animate-spin`}),t(`backup.restoreFromGit.restoring`)]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(nt,{className:`w-4 h-4 mr-2`}),t(`backup.restore`)]})})]})]})})]})})}),m&&(0,Y.jsx)(Tt,{variant:`danger`,overlayZIndex:`z-[110]`,title:t(`backup.restoreFromGit.confirmTitle`),message:c?t(`backup.restoreFromGit.confirmMessageOverwrite`):w?`${t(`backup.restoreFromGit.confirmMessage`)} ${t(`backup.restoreFromGit.kprofilesOverwriteCaveat`)}`:t(`backup.restoreFromGit.confirmMessage`),confirmText:t(`backup.restore`),isLoading:E,loadingText:t(`backup.restoreFromGit.restoring`),onConfirm:()=>T.mutate(),onCancel:()=>h(!1)})]})}function Ii(e){if(!e)return`-`;let t=We(e);return t?t.toLocaleString():`-`}function Li({status:e}){if(!e)return null;let t={success:`bg-green-100 dark:bg-green-500/20 text-green-700 dark:text-green-400`,failed:`bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400`,skipped:`bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400`,running:`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`},n={success:(0,Y.jsx)(j,{className:`w-3 h-3`}),failed:(0,Y.jsx)(O,{className:`w-3 h-3`}),skipped:(0,Y.jsx)(Ne,{className:`w-3 h-3`}),running:(0,Y.jsx)(R,{className:`w-3 h-3 animate-spin`})};return(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded text-xs font-medium ${t[e]||`bg-gray-500/20 text-gray-400`}`,children:[n[e],e.charAt(0).toUpperCase()+e.slice(1)]})}var Ri={github:`backup.repoUrlPlaceholderGitHub`,gitea:`backup.repoUrlPlaceholderGitea`,forgejo:`backup.repoUrlPlaceholderForgejo`,gitlab:`backup.repoUrlPlaceholderGitLab`},zi={github:`ghp_xxxxxxxxxxxx`,gitea:`your_access_token`,forgejo:`your_access_token`,gitlab:`glpat-xxxxxxxxxxxx`},Bi={github:`backup.tokenHintGitHub`,gitea:`backup.tokenHintGitea`,forgejo:`backup.tokenHintForgejo`,gitlab:`backup.tokenHintGitLab`};function Vi(e){return JSON.stringify(e)}function Hi(e,t){if(!t)return e;let n={};for(let r of Object.keys(e))e[r]!==t[r]&&(n[r]=e[r]);return n}function Ui(){let e=u(),{showToast:t}=ee(),{t:n}=l(),{hasPermission:i}=un(),a=i(`github:restore`),[o,s]=(0,X.useState)(``),[c,m]=(0,X.useState)(``),[h,g]=(0,X.useState)(`main`),[_,v]=(0,X.useState)(`github`),[y,b]=(0,X.useState)(!1),[x,S]=(0,X.useState)(`daily`),[C,w]=(0,X.useState)(!0),[T,E]=(0,X.useState)(!0),[D,k]=(0,X.useState)(!1),[A,M]=(0,X.useState)(!1),[N,P]=(0,X.useState)(!1),[te,F]=(0,X.useState)(!1),[ne,I]=(0,X.useState)(!0),[re,L]=(0,X.useState)(!1),[ae,z]=(0,X.useState)(!1),[oe,se]=(0,X.useState)(``),[B,ce]=(0,X.useState)(!1),[le,ue]=(0,X.useState)(null),[de,fe]=(0,X.useState)(null),V=(0,X.useRef)(null),[pe,me]=(0,X.useState)(!1),[he,ge]=(0,X.useState)(null),[_e,ve]=(0,X.useState)(null),[ye,be]=(0,X.useState)(``),{data:H,refetch:xe}=d({queryKey:[`local-backup-status`],queryFn:r.getLocalBackupStatus,refetchInterval:e=>e.state.data?.is_running?1e3:1e4}),{data:Se,refetch:Ce}=d({queryKey:[`local-backup-files`],queryFn:r.getLocalBackups,refetchInterval:3e4}),{data:we,refetch:Te}=d({queryKey:[`local-backup-path-check`],queryFn:r.checkLocalBackupPath,enabled:H?.enabled===!0,refetchOnWindowFocus:!1});(0,X.useEffect)(()=>{H?.path!==void 0&&be(H.path)},[H?.path]);let Ee=f({mutationFn:r.triggerLocalBackup,onSuccess:e=>{e.success?t(n(`backup.scheduledBackupComplete`)):t(e.message,`error`),xe(),Ce(),Te()},onError:()=>t(n(`backup.scheduledBackupFailed`),`error`)}),Oe=f({mutationFn:e=>r.deleteLocalBackup(e),onSuccess:()=>{Ce(),ge(null)}}),ke=f({mutationFn:async e=>(ve(null),z(!0),fe(null),se(n(`backup.restoring`)),r.restoreLocalBackup(e)),onSuccess:e=>{z(!1),se(``),e.success?(fe({success:!0,message:e.message}),t(n(`backup.backupRestoredRestart`),`success`)):(fe({success:!1,message:e.message}),t(e.message,`error`))},onError:e=>{z(!1),se(``);let r=e instanceof Error?e.message:n(`backup.failedToRestore`);fe({success:!1,message:r}),t(r,`error`)}});(0,X.useEffect)(()=>{if(re||ae){let e=e=>(e.preventDefault(),e.returnValue=`A backup operation is in progress. Are you sure you want to leave?`,e.returnValue);return window.addEventListener(`beforeunload`,e),()=>window.removeEventListener(`beforeunload`,e)}},[re,ae]);let[Ae,je]=(0,X.useState)(!1),[Me,Ne]=(0,X.useState)(null),[Pe,Fe]=(0,X.useState)(null),Le=(0,X.useRef)(null),Re=(0,X.useRef)(null),ze=(0,X.useRef)(null),Be=(0,X.useRef)(null),Ve=(0,X.useRef)(``),[He,We]=(0,X.useState)(!1),Ge=(0,X.useMemo)(()=>({repository_url:o,branch:h,provider:_,allow_insecure_http:te,schedule_enabled:y,schedule_type:x,backup_kprofiles:C,backup_cloud_profiles:T,backup_settings:D,backup_spools:A,backup_archives:N,enabled:ne}),[o,h,_,te,y,x,C,T,D,A,N,ne]),Ke=(0,X.useMemo)(()=>Vi(Ge),[Ge]),{data:q,isLoading:Ye}=d({queryKey:[`github-backup-config`],queryFn:r.getGitHubBackupConfig}),{data:Xe}=d({queryKey:[`github-backup-status`],queryFn:r.getGitHubBackupStatus,refetchInterval:e=>e.state.data?.is_running?500:1e4}),{data:Ze}=d({queryKey:[`github-backup-logs`],queryFn:()=>r.getGitHubBackupLogs(20)}),{data:Qe}=d({queryKey:[`cloud-status`],queryFn:r.getCloudStatus}),{data:$e}=d({queryKey:[`github-backup-cloud-accounts`],queryFn:r.getGitHubBackupCloudAccounts,staleTime:6e4}),et=($e?.bambu??0)+($e?.orca??0),tt=$e?et>0:!!Qe?.is_authenticated,{data:rt}=d({queryKey:[`printers`],queryFn:r.getPrinters}),it=p({queries:(rt??[]).map(e=>({queryKey:[`printerStatus`,e.id],queryFn:()=>r.getPrinterStatus(e.id),staleTime:1e4,refetchInterval:3e4}))}),ot=(rt??[]).map((e,t)=>({printer:e,connected:it[t]?.data?.connected??!1})),st=ot.length,ut=ot.filter(e=>e.connected).length,dt=st>0&&ut===0,ft=ut>0&&ut(ze.current&&clearTimeout(ze.current),q?(We(!1),Be.current={repository_url:q.repository_url,branch:q.branch,provider:q.provider??`github`,allow_insecure_http:q.allow_insecure_http??!1,schedule_enabled:q.schedule_enabled,schedule_type:q.schedule_type,backup_kprofiles:q.backup_kprofiles,backup_cloud_profiles:q.backup_cloud_profiles,backup_settings:q.backup_settings,backup_spools:q.backup_spools,backup_archives:q.backup_archives,enabled:q.enabled},s(q.repository_url),g(q.branch),v(q.provider??`github`),b(q.schedule_enabled),S(q.schedule_type),w(q.backup_kprofiles),E(q.backup_cloud_profiles),k(q.backup_settings),M(q.backup_spools),P(q.backup_archives),F(q.allow_insecure_http??!1),I(q.enabled),m(``),ze.current=setTimeout(()=>{We(!0)},100)):(We(!1),Be.current=null,m(``)),()=>{ze.current&&clearTimeout(ze.current)}),[q]);let pt=(0,X.useCallback)(async(i=!1)=>{if(q)try{i&&c?(await r.saveGitHubBackupConfig({...Ge,access_token:c}),m(``),Fe(null),t(n(`backup.tokenUpdated`)),Ve.current=``):(await r.updateGitHubBackupConfig(Hi(Ge,Be.current)),Fe(null),t(n(`backup.settingsSaved`))),Be.current=Ge,e.invalidateQueries({queryKey:[`github-backup-config`]}),e.invalidateQueries({queryKey:[`github-backup-status`]})}catch(e){Fe(e.message)}},[q,c,Ge,e,t,n]),mt=(0,X.useRef)(pt);(0,X.useEffect)(()=>{mt.current=pt},[pt]),(0,X.useEffect)(()=>{if(!(!He||!q)&&!(Be.current&&Ke===Vi(Be.current)))return Le.current&&clearTimeout(Le.current),Le.current=setTimeout(()=>{pt(!1)},500),()=>{Le.current&&clearTimeout(Le.current)}},[He,q,Ke,pt]),(0,X.useEffect)(()=>{if(!(!He||!q||!c)&&c!==Ve.current)return Ve.current=c,Re.current&&clearTimeout(Re.current),Re.current=setTimeout(()=>{mt.current(!0)},1e3),()=>{Re.current&&clearTimeout(Re.current)}},[He,c,q]);let ht=f({mutationFn:e=>r.saveGitHubBackupConfig(e),onMutate:()=>{Fe(null)},onSuccess:()=>{e.invalidateQueries({queryKey:[`github-backup-config`]}),e.invalidateQueries({queryKey:[`github-backup-status`]}),t(n(`backup.githubBackupEnabled`)),m(``),We(!0)},onError:e=>{Fe(e.message)}}),_t=f({mutationFn:r.triggerGitHubBackup,onSuccess:r=>{e.invalidateQueries({queryKey:[`github-backup-status`]}),e.invalidateQueries({queryKey:[`github-backup-logs`]}),r.success?r.files_changed>0?t(n(`backup.backupCompleteFiles`,{count:r.files_changed})):t(n(`backup.backupSkippedNoChanges`)):t(n(`backup.backupFailed2`,{message:r.message}),`error`)},onError:e=>{t(n(`backup.backupFailed2`,{message:e.message}),`error`)}}),vt=f({mutationFn:()=>r.clearGitHubBackupLogs(0),onSuccess:r=>{e.invalidateQueries({queryKey:[`github-backup-logs`]}),t(n(`backup.clearedLogs`,{count:r.deleted}))},onError:e=>{t(n(`backup.failedToClearLogs`,{message:e.message}),`error`)}}),yt=async()=>{je(!0),Ne(null);try{let e;if(c){if(!o){t(n(`backup.enterRepoUrl`),`error`),je(!1);return}e=await r.testGitHubConnection(o,c,_)}else if(q?.has_token)e=await r.testGitHubStoredConnection();else{t(n(`backup.enterRepoAndToken`),`error`),je(!1);return}Ne({success:e.success,message:e.message,isPrivate:e.is_private})}catch(e){Ne({success:!1,message:e.message,isPrivate:null})}finally{je(!1)}};return Ye?(0,Y.jsx)(`div`,{className:`flex items-center justify-center py-12`,children:(0,Y.jsx)(R,{className:`w-8 h-8 animate-spin text-bambu-green`})}):(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-6`,children:[(0,Y.jsxs)(`div`,{className:`space-y-6`,children:[(0,Y.jsxs)(G,{id:`card-backup-github`,children:[(0,Y.jsx)(U,{children:(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(It,{className:`w-5 h-5 text-gray-400`}),(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:n(`backup.githubBackup`)})]}),q&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:n(`backup.enabled`)}),(0,Y.jsx)(J,{checked:ne,onChange:I})]})]})}),(0,Y.jsxs)(W,{className:`space-y-4`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`backup.githubDescription`)}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{htmlFor:`git-provider-select`,className:`block text-sm text-bambu-gray mb-1`,children:n(`backup.provider`)}),(0,Y.jsxs)(`select`,{id:`git-provider-select`,value:_,onChange:e=>{v(e.target.value),Ne(null),Fe(null)},className:`w-full h-10 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,Y.jsx)(`option`,{value:`github`,children:n(`backup.providerGitHub`)}),(0,Y.jsx)(`option`,{value:`gitlab`,children:n(`backup.providerGitLab`)}),(0,Y.jsx)(`option`,{value:`gitea`,children:n(`backup.providerGitea`)}),(0,Y.jsx)(`option`,{value:`forgejo`,children:n(`backup.providerForgejo`)})]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`backup.repositoryUrl`)}),(0,Y.jsx)(`input`,{type:`text`,value:o,onChange:e=>{s(e.target.value),Ne(null),Fe(null)},placeholder:n(Ri[_]),className:`w-full h-10 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,Y.jsxs)(`label`,{className:`flex items-start gap-2 mt-2 cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:te,onChange:e=>{F(e.target.checked),Ne(null)},className:`w-4 h-4 mt-0.5 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:n(`backup.allowInsecureHttp`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`backup.allowInsecureHttpHint`)})]})]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[n(`backup.personalAccessToken`),` `,q?.has_token&&(0,Y.jsx)(`span`,{className:`text-green-700 dark:text-green-400`,children:n(`backup.tokenSaved`)})]}),(0,Y.jsx)(`input`,{type:`password`,value:c,onChange:e=>{m(e.target.value),Ne(null),Fe(null)},placeholder:q?.has_token?n(`backup.enterNewToken`):zi[_],className:`w-full h-10 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(Bi[_])})]}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`backup.branch`)}),(0,Y.jsx)(`input`,{type:`text`,value:h,onChange:e=>g(e.target.value),placeholder:`main`,className:`w-full h-10 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`backup.autoBackup`)}),(0,Y.jsxs)(`select`,{value:y?x:`disabled`,onChange:e=>{e.target.value===`disabled`?b(!1):(b(!0),S(e.target.value))},className:`w-full h-10 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,Y.jsx)(`option`,{value:`disabled`,children:n(`backup.manualOnly`)}),(0,Y.jsx)(`option`,{value:`hourly`,children:n(`backup.hourly`)}),(0,Y.jsx)(`option`,{value:`daily`,children:n(`backup.daily`)}),(0,Y.jsx)(`option`,{value:`weekly`,children:n(`backup.weekly`)})]})]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-2`,children:n(`backup.includeInBackup`)}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsxs)(`label`,{className:`flex items-start gap-2 ${dt?`cursor-not-allowed opacity-60`:`cursor-pointer`}`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:C,onChange:e=>w(e.target.checked),className:`w-4 h-4 mt-0.5 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`,disabled:dt}),(0,Y.jsxs)(`div`,{className:`flex-1`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{className:`text-sm ${dt?`text-bambu-gray`:`text-white`}`,children:n(`backup.kProfiles`)}),dt&&(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-xs bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400`,children:[(0,Y.jsx)(Ie,{className:`w-3 h-3`}),n(`backup.noPrintersConnected`)]}),ft&&(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-xs bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400`,children:[(0,Y.jsx)(Ie,{className:`w-3 h-3`}),n(`backup.printersConnected`,{connected:ut,total:st})]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`backup.kProfilesDescription`)})]})]}),(0,Y.jsxs)(`label`,{className:`flex items-start gap-2 ${tt?`cursor-pointer`:`cursor-not-allowed opacity-60`}`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:T,onChange:e=>E(e.target.checked),className:`w-4 h-4 mt-0.5 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`,disabled:!tt}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{className:`text-sm ${tt?`text-white`:`text-bambu-gray`}`,children:n(`backup.cloudProfiles`)}),!tt&&(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-xs bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400`,children:[(0,Y.jsx)(Ie,{className:`w-3 h-3`}),n(`backup.cloudLoginRequiredShort`)]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`backup.cloudProfilesDescription`)}),et>0&&(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:n(`backup.cloudProfilesAccounts`,{bambu:$e?.bambu??0,orca:$e?.orca??0})})]})]}),(0,Y.jsxs)(`label`,{className:`flex items-start gap-2 cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:D,onChange:e=>k(e.target.checked),className:`w-4 h-4 mt-0.5 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-white text-sm`,children:n(`backup.appSettings`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`backup.appSettingsDescription`)})]})]}),(0,Y.jsxs)(`label`,{className:`flex items-start gap-2 cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:A,onChange:e=>M(e.target.checked),className:`w-4 h-4 mt-0.5 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-white text-sm`,children:n(`backup.spoolInventory`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`backup.spoolInventoryDescription`)})]})]}),(0,Y.jsxs)(`label`,{className:`flex items-start gap-2 cursor-pointer`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:N,onChange:e=>P(e.target.checked),className:`w-4 h-4 mt-0.5 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-white text-sm`,children:n(`backup.printArchives`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`backup.printArchivesDescription`)})]})]})]})]}),(0,Y.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary pt-4 space-y-3`,children:[Xe?.configured&&(0,Y.jsxs)(`div`,{className:`flex items-center justify-between text-sm`,children:[(0,Y.jsx)(`div`,{className:`flex items-center gap-2 text-bambu-gray`,children:Xe.last_backup_at?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`span`,{children:[n(`backup.lastBackupAt`),` `,Ue(Xe.last_backup_at,`system`,n)]}),(0,Y.jsx)(Li,{status:Xe.last_backup_status})]}):(0,Y.jsx)(`span`,{children:n(`backup.noBackupsYet`)})}),Xe.next_scheduled_run&&(0,Y.jsxs)(`span`,{className:`text-bambu-gray`,children:[(0,Y.jsx)(lt,{className:`w-3 h-3 inline mr-1`}),n(`backup.next`),` `,Ue(Xe.next_scheduled_run,`system`,n)]})]}),Pe&&(0,Y.jsxs)(`div`,{className:`text-sm text-red-700 dark:text-red-400 bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30 rounded p-3 flex items-start gap-2`,children:[(0,Y.jsx)(O,{className:`w-4 h-4 mt-0.5 shrink-0`}),(0,Y.jsx)(`div`,{className:`flex-1 leading-relaxed whitespace-pre-wrap break-words`,children:Pe}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>Fe(null),className:`text-bambu-gray hover:text-white shrink-0`,"aria-label":n(`common.dismiss`,`Dismiss`),children:(0,Y.jsx)(O,{className:`w-4 h-4`})})]}),Me&&(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsxs)(`div`,{className:`text-sm flex items-center gap-1 ${Me.success?`text-green-700 dark:text-green-400`:`text-red-700 dark:text-red-400`}`,children:[Me.success?(0,Y.jsx)(j,{className:`w-4 h-4`}):(0,Y.jsx)(O,{className:`w-4 h-4`}),Me.message]}),Me.success&&Me.isPrivate===!0&&(0,Y.jsxs)(`div`,{className:`text-xs flex items-center gap-1 text-green-700 dark:text-green-400`,children:[(0,Y.jsx)(j,{className:`w-3.5 h-3.5`}),n(`backup.repoIsPrivate`,`Repository is private — safe to back up to.`)]}),Me.success&&Me.isPrivate===!1&&(0,Y.jsxs)(`div`,{className:`text-xs text-red-700 dark:text-red-400 bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30 rounded p-2 flex items-start gap-1.5`,children:[(0,Y.jsx)(O,{className:`w-4 h-4 mt-0.5 shrink-0`}),(0,Y.jsx)(`span`,{children:n(`backup.repoIsPublicWarning`,`Repository is PUBLIC. Bambuddy backups include MQTT credentials, Home Assistant tokens, Prometheus tokens, your Bambu Cloud email, and printer access codes via K-profiles. Saving is blocked until you make the repository private in your provider's settings.`)})]}),Me.success&&Me.isPrivate===null&&(0,Y.jsxs)(`div`,{className:`text-xs text-yellow-700 dark:text-yellow-400 bg-yellow-50 dark:bg-yellow-500/10 border border-yellow-300 dark:border-yellow-500/30 rounded p-2 flex items-start gap-1.5`,children:[(0,Y.jsx)(O,{className:`w-4 h-4 mt-0.5 shrink-0`}),(0,Y.jsx)(`span`,{children:n(`backup.repoVisibilityUnknown`,`Could not determine repository visibility. Bambuddy refuses to back up to anything not confirmed private; saving will be blocked.`)})]})]}),(0,Y.jsx)(`div`,{className:`flex flex-wrap items-center gap-2`,children:Xe?.configured?(0,Y.jsx)(Y.Fragment,{children:_t.isPending||Xe.is_running?(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-green`,children:[(0,Y.jsx)(R,{className:`w-4 h-4 animate-spin`}),(0,Y.jsx)(`span`,{className:`text-sm`,children:Xe.progress||n(`backup.startingBackup`)})]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(K,{variant:`primary`,size:`sm`,onClick:()=>_t.mutate(),disabled:!q?.enabled,children:[(0,Y.jsx)(De,{className:`w-4 h-4`}),n(`backup.backupNow`)]}),(0,Y.jsxs)(K,{variant:`secondary`,size:`sm`,onClick:yt,disabled:Ae,children:[Ae?(0,Y.jsx)(R,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(at,{className:`w-4 h-4`}),n(`backup.test`)]}),a&&(0,Y.jsxs)(K,{variant:`secondary`,size:`sm`,onClick:()=>me(!0),disabled:Xe.restore_running,children:[(0,Y.jsx)(nt,{className:`w-4 h-4`}),n(`backup.restoreFromGit.button`)]})]})}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(K,{variant:`primary`,size:`sm`,onClick:()=>{if(!o){t(n(`backup.repoRequired`),`error`);return}if(!c){t(n(`backup.tokenRequired`),`error`);return}ht.mutate({repository_url:o,access_token:c,branch:h,provider:_,allow_insecure_http:te,schedule_enabled:y,schedule_type:x,backup_kprofiles:C,backup_cloud_profiles:T,backup_settings:D,backup_spools:A,backup_archives:N,enabled:ne})},disabled:ht.isPending||!o||!c,children:[ht.isPending?(0,Y.jsx)(R,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(j,{className:`w-4 h-4`}),n(`backup.enableBackup`)]}),(0,Y.jsxs)(K,{variant:`secondary`,size:`sm`,onClick:yt,disabled:Ae||!o||!c,children:[Ae?(0,Y.jsx)(R,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(at,{className:`w-4 h-4`}),n(`backup.testConnection`)]})]})})]})]})]}),Ze&&Ze.length>0&&(0,Y.jsxs)(G,{id:`card-backup-history`,children:[(0,Y.jsx)(U,{children:(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(ie,{className:`w-5 h-5 text-gray-400`}),(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:n(`backup.history`)})]}),(0,Y.jsxs)(K,{variant:`ghost`,size:`sm`,onClick:()=>vt.mutate(),disabled:vt.isPending,children:[(0,Y.jsx)(qe,{className:`w-4 h-4`}),n(`backup.clear`)]})]})}),(0,Y.jsx)(W,{children:(0,Y.jsx)(`div`,{className:`overflow-x-auto`,children:(0,Y.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,Y.jsx)(`thead`,{children:(0,Y.jsxs)(`tr`,{className:`text-bambu-gray border-b border-bambu-dark-tertiary`,children:[(0,Y.jsx)(`th`,{className:`text-left py-2 px-2`,children:n(`backup.date`)}),(0,Y.jsx)(`th`,{className:`text-left py-2 px-2`,children:n(`backup.trigger`)}),(0,Y.jsx)(`th`,{className:`text-left py-2 px-2`,children:n(`backup.status`)}),(0,Y.jsx)(`th`,{className:`text-left py-2 px-2`,children:n(`backup.commit`)})]})}),(0,Y.jsx)(`tbody`,{children:Ze.slice(0,10).map(e=>(0,Y.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/50 hover:bg-bambu-dark-secondary`,children:[(0,Y.jsx)(`td`,{className:`py-2 px-2 text-white`,children:Ii(e.started_at)}),(0,Y.jsx)(`td`,{className:`py-2 px-2 text-bambu-gray`,children:n(`backup.triggers.${e.trigger}`,{defaultValue:e.trigger})}),(0,Y.jsx)(`td`,{className:`py-2 px-2`,children:(0,Y.jsx)(Li,{status:e.status})}),(0,Y.jsx)(`td`,{className:`py-2 px-2`,children:e.commit_sha?(0,Y.jsxs)(`a`,{href:`${q?.repository_url}/commit/${e.commit_sha}`,target:`_blank`,rel:`noopener noreferrer`,className:`text-bambu-green hover:underline inline-flex items-center gap-1`,children:[e.commit_sha.substring(0,7),(0,Y.jsx)(Je,{className:`w-3 h-3`})]}):(0,Y.jsx)(`span`,{className:`text-bambu-gray`,children:`-`})})]},e.id))})]})})})]})]}),(0,Y.jsxs)(`div`,{className:`space-y-6`,children:[(0,Y.jsxs)(G,{id:`card-backup-local`,children:[(0,Y.jsx)(U,{children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(gt,{className:`w-5 h-5 text-gray-400`}),(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:n(`backup.localBackup`)})]})}),(0,Y.jsxs)(W,{className:`space-y-4`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`backup.localBackupDescription`)}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between py-3 border-b border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-white`,children:n(`backup.downloadBackupLabel`)}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`backup.completeBackupZip`)})]}),(0,Y.jsxs)(K,{variant:`secondary`,size:`sm`,disabled:re||ae,onClick:async()=>{L(!0),se(n(`backup.preparingBackup`));try{se(n(`backup.creatingArchive`));let{blob:e,filename:i}=await r.exportBackup();se(n(`backup.downloadingFile`));let a=URL.createObjectURL(e),o=document.createElement(`a`);o.href=a,o.download=i,o.click(),URL.revokeObjectURL(a),t(n(`backup.backupDownloaded`))}catch(e){t(n(`backup.failedToCreateBackup`,{message:e instanceof Error?e.message:`Unknown error`}),`error`)}finally{L(!1),se(``)}},children:[(0,Y.jsx)(sn,{className:`w-4 h-4`}),n(`backup.download`)]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between py-3 border-b border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-white`,children:n(`backup.restoreBackup`)}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`backup.restoreDescription`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray-light mt-1`,children:n(`backup.restoreNote`)})]}),(0,Y.jsx)(`input`,{ref:V,type:`file`,accept:`.zip`,className:`hidden`,onChange:e=>{let t=e.target.files?.[0];t&&(ue(t),ce(!0)),e.target.value=``}}),(0,Y.jsxs)(K,{variant:`secondary`,size:`sm`,disabled:ae||re,onClick:()=>V.current?.click(),children:[(0,Y.jsx)(Wt,{className:`w-4 h-4`}),n(`backup.restore`)]})]}),de&&(0,Y.jsx)(`div`,{className:`p-3 rounded-lg ${de.success?`bg-green-50 dark:bg-green-500/10 border border-green-300 dark:border-green-500/30`:`bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30`}`,children:(0,Y.jsxs)(`div`,{className:`flex items-start gap-2 text-sm`,children:[de.success?(0,Y.jsx)(j,{className:`w-4 h-4 text-green-600 dark:text-green-400 mt-0.5 flex-shrink-0`}):(0,Y.jsx)(O,{className:`w-4 h-4 text-red-600 dark:text-red-400 mt-0.5 flex-shrink-0`}),(0,Y.jsxs)(`div`,{className:de.success?`text-green-800 dark:text-green-200`:`text-red-800 dark:text-red-200`,children:[de.message,de.success&&(0,Y.jsx)(`div`,{className:`mt-2`,children:(0,Y.jsxs)(K,{size:`sm`,onClick:()=>window.location.reload(),children:[(0,Y.jsx)(nt,{className:`w-3 h-3`}),n(`backup.reloadNow`)]})})]})]})}),(0,Y.jsx)(`div`,{className:`p-3 rounded-lg bg-yellow-50 dark:bg-yellow-500/10 border border-yellow-300 dark:border-yellow-500/30`,children:(0,Y.jsxs)(`div`,{className:`flex items-start gap-2 text-sm`,children:[(0,Y.jsx)(Ie,{className:`w-4 h-4 text-yellow-600 dark:text-yellow-400 mt-0.5 flex-shrink-0`}),(0,Y.jsxs)(`div`,{className:`text-yellow-800 dark:text-yellow-200`,children:[(0,Y.jsx)(`span`,{className:`font-medium`,children:n(`backup.restoreReplacesAll`)}),` `,(0,Y.jsx)(`span`,{className:`text-yellow-800/80 dark:text-yellow-200/70`,children:n(`backup.restoreReplacesAllDetail`)})]})]})})]})]}),(0,Y.jsxs)(G,{id:`card-backup-scheduled`,children:[(0,Y.jsx)(U,{children:(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(xn,{className:`w-5 h-5 text-gray-400`}),(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:n(`backup.scheduledBackup`)})]}),(0,Y.jsx)(J,{checked:H?.enabled??!1,onChange:async i=>{try{await r.updateSettings({local_backup_enabled:i}),e.invalidateQueries({queryKey:[`settings`]}),t(n(`backup.settingsSaved`))}catch(e){t(n(`backup.failedToSave`,{message:e instanceof Error?e.message:`Unknown error`}),`error`)}xe()}})]})}),(0,Y.jsxs)(W,{className:`space-y-4`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`backup.scheduledBackupDescription`)}),H?.enabled&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`div`,{className:`grid grid-cols-3 gap-4`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`backup.frequency`)}),(0,Y.jsxs)(`select`,{value:H?.schedule??`daily`,className:`w-full h-10 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,onChange:async e=>{try{await r.updateSettings({local_backup_schedule:e.target.value}),t(n(`backup.settingsSaved`))}catch(e){t(n(`backup.failedToSave`,{message:e instanceof Error?e.message:`Unknown error`}),`error`)}xe()},children:[(0,Y.jsx)(`option`,{value:`hourly`,children:n(`backup.hourly`)}),(0,Y.jsx)(`option`,{value:`daily`,children:n(`backup.daily`)}),(0,Y.jsx)(`option`,{value:`weekly`,children:n(`backup.weekly`)})]})]}),(H?.schedule??`daily`)!==`hourly`&&(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`backup.backupTime`)}),(0,Y.jsx)(`input`,{type:`time`,value:H?.time??`03:00`,className:`w-full h-10 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,onChange:async e=>{try{await r.updateSettings({local_backup_time:e.target.value}),t(n(`backup.settingsSaved`))}catch(e){t(n(`backup.failedToSave`,{message:e instanceof Error?e.message:`Unknown error`}),`error`)}xe()}}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray-light mt-1`,children:n(`backup.localTimeHint`,{tz:H?.timezone||`UTC`})})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`backup.retention`)}),(0,Y.jsx)(ct,{min:1,max:100,value:H?.retention??5,className:`w-full h-10 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,onChange:async e=>{try{await r.updateSettings({local_backup_retention:e}),t(n(`backup.settingsSaved`))}catch(e){t(n(`backup.failedToSave`,{message:e instanceof Error?e.message:`Unknown error`}),`error`)}xe()},fallback:5}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray-light mt-1`,children:n(`backup.retentionDescription`)})]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`backup.outputPath`)}),(0,Y.jsx)(`input`,{type:`text`,value:ye,onChange:e=>be(e.target.value),className:`w-full h-10 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,onBlur:async()=>{try{await r.updateSettings({local_backup_path:ye}),t(n(`backup.settingsSaved`))}catch(e){t(n(`backup.failedToSave`,{message:e instanceof Error?e.message:`Unknown error`}),`error`)}xe(),Ce(),Te()},onKeyDown:e=>{e.key===`Enter`&&e.target.blur()}}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray-light mt-1`,children:ye?n(`backup.outputPathDescription`):(0,Y.jsxs)(Y.Fragment,{children:[n(`backup.defaultPathLabel`),` `,(0,Y.jsx)(`code`,{className:`text-bambu-gray`,children:H?.default_path||`...`})]})}),we&&!we.writable&&(0,Y.jsx)(`div`,{className:`mt-2 p-3 rounded-lg bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30`,children:(0,Y.jsxs)(`div`,{className:`flex items-start gap-2 text-sm`,children:[(0,Y.jsx)(Ie,{className:`w-4 h-4 text-red-600 dark:text-red-400 mt-0.5 flex-shrink-0`}),(0,Y.jsxs)(`div`,{className:`min-w-0 text-red-800 dark:text-red-200`,children:[(0,Y.jsx)(`p`,{className:`font-medium`,children:n(`backup.pathCheck.title`)}),(0,Y.jsx)(`p`,{className:`mt-1 text-red-800/80 dark:text-red-200/80`,children:n(`backup.pathCheck.${we.code}`,{path:we.path,defaultValue:we.message})}),we.remedy&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`p`,{className:`mt-2 font-medium`,children:n(`backup.pathCheck.howToFix`)}),(0,Y.jsx)(`pre`,{className:`mt-1 p-2 rounded bg-black/10 dark:bg-black/40 text-xs whitespace-pre-wrap break-words`,children:we.remedy})]}),we.detail&&(0,Y.jsx)(`p`,{className:`mt-2 text-xs text-red-800/60 dark:text-red-200/60 break-words`,children:we.detail})]})]})}),we?.writable&&we.warning===`container_ephemeral`&&(0,Y.jsx)(`div`,{className:`mt-2 p-3 rounded-lg bg-yellow-50 dark:bg-yellow-500/10 border border-yellow-300 dark:border-yellow-500/30`,children:(0,Y.jsxs)(`div`,{className:`flex items-start gap-2 text-sm`,children:[(0,Y.jsx)(Ie,{className:`w-4 h-4 text-yellow-600 dark:text-yellow-400 mt-0.5 flex-shrink-0`}),(0,Y.jsxs)(`div`,{className:`min-w-0 text-yellow-800 dark:text-yellow-200`,children:[(0,Y.jsx)(`p`,{className:`font-medium`,children:n(`backup.pathCheck.ephemeralTitle`)}),(0,Y.jsx)(`p`,{className:`mt-1 text-yellow-800/80 dark:text-yellow-200/80`,children:n(`backup.pathCheck.container_ephemeral`,{path:we.path})}),we.remedy&&(0,Y.jsx)(`pre`,{className:`mt-1 p-2 rounded bg-black/10 dark:bg-black/40 text-xs whitespace-pre-wrap break-words`,children:we.remedy})]})]})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between py-3 border-t border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{className:`text-sm`,children:[H?.last_backup_at&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray`,children:[(0,Y.jsxs)(`span`,{children:[n(`backup.lastBackup`),`:`]}),(0,Y.jsx)(Li,{status:H.last_status}),(0,Y.jsx)(`span`,{children:Ue(H.last_backup_at)})]}),H?.next_run&&(0,Y.jsxs)(`div`,{className:`text-bambu-gray mt-1`,children:[(0,Y.jsxs)(`span`,{children:[n(`backup.nextBackup`),`: `]}),(0,Y.jsx)(`span`,{children:Ii(H.next_run)})]})]}),(0,Y.jsxs)(K,{variant:`secondary`,size:`sm`,disabled:H?.is_running||Ee.isPending,onClick:()=>Ee.mutate(),children:[H?.is_running||Ee.isPending?(0,Y.jsx)(R,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(De,{className:`w-4 h-4`}),H?.is_running?n(`backup.backupRunning`):n(`backup.runNow`)]})]}),Se&&Se.length>0&&(0,Y.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary pt-3`,children:[(0,Y.jsx)(`h3`,{className:`text-sm font-medium text-white mb-2`,children:n(`backup.backupFiles`)}),(0,Y.jsx)(`div`,{className:`space-y-1`,children:Se.map(e=>(0,Y.jsxs)(`div`,{className:`flex items-center justify-between py-1.5 px-2 rounded hover:bg-bambu-dark-tertiary/50 text-sm`,children:[(0,Y.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Y.jsx)(`span`,{className:`text-white truncate block`,children:e.filename}),(0,Y.jsxs)(`span`,{className:`text-bambu-gray text-xs`,children:[(e.size/1024/1024).toFixed(1),` MB · `,Ii(e.created_at)]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1 flex-shrink-0`,children:[(0,Y.jsx)(`button`,{className:`text-bambu-gray hover:text-bambu-green p-1`,title:n(`backup.download`),onClick:async()=>{try{let{blob:t,filename:n}=await r.downloadLocalBackup(e.filename),i=URL.createObjectURL(t),a=document.createElement(`a`);a.href=i,a.download=n,a.click(),URL.revokeObjectURL(i)}catch{t(n(`backup.scheduledBackupFailed`),`error`)}},children:(0,Y.jsx)(sn,{className:`w-3.5 h-3.5`})}),(0,Y.jsx)(`button`,{className:`text-bambu-gray hover:text-yellow-600 dark:hover:text-yellow-400 p-1`,title:n(`backup.restore`),onClick:()=>ve(e.filename),children:(0,Y.jsx)(nt,{className:`w-3.5 h-3.5`})}),(0,Y.jsx)(`button`,{className:`text-bambu-gray hover:text-red-600 dark:hover:text-red-400 p-1`,onClick:()=>ge(e.filename),title:n(`backup.deleteBackup`),children:(0,Y.jsx)(qe,{className:`w-3.5 h-3.5`})})]})]},e.filename))})]}),Se&&Se.length===0&&(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray text-center py-3 border-t border-bambu-dark-tertiary`,children:n(`backup.noScheduledBackups`)})]})]})]})]}),pe&&(0,Y.jsx)(Fi,{onClose:()=>me(!1)}),he&&(0,Y.jsx)(Tt,{title:n(`backup.deleteBackup`),message:n(`backup.deleteBackupConfirm`),confirmText:n(`backup.deleteBackup`),variant:`danger`,onConfirm:()=>Oe.mutate(he),onCancel:()=>ge(null)}),_e&&(0,Y.jsx)(Tt,{title:n(`backup.restoreConfirmTitle`),message:n(`backup.restoreConfirmMessage`,{filename:_e}),confirmText:n(`backup.restoreConfirmButton`),variant:`danger`,onConfirm:()=>ke.mutate(_e),onCancel:()=>ve(null)}),B&&le&&(0,Y.jsx)(Tt,{title:n(`backup.restoreConfirmTitle`),message:n(`backup.restoreConfirmMessage`,{filename:le.name}),confirmText:n(`backup.restoreConfirmButton`),variant:`danger`,onConfirm:async()=>{ce(!1),z(!0),fe(null);try{se(n(`backup.uploadingFile`));let e=await r.importBackup(le);fe(e),e.success?t(n(`backup.backupRestoredRestart`),`success`):t(e.message||n(`backup.failedToRestore`),`error`)}catch(e){let r=e instanceof Error?e.message:n(`backup.failedToRestore`);fe({success:!1,message:r}),t(r,`error`)}finally{z(!1),se(``),ue(null)}},onCancel:()=>{ce(!1),ue(null)}}),(re||ae)&&(0,Y.jsx)(`div`,{className:`fixed inset-0 bg-black/80 flex items-center justify-center z-[100]`,children:(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl p-8 max-w-md w-full mx-4 text-center`,children:[(0,Y.jsx)(`div`,{className:`flex justify-center mb-4`,children:(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsx)(`div`,{className:`w-16 h-16 border-4 border-bambu-dark-tertiary rounded-full`}),(0,Y.jsx)(`div`,{className:`w-16 h-16 border-4 border-bambu-green border-t-transparent rounded-full absolute inset-0 animate-spin`})]})}),(0,Y.jsx)(`h3`,{className:`text-xl font-semibold text-white mb-2`,children:n(re?`backup.creatingBackup`:`backup.restoringBackup`)}),(0,Y.jsx)(`p`,{className:`text-bambu-gray mb-4`,children:oe||n(re?`backup.preparing`:`backup.processing`)}),(0,Y.jsx)(`div`,{className:`p-3 rounded-lg bg-yellow-50 dark:bg-yellow-500/10 border border-yellow-300 dark:border-yellow-500/30`,children:(0,Y.jsxs)(`div`,{className:`flex items-start gap-2 text-sm`,children:[(0,Y.jsx)(Ie,{className:`w-4 h-4 text-yellow-600 dark:text-yellow-400 mt-0.5 flex-shrink-0`}),(0,Y.jsx)(`p`,{className:`text-yellow-800 dark:text-yellow-200 text-left`,children:n(`backup.doNotClosePage`)})]})})]})})]})}function Wi(e){let t=e.trim();if(t===``)return!0;if(/\s/.test(t)||!/^https?:\/\/[^\s/?#]/i.test(t))return!1;try{return new URL(t).hostname!==``}catch{return!1}}function Gi(){let{t:e}=l(),t=u(),{showToast:n}=ee(),[i,a]=(0,X.useState)(!1),[o,s]=(0,X.useState)(``),[c,p]=(0,X.useState)(``),[m,h]=(0,X.useState)(``),[g,_]=(0,X.useState)(`medium`),[v,y]=(0,X.useState)(`notify`),[b,x]=(0,X.useState)(10),[S,C]=(0,X.useState)(null),[w,E]=(0,X.useState)(null),[D,O]=(0,X.useState)(!1),k=Wi(c),{data:j}=d({queryKey:[`settings`],queryFn:r.getSettings}),{data:M,refetch:N}=d({queryKey:[`obico-status`],queryFn:r.getObicoStatus,refetchInterval:1e4}),{data:P}=d({queryKey:[`printers`],queryFn:r.getPrinters});(0,X.useEffect)(()=>{if(j){a(j.obico_enabled??!1),s(j.obico_ml_url??``),p(j.bambuddy_internal_url??``),h(j.obico_ml_token??``),_(j.obico_sensitivity??`medium`),y(j.obico_action??`notify`),x(j.obico_poll_interval??10);try{let e=j.obico_enabled_printers?JSON.parse(j.obico_enabled_printers):null;C(Array.isArray(e)?e:null)}catch{C(null)}O(!0)}},[j]);let te=f({mutationFn:()=>r.updateSettings({obico_enabled:i,obico_ml_url:o,...k?{bambuddy_internal_url:c.trim()}:{},obico_ml_token:m,obico_sensitivity:g,obico_action:v,obico_poll_interval:b,obico_enabled_printers:S===null?``:JSON.stringify(S)}),onSuccess:()=>{t.invalidateQueries({queryKey:[`settings`]}),t.invalidateQueries({queryKey:[`obico-status`]}),t.invalidateQueries({queryKey:[`obico-printer-status`]}),n(e(`settings.toast.settingsSaved`))}}),F=(0,X.useMemo)(()=>!D||!j?!1:j.obico_enabled!==i||j.obico_ml_url!==o||k&&(j.bambuddy_internal_url??``)!==c.trim()||(j.obico_ml_token??``)!==m||j.obico_sensitivity!==g||j.obico_action!==v||j.obico_poll_interval!==b||j.obico_enabled_printers!==(S===null?``:JSON.stringify(S)),[j,D,i,o,c,k,m,g,v,b,S]);(0,X.useEffect)(()=>{if(!F)return;let e=setTimeout(()=>te.mutate(),500);return()=>clearTimeout(e)},[F,i,o,c,m,g,v,b,S]);let ne=async()=>{E(null);try{F&&await te.mutateAsync();let t=await r.testObicoConnection(o,m);t.ok?E({ok:!0,message:t.auth_ok===null?e(`failureDetection.testSuccessTokenUnknown`):e(`failureDetection.testSuccess`)}):E({ok:!1,message:t.error||`HTTP ${t.status_code??`?`} — ${t.body??e(`failureDetection.testFailed`)}`})}catch(e){E({ok:!1,message:e instanceof Error?e.message:String(e)})}},I=(e,t)=>{if(S===null){let n=P?.map(e=>e.id)??[];C(t?n:n.filter(t=>t!==e));return}C(t?[...S,e]:S.filter(t=>t!==e))};return(0,Y.jsxs)(`div`,{className:`flex flex-col lg:flex-row gap-4 lg:gap-6`,children:[(0,Y.jsxs)(`div`,{className:`space-y-3 flex-1 lg:max-w-xl`,children:[(0,Y.jsxs)(G,{id:`card-fd-ml`,children:[(0,Y.jsxs)(U,{children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(Se,{className:`w-5 h-5 text-bambu-green`}),(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`failureDetection.title`)})]}),(0,Y.jsx)(J,{checked:i,onChange:a})]}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray mt-2`,children:e(`failureDetection.description`)})]}),(0,Y.jsxs)(W,{className:`space-y-4`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:e(`failureDetection.mlUrl`)}),(0,Y.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Y.jsx)(`input`,{type:`text`,value:o,onChange:e=>s(e.target.value),placeholder:`http://192.168.1.10:3333`,className:`flex-1 bg-gray-800 border border-gray-700 rounded px-3 py-2 text-white text-sm`,disabled:!i}),(0,Y.jsx)(K,{onClick:ne,disabled:!o||te.isPending,variant:`secondary`,children:e(`failureDetection.test`)})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`failureDetection.mlUrlHint`)}),(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1 mt-3`,children:e(`failureDetection.mlToken`)}),(0,Y.jsx)(`input`,{type:`password`,value:m,onChange:e=>h(e.target.value),autoComplete:`off`,placeholder:e(`failureDetection.mlTokenPlaceholder`),className:`w-full bg-gray-800 border border-gray-700 rounded px-3 py-2 text-white text-sm`,disabled:!i}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`failureDetection.mlTokenHint`)}),w&&(0,Y.jsxs)(`div`,{className:`flex items-start gap-2 mt-2 text-sm ${w.ok?`text-green-700 dark:text-green-400`:`text-red-700 dark:text-red-400`}`,children:[w.ok?(0,Y.jsx)(T,{className:`w-4 h-4 mt-0.5`}):(0,Y.jsx)(Re,{className:`w-4 h-4 mt-0.5`}),(0,Y.jsx)(`span`,{children:w.message})]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:e(`failureDetection.bambuddyInternalUrl`)}),(0,Y.jsx)(`input`,{type:`text`,value:c,onChange:e=>p(e.target.value),placeholder:`http://bambuddy:8000`,className:`w-full bg-gray-800 border border-gray-700 rounded px-3 py-2 text-white text-sm`,disabled:!i,"aria-invalid":!k}),!k&&(0,Y.jsx)(`p`,{className:`text-xs text-red-700 dark:text-red-400 mt-1`,children:e(`failureDetection.bambuddyInternalUrlInvalid`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`failureDetection.bambuddyInternalUrlHint`)})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:e(`failureDetection.sensitivity`)}),(0,Y.jsxs)(`select`,{value:g,onChange:e=>_(e.target.value),disabled:!i,className:`w-full bg-gray-800 border border-gray-700 rounded px-3 py-2 text-white text-sm`,children:[(0,Y.jsx)(`option`,{value:`low`,children:e(`failureDetection.sensitivityLow`)}),(0,Y.jsx)(`option`,{value:`medium`,children:e(`failureDetection.sensitivityMedium`)}),(0,Y.jsx)(`option`,{value:`high`,children:e(`failureDetection.sensitivityHigh`)})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`failureDetection.sensitivityHint`)})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:e(`failureDetection.action`)}),(0,Y.jsxs)(`select`,{value:v,onChange:e=>y(e.target.value),disabled:!i,className:`w-full bg-gray-800 border border-gray-700 rounded px-3 py-2 text-white text-sm`,children:[(0,Y.jsx)(`option`,{value:`notify`,children:e(`failureDetection.actionNotify`)}),(0,Y.jsx)(`option`,{value:`pause`,children:e(`failureDetection.actionPause`)}),(0,Y.jsx)(`option`,{value:`pause_and_off`,children:e(`failureDetection.actionPauseOff`)})]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:e(`failureDetection.pollInterval`)}),(0,Y.jsx)(ct,{value:b,onChange:x,fallback:10,min:5,max:120,disabled:!i,className:`w-full bg-gray-800 border border-gray-700 rounded px-3 py-2 text-white text-sm`}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`failureDetection.pollIntervalHint`)})]}),M&&!M.external_url_configured&&i&&(0,Y.jsxs)(`div`,{className:`flex items-start gap-2 p-3 bg-amber-50 dark:bg-amber-900/30 border border-amber-300 dark:border-amber-700 rounded text-sm text-amber-800 dark:text-amber-200`,children:[(0,Y.jsx)(Ie,{className:`w-4 h-4 mt-0.5 flex-shrink-0`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`font-medium`,children:e(`failureDetection.externalUrlMissing`)}),(0,Y.jsx)(`div`,{className:`text-xs mt-1`,children:e(`failureDetection.externalUrlHint`)})]})]})]})]}),(0,Y.jsxs)(G,{id:`card-fd-perprinter`,children:[(0,Y.jsxs)(U,{children:[(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`failureDetection.perPrinterTitle`)}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:e(`failureDetection.perPrinterHint`)})]}),(0,Y.jsxs)(W,{className:`space-y-2`,children:[(0,Y.jsxs)(`label`,{className:`flex items-center gap-2 text-sm`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:S===null,onChange:e=>C(e.target.checked?null:P?.map(e=>e.id)??[]),disabled:!i}),(0,Y.jsx)(`span`,{className:`text-white`,children:e(`failureDetection.monitorAll`)})]}),S!==null&&P&&(0,Y.jsx)(`div`,{className:`pl-5 space-y-1 border-l border-gray-700`,children:P.map(e=>(0,Y.jsxs)(`label`,{className:`flex items-center gap-2 text-sm`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:S.includes(e.id),onChange:t=>I(e.id,t.target.checked),disabled:!i}),(0,Y.jsx)(`span`,{className:`text-white`,children:e.name})]},e.id))})]})]})]}),(0,Y.jsxs)(`div`,{className:`space-y-3 flex-1 lg:max-w-xl`,children:[(0,Y.jsxs)(G,{id:`card-fd-status`,children:[(0,Y.jsx)(U,{children:(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`failureDetection.statusTitle`)})}),(0,Y.jsx)(W,{children:M?(0,Y.jsxs)(`div`,{className:`space-y-3 text-sm`,children:[(0,Y.jsxs)(`div`,{className:`flex justify-between`,children:[(0,Y.jsx)(`span`,{className:`text-bambu-gray`,children:e(`failureDetection.serviceRunning`)}),(0,Y.jsx)(`span`,{className:M.is_running?`text-green-700 dark:text-green-400`:`text-red-700 dark:text-red-400`,children:M.is_running?e(`common.yes`):e(`common.no`)})]}),(0,Y.jsxs)(`div`,{className:`flex justify-between`,children:[(0,Y.jsx)(`span`,{className:`text-bambu-gray`,children:e(`failureDetection.thresholds`)}),(0,Y.jsxs)(`span`,{className:`text-white font-mono`,children:[M.thresholds.low.toFixed(2),` / `,M.thresholds.high.toFixed(2)]})]}),M.last_error&&(0,Y.jsxs)(`div`,{className:`flex items-start gap-2 text-red-700 dark:text-red-400`,children:[(0,Y.jsx)(Re,{className:`w-4 h-4 mt-0.5 flex-shrink-0`}),(0,Y.jsx)(`span`,{className:`break-words`,children:M.last_error})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`text-bambu-gray mb-1`,children:e(`failureDetection.activePrinters`)}),Object.keys(M.per_printer).length===0?(0,Y.jsx)(`div`,{className:`text-bambu-gray italic text-xs`,children:e(`failureDetection.noActivePrints`)}):(0,Y.jsx)(`div`,{className:`space-y-1`,children:Object.entries(M.per_printer).map(([e,t])=>{let n=P?.find(t=>String(t.id)===e),r=t.class===`failure`?`text-red-700 dark:text-red-400`:t.class===`warning`?`text-amber-700 dark:text-amber-400`:`text-green-700 dark:text-green-400`;return(0,Y.jsxs)(`div`,{className:`flex justify-between`,children:[(0,Y.jsx)(`span`,{className:`text-white`,children:n?.name??`Printer ${e}`}),(0,Y.jsxs)(`span`,{className:`font-mono ${r}`,children:[t.class,` (`,t.score.toFixed(3),`, `,t.frame_count,`f)`]})]},e)})})]})]}):(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray`,children:[(0,Y.jsx)(R,{className:`w-4 h-4 animate-spin`}),(0,Y.jsx)(`span`,{children:e(`common.loading`)})]})})]}),(0,Y.jsxs)(G,{id:`card-fd-history`,children:[(0,Y.jsx)(U,{children:(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`failureDetection.historyTitle`)}),(0,Y.jsx)(`button`,{onClick:()=>N(),className:`text-xs text-bambu-gray hover:text-white`,children:e(`common.refresh`)})]})}),(0,Y.jsx)(W,{children:!M||M.history.length===0?(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray text-sm`,children:[(0,Y.jsx)(A,{className:`w-4 h-4`}),(0,Y.jsx)(`span`,{children:e(`failureDetection.noHistory`)})]}):(0,Y.jsx)(`div`,{className:`space-y-1 max-h-96 overflow-y-auto text-xs font-mono`,children:M.history.map((e,t)=>{let n=P?.find(t=>t.id===e.printer_id),r=e.class===`failure`?`text-red-700 dark:text-red-400`:e.class===`warning`?`text-amber-700 dark:text-amber-400`:`text-bambu-gray`;return(0,Y.jsxs)(`div`,{className:`flex justify-between gap-2 py-1 border-b border-gray-800`,children:[(0,Y.jsx)(`span`,{className:`text-bambu-gray`,children:new Date(e.timestamp).toLocaleTimeString()}),(0,Y.jsx)(`span`,{className:`text-white truncate`,children:n?.name??`#${e.printer_id}`}),(0,Y.jsxs)(`span`,{className:r,children:[e.class,` `,e.score.toFixed(3)]})]},t)})})})]})]})]})}var Ki={starttls:587,ssl:465,none:25},qi={587:`starttls`,465:`ssl`,25:`none`};function Ji(){let{t:e}=l(),{showToast:t}=ee(),n=u(),[i,a]=(0,X.useState)({smtp_host:``,smtp_port:587,smtp_username:``,smtp_password:``,smtp_security:`starttls`,smtp_auth_enabled:!0,smtp_from_email:``,smtp_from_name:`BamBuddy`}),[o,s]=(0,X.useState)(``),{data:c,isLoading:p}=d({queryKey:[`smtpSettings`],queryFn:()=>r.getSMTPSettings()}),{authEnabled:m}=un(),{data:g}=d({queryKey:[`advancedAuthStatus`],queryFn:()=>r.getAdvancedAuthStatus()});(0,X.useEffect)(()=>{c&&a({...c,smtp_password:``})},[c]);let _=e=>{a({...i,smtp_security:e,smtp_port:Ki[e]})},v=e=>{let t=qi[e];a({...i,smtp_port:e,...t?{smtp_security:t}:{}})},y=e=>{a({...i,smtp_auth_enabled:e,...e?{}:{smtp_username:``,smtp_password:``}})},b=f({mutationFn:e=>r.saveSMTPSettings(e),onSuccess:()=>{n.invalidateQueries({queryKey:[`smtpSettings`]}),n.invalidateQueries({queryKey:[`advancedAuthStatus`]}),t(e(`settings.email.success.settingsSaved`),`success`)},onError:e=>{t(e.message,`error`)}}),x=f({mutationFn:e=>r.testSMTP(e),onSuccess:e=>{t(e.message,e.success?`success`:`error`)},onError:e=>{t(e.message,`error`)}}),S=f({mutationFn:e=>e?r.enableAdvancedAuth():r.disableAdvancedAuth(),onSuccess:e=>{n.invalidateQueries({queryKey:[`advancedAuthStatus`]}),t(e.message,`success`)},onError:e=>{t(e.message,`error`)}}),C=()=>{if(!i.smtp_host||!i.smtp_from_email){t(e(`settings.email.errors.requiredFields`),`error`);return}if(i.smtp_auth_enabled&&!i.smtp_username){t(e(`settings.email.errors.usernameRequired`),`error`);return}b.mutate(i)},w=()=>{if(!o){t(e(`settings.email.errors.enterTestEmail`),`error`);return}x.mutate({test_recipient:o})},T=()=>{if(!m){t(e(`settings.email.errors.enableAuthFirst`),`error`);return}if(!g?.advanced_auth_enabled&&!g?.smtp_configured){t(e(`settings.email.errors.configureSmtpFirst`),`error`);return}S.mutate(!g?.advanced_auth_enabled)};if(p)return(0,Y.jsx)(`div`,{className:`flex items-center justify-center p-12`,children:(0,Y.jsx)(R,{className:`w-8 h-8 animate-spin text-bambu-green`})});let E=g?.advanced_auth_enabled??!1,D=`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,O=`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white/40 placeholder-bambu-gray/40 cursor-not-allowed`;return(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsxs)(G,{id:`card-email-advanced-auth`,children:[(0,Y.jsx)(U,{children:(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(Vt,{className:`w-5 h-5 text-bambu-green`}),(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`settings.email.advancedAuth`)||`Advanced Authentication`})]}),(0,Y.jsx)(K,{onClick:T,disabled:S.isPending,variant:E?`danger`:`primary`,children:E?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(h,{className:`w-4 h-4`}),e(`settings.email.disable`)||`Disable`]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(z,{className:`w-4 h-4`}),e(`settings.email.enable`)||`Enable`]})})]})}),(0,Y.jsx)(W,{children:(0,Y.jsx)(`div`,{className:`space-y-3`,children:E?(0,Y.jsx)(`div`,{className:`bg-green-50 dark:bg-green-500/10 border border-green-300 dark:border-green-500/30 rounded-lg p-4`,children:(0,Y.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,Y.jsx)(j,{className:`w-5 h-5 text-green-600 dark:text-green-400 mt-0.5 flex-shrink-0`}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(`p`,{className:`text-white font-medium`,children:e(`settings.email.advancedAuthEnabled`)||`Advanced Authentication is enabled`}),(0,Y.jsxs)(`ul`,{className:`text-sm text-green-700 dark:text-green-300 space-y-1 list-disc list-inside`,children:[(0,Y.jsx)(`li`,{children:e(`settings.email.feature1`)||`Passwords are auto-generated and emailed to new users`}),(0,Y.jsx)(`li`,{children:e(`settings.email.feature2`)||`Users can login with username or email`}),(0,Y.jsx)(`li`,{children:e(`settings.email.feature3`)||`Forgot password feature is available`}),(0,Y.jsx)(`li`,{children:e(`settings.email.feature4`)||`Admins can reset user passwords via email`})]})]})]})}):(0,Y.jsx)(`div`,{className:`bg-yellow-50 dark:bg-yellow-500/10 border border-yellow-300 dark:border-yellow-500/30 rounded-lg p-4`,children:(0,Y.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,Y.jsx)(Ie,{className:`w-5 h-5 text-yellow-600 dark:text-yellow-400 mt-0.5 flex-shrink-0`}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(`p`,{className:`text-white font-medium`,children:e(`settings.email.advancedAuthDisabled`)||`Advanced Authentication is disabled`}),(0,Y.jsx)(`p`,{className:`text-sm text-yellow-700 dark:text-yellow-300`,children:e(`settings.email.advancedAuthDisabledDesc`)||`Enable advanced authentication to activate email-based features for user management.`})]})]})})})})]}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-3 gap-4`,children:[(0,Y.jsx)(`div`,{className:`lg:col-span-2`,children:(0,Y.jsxs)(G,{id:`card-smtp-config`,children:[(0,Y.jsx)(U,{children:(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`settings.email.smtpSettings`)||`SMTP Configuration`})}),(0,Y.jsx)(W,{children:(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:e(`settings.email.authentication`)||`Authentication`}),(0,Y.jsxs)(`select`,{value:i.smtp_auth_enabled?`true`:`false`,onChange:e=>y(e.target.value===`true`),className:D,children:[(0,Y.jsx)(`option`,{value:`true`,children:e(`settings.email.authOptions.enabled`)}),(0,Y.jsx)(`option`,{value:`false`,children:e(`settings.email.authOptions.disabled`)})]})]}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4 transition-opacity ${i.smtp_auth_enabled?``:`opacity-40 pointer-events-none`}`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:e(`settings.email.username`)||`Username`}),(0,Y.jsx)(`input`,{type:`text`,value:i.smtp_username||``,onChange:e=>a({...i,smtp_username:e.target.value}),placeholder:`your.email@gmail.com`,disabled:!i.smtp_auth_enabled,className:i.smtp_auth_enabled?D:O})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:e(`settings.email.password`)||`Password`}),(0,Y.jsx)(`input`,{type:`password`,value:i.smtp_password||``,onChange:e=>a({...i,smtp_password:e.target.value}),placeholder:c?`••••••••`:`App password`,disabled:!i.smtp_auth_enabled,className:i.smtp_auth_enabled?D:O})]})]}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:[e(`settings.email.smtpHost`)||`SMTP Server`,` *`]}),(0,Y.jsx)(`input`,{type:`text`,value:i.smtp_host,onChange:e=>a({...i,smtp_host:e.target.value}),placeholder:`smtp.gmail.com`,className:D})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:e(`settings.email.smtpPort`)||`SMTP Port`}),(0,Y.jsx)(ct,{value:i.smtp_port,onChange:v,min:1,max:65535,fallback:587,placeholder:`587`,className:D})]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:e(`settings.email.security`)||`Security`}),(0,Y.jsxs)(`select`,{value:i.smtp_security,onChange:e=>_(e.target.value),className:D,children:[(0,Y.jsx)(`option`,{value:`starttls`,children:e(`settings.email.securityOptions.starttls`)}),(0,Y.jsx)(`option`,{value:`ssl`,children:e(`settings.email.securityOptions.ssl`)}),(0,Y.jsx)(`option`,{value:`none`,children:e(`settings.email.securityOptions.none`)})]})]}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:[e(`settings.email.fromEmail`)||`From Email`,` *`]}),(0,Y.jsx)(`input`,{type:`email`,value:i.smtp_from_email,onChange:e=>a({...i,smtp_from_email:e.target.value}),placeholder:`your@email.com`,className:D})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:e(`settings.email.fromName`)||`From Name`}),(0,Y.jsx)(`input`,{type:`text`,value:i.smtp_from_name,onChange:e=>a({...i,smtp_from_name:e.target.value}),placeholder:`BamBuddy`,className:D})]})]}),(0,Y.jsx)(`div`,{className:`flex gap-2`,children:(0,Y.jsx)(K,{onClick:C,disabled:b.isPending,className:`flex-1`,children:b.isPending?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(R,{className:`w-4 h-4 animate-spin`}),e(`settings.email.saving`)||`Saving...`]}):e(`settings.email.save`)||`Save Settings`})})]})})]})}),(0,Y.jsx)(`div`,{children:(0,Y.jsxs)(G,{id:`card-email-test`,children:[(0,Y.jsx)(U,{children:(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`settings.email.testConnection`)||`Test SMTP Connection`})}),(0,Y.jsx)(W,{children:(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:e(`settings.email.testRecipient`)||`Test Recipient Email`}),(0,Y.jsx)(`input`,{type:`email`,value:o,onChange:e=>s(e.target.value),placeholder:`test@example.com`,className:D})]}),(0,Y.jsx)(K,{onClick:w,disabled:x.isPending,variant:`secondary`,children:x.isPending?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(R,{className:`w-4 h-4 animate-spin`}),e(`settings.email.sending`)||`Sending...`]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(Sn,{className:`w-4 h-4`}),e(`settings.email.sendTest`)||`Send Test Email`]})})]})})]})})]})]})}var Yi={starttls:`389`,ldaps:`636`};function Xi(){let{t:e}=l(),{showToast:t}=ee(),n=u(),{authEnabled:i}=un(),[a,o]=(0,X.useState)({ldap_server_url:``,ldap_bind_dn:``,ldap_bind_password:``,ldap_search_base:``,ldap_user_filter:`(sAMAccountName={username})`,ldap_security:`starttls`,ldap_group_mapping:``,ldap_auto_provision:!1,ldap_default_group:``}),{data:s,isLoading:c}=d({queryKey:[`settings`],queryFn:()=>r.getSettings()}),{data:p}=d({queryKey:[`ldapStatus`],queryFn:()=>r.getLDAPStatus()}),{data:m=[]}=d({queryKey:[`groups`],queryFn:()=>r.getGroups()});(0,X.useEffect)(()=>{s&&o({ldap_server_url:s.ldap_server_url||``,ldap_bind_dn:s.ldap_bind_dn||``,ldap_bind_password:``,ldap_search_base:s.ldap_search_base||``,ldap_user_filter:s.ldap_user_filter||`(sAMAccountName={username})`,ldap_security:s.ldap_security||`starttls`,ldap_group_mapping:s.ldap_group_mapping||``,ldap_auto_provision:s.ldap_auto_provision??!1,ldap_default_group:s.ldap_default_group||``})},[s]);let g=f({mutationFn:e=>r.updateSettings(e),onSuccess:()=>{n.invalidateQueries({queryKey:[`settings`]}),n.invalidateQueries({queryKey:[`ldapStatus`]}),t(e(`settings.ldap.settingsSaved`)||`LDAP settings saved`,`success`)},onError:e=>{t(e.message,`error`)}}),_=f({mutationFn:e=>r.updateSettings({ldap_enabled:e}),onSuccess:()=>{n.invalidateQueries({queryKey:[`settings`]}),n.invalidateQueries({queryKey:[`ldapStatus`]}),t(p?.ldap_enabled?e(`settings.ldap.disabled`)||`LDAP authentication disabled`:e(`settings.ldap.enabled`)||`LDAP authentication enabled`,`success`)},onError:e=>{t(e.message,`error`)}}),v=f({mutationFn:()=>r.testLDAP(),onSuccess:e=>{t(e.message,e.success?`success`:`error`)},onError:e=>{t(e.message,`error`)}}),y=()=>{if(!a.ldap_server_url){t(e(`settings.ldap.errors.serverRequired`)||`LDAP server URL is required`,`error`);return}if(!a.ldap_search_base){t(e(`settings.ldap.errors.searchBaseRequired`)||`Search base DN is required`,`error`);return}let n={ldap_server_url:a.ldap_server_url,ldap_bind_dn:a.ldap_bind_dn,ldap_search_base:a.ldap_search_base,ldap_user_filter:a.ldap_user_filter,ldap_security:a.ldap_security,ldap_group_mapping:a.ldap_group_mapping,ldap_auto_provision:a.ldap_auto_provision,ldap_default_group:a.ldap_default_group};a.ldap_bind_password&&(n.ldap_bind_password=a.ldap_bind_password),g.mutate(n)},b=()=>{if(!i){t(e(`settings.ldap.errors.enableAuthFirst`)||`Enable authentication first`,`error`);return}if(!p?.ldap_enabled&&!p?.ldap_configured){t(e(`settings.ldap.errors.configureLdapFirst`)||`Save LDAP settings first`,`error`);return}_.mutate(!p?.ldap_enabled)};if(c)return(0,Y.jsx)(`div`,{className:`flex items-center justify-center p-12`,children:(0,Y.jsx)(R,{className:`w-8 h-8 animate-spin text-bambu-green`})});let x=p?.ldap_enabled??!1,S=`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`;return(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsxs)(G,{id:`card-ldap-toggle`,children:[(0,Y.jsx)(U,{children:(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(Me,{className:`w-5 h-5 text-bambu-green`}),(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`settings.ldap.title`)||`LDAP Authentication`})]}),(0,Y.jsx)(K,{onClick:b,disabled:_.isPending,variant:x?`danger`:`primary`,children:x?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(h,{className:`w-4 h-4`}),e(`common.disable`)||`Disable`]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(z,{className:`w-4 h-4`}),e(`common.enable`)||`Enable`]})})]})}),(0,Y.jsx)(W,{children:x?(0,Y.jsx)(`div`,{className:`bg-green-50 dark:bg-green-500/10 border border-green-300 dark:border-green-500/30 rounded-lg p-4`,children:(0,Y.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,Y.jsx)(j,{className:`w-5 h-5 text-green-600 dark:text-green-400 mt-0.5 flex-shrink-0`}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(`p`,{className:`text-white font-medium`,children:e(`settings.ldap.enabledDesc`)||`LDAP authentication is enabled`}),(0,Y.jsxs)(`ul`,{className:`text-sm text-green-700 dark:text-green-300 space-y-1 list-disc list-inside`,children:[(0,Y.jsx)(`li`,{children:e(`settings.ldap.feature1`)||`Users can login with LDAP credentials`}),(0,Y.jsx)(`li`,{children:e(`settings.ldap.feature2`)||`Local admin account remains as fallback`}),(0,Y.jsx)(`li`,{children:e(`settings.ldap.feature3`)||`LDAP groups are mapped to BamBuddy groups on login`})]})]})]})}):(0,Y.jsx)(`div`,{className:`bg-yellow-50 dark:bg-yellow-500/10 border border-yellow-300 dark:border-yellow-500/30 rounded-lg p-4`,children:(0,Y.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,Y.jsx)(Ie,{className:`w-5 h-5 text-yellow-600 dark:text-yellow-400 mt-0.5 flex-shrink-0`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-white font-medium`,children:e(`settings.ldap.disabledDesc`)||`LDAP authentication is disabled`}),(0,Y.jsx)(`p`,{className:`text-sm text-yellow-700 dark:text-yellow-300 mt-1`,children:e(`settings.ldap.disabledHint`)||`Configure and save LDAP settings below, then enable.`})]})]})})})]}),(0,Y.jsxs)(G,{id:`card-ldap-server`,children:[(0,Y.jsx)(U,{children:(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`settings.ldap.serverConfig`)||`LDAP Server Configuration`})}),(0,Y.jsx)(W,{children:(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-3`,children:[(0,Y.jsxs)(`div`,{className:`md:col-span-2`,children:[(0,Y.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:e(`settings.ldap.serverUrl`)||`Server URL`}),(0,Y.jsx)(`input`,{type:`text`,className:S,placeholder:`ldaps://ldap.example.com:636`,value:a.ldap_server_url,onChange:e=>o({...a,ldap_server_url:e.target.value})}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`settings.ldap.serverUrlHint`)||`Use ldaps:// for SSL or ldap:// with StartTLS`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:e(`settings.ldap.security`)||`Security`}),(0,Y.jsx)(`div`,{className:`flex gap-2`,children:[`starttls`,`ldaps`].map(e=>(0,Y.jsx)(`button`,{onClick:()=>o({...a,ldap_security:e}),className:`flex-1 px-2 py-2 rounded-lg text-sm font-medium transition-colors ${a.ldap_security===e?`bg-bambu-green text-black`:`bg-bambu-dark-secondary text-bambu-gray hover:text-white border border-bambu-dark-tertiary`}`,children:e===`starttls`?`StartTLS`:`LDAPS`},e))}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`settings.ldap.securityHint`)||`Default port: ${Yi[a.ldap_security]}`})]})]}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:e(`settings.ldap.bindDn`)||`Bind DN (Service Account)`}),(0,Y.jsx)(`input`,{type:`text`,className:S,placeholder:`cn=service-account,ou=service,dc=example,dc=com`,value:a.ldap_bind_dn,onChange:e=>o({...a,ldap_bind_dn:e.target.value})})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:e(`settings.ldap.bindPassword`)||`Bind Password`}),(0,Y.jsx)(`input`,{type:`password`,className:S,placeholder:s?.ldap_bind_dn?`••••••••`:``,value:a.ldap_bind_password,onChange:e=>o({...a,ldap_bind_password:e.target.value})})]})]}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:e(`settings.ldap.searchBase`)||`Search Base DN`}),(0,Y.jsx)(`input`,{type:`text`,className:S,placeholder:`ou=users,dc=example,dc=com`,value:a.ldap_search_base,onChange:e=>o({...a,ldap_search_base:e.target.value})})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:e(`settings.ldap.userFilter`)||`User Search Filter`}),(0,Y.jsx)(`input`,{type:`text`,className:S,placeholder:`(sAMAccountName={username})`,value:a.ldap_user_filter,onChange:e=>o({...a,ldap_user_filter:e.target.value})})]})]}),(0,Y.jsx)(Rt,{summary:(0,Y.jsx)(`span`,{className:`text-sm font-medium text-bambu-gray`,children:e(`settings.ldap.advanced`)||`Advanced`}),className:`border-t border-bambu-dark-tertiary pt-3`,summaryClassName:`py-1`,children:(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm font-medium text-white`,children:e(`settings.ldap.autoProvision`)||`Auto-provision users`}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:e(`settings.ldap.autoProvisionHint`)||`Automatically create a BamBuddy account on first LDAP login`})]}),(0,Y.jsx)(`button`,{onClick:()=>o({...a,ldap_auto_provision:!a.ldap_auto_provision}),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors flex-shrink-0 ${a.ldap_auto_provision?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,children:(0,Y.jsx)(`span`,{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${a.ldap_auto_provision?`translate-x-6`:`translate-x-1`}`})})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:e(`settings.ldap.defaultGroup`)||`Default group`}),(0,Y.jsxs)(`select`,{className:S,value:a.ldap_default_group,onChange:e=>o({...a,ldap_default_group:e.target.value}),children:[(0,Y.jsx)(`option`,{value:``,children:e(`settings.ldap.defaultGroupNone`)||`— None (reject login) —`}),m.map(e=>(0,Y.jsx)(`option`,{value:e.name,children:e.name},e.id))]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`settings.ldap.defaultGroupHint`)||`Fallback group assigned when an LDAP user authenticates but is not listed in any mapped group. Leave empty to leave unmapped users without permissions.`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:e(`settings.ldap.groupMapping`)||`Group Mapping (JSON)`}),(0,Y.jsx)(`textarea`,{className:`${S} font-mono text-sm`,rows:4,placeholder:`{ "CN=PrintFarm_Admins,OU=Groups,DC=example,DC=com": "Administrators", diff --git a/static/assets/SetupPage-C42DVxS_.js b/static/assets/SetupPage-D-ymjFl3.js similarity index 98% rename from static/assets/SetupPage-C42DVxS_.js rename to static/assets/SetupPage-D-ymjFl3.js index dbfbf837c..1f2510475 100644 --- a/static/assets/SetupPage-C42DVxS_.js +++ b/static/assets/SetupPage-D-ymjFl3.js @@ -1 +1 @@ -import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,w as i}from"./client-DnySrlFv.js";import{t as a}from"./useMutation-B-Tr2hIP.js";import{t as o}from"./info-ROUoQhJR.js";import{n as s}from"./ToastContext-BRX0SW3C.js";import{Vn as c,vt as l,yt as u}from"./index-0t--Yqoi.js";var d=e(n(),1),f=t();function p(){let e=c(),{t}=i(),{showToast:n}=s(),{mode:p}=l(),{refreshAuth:m}=u(),[h,g]=(0,d.useState)(!1),[_,v]=(0,d.useState)(``),[y,b]=(0,d.useState)(``),[x,S]=(0,d.useState)(``),C=a({mutationFn:()=>r.setupAuth({auth_enabled:h,admin_username:h?_:void 0,admin_password:h?y:void 0}),onSuccess:async r=>{await m(),r.auth_enabled?r.admin_created?(n(t(`setup.toast.authEnabledAdminCreated`)),e(`/login`)):(n(t(`setup.toast.authEnabledExistingAdmins`)),e(`/login`)):(n(t(`setup.toast.setupCompleted`)),e(`/`))},onError:e=>{n(e.message,`error`)}});return(0,f.jsx)(`div`,{className:`min-h-screen flex items-center justify-center bg-bambu-dark p-4`,children:(0,f.jsxs)(`div`,{className:`max-w-md w-full space-y-8 p-8 bg-gradient-to-br from-bambu-card to-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary shadow-lg`,children:[(0,f.jsxs)(`div`,{className:`text-center`,children:[(0,f.jsx)(`div`,{className:`flex items-center justify-center mb-6`,children:(0,f.jsx)(`img`,{src:p===`dark`?`/img/bambuddy_logo_dark_transparent.png`:`/img/bambuddy_logo_light.png`,alt:`Bambuddy`,className:`h-16`})}),(0,f.jsx)(`h2`,{className:`text-3xl font-bold text-white`,children:t(`setup.title`)}),(0,f.jsx)(`p`,{className:`mt-2 text-sm text-bambu-gray`,children:t(`setup.subtitle`)})]}),(0,f.jsxs)(`form`,{className:`mt-8 space-y-6`,onSubmit:e=>{if(e.preventDefault(),h&&(_||y)){if(!_||!y){n(t(`setup.toast.enterBothCredentials`),`error`);return}if(y!==x){n(t(`setup.toast.passwordsDoNotMatch`),`error`);return}if(y.length<6){n(t(`setup.toast.passwordTooShort`),`error`);return}}C.mutate()},children:[(0,f.jsxs)(`div`,{className:`space-y-4`,children:[(0,f.jsxs)(`div`,{className:`flex items-center p-4 bg-bambu-dark-secondary/50 rounded-lg border border-bambu-dark-tertiary`,children:[(0,f.jsx)(`input`,{id:`auth-enabled`,type:`checkbox`,checked:h,onChange:e=>g(e.target.checked),className:`h-4 w-4 text-bambu-green focus:ring-bambu-green border-bambu-dark-tertiary rounded bg-bambu-dark-secondary`}),(0,f.jsx)(`label`,{htmlFor:`auth-enabled`,className:`ml-3 block text-sm font-medium text-white`,children:t(`setup.enableAuth`)})]}),h&&(0,f.jsxs)(`div`,{className:`space-y-4 mt-4`,children:[(0,f.jsx)(`div`,{className:`p-3 bg-bambu-dark-secondary/50 border border-bambu-dark-tertiary rounded-lg`,children:(0,f.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,f.jsx)(o,{className:`w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0`}),(0,f.jsxs)(`div`,{className:`text-sm text-bambu-gray`,children:[(0,f.jsx)(`p`,{className:`text-white font-medium mb-1`,children:t(`setup.adminAccount`)}),(0,f.jsx)(`p`,{children:t(`setup.adminAccountDesc`)})]})]})}),(0,f.jsxs)(`div`,{children:[(0,f.jsxs)(`label`,{htmlFor:`admin-username`,className:`block text-sm font-medium text-white mb-2`,children:[t(`setup.adminUsername`),` `,(0,f.jsx)(`span`,{className:`text-bambu-gray text-xs`,children:t(`setup.optionalIfAdminExists`)})]}),(0,f.jsx)(`input`,{id:`admin-username`,type:`text`,value:_,onChange:e=>v(e.target.value),className:`block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:t(`setup.adminUsernamePlaceholder`),autoComplete:`username`})]}),(0,f.jsxs)(`div`,{children:[(0,f.jsxs)(`label`,{htmlFor:`admin-password`,className:`block text-sm font-medium text-white mb-2`,children:[t(`setup.adminPassword`),` `,(0,f.jsx)(`span`,{className:`text-bambu-gray text-xs`,children:t(`setup.optionalIfAdminExists`)})]}),(0,f.jsx)(`input`,{id:`admin-password`,type:`password`,value:y,onChange:e=>b(e.target.value),className:`block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:t(`setup.adminPasswordPlaceholder`),minLength:6,autoComplete:`new-password`})]}),y&&(0,f.jsxs)(`div`,{children:[(0,f.jsx)(`label`,{htmlFor:`confirm-password`,className:`block text-sm font-medium text-white mb-2`,children:t(`setup.confirmPassword`)}),(0,f.jsx)(`input`,{id:`confirm-password`,type:`password`,value:x,onChange:e=>S(e.target.value),className:`block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:t(`setup.confirmPasswordPlaceholder`),minLength:6,autoComplete:`new-password`})]})]})]}),(0,f.jsx)(`div`,{children:(0,f.jsx)(`button`,{type:`submit`,disabled:C.isPending,className:`w-full flex justify-center py-3 px-4 bg-bambu-green hover:bg-bambu-green-light text-white font-medium rounded-lg shadow-lg shadow-bambu-green/20 hover:shadow-bambu-green/30 focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:ring-offset-2 focus:ring-offset-bambu-dark-secondary transition-all disabled:opacity-50 disabled:cursor-not-allowed disabled:hover:bg-bambu-green`,children:C.isPending?t(`setup.settingUp`):t(`setup.completeSetup`)})})]})]})})}export{p as SetupPage}; \ No newline at end of file +import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,w as i}from"./client-DnySrlFv.js";import{t as a}from"./useMutation-B-Tr2hIP.js";import{t as o}from"./info-ROUoQhJR.js";import{n as s}from"./ToastContext-BRX0SW3C.js";import{Vn as c,vt as l,yt as u}from"./index-Cxa-KVmA.js";var d=e(n(),1),f=t();function p(){let e=c(),{t}=i(),{showToast:n}=s(),{mode:p}=l(),{refreshAuth:m}=u(),[h,g]=(0,d.useState)(!1),[_,v]=(0,d.useState)(``),[y,b]=(0,d.useState)(``),[x,S]=(0,d.useState)(``),C=a({mutationFn:()=>r.setupAuth({auth_enabled:h,admin_username:h?_:void 0,admin_password:h?y:void 0}),onSuccess:async r=>{await m(),r.auth_enabled?r.admin_created?(n(t(`setup.toast.authEnabledAdminCreated`)),e(`/login`)):(n(t(`setup.toast.authEnabledExistingAdmins`)),e(`/login`)):(n(t(`setup.toast.setupCompleted`)),e(`/`))},onError:e=>{n(e.message,`error`)}});return(0,f.jsx)(`div`,{className:`min-h-screen flex items-center justify-center bg-bambu-dark p-4`,children:(0,f.jsxs)(`div`,{className:`max-w-md w-full space-y-8 p-8 bg-gradient-to-br from-bambu-card to-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary shadow-lg`,children:[(0,f.jsxs)(`div`,{className:`text-center`,children:[(0,f.jsx)(`div`,{className:`flex items-center justify-center mb-6`,children:(0,f.jsx)(`img`,{src:p===`dark`?`/img/bambuddy_logo_dark_transparent.png`:`/img/bambuddy_logo_light.png`,alt:`Bambuddy`,className:`h-16`})}),(0,f.jsx)(`h2`,{className:`text-3xl font-bold text-white`,children:t(`setup.title`)}),(0,f.jsx)(`p`,{className:`mt-2 text-sm text-bambu-gray`,children:t(`setup.subtitle`)})]}),(0,f.jsxs)(`form`,{className:`mt-8 space-y-6`,onSubmit:e=>{if(e.preventDefault(),h&&(_||y)){if(!_||!y){n(t(`setup.toast.enterBothCredentials`),`error`);return}if(y!==x){n(t(`setup.toast.passwordsDoNotMatch`),`error`);return}if(y.length<6){n(t(`setup.toast.passwordTooShort`),`error`);return}}C.mutate()},children:[(0,f.jsxs)(`div`,{className:`space-y-4`,children:[(0,f.jsxs)(`div`,{className:`flex items-center p-4 bg-bambu-dark-secondary/50 rounded-lg border border-bambu-dark-tertiary`,children:[(0,f.jsx)(`input`,{id:`auth-enabled`,type:`checkbox`,checked:h,onChange:e=>g(e.target.checked),className:`h-4 w-4 text-bambu-green focus:ring-bambu-green border-bambu-dark-tertiary rounded bg-bambu-dark-secondary`}),(0,f.jsx)(`label`,{htmlFor:`auth-enabled`,className:`ml-3 block text-sm font-medium text-white`,children:t(`setup.enableAuth`)})]}),h&&(0,f.jsxs)(`div`,{className:`space-y-4 mt-4`,children:[(0,f.jsx)(`div`,{className:`p-3 bg-bambu-dark-secondary/50 border border-bambu-dark-tertiary rounded-lg`,children:(0,f.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,f.jsx)(o,{className:`w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0`}),(0,f.jsxs)(`div`,{className:`text-sm text-bambu-gray`,children:[(0,f.jsx)(`p`,{className:`text-white font-medium mb-1`,children:t(`setup.adminAccount`)}),(0,f.jsx)(`p`,{children:t(`setup.adminAccountDesc`)})]})]})}),(0,f.jsxs)(`div`,{children:[(0,f.jsxs)(`label`,{htmlFor:`admin-username`,className:`block text-sm font-medium text-white mb-2`,children:[t(`setup.adminUsername`),` `,(0,f.jsx)(`span`,{className:`text-bambu-gray text-xs`,children:t(`setup.optionalIfAdminExists`)})]}),(0,f.jsx)(`input`,{id:`admin-username`,type:`text`,value:_,onChange:e=>v(e.target.value),className:`block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:t(`setup.adminUsernamePlaceholder`),autoComplete:`username`})]}),(0,f.jsxs)(`div`,{children:[(0,f.jsxs)(`label`,{htmlFor:`admin-password`,className:`block text-sm font-medium text-white mb-2`,children:[t(`setup.adminPassword`),` `,(0,f.jsx)(`span`,{className:`text-bambu-gray text-xs`,children:t(`setup.optionalIfAdminExists`)})]}),(0,f.jsx)(`input`,{id:`admin-password`,type:`password`,value:y,onChange:e=>b(e.target.value),className:`block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:t(`setup.adminPasswordPlaceholder`),minLength:6,autoComplete:`new-password`})]}),y&&(0,f.jsxs)(`div`,{children:[(0,f.jsx)(`label`,{htmlFor:`confirm-password`,className:`block text-sm font-medium text-white mb-2`,children:t(`setup.confirmPassword`)}),(0,f.jsx)(`input`,{id:`confirm-password`,type:`password`,value:x,onChange:e=>S(e.target.value),className:`block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:t(`setup.confirmPasswordPlaceholder`),minLength:6,autoComplete:`new-password`})]})]})]}),(0,f.jsx)(`div`,{children:(0,f.jsx)(`button`,{type:`submit`,disabled:C.isPending,className:`w-full flex justify-center py-3 px-4 bg-bambu-green hover:bg-bambu-green-light text-white font-medium rounded-lg shadow-lg shadow-bambu-green/20 hover:shadow-bambu-green/30 focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:ring-offset-2 focus:ring-offset-bambu-dark-secondary transition-all disabled:opacity-50 disabled:cursor-not-allowed disabled:hover:bg-bambu-green`,children:C.isPending?t(`setup.settingUp`):t(`setup.completeSetup`)})})]})]})})}export{p as SetupPage}; \ No newline at end of file diff --git a/static/assets/SliceModal-TzmWgODN.js b/static/assets/SliceModal-YlJTMEj6.js similarity index 99% rename from static/assets/SliceModal-TzmWgODN.js rename to static/assets/SliceModal-YlJTMEj6.js index 4be28a136..85996dceb 100644 --- a/static/assets/SliceModal-TzmWgODN.js +++ b/static/assets/SliceModal-YlJTMEj6.js @@ -1,2 +1,2 @@ -import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,w as i,x as a}from"./client-DnySrlFv.js";import{n as o}from"./QueryClientProvider-Ce8_sN3w.js";import{t as s}from"./useQuery-BBCjCezC.js";import{t as c}from"./useMutation-B-Tr2hIP.js";import{t as l}from"./createLucideIcon-DvBYJlWL.js";import{a as u}from"./info-ROUoQhJR.js";import{n as d}from"./ToastContext-BRX0SW3C.js";import{t as f}from"./cloud-off-DfYbNG2N.js";import{t as p}from"./cog-Dol1I0kq.js";import{t as m}from"./loader-circle-BEmFtawu.js";import{t as h}from"./search-0n0CBc74.js";import{t as g}from"./x-DR-Trv6U.js";import{o as _}from"./date-G9KUauqz.js";import{B as v,Gt as y,H as b,Kn as x,Kt as S,Q as C,U as w,W as T,cn as E,t as ee,tt as te,w as D}from"./index-0t--Yqoi.js";import{a as O,i as ne,n as k,t as A}from"./slicerPrinterMatch-CUdoNag2.js";var re=l(`grid-2x2`,[[`path`,{d:`M12 3v18`,key:`108xh3`}],[`path`,{d:`M3 12h18`,key:`1i2n21`}],[`rect`,{x:`3`,y:`3`,width:`18`,height:`18`,rx:`2`,key:`h1oib`}]]),j=e(n(),1),M=1024;function ie(){let[e,t]=(0,j.useState)(()=>typeof window<`u`?window.innerWidth>=M:!1);return(0,j.useEffect)(()=>{let e=window.matchMedia(`(min-width: ${M}px)`),n=e=>{t(e.matches)};return t(e.matches),e.addEventListener(`change`,n),()=>e.removeEventListener(`change`,n)},[]),e}var N=t();function ae({plates:e,onSelect:t,onClose:n}){let{t:r}=i();return(0,N.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-4`,onClick:n,children:(0,N.jsxs)(`div`,{className:`w-full max-w-3xl max-h-[85vh] flex flex-col rounded-lg bg-bambu-dark-secondary border border-bambu-dark-tertiary/60`,onClick:e=>e.stopPropagation(),children:[(0,N.jsxs)(`div`,{className:`flex-shrink-0 flex items-start justify-between gap-3 px-4 pt-4 pb-3 border-b border-bambu-dark-tertiary/40`,children:[(0,N.jsxs)(`div`,{className:`min-w-0`,children:[(0,N.jsx)(`h3`,{className:`text-white font-medium`,children:r(`archives.platePicker.title`)}),(0,N.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:r(`archives.platePicker.hint`)})]}),(0,N.jsx)(`button`,{onClick:n,className:`flex-shrink-0 text-bambu-gray hover:text-white transition-colors`,"aria-label":r(`common.close`,`Close`),children:(0,N.jsx)(g,{className:`w-5 h-5`})})]}),(0,N.jsx)(`div`,{className:`flex-1 overflow-y-auto p-4`,children:(0,N.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-2`,children:e.map(e=>(0,N.jsxs)(`button`,{type:`button`,onClick:()=>t(e.index),className:`flex items-center gap-2 p-2 rounded-lg border border-bambu-dark-tertiary bg-bambu-dark hover:border-bambu-gray transition-colors text-left`,children:[e.has_thumbnail&&e.thumbnail_url!=null?(0,N.jsx)(`img`,{src:a(e.thumbnail_url),alt:`Plate ${e.index}`,className:`w-12 h-12 rounded object-cover bg-bambu-dark-tertiary flex-shrink-0`}):(0,N.jsx)(`div`,{className:`w-12 h-12 rounded bg-bambu-dark-tertiary flex items-center justify-center flex-shrink-0`,children:(0,N.jsx)(E,{className:`w-5 h-5 text-bambu-gray`})}),(0,N.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,N.jsx)(`p`,{className:`text-sm text-white font-medium truncate`,children:e.name?`${r(`archives.platePicker.plateLabel`,{index:e.index})} — ${e.name}`:r(`archives.platePicker.plateLabel`,{index:e.index})}),(0,N.jsxs)(`p`,{className:`text-xs text-bambu-gray truncate`,children:[e.objects.length>0?e.objects.slice(0,3).join(`, `)+(e.objects.length>3?`…`:``):e.object_count!=null&&e.object_count>0?r(`archives.platePicker.objectCount`,{count:e.object_count}):`${e.filaments.length} filament${e.filaments.length===1?``:`s`}`,e.print_time_seconds==null?``:` • ${_(e.print_time_seconds)}`]})]})]},e.index))})})]})})}var P=[`local`,`orca_cloud`,`cloud`,`standard`],F={local:1.75,orca_cloud:1.5,cloud:1,standard:.5};function oe(e,t){for(let n of P){let r=e[n][t];if(r.length>0)return{source:r[0].source,id:r[0].id}}return null}function I(e,t,n){return t?e[t.source][n].find(e=>e.id===t.id)??null:null}function se(e,t,n){if(!n)return null;for(let r of P){let i=e[r][t].find(e=>e.name===n);if(i)return{source:i.source,id:i.id}}return null}function ce(e,t,n,r){let i=se(e,`process`,r);if(i){let r=I(e,i,`process`);if(r&&O(r,`process`,t,n)!==`mismatch`)return i}for(let r of[`match`,`unknown`])for(let i of P){let a=de(e[i].process.filter(e=>O(e,`process`,t,n)===r));if(a)return{source:a.source,id:a.id}}return oe(e,`process`)}var le=.2,ue=/^\s*([\d.]+)\s*mm\b/i;function de(e){let t=null,n=1/0,r=-1/0;for(let i of e){let e=ue.exec(i.name),a=e?Number.parseFloat(e[1]):NaN,o=Number.isFinite(a)&&a>0,s=o?Math.abs(a-le):1/0;(t==null||sr)&&(t=i,n=s,r=o?a:-1/0)}return t}function fe(e,t){let n=t.trim().toUpperCase(),r=(e.filament_type??``).trim().toUpperCase();return!!n&&!!r&&n!==r}function pe(e,t,n,r){let i=t.type.trim().toUpperCase(),a=C(t.color),o=null,s=null,c=null,l=null;for(let u of P)for(let d of e[u].filament){let e=0,f=(d.filament_type??``).trim().toUpperCase(),p=C(d.filament_colour??``);i&&f&&i===f&&(e+=10),a&&p&&(p===a?e+=5:v(d.filament_colour??``,t.color)&&(e+=2)),e+=F[u];let m={source:d.source,id:d.id};fe(d,i)?O(d,`filament`,n,r)===`mismatch`?(l==null||e>l.score)&&(l={ref:m,score:e}):(c==null||e>c.score)&&(c={ref:m,score:e}):O(d,`filament`,n,r)===`mismatch`?(s==null||e>s.score)&&(s={ref:m,score:e}):(o==null||e>o.score)&&(o={ref:m,score:e})}return o==null?s==null?c==null?l==null?oe(e,`filament`):l.ref:c.ref:s.ref:o.ref}function me(e){return`${e.source}:${e.id}`}function he(e,t){if(!e)return null;let n=e.replace(/^#\s*/,``).trim().match(/^Bambu Lab\s+(.+?)(?:\s+[\d.]+\s*nozzle)?$/i);if(!n)return null;let r=n[1].trim(),i=`bambu lab ${r}`.toLowerCase();for(let[e,n]of Object.entries(t))if(e.toLowerCase()===i)return n;return r}function ge(e,t){return!e||!t?!1:ne(e.trim(),t.trim())}function _e(e,t){return t?e.filter(e=>ge(e.model,t)):e}function ve(e,t,n={}){return e?he((Object.hasOwn(n,e)?n[e]:null)||e,t):null}function ye(e,t,n,r={}){let i=ve(e.name,n,r);return i===null?!0:t.some(e=>ge(e,i))}function be(e,t,n,r={}){let i=null;for(let a of P)for(let o of e[a].printer){let e=ve(o.name,n,r);if(e===null||!t.some(t=>ge(t,e)))continue;let s={source:a,id:o.id};if(/\b0\.4\s*nozzle\b/i.test(o.name))return s;i??=s}return i}function xe(e){let t=e.replace(/^#\s*/,``),n=t.lastIndexOf(`@`);return n>0&&(t=t.slice(0,n)),t.replace(/\s+/g,` `).trim().toLowerCase()}function Se(e){let t=e.replace(/^#\s*/,``),n=t.lastIndexOf(`@`);return n>0&&(t=t.slice(0,n)),t.replace(/\s+/g,` `).trim()}function Ce(e){return!!e.tray_type}function we(e){let t=e.saved_preset;return t&&te(t.preset_id,e.tray_info_idx,t.tray_info_idx)?t:null}function Te(e){if(e.preset_source===`local`){let t=e.preset_id.match(/^local_(\d+)$/);return t?{source:`local`,id:t[1]}:null}return(e.preset_source===`cloud`||e.preset_source===`orca_cloud`)&&e.preset_id?{source:e.preset_source,id:e.preset_id}:null}function Ee(e,t){let n=[];t?.preset_name&&n.push(t.preset_name);let r=(e.tray_sub_brands??``).trim();r?(/^GF/i.test(e.tray_info_idx??``)&&!/^bambu\b/i.test(r)&&n.push(`Bambu ${r}`),n.push(r)):e.tray_type&&n.push(`Generic ${e.tray_type}`);let i=new Set;return n.filter(e=>{let t=xe(e);return!t||i.has(t)?!1:(i.add(t),!0)})}function De(e){let t=new Map;for(let n of P)for(let r of e[n].filament){let e=xe(r.name),i=t.get(e);i?i.push({source:n,preset:r}):t.set(e,[{source:n,preset:r}])}return t}function Oe(e,t,n,r,i){if(!Ce(e))return null;let a=we(e),o=e=>O(e,`filament`,r,i);if(a){let e=Te(a),n=e?t[e.source].filament.find(t=>t.id===e.id):void 0;if(e&&n&&o(n)!==`mismatch`)return{ref:e,preset:n}}let s=a?Te(a)?.source:void 0;for(let t of Ee(e,a)){let r=n.get(xe(t))??[],i=s?[...r.filter(e=>e.source===s),...r.filter(e=>e.source!==s)]:r,a=null;for(let{source:t,preset:n}of i){if(fe(n,e.tray_type??``))continue;let r=o(n);if(r===`match`)return{ref:{source:t,id:n.id},preset:n};r===`unknown`&&!a&&(a={ref:{source:t,id:n.id},preset:n})}if(a)return a}return null}function ke(e){let t=[];for(let n of e){for(let e of n.ams)for(let n of e.trays)Ce(n)&&t.push(n);for(let e of n.external)Ce(e)&&t.push(e)}return t}function Ae(e,t,n,r,i){let a=new Set;for(let o of ke(e)){let e=Oe(o,t,n,r,i);e&&a.add(me(e.ref))}return a}function je(e){let t=(e.tray_color??``).replace(/^#/,``);return/^[0-9a-fA-F]{6}/.test(t)?`#${t.slice(0,6).toUpperCase()}`:null}function Me({printers:e,data:t,index:n,selectedPrinterName:r,compatIndex:a,slotLabel:o,onPick:s,onClose:c}){let{t:l}=i();return(0,j.useEffect)(()=>{let e=e=>{e.key===`Escape`&&c()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[c]),(0,N.jsx)(`div`,{className:`fixed inset-0 z-[60] flex items-center justify-center bg-black/60 p-4`,onClick:c,children:(0,N.jsxs)(`div`,{role:`dialog`,"aria-modal":`true`,"aria-labelledby":`slice-spool-picker-title`,className:`w-full max-w-3xl max-h-[85vh] flex flex-col rounded-lg bg-bambu-dark-secondary border border-bambu-dark-tertiary/60`,onClick:e=>e.stopPropagation(),children:[(0,N.jsxs)(`div`,{className:`flex-shrink-0 flex items-start justify-between gap-3 px-4 pt-4 pb-3 border-b border-bambu-dark-tertiary/40`,children:[(0,N.jsxs)(`div`,{className:`min-w-0`,children:[(0,N.jsx)(`h3`,{id:`slice-spool-picker-title`,className:`text-white font-medium`,children:l(`slice.loadedSpools.title`,`Loaded spools`)}),(0,N.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1 truncate`,children:o})]}),(0,N.jsx)(`button`,{type:`button`,onClick:c,className:`flex-shrink-0 text-bambu-gray hover:text-white transition-colors`,"aria-label":l(`common.close`),children:(0,N.jsx)(g,{className:`w-5 h-5`})})]}),(0,N.jsx)(`div`,{className:`flex-1 overflow-y-auto p-4 space-y-5`,children:e.length===0?(0,N.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:l(`slice.loadedSpools.none`,`No printer of this model is online.`)}):e.map(e=>(0,N.jsx)(Ne,{printer:e,matchFor:e=>Oe(e,t,n,r,a),onPick:s},e.id))})]})})}function Ne({printer:e,matchFor:t,onPick:n}){let{t:r}=i(),a=e.ams.filter(e=>!e.is_ams_ht),o=e.ams.filter(e=>e.is_ams_ht),s=e.ams.length>0||e.external.length>0,c=(e,r)=>(0,N.jsx)(Pe,{tray:e,label:r,match:t(e),onPick:n},`${e.ams_id}-${e.tray_id}`);return(0,N.jsxs)(`section`,{children:[(0,N.jsxs)(`h4`,{className:`text-sm text-white font-medium mb-2`,children:[e.name,e.model&&(0,N.jsx)(`span`,{className:`ml-2 text-xs text-bambu-gray font-normal`,children:e.model})]}),!s&&(0,N.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:r(`slice.loadedSpools.nothingLoaded`,`No AMS and no external spool.`)}),(0,N.jsxs)(`div`,{className:`space-y-3`,children:[a.map(e=>(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`div`,{className:`text-xs text-bambu-gray mb-1`,children:w(e.id,e.trays.length)}),(0,N.jsx)(`div`,{className:`grid grid-cols-2 sm:grid-cols-4 gap-2`,children:e.trays.map(t=>c(t,b(e.id,t.tray_id,!1,!1)))})]},e.id)),o.length>0&&(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`div`,{className:`text-xs text-bambu-gray mb-1`,children:`AMS-HT`}),(0,N.jsx)(`div`,{className:`grid grid-cols-2 sm:grid-cols-4 gap-2`,children:o.flatMap(e=>e.trays.map(t=>c(t,b(e.id,t.tray_id,!0,!1))))})]}),e.external.length>0&&(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`div`,{className:`text-xs text-bambu-gray mb-1`,children:r(`printers.external`)}),(0,N.jsx)(`div`,{className:`grid grid-cols-2 sm:grid-cols-4 gap-2`,children:e.external.map(t=>c(t,e.external_holders>1?t.tray_id===0?r(`printers.extL`):r(`printers.extR`):r(`printers.ext`)))})]})]})]})}function Pe({tray:e,label:t,match:n,onPick:r}){let{t:a}=i(),o=T(e),s=je(e),c=(0,j.useMemo)(()=>{if(n)return Se(n.preset.name);let t=we(e);return t?.preset_name?Se(t.preset_name):e.tray_sub_brands||null},[n,e]);if(o!==null)return(0,N.jsxs)(`div`,{className:`rounded-md border border-dashed border-bambu-dark-tertiary px-2 py-2 text-xs text-bambu-gray/70`,children:[(0,N.jsx)(`div`,{className:`font-medium text-bambu-gray`,children:t}),(0,N.jsx)(`div`,{children:o===`reset`?a(`slice.loadedSpools.unknownSpool`,`Unidentified spool`):a(`slice.loadedSpools.empty`,`Empty`)})]});let l=n===null;return(0,N.jsxs)(`button`,{type:`button`,disabled:l,onClick:()=>n&&r(n,s),title:l?a(`slice.loadedSpools.noProfile`,`No profile for the selected printer`):c??void 0,className:`text-left rounded-md border border-bambu-dark-tertiary bg-bambu-dark px-2 py-2 text-xs transition-colors enabled:hover:border-bambu-green disabled:opacity-50 disabled:cursor-not-allowed`,children:[(0,N.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,N.jsx)(D,{rgba:e.tray_color,className:`w-3.5 h-3.5 shrink-0`,effectSize:`table`}),(0,N.jsx)(`span`,{className:`font-medium text-white`,children:t}),(0,N.jsx)(`span`,{className:`ml-auto text-bambu-gray`,children:e.tray_type})]}),(0,N.jsx)(`div`,{className:`mt-1 truncate text-bambu-gray`,title:c??void 0,children:c??`—`}),l&&(0,N.jsx)(`div`,{className:`mt-0.5 truncate text-[11px] text-amber-600 dark:text-amber-400`,children:a(`slice.loadedSpools.noProfileShort`,`No profile for this printer`)})]})}var L=e=>typeof e==`object`&&!!e&&`enumKey`in e,Fe=`enum:`;function R(e){if(typeof e==`number`)return e;if(typeof e==`boolean`)return+!!e;if(typeof e!=`string`)return;let t=Number.parseFloat(e);return Number.isFinite(t)?t:void 0}function z(e){if(typeof e==`boolean`)return e;if(typeof e==`number`)return e!==0;if(e===`1`||e===`true`)return!0;if(e===`0`||e===`false`)return!1}function Ie(e,t){return{get:n=>{let r=e[n];if((r===void 0||r===``)&&(r=t[n]?.default),Array.isArray(r)&&(r=r[0]),typeof r==`boolean`||typeof r==`number`||typeof r==`string`)return r},has:e=>e in t}}var B=[`->`,`||`,`&&`,`==`,`!=`,`<=`,`>=`,`(`,`)`,`,`,`<`,`>`,`!`];function Le(e){let t=[],n=0;for(;ntypeof window<`u`?window.innerWidth>=M:!1);return(0,j.useEffect)(()=>{let e=window.matchMedia(`(min-width: ${M}px)`),n=e=>{t(e.matches)};return t(e.matches),e.addEventListener(`change`,n),()=>e.removeEventListener(`change`,n)},[]),e}var N=t();function ae({plates:e,onSelect:t,onClose:n}){let{t:r}=i();return(0,N.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-4`,onClick:n,children:(0,N.jsxs)(`div`,{className:`w-full max-w-3xl max-h-[85vh] flex flex-col rounded-lg bg-bambu-dark-secondary border border-bambu-dark-tertiary/60`,onClick:e=>e.stopPropagation(),children:[(0,N.jsxs)(`div`,{className:`flex-shrink-0 flex items-start justify-between gap-3 px-4 pt-4 pb-3 border-b border-bambu-dark-tertiary/40`,children:[(0,N.jsxs)(`div`,{className:`min-w-0`,children:[(0,N.jsx)(`h3`,{className:`text-white font-medium`,children:r(`archives.platePicker.title`)}),(0,N.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:r(`archives.platePicker.hint`)})]}),(0,N.jsx)(`button`,{onClick:n,className:`flex-shrink-0 text-bambu-gray hover:text-white transition-colors`,"aria-label":r(`common.close`,`Close`),children:(0,N.jsx)(g,{className:`w-5 h-5`})})]}),(0,N.jsx)(`div`,{className:`flex-1 overflow-y-auto p-4`,children:(0,N.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-2`,children:e.map(e=>(0,N.jsxs)(`button`,{type:`button`,onClick:()=>t(e.index),className:`flex items-center gap-2 p-2 rounded-lg border border-bambu-dark-tertiary bg-bambu-dark hover:border-bambu-gray transition-colors text-left`,children:[e.has_thumbnail&&e.thumbnail_url!=null?(0,N.jsx)(`img`,{src:a(e.thumbnail_url),alt:`Plate ${e.index}`,className:`w-12 h-12 rounded object-cover bg-bambu-dark-tertiary flex-shrink-0`}):(0,N.jsx)(`div`,{className:`w-12 h-12 rounded bg-bambu-dark-tertiary flex items-center justify-center flex-shrink-0`,children:(0,N.jsx)(E,{className:`w-5 h-5 text-bambu-gray`})}),(0,N.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,N.jsx)(`p`,{className:`text-sm text-white font-medium truncate`,children:e.name?`${r(`archives.platePicker.plateLabel`,{index:e.index})} — ${e.name}`:r(`archives.platePicker.plateLabel`,{index:e.index})}),(0,N.jsxs)(`p`,{className:`text-xs text-bambu-gray truncate`,children:[e.objects.length>0?e.objects.slice(0,3).join(`, `)+(e.objects.length>3?`…`:``):e.object_count!=null&&e.object_count>0?r(`archives.platePicker.objectCount`,{count:e.object_count}):`${e.filaments.length} filament${e.filaments.length===1?``:`s`}`,e.print_time_seconds==null?``:` • ${_(e.print_time_seconds)}`]})]})]},e.index))})})]})})}var P=[`local`,`orca_cloud`,`cloud`,`standard`],F={local:1.75,orca_cloud:1.5,cloud:1,standard:.5};function oe(e,t){for(let n of P){let r=e[n][t];if(r.length>0)return{source:r[0].source,id:r[0].id}}return null}function I(e,t,n){return t?e[t.source][n].find(e=>e.id===t.id)??null:null}function se(e,t,n){if(!n)return null;for(let r of P){let i=e[r][t].find(e=>e.name===n);if(i)return{source:i.source,id:i.id}}return null}function ce(e,t,n,r){let i=se(e,`process`,r);if(i){let r=I(e,i,`process`);if(r&&O(r,`process`,t,n)!==`mismatch`)return i}for(let r of[`match`,`unknown`])for(let i of P){let a=de(e[i].process.filter(e=>O(e,`process`,t,n)===r));if(a)return{source:a.source,id:a.id}}return oe(e,`process`)}var le=.2,ue=/^\s*([\d.]+)\s*mm\b/i;function de(e){let t=null,n=1/0,r=-1/0;for(let i of e){let e=ue.exec(i.name),a=e?Number.parseFloat(e[1]):NaN,o=Number.isFinite(a)&&a>0,s=o?Math.abs(a-le):1/0;(t==null||sr)&&(t=i,n=s,r=o?a:-1/0)}return t}function fe(e,t){let n=t.trim().toUpperCase(),r=(e.filament_type??``).trim().toUpperCase();return!!n&&!!r&&n!==r}function pe(e,t,n,r){let i=t.type.trim().toUpperCase(),a=C(t.color),o=null,s=null,c=null,l=null;for(let u of P)for(let d of e[u].filament){let e=0,f=(d.filament_type??``).trim().toUpperCase(),p=C(d.filament_colour??``);i&&f&&i===f&&(e+=10),a&&p&&(p===a?e+=5:v(d.filament_colour??``,t.color)&&(e+=2)),e+=F[u];let m={source:d.source,id:d.id};fe(d,i)?O(d,`filament`,n,r)===`mismatch`?(l==null||e>l.score)&&(l={ref:m,score:e}):(c==null||e>c.score)&&(c={ref:m,score:e}):O(d,`filament`,n,r)===`mismatch`?(s==null||e>s.score)&&(s={ref:m,score:e}):(o==null||e>o.score)&&(o={ref:m,score:e})}return o==null?s==null?c==null?l==null?oe(e,`filament`):l.ref:c.ref:s.ref:o.ref}function me(e){return`${e.source}:${e.id}`}function he(e,t){if(!e)return null;let n=e.replace(/^#\s*/,``).trim().match(/^Bambu Lab\s+(.+?)(?:\s+[\d.]+\s*nozzle)?$/i);if(!n)return null;let r=n[1].trim(),i=`bambu lab ${r}`.toLowerCase();for(let[e,n]of Object.entries(t))if(e.toLowerCase()===i)return n;return r}function ge(e,t){return!e||!t?!1:ne(e.trim(),t.trim())}function _e(e,t){return t?e.filter(e=>ge(e.model,t)):e}function ve(e,t,n={}){return e?he((Object.hasOwn(n,e)?n[e]:null)||e,t):null}function ye(e,t,n,r={}){let i=ve(e.name,n,r);return i===null?!0:t.some(e=>ge(e,i))}function be(e,t,n,r={}){let i=null;for(let a of P)for(let o of e[a].printer){let e=ve(o.name,n,r);if(e===null||!t.some(t=>ge(t,e)))continue;let s={source:a,id:o.id};if(/\b0\.4\s*nozzle\b/i.test(o.name))return s;i??=s}return i}function xe(e){let t=e.replace(/^#\s*/,``),n=t.lastIndexOf(`@`);return n>0&&(t=t.slice(0,n)),t.replace(/\s+/g,` `).trim().toLowerCase()}function Se(e){let t=e.replace(/^#\s*/,``),n=t.lastIndexOf(`@`);return n>0&&(t=t.slice(0,n)),t.replace(/\s+/g,` `).trim()}function Ce(e){return!!e.tray_type}function we(e){let t=e.saved_preset;return t&&te(t.preset_id,e.tray_info_idx,t.tray_info_idx)?t:null}function Te(e){if(e.preset_source===`local`){let t=e.preset_id.match(/^local_(\d+)$/);return t?{source:`local`,id:t[1]}:null}return(e.preset_source===`cloud`||e.preset_source===`orca_cloud`)&&e.preset_id?{source:e.preset_source,id:e.preset_id}:null}function Ee(e,t){let n=[];t?.preset_name&&n.push(t.preset_name);let r=(e.tray_sub_brands??``).trim();r?(/^GF/i.test(e.tray_info_idx??``)&&!/^bambu\b/i.test(r)&&n.push(`Bambu ${r}`),n.push(r)):e.tray_type&&n.push(`Generic ${e.tray_type}`);let i=new Set;return n.filter(e=>{let t=xe(e);return!t||i.has(t)?!1:(i.add(t),!0)})}function De(e){let t=new Map;for(let n of P)for(let r of e[n].filament){let e=xe(r.name),i=t.get(e);i?i.push({source:n,preset:r}):t.set(e,[{source:n,preset:r}])}return t}function Oe(e,t,n,r,i){if(!Ce(e))return null;let a=we(e),o=e=>O(e,`filament`,r,i);if(a){let e=Te(a),n=e?t[e.source].filament.find(t=>t.id===e.id):void 0;if(e&&n&&o(n)!==`mismatch`)return{ref:e,preset:n}}let s=a?Te(a)?.source:void 0;for(let t of Ee(e,a)){let r=n.get(xe(t))??[],i=s?[...r.filter(e=>e.source===s),...r.filter(e=>e.source!==s)]:r,a=null;for(let{source:t,preset:n}of i){if(fe(n,e.tray_type??``))continue;let r=o(n);if(r===`match`)return{ref:{source:t,id:n.id},preset:n};r===`unknown`&&!a&&(a={ref:{source:t,id:n.id},preset:n})}if(a)return a}return null}function ke(e){let t=[];for(let n of e){for(let e of n.ams)for(let n of e.trays)Ce(n)&&t.push(n);for(let e of n.external)Ce(e)&&t.push(e)}return t}function Ae(e,t,n,r,i){let a=new Set;for(let o of ke(e)){let e=Oe(o,t,n,r,i);e&&a.add(me(e.ref))}return a}function je(e){let t=(e.tray_color??``).replace(/^#/,``);return/^[0-9a-fA-F]{6}/.test(t)?`#${t.slice(0,6).toUpperCase()}`:null}function Me({printers:e,data:t,index:n,selectedPrinterName:r,compatIndex:a,slotLabel:o,onPick:s,onClose:c}){let{t:l}=i();return(0,j.useEffect)(()=>{let e=e=>{e.key===`Escape`&&c()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[c]),(0,N.jsx)(`div`,{className:`fixed inset-0 z-[60] flex items-center justify-center bg-black/60 p-4`,onClick:c,children:(0,N.jsxs)(`div`,{role:`dialog`,"aria-modal":`true`,"aria-labelledby":`slice-spool-picker-title`,className:`w-full max-w-3xl max-h-[85vh] flex flex-col rounded-lg bg-bambu-dark-secondary border border-bambu-dark-tertiary/60`,onClick:e=>e.stopPropagation(),children:[(0,N.jsxs)(`div`,{className:`flex-shrink-0 flex items-start justify-between gap-3 px-4 pt-4 pb-3 border-b border-bambu-dark-tertiary/40`,children:[(0,N.jsxs)(`div`,{className:`min-w-0`,children:[(0,N.jsx)(`h3`,{id:`slice-spool-picker-title`,className:`text-white font-medium`,children:l(`slice.loadedSpools.title`,`Loaded spools`)}),(0,N.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1 truncate`,children:o})]}),(0,N.jsx)(`button`,{type:`button`,onClick:c,className:`flex-shrink-0 text-bambu-gray hover:text-white transition-colors`,"aria-label":l(`common.close`),children:(0,N.jsx)(g,{className:`w-5 h-5`})})]}),(0,N.jsx)(`div`,{className:`flex-1 overflow-y-auto p-4 space-y-5`,children:e.length===0?(0,N.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:l(`slice.loadedSpools.none`,`No printer of this model is online.`)}):e.map(e=>(0,N.jsx)(Ne,{printer:e,matchFor:e=>Oe(e,t,n,r,a),onPick:s},e.id))})]})})}function Ne({printer:e,matchFor:t,onPick:n}){let{t:r}=i(),a=e.ams.filter(e=>!e.is_ams_ht),o=e.ams.filter(e=>e.is_ams_ht),s=e.ams.length>0||e.external.length>0,c=(e,r)=>(0,N.jsx)(Pe,{tray:e,label:r,match:t(e),onPick:n},`${e.ams_id}-${e.tray_id}`);return(0,N.jsxs)(`section`,{children:[(0,N.jsxs)(`h4`,{className:`text-sm text-white font-medium mb-2`,children:[e.name,e.model&&(0,N.jsx)(`span`,{className:`ml-2 text-xs text-bambu-gray font-normal`,children:e.model})]}),!s&&(0,N.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:r(`slice.loadedSpools.nothingLoaded`,`No AMS and no external spool.`)}),(0,N.jsxs)(`div`,{className:`space-y-3`,children:[a.map(e=>(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`div`,{className:`text-xs text-bambu-gray mb-1`,children:w(e.id,e.trays.length)}),(0,N.jsx)(`div`,{className:`grid grid-cols-2 sm:grid-cols-4 gap-2`,children:e.trays.map(t=>c(t,b(e.id,t.tray_id,!1,!1)))})]},e.id)),o.length>0&&(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`div`,{className:`text-xs text-bambu-gray mb-1`,children:`AMS-HT`}),(0,N.jsx)(`div`,{className:`grid grid-cols-2 sm:grid-cols-4 gap-2`,children:o.flatMap(e=>e.trays.map(t=>c(t,b(e.id,t.tray_id,!0,!1))))})]}),e.external.length>0&&(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`div`,{className:`text-xs text-bambu-gray mb-1`,children:r(`printers.external`)}),(0,N.jsx)(`div`,{className:`grid grid-cols-2 sm:grid-cols-4 gap-2`,children:e.external.map(t=>c(t,e.external_holders>1?t.tray_id===0?r(`printers.extL`):r(`printers.extR`):r(`printers.ext`)))})]})]})]})}function Pe({tray:e,label:t,match:n,onPick:r}){let{t:a}=i(),o=T(e),s=je(e),c=(0,j.useMemo)(()=>{if(n)return Se(n.preset.name);let t=we(e);return t?.preset_name?Se(t.preset_name):e.tray_sub_brands||null},[n,e]);if(o!==null)return(0,N.jsxs)(`div`,{className:`rounded-md border border-dashed border-bambu-dark-tertiary px-2 py-2 text-xs text-bambu-gray/70`,children:[(0,N.jsx)(`div`,{className:`font-medium text-bambu-gray`,children:t}),(0,N.jsx)(`div`,{children:o===`reset`?a(`slice.loadedSpools.unknownSpool`,`Unidentified spool`):a(`slice.loadedSpools.empty`,`Empty`)})]});let l=n===null;return(0,N.jsxs)(`button`,{type:`button`,disabled:l,onClick:()=>n&&r(n,s),title:l?a(`slice.loadedSpools.noProfile`,`No profile for the selected printer`):c??void 0,className:`text-left rounded-md border border-bambu-dark-tertiary bg-bambu-dark px-2 py-2 text-xs transition-colors enabled:hover:border-bambu-green disabled:opacity-50 disabled:cursor-not-allowed`,children:[(0,N.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,N.jsx)(D,{rgba:e.tray_color,className:`w-3.5 h-3.5 shrink-0`,effectSize:`table`}),(0,N.jsx)(`span`,{className:`font-medium text-white`,children:t}),(0,N.jsx)(`span`,{className:`ml-auto text-bambu-gray`,children:e.tray_type})]}),(0,N.jsx)(`div`,{className:`mt-1 truncate text-bambu-gray`,title:c??void 0,children:c??`—`}),l&&(0,N.jsx)(`div`,{className:`mt-0.5 truncate text-[11px] text-amber-600 dark:text-amber-400`,children:a(`slice.loadedSpools.noProfileShort`,`No profile for this printer`)})]})}var L=e=>typeof e==`object`&&!!e&&`enumKey`in e,Fe=`enum:`;function R(e){if(typeof e==`number`)return e;if(typeof e==`boolean`)return+!!e;if(typeof e!=`string`)return;let t=Number.parseFloat(e);return Number.isFinite(t)?t:void 0}function z(e){if(typeof e==`boolean`)return e;if(typeof e==`number`)return e!==0;if(e===`1`||e===`true`)return!0;if(e===`0`||e===`false`)return!1}function Ie(e,t){return{get:n=>{let r=e[n];if((r===void 0||r===``)&&(r=t[n]?.default),Array.isArray(r)&&(r=r[0]),typeof r==`boolean`||typeof r==`number`||typeof r==`string`)return r},has:e=>e in t}}var B=[`->`,`||`,`&&`,`==`,`!=`,`<=`,`>=`,`(`,`)`,`,`,`<`,`>`,`!`];function Le(e){let t=[],n=0;for(;ne.startsWith(t,n));if(a){t.push({kind:`op`,value:a}),n+=a.length;continue}let o=/^[A-Za-z_][A-Za-z0-9_]*(::[A-Za-z_][A-Za-z0-9_]*)*/.exec(e.slice(n));if(o){t.push({kind:`id`,value:o[0]}),n+=o[0].length;continue}return}return t}var Re=new Set([`opt_bool`,`opt_int`,`opt_float`,`opt_float_nullable`,`opt_int_nullable`,`opt_bool_nullable`,`opt_enum`,`opt_string`,`option`,`has`]),ze=class e{tokens=[];pos=0;cfg;locals;schema;resolving;memo;constructor(e,t,n,r,i){this.cfg=e,this.locals=t,this.schema=n,this.resolving=r,this.memo=i}evaluate(e){let t=Le(e);if(!t||t.length===0)return;this.tokens=t,this.pos=0;let n=this.parseOr();if(this.pos===this.tokens.length)return n}peek(){return this.tokens[this.pos]}eatOp(e){let t=this.peek();return t&&t.kind===`op`&&t.value===e?(this.pos+=1,!0):!1}parseOr(){let e=this.parseAnd();for(;this.eatOp(`||`);){let t=this.parseAnd(),n=z(e),r=z(t);e=n===!0||r===!0?!0:n===void 0||r===void 0?void 0:n||r}return e}parseAnd(){let e=this.parseComparison();for(;this.eatOp(`&&`);){let t=this.parseComparison(),n=z(e),r=z(t);e=n===!1||r===!1?!1:n===void 0||r===void 0?void 0:n&&r}return e}parseComparison(){let e=this.parseUnary();for(let t of[`==`,`!=`,`<=`,`>=`,`<`,`>`])if(this.eatOp(t))return Be(e,this.parseUnary(),t,this.schema);return e}parseUnary(){if(this.eatOp(`!`)){let e=z(this.parseUnary());return e===void 0?void 0:!e}return this.parsePrimary()}parsePrimary(){let e=this.peek();if(!e)return;if(e.kind===`num`||e.kind===`str`)return this.pos+=1,e.value;if(e.kind===`op`&&e.value===`(`){this.pos+=1;let e=this.parseOr();return this.eatOp(`)`)?e:void 0}if(e.kind!==`id`)return;if(this.pos+=1,e.value===`true`)return!0;if(e.value===`false`)return!1;if(e.value===`config`)return this.parseConfigAccess();let t=this.locals[e.value];return t===void 0?`${Fe}${e.value}`:this.resolveLocal(e.value,t)}parseConfigAccess(){if(!this.eatOp(`->`))return;let e=this.peek();if(!e||e.kind!==`id`||!Re.has(e.value))return;if(this.pos+=1,this.eatOp(`<`)){let e=1;for(;e>0;){let t=this.peek();if(!t)return;this.pos+=1,t.kind===`op`&&t.value===`<`&&(e+=1),t.kind===`op`&&t.value===`>`&&--e}}if(!this.eatOp(`(`))return;let t=this.peek();if(!t||t.kind!==`str`)return;this.pos+=1;let n=t.value;for(;this.eatOp(`,`);){let e=0;for(;;){let t=this.peek();if(!t)return;if(t.kind===`op`&&t.value===`(`&&(e+=1),t.kind===`op`&&t.value===`)`){if(e===0)break;--e}if(t.kind===`op`&&t.value===`,`&&e===0)break;this.pos+=1}}if(!this.eatOp(`)`))return;if(this.eatOp(`->`)){let e=this.peek();if(!e||e.kind!==`id`)return;this.pos+=1}if(e.value===`has`)return this.cfg.has(n);let r=this.cfg.get(n);return this.schema[n]?.enum_values?{enumKey:n,value:typeof r==`string`?r:void 0}:r}resolveLocal(t,n){let r=this.memo.get(t);if(r!==void 0||this.memo.has(t))return r;if(this.resolving.has(t))return;this.resolving.add(t);let i=new e(this.cfg,this.locals,this.schema,this.resolving,this.memo).evaluate(n);return this.resolving.delete(t),this.memo.set(t,i),i}};function Be(e,t,n,r){let i=typeof e==`string`&&e.startsWith(Fe)?e:typeof t==`string`&&t.startsWith(Fe)?t:void 0;if(i!==void 0){if(n!==`==`&&n!==`!=`)return;let a=i===e?t:e;if(!L(a))return;let o=r[a.enumKey]?.enum_values;if(!o||a.value===void 0)return;let s=Ve(i.slice(5)).filter(e=>o.includes(e));if(s.length!==1)return;let c=s[0]===a.value;return n===`==`?c:!c}let a=L(e)?e.value:e,o=L(t)?t.value:t;if(n===`==`||n===`!=`){if(a===void 0||o===void 0)return;let e=typeof a==`string`||typeof o==`string`?String(a)===String(o):R(a)===R(o);return n===`==`?e:!e}let s=R(a),c=R(o);if(!(s===void 0||c===void 0)){if(n===`<`)return s`)return s>c;if(n===`>=`)return s>=c}}function Ve(e){let t=e.includes(`::`)?e.slice(e.lastIndexOf(`::`)+2):e,n=[t,/^[a-z]+([A-Z].*)$/.exec(t)?.[1]].filter(e=>!!e),r=new Set;for(let e of n){let t=e.replace(/([a-z0-9])([A-Z])/g,`$1_$2`).toLowerCase();r.add(t),r.add(t.replace(/_/g,` `)),r.add(t.replace(/_/g,``))}return[...r]}function V(e,t,n){let r=Ie(e,t),i=new Map,a=new Set;for(let e of n.rules){let o=H(e.enable_if);if(o&&z(new ze(r,n.locals,t,new Set,i).evaluate(o))===!1)for(let t of e.fields)a.add(t)}return a}function H(e){let t=0;for(let n=0;nHe.has(e.type);function We(e){if(typeof e==`number`)return Number.isFinite(e)?e:void 0;if(typeof e!=`string`)return;let t=Number.parseFloat(e);return Number.isFinite(t)?t:void 0}function Ge(e){let t=e.sidetext;if(!(!t||t.includes(`->`)||t.includes(`::`)))return t}function U(e,t){let n=t===void 0?e.default:t;return n===void 0?``:Array.isArray(n)?n.map(String).join(`, `):typeof n==`boolean`?n?`1`:`0`:String(n)}function W(e,t){if(Ue(e))return(Array.isArray(t)?t.map(String):String(t).split(`,`)).map(e=>e.trim()).filter(e=>e!==``);if(e.type===`coBool`)return typeof t==`boolean`?t?`1`:`0`:t===`1`||t===`true`||t===1?`1`:`0`;let n=String(t).trim();return e.type===`coPercent`?n.endsWith(`%`)?n:`${n}%`:n}function G(e,t){let n={};for(let[r,i]of Object.entries(e)){let e=t[r];e&&(n[r]=W(e,i))}return n}function K(e,t,n){if(t===void 0||t===``)return!1;let r=t=>{let n=W(e,Array.isArray(t)?t.map(String).join(`, `):t);return Array.isArray(n)?n.join(`, `):n},i=r(t),a=n===void 0?e.default:n;return a===void 0?i!==``:i!==r(a)}var Ke=new Set([`support_filament`,`support_interface_filament`,`outer_wall_filament_id`,`inner_wall_filament_id`,`top_surface_filament_id`,`bottom_surface_filament_id`,`internal_solid_filament_id`,`sparse_infill_filament_id`]),qe=[`simple`,`advanced`,`expert`],Je={simple:0,advanced:1,expert:2,develop:3};function Ye({values:e,onChange:t,disabled:n=!1,sourceOverrides:r=[],sourceSelected:a,onToggleSource:o,filamentChoices:s,presetValues:c,presetValuesResolved:l=!0,presetValuesReason:u}){let{t:d}=i(),[f,p]=(0,j.useState)(null),[g,_]=(0,j.useState)(`simple`),[v,b]=(0,j.useState)(null),[S,C]=(0,j.useState)(``);(0,j.useEffect)(()=>{let e=!1;return Promise.all([x(()=>import(`./process-schema-CzfeynAH.js`),[]),x(()=>import(`./process-ui-tree-BWrKRLV6.js`),[]),x(()=>import(`./process-toggle-rules-DDBax3G5.js`),[])]).then(([t,n,r])=>{e||p({schema:t.default??t,tree:n.default??n,toggles:r.default??r})}),()=>{e=!0}},[]);let w=(0,j.useMemo)(()=>{let t={...c??{}};for(let e of r)a?.has(e.key)&&(t[e.key]=e.value);for(let[n,r]of Object.entries(e))r!==void 0&&r!==``&&(t[n]=r);return t},[c,r,a,e]),T=(0,j.useMemo)(()=>f?V(w,f.schema,f.toggles):new Set,[f,w]),E=(0,j.useMemo)(()=>new Map(r.map(e=>[e.key,e])),[r]),ee=(0,j.useMemo)(()=>r.filter(e=>!e.printer_coupled&&!e.preset_defining),[r]),te=(0,j.useMemo)(()=>r.filter(e=>a?.has(e.key)).length,[r,a]),D=(0,j.useMemo)(()=>f?r.filter(e=>!f.schema[e.key]):[],[f,r]),O=e=>{if(!f)return;let n={};for(let[t,r]of Object.entries(e))f.schema[t]&&K(f.schema[t],r,c?.[t])&&(n[t]=r);t(e,G(n,f.schema))},ne=(t,n)=>{let r={...e};n===void 0?delete r[t]:r[t]=n,O(r)},k=(0,j.useMemo)(()=>{if(!f)return[];let e=e=>e.toLowerCase().replace(/[_\s]+/g,` `).trim(),t=e(S),n=e=>Je[f.schema[e]?.mode??`expert`]<=Je[g],r=(n,r,i)=>{if(!t)return!0;let a=f.schema[n];return[n,a?.label??``,a?.tooltip??``,r,i].some(n=>e(n).includes(t))};return f.tree.map(e=>({...e,groups:e.groups.map(t=>({...t,options:t.options.filter(i=>n(i)&&r(i,t.group,e.page))})).filter(e=>e.options.length>0)})).filter(e=>e.groups.length>0)},[f,g,S]),A=(0,j.useMemo)(()=>k.length===0||S.trim()?null:k.find(e=>e.page===v)??k[0],[k,v,S]),re=(0,j.useMemo)(()=>f?Object.keys(e).filter(t=>f.schema[t]&&K(f.schema[t],e[t],c?.[t])).length:0,[f,e,c]);if(!f)return(0,N.jsxs)(`div`,{className:`flex items-center justify-center gap-2 py-8 text-sm text-bambu-gray`,children:[(0,N.jsx)(m,{className:`w-4 h-4 animate-spin`}),d(`slicerSettings.loading`,`Loading slicer settings...`)]});let M=A?[A]:k;return(0,N.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,N.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,N.jsx)(`div`,{className:`flex overflow-hidden rounded border border-bambu-dark-tertiary`,children:qe.map(e=>(0,N.jsx)(`button`,{type:`button`,onClick:()=>_(e),disabled:n,className:`px-2.5 py-1 text-xs capitalize transition-colors ${g===e?`bg-bambu-green text-white`:`text-bambu-gray hover:text-white`}`,children:d(`slicerSettings.mode.${e}`,e)},e))}),(0,N.jsxs)(`div`,{className:`relative flex-1 min-w-[10rem]`,children:[(0,N.jsx)(h,{className:`absolute left-2 top-1/2 -translate-y-1/2 w-3.5 h-3.5 text-bambu-gray`}),(0,N.jsx)(`input`,{type:`search`,value:S,onChange:e=>C(e.target.value),disabled:n,placeholder:d(`slicerSettings.searchPlaceholder`,`Search settings`),className:`w-full rounded border border-bambu-dark-tertiary bg-bambu-dark pl-7 pr-2 py-1 text-xs text-white placeholder:text-bambu-gray/60 focus:border-bambu-green focus:outline-none disabled:opacity-40`})]}),re>0&&(0,N.jsxs)(`button`,{type:`button`,onClick:()=>O({}),disabled:n,className:`flex items-center gap-1 text-xs text-bambu-gray hover:text-white`,children:[(0,N.jsx)(y,{className:`w-3 h-3`}),d(`slicerSettings.resetAll`,`Reset {{count}}`,{count:re})]})]}),!l&&(0,N.jsx)(`p`,{className:`rounded border border-amber-300 bg-amber-50 px-2 py-1 text-[0.7rem] text-amber-800 dark:border-amber-700/40 dark:bg-amber-900/20 dark:text-amber-200`,children:u===`sidecar_outdated`?d(`slicerSettings.presetValuesOutdatedSidecar`,`Showing slicer defaults: your slicer sidecar is older than this feature and can't report a preset's values. Update the sidecar image to see them. Anything you don't change still uses the preset.`):u===`not_configured`?d(`slicerSettings.presetValuesNotConfigured`,`Showing slicer defaults: no slicer sidecar is configured, so a preset's values can't be read. Anything you don't change still uses the preset.`):u===`sidecar_unavailable`?d(`slicerSettings.presetValuesSidecarUnavailable`,`Showing slicer defaults: the slicer sidecar did not answer, so a preset's values can't be read. Anything you don't change still uses the preset.`):d(`slicerSettings.presetValuesUnavailable`,`Showing slicer defaults: the picked preset's own values could not be read. Anything you don't change still uses the preset.`)}),r.length>0&&o&&(0,N.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 rounded border border-bambu-dark-tertiary px-2 py-1.5 text-[0.7rem] text-bambu-gray`,children:[(0,N.jsx)(`span`,{className:`min-w-0 flex-1`,children:d(`slicerSettings.fromFileSummary`,`The designer changed {{count}} process settings in this file. Only the ones you tick are used.`,{count:r.length})}),(0,N.jsx)(`button`,{type:`button`,disabled:n,onClick:()=>ee.forEach(e=>o(e.key,!0)),title:d(`slicerSettings.fromFileUseAllHint`,`Ticks the settings that carry across printers. The ones tuned for the designer's own printer, and the ones that define the preset you picked, stay off.`),className:`shrink-0 rounded border border-bambu-dark-tertiary px-1.5 py-0.5 hover:text-white disabled:opacity-40`,children:d(`slicerSettings.fromFileUseAll`,`Use the designer's settings`)}),te>0&&(0,N.jsx)(`button`,{type:`button`,disabled:n,onClick:()=>r.forEach(e=>o(e.key,!1)),className:`shrink-0 rounded border border-bambu-dark-tertiary px-1.5 py-0.5 hover:text-white disabled:opacity-40`,children:d(`slicerSettings.fromFileClear`,`Clear {{count}}`,{count:te})})]}),!S.trim()&&(0,N.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:k.map(e=>(0,N.jsx)(`button`,{type:`button`,onClick:()=>b(e.page),disabled:n,className:`px-2 py-1 text-xs rounded transition-colors ${A?.page===e.page?`bg-bambu-dark-tertiary text-white`:`text-bambu-gray hover:text-white`}`,children:e.page},e.page))}),M.length===0?(0,N.jsx)(`p`,{className:`py-6 text-center text-xs text-bambu-gray`,children:d(`slicerSettings.noMatches`,`No settings match this search.`)}):(0,N.jsxs)(`div`,{className:`flex flex-col gap-4 max-h-[22rem] lg:max-h-[58vh] overflow-y-auto pr-1`,children:[M.map(t=>(0,N.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[S.trim()&&(0,N.jsx)(`p`,{className:`text-[0.7rem] uppercase tracking-wide text-bambu-gray/70`,children:t.page}),t.groups.map(r=>(0,N.jsxs)(`fieldset`,{className:`flex flex-col gap-1.5`,children:[(0,N.jsx)(`legend`,{className:`mb-1 text-xs font-medium text-white`,children:r.group}),r.options.map(t=>(0,N.jsx)(Xe,{optionKey:t,option:f.schema[t],value:e[t],onChange:e=>ne(t,e),disabled:n||T.has(t),disabledBySlicer:T.has(t),formDisabled:n,source:E.get(t),sourceOn:a?.has(t)??!1,onToggleSource:o,filamentChoices:Ke.has(t)?s:void 0,presetValue:c?.[t]},t))]},`${t.page}:${r.group}`))]},t.page)),D.length>0&&!S.trim()&&(0,N.jsxs)(`fieldset`,{className:`flex flex-col gap-1.5`,children:[(0,N.jsx)(`legend`,{className:`mb-1 text-xs font-medium text-white`,children:d(`slicerSettings.otherFromFile`,`Other settings from this file`)}),D.map(e=>(0,N.jsxs)(`label`,{className:`flex items-center gap-2 text-xs cursor-pointer`,children:[(0,N.jsx)(`input`,{type:`checkbox`,checked:a?.has(e.key)??!1,disabled:n||!o,onChange:t=>o?.(e.key,t.target.checked),className:`shrink-0 cursor-pointer disabled:opacity-40`}),(0,N.jsxs)(`span`,{className:`min-w-0 flex-1 truncate`,children:[(0,N.jsx)(`span`,{className:`font-mono text-bambu-gray`,children:e.key}),(0,N.jsx)(`span`,{className:`ml-1.5 text-white`,children:q(e.value)})]}),(e.printer_coupled||e.preset_defining)&&(0,N.jsx)(`span`,{className:`shrink-0 rounded bg-amber-100 px-1 py-0.5 text-[10px] text-amber-700 dark:bg-amber-500/20 dark:text-amber-400`,children:e.printer_coupled?d(`slicerSettings.fromFilePrinterCoupled`,`designer's printer`):d(`slicerSettings.fromFileOverridesPreset`,`overrides preset`)})]},e.key))]})]})]})}function Xe({optionKey:e,option:t,value:n,onChange:r,disabled:a,disabledBySlicer:o,formDisabled:s,source:c,sourceOn:l=!1,onToggleSource:u,filamentChoices:d,presetValue:f}){let{t:p}=i(),m=K(t,n,f),h=Ge(t),g=n===void 0?l&&c?q(c.value):U(t,f):String(n);return(0,N.jsxs)(`div`,{className:`flex items-center gap-2 group`,title:t.tooltip,children:[(0,N.jsxs)(`label`,{htmlFor:`slicer-opt-${e}`,className:`flex min-w-0 flex-1 items-center gap-1 text-xs ${o?`text-bambu-gray/40`:`text-bambu-gray`}`,children:[(0,N.jsx)(`span`,{className:`truncate`,title:t.label||e,children:t.label||e}),m&&(0,N.jsx)(`span`,{className:`shrink-0 text-bambu-green`,"aria-hidden":`true`,children:`•`}),c&&(0,N.jsx)(`span`,{className:`shrink-0 rounded px-1 py-0.5 text-[10px] ${c.printer_coupled||c.preset_defining?`bg-amber-100 text-amber-700 dark:bg-amber-500/20 dark:text-amber-400`:`bg-bambu-green/15 text-bambu-green`}`,title:c.printer_coupled?p(`slicerSettings.fromFilePrinterCoupledHint`,`Tuned for the printer this file was designed for -- may be wrong or out of range on yours.`):c.preset_defining?p(`slicerSettings.fromFileOverridesPresetHint`,`The file sets this to {{value}} where the preset you picked uses {{preset}}. Tick it only if the file should win.`,{value:q(c.value),preset:U(t,f)}):p(`slicerSettings.fromFileHint`,`The designer changed this in the source file. Its value is {{value}}.`,{value:q(c.value)}),children:c.printer_coupled?p(`slicerSettings.fromFilePrinterCoupled`,`designer's printer`):c.preset_defining?p(`slicerSettings.fromFileOverridesPreset`,`overrides preset`):p(`slicerSettings.fromFile`,`from file`)})]}),(0,N.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1.5`,children:[(0,N.jsx)(`span`,{className:`flex w-3 shrink-0 justify-center`,children:c&&u&&(0,N.jsx)(`input`,{type:`checkbox`,checked:l,disabled:s,onChange:t=>u(e,t.target.checked),"aria-label":p(`slicerSettings.useFromFile`,`Use the source file's value for {{option}}`,{option:t.label||e}),title:p(`slicerSettings.useFromFile`,`Use the source file's value for {{option}}`,{option:t.label||e}),className:`w-3 h-3 cursor-pointer disabled:opacity-40`})}),(0,N.jsx)(`div`,{className:`w-40`,children:(0,N.jsx)(Ze,{id:`slicer-opt-${e}`,option:t,current:g,onChange:r,disabled:a,filamentChoices:d})}),(0,N.jsx)(`span`,{className:`w-16 shrink-0 whitespace-nowrap text-[0.65rem] text-bambu-gray/60`,children:h??``}),(0,N.jsx)(`button`,{type:`button`,onClick:()=>r(void 0),disabled:a||!m,"aria-label":p(`slicerSettings.resetOption`,`Reset to default`),className:`p-0.5 transition-opacity ${m?`text-bambu-gray hover:text-white`:`opacity-0 pointer-events-none`}`,children:(0,N.jsx)(y,{className:`w-3 h-3`})})]})]})}function q(e){return Array.isArray(e)?e.map(e=>String(e)).join(`, `):e==null?``:String(e)}function Ze({id:e,option:t,current:n,onChange:r,disabled:a,filamentChoices:o}){let{t:s}=i(),c=`w-full rounded border border-bambu-dark-tertiary bg-bambu-dark px-1.5 py-0.5 text-xs text-white focus:border-bambu-green focus:outline-none disabled:opacity-40`;if(o&&o.length>0){let t=o.find(e=>String(e.index)===n);return(0,N.jsxs)(`div`,{className:`relative w-full`,children:[(0,N.jsxs)(`select`,{id:e,value:n,onChange:e=>r(e.target.value),disabled:a,className:`${c} w-full cursor-pointer appearance-none pr-5`,title:t?.label,children:[(0,N.jsx)(`option`,{value:`0`,children:s(`slicerSettings.filamentDefault`,`Default`)}),o.map(e=>(0,N.jsxs)(`option`,{value:String(e.index),children:[e.index,`: `,e.label]},e.index))]}),(0,N.jsx)(u,{className:`pointer-events-none absolute right-1.5 top-1/2 h-3 w-3 -translate-y-1/2 text-bambu-gray`})]})}return t.type===`coBool`?(0,N.jsx)(`input`,{id:e,type:`checkbox`,checked:n===`1`||n===`true`,onChange:e=>r(e.target.checked),disabled:a,className:`w-3.5 h-3.5 cursor-pointer disabled:opacity-40`}):t.type===`coEnum`&&t.enum_values?(0,N.jsxs)(`div`,{className:`relative w-full`,children:[(0,N.jsx)(`select`,{id:e,value:n,onChange:e=>r(e.target.value),disabled:a,className:`${c} w-full cursor-pointer appearance-none pr-5`,children:t.enum_values.map((e,n)=>(0,N.jsx)(`option`,{value:e,children:t.enum_labels?.[n]??e},e))}),(0,N.jsx)(u,{className:`pointer-events-none absolute right-1.5 top-1/2 h-3 w-3 -translate-y-1/2 text-bambu-gray`})]}):t.type===`coInt`||t.type===`coFloat`||t.type===`coPercent`?(0,N.jsx)(`input`,{id:e,type:`number`,value:n.replace(`%`,``),min:We(t.min),max:We(t.max),step:t.type===`coInt`?1:`any`,onChange:e=>r(e.target.value),disabled:a,className:c}):(0,N.jsx)(`input`,{id:e,type:`text`,value:n,onChange:e=>r(e.target.value),disabled:a,className:c})}var Qe=`bambuddy.slice.onlyConnectedModels`,$e=`bambuddy.slice.onlyLoadedSpools`;function et(e){try{return localStorage.getItem(e)===`true`}catch{return!1}}function tt(e,t){try{localStorage.setItem(e,String(t))}catch{}}var nt=[];function J(e){return e?`${e.source}:${e.id}`:``}function Y(e){if(!e)return null;let t=e.indexOf(`:`);if(t<0)return null;let n=e.slice(0,t),r=e.slice(t+1);return n!==`orca_cloud`&&n!==`cloud`&&n!==`local`&&n!==`standard`?null:{source:n,id:r}}function rt({requestId:e,sourceName:t}){let{t:n}=i(),{showPersistentToast:a,dismissToast:o}=d(),[s,c]=(0,j.useState)(0),[l,u]=(0,j.useState)(null),f=t;try{f=decodeURIComponent(t)}catch{}(0,j.useEffect)(()=>{let e=Date.now(),t=setInterval(()=>c(Math.floor((Date.now()-e)/1e3)),1e3);return()=>clearInterval(t)},[]),(0,j.useEffect)(()=>{let t=!1,n=setInterval(async()=>{if(t)return;let n=await r.getPreviewSliceProgress(e);!t&&n&&u(n)},1e3);return()=>{t=!0,clearInterval(n)}},[e]);let p=`slice-preview-${e}`;(0,j.useEffect)(()=>{let e=l&&l.stage&&l.total_percent>0,t=it(s);return e?a(p,n(`slice.previewWithProgress`,`Analyzing {{name}} — {{stage}} ({{percent}}%) — {{elapsed}}`,{name:f,stage:l.stage,percent:Math.min(100,Math.max(0,Math.round(l.total_percent))),elapsed:t}),`loading`):a(p,n(`slice.previewToast`,{name:f,elapsed:t}),`loading`),()=>{o(p)}},[s,l,f,a,o,n,p]);let h=l?.stage,g=l?.total_percent,_=h&&typeof g==`number`&&g>0?`${h} (${Math.min(100,Math.max(0,Math.round(g)))}%)`:n(`slice.analyzingPlateFilaments`);return(0,N.jsxs)(`div`,{className:`flex flex-col gap-1 text-bambu-gray text-sm py-2`,children:[(0,N.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,N.jsx)(m,{className:`w-4 h-4 animate-spin`}),_,(0,N.jsxs)(`span`,{className:`text-xs tabular-nums`,children:[s,`s`]})]}),s>=5&&(0,N.jsx)(`div`,{className:`text-xs text-bambu-gray/70 pl-6`,children:n(`slice.analyzingPlateFilamentsHint`,`Running a preview slice to discover which AMS slots this plate uses. Cached after — re-opening is instant.`)})]})}function it(e){let t=Math.max(0,Math.floor(e));if(t<60)return`${t}s`;let n=Math.floor(t/60),r=t%60;return n<60?`${n}m ${r}s`:`${Math.floor(n/60)}h ${n%60}m`}var at=`#00AE42`;function X(e){let t=(e||``).trim();return/^#[0-9a-fA-F]{6}([0-9a-fA-F]{2})?$/.test(t)?t.slice(0,7).toUpperCase():at}function ot({source:e,onClose:t,defaultAutoArrange:n=!1}){let{t:a}=i(),{trackJob:l}=ee(),u=o(),[f,h]=(0,j.useState)(null),[_,v]=(0,j.useState)(null),[y,b]=(0,j.useState)([]),x=(0,j.useRef)(new Set),C=(0,j.useRef)(!1),[w,T]=(0,j.useState)([]),[E,te]=(0,j.useState)(null),[D,ne]=(0,j.useState)(null),[A,re]=(0,j.useState)(!1),[M,P]=(0,j.useState)(null),[F,le]=(0,j.useState)(!1),[ue,de]=(0,j.useState)(!1),[me,he]=(0,j.useState)(n),[ge,xe]=(0,j.useState)(new Set),[Se,Ce]=(0,j.useState)({}),[we,Te]=(0,j.useState)({}),[Ee,Oe]=(0,j.useState)(!1),ke=ie(),je=ke||Ee,Ne=s({queryKey:[`slicer-pipelines`],queryFn:()=>r.listSlicerPipelines(),staleTime:6e4}),[Pe,L]=(0,j.useState)(!1),[Fe,R]=(0,j.useState)(``),{showToast:z}=d(),Ie=c({mutationFn:e=>r.createSlicerPipeline(e),onSuccess:()=>{u.invalidateQueries({queryKey:[`slicer-pipelines`]}),z(a(`slice.pipelines.toast.saved`,`Pipeline saved`),`success`),L(!1),R(``)},onError:e=>{z(e.message||a(`slice.pipelines.toast.saveFailed`,`Save failed`),`error`)}}),B=s({queryKey:[`slicePlates`,e.kind,e.id],queryFn:async()=>e.kind===`libraryFile`?r.getLibraryFilePlates(e.id):r.getArchivePlates(e.id),staleTime:6e4}),Le=!!B.data?.is_multi_plate&&(B.data?.plates?.length??0)>1,Re=Le&&D==null,ze=D??1,Be=(0,j.useMemo)(()=>{let t=typeof crypto<`u`&&`randomUUID`in crypto?crypto.randomUUID():`${Date.now()}-${Math.random().toString(36).slice(2)}`;return`${e.kind}-${e.id}-p${ze}-${t}`},[e.kind,e.id,ze]),Ve=s({queryKey:[`sliceFilamentReqs`,e.kind,e.id,ze],queryFn:async()=>e.kind===`libraryFile`?r.getLibraryFileFilamentRequirements(e.id,ze,Be,!0):r.getArchiveFilamentRequirements(e.id,ze,Be,!0),enabled:!Re,staleTime:6e4}),V=(0,j.useMemo)(()=>{let e=Ve.data?.filaments??[],t=e.length>0?e:[{slot_id:1,type:``,color:``,used_grams:0,used_meters:0}];return A?t.map(e=>({...e,used_in_plate:!0})):t},[A,Ve.data]),H=s({queryKey:[`slicerPresets`],queryFn:()=>r.getSlicerPresets(),staleTime:6e4,enabled:!B.isLoading&&!Re}),[He,Ue]=(0,j.useState)(!1),We=async()=>{if(!He){Ue(!0);try{let e=await r.getSlicerPresets({refresh:!0});u.setQueryData([`slicerPresets`],e)}catch{u.invalidateQueries({queryKey:[`slicerPresets`]})}finally{Ue(!1)}}},Ge=s({queryKey:[`slicerPrinterModels`],queryFn:r.getSlicerPrinterModels,staleTime:1/0}),U=(0,j.useMemo)(()=>!H.data||!f?null:I(H.data,f,`printer`)?.name??null,[H.data,f]),W=(0,j.useMemo)(()=>{let e={},t=H.data;if(!t)return e;for(let n of[t.local,t.orca_cloud,t.cloud,t.standard])for(let t of n.printer)t.inherits&&!Object.hasOwn(e,t.name)&&(e[t.name]=t.inherits);return e},[H.data]),G=(0,j.useMemo)(()=>k(Ge.data??{},W),[Ge.data,W]),[K,Ke]=(0,j.useState)(()=>et(Qe)),[qe,Je]=(0,j.useState)(()=>et($e)),[Xe,q]=(0,j.useState)(null),Ze=s({queryKey:[`slicerLoadedSpools`],queryFn:r.getSlicerLoadedSpools,staleTime:15e3,retry:!1,enabled:!Re}),J=Ze.data?.printers??nt,Y=(0,j.useMemo)(()=>Ge.data??{},[Ge.data]),it=(0,j.useMemo)(()=>_e(J,ve(U,Y,W)),[J,U,Y,W]),at=(0,j.useMemo)(()=>H.data?De(H.data):new Map,[H.data]),X=(0,j.useMemo)(()=>H.data?Ae(it,H.data,at,U,G):new Set,[it,H.data,at,U,G]),ot=(0,j.useMemo)(()=>{if(!K||J.length===0)return null;let e=J.map(e=>e.model);return t=>ye(t,e,Y,W)},[K,J,Y,W]),Z=(0,j.useMemo)(()=>!qe||X.size===0?null:e=>X.has(`${e.source}:${e.id}`),[qe,X]),ut=(0,j.useMemo)(()=>{let e=H.data;if(!e||!Z)return null;let t=e=>({...e,filament:e.filament.filter(Z)});return{...e,local:t(e.local),orca_cloud:t(e.orca_cloud),cloud:t(e.cloud),standard:t(e.standard)}},[H.data,Z]),dt=s({queryKey:[`slicer-preset-values`,_?.source,_?.id],queryFn:()=>r.getSlicerPresetValues(_),enabled:_!=null,staleTime:5*6e4}),ft=dt.data?.values,pt=dt.data?.resolved??dt.isLoading,mt=dt.data?.reason??(dt.isError?`sidecar_unavailable`:void 0),ht=(0,j.useMemo)(()=>{let e=H.data;return V.map((t,n)=>{let r=y[n]??null,i=e&&r?I(e,r,`filament`):null;return{index:n+1,label:i?.name||t.type||a(`slice.filamentSlotUnset`,`not set`),color:t.color||void 0}})},[V,y,H.data,a]),Q=B.data?.embedded_printer??null,gt=(0,j.useMemo)(()=>B.data?.design_overrides??[],[B.data]),_t=B.data?.embedded_process??null,vt=(0,j.useMemo)(()=>{if(!Q||!_t||!U)return!1;let e=e=>e.replace(/^#\s*/,``).trim().toLowerCase();return e(U)===e(Q)},[Q,_t,U]);(0,j.useEffect)(()=>{vt||le(!1)},[vt]),(0,j.useEffect)(()=>{xe(F?new Set(gt.map(e=>e.key)):new Set)},[gt,F]),(0,j.useEffect)(()=>{let e=H.data;e&&(f??h(se(e,`printer`,Q)??oe(e,`printer`)))},[H.data,Q]),(0,j.useEffect)(()=>{let e=H.data;if(!e||!ot||C.current||!f||F)return;let t=I(e,f,`printer`);if(t&&ot(t))return;let n=se(e,`printer`,Q),r=I(e,n,`printer`),i=r&&ot(r)?n:be(e,J.map(e=>e.model),Y,W);i&&h(i)},[H.data,ot,f,Q,J,Y,W,F]),(0,j.useEffect)(()=>{let e=H.data;e&&v(t=>{if(t){let n=I(e,t,`process`);if(n&&O(n,`process`,U,G)!==`mismatch`)return t}return ce(e,U,G,_t)})},[H.data,U,G,_t]),(0,j.useEffect)(()=>{let e=H.data;e&&b(t=>V.map((n,r)=>{let i=t[r]??null;if(i){let t=I(e,i,`filament`),a=t&&!x.current.has(r)&&fe(t,n.type),o=t&&Z!==null&&!x.current.has(r)&&!Z(t);if(t&&!a&&!o&&O(t,`filament`,U,G)!==`mismatch`)return i}let a={type:n.type,color:n.color},o=ut&&pe(ut,a,U,G),s=I(e,o??null,`filament`);return o&&s&&!fe(s,n.type)?o:pe(e,a,U,G)}))},[H.data,V,U,G,Z,ut]),(0,j.useEffect)(()=>{T(e=>e.length===V.length?e:(x.current=new Set,V.map(()=>null)))},[V]);let yt=c({mutationFn:async t=>{let n=bt(t);return e.kind===`libraryFile`?r.sliceLibraryFile(e.id,n):r.sliceArchive(e.id,n)},onSuccess:n=>{l(n.job_id,e.kind,e.filename),t()},onError:e=>{te(e instanceof Error?e.message:String(e))}});function bt(e){if(!f||!_||y.length===0||y.some(e=>e==null))throw Error(a(`slice.allPresetsRequired`));return{printer_preset:f,process_preset:_,filament_preset:y[0],filament_presets:y,filament_colours:V.map((e,t)=>w[t]??e.color??``),...e==null?{}:{plate:e},...M==null?{}:{bed_type:M},...F&&vt?{use_embedded_settings:!0}:{},...!F&>.length>0?{design_overrides:[...ge]}:{},...!F&&Object.keys(Se).length>0?{process_overrides:we}:{},...ue?{auto_orient:!0}:{},...me?{auto_arrange:!0}:{}}}let xt=f!=null&&_!=null&&Ve.isSuccess&&y.length>0&&y.every(e=>e!=null),$=yt.isPending,St=B.data?.plates?.length??0,Ct=Le&&St>1&&!Re;return Re&&B.data?(0,N.jsx)(ae,{plates:B.data.plates,onSelect:e=>ne(e),onClose:t}):(0,N.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-4`,onClick:()=>{$||t()},children:[(0,N.jsxs)(`div`,{className:`w-full max-w-xl lg:max-w-5xl xl:max-w-7xl 2xl:max-w-[96rem] max-h-[85vh] flex flex-col rounded-lg bg-bambu-dark-secondary border border-bambu-dark-tertiary/60`,onClick:e=>e.stopPropagation(),children:[(0,N.jsxs)(`div`,{className:`flex-shrink-0 flex items-start justify-between gap-3 px-4 pt-4 pb-3 border-b border-bambu-dark-tertiary/40`,children:[(0,N.jsxs)(`div`,{className:`min-w-0`,children:[(0,N.jsxs)(`h3`,{className:`text-white font-medium flex items-center gap-2`,children:[(0,N.jsx)(p,{className:`w-4 h-4`}),a(`slice.title`)]}),(0,N.jsxs)(`p`,{className:`text-xs text-bambu-gray mt-1 truncate`,title:e.filename,children:[e.filename,D==null?``:` • ${a(`archives.platePicker.plateLabel`,{index:D})}`]})]}),(0,N.jsx)(`button`,{onClick:t,disabled:$,className:`flex-shrink-0 text-bambu-gray hover:text-white transition-colors disabled:opacity-50`,"aria-label":a(`common.close`),children:(0,N.jsx)(g,{className:`w-5 h-5`})})]}),(0,N.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-4 space-y-4`,children:[(B.isLoading||H.isLoading)&&(0,N.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray text-sm`,children:[(0,N.jsx)(m,{className:`w-4 h-4 animate-spin`}),a(`slice.loadingPresets`)]}),H.isError&&(0,N.jsx)(`div`,{className:`text-sm text-red-700 dark:text-red-400`,role:`alert`,children:a(`slice.presetsLoadFailed`,`Failed to load presets. Open Settings → Profiles to import them, or sign in to Bambu Cloud.`)}),H.data&&(0,N.jsxs)(N.Fragment,{children:[(0,N.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,N.jsxs)(`div`,{className:`flex-1 space-y-2`,children:[(0,N.jsx)(st,{status:H.data.cloud_status,cloudName:`bambu`}),(0,N.jsx)(st,{status:H.data.orca_cloud_status,cloudName:`orca`})]}),(0,N.jsxs)(`button`,{type:`button`,onClick:We,disabled:He||$,className:`flex-shrink-0 inline-flex items-center gap-1 px-2 py-1 rounded-md text-xs text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary/40 disabled:opacity-50 disabled:cursor-not-allowed transition-colors`,title:a(`slice.refreshPresetsTitle`),"aria-label":a(`slice.refreshPresets`),children:[(0,N.jsx)(S,{className:`w-3.5 h-3.5 ${He?`animate-spin`:``}`}),a(`slice.refreshPresets`)]})]}),(0,N.jsxs)(`div`,{className:`lg:grid lg:grid-cols-[minmax(20rem,2fr)_minmax(0,3fr)] lg:gap-5 lg:items-start`,children:[(0,N.jsxs)(`div`,{className:`space-y-4 min-w-0`,children:[(0,N.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 px-2 py-1.5 rounded-md bg-bambu-dark/40 border border-bambu-dark-tertiary`,children:[(0,N.jsxs)(`span`,{className:`text-xs font-medium text-bambu-gray flex items-center gap-1`,children:[(0,N.jsx)(p,{className:`w-3.5 h-3.5`}),` `,a(`slice.pipelines.label`,`Pipeline`)]}),(0,N.jsxs)(`select`,{value:``,disabled:$||(Ne.data?.pipelines.length??0)===0,onChange:e=>{let t=parseInt(e.target.value,10);if(Number.isNaN(t))return;let n=Ne.data?.pipelines.find(e=>e.id===t);n&&(C.current=!0,h(n.printer_preset),v(n.process_preset),P(n.bed_type),b(e=>{let t=e.length>0?[...e]:n.filament_presets.map(()=>null);for(let e=0;e(0,N.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),Pe?(0,N.jsxs)(`div`,{className:`flex items-center gap-1 flex-1 min-w-[16ch]`,children:[(0,N.jsx)(`input`,{autoFocus:!0,value:Fe,onChange:e=>R(e.target.value),placeholder:a(`slice.pipelines.namePlaceholder`,`Pipeline name`),"aria-label":a(`slice.pipelines.nameAria`,`New pipeline name`),className:`flex-1 text-xs px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white`}),(0,N.jsx)(`button`,{type:`button`,onClick:()=>{let e=Fe.trim();if(!e||!f||!_)return;let t=y.filter(e=>e!==null);t.length!==0&&Ie.mutate({name:e,printer_preset:f,process_preset:_,filament_presets:t,bed_type:M})},disabled:Ie.isPending||!Fe.trim(),className:`text-xs px-2 py-1 bg-bambu-green hover:bg-bambu-green/80 text-white rounded disabled:opacity-50`,children:Ie.isPending?(0,N.jsx)(m,{className:`w-3 h-3 animate-spin`}):a(`common.save`,`Save`)}),(0,N.jsx)(`button`,{type:`button`,onClick:()=>{L(!1),R(``)},className:`text-xs px-2 py-1 text-bambu-gray hover:text-white`,children:a(`common.cancel`,`Cancel`)})]}):(0,N.jsx)(`button`,{type:`button`,onClick:()=>{R(``),L(!0)},disabled:$||!f||!_||y.length===0||y.some(e=>e===null),className:`text-xs px-2 py-1 bg-bambu-green/20 hover:bg-bambu-green/30 text-bambu-green border border-bambu-green/40 rounded disabled:opacity-50 disabled:cursor-not-allowed`,title:a(`slice.pipelines.saveTitle`,`Save the current four-slot selection as a reusable pipeline`),children:a(`slice.pipelines.saveButton`,`Save as pipeline`)})]}),Ze.isSuccess&&(0,N.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,N.jsxs)(`label`,{className:`flex items-start gap-2 text-sm text-bambu-gray cursor-pointer select-none`,children:[(0,N.jsx)(`input`,{type:`checkbox`,checked:K,onChange:e=>{Ke(e.target.checked),tt(Qe,e.target.checked)},disabled:$,className:`mt-0.5 cursor-pointer`}),(0,N.jsxs)(`span`,{children:[a(`slice.filters.onlyConnectedModels`,`Only printers that are online`),(0,N.jsx)(`span`,{className:`block text-xs text-bambu-gray/70`,children:a(`slice.filters.onlyConnectedModelsHint`,`Printer profiles for the models online right now, at every nozzle size.`)})]})]}),(0,N.jsxs)(`label`,{className:`flex items-start gap-2 text-sm text-bambu-gray cursor-pointer select-none`,children:[(0,N.jsx)(`input`,{type:`checkbox`,checked:qe,onChange:e=>{Je(e.target.checked),tt($e,e.target.checked)},disabled:$,className:`mt-0.5 cursor-pointer`}),(0,N.jsxs)(`span`,{children:[a(`slice.filters.onlyLoadedSpools`,`Only spools that are loaded`),(0,N.jsx)(`span`,{className:`block text-xs text-bambu-gray/70`,children:a(`slice.filters.onlyLoadedSpoolsHint`,`Filament profiles of the spools in the online printers of the selected model. A profile you pick yourself stays.`)})]})]}),(K||qe)&&J.length===0&&(0,N.jsx)(`p`,{className:`text-xs text-bambu-gray/70`,role:`status`,children:a(`slice.filters.noneOnline`,`No printer is online, so every profile is shown.`)}),qe&&J.length>0&&X.size===0&&(0,N.jsx)(`p`,{className:`text-xs text-bambu-gray/70`,role:`status`,children:a(`slice.filters.noneLoaded`,`No loaded spool has a profile for this printer, so every filament profile is shown.`)})]}),(0,N.jsx)(lt,{label:a(`slice.printer`),slot:`printer`,data:H.data,value:f,onChange:e=>{C.current=!0,h(e)},allowed:ot,filteredLabel:a(`slice.filters.notOnline`,`Not online`),disabled:$||F}),vt&&(0,N.jsxs)(`label`,{className:`flex items-start gap-2 text-sm text-bambu-gray cursor-pointer select-none`,children:[(0,N.jsx)(`input`,{type:`checkbox`,checked:F,onChange:e=>le(e.target.checked),disabled:$,className:`mt-0.5 cursor-pointer`}),(0,N.jsxs)(`span`,{children:[a(`slice.useEmbedded`),(0,N.jsx)(`span`,{className:`block text-xs text-bambu-gray/70`,children:a(`slice.useEmbeddedHint`)})]})]}),(0,N.jsx)(lt,{label:a(`slice.process`),slot:`process`,data:H.data,value:_,onChange:v,disabled:$||F,selectedPrinterName:U,compatIndex:G}),(0,N.jsx)(ct,{value:M,onChange:P,disabled:$||F}),(0,N.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,N.jsxs)(`label`,{className:`flex items-start gap-2 text-sm text-bambu-gray cursor-pointer select-none`,children:[(0,N.jsx)(`input`,{type:`checkbox`,checked:ue,onChange:e=>de(e.target.checked),disabled:$,className:`mt-0.5 cursor-pointer`}),(0,N.jsxs)(`span`,{children:[a(`slice.autoOrient`),(0,N.jsx)(`span`,{className:`block text-xs text-bambu-gray/70`,children:a(`slice.autoOrientHint`)})]})]}),(0,N.jsxs)(`label`,{className:`flex items-start gap-2 text-sm text-bambu-gray cursor-pointer select-none`,children:[(0,N.jsx)(`input`,{type:`checkbox`,checked:me,onChange:e=>he(e.target.checked),disabled:$,className:`mt-0.5 cursor-pointer`}),(0,N.jsxs)(`span`,{children:[a(`slice.autoArrange`),(0,N.jsx)(`span`,{className:`block text-xs text-bambu-gray/70`,children:a(`slice.autoArrangeHint`)})]})]})]}),Ve.isLoading?(0,N.jsx)(rt,{requestId:Be,sourceName:e.filename}):V.map((e,t)=>{let n=e.used_in_plate!==!1,r=V.length>1?a(`slice.filamentSlot`,{index:t+1,type:e.type}):a(`slice.filament`);return(0,N.jsx)(lt,{label:n?r:`${r} ${a(`slice.notUsedByPlate`)}`,slot:`filament`,data:H.data,value:y[t]??null,onChange:e=>{x.current.add(t),b(n=>{let r=n.length===V.length?[...n]:V.map((e,t)=>n[t]??null);return r[t]=e,r})},disabled:$||!n||F,swatchColor:w[t]??e.color,swatchColorLabel:a(`slice.filamentColour`),onSwatchColorChange:e=>T(n=>{let r=n.length===V.length?[...n]:V.map((e,t)=>n[t]??null);return r[t]=e,r}),selectedPrinterName:U,compatIndex:G,allowed:Z,filteredLabel:a(`slice.filters.notLoaded`,`Not loaded`),onPick:J.length>0?()=>q(t):void 0},`filament-${t}`)})]}),(0,N.jsx)(`div`,{className:`mt-4 lg:mt-0 min-w-0`,children:(0,N.jsxs)(`div`,{className:`rounded border border-bambu-dark-tertiary p-3 ${F?`opacity-60`:``}`,children:[(0,N.jsxs)(`button`,{type:`button`,onClick:()=>Oe(e=>!e),"aria-expanded":je,disabled:ke,className:`flex w-full items-center justify-between gap-2 text-left lg:cursor-default`,children:[(0,N.jsxs)(`span`,{className:`text-sm text-white`,children:[a(`slice.processSettings`,`Process settings`),(0,N.jsx)(`span`,{className:`block text-xs text-bambu-gray/70`,children:F?a(`slice.processSettingsEmbedded`,`Not used while "Use the file's built-in settings" is on -- the file's own settings drive this slice.`):a(`slice.processSettingsHint`,`Adjust the picked preset for this slice. Anything you don't touch stays as the preset defines it.`)})]}),(0,N.jsx)(`span`,{className:`shrink-0 text-xs text-bambu-gray`,children:F?a(`slice.processSettingsInactive`,`Inactive`):Object.keys(we).length>0?a(`slice.processSettingsChanged`,`{{count}} changed`,{count:Object.keys(we).length}):a(`slice.processSettingsUnchanged`,`Preset defaults`)})]}),je&&(0,N.jsx)(`div`,{className:`mt-3 border-t border-bambu-dark-tertiary pt-3`,children:(0,N.jsx)(Ye,{values:Se,onChange:(e,t)=>{Ce(e),Te(t)},disabled:$||F,filamentChoices:ht,presetValues:ft,presetValuesResolved:pt,presetValuesReason:mt,sourceOverrides:gt,sourceSelected:ge,onToggleSource:(e,t)=>xe(n=>{let r=new Set(n);return t?r.add(e):r.delete(e),r})})})]})})]})]}),E&&(0,N.jsx)(`div`,{className:`text-sm text-red-700 dark:text-red-400 bg-red-900/20 border border-red-900/40 rounded p-2`,role:`alert`,children:E})]}),(0,N.jsxs)(`div`,{className:`flex-shrink-0 flex justify-end gap-2 px-4 py-3 border-t border-bambu-dark-tertiary/40`,children:[(0,N.jsx)(`button`,{type:`button`,onClick:t,disabled:$,className:`px-3 py-1.5 text-sm rounded-md border border-bambu-dark-tertiary text-bambu-gray hover:text-white hover:border-bambu-gray transition-colors disabled:opacity-50`,children:a(`common.cancel`)}),Ct&&(0,N.jsxs)(`label`,{className:`flex items-center gap-2 mr-auto text-sm text-bambu-gray cursor-pointer select-none`,title:a(`slice.actionAllTitle`,{count:St}),children:[(0,N.jsx)(`input`,{type:`checkbox`,checked:A,onChange:e=>re(e.target.checked),disabled:$,className:`cursor-pointer`}),a(`slice.allPlatesToggle`,{count:St})]}),(0,N.jsx)(`button`,{type:`button`,onClick:()=>{te(null);let e=A?0:D;yt.mutate(e)},disabled:!xt||$,className:`px-3 py-1.5 text-sm rounded-md bg-bambu-green hover:bg-bambu-green/90 text-bambu-dark font-medium transition-colors disabled:opacity-50 disabled:cursor-not-allowed flex items-center gap-2`,children:$?(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(m,{className:`w-4 h-4 animate-spin`}),a(`slice.enqueuing`)]}):A?a(`slice.actionAll`,{count:St}):a(`slice.action`)})]})]}),Xe!==null&&H.data&&V[Xe]&&(0,N.jsx)(`div`,{onClick:e=>e.stopPropagation(),children:(0,N.jsx)(Me,{printers:it,data:H.data,index:at,selectedPrinterName:U,compatIndex:G,slotLabel:V.length>1?a(`slice.filamentSlot`,{index:Xe+1,type:V[Xe].type}):a(`slice.filament`),onClose:()=>q(null),onPick:(e,t)=>{let n=Xe;x.current.add(n),b(t=>{let r=t.length===V.length?[...t]:V.map((e,n)=>t[n]??null);return r[n]=e.ref,r}),t&&T(e=>{let r=e.length===V.length?[...e]:V.map((t,n)=>e[n]??null);return r[n]=t,r}),q(null)}})})]})}function st({status:e,cloudName:t=`bambu`}){let{t:n}=i();if(e===`ok`||e===`not_authenticated`)return null;let r=t===`orca`?{expired:{key:`slice.orcaCloud.expired`,fallback:`Orca Cloud session expired — sign in again to refresh your Orca presets.`},unreachable:{key:`slice.orcaCloud.unreachable`,fallback:`Orca Cloud is unreachable right now. Other presets still work.`}}:{expired:{key:`slice.cloud.expired`,fallback:`Bambu Cloud session expired — sign in again to refresh your cloud presets.`},unreachable:{key:`slice.cloud.unreachable`,fallback:`Bambu Cloud is unreachable right now. Local and standard presets still work.`}},{tone:a,icon:o}={expired:{tone:`border-amber-300 dark:border-amber-700/40 bg-amber-50 dark:bg-amber-900/20 text-amber-800 dark:text-amber-200`,icon:f},unreachable:{tone:`border-bambu-dark-tertiary/40 bg-bambu-dark text-bambu-gray`,icon:f}}[e],{key:s,fallback:c}=r[e];return(0,N.jsxs)(`div`,{className:`flex items-start gap-2 text-xs rounded-md border p-2 ${a}`,role:`status`,children:[(0,N.jsx)(o,{className:`w-4 h-4 flex-shrink-0 mt-0.5`}),(0,N.jsx)(`span`,{children:n(s,c)})]})}var Z=[{value:`Cool Plate`,labelKey:`slice.bedType.coolPlate`,fallback:`Cool Plate`},{value:`Cool Plate (SuperTack)`,labelKey:`slice.bedType.coolPlateSuperTack`,fallback:`Cool Plate SuperTack`},{value:`Engineering Plate`,labelKey:`slice.bedType.engineering`,fallback:`Engineering Plate`},{value:`High Temp Plate`,labelKey:`slice.bedType.highTemp`,fallback:`High Temp Plate`},{value:`Textured PEI Plate`,labelKey:`slice.bedType.texturedPEI`,fallback:`Textured PEI Plate`},{value:`Smooth PEI Plate`,labelKey:`slice.bedType.smoothPEI`,fallback:`Smooth PEI Plate`}];function ct({value:e,onChange:t,disabled:n}){let{t:r}=i();return(0,N.jsxs)(`label`,{className:`block`,children:[(0,N.jsx)(`span`,{className:`block text-xs text-bambu-gray mb-1`,children:r(`slice.bedType.label`)}),(0,N.jsxs)(`select`,{value:e??``,onChange:e=>t(e.target.value===``?null:e.target.value),disabled:n,className:`flex-1 min-w-0 px-3 py-2 rounded-md bg-bambu-dark border border-bambu-dark-tertiary text-white text-sm focus:outline-none focus:border-bambu-gray disabled:opacity-50`,children:[(0,N.jsx)(`option`,{value:``,children:r(`slice.bedType.auto`)}),Z.map(e=>(0,N.jsx)(`option`,{value:e.value,children:r(e.labelKey,e.fallback)},e.value))]})]})}function lt({label:e,slot:t,data:n,value:r,onChange:a,disabled:o,swatchColor:s,onSwatchColorChange:c,swatchColorLabel:l,selectedPrinterName:u,compatIndex:d,allowed:f,filteredLabel:p,onPick:m}){let{t:h}=i(),[g,_]=(0,j.useState)(!1),v=(0,j.useId)(),y=`${v}-colour`,{sections:b,otherEntries:x,filteredEntries:S}=(0,j.useMemo)(()=>{let e=[{key:`local`,label:`slice.tier.local`,fallback:`Imported`},{key:`orca_cloud`,label:`slice.tier.orcaCloud`,fallback:`Orca Cloud`},{key:`cloud`,label:`slice.tier.cloud`,fallback:`Bambu Cloud`},{key:`standard`,label:`slice.tier.standard`,fallback:`Standard`}],r=t!==`printer`,i=[],a=[],o=[];for(let{key:s,label:c,fallback:l}of e){let e=n[s][t];if(e.length>0&&a.push({tierLabel:h(c,l),entries:e}),!r){e.length>0&&i.push({tierLabel:h(c,l),entries:e});continue}let f=[];for(let n of e)O(n,t,u??null,d??A)===`mismatch`?o.push(n):f.push(n);f.length>0&&i.push({tierLabel:h(c,l),entries:f})}if(i.length===0&&o.length>0)return{sections:a,otherEntries:[],filteredEntries:[]};if(f){let e=[],t=[];for(let n of i){let r=n.entries.filter(e=>f(e)?!0:(t.push(e),!1));r.length>0&&e.push({tierLabel:n.tierLabel,entries:r})}if(e.length>0)return{sections:e,otherEntries:o,filteredEntries:t}}return{sections:i,otherEntries:o,filteredEntries:[]}},[n,t,h,u,d,f]),C=J(r),w=(0,j.useMemo)(()=>g?x:x.filter(e=>`${e.source}:${e.id}`===C),[g,x,C]),T=(0,j.useMemo)(()=>g?S:S.filter(e=>`${e.source}:${e.id}`===C),[g,S,C]),E=x.length-w.length+S.length-T.length,ee=b.reduce((e,t)=>e+t.entries.length,0)+w.length+T.length;return(0,N.jsxs)(`div`,{className:`block`,children:[(0,N.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-bambu-gray mb-1`,children:[!c&&s&&(0,N.jsx)(`span`,{className:`inline-block w-3 h-3 rounded-full border border-bambu-dark-tertiary`,style:{backgroundColor:s},"aria-hidden":!0}),(0,N.jsx)(`label`,{htmlFor:v,children:e}),(E>0||g)&&(0,N.jsxs)(`span`,{className:`ml-auto flex items-center gap-1.5 font-normal`,children:[E>0&&(0,N.jsx)(`span`,{className:`text-bambu-gray/60`,children:h(`slice.presetsHidden`,`{{count}} hidden`,{count:E})}),(0,N.jsx)(`button`,{type:`button`,onClick:()=>_(e=>!e),disabled:o,className:`text-bambu-green hover:underline disabled:opacity-50 disabled:no-underline`,children:g?h(`slice.showFewerPresets`,`Show fewer`):h(`slice.showAllPresets`,`Show all`)})]})]}),(0,N.jsxs)(`div`,{className:`flex items-stretch gap-2`,children:[(0,N.jsxs)(`select`,{id:v,value:J(r),onChange:e=>a(Y(e.target.value)),disabled:o||ee===0,className:`w-full px-3 py-2 rounded-md bg-bambu-dark border border-bambu-dark-tertiary text-white text-sm focus:outline-none focus:border-bambu-gray disabled:opacity-50`,children:[(0,N.jsx)(`option`,{value:``,children:h(ee===0?`slice.noPresetsForSlot`:`slice.selectPreset`)}),b.map(e=>(0,N.jsx)(`optgroup`,{label:e.tierLabel,children:e.entries.map(e=>(0,N.jsx)(`option`,{value:`${e.source}:${e.id}`,children:e.name},`${e.source}:${e.id}`))},e.tierLabel)),T.length>0&&(0,N.jsx)(`optgroup`,{label:p??h(`slice.otherPrinters`),children:T.map(e=>(0,N.jsx)(`option`,{value:`${e.source}:${e.id}`,children:e.name},`${e.source}:${e.id}`))}),w.length>0&&(0,N.jsx)(`optgroup`,{label:h(`slice.otherPrinters`),children:w.map(e=>(0,N.jsx)(`option`,{value:`${e.source}:${e.id}`,children:e.name},`${e.source}:${e.id}`))})]}),c&&(0,N.jsxs)(`label`,{htmlFor:y,title:l,className:`flex items-center gap-2 px-2.5 rounded-md bg-bambu-dark border border-bambu-dark-tertiary text-sm ${o?`opacity-50 cursor-not-allowed`:`cursor-pointer hover:border-bambu-gray transition-colors`}`,children:[(0,N.jsx)(`input`,{id:y,type:`color`,value:X(s),onChange:e=>c(e.target.value.toUpperCase()),disabled:o,"aria-label":l,style:{backgroundColor:X(s)},className:`slice-colour-swatch w-4 h-4 shrink-0 rounded-full border border-bambu-dark-tertiary p-0 disabled:cursor-not-allowed enabled:cursor-pointer`}),(0,N.jsx)(`span`,{className:`font-mono text-xs text-white tracking-tight`,children:X(s)})]}),m&&(0,N.jsxs)(`button`,{type:`button`,onClick:m,disabled:o,title:h(`slice.loadedSpools.pickTitle`,`Pick a spool loaded in a connected printer`),className:`flex items-center gap-1.5 px-2.5 rounded-md bg-bambu-dark border border-bambu-dark-tertiary text-sm text-bambu-gray transition-colors enabled:hover:text-white enabled:hover:border-bambu-gray disabled:opacity-50 disabled:cursor-not-allowed`,children:[(0,N.jsx)(re,{className:`w-4 h-4`,"aria-hidden":!0}),h(`slice.loadedSpools.pick`,`Pick`)]})]})]})}export{ae as n,ot as t}; \ No newline at end of file diff --git a/static/assets/SpoolBuddyAmsPage-CUILYofw.js b/static/assets/SpoolBuddyAmsPage-BzUFeU61.js similarity index 99% rename from static/assets/SpoolBuddyAmsPage-CUILYofw.js rename to static/assets/SpoolBuddyAmsPage-BzUFeU61.js index 9928da5ab..1e01fba73 100644 --- a/static/assets/SpoolBuddyAmsPage-CUILYofw.js +++ b/static/assets/SpoolBuddyAmsPage-BzUFeU61.js @@ -1 +1 @@ -import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,w as i}from"./client-DnySrlFv.js";import{n as a}from"./QueryClientProvider-Ce8_sN3w.js";import{t as o}from"./useQuery-BBCjCezC.js";import{t as s}from"./useMutation-B-Tr2hIP.js";import{n as c}from"./ToastContext-BRX0SW3C.js";import{t as l}from"./link-2-MI-QCMh8.js";import{t as u}from"./package-BGUevlqS.js";import{t as ee}from"./settings-2-Cvn837lh.js";import{t as d}from"./unlink-C098nwOf.js";import{t as te}from"./x-DR-Trv6U.js";import{G as f,H as ne,Hn as re,J as ie,K as ae,X as oe,cn as se,et as ce,ft as p,lt as le,q as ue,tt as m}from"./index-0t--Yqoi.js";import{i as de,n as fe,r as pe,t as me}from"./AmsUnitCard-Dim7pnZ8.js";import{n as he}from"./spoolPaint-CrvpHqdD.js";import{t as ge}from"./printerModel-DrNvERGQ.js";import{n as _e,r as ve,t as ye}from"./ConfigureAmsSlotModal-D0mYskEf.js";var h=e(n(),1),g=t();function _(e){let t=p(e.color_name,e.rgba,e.color_name_is_synthesized);return t?` - ${t}`:``}function be(e){return e<=3?`AMS ${String.fromCharCode(65+e)}`:e>=128&&e<=135?`AMS HT ${String.fromCharCode(65+e-128)}`:`AMS ${e}`}function v(e){return!e.tray_type||e.tray_type===``}function xe(e){return e?`#${e.slice(0,6)}`:`#808080`}function y(){let{selectedPrinterId:e,setAlert:t}=re(),{t:n}=i(),p=a(),{showToast:y}=c(),{data:b}=o({queryKey:[`printerStatus`,e],queryFn:()=>r.getPrinterStatus(e),enabled:e!==null,staleTime:30*1e3}),{data:x}=o({queryKey:[`printer`,e],queryFn:()=>r.getPrinter(e),enabled:e!==null,staleTime:60*1e3}),{data:S}=o({queryKey:[`slotPresets`,e],queryFn:()=>r.getSlotPresets(e),enabled:e!==null,staleTime:120*1e3}),{data:C}=o({queryKey:[`settings`],queryFn:()=>r.getSettings(),staleTime:300*1e3}),{data:Se}=o({queryKey:[`spoolman-status`],queryFn:r.getSpoolmanStatus,staleTime:60*1e3}),w=Se?.enabled&&Se?.connected,{data:Ce}=o({queryKey:[`linked-spools`],queryFn:r.getLinkedSpools,enabled:!!w,staleTime:30*1e3}),T=Ce?.linked,{data:E=[]}=o({queryKey:[`spoolman-slot-assignments-all`],queryFn:()=>r.getSpoolmanSlotAssignments(),enabled:!!w,staleTime:30*1e3}),{data:D=[]}=o({queryKey:[`spoolman-inventory-spools`],queryFn:()=>r.getSpoolmanInventorySpools(!1),enabled:!!w,staleTime:30*1e3}),{data:O}=o({queryKey:[`spool-assignments`,e],queryFn:()=>r.getAssignments(e),enabled:e!==null,staleTime:30*1e3}),k=(0,h.useMemo)(()=>{let e={};if(!O)return e;for(let t of O){let n=t.spool;if(n&&n.label_weight>0&&n.weight_used!=null){let r=Math.round(Math.max(0,n.label_weight-n.weight_used)/n.label_weight*100);e[`${t.ams_id}-${t.tray_id}`]=r}}return e},[O]),A=x?.serial_number??``,j=(0,h.useCallback)((t,n,r)=>{if(e!==null&&E.length&&D.length){let r=E.find(r=>r.printer_id===e&&r.ams_id===t&&r.tray_id===n);if(r){let e=D.find(e=>e.id===r.spoolman_spool_id);if(e&&(e.label_weight??0)>0)return Math.round(Math.max(0,e.label_weight-e.weight_used)/e.label_weight*100)}}if(T&&A){let e=(r?.tray_uuid||r?.tag_uid||f(A,t,n))?.toUpperCase(),i=ie(e?T[e]:void 0);if(i!==null)return i}return null},[T,A,e,E,D]),M=b?.connected??!1,N=(0,h.useRef)({});(0,h.useEffect)(()=>{e&&b?.ams&&b.ams.length>0&&(N.current[e]=b.ams)},[b?.ams,e]);let P=(0,h.useMemo)(()=>{let t=b?.ams;return t&&t.length>0?t:(e?N.current[e]:null)??[]},[b?.ams,e]),F=(0,h.useMemo)(()=>P.filter(e=>!e.is_ams_ht),[P]),we=(0,h.useMemo)(()=>P.filter(e=>e.is_ams_ht),[P]),Te=(0,h.useMemo)(()=>{let e={};if(!T||!A)return e;for(let t of F)for(let n=0;n<(t.tray?.length??0);n++){let r=t.tray[n],i=j(t.id,n,v(r)?null:r);i!==null&&(e[`${t.id}-${n}`]=i)}return e},[T,A,F,j]),I=(0,h.useRef)(void 0),L=b?.tray_now;L!==void 0&&L!==255?I.current=L:L===255&&(I.current=void 0);let R=L!==void 0&&L!==255?L:I.current,z=x?.nozzle_count===2||b?.temperatures?.nozzle_2!==void 0,B=(0,h.useMemo)(()=>[...b?.vt_tray??[]].sort((e,t)=>(e.id??254)-(t.id??254)),[b?.vt_tray]),V=C?{humidityGood:Number(C.ams_humidity_good)||40,humidityFair:Number(C.ams_humidity_fair)||60,tempGood:Number(C.ams_temp_good)||28,tempFair:Number(C.ams_temp_fair)||35}:void 0,H=(0,h.useRef)({});(0,h.useEffect)(()=>{b?.ams_extruder_map&&Object.keys(b.ams_extruder_map).length>0&&(H.current=b.ams_extruder_map)},[b?.ams_extruder_map]);let U=b?.ams_extruder_map&&Object.keys(b.ams_extruder_map).length>0?b.ams_extruder_map:H.current,W=(0,h.useCallback)(e=>{if(!z)return null;let t=U[String(e)],n=e>=128?e-128:e;return(t===void 0?n:t)===1?`L`:`R`},[z,U]),[G,Ee]=(0,h.useState)(null),[K,q]=(0,h.useState)(null),[J,De]=(0,h.useState)(null),[Y,X]=(0,h.useState)(null),Oe=(0,h.useCallback)((e,t)=>O?.find(n=>n.ams_id===Number(e)&&n.tray_id===Number(t)),[O]),ke=(0,h.useCallback)((e,t,n)=>{if(!T||!A)return;let r=(n?.tray_uuid||n?.tag_uid||f(A,e,t))?.toUpperCase();return r?T[r]:void 0},[T,A]),Z=s({mutationFn:({printerId:e,amsId:t,trayId:n})=>r.unassignSpool(e,t,n),onSuccess:()=>{p.invalidateQueries({queryKey:[`spool-assignments`,e]}),p.invalidateQueries({queryKey:[`spool-assignments`]}),y(n(`inventory.unassignSuccess`,`Spool unassigned`),`success`),q(null)}}),Ae=s({mutationFn:e=>r.unlinkSpool(e),onSuccess:e=>{y(n(`spoolman.unlinkSuccess`)||e?.message,`success`),p.invalidateQueries({queryKey:[`linked-spools`]}),p.invalidateQueries({queryKey:[`unlinked-spools`]}),p.invalidateQueries({queryKey:[`spoolman-slot-assignments`]}),p.invalidateQueries({queryKey:[`spoolman-slot-assignments-all`]}),p.invalidateQueries({queryKey:[`spoolman-inventory-spools`]}),q(null)},onError:e=>{y(e.message||n(`spoolman.unlinkFailed`),`error`)}}),je=s({mutationFn:e=>r.unassignSpoolmanSlot(e),onSuccess:()=>{y(n(`inventory.unassignSuccess`,`Spool unassigned`),`success`),p.invalidateQueries({queryKey:[`spoolman-slot-assignments`]}),p.invalidateQueries({queryKey:[`spoolman-slot-assignments-all`]}),p.invalidateQueries({queryKey:[`spoolman-inventory-spools`]}),p.invalidateQueries({queryKey:[`unlinked-spools`]}),p.invalidateQueries({queryKey:[`linked-spools`]}),q(null)},onError:e=>{y(e.message||n(`inventory.assignFailed`,`Failed to unassign spool`),`error`)}}),Q=(0,h.useCallback)(e=>R===void 0?null:e<=3&&Math.floor(R/4)===e?R%4:e>=128&&e<=135&&R===ue(e,0,!1)?0:null,[R]),$=(0,h.useCallback)((e,t,n)=>{let r=ue(e,t,!1),i=S?.[r],a=U[String(e)],o=e>=128?e-128:e,s=a===void 0?o:a;q({amsId:e,trayId:t,trayCount:n&&e>=128?1:4,tray:n,trayType:n?.tray_type||void 0,trayColor:n?.tray_color||void 0,traySubBrands:n?.tray_sub_brands||void 0,trayInfoIdx:n?.tray_info_idx||void 0,extruderId:z?s:void 0,caliIdx:n?.cali_idx,savedPresetId:m(i?.preset_id,n?.tray_info_idx,i?.tray_info_idx)?i?.preset_id:void 0,location:`${be(e)} Slot ${t+1}`})},[S,U,z]),Me=(0,h.useCallback)(e=>{let t=e.id??254,n=t-254,r=S?.[1020+n];q({amsId:255,trayId:n,trayCount:1,tray:v(e)?null:e,trayType:e.tray_type||void 0,trayColor:e.tray_color||void 0,traySubBrands:e.tray_sub_brands||void 0,trayInfoIdx:e.tray_info_idx||void 0,extruderId:z?+(t===254):void 0,caliIdx:e.cali_idx,savedPresetId:m(r?.preset_id,e.tray_info_idx,r?.tray_info_idx)?r?.preset_id:void 0,location:z?t===254?`Ext-L`:`Ext-R`:`External`})},[S,z]),Ne=(0,h.useCallback)(()=>{if(!K)return;let{tray:e,location:t,...n}=K;q(null),Ee(n)},[K]),Pe=(0,h.useCallback)(()=>{if(!K||!e)return;let{amsId:t,trayId:n,trayType:r,trayColor:i,location:a}=K;q(null),De({printerId:e,amsId:t,trayId:n,trayInfo:{type:r||``,material:r,color:i?.slice(0,6)||``,location:a}})},[K,e]),Fe=(0,h.useCallback)(()=>{if(!K||!e)return;let{amsId:t,trayId:n,tray:r}=K,i=(r?.tray_uuid||r?.tag_uid||f(A,t,n))?.toUpperCase()||``;q(null),X({tagUid:r?.tag_uid||i,trayUuid:r?.tray_uuid||``,printerId:e,amsId:t,trayId:n})},[K,e,A]),Ie=(0,h.useCallback)(()=>{if(!K||!e)return;let{amsId:t,trayId:n}=K;Z.mutate({printerId:e,amsId:t,trayId:n})},[K,e,Z]);(0,h.useEffect)(()=>{if(!M&&e){t({type:`warning`,message:n(`spoolbuddy.ams.printerDisconnected`,`Printer disconnected`)});return}for(let e of P){let n=e.tray||[];for(let r=0;r=0&&i.remain<15&&i.tray_type){let n=e.id===254||e.id===255,a=!n&&e.id>=128,o=ne(e.id,r,a,n);t({type:`warning`,message:`Low Filament: ${i.tray_type} (${o}) - ${i.remain}% remaining`});return}}}t(null)},[P,M,e,t,n]);let Le=(0,h.useMemo)(()=>{let e=[];for(let t of we){let n=t.tray?.[0]||{id:0,tray_color:null,tray_type:``,tray_sub_brands:null,tray_id_name:null,tray_info_idx:null,remain:-1,k:null,cali_idx:null,tag_uid:null,tray_uuid:null,nozzle_temp_min:null,nozzle_temp_max:null},r=j(t.id,0,v(n)?null:n),i=k[`${t.id}-0`]??null,a=n.remain!=null&&n.remain>=0?n.remain:null,o=i===0&&a!==null&&a>0?null:i;e.push({key:`ht-${t.id}`,label:be(t.id),tray:n,isEmpty:v(n),isActive:Q(t.id)===0,temp:t.temp,humidity:t.humidity,nozzleSide:W(t.id),effectiveFill:r??o??a,onClick:()=>$(t.id,0,v(n)?null:n)})}for(let t of B){let r=t.id??254,i=z&&R===254?r===254&&b?.active_extruder===1||r===255&&b?.active_extruder===0:R===r,a=r-254,o=j(255,a,v(t)?null:t),s=k[`255-${a}`]??null,c=t.remain!=null&&t.remain>=0?t.remain:null,l=s===0&&c!==null&&c>0?null:s;e.push({key:`ext-${r}`,label:z?r===254?n(`printers.extL`,`Ext-L`):n(`printers.extR`,`Ext-R`):n(`printers.ext`,`Ext`),tray:t,isEmpty:v(t),isActive:i,nozzleSide:null,effectiveFill:o??l??c,onClick:()=>Me(t)})}return e},[we,B,z,R,b?.active_extruder,n,Q,W,$,Me,k,j]);return(0,g.jsxs)(`div`,{className:`h-full flex flex-col p-4`,children:[(0,g.jsx)(`div`,{className:`flex-1 min-h-0`,children:e?M?P.length===0&&B.length===0?(0,g.jsx)(`div`,{className:`flex-1 flex items-center justify-center h-full`,children:(0,g.jsxs)(`div`,{className:`text-center text-white/50`,children:[(0,g.jsx)(se,{className:`w-12 h-12 mx-auto mb-3 opacity-50`}),(0,g.jsx)(`p`,{className:`text-lg mb-2`,children:n(`spoolbuddy.ams.noData`,`No AMS detected`)}),(0,g.jsx)(`p`,{className:`text-sm`,children:n(`spoolbuddy.ams.connectAms`,`Connect an AMS to see filament slots`)})]})}):(0,g.jsxs)(`div`,{className:`flex flex-col gap-3 h-full`,children:[(0,g.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3`,children:F.map(e=>(0,g.jsx)(me,{unit:e,activeSlot:Q(e.id),onConfigureSlot:$,isDualNozzle:z,nozzleSide:W(e.id),thresholds:V,fillOverrides:k,spoolmanFillOverrides:Te},e.id))}),Le.length>0&&(0,g.jsx)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-3`,children:Le.map(({key:e,label:t,tray:n,isEmpty:r,isActive:i,temp:a,humidity:o,nozzleSide:s,effectiveFill:c,onClick:l})=>{let u=xe(n.tray_color);return(0,g.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg px-3 py-2 cursor-pointer hover:bg-bambu-dark-secondary/80 transition-all flex items-center gap-3 ${i?`ring-2 ring-bambu-green`:``}`,onClick:l,children:[(0,g.jsxs)(`div`,{className:`relative w-10 h-10 flex-shrink-0`,children:[r?(0,g.jsx)(`div`,{className:`w-full h-full rounded-full border-2 border-dashed border-gray-500 flex items-center justify-center`,children:(0,g.jsx)(`div`,{className:`w-1.5 h-1.5 rounded-full bg-gray-600`})}):(0,g.jsxs)(`svg`,{viewBox:`0 0 56 56`,className:`w-full h-full`,children:[(0,g.jsx)(`circle`,{cx:`28`,cy:`28`,r:`26`,fill:u}),(0,g.jsx)(`circle`,{cx:`28`,cy:`28`,r:`20`,fill:u,style:{filter:`brightness(0.85)`}}),(0,g.jsx)(`ellipse`,{cx:`20`,cy:`20`,rx:`6`,ry:`4`,fill:`white`,opacity:`0.3`}),(0,g.jsx)(`circle`,{cx:`28`,cy:`28`,r:`8`,fill:`#2d2d2d`}),(0,g.jsx)(`circle`,{cx:`28`,cy:`28`,r:`5`,fill:`#1a1a1a`})]}),i&&(0,g.jsx)(`div`,{className:`absolute -bottom-0.5 left-1/2 -translate-x-1/2 w-1.5 h-1.5 bg-bambu-green rounded-full`})]}),(0,g.jsxs)(`div`,{className:`min-w-0`,children:[(0,g.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,g.jsx)(`span`,{className:`text-xs text-white/50 font-medium truncate`,children:t}),s&&(0,g.jsx)(pe,{side:s})]}),(0,g.jsx)(`div`,{className:`text-sm text-white/80 truncate`,children:r?`Empty`:n.tray_type||`?`}),(a!=null||o!=null)&&(0,g.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[a!=null&&(0,g.jsx)(de,{temp:a,goodThreshold:V?.tempGood,fairThreshold:V?.tempFair}),o!=null&&(0,g.jsx)(fe,{humidity:o,goodThreshold:V?.humidityGood,fairThreshold:V?.humidityFair})]})]}),!r&&c!=null&&c>=0&&(0,g.jsx)(`div`,{className:`w-1.5 h-8 bg-bambu-dark-tertiary rounded-full overflow-hidden flex-shrink-0 flex flex-col-reverse`,children:(0,g.jsx)(`div`,{className:`w-full rounded-full`,style:{height:`${c}%`,backgroundColor:ae(c)}})})]},e)})})]}):(0,g.jsx)(`div`,{className:`flex-1 flex items-center justify-center h-full`,children:(0,g.jsx)(`div`,{className:`text-center text-white/50`,children:(0,g.jsx)(`p`,{className:`text-lg mb-2`,children:n(`spoolbuddy.ams.printerDisconnected`,`Printer disconnected`)})})}):(0,g.jsx)(`div`,{className:`flex-1 flex items-center justify-center h-full`,children:(0,g.jsxs)(`div`,{className:`text-center text-white/50`,children:[(0,g.jsx)(`p`,{className:`text-lg mb-2`,children:n(`spoolbuddy.ams.noPrinter`,`No printer selected`)}),(0,g.jsx)(`p`,{className:`text-sm`,children:n(`spoolbuddy.ams.selectPrinter`,`Select a printer from the top bar`)})]})})}),G&&e&&(0,g.jsx)(ye,{isOpen:!!G,onClose:()=>Ee(null),printerId:e,slotInfo:G,printerModel:ge(x?.model??null)||void 0,nozzleDiameter:ce(b,G.amsId),fullScreen:!0,onSuccess:()=>{p.invalidateQueries({queryKey:[`slotPresets`,e]}),p.invalidateQueries({queryKey:[`printerStatus`,e]})}}),K&&e&&(()=>{let t=Oe(K.amsId,K.trayId),r=ke(K.amsId,K.trayId,K.tray),i=w?E.find(t=>t.printer_id===e&&t.ams_id===K.amsId&&t.tray_id===K.trayId):void 0,a=i?D.find(e=>e.id===i.spoolman_spool_id)??null:null;return(0,g.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[(0,g.jsx)(`div`,{className:`absolute inset-0 bg-black/60 backdrop-blur-sm`,onClick:()=>q(null)}),(0,g.jsxs)(`div`,{className:`relative w-full max-w-sm mx-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl`,children:[(0,g.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,g.jsxs)(`div`,{className:`flex items-center gap-2`,children:[K.trayColor&&(0,g.jsx)(`span`,{className:`w-4 h-4 rounded-full border border-black/20`,style:{backgroundColor:`#${K.trayColor.slice(0,6)}`}}),(0,g.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:K.location}),K.traySubBrands&&(0,g.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[`(`,K.traySubBrands,`)`]})]}),(0,g.jsx)(`button`,{onClick:()=>q(null),className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,g.jsx)(te,{className:`w-5 h-5`})})]}),(0,g.jsxs)(`div`,{className:`p-4 space-y-2`,children:[!w&&t?.spool&&(0,g.jsxs)(`div`,{className:`p-2.5 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary mb-3`,children:[(0,g.jsx)(`p`,{className:`text-xs text-bambu-gray mb-1`,children:n(`inventory.assignedSpool`,`Assigned spool`)}),(0,g.jsxs)(`div`,{className:`flex items-center gap-2`,children:[t.spool.rgba&&(0,g.jsx)(`span`,{className:`w-3 h-3 rounded-full border border-black/20 flex-shrink-0`,style:he(t.spool)??le(t.spool.rgba)}),(0,g.jsxs)(`span`,{className:`text-sm text-white`,children:[t.spool.brand?`${t.spool.brand} `:``,t.spool.material,t.spool.subtype?` ${t.spool.subtype}`:``,_(t.spool)]}),(0,g.jsxs)(`span`,{className:`text-[10px] font-mono text-zinc-500 shrink-0 ml-auto`,children:[`#`,t.spool.id]})]})]}),w&&r&&!a&&(0,g.jsxs)(`div`,{className:`p-2.5 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary mb-3`,children:[(0,g.jsx)(`p`,{className:`text-xs text-bambu-gray mb-1`,children:n(`spoolman.linkedSpool`,`Linked spool`)}),(0,g.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,g.jsxs)(`span`,{className:`text-sm text-white`,children:[`Spoolman #`,r.id,r.remaining_weight==null?``:` (${Math.round(r.remaining_weight)}g)`]})})]}),w&&a&&(0,g.jsxs)(`div`,{className:`p-2.5 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary mb-3`,children:[(0,g.jsx)(`p`,{className:`text-xs text-bambu-gray mb-1`,children:n(`inventory.assignedSpool`,`Assigned spool`)}),(0,g.jsxs)(`div`,{className:`flex items-center gap-2`,children:[a.rgba&&(0,g.jsx)(`span`,{className:`w-3 h-3 rounded-full border border-black/20 flex-shrink-0`,style:he(a)??le(a.rgba)}),(0,g.jsxs)(`span`,{className:`text-sm text-white`,children:[a.brand?`${a.brand} `:``,a.material,a.subtype?` ${a.subtype}`:``,_(a)]})]})]}),(0,g.jsxs)(`button`,{onClick:Ne,className:`w-full flex items-center gap-3 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary hover:border-bambu-blue transition-colors text-left`,children:[(0,g.jsx)(ee,{className:`w-5 h-5 text-bambu-blue flex-shrink-0`}),(0,g.jsxs)(`div`,{children:[(0,g.jsx)(`p`,{className:`text-white font-medium`,children:n(`configureAmsSlot.title`)}),(0,g.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`spoolbuddy.ams.configureDesc`,`Set filament preset, K-profile, and color`)})]})]}),!w&&(oe(K?.tray)?null:t?(0,g.jsxs)(`button`,{onClick:Ie,disabled:Z.isPending,className:`w-full flex items-center gap-3 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary hover:border-amber-500 transition-colors text-left`,children:[(0,g.jsx)(d,{className:`w-5 h-5 text-amber-400 flex-shrink-0`}),(0,g.jsxs)(`div`,{children:[(0,g.jsx)(`p`,{className:`text-amber-400 font-medium`,children:n(`inventory.unassignSpool`,`Unassign`)}),(0,g.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`spoolbuddy.ams.unassignDesc`,`Remove inventory spool from this slot`)})]})]}):(0,g.jsxs)(`button`,{onClick:Pe,className:`w-full flex items-center gap-3 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary hover:border-bambu-green transition-colors text-left`,children:[(0,g.jsx)(u,{className:`w-5 h-5 text-bambu-green flex-shrink-0`}),(0,g.jsxs)(`div`,{children:[(0,g.jsx)(`p`,{className:`text-white font-medium`,children:n(`inventory.assignSpool`)}),(0,g.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`spoolbuddy.ams.assignDesc`,`Track a spool from your inventory`)})]})]})),w&&(r?.id?(0,g.jsxs)(`button`,{onClick:()=>Ae.mutate(r.id),disabled:Ae.isPending,className:`w-full flex items-center gap-3 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary hover:border-amber-500 transition-colors text-left active:opacity-50`,children:[(0,g.jsx)(d,{className:`w-5 h-5 text-amber-400 flex-shrink-0`}),(0,g.jsxs)(`div`,{children:[(0,g.jsx)(`p`,{className:`text-amber-400 font-medium`,children:n(`inventory.unassignSpool`)}),(0,g.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`spoolbuddy.ams.unlinkDesc`,`Remove Spoolman link from this slot`)})]})]}):a?(0,g.jsxs)(`button`,{onClick:()=>je.mutate(a.id),disabled:je.isPending,className:`w-full flex items-center gap-3 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary hover:border-amber-500 transition-colors text-left active:opacity-50`,children:[(0,g.jsx)(d,{className:`w-5 h-5 text-amber-400 flex-shrink-0`}),(0,g.jsxs)(`div`,{children:[(0,g.jsx)(`p`,{className:`text-amber-400 font-medium`,children:n(`inventory.unassignSpool`)}),(0,g.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`spoolbuddy.ams.unassignDesc`,`Remove inventory spool from this slot`)})]})]}):(0,g.jsxs)(`button`,{onClick:Fe,className:`w-full flex items-center gap-3 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary hover:border-bambu-green transition-colors text-left`,children:[(0,g.jsx)(l,{className:`w-5 h-5 text-bambu-green flex-shrink-0`}),(0,g.jsxs)(`div`,{children:[(0,g.jsx)(`p`,{className:`text-white font-medium`,children:n(`inventory.assignSpool`)}),(0,g.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`spoolbuddy.ams.linkDesc`,`Link a Spoolman spool to this slot`)})]})]}))]})]})]})})(),J&&(0,g.jsx)(_e,{isOpen:!!J,onClose:()=>{De(null),p.invalidateQueries({queryKey:[`spool-assignments`,e]}),p.invalidateQueries({queryKey:[`spool-assignments`]})},printerId:J.printerId,amsId:J.amsId,trayId:J.trayId,trayInfo:J.trayInfo,spoolmanEnabled:!!w}),Y&&(0,g.jsx)(ve,{isOpen:!!Y,onClose:()=>X(null),tagUid:Y.tagUid,trayUuid:Y.trayUuid,printerId:Y.printerId,amsId:Y.amsId,trayId:Y.trayId})]})}export{y as SpoolBuddyAmsPage}; \ No newline at end of file +import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,w as i}from"./client-DnySrlFv.js";import{n as a}from"./QueryClientProvider-Ce8_sN3w.js";import{t as o}from"./useQuery-BBCjCezC.js";import{t as s}from"./useMutation-B-Tr2hIP.js";import{n as c}from"./ToastContext-BRX0SW3C.js";import{t as l}from"./link-2-MI-QCMh8.js";import{t as u}from"./package-BGUevlqS.js";import{t as ee}from"./settings-2-Cvn837lh.js";import{t as d}from"./unlink-C098nwOf.js";import{t as te}from"./x-DR-Trv6U.js";import{G as f,H as ne,Hn as re,J as ie,K as ae,X as oe,cn as se,et as ce,ft as p,lt as le,q as ue,tt as m}from"./index-Cxa-KVmA.js";import{i as de,n as fe,r as pe,t as me}from"./AmsUnitCard-CeSWF1rR.js";import{n as he}from"./spoolPaint-CrvpHqdD.js";import{t as ge}from"./printerModel-DrNvERGQ.js";import{n as _e,r as ve,t as ye}from"./ConfigureAmsSlotModal-BgpDvjjX.js";var h=e(n(),1),g=t();function _(e){let t=p(e.color_name,e.rgba,e.color_name_is_synthesized);return t?` - ${t}`:``}function be(e){return e<=3?`AMS ${String.fromCharCode(65+e)}`:e>=128&&e<=135?`AMS HT ${String.fromCharCode(65+e-128)}`:`AMS ${e}`}function v(e){return!e.tray_type||e.tray_type===``}function xe(e){return e?`#${e.slice(0,6)}`:`#808080`}function y(){let{selectedPrinterId:e,setAlert:t}=re(),{t:n}=i(),p=a(),{showToast:y}=c(),{data:b}=o({queryKey:[`printerStatus`,e],queryFn:()=>r.getPrinterStatus(e),enabled:e!==null,staleTime:30*1e3}),{data:x}=o({queryKey:[`printer`,e],queryFn:()=>r.getPrinter(e),enabled:e!==null,staleTime:60*1e3}),{data:S}=o({queryKey:[`slotPresets`,e],queryFn:()=>r.getSlotPresets(e),enabled:e!==null,staleTime:120*1e3}),{data:C}=o({queryKey:[`settings`],queryFn:()=>r.getSettings(),staleTime:300*1e3}),{data:Se}=o({queryKey:[`spoolman-status`],queryFn:r.getSpoolmanStatus,staleTime:60*1e3}),w=Se?.enabled&&Se?.connected,{data:Ce}=o({queryKey:[`linked-spools`],queryFn:r.getLinkedSpools,enabled:!!w,staleTime:30*1e3}),T=Ce?.linked,{data:E=[]}=o({queryKey:[`spoolman-slot-assignments-all`],queryFn:()=>r.getSpoolmanSlotAssignments(),enabled:!!w,staleTime:30*1e3}),{data:D=[]}=o({queryKey:[`spoolman-inventory-spools`],queryFn:()=>r.getSpoolmanInventorySpools(!1),enabled:!!w,staleTime:30*1e3}),{data:O}=o({queryKey:[`spool-assignments`,e],queryFn:()=>r.getAssignments(e),enabled:e!==null,staleTime:30*1e3}),k=(0,h.useMemo)(()=>{let e={};if(!O)return e;for(let t of O){let n=t.spool;if(n&&n.label_weight>0&&n.weight_used!=null){let r=Math.round(Math.max(0,n.label_weight-n.weight_used)/n.label_weight*100);e[`${t.ams_id}-${t.tray_id}`]=r}}return e},[O]),A=x?.serial_number??``,j=(0,h.useCallback)((t,n,r)=>{if(e!==null&&E.length&&D.length){let r=E.find(r=>r.printer_id===e&&r.ams_id===t&&r.tray_id===n);if(r){let e=D.find(e=>e.id===r.spoolman_spool_id);if(e&&(e.label_weight??0)>0)return Math.round(Math.max(0,e.label_weight-e.weight_used)/e.label_weight*100)}}if(T&&A){let e=(r?.tray_uuid||r?.tag_uid||f(A,t,n))?.toUpperCase(),i=ie(e?T[e]:void 0);if(i!==null)return i}return null},[T,A,e,E,D]),M=b?.connected??!1,N=(0,h.useRef)({});(0,h.useEffect)(()=>{e&&b?.ams&&b.ams.length>0&&(N.current[e]=b.ams)},[b?.ams,e]);let P=(0,h.useMemo)(()=>{let t=b?.ams;return t&&t.length>0?t:(e?N.current[e]:null)??[]},[b?.ams,e]),F=(0,h.useMemo)(()=>P.filter(e=>!e.is_ams_ht),[P]),we=(0,h.useMemo)(()=>P.filter(e=>e.is_ams_ht),[P]),Te=(0,h.useMemo)(()=>{let e={};if(!T||!A)return e;for(let t of F)for(let n=0;n<(t.tray?.length??0);n++){let r=t.tray[n],i=j(t.id,n,v(r)?null:r);i!==null&&(e[`${t.id}-${n}`]=i)}return e},[T,A,F,j]),I=(0,h.useRef)(void 0),L=b?.tray_now;L!==void 0&&L!==255?I.current=L:L===255&&(I.current=void 0);let R=L!==void 0&&L!==255?L:I.current,z=x?.nozzle_count===2||b?.temperatures?.nozzle_2!==void 0,B=(0,h.useMemo)(()=>[...b?.vt_tray??[]].sort((e,t)=>(e.id??254)-(t.id??254)),[b?.vt_tray]),V=C?{humidityGood:Number(C.ams_humidity_good)||40,humidityFair:Number(C.ams_humidity_fair)||60,tempGood:Number(C.ams_temp_good)||28,tempFair:Number(C.ams_temp_fair)||35}:void 0,H=(0,h.useRef)({});(0,h.useEffect)(()=>{b?.ams_extruder_map&&Object.keys(b.ams_extruder_map).length>0&&(H.current=b.ams_extruder_map)},[b?.ams_extruder_map]);let U=b?.ams_extruder_map&&Object.keys(b.ams_extruder_map).length>0?b.ams_extruder_map:H.current,W=(0,h.useCallback)(e=>{if(!z)return null;let t=U[String(e)],n=e>=128?e-128:e;return(t===void 0?n:t)===1?`L`:`R`},[z,U]),[G,Ee]=(0,h.useState)(null),[K,q]=(0,h.useState)(null),[J,De]=(0,h.useState)(null),[Y,X]=(0,h.useState)(null),Oe=(0,h.useCallback)((e,t)=>O?.find(n=>n.ams_id===Number(e)&&n.tray_id===Number(t)),[O]),ke=(0,h.useCallback)((e,t,n)=>{if(!T||!A)return;let r=(n?.tray_uuid||n?.tag_uid||f(A,e,t))?.toUpperCase();return r?T[r]:void 0},[T,A]),Z=s({mutationFn:({printerId:e,amsId:t,trayId:n})=>r.unassignSpool(e,t,n),onSuccess:()=>{p.invalidateQueries({queryKey:[`spool-assignments`,e]}),p.invalidateQueries({queryKey:[`spool-assignments`]}),y(n(`inventory.unassignSuccess`,`Spool unassigned`),`success`),q(null)}}),Ae=s({mutationFn:e=>r.unlinkSpool(e),onSuccess:e=>{y(n(`spoolman.unlinkSuccess`)||e?.message,`success`),p.invalidateQueries({queryKey:[`linked-spools`]}),p.invalidateQueries({queryKey:[`unlinked-spools`]}),p.invalidateQueries({queryKey:[`spoolman-slot-assignments`]}),p.invalidateQueries({queryKey:[`spoolman-slot-assignments-all`]}),p.invalidateQueries({queryKey:[`spoolman-inventory-spools`]}),q(null)},onError:e=>{y(e.message||n(`spoolman.unlinkFailed`),`error`)}}),je=s({mutationFn:e=>r.unassignSpoolmanSlot(e),onSuccess:()=>{y(n(`inventory.unassignSuccess`,`Spool unassigned`),`success`),p.invalidateQueries({queryKey:[`spoolman-slot-assignments`]}),p.invalidateQueries({queryKey:[`spoolman-slot-assignments-all`]}),p.invalidateQueries({queryKey:[`spoolman-inventory-spools`]}),p.invalidateQueries({queryKey:[`unlinked-spools`]}),p.invalidateQueries({queryKey:[`linked-spools`]}),q(null)},onError:e=>{y(e.message||n(`inventory.assignFailed`,`Failed to unassign spool`),`error`)}}),Q=(0,h.useCallback)(e=>R===void 0?null:e<=3&&Math.floor(R/4)===e?R%4:e>=128&&e<=135&&R===ue(e,0,!1)?0:null,[R]),$=(0,h.useCallback)((e,t,n)=>{let r=ue(e,t,!1),i=S?.[r],a=U[String(e)],o=e>=128?e-128:e,s=a===void 0?o:a;q({amsId:e,trayId:t,trayCount:n&&e>=128?1:4,tray:n,trayType:n?.tray_type||void 0,trayColor:n?.tray_color||void 0,traySubBrands:n?.tray_sub_brands||void 0,trayInfoIdx:n?.tray_info_idx||void 0,extruderId:z?s:void 0,caliIdx:n?.cali_idx,savedPresetId:m(i?.preset_id,n?.tray_info_idx,i?.tray_info_idx)?i?.preset_id:void 0,location:`${be(e)} Slot ${t+1}`})},[S,U,z]),Me=(0,h.useCallback)(e=>{let t=e.id??254,n=t-254,r=S?.[1020+n];q({amsId:255,trayId:n,trayCount:1,tray:v(e)?null:e,trayType:e.tray_type||void 0,trayColor:e.tray_color||void 0,traySubBrands:e.tray_sub_brands||void 0,trayInfoIdx:e.tray_info_idx||void 0,extruderId:z?+(t===254):void 0,caliIdx:e.cali_idx,savedPresetId:m(r?.preset_id,e.tray_info_idx,r?.tray_info_idx)?r?.preset_id:void 0,location:z?t===254?`Ext-L`:`Ext-R`:`External`})},[S,z]),Ne=(0,h.useCallback)(()=>{if(!K)return;let{tray:e,location:t,...n}=K;q(null),Ee(n)},[K]),Pe=(0,h.useCallback)(()=>{if(!K||!e)return;let{amsId:t,trayId:n,trayType:r,trayColor:i,location:a}=K;q(null),De({printerId:e,amsId:t,trayId:n,trayInfo:{type:r||``,material:r,color:i?.slice(0,6)||``,location:a}})},[K,e]),Fe=(0,h.useCallback)(()=>{if(!K||!e)return;let{amsId:t,trayId:n,tray:r}=K,i=(r?.tray_uuid||r?.tag_uid||f(A,t,n))?.toUpperCase()||``;q(null),X({tagUid:r?.tag_uid||i,trayUuid:r?.tray_uuid||``,printerId:e,amsId:t,trayId:n})},[K,e,A]),Ie=(0,h.useCallback)(()=>{if(!K||!e)return;let{amsId:t,trayId:n}=K;Z.mutate({printerId:e,amsId:t,trayId:n})},[K,e,Z]);(0,h.useEffect)(()=>{if(!M&&e){t({type:`warning`,message:n(`spoolbuddy.ams.printerDisconnected`,`Printer disconnected`)});return}for(let e of P){let n=e.tray||[];for(let r=0;r=0&&i.remain<15&&i.tray_type){let n=e.id===254||e.id===255,a=!n&&e.id>=128,o=ne(e.id,r,a,n);t({type:`warning`,message:`Low Filament: ${i.tray_type} (${o}) - ${i.remain}% remaining`});return}}}t(null)},[P,M,e,t,n]);let Le=(0,h.useMemo)(()=>{let e=[];for(let t of we){let n=t.tray?.[0]||{id:0,tray_color:null,tray_type:``,tray_sub_brands:null,tray_id_name:null,tray_info_idx:null,remain:-1,k:null,cali_idx:null,tag_uid:null,tray_uuid:null,nozzle_temp_min:null,nozzle_temp_max:null},r=j(t.id,0,v(n)?null:n),i=k[`${t.id}-0`]??null,a=n.remain!=null&&n.remain>=0?n.remain:null,o=i===0&&a!==null&&a>0?null:i;e.push({key:`ht-${t.id}`,label:be(t.id),tray:n,isEmpty:v(n),isActive:Q(t.id)===0,temp:t.temp,humidity:t.humidity,nozzleSide:W(t.id),effectiveFill:r??o??a,onClick:()=>$(t.id,0,v(n)?null:n)})}for(let t of B){let r=t.id??254,i=z&&R===254?r===254&&b?.active_extruder===1||r===255&&b?.active_extruder===0:R===r,a=r-254,o=j(255,a,v(t)?null:t),s=k[`255-${a}`]??null,c=t.remain!=null&&t.remain>=0?t.remain:null,l=s===0&&c!==null&&c>0?null:s;e.push({key:`ext-${r}`,label:z?r===254?n(`printers.extL`,`Ext-L`):n(`printers.extR`,`Ext-R`):n(`printers.ext`,`Ext`),tray:t,isEmpty:v(t),isActive:i,nozzleSide:null,effectiveFill:o??l??c,onClick:()=>Me(t)})}return e},[we,B,z,R,b?.active_extruder,n,Q,W,$,Me,k,j]);return(0,g.jsxs)(`div`,{className:`h-full flex flex-col p-4`,children:[(0,g.jsx)(`div`,{className:`flex-1 min-h-0`,children:e?M?P.length===0&&B.length===0?(0,g.jsx)(`div`,{className:`flex-1 flex items-center justify-center h-full`,children:(0,g.jsxs)(`div`,{className:`text-center text-white/50`,children:[(0,g.jsx)(se,{className:`w-12 h-12 mx-auto mb-3 opacity-50`}),(0,g.jsx)(`p`,{className:`text-lg mb-2`,children:n(`spoolbuddy.ams.noData`,`No AMS detected`)}),(0,g.jsx)(`p`,{className:`text-sm`,children:n(`spoolbuddy.ams.connectAms`,`Connect an AMS to see filament slots`)})]})}):(0,g.jsxs)(`div`,{className:`flex flex-col gap-3 h-full`,children:[(0,g.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3`,children:F.map(e=>(0,g.jsx)(me,{unit:e,activeSlot:Q(e.id),onConfigureSlot:$,isDualNozzle:z,nozzleSide:W(e.id),thresholds:V,fillOverrides:k,spoolmanFillOverrides:Te},e.id))}),Le.length>0&&(0,g.jsx)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-3`,children:Le.map(({key:e,label:t,tray:n,isEmpty:r,isActive:i,temp:a,humidity:o,nozzleSide:s,effectiveFill:c,onClick:l})=>{let u=xe(n.tray_color);return(0,g.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg px-3 py-2 cursor-pointer hover:bg-bambu-dark-secondary/80 transition-all flex items-center gap-3 ${i?`ring-2 ring-bambu-green`:``}`,onClick:l,children:[(0,g.jsxs)(`div`,{className:`relative w-10 h-10 flex-shrink-0`,children:[r?(0,g.jsx)(`div`,{className:`w-full h-full rounded-full border-2 border-dashed border-gray-500 flex items-center justify-center`,children:(0,g.jsx)(`div`,{className:`w-1.5 h-1.5 rounded-full bg-gray-600`})}):(0,g.jsxs)(`svg`,{viewBox:`0 0 56 56`,className:`w-full h-full`,children:[(0,g.jsx)(`circle`,{cx:`28`,cy:`28`,r:`26`,fill:u}),(0,g.jsx)(`circle`,{cx:`28`,cy:`28`,r:`20`,fill:u,style:{filter:`brightness(0.85)`}}),(0,g.jsx)(`ellipse`,{cx:`20`,cy:`20`,rx:`6`,ry:`4`,fill:`white`,opacity:`0.3`}),(0,g.jsx)(`circle`,{cx:`28`,cy:`28`,r:`8`,fill:`#2d2d2d`}),(0,g.jsx)(`circle`,{cx:`28`,cy:`28`,r:`5`,fill:`#1a1a1a`})]}),i&&(0,g.jsx)(`div`,{className:`absolute -bottom-0.5 left-1/2 -translate-x-1/2 w-1.5 h-1.5 bg-bambu-green rounded-full`})]}),(0,g.jsxs)(`div`,{className:`min-w-0`,children:[(0,g.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,g.jsx)(`span`,{className:`text-xs text-white/50 font-medium truncate`,children:t}),s&&(0,g.jsx)(pe,{side:s})]}),(0,g.jsx)(`div`,{className:`text-sm text-white/80 truncate`,children:r?`Empty`:n.tray_type||`?`}),(a!=null||o!=null)&&(0,g.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[a!=null&&(0,g.jsx)(de,{temp:a,goodThreshold:V?.tempGood,fairThreshold:V?.tempFair}),o!=null&&(0,g.jsx)(fe,{humidity:o,goodThreshold:V?.humidityGood,fairThreshold:V?.humidityFair})]})]}),!r&&c!=null&&c>=0&&(0,g.jsx)(`div`,{className:`w-1.5 h-8 bg-bambu-dark-tertiary rounded-full overflow-hidden flex-shrink-0 flex flex-col-reverse`,children:(0,g.jsx)(`div`,{className:`w-full rounded-full`,style:{height:`${c}%`,backgroundColor:ae(c)}})})]},e)})})]}):(0,g.jsx)(`div`,{className:`flex-1 flex items-center justify-center h-full`,children:(0,g.jsx)(`div`,{className:`text-center text-white/50`,children:(0,g.jsx)(`p`,{className:`text-lg mb-2`,children:n(`spoolbuddy.ams.printerDisconnected`,`Printer disconnected`)})})}):(0,g.jsx)(`div`,{className:`flex-1 flex items-center justify-center h-full`,children:(0,g.jsxs)(`div`,{className:`text-center text-white/50`,children:[(0,g.jsx)(`p`,{className:`text-lg mb-2`,children:n(`spoolbuddy.ams.noPrinter`,`No printer selected`)}),(0,g.jsx)(`p`,{className:`text-sm`,children:n(`spoolbuddy.ams.selectPrinter`,`Select a printer from the top bar`)})]})})}),G&&e&&(0,g.jsx)(ye,{isOpen:!!G,onClose:()=>Ee(null),printerId:e,slotInfo:G,printerModel:ge(x?.model??null)||void 0,nozzleDiameter:ce(b,G.amsId),fullScreen:!0,onSuccess:()=>{p.invalidateQueries({queryKey:[`slotPresets`,e]}),p.invalidateQueries({queryKey:[`printerStatus`,e]})}}),K&&e&&(()=>{let t=Oe(K.amsId,K.trayId),r=ke(K.amsId,K.trayId,K.tray),i=w?E.find(t=>t.printer_id===e&&t.ams_id===K.amsId&&t.tray_id===K.trayId):void 0,a=i?D.find(e=>e.id===i.spoolman_spool_id)??null:null;return(0,g.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[(0,g.jsx)(`div`,{className:`absolute inset-0 bg-black/60 backdrop-blur-sm`,onClick:()=>q(null)}),(0,g.jsxs)(`div`,{className:`relative w-full max-w-sm mx-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl`,children:[(0,g.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,g.jsxs)(`div`,{className:`flex items-center gap-2`,children:[K.trayColor&&(0,g.jsx)(`span`,{className:`w-4 h-4 rounded-full border border-black/20`,style:{backgroundColor:`#${K.trayColor.slice(0,6)}`}}),(0,g.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:K.location}),K.traySubBrands&&(0,g.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[`(`,K.traySubBrands,`)`]})]}),(0,g.jsx)(`button`,{onClick:()=>q(null),className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,g.jsx)(te,{className:`w-5 h-5`})})]}),(0,g.jsxs)(`div`,{className:`p-4 space-y-2`,children:[!w&&t?.spool&&(0,g.jsxs)(`div`,{className:`p-2.5 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary mb-3`,children:[(0,g.jsx)(`p`,{className:`text-xs text-bambu-gray mb-1`,children:n(`inventory.assignedSpool`,`Assigned spool`)}),(0,g.jsxs)(`div`,{className:`flex items-center gap-2`,children:[t.spool.rgba&&(0,g.jsx)(`span`,{className:`w-3 h-3 rounded-full border border-black/20 flex-shrink-0`,style:he(t.spool)??le(t.spool.rgba)}),(0,g.jsxs)(`span`,{className:`text-sm text-white`,children:[t.spool.brand?`${t.spool.brand} `:``,t.spool.material,t.spool.subtype?` ${t.spool.subtype}`:``,_(t.spool)]}),(0,g.jsxs)(`span`,{className:`text-[10px] font-mono text-zinc-500 shrink-0 ml-auto`,children:[`#`,t.spool.id]})]})]}),w&&r&&!a&&(0,g.jsxs)(`div`,{className:`p-2.5 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary mb-3`,children:[(0,g.jsx)(`p`,{className:`text-xs text-bambu-gray mb-1`,children:n(`spoolman.linkedSpool`,`Linked spool`)}),(0,g.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,g.jsxs)(`span`,{className:`text-sm text-white`,children:[`Spoolman #`,r.id,r.remaining_weight==null?``:` (${Math.round(r.remaining_weight)}g)`]})})]}),w&&a&&(0,g.jsxs)(`div`,{className:`p-2.5 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary mb-3`,children:[(0,g.jsx)(`p`,{className:`text-xs text-bambu-gray mb-1`,children:n(`inventory.assignedSpool`,`Assigned spool`)}),(0,g.jsxs)(`div`,{className:`flex items-center gap-2`,children:[a.rgba&&(0,g.jsx)(`span`,{className:`w-3 h-3 rounded-full border border-black/20 flex-shrink-0`,style:he(a)??le(a.rgba)}),(0,g.jsxs)(`span`,{className:`text-sm text-white`,children:[a.brand?`${a.brand} `:``,a.material,a.subtype?` ${a.subtype}`:``,_(a)]})]})]}),(0,g.jsxs)(`button`,{onClick:Ne,className:`w-full flex items-center gap-3 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary hover:border-bambu-blue transition-colors text-left`,children:[(0,g.jsx)(ee,{className:`w-5 h-5 text-bambu-blue flex-shrink-0`}),(0,g.jsxs)(`div`,{children:[(0,g.jsx)(`p`,{className:`text-white font-medium`,children:n(`configureAmsSlot.title`)}),(0,g.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`spoolbuddy.ams.configureDesc`,`Set filament preset, K-profile, and color`)})]})]}),!w&&(oe(K?.tray)?null:t?(0,g.jsxs)(`button`,{onClick:Ie,disabled:Z.isPending,className:`w-full flex items-center gap-3 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary hover:border-amber-500 transition-colors text-left`,children:[(0,g.jsx)(d,{className:`w-5 h-5 text-amber-400 flex-shrink-0`}),(0,g.jsxs)(`div`,{children:[(0,g.jsx)(`p`,{className:`text-amber-400 font-medium`,children:n(`inventory.unassignSpool`,`Unassign`)}),(0,g.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`spoolbuddy.ams.unassignDesc`,`Remove inventory spool from this slot`)})]})]}):(0,g.jsxs)(`button`,{onClick:Pe,className:`w-full flex items-center gap-3 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary hover:border-bambu-green transition-colors text-left`,children:[(0,g.jsx)(u,{className:`w-5 h-5 text-bambu-green flex-shrink-0`}),(0,g.jsxs)(`div`,{children:[(0,g.jsx)(`p`,{className:`text-white font-medium`,children:n(`inventory.assignSpool`)}),(0,g.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`spoolbuddy.ams.assignDesc`,`Track a spool from your inventory`)})]})]})),w&&(r?.id?(0,g.jsxs)(`button`,{onClick:()=>Ae.mutate(r.id),disabled:Ae.isPending,className:`w-full flex items-center gap-3 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary hover:border-amber-500 transition-colors text-left active:opacity-50`,children:[(0,g.jsx)(d,{className:`w-5 h-5 text-amber-400 flex-shrink-0`}),(0,g.jsxs)(`div`,{children:[(0,g.jsx)(`p`,{className:`text-amber-400 font-medium`,children:n(`inventory.unassignSpool`)}),(0,g.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`spoolbuddy.ams.unlinkDesc`,`Remove Spoolman link from this slot`)})]})]}):a?(0,g.jsxs)(`button`,{onClick:()=>je.mutate(a.id),disabled:je.isPending,className:`w-full flex items-center gap-3 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary hover:border-amber-500 transition-colors text-left active:opacity-50`,children:[(0,g.jsx)(d,{className:`w-5 h-5 text-amber-400 flex-shrink-0`}),(0,g.jsxs)(`div`,{children:[(0,g.jsx)(`p`,{className:`text-amber-400 font-medium`,children:n(`inventory.unassignSpool`)}),(0,g.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`spoolbuddy.ams.unassignDesc`,`Remove inventory spool from this slot`)})]})]}):(0,g.jsxs)(`button`,{onClick:Fe,className:`w-full flex items-center gap-3 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary hover:border-bambu-green transition-colors text-left`,children:[(0,g.jsx)(l,{className:`w-5 h-5 text-bambu-green flex-shrink-0`}),(0,g.jsxs)(`div`,{children:[(0,g.jsx)(`p`,{className:`text-white font-medium`,children:n(`inventory.assignSpool`)}),(0,g.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`spoolbuddy.ams.linkDesc`,`Link a Spoolman spool to this slot`)})]})]}))]})]})]})})(),J&&(0,g.jsx)(_e,{isOpen:!!J,onClose:()=>{De(null),p.invalidateQueries({queryKey:[`spool-assignments`,e]}),p.invalidateQueries({queryKey:[`spool-assignments`]})},printerId:J.printerId,amsId:J.amsId,trayId:J.trayId,trayInfo:J.trayInfo,spoolmanEnabled:!!w}),Y&&(0,g.jsx)(ve,{isOpen:!!Y,onClose:()=>X(null),tagUid:Y.tagUid,trayUuid:Y.trayUuid,printerId:Y.printerId,amsId:Y.amsId,trayId:Y.trayId})]})}export{y as SpoolBuddyAmsPage}; \ No newline at end of file diff --git a/static/assets/SpoolBuddyCalibrationPage-BqJCOceW.js b/static/assets/SpoolBuddyCalibrationPage-C9Vz9h1f.js similarity index 98% rename from static/assets/SpoolBuddyCalibrationPage-BqJCOceW.js rename to static/assets/SpoolBuddyCalibrationPage-C9Vz9h1f.js index 91abdc372..d001222fd 100644 --- a/static/assets/SpoolBuddyCalibrationPage-BqJCOceW.js +++ b/static/assets/SpoolBuddyCalibrationPage-C9Vz9h1f.js @@ -1 +1 @@ -import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,v as r,w as i}from"./client-DnySrlFv.js";import{t as a}from"./useQuery-BBCjCezC.js";import{Hn as o,Vn as s}from"./index-0t--Yqoi.js";var c=e(n(),1),l=t();function u({device:e,weight:t,weightStable:n,rawAdc:a}){let{t:o}=i(),[s,u]=(0,c.useState)(!1),[d,f]=(0,c.useState)(`idle`),[p,m]=(0,c.useState)(`500`),[h,g]=(0,c.useState)(null),[_,v]=(0,c.useState)(!1),y=e=>{e===`backspace`?m(e=>e.slice(0,-1)||``):e===`.`&&!p.includes(`.`)?m(e=>e+`.`):e>=`0`&&e<=`9`&&m(t=>t===`0`?e:t+e)};return(0,l.jsxs)(`div`,{className:`space-y-4`,children:[(0,l.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-4`,children:[(0,l.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,l.jsx)(`span`,{className:`text-sm text-zinc-400`,children:o(`spoolbuddy.settings.currentWeight`,`Current weight`)}),(0,l.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,l.jsx)(`div`,{className:`w-2 h-2 rounded-full ${n?`bg-green-500`:`bg-amber-500 animate-pulse`}`}),(0,l.jsx)(`span`,{className:`text-lg font-mono text-zinc-200`,children:t===null?`-- g`:`${t.toFixed(1)} g`})]})]}),(0,l.jsxs)(`div`,{className:`grid grid-cols-2 gap-4 mt-3 text-xs`,children:[(0,l.jsxs)(`div`,{className:`flex justify-between`,children:[(0,l.jsx)(`span`,{className:`text-zinc-500`,children:o(`spoolbuddy.settings.tareOffset`,`Tare offset`)}),(0,l.jsx)(`span`,{className:`text-zinc-400 font-mono`,children:e.tare_offset})]}),(0,l.jsxs)(`div`,{className:`flex justify-between`,children:[(0,l.jsx)(`span`,{className:`text-zinc-500`,children:o(`spoolbuddy.settings.calFactor`,`Cal. factor`)}),(0,l.jsx)(`span`,{className:`text-zinc-400 font-mono`,children:e.calibration_factor.toFixed(2)})]})]})]}),d===`idle`?(0,l.jsxs)(`div`,{className:`flex gap-2`,children:[(0,l.jsx)(`button`,{onClick:async()=>{v(!0);try{await r.tare(e.device_id)}catch(e){console.error(`Failed to tare:`,e)}finally{v(!1)}},disabled:_,className:`flex-1 px-4 py-2.5 rounded-lg text-sm font-medium bg-zinc-700 text-zinc-200 hover:bg-zinc-600 disabled:opacity-40 transition-colors min-h-[44px]`,children:_?`...`:o(`spoolbuddy.weight.tare`,`Tare`)}),(0,l.jsx)(`button`,{onClick:()=>{f(`tare`)},className:`flex-1 px-4 py-2.5 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 transition-colors min-h-[44px]`,children:o(`spoolbuddy.weight.calibrate`,`Calibrate`)})]}):(0,l.jsxs)(`div`,{className:`bg-zinc-800 border border-zinc-700 rounded-lg p-3 space-y-2`,children:[(0,l.jsx)(`div`,{className:`text-sm font-medium text-zinc-200`,children:d===`tare`?o(`spoolbuddy.settings.calStep1`,`Step 1: Remove all items from the scale`):o(`spoolbuddy.settings.calStep2`,`Step 2: Place known weight on scale`)}),d===`weight`&&(0,l.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,l.jsx)(`span`,{className:`text-xs text-zinc-400`,children:o(`spoolbuddy.settings.knownWeight`,`Known weight (g)`)}),(0,l.jsxs)(`div`,{className:`flex-1 bg-zinc-900 border border-zinc-600 rounded px-3 py-1.5 text-right text-base font-mono text-zinc-100`,children:[p||`0`,(0,l.jsx)(`span`,{className:`text-zinc-500 ml-1`,children:`g`})]})]}),(0,l.jsx)(`div`,{className:`grid grid-cols-4 gap-1`,children:[`7`,`8`,`9`,`backspace`,`4`,`5`,`6`,`.`,`1`,`2`,`3`,`0`].map(e=>(0,l.jsx)(`button`,{onClick:()=>y(e),className:`py-2 rounded text-sm font-medium transition-colors min-h-[36px] ${e===`backspace`?`bg-zinc-700 text-zinc-300 hover:bg-zinc-600`:`bg-zinc-800 text-zinc-100 hover:bg-zinc-700 border border-zinc-700`}`,children:e===`backspace`?`⌫`:e},e))})]}),(0,l.jsxs)(`div`,{className:`flex gap-2`,children:[(0,l.jsx)(`button`,{onClick:()=>f(`idle`),className:`flex-1 px-4 py-2 rounded-lg text-sm bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors min-h-[40px]`,children:o(`common.cancel`,`Cancel`)}),(0,l.jsx)(`button`,{onClick:async()=>{if(d===`tare`){u(!0);try{g(a),await r.tare(e.device_id),f(`weight`)}catch(e){console.error(`Failed to tare:`,e)}finally{u(!1)}}else if(d===`weight`){let t=parseFloat(p);if(a===null||!t||t<=0)return;u(!0);try{await r.setCalibrationFactor(e.device_id,t,a,h??void 0),f(`idle`)}catch(e){console.error(`Failed to calibrate:`,e)}finally{u(!1)}}},disabled:s,className:`flex-1 px-4 py-2 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 disabled:opacity-40 transition-colors min-h-[40px]`,children:s?`...`:d===`tare`?o(`spoolbuddy.settings.setZero`,`Set Zero`):o(`spoolbuddy.settings.calibrateNow`,`Calibrate`)})]})]})]})}function d(){let{sbState:e}=o(),{t}=i(),n=s(),{data:c=[]}=a({queryKey:[`spoolbuddy-devices`],queryFn:()=>r.getDevices(),refetchInterval:1e4}),d=e.deviceId?c.find(t=>t.device_id===e.deviceId)??c[0]:c[0];return(0,l.jsxs)(`div`,{className:`h-full flex flex-col p-4`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-3 mb-4`,children:[(0,l.jsx)(`button`,{onClick:()=>n(`/spoolbuddy/settings`),className:`p-1.5 rounded-lg text-zinc-400 hover:text-zinc-200 hover:bg-zinc-800 transition-colors`,children:(0,l.jsx)(`svg`,{className:`w-5 h-5`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:2,children:(0,l.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M15 19l-7-7 7-7`})})}),(0,l.jsx)(`h1`,{className:`text-xl font-semibold text-zinc-100`,children:t(`spoolbuddy.settings.scaleCalibration`,`Scale Calibration`)})]}),(0,l.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto`,children:d?(0,l.jsx)(u,{device:d,weight:e.weight,weightStable:e.weightStable,rawAdc:e.rawAdc}):(0,l.jsx)(`div`,{className:`flex items-center justify-center h-32`,children:(0,l.jsx)(`div`,{className:`text-center text-zinc-500`,children:(0,l.jsx)(`p`,{className:`text-sm`,children:t(`spoolbuddy.settings.noDevice`,`No SpoolBuddy device found`)})})})})]})}export{d as SpoolBuddyCalibrationPage}; \ No newline at end of file +import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,v as r,w as i}from"./client-DnySrlFv.js";import{t as a}from"./useQuery-BBCjCezC.js";import{Hn as o,Vn as s}from"./index-Cxa-KVmA.js";var c=e(n(),1),l=t();function u({device:e,weight:t,weightStable:n,rawAdc:a}){let{t:o}=i(),[s,u]=(0,c.useState)(!1),[d,f]=(0,c.useState)(`idle`),[p,m]=(0,c.useState)(`500`),[h,g]=(0,c.useState)(null),[_,v]=(0,c.useState)(!1),y=e=>{e===`backspace`?m(e=>e.slice(0,-1)||``):e===`.`&&!p.includes(`.`)?m(e=>e+`.`):e>=`0`&&e<=`9`&&m(t=>t===`0`?e:t+e)};return(0,l.jsxs)(`div`,{className:`space-y-4`,children:[(0,l.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-4`,children:[(0,l.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,l.jsx)(`span`,{className:`text-sm text-zinc-400`,children:o(`spoolbuddy.settings.currentWeight`,`Current weight`)}),(0,l.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,l.jsx)(`div`,{className:`w-2 h-2 rounded-full ${n?`bg-green-500`:`bg-amber-500 animate-pulse`}`}),(0,l.jsx)(`span`,{className:`text-lg font-mono text-zinc-200`,children:t===null?`-- g`:`${t.toFixed(1)} g`})]})]}),(0,l.jsxs)(`div`,{className:`grid grid-cols-2 gap-4 mt-3 text-xs`,children:[(0,l.jsxs)(`div`,{className:`flex justify-between`,children:[(0,l.jsx)(`span`,{className:`text-zinc-500`,children:o(`spoolbuddy.settings.tareOffset`,`Tare offset`)}),(0,l.jsx)(`span`,{className:`text-zinc-400 font-mono`,children:e.tare_offset})]}),(0,l.jsxs)(`div`,{className:`flex justify-between`,children:[(0,l.jsx)(`span`,{className:`text-zinc-500`,children:o(`spoolbuddy.settings.calFactor`,`Cal. factor`)}),(0,l.jsx)(`span`,{className:`text-zinc-400 font-mono`,children:e.calibration_factor.toFixed(2)})]})]})]}),d===`idle`?(0,l.jsxs)(`div`,{className:`flex gap-2`,children:[(0,l.jsx)(`button`,{onClick:async()=>{v(!0);try{await r.tare(e.device_id)}catch(e){console.error(`Failed to tare:`,e)}finally{v(!1)}},disabled:_,className:`flex-1 px-4 py-2.5 rounded-lg text-sm font-medium bg-zinc-700 text-zinc-200 hover:bg-zinc-600 disabled:opacity-40 transition-colors min-h-[44px]`,children:_?`...`:o(`spoolbuddy.weight.tare`,`Tare`)}),(0,l.jsx)(`button`,{onClick:()=>{f(`tare`)},className:`flex-1 px-4 py-2.5 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 transition-colors min-h-[44px]`,children:o(`spoolbuddy.weight.calibrate`,`Calibrate`)})]}):(0,l.jsxs)(`div`,{className:`bg-zinc-800 border border-zinc-700 rounded-lg p-3 space-y-2`,children:[(0,l.jsx)(`div`,{className:`text-sm font-medium text-zinc-200`,children:d===`tare`?o(`spoolbuddy.settings.calStep1`,`Step 1: Remove all items from the scale`):o(`spoolbuddy.settings.calStep2`,`Step 2: Place known weight on scale`)}),d===`weight`&&(0,l.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,l.jsx)(`span`,{className:`text-xs text-zinc-400`,children:o(`spoolbuddy.settings.knownWeight`,`Known weight (g)`)}),(0,l.jsxs)(`div`,{className:`flex-1 bg-zinc-900 border border-zinc-600 rounded px-3 py-1.5 text-right text-base font-mono text-zinc-100`,children:[p||`0`,(0,l.jsx)(`span`,{className:`text-zinc-500 ml-1`,children:`g`})]})]}),(0,l.jsx)(`div`,{className:`grid grid-cols-4 gap-1`,children:[`7`,`8`,`9`,`backspace`,`4`,`5`,`6`,`.`,`1`,`2`,`3`,`0`].map(e=>(0,l.jsx)(`button`,{onClick:()=>y(e),className:`py-2 rounded text-sm font-medium transition-colors min-h-[36px] ${e===`backspace`?`bg-zinc-700 text-zinc-300 hover:bg-zinc-600`:`bg-zinc-800 text-zinc-100 hover:bg-zinc-700 border border-zinc-700`}`,children:e===`backspace`?`⌫`:e},e))})]}),(0,l.jsxs)(`div`,{className:`flex gap-2`,children:[(0,l.jsx)(`button`,{onClick:()=>f(`idle`),className:`flex-1 px-4 py-2 rounded-lg text-sm bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors min-h-[40px]`,children:o(`common.cancel`,`Cancel`)}),(0,l.jsx)(`button`,{onClick:async()=>{if(d===`tare`){u(!0);try{g(a),await r.tare(e.device_id),f(`weight`)}catch(e){console.error(`Failed to tare:`,e)}finally{u(!1)}}else if(d===`weight`){let t=parseFloat(p);if(a===null||!t||t<=0)return;u(!0);try{await r.setCalibrationFactor(e.device_id,t,a,h??void 0),f(`idle`)}catch(e){console.error(`Failed to calibrate:`,e)}finally{u(!1)}}},disabled:s,className:`flex-1 px-4 py-2 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 disabled:opacity-40 transition-colors min-h-[40px]`,children:s?`...`:d===`tare`?o(`spoolbuddy.settings.setZero`,`Set Zero`):o(`spoolbuddy.settings.calibrateNow`,`Calibrate`)})]})]})]})}function d(){let{sbState:e}=o(),{t}=i(),n=s(),{data:c=[]}=a({queryKey:[`spoolbuddy-devices`],queryFn:()=>r.getDevices(),refetchInterval:1e4}),d=e.deviceId?c.find(t=>t.device_id===e.deviceId)??c[0]:c[0];return(0,l.jsxs)(`div`,{className:`h-full flex flex-col p-4`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-3 mb-4`,children:[(0,l.jsx)(`button`,{onClick:()=>n(`/spoolbuddy/settings`),className:`p-1.5 rounded-lg text-zinc-400 hover:text-zinc-200 hover:bg-zinc-800 transition-colors`,children:(0,l.jsx)(`svg`,{className:`w-5 h-5`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:2,children:(0,l.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M15 19l-7-7 7-7`})})}),(0,l.jsx)(`h1`,{className:`text-xl font-semibold text-zinc-100`,children:t(`spoolbuddy.settings.scaleCalibration`,`Scale Calibration`)})]}),(0,l.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto`,children:d?(0,l.jsx)(u,{device:d,weight:e.weight,weightStable:e.weightStable,rawAdc:e.rawAdc}):(0,l.jsx)(`div`,{className:`flex items-center justify-center h-32`,children:(0,l.jsx)(`div`,{className:`text-center text-zinc-500`,children:(0,l.jsx)(`p`,{className:`text-sm`,children:t(`spoolbuddy.settings.noDevice`,`No SpoolBuddy device found`)})})})})]})}export{d as SpoolBuddyCalibrationPage}; \ No newline at end of file diff --git a/static/assets/SpoolBuddyDashboard-BEpEFke6.js b/static/assets/SpoolBuddyDashboard-0Mnwe1xw.js similarity index 99% rename from static/assets/SpoolBuddyDashboard-BEpEFke6.js rename to static/assets/SpoolBuddyDashboard-0Mnwe1xw.js index c053e9883..7cd1ea803 100644 --- a/static/assets/SpoolBuddyDashboard-BEpEFke6.js +++ b/static/assets/SpoolBuddyDashboard-0Mnwe1xw.js @@ -1 +1 @@ -import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,t as i,v as a,w as o}from"./client-DnySrlFv.js";import{n as s}from"./QueryClientProvider-Ce8_sN3w.js";import{t as c}from"./useQuery-BBCjCezC.js";import{t as l}from"./useMutation-B-Tr2hIP.js";import{t as u}from"./useQueries-Be6PMvSC.js";import{t as d}from"./check-Ck0cMLU4.js";import{n as f}from"./ToastContext-BRX0SW3C.js";import{t as p}from"./triangle-alert-Dt_1FcBy.js";import{t as m}from"./unlink-C098nwOf.js";import{t as h}from"./x-DR-Trv6U.js";import{Hn as g,Kt as ee,ft as _,pt as v}from"./index-0t--Yqoi.js";import{t as y}from"./AssignToAmsModal-CcnpBCWY.js";import{t as b}from"./SpoolIcon-DE8TbEec.js";var x=e(n(),1),S=t(),C=`spoolbuddy-default-core-weight`;function w(){try{let e=localStorage.getItem(C);if(e){let t=parseInt(e,10);if(t>=0&&t<=500)return t}}catch{}return 250}function T({spool:e,scaleWeight:t,onClose:n,onSyncWeight:r,onAssignToAms:i,isAssigned:s,onUnassignFromAms:c}){let{t:l}=o(),[u,f]=(0,x.useState)(!1),[h,g]=(0,x.useState)(!1),y=v(e.rgba),C=_(e.color_name,e.rgba,e.color_name_is_synthesized),T=e.core_weight&&e.core_weight>0?e.core_weight:w(),E=t===null?null:Math.round(Math.max(0,t)),D=E===null?null:Math.round(Math.max(0,E-T)),O=Math.round(e.label_weight||1e3),k=D===null?null:Math.min(100,Math.round(D/O*100)),A=k===null?`#808080`:k>50?`#22c55e`:k>20?`#eab308`:`#ef4444`,te=Math.max(0,(e.label_weight||0)-(e.weight_used||0))+T,j=E===null?null:E-te,M=j===null?null:Math.abs(j)<=50,N=async()=>{if(t!==null){f(!0);try{await a.updateSpoolWeight(e.id,Math.round(t)),g(!0),r?.(),setTimeout(()=>g(!1),3e3)}catch(e){console.error(`Failed to sync weight:`,e)}finally{f(!1)}}};return(0,S.jsxs)(`div`,{className:`flex flex-col items-center space-y-4 max-w-md`,children:[(0,S.jsxs)(`div`,{className:`flex items-start gap-5`,children:[(0,S.jsxs)(`div`,{className:`relative shrink-0`,children:[(0,S.jsx)(b,{color:y,isEmpty:!1,size:100,spool:e}),k!==null&&(0,S.jsxs)(`div`,{className:`absolute -bottom-2 -right-2 px-2 py-0.5 rounded-full text-xs font-bold text-white shadow-lg`,style:{backgroundColor:A},children:[k,`%`]})]}),(0,S.jsxs)(`div`,{className:`flex-1 min-w-0 pt-1`,children:[(0,S.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,S.jsx)(`h3`,{className:`text-lg font-semibold text-zinc-100`,children:C||l(`spoolbuddy.spool.unknownColor`)}),(0,S.jsxs)(`span`,{className:`text-xs font-mono text-zinc-500 shrink-0`,children:[`#`,e.id]})]}),(0,S.jsxs)(`p`,{className:`text-sm text-zinc-400`,children:[e.brand,` • `,e.material,e.subtype&&` ${e.subtype}`]}),D!==null&&(0,S.jsxs)(`div`,{className:`mt-3`,children:[(0,S.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,S.jsxs)(`span`,{className:`text-3xl font-bold font-mono text-zinc-100`,children:[D,`g`]}),(0,S.jsxs)(`span`,{className:`text-sm text-zinc-500`,children:[`/ `,O,`g`]})]}),(0,S.jsx)(`p`,{className:`text-xs text-zinc-500 mt-0.5`,children:l(`spoolbuddy.spool.remaining`,`Remaining`)}),(0,S.jsx)(`div`,{className:`mt-2 max-w-xs`,children:(0,S.jsx)(`div`,{className:`h-2 bg-zinc-700 rounded-full overflow-hidden`,children:(0,S.jsx)(`div`,{className:`h-full rounded-full transition-all duration-500`,style:{width:`${k}%`,backgroundColor:A}})})})]})]})]}),(0,S.jsxs)(`div`,{className:`grid grid-cols-2 gap-x-6 gap-y-2 text-sm bg-zinc-800 rounded-lg p-4 w-full`,children:[(0,S.jsxs)(`div`,{className:`flex justify-between`,children:[(0,S.jsx)(`span`,{className:`text-zinc-500`,children:l(`spoolbuddy.dashboard.grossWeight`,`Gross weight`)}),(0,S.jsx)(`span`,{className:`font-mono text-zinc-300`,children:E===null?`—`:`${E}g`})]}),(0,S.jsxs)(`div`,{className:`flex justify-between`,children:[(0,S.jsx)(`span`,{className:`text-zinc-500`,children:l(`spoolbuddy.spool.coreWeight`,`Core`)}),(0,S.jsxs)(`span`,{className:`font-mono text-zinc-300`,children:[T,`g`]})]}),(0,S.jsxs)(`div`,{className:`flex justify-between`,children:[(0,S.jsx)(`span`,{className:`text-zinc-500`,children:l(`spoolbuddy.dashboard.spoolSize`,`Spool size`)}),(0,S.jsxs)(`span`,{className:`font-mono text-zinc-300`,children:[O,`g`]})]}),(0,S.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,S.jsx)(`span`,{className:`text-zinc-500`,children:l(`spoolbuddy.spool.scaleWeight`,`Scale`)}),E===null?(0,S.jsx)(`span`,{className:`text-zinc-500`,children:`—`}):(0,S.jsxs)(`span`,{className:`flex items-center gap-1 font-mono ${M?`text-green-500`:`text-yellow-500`}`,children:[E,`g`,M?(0,S.jsx)(d,{className:`w-3.5 h-3.5`}):(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(p,{className:`w-3.5 h-3.5`}),(0,S.jsx)(`button`,{onClick:N,className:`p-1 hover:bg-green-500/20 rounded transition-colors text-green-500`,title:l(`spoolbuddy.dashboard.syncWeight`,`Sync Weight`),children:(0,S.jsx)(ee,{className:`w-4 h-4`})})]})]})]}),(0,S.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,S.jsx)(`span`,{className:`text-zinc-500`,children:l(`spoolbuddy.dashboard.tagId`,`Tag`)}),(0,S.jsx)(`span`,{className:`font-mono text-xs text-zinc-400 truncate max-w-[120px]`,title:e.tag_uid||``,children:e.tag_uid?e.tag_uid.slice(-8):`—`})]})]}),(0,S.jsxs)(`div`,{className:`flex gap-2 justify-center`,children:[i&&(0,S.jsx)(`button`,{onClick:s?void 0:i,disabled:!!s,className:`px-5 py-2.5 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 transition-colors min-h-[44px] disabled:opacity-50 disabled:cursor-not-allowed`,children:l(`spoolbuddy.modal.assignToAms`,`Assign to AMS`)}),c&&(0,S.jsxs)(`button`,{onClick:c,className:`px-5 py-2.5 rounded-lg text-sm font-medium bg-red-600/20 text-red-400 hover:bg-red-600/30 transition-colors min-h-[44px]`,children:[(0,S.jsx)(m,{className:`w-4 h-4 inline mr-1`}),l(`inventory.unassignSpool`)]}),(0,S.jsx)(`button`,{onClick:N,disabled:t===null||u,className:`px-5 py-2.5 rounded-lg text-sm font-medium transition-colors min-h-[44px] ${h?`bg-green-600/20 text-green-400`:i?`bg-zinc-700 text-zinc-300 hover:bg-zinc-600 disabled:opacity-40 disabled:cursor-not-allowed`:`bg-green-600 text-white hover:bg-green-700 disabled:opacity-40 disabled:cursor-not-allowed`}`,children:u?`...`:h?l(`spoolbuddy.dashboard.weightSynced`,`Synced!`):l(`spoolbuddy.dashboard.syncWeight`,`Sync Weight`)}),n&&(0,S.jsx)(`button`,{onClick:n,className:`px-5 py-2.5 rounded-lg text-sm font-medium bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors min-h-[44px]`,children:l(`spoolbuddy.dashboard.close`,`Close`)})]})]})}function E({tagUid:e,scaleWeight:t,coreWeight:n,onLinkSpool:r,onAddToInventory:i,onClose:a}){let{t:s}=o(),c=n??w(),l=t===null?null:Math.round(Math.max(0,t)),u=l===null?null:Math.round(Math.max(0,l-c));return(0,S.jsxs)(`div`,{className:`flex flex-col items-center text-center space-y-5`,children:[(0,S.jsx)(`div`,{className:`w-20 h-20 rounded-2xl bg-green-500/15 flex items-center justify-center`,children:(0,S.jsx)(`svg`,{className:`w-10 h-10 text-green-500`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,S.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`2`,d:`M7 7h.01M7 3h5c.512 0 1.024.195 1.414.586l7 7a2 2 0 010 2.828l-7 7a2 2 0 01-2.828 0l-7-7A2 2 0 013 12V7a4 4 0 014-4z`})})}),(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`h3`,{className:`text-lg font-semibold text-zinc-100`,children:s(`spoolbuddy.dashboard.newTag`,`New Tag Detected`)}),(0,S.jsx)(`p`,{className:`text-sm text-zinc-500 font-mono mt-1`,children:e})]}),l!==null&&(0,S.jsxs)(`div`,{className:`text-sm text-zinc-400`,children:[(0,S.jsxs)(`span`,{className:`font-mono font-semibold`,children:[l,`g`]}),` `,s(`spoolbuddy.dashboard.onScale`,`on scale`),u!==null&&u>0&&(0,S.jsxs)(`span`,{className:`text-zinc-500`,children:[` • ~`,u,`g filament`]})]}),(0,S.jsxs)(`div`,{className:`flex flex-wrap gap-2 justify-center`,children:[i&&(0,S.jsx)(`button`,{onClick:i,className:`px-5 py-2.5 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 transition-colors min-h-[44px]`,children:s(`spoolbuddy.modal.addToInventory`,`Add to Inventory`)}),r&&(0,S.jsxs)(`button`,{onClick:r,className:`px-5 py-2.5 rounded-lg text-sm font-medium bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors min-h-[44px]`,children:[(0,S.jsx)(`svg`,{className:`w-4 h-4 inline-block mr-1.5 -mt-0.5`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,S.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`2`,d:`M13.828 10.172a4 4 0 00-5.656 0l-4 4a4 4 0 105.656 5.656l1.102-1.101m-.758-4.899a4 4 0 005.656 0l4-4a4 4 0 00-5.656-5.656l-1.1 1.1`})}),s(`inventory.assignSpool`,`Assign Spool`)]}),a&&(0,S.jsx)(`button`,{onClick:a,className:`px-5 py-2.5 rounded-lg text-sm font-medium bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors min-h-[44px]`,children:s(`spoolbuddy.dashboard.close`,`Close`)})]})]})}function D({isOpen:e,onClose:t,tagId:n,untaggedSpools:r,onLink:i}){let{t:a}=o(),[s,c]=(0,x.useState)(null),l=(0,x.useCallback)(()=>{c(null),t()},[t]),u=(0,x.useCallback)(e=>{e.key===`Escape`&&l()},[l]);return(0,x.useEffect)(()=>(e&&(document.addEventListener(`keydown`,u),document.body.style.overflow=`hidden`),()=>{document.removeEventListener(`keydown`,u),document.body.style.overflow=``}),[e,u]),e?(0,S.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/70 animate-fade-in`,onClick:l,children:(0,S.jsxs)(`div`,{className:`bg-zinc-800 rounded-xl shadow-2xl w-full max-w-lg mx-4 animate-slide-up`,onClick:e=>e.stopPropagation(),children:[(0,S.jsxs)(`div`,{className:`flex items-center justify-between px-5 py-4 border-b border-zinc-700`,children:[(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`h2`,{className:`text-base font-semibold text-zinc-100`,children:a(`spoolbuddy.dashboard.linkTagTitle`,`Link Tag to Spool`)}),(0,S.jsx)(`p`,{className:`text-sm text-zinc-500 font-mono`,children:n})]}),(0,S.jsx)(`button`,{onClick:l,className:`p-2 rounded-lg text-zinc-500 hover:text-zinc-300 hover:bg-zinc-700 transition-colors`,children:(0,S.jsx)(h,{className:`w-5 h-5`})})]}),(0,S.jsxs)(`div`,{className:`px-5 py-4 space-y-3 max-h-[400px] overflow-y-auto`,children:[(0,S.jsx)(`p`,{className:`text-sm text-zinc-400`,children:a(`spoolbuddy.dashboard.selectSpool`,`Select a spool to link this tag to:`)}),r.length===0?(0,S.jsx)(`div`,{className:`text-center py-8 text-zinc-500`,children:a(`spoolbuddy.dashboard.noUntagged`,`No spools without tags found`)}):(0,S.jsx)(`div`,{className:`space-y-2`,children:r.map(e=>(0,S.jsxs)(`button`,{type:`button`,onClick:()=>c(e),className:`w-full flex items-center gap-3 p-3 rounded-lg border-2 transition-all text-left ${s?.id===e.id?`border-green-500 bg-green-500/10`:`border-zinc-700 hover:border-green-500/50 hover:bg-zinc-700/50`}`,children:[(0,S.jsx)(b,{color:v(e.rgba),spool:e,isEmpty:!1,size:40}),(0,S.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,S.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,S.jsx)(`div`,{className:`font-medium text-zinc-100 truncate`,children:_(e.color_name,e.rgba,e.color_name_is_synthesized)||a(`spoolbuddy.spool.unknownColor`)}),(0,S.jsxs)(`span`,{className:`text-[10px] font-mono text-zinc-500 shrink-0`,children:[`#`,e.id]})]}),(0,S.jsxs)(`div`,{className:`text-sm text-zinc-400 truncate`,children:[e.brand,` • `,e.material,e.subtype&&` ${e.subtype}`]})]}),(0,S.jsxs)(`div`,{className:`text-sm font-mono text-zinc-500`,children:[Math.max(0,e.label_weight-e.weight_used),`g`]})]},e.id))})]}),(0,S.jsxs)(`div`,{className:`flex justify-end gap-2 px-5 py-4 border-t border-zinc-700`,children:[(0,S.jsx)(`button`,{onClick:l,className:`px-4 py-2.5 rounded-lg text-sm font-medium bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors min-h-[44px]`,children:a(`common.cancel`,`Cancel`)}),(0,S.jsx)(`button`,{onClick:()=>{s&&(i(s),c(null))},disabled:!s,className:`px-4 py-2.5 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 disabled:opacity-40 disabled:cursor-not-allowed transition-colors min-h-[44px]`,children:a(`spoolbuddy.dashboard.linkTag`,`Link Tag`)})]})]})}):null}function O(e){return e?e.replace(/[^0-9a-f]/gi,``).toUpperCase():``}function k(e,t){let n=O(e),r=O(t);return!n||!r?!1:n===r?!0:n.endsWith(r)||r.endsWith(n)}var A=[`#00AE42`,`#FF6B35`,`#3B82F6`,`#EF4444`,`#A855F7`,`#FBBF24`,`#14B8A6`,`#EC4899`,`#F97316`,`#22C55E`];function te(){let{t:e}=o(),[t,n]=(0,x.useState)(0);(0,x.useEffect)(()=>{let e=setInterval(()=>{n(e=>(e+1)%A.length)},5e3);return()=>clearInterval(e)},[]);let r=A[t];return(0,S.jsxs)(`div`,{className:`flex flex-col items-center text-center`,children:[(0,S.jsxs)(`div`,{className:`relative mb-6 flex items-center justify-center`,style:{width:160,height:160},children:[(0,S.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center pointer-events-none`,children:[0,1].map(e=>(0,S.jsx)(`div`,{className:`absolute rounded-full border spoolbuddy-optimized-ping`,style:{width:80,height:80,borderColor:`${r}4D`,transition:`border-color 140ms linear`,animationDelay:`${e*.8}s`}},e))}),(0,S.jsxs)(`div`,{className:`relative overflow-hidden rounded-full`,children:[(0,S.jsx)(`div`,{className:`absolute inset-0 rounded-full opacity-30 spoolbuddy-spool-glow`,style:{background:`radial-gradient(circle, ${r} 0%, transparent 70%)`}}),(0,S.jsx)(`div`,{className:`relative`,style:{transition:`opacity 140ms linear`},children:(0,S.jsx)(b,{color:r,isEmpty:!1,size:100})})]})]}),(0,S.jsxs)(`div`,{className:`space-y-2`,children:[(0,S.jsx)(`p`,{className:`text-xl font-medium text-zinc-300`,children:e(`spoolbuddy.dashboard.readyToScan`,`Ready to scan`)}),(0,S.jsx)(`p`,{className:`text-sm text-zinc-500`,children:e(`spoolbuddy.dashboard.idleMessage`,`Place a spool on the scale to identify it`)})]}),(0,S.jsxs)(`div`,{className:`mt-6 flex items-center gap-2 text-sm text-zinc-600`,children:[(0,S.jsx)(`svg`,{className:`w-4 h-4`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,S.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`2`,d:`M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z`})}),(0,S.jsx)(`span`,{children:e(`spoolbuddy.dashboard.nfcHint`,`NFC tag will be read automatically`)})]})]})}function j(){let{t:e}=o();return(0,S.jsxs)(`div`,{className:`flex flex-col items-center text-center`,children:[(0,S.jsx)(`div`,{className:`relative mb-6 flex items-center justify-center`,style:{width:160,height:160},children:(0,S.jsx)(`div`,{className:`w-24 h-24 rounded-full bg-zinc-800 flex items-center justify-center`,children:(0,S.jsx)(`svg`,{className:`w-12 h-12 text-zinc-600`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,S.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`1.5`,d:`M18.364 5.636a9 9 0 010 12.728m0 0l-12.728-12.728m12.728 12.728L5.636 5.636m12.728 0a9 9 0 00-12.728 0m0 12.728a9 9 0 010-12.728`})})})}),(0,S.jsxs)(`div`,{className:`space-y-2`,children:[(0,S.jsx)(`p`,{className:`text-lg font-medium text-zinc-500`,children:e(`spoolbuddy.status.deviceOffline`,`Device Offline`)}),(0,S.jsx)(`p`,{className:`text-sm text-zinc-600`,children:e(`spoolbuddy.status.connectDisplay`,`Connect the SpoolBuddy display to scan spools`)})]}),(0,S.jsxs)(`div`,{className:`mt-6 flex items-center gap-2 text-xs text-zinc-600`,children:[(0,S.jsx)(`svg`,{className:`w-4 h-4`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,S.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`2`,d:`M8.111 16.404a5.5 5.5 0 017.778 0M12 20h.01m-7.08-7.071c3.904-3.905 10.236-3.905 14.14 0M1.394 9.393c5.857-5.857 15.355-5.857 21.213 0`})}),(0,S.jsx)(`span`,{children:e(`spoolbuddy.status.waitingConnection`,`Waiting for device connection...`)})]})]})}function M(){let{sbState:e,selectedPrinterId:t}=g(),{t:n}=o(),{showToast:a}=f(),{data:d}=c({queryKey:[`spoolman-settings`],queryFn:r.getSpoolmanSettings,staleTime:300*1e3}),p=d?.spoolman_enabled===`true`&&!!d?.spoolman_url,{data:m=[],refetch:h}=c({queryKey:p?[`spoolman-inventory-spools`]:[`inventory-spools`],queryFn:()=>p?r.getSpoolmanInventorySpools(!1):r.getSpools(!1),enabled:d!==void 0}),{data:ee=[]}=c({queryKey:[`spoolman-slot-assignments`],queryFn:()=>r.getSpoolmanSlotAssignments(),enabled:p,staleTime:3*1e3,refetchInterval:3*1e3,refetchIntervalInBackground:!1}),{data:_=[]}=c({queryKey:[`printers`],queryFn:()=>r.getPrinters()}),v=u({queries:_.map(e=>({queryKey:[`printerStatus`,e.id],queryFn:()=>r.getPrinterStatus(e.id),refetchInterval:1e4,select:e=>({connected:e?.connected,awaiting_plate_clear:e?.awaiting_plate_clear===!0})}))}),b=_.map((e,t)=>({printer:e,pending:v[t]?.data?.awaiting_plate_clear===!0})).filter(e=>e.pending),C=s(),w=l({mutationFn:e=>r.clearPlate(e),onSuccess:(e,t)=>{C.setQueryData([`printerStatus`,t],e=>e&&{...e,awaiting_plate_clear:!1}),a(n(`spoolbuddy.dashboard.plateClearedToast`,`Plate marked as cleared`),`success`)},onError:()=>{a(n(`spoolbuddy.dashboard.plateClearFailed`,`Could not mark plate as cleared`),`error`)}}),O=l({mutationFn:e=>r.unassignSpoolmanSlot(e),onSuccess:()=>{C.invalidateQueries({queryKey:[`spoolman-slot-assignments`]}),C.invalidateQueries({queryKey:[`spoolman-inventory-spools`]})},onError:()=>a(n(`inventory.unassignFailed`,`Failed to unassign spool`),`error`)}),[A,M]=(0,x.useState)(null),[N,P]=(0,x.useState)(null),[F,I]=(0,x.useState)(null),[L,R]=(0,x.useState)(null),[ne,z]=(0,x.useState)(!1),[re,B]=(0,x.useState)(!1),[ie,V]=(0,x.useState)(!1),[ae,oe]=(0,x.useState)(!1),[H,U]=(0,x.useState)(null),W=e.matchedSpool?.tag_uid??e.unknownTagUid??null,G=e.unknownTagUid?e.unknownTrayUuid:null,K=e.weight,q=e.weightStable,J=(0,x.useRef)(null);K===null?J.current=null:(J.current===null||Math.abs(K-J.current)>=3||q)&&(J.current=K);let Y=J.current,X=(0,x.useMemo)(()=>{if(e.matchedSpool?.id){let t=m.find(t=>t.id===e.matchedSpool?.id);if(t)return t}if(!A)return null;let t=m.find(e=>k(e.tag_uid,A));if(t)return t;if(N){let e=m.find(e=>e.tray_uuid?.toUpperCase()===N);if(e)return e}return H||null},[A,N,e.matchedSpool,m,H]),Z=(0,x.useMemo)(()=>{if(X&&!H)return X;let t=e.matchedSpool;return t?{id:t.id,tag_uid:t.tag_uid,material:t.material,subtype:t.subtype,color_name:t.color_name,color_name_is_synthesized:t.color_name_is_synthesized,rgba:t.rgba,brand:t.brand,label_weight:t.label_weight,core_weight:t.core_weight,weight_used:t.weight_used}:null},[X,H,e.matchedSpool]),se=p&&Z!=null?ee.some(e=>e.spoolman_spool_id===Z.id):!1,Q=(0,x.useMemo)(()=>p?m.filter(e=>!e.tag_uid&&!e.tray_uuid&&!e.archived_at):m.filter(e=>!e.tag_uid&&!e.archived_at),[m,p]);(0,x.useEffect)(()=>{if(W){let e=L===W;(A!==null&&A!==W||!e&&A!==W)&&(M(W),P(G),I(null),R(null),U(null)),!e&&K!==null&&q&&I(Math.round(Math.max(0,K)))}else L&&(M(null),P(null),R(null),I(null),U(null))},[W,G,K,q,A,L]);let ce=()=>{R(A)},le=async e=>{if(A)try{if(p){let t=await r.linkTagToSpoolmanSpool(e.id,{tag_uid:A,tray_uuid:N||void 0});if(!t){a(n(`spoolman.linkFailed`),`error`);return}let{id:i,material:o,subtype:s,color_name:c,color_name_is_synthesized:l,rgba:u,brand:d,label_weight:f,core_weight:p,weight_used:m}=t;U({id:i,material:o,subtype:s,color_name:c,color_name_is_synthesized:l,rgba:u,brand:d,label_weight:f,core_weight:p,weight_used:m}),a(n(`spoolman.linkSuccess`),`success`)}else await r.linkTagToSpool(e.id,{tag_uid:A,...N?{tray_uuid:N}:{},tag_type:N?`bambulab`:`generic`,data_origin:`nfc_link`});h()}catch(e){console.error(`Failed to link tag:`,e);let t=e instanceof i&&e.status===409&&e.code===`tag_already_linked`?e.detail?.spool_id:void 0;a(typeof t==`number`?n(`inventory.tagAlreadyLinked`,{id:t}):n(`spoolman.linkFailed`),`error`)}finally{z(!1)}},ue=async()=>{if(A){oe(!0);try{let e=$??F;if(p){let t=await r.createSpoolmanInventorySpool({material:`PLA`,subtype:null,color_name:null,rgba:null,extra_colors:null,effect_type:null,brand:null,label_weight:1e3,weight_used:0,slicer_filament:null,slicer_filament_name:null,nozzle_temp_min:null,nozzle_temp_max:null,note:null,added_full:null,last_used:null,encode_time:null,tag_uid:null,tray_uuid:null,data_origin:null,tag_type:null,cost_per_kg:null,last_scale_weight:e===null?null:Math.round(e),last_weighed_at:e===null?null:new Date().toISOString(),category:null,low_stock_threshold_pct:null});await r.linkTagToSpoolmanSpool(t.id,{tag_uid:A,tray_uuid:N||void 0})}else await r.createSpool({material:`PLA`,subtype:null,color_name:null,rgba:null,extra_colors:null,effect_type:null,brand:null,label_weight:1e3,core_weight:250,core_weight_catalog_id:null,weight_used:0,slicer_filament:null,slicer_filament_name:null,nozzle_temp_min:null,nozzle_temp_max:null,note:null,added_full:null,last_used:null,encode_time:null,tag_uid:A,tray_uuid:N,data_origin:`spoolbuddy`,tag_type:N?`bambulab`:`generic`,cost_per_kg:null,last_scale_weight:e===null?null:Math.round(e),last_weighed_at:e===null?null:new Date().toISOString(),category:null,low_stock_threshold_pct:null,material_number:null})}catch(e){let t=e instanceof Error?e.message:String(e);console.error(`Failed to quick-add spool:`,t),a(t||n(`spoolbuddy.errors.quickAddFailed`,`Failed to add spool`),`error`)}finally{V(!1),oe(!1),h()}}},$=K!==null&&(W===A||W===null&&A!==null)?K:null,de=m.length,fe=new Set(m.map(e=>e.material)).size,pe=new Set(m.filter(e=>e.brand).map(e=>e.brand)).size;return(0,S.jsxs)(`div`,{className:`h-full flex flex-col p-4`,children:[(0,S.jsxs)(`div`,{className:`flex items-center gap-6 px-4 py-1.5 bg-zinc-800/50 rounded-xl border border-zinc-700/50 mb-3 shrink-0`,children:[(0,S.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,S.jsx)(`span`,{className:`text-xl font-bold text-zinc-100`,children:de}),(0,S.jsx)(`span`,{className:`text-sm text-zinc-500`,children:n(`spoolbuddy.inventory.spools`,`Spools`)})]}),(0,S.jsx)(`div`,{className:`w-px h-5 bg-zinc-700`}),(0,S.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,S.jsx)(`span`,{className:`text-xl font-bold text-zinc-100`,children:fe}),(0,S.jsx)(`span`,{className:`text-sm text-zinc-500`,children:n(`spoolbuddy.spool.material`,`Materials`)})]}),(0,S.jsx)(`div`,{className:`w-px h-5 bg-zinc-700`}),(0,S.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,S.jsx)(`span`,{className:`text-xl font-bold text-zinc-100`,children:pe}),(0,S.jsx)(`span`,{className:`text-sm text-zinc-500`,children:n(`spoolbuddy.spool.brand`,`Brands`)})]})]}),(0,S.jsxs)(`div`,{className:`flex-1 flex gap-4 min-h-0`,children:[(0,S.jsxs)(`div`,{className:`w-5/12 flex flex-col min-h-0`,children:[(0,S.jsxs)(`div`,{className:`border border-dashed border-zinc-700/50 rounded-xl p-4`,children:[(0,S.jsx)(`h2`,{className:`text-sm font-semibold text-zinc-400 uppercase tracking-wide mb-3`,children:n(`spoolbuddy.dashboard.device`,`Device`)}),(0,S.jsxs)(`div`,{className:`space-y-2.5`,children:[(0,S.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,S.jsx)(`div`,{className:`w-2.5 h-2.5 rounded-full ${e.deviceOnline?`bg-green-500`:`bg-red-500`}`}),(0,S.jsx)(`span`,{className:`text-base text-zinc-400`,children:e.deviceOnline?n(`spoolbuddy.status.online`,`Online`):n(`spoolbuddy.status.offline`,`Disconnected`)})]}),(0,S.jsxs)(`div`,{className:`flex items-center justify-between p-3 bg-zinc-800/50 rounded-lg`,children:[(0,S.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,S.jsx)(`svg`,{className:`w-4 h-4 ${e.deviceOnline?`text-green-500`:`text-zinc-500`}`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,S.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`2`,d:`M3 6l3 1m0 0l-3 9a5.002 5.002 0 006.001 0M6 7l3 9M6 7l6-2m6 2l3-1m-3 1l-3 9a5.002 5.002 0 006.001 0M18 7l3 9m-3-9l-6-2m0-2v2m0 16V5m0 16H9m3 0h3`})}),(0,S.jsx)(`span`,{className:`text-sm text-zinc-500`,children:n(`spoolbuddy.spool.scaleWeight`,`Scale`)})]}),(0,S.jsx)(`span`,{className:`text-lg font-mono font-semibold text-zinc-100`,children:Y===null?`—`:`${Math.abs(Y)<=20?0:Math.round(Math.max(0,Y))}g`})]}),(0,S.jsxs)(`div`,{className:`flex items-center justify-between p-3 bg-zinc-800/50 rounded-lg`,children:[(0,S.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,S.jsx)(`svg`,{className:`w-4 h-4 ${e.deviceOnline?`text-green-500`:`text-zinc-500`}`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,S.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`2`,d:`M7 7h.01M7 3h5c.512 0 1.024.195 1.414.586l7 7a2 2 0 010 2.828l-7 7a2 2 0 01-2.828 0l-7-7A2 2 0 013 12V7a4 4 0 014-4z`})}),(0,S.jsx)(`span`,{className:`text-sm text-zinc-500`,children:`NFC`})]}),(0,S.jsx)(`span`,{className:`text-sm font-medium ${W?`text-green-500`:`text-zinc-500`}`,children:W?n(`spoolbuddy.dashboard.tagDetected`,`Tag detected`):n(`spoolbuddy.dashboard.noTag`,`No tag`)})]})]})]}),_.length>0&&(0,S.jsxs)(`div`,{className:`mt-3 border border-dashed border-zinc-700/50 rounded-xl p-4`,children:[(0,S.jsx)(`h2`,{className:`text-sm font-semibold text-zinc-400 uppercase tracking-wide mb-2.5`,children:n(`spoolbuddy.dashboard.printers`,`Printers`)}),(0,S.jsx)(`div`,{className:`flex flex-wrap gap-2 overflow-hidden`,children:_.map((e,t)=>{let n=v[t]?.data?.connected??!1;return(0,S.jsxs)(`div`,{className:`flex items-center gap-1.5 px-2.5 py-1 bg-zinc-800/50 rounded-lg`,title:`${e.name} — ${n?`Online`:`Offline`}`,children:[(0,S.jsx)(`div`,{className:`w-2 h-2 rounded-full shrink-0 ${n?`bg-green-500`:`bg-zinc-600`}`}),(0,S.jsx)(`span`,{className:`text-xs text-zinc-400 truncate max-w-[100px]`,children:e.name})]},e.id)})}),b.length>0&&(0,S.jsx)(`div`,{className:`mt-2 flex flex-wrap gap-2`,"data-testid":`plate-clear-section`,"aria-label":n(`spoolbuddy.dashboard.plateReadyLabel`,`Plates ready to clear`),children:b.map(({printer:e})=>(0,S.jsxs)(`button`,{type:`button`,onClick:()=>w.mutate(e.id),disabled:w.isPending,"data-testid":`plate-clear-button-${e.id}`,title:n(`spoolbuddy.dashboard.plateReady`,`Plate ready: {{name}}`,{name:e.name}),className:`flex items-center gap-1.5 px-2.5 py-1 rounded-lg bg-amber-500/10 hover:bg-amber-500/20 active:bg-amber-500/30 border border-amber-500/30 text-amber-200 transition-colors disabled:opacity-60 disabled:cursor-wait`,children:[(0,S.jsxs)(`svg`,{className:`w-3 h-3 shrink-0`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:[(0,S.jsx)(`path`,{d:`M12 9v4`}),(0,S.jsx)(`path`,{d:`M12 17h.01`}),(0,S.jsx)(`path`,{d:`M10.29 3.86 1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z`})]}),(0,S.jsx)(`span`,{className:`text-xs truncate max-w-[100px]`,children:e.name}),(0,S.jsx)(`span`,{className:`text-xs opacity-70`,"aria-hidden":`true`,children:`·`}),(0,S.jsx)(`span`,{className:`text-xs font-medium`,children:n(`spoolbuddy.dashboard.plateClearAction`,`Clear`)})]},e.id))})]})]}),(0,S.jsx)(`div`,{className:`w-7/12 min-h-0`,children:(0,S.jsxs)(`div`,{className:`border border-dashed border-zinc-700/50 rounded-xl p-6 h-full flex flex-col`,children:[(0,S.jsx)(`h2`,{className:`text-sm font-semibold text-zinc-400 uppercase tracking-wide mb-4 shrink-0`,children:n(`spoolbuddy.dashboard.currentSpool`,`Current Spool`)}),(0,S.jsx)(`div`,{className:`flex-1 flex items-center justify-center min-h-0`,children:e.deviceOnline?(X||e.matchedSpool)&&A&&L!==A?(0,S.jsx)(T,{spool:(()=>{let t=X??e.matchedSpool;return{id:t.id,tag_uid:A,material:t.material,subtype:t.subtype,color_name:t.color_name,color_name_is_synthesized:t.color_name_is_synthesized,rgba:t.rgba,brand:t.brand,label_weight:t.label_weight,core_weight:t.core_weight,weight_used:t.weight_used}})(),scaleWeight:$??F,onSyncWeight:()=>h(),onAssignToAms:()=>B(!0),isAssigned:se,onUnassignFromAms:se&&X?.id!=null?()=>O.mutate(X.id):void 0,onClose:ce}):W&&A&&!X&&!e.matchedSpool&&L!==A?(0,S.jsx)(E,{tagUid:A,scaleWeight:$??F,onLinkSpool:Q.length>0?()=>z(!0):void 0,onAddToInventory:()=>V(!0),onClose:ce}):(0,S.jsx)(te,{}):(0,S.jsx)(j,{})})]})})]}),Z&&!H&&A&&(0,S.jsx)(y,{isOpen:re,onClose:()=>B(!1),spool:Z,printerId:t,variant:`kiosk`,spoolmanMode:p}),A&&(0,S.jsx)(D,{isOpen:ne,onClose:()=>z(!1),tagId:A,untaggedSpools:Q,onLink:le}),ie&&A&&(0,S.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60`,children:(0,S.jsxs)(`div`,{className:`bg-zinc-800 rounded-2xl p-6 mx-4 max-w-sm w-full border border-zinc-700`,children:[(0,S.jsx)(`h3`,{className:`text-lg font-semibold text-zinc-100 mb-3`,children:n(`spoolbuddy.modal.addToInventory`,`Add to Inventory`)}),(0,S.jsxs)(`div`,{className:`flex gap-2.5 p-3 bg-amber-500/10 border border-amber-500/20 rounded-lg mb-4`,children:[(0,S.jsx)(`svg`,{className:`w-5 h-5 text-amber-500 shrink-0 mt-0.5`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,S.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`2`,d:`M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z`})}),(0,S.jsx)(`p`,{className:`text-sm text-amber-200/80`,children:n(`spoolbuddy.modal.quickAddHint`,`For best results, add the spool in the Bambuddy web interface first (with material, color, brand), then use "Assign Spool" here to assign the NFC tag.`)})]}),(0,S.jsx)(`p`,{className:`text-sm text-zinc-400 mb-1`,children:n(`spoolbuddy.modal.quickAddDesc`,`This will create a basic PLA spool entry with this NFC tag. You can edit the details later in Bambuddy.`)}),(0,S.jsx)(`p`,{className:`text-xs text-zinc-500 font-mono mb-5`,children:A}),(0,S.jsxs)(`div`,{className:`flex gap-3`,children:[(0,S.jsx)(`button`,{onClick:()=>V(!1),className:`flex-1 px-4 py-2.5 rounded-lg text-sm font-medium bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors min-h-[44px]`,children:n(`common.cancel`,`Cancel`)}),(0,S.jsx)(`button`,{onClick:ue,disabled:ae,className:`flex-1 px-4 py-2.5 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 disabled:opacity-50 transition-colors min-h-[44px]`,children:ae?n(`common.saving`,`Saving...`):n(`spoolbuddy.modal.addAnyway`,`Add Anyway`)})]})]})})]})}export{M as SpoolBuddyDashboard}; \ No newline at end of file +import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,t as i,v as a,w as o}from"./client-DnySrlFv.js";import{n as s}from"./QueryClientProvider-Ce8_sN3w.js";import{t as c}from"./useQuery-BBCjCezC.js";import{t as l}from"./useMutation-B-Tr2hIP.js";import{t as u}from"./useQueries-Be6PMvSC.js";import{t as d}from"./check-Ck0cMLU4.js";import{n as f}from"./ToastContext-BRX0SW3C.js";import{t as p}from"./triangle-alert-Dt_1FcBy.js";import{t as m}from"./unlink-C098nwOf.js";import{t as h}from"./x-DR-Trv6U.js";import{Hn as g,Kt as ee,ft as _,pt as v}from"./index-Cxa-KVmA.js";import{t as y}from"./AssignToAmsModal-dWQ_DHhy.js";import{t as b}from"./SpoolIcon-DE8TbEec.js";var x=e(n(),1),S=t(),C=`spoolbuddy-default-core-weight`;function w(){try{let e=localStorage.getItem(C);if(e){let t=parseInt(e,10);if(t>=0&&t<=500)return t}}catch{}return 250}function T({spool:e,scaleWeight:t,onClose:n,onSyncWeight:r,onAssignToAms:i,isAssigned:s,onUnassignFromAms:c}){let{t:l}=o(),[u,f]=(0,x.useState)(!1),[h,g]=(0,x.useState)(!1),y=v(e.rgba),C=_(e.color_name,e.rgba,e.color_name_is_synthesized),T=e.core_weight&&e.core_weight>0?e.core_weight:w(),E=t===null?null:Math.round(Math.max(0,t)),D=E===null?null:Math.round(Math.max(0,E-T)),O=Math.round(e.label_weight||1e3),k=D===null?null:Math.min(100,Math.round(D/O*100)),A=k===null?`#808080`:k>50?`#22c55e`:k>20?`#eab308`:`#ef4444`,te=Math.max(0,(e.label_weight||0)-(e.weight_used||0))+T,j=E===null?null:E-te,M=j===null?null:Math.abs(j)<=50,N=async()=>{if(t!==null){f(!0);try{await a.updateSpoolWeight(e.id,Math.round(t)),g(!0),r?.(),setTimeout(()=>g(!1),3e3)}catch(e){console.error(`Failed to sync weight:`,e)}finally{f(!1)}}};return(0,S.jsxs)(`div`,{className:`flex flex-col items-center space-y-4 max-w-md`,children:[(0,S.jsxs)(`div`,{className:`flex items-start gap-5`,children:[(0,S.jsxs)(`div`,{className:`relative shrink-0`,children:[(0,S.jsx)(b,{color:y,isEmpty:!1,size:100,spool:e}),k!==null&&(0,S.jsxs)(`div`,{className:`absolute -bottom-2 -right-2 px-2 py-0.5 rounded-full text-xs font-bold text-white shadow-lg`,style:{backgroundColor:A},children:[k,`%`]})]}),(0,S.jsxs)(`div`,{className:`flex-1 min-w-0 pt-1`,children:[(0,S.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,S.jsx)(`h3`,{className:`text-lg font-semibold text-zinc-100`,children:C||l(`spoolbuddy.spool.unknownColor`)}),(0,S.jsxs)(`span`,{className:`text-xs font-mono text-zinc-500 shrink-0`,children:[`#`,e.id]})]}),(0,S.jsxs)(`p`,{className:`text-sm text-zinc-400`,children:[e.brand,` • `,e.material,e.subtype&&` ${e.subtype}`]}),D!==null&&(0,S.jsxs)(`div`,{className:`mt-3`,children:[(0,S.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,S.jsxs)(`span`,{className:`text-3xl font-bold font-mono text-zinc-100`,children:[D,`g`]}),(0,S.jsxs)(`span`,{className:`text-sm text-zinc-500`,children:[`/ `,O,`g`]})]}),(0,S.jsx)(`p`,{className:`text-xs text-zinc-500 mt-0.5`,children:l(`spoolbuddy.spool.remaining`,`Remaining`)}),(0,S.jsx)(`div`,{className:`mt-2 max-w-xs`,children:(0,S.jsx)(`div`,{className:`h-2 bg-zinc-700 rounded-full overflow-hidden`,children:(0,S.jsx)(`div`,{className:`h-full rounded-full transition-all duration-500`,style:{width:`${k}%`,backgroundColor:A}})})})]})]})]}),(0,S.jsxs)(`div`,{className:`grid grid-cols-2 gap-x-6 gap-y-2 text-sm bg-zinc-800 rounded-lg p-4 w-full`,children:[(0,S.jsxs)(`div`,{className:`flex justify-between`,children:[(0,S.jsx)(`span`,{className:`text-zinc-500`,children:l(`spoolbuddy.dashboard.grossWeight`,`Gross weight`)}),(0,S.jsx)(`span`,{className:`font-mono text-zinc-300`,children:E===null?`—`:`${E}g`})]}),(0,S.jsxs)(`div`,{className:`flex justify-between`,children:[(0,S.jsx)(`span`,{className:`text-zinc-500`,children:l(`spoolbuddy.spool.coreWeight`,`Core`)}),(0,S.jsxs)(`span`,{className:`font-mono text-zinc-300`,children:[T,`g`]})]}),(0,S.jsxs)(`div`,{className:`flex justify-between`,children:[(0,S.jsx)(`span`,{className:`text-zinc-500`,children:l(`spoolbuddy.dashboard.spoolSize`,`Spool size`)}),(0,S.jsxs)(`span`,{className:`font-mono text-zinc-300`,children:[O,`g`]})]}),(0,S.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,S.jsx)(`span`,{className:`text-zinc-500`,children:l(`spoolbuddy.spool.scaleWeight`,`Scale`)}),E===null?(0,S.jsx)(`span`,{className:`text-zinc-500`,children:`—`}):(0,S.jsxs)(`span`,{className:`flex items-center gap-1 font-mono ${M?`text-green-500`:`text-yellow-500`}`,children:[E,`g`,M?(0,S.jsx)(d,{className:`w-3.5 h-3.5`}):(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(p,{className:`w-3.5 h-3.5`}),(0,S.jsx)(`button`,{onClick:N,className:`p-1 hover:bg-green-500/20 rounded transition-colors text-green-500`,title:l(`spoolbuddy.dashboard.syncWeight`,`Sync Weight`),children:(0,S.jsx)(ee,{className:`w-4 h-4`})})]})]})]}),(0,S.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,S.jsx)(`span`,{className:`text-zinc-500`,children:l(`spoolbuddy.dashboard.tagId`,`Tag`)}),(0,S.jsx)(`span`,{className:`font-mono text-xs text-zinc-400 truncate max-w-[120px]`,title:e.tag_uid||``,children:e.tag_uid?e.tag_uid.slice(-8):`—`})]})]}),(0,S.jsxs)(`div`,{className:`flex gap-2 justify-center`,children:[i&&(0,S.jsx)(`button`,{onClick:s?void 0:i,disabled:!!s,className:`px-5 py-2.5 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 transition-colors min-h-[44px] disabled:opacity-50 disabled:cursor-not-allowed`,children:l(`spoolbuddy.modal.assignToAms`,`Assign to AMS`)}),c&&(0,S.jsxs)(`button`,{onClick:c,className:`px-5 py-2.5 rounded-lg text-sm font-medium bg-red-600/20 text-red-400 hover:bg-red-600/30 transition-colors min-h-[44px]`,children:[(0,S.jsx)(m,{className:`w-4 h-4 inline mr-1`}),l(`inventory.unassignSpool`)]}),(0,S.jsx)(`button`,{onClick:N,disabled:t===null||u,className:`px-5 py-2.5 rounded-lg text-sm font-medium transition-colors min-h-[44px] ${h?`bg-green-600/20 text-green-400`:i?`bg-zinc-700 text-zinc-300 hover:bg-zinc-600 disabled:opacity-40 disabled:cursor-not-allowed`:`bg-green-600 text-white hover:bg-green-700 disabled:opacity-40 disabled:cursor-not-allowed`}`,children:u?`...`:h?l(`spoolbuddy.dashboard.weightSynced`,`Synced!`):l(`spoolbuddy.dashboard.syncWeight`,`Sync Weight`)}),n&&(0,S.jsx)(`button`,{onClick:n,className:`px-5 py-2.5 rounded-lg text-sm font-medium bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors min-h-[44px]`,children:l(`spoolbuddy.dashboard.close`,`Close`)})]})]})}function E({tagUid:e,scaleWeight:t,coreWeight:n,onLinkSpool:r,onAddToInventory:i,onClose:a}){let{t:s}=o(),c=n??w(),l=t===null?null:Math.round(Math.max(0,t)),u=l===null?null:Math.round(Math.max(0,l-c));return(0,S.jsxs)(`div`,{className:`flex flex-col items-center text-center space-y-5`,children:[(0,S.jsx)(`div`,{className:`w-20 h-20 rounded-2xl bg-green-500/15 flex items-center justify-center`,children:(0,S.jsx)(`svg`,{className:`w-10 h-10 text-green-500`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,S.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`2`,d:`M7 7h.01M7 3h5c.512 0 1.024.195 1.414.586l7 7a2 2 0 010 2.828l-7 7a2 2 0 01-2.828 0l-7-7A2 2 0 013 12V7a4 4 0 014-4z`})})}),(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`h3`,{className:`text-lg font-semibold text-zinc-100`,children:s(`spoolbuddy.dashboard.newTag`,`New Tag Detected`)}),(0,S.jsx)(`p`,{className:`text-sm text-zinc-500 font-mono mt-1`,children:e})]}),l!==null&&(0,S.jsxs)(`div`,{className:`text-sm text-zinc-400`,children:[(0,S.jsxs)(`span`,{className:`font-mono font-semibold`,children:[l,`g`]}),` `,s(`spoolbuddy.dashboard.onScale`,`on scale`),u!==null&&u>0&&(0,S.jsxs)(`span`,{className:`text-zinc-500`,children:[` • ~`,u,`g filament`]})]}),(0,S.jsxs)(`div`,{className:`flex flex-wrap gap-2 justify-center`,children:[i&&(0,S.jsx)(`button`,{onClick:i,className:`px-5 py-2.5 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 transition-colors min-h-[44px]`,children:s(`spoolbuddy.modal.addToInventory`,`Add to Inventory`)}),r&&(0,S.jsxs)(`button`,{onClick:r,className:`px-5 py-2.5 rounded-lg text-sm font-medium bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors min-h-[44px]`,children:[(0,S.jsx)(`svg`,{className:`w-4 h-4 inline-block mr-1.5 -mt-0.5`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,S.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`2`,d:`M13.828 10.172a4 4 0 00-5.656 0l-4 4a4 4 0 105.656 5.656l1.102-1.101m-.758-4.899a4 4 0 005.656 0l4-4a4 4 0 00-5.656-5.656l-1.1 1.1`})}),s(`inventory.assignSpool`,`Assign Spool`)]}),a&&(0,S.jsx)(`button`,{onClick:a,className:`px-5 py-2.5 rounded-lg text-sm font-medium bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors min-h-[44px]`,children:s(`spoolbuddy.dashboard.close`,`Close`)})]})]})}function D({isOpen:e,onClose:t,tagId:n,untaggedSpools:r,onLink:i}){let{t:a}=o(),[s,c]=(0,x.useState)(null),l=(0,x.useCallback)(()=>{c(null),t()},[t]),u=(0,x.useCallback)(e=>{e.key===`Escape`&&l()},[l]);return(0,x.useEffect)(()=>(e&&(document.addEventListener(`keydown`,u),document.body.style.overflow=`hidden`),()=>{document.removeEventListener(`keydown`,u),document.body.style.overflow=``}),[e,u]),e?(0,S.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/70 animate-fade-in`,onClick:l,children:(0,S.jsxs)(`div`,{className:`bg-zinc-800 rounded-xl shadow-2xl w-full max-w-lg mx-4 animate-slide-up`,onClick:e=>e.stopPropagation(),children:[(0,S.jsxs)(`div`,{className:`flex items-center justify-between px-5 py-4 border-b border-zinc-700`,children:[(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`h2`,{className:`text-base font-semibold text-zinc-100`,children:a(`spoolbuddy.dashboard.linkTagTitle`,`Link Tag to Spool`)}),(0,S.jsx)(`p`,{className:`text-sm text-zinc-500 font-mono`,children:n})]}),(0,S.jsx)(`button`,{onClick:l,className:`p-2 rounded-lg text-zinc-500 hover:text-zinc-300 hover:bg-zinc-700 transition-colors`,children:(0,S.jsx)(h,{className:`w-5 h-5`})})]}),(0,S.jsxs)(`div`,{className:`px-5 py-4 space-y-3 max-h-[400px] overflow-y-auto`,children:[(0,S.jsx)(`p`,{className:`text-sm text-zinc-400`,children:a(`spoolbuddy.dashboard.selectSpool`,`Select a spool to link this tag to:`)}),r.length===0?(0,S.jsx)(`div`,{className:`text-center py-8 text-zinc-500`,children:a(`spoolbuddy.dashboard.noUntagged`,`No spools without tags found`)}):(0,S.jsx)(`div`,{className:`space-y-2`,children:r.map(e=>(0,S.jsxs)(`button`,{type:`button`,onClick:()=>c(e),className:`w-full flex items-center gap-3 p-3 rounded-lg border-2 transition-all text-left ${s?.id===e.id?`border-green-500 bg-green-500/10`:`border-zinc-700 hover:border-green-500/50 hover:bg-zinc-700/50`}`,children:[(0,S.jsx)(b,{color:v(e.rgba),spool:e,isEmpty:!1,size:40}),(0,S.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,S.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,S.jsx)(`div`,{className:`font-medium text-zinc-100 truncate`,children:_(e.color_name,e.rgba,e.color_name_is_synthesized)||a(`spoolbuddy.spool.unknownColor`)}),(0,S.jsxs)(`span`,{className:`text-[10px] font-mono text-zinc-500 shrink-0`,children:[`#`,e.id]})]}),(0,S.jsxs)(`div`,{className:`text-sm text-zinc-400 truncate`,children:[e.brand,` • `,e.material,e.subtype&&` ${e.subtype}`]})]}),(0,S.jsxs)(`div`,{className:`text-sm font-mono text-zinc-500`,children:[Math.max(0,e.label_weight-e.weight_used),`g`]})]},e.id))})]}),(0,S.jsxs)(`div`,{className:`flex justify-end gap-2 px-5 py-4 border-t border-zinc-700`,children:[(0,S.jsx)(`button`,{onClick:l,className:`px-4 py-2.5 rounded-lg text-sm font-medium bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors min-h-[44px]`,children:a(`common.cancel`,`Cancel`)}),(0,S.jsx)(`button`,{onClick:()=>{s&&(i(s),c(null))},disabled:!s,className:`px-4 py-2.5 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 disabled:opacity-40 disabled:cursor-not-allowed transition-colors min-h-[44px]`,children:a(`spoolbuddy.dashboard.linkTag`,`Link Tag`)})]})]})}):null}function O(e){return e?e.replace(/[^0-9a-f]/gi,``).toUpperCase():``}function k(e,t){let n=O(e),r=O(t);return!n||!r?!1:n===r?!0:n.endsWith(r)||r.endsWith(n)}var A=[`#00AE42`,`#FF6B35`,`#3B82F6`,`#EF4444`,`#A855F7`,`#FBBF24`,`#14B8A6`,`#EC4899`,`#F97316`,`#22C55E`];function te(){let{t:e}=o(),[t,n]=(0,x.useState)(0);(0,x.useEffect)(()=>{let e=setInterval(()=>{n(e=>(e+1)%A.length)},5e3);return()=>clearInterval(e)},[]);let r=A[t];return(0,S.jsxs)(`div`,{className:`flex flex-col items-center text-center`,children:[(0,S.jsxs)(`div`,{className:`relative mb-6 flex items-center justify-center`,style:{width:160,height:160},children:[(0,S.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center pointer-events-none`,children:[0,1].map(e=>(0,S.jsx)(`div`,{className:`absolute rounded-full border spoolbuddy-optimized-ping`,style:{width:80,height:80,borderColor:`${r}4D`,transition:`border-color 140ms linear`,animationDelay:`${e*.8}s`}},e))}),(0,S.jsxs)(`div`,{className:`relative overflow-hidden rounded-full`,children:[(0,S.jsx)(`div`,{className:`absolute inset-0 rounded-full opacity-30 spoolbuddy-spool-glow`,style:{background:`radial-gradient(circle, ${r} 0%, transparent 70%)`}}),(0,S.jsx)(`div`,{className:`relative`,style:{transition:`opacity 140ms linear`},children:(0,S.jsx)(b,{color:r,isEmpty:!1,size:100})})]})]}),(0,S.jsxs)(`div`,{className:`space-y-2`,children:[(0,S.jsx)(`p`,{className:`text-xl font-medium text-zinc-300`,children:e(`spoolbuddy.dashboard.readyToScan`,`Ready to scan`)}),(0,S.jsx)(`p`,{className:`text-sm text-zinc-500`,children:e(`spoolbuddy.dashboard.idleMessage`,`Place a spool on the scale to identify it`)})]}),(0,S.jsxs)(`div`,{className:`mt-6 flex items-center gap-2 text-sm text-zinc-600`,children:[(0,S.jsx)(`svg`,{className:`w-4 h-4`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,S.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`2`,d:`M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z`})}),(0,S.jsx)(`span`,{children:e(`spoolbuddy.dashboard.nfcHint`,`NFC tag will be read automatically`)})]})]})}function j(){let{t:e}=o();return(0,S.jsxs)(`div`,{className:`flex flex-col items-center text-center`,children:[(0,S.jsx)(`div`,{className:`relative mb-6 flex items-center justify-center`,style:{width:160,height:160},children:(0,S.jsx)(`div`,{className:`w-24 h-24 rounded-full bg-zinc-800 flex items-center justify-center`,children:(0,S.jsx)(`svg`,{className:`w-12 h-12 text-zinc-600`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,S.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`1.5`,d:`M18.364 5.636a9 9 0 010 12.728m0 0l-12.728-12.728m12.728 12.728L5.636 5.636m12.728 0a9 9 0 00-12.728 0m0 12.728a9 9 0 010-12.728`})})})}),(0,S.jsxs)(`div`,{className:`space-y-2`,children:[(0,S.jsx)(`p`,{className:`text-lg font-medium text-zinc-500`,children:e(`spoolbuddy.status.deviceOffline`,`Device Offline`)}),(0,S.jsx)(`p`,{className:`text-sm text-zinc-600`,children:e(`spoolbuddy.status.connectDisplay`,`Connect the SpoolBuddy display to scan spools`)})]}),(0,S.jsxs)(`div`,{className:`mt-6 flex items-center gap-2 text-xs text-zinc-600`,children:[(0,S.jsx)(`svg`,{className:`w-4 h-4`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,S.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`2`,d:`M8.111 16.404a5.5 5.5 0 017.778 0M12 20h.01m-7.08-7.071c3.904-3.905 10.236-3.905 14.14 0M1.394 9.393c5.857-5.857 15.355-5.857 21.213 0`})}),(0,S.jsx)(`span`,{children:e(`spoolbuddy.status.waitingConnection`,`Waiting for device connection...`)})]})]})}function M(){let{sbState:e,selectedPrinterId:t}=g(),{t:n}=o(),{showToast:a}=f(),{data:d}=c({queryKey:[`spoolman-settings`],queryFn:r.getSpoolmanSettings,staleTime:300*1e3}),p=d?.spoolman_enabled===`true`&&!!d?.spoolman_url,{data:m=[],refetch:h}=c({queryKey:p?[`spoolman-inventory-spools`]:[`inventory-spools`],queryFn:()=>p?r.getSpoolmanInventorySpools(!1):r.getSpools(!1),enabled:d!==void 0}),{data:ee=[]}=c({queryKey:[`spoolman-slot-assignments`],queryFn:()=>r.getSpoolmanSlotAssignments(),enabled:p,staleTime:3*1e3,refetchInterval:3*1e3,refetchIntervalInBackground:!1}),{data:_=[]}=c({queryKey:[`printers`],queryFn:()=>r.getPrinters()}),v=u({queries:_.map(e=>({queryKey:[`printerStatus`,e.id],queryFn:()=>r.getPrinterStatus(e.id),refetchInterval:1e4,select:e=>({connected:e?.connected,awaiting_plate_clear:e?.awaiting_plate_clear===!0})}))}),b=_.map((e,t)=>({printer:e,pending:v[t]?.data?.awaiting_plate_clear===!0})).filter(e=>e.pending),C=s(),w=l({mutationFn:e=>r.clearPlate(e),onSuccess:(e,t)=>{C.setQueryData([`printerStatus`,t],e=>e&&{...e,awaiting_plate_clear:!1}),a(n(`spoolbuddy.dashboard.plateClearedToast`,`Plate marked as cleared`),`success`)},onError:()=>{a(n(`spoolbuddy.dashboard.plateClearFailed`,`Could not mark plate as cleared`),`error`)}}),O=l({mutationFn:e=>r.unassignSpoolmanSlot(e),onSuccess:()=>{C.invalidateQueries({queryKey:[`spoolman-slot-assignments`]}),C.invalidateQueries({queryKey:[`spoolman-inventory-spools`]})},onError:()=>a(n(`inventory.unassignFailed`,`Failed to unassign spool`),`error`)}),[A,M]=(0,x.useState)(null),[N,P]=(0,x.useState)(null),[F,I]=(0,x.useState)(null),[L,R]=(0,x.useState)(null),[ne,z]=(0,x.useState)(!1),[re,B]=(0,x.useState)(!1),[ie,V]=(0,x.useState)(!1),[ae,oe]=(0,x.useState)(!1),[H,U]=(0,x.useState)(null),W=e.matchedSpool?.tag_uid??e.unknownTagUid??null,G=e.unknownTagUid?e.unknownTrayUuid:null,K=e.weight,q=e.weightStable,J=(0,x.useRef)(null);K===null?J.current=null:(J.current===null||Math.abs(K-J.current)>=3||q)&&(J.current=K);let Y=J.current,X=(0,x.useMemo)(()=>{if(e.matchedSpool?.id){let t=m.find(t=>t.id===e.matchedSpool?.id);if(t)return t}if(!A)return null;let t=m.find(e=>k(e.tag_uid,A));if(t)return t;if(N){let e=m.find(e=>e.tray_uuid?.toUpperCase()===N);if(e)return e}return H||null},[A,N,e.matchedSpool,m,H]),Z=(0,x.useMemo)(()=>{if(X&&!H)return X;let t=e.matchedSpool;return t?{id:t.id,tag_uid:t.tag_uid,material:t.material,subtype:t.subtype,color_name:t.color_name,color_name_is_synthesized:t.color_name_is_synthesized,rgba:t.rgba,brand:t.brand,label_weight:t.label_weight,core_weight:t.core_weight,weight_used:t.weight_used}:null},[X,H,e.matchedSpool]),se=p&&Z!=null?ee.some(e=>e.spoolman_spool_id===Z.id):!1,Q=(0,x.useMemo)(()=>p?m.filter(e=>!e.tag_uid&&!e.tray_uuid&&!e.archived_at):m.filter(e=>!e.tag_uid&&!e.archived_at),[m,p]);(0,x.useEffect)(()=>{if(W){let e=L===W;(A!==null&&A!==W||!e&&A!==W)&&(M(W),P(G),I(null),R(null),U(null)),!e&&K!==null&&q&&I(Math.round(Math.max(0,K)))}else L&&(M(null),P(null),R(null),I(null),U(null))},[W,G,K,q,A,L]);let ce=()=>{R(A)},le=async e=>{if(A)try{if(p){let t=await r.linkTagToSpoolmanSpool(e.id,{tag_uid:A,tray_uuid:N||void 0});if(!t){a(n(`spoolman.linkFailed`),`error`);return}let{id:i,material:o,subtype:s,color_name:c,color_name_is_synthesized:l,rgba:u,brand:d,label_weight:f,core_weight:p,weight_used:m}=t;U({id:i,material:o,subtype:s,color_name:c,color_name_is_synthesized:l,rgba:u,brand:d,label_weight:f,core_weight:p,weight_used:m}),a(n(`spoolman.linkSuccess`),`success`)}else await r.linkTagToSpool(e.id,{tag_uid:A,...N?{tray_uuid:N}:{},tag_type:N?`bambulab`:`generic`,data_origin:`nfc_link`});h()}catch(e){console.error(`Failed to link tag:`,e);let t=e instanceof i&&e.status===409&&e.code===`tag_already_linked`?e.detail?.spool_id:void 0;a(typeof t==`number`?n(`inventory.tagAlreadyLinked`,{id:t}):n(`spoolman.linkFailed`),`error`)}finally{z(!1)}},ue=async()=>{if(A){oe(!0);try{let e=$??F;if(p){let t=await r.createSpoolmanInventorySpool({material:`PLA`,subtype:null,color_name:null,rgba:null,extra_colors:null,effect_type:null,brand:null,label_weight:1e3,weight_used:0,slicer_filament:null,slicer_filament_name:null,nozzle_temp_min:null,nozzle_temp_max:null,note:null,added_full:null,last_used:null,encode_time:null,tag_uid:null,tray_uuid:null,data_origin:null,tag_type:null,cost_per_kg:null,last_scale_weight:e===null?null:Math.round(e),last_weighed_at:e===null?null:new Date().toISOString(),category:null,low_stock_threshold_pct:null});await r.linkTagToSpoolmanSpool(t.id,{tag_uid:A,tray_uuid:N||void 0})}else await r.createSpool({material:`PLA`,subtype:null,color_name:null,rgba:null,extra_colors:null,effect_type:null,brand:null,label_weight:1e3,core_weight:250,core_weight_catalog_id:null,weight_used:0,slicer_filament:null,slicer_filament_name:null,nozzle_temp_min:null,nozzle_temp_max:null,note:null,added_full:null,last_used:null,encode_time:null,tag_uid:A,tray_uuid:N,data_origin:`spoolbuddy`,tag_type:N?`bambulab`:`generic`,cost_per_kg:null,last_scale_weight:e===null?null:Math.round(e),last_weighed_at:e===null?null:new Date().toISOString(),category:null,low_stock_threshold_pct:null,material_number:null})}catch(e){let t=e instanceof Error?e.message:String(e);console.error(`Failed to quick-add spool:`,t),a(t||n(`spoolbuddy.errors.quickAddFailed`,`Failed to add spool`),`error`)}finally{V(!1),oe(!1),h()}}},$=K!==null&&(W===A||W===null&&A!==null)?K:null,de=m.length,fe=new Set(m.map(e=>e.material)).size,pe=new Set(m.filter(e=>e.brand).map(e=>e.brand)).size;return(0,S.jsxs)(`div`,{className:`h-full flex flex-col p-4`,children:[(0,S.jsxs)(`div`,{className:`flex items-center gap-6 px-4 py-1.5 bg-zinc-800/50 rounded-xl border border-zinc-700/50 mb-3 shrink-0`,children:[(0,S.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,S.jsx)(`span`,{className:`text-xl font-bold text-zinc-100`,children:de}),(0,S.jsx)(`span`,{className:`text-sm text-zinc-500`,children:n(`spoolbuddy.inventory.spools`,`Spools`)})]}),(0,S.jsx)(`div`,{className:`w-px h-5 bg-zinc-700`}),(0,S.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,S.jsx)(`span`,{className:`text-xl font-bold text-zinc-100`,children:fe}),(0,S.jsx)(`span`,{className:`text-sm text-zinc-500`,children:n(`spoolbuddy.spool.material`,`Materials`)})]}),(0,S.jsx)(`div`,{className:`w-px h-5 bg-zinc-700`}),(0,S.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,S.jsx)(`span`,{className:`text-xl font-bold text-zinc-100`,children:pe}),(0,S.jsx)(`span`,{className:`text-sm text-zinc-500`,children:n(`spoolbuddy.spool.brand`,`Brands`)})]})]}),(0,S.jsxs)(`div`,{className:`flex-1 flex gap-4 min-h-0`,children:[(0,S.jsxs)(`div`,{className:`w-5/12 flex flex-col min-h-0`,children:[(0,S.jsxs)(`div`,{className:`border border-dashed border-zinc-700/50 rounded-xl p-4`,children:[(0,S.jsx)(`h2`,{className:`text-sm font-semibold text-zinc-400 uppercase tracking-wide mb-3`,children:n(`spoolbuddy.dashboard.device`,`Device`)}),(0,S.jsxs)(`div`,{className:`space-y-2.5`,children:[(0,S.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,S.jsx)(`div`,{className:`w-2.5 h-2.5 rounded-full ${e.deviceOnline?`bg-green-500`:`bg-red-500`}`}),(0,S.jsx)(`span`,{className:`text-base text-zinc-400`,children:e.deviceOnline?n(`spoolbuddy.status.online`,`Online`):n(`spoolbuddy.status.offline`,`Disconnected`)})]}),(0,S.jsxs)(`div`,{className:`flex items-center justify-between p-3 bg-zinc-800/50 rounded-lg`,children:[(0,S.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,S.jsx)(`svg`,{className:`w-4 h-4 ${e.deviceOnline?`text-green-500`:`text-zinc-500`}`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,S.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`2`,d:`M3 6l3 1m0 0l-3 9a5.002 5.002 0 006.001 0M6 7l3 9M6 7l6-2m6 2l3-1m-3 1l-3 9a5.002 5.002 0 006.001 0M18 7l3 9m-3-9l-6-2m0-2v2m0 16V5m0 16H9m3 0h3`})}),(0,S.jsx)(`span`,{className:`text-sm text-zinc-500`,children:n(`spoolbuddy.spool.scaleWeight`,`Scale`)})]}),(0,S.jsx)(`span`,{className:`text-lg font-mono font-semibold text-zinc-100`,children:Y===null?`—`:`${Math.abs(Y)<=20?0:Math.round(Math.max(0,Y))}g`})]}),(0,S.jsxs)(`div`,{className:`flex items-center justify-between p-3 bg-zinc-800/50 rounded-lg`,children:[(0,S.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,S.jsx)(`svg`,{className:`w-4 h-4 ${e.deviceOnline?`text-green-500`:`text-zinc-500`}`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,S.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`2`,d:`M7 7h.01M7 3h5c.512 0 1.024.195 1.414.586l7 7a2 2 0 010 2.828l-7 7a2 2 0 01-2.828 0l-7-7A2 2 0 013 12V7a4 4 0 014-4z`})}),(0,S.jsx)(`span`,{className:`text-sm text-zinc-500`,children:`NFC`})]}),(0,S.jsx)(`span`,{className:`text-sm font-medium ${W?`text-green-500`:`text-zinc-500`}`,children:W?n(`spoolbuddy.dashboard.tagDetected`,`Tag detected`):n(`spoolbuddy.dashboard.noTag`,`No tag`)})]})]})]}),_.length>0&&(0,S.jsxs)(`div`,{className:`mt-3 border border-dashed border-zinc-700/50 rounded-xl p-4`,children:[(0,S.jsx)(`h2`,{className:`text-sm font-semibold text-zinc-400 uppercase tracking-wide mb-2.5`,children:n(`spoolbuddy.dashboard.printers`,`Printers`)}),(0,S.jsx)(`div`,{className:`flex flex-wrap gap-2 overflow-hidden`,children:_.map((e,t)=>{let n=v[t]?.data?.connected??!1;return(0,S.jsxs)(`div`,{className:`flex items-center gap-1.5 px-2.5 py-1 bg-zinc-800/50 rounded-lg`,title:`${e.name} — ${n?`Online`:`Offline`}`,children:[(0,S.jsx)(`div`,{className:`w-2 h-2 rounded-full shrink-0 ${n?`bg-green-500`:`bg-zinc-600`}`}),(0,S.jsx)(`span`,{className:`text-xs text-zinc-400 truncate max-w-[100px]`,children:e.name})]},e.id)})}),b.length>0&&(0,S.jsx)(`div`,{className:`mt-2 flex flex-wrap gap-2`,"data-testid":`plate-clear-section`,"aria-label":n(`spoolbuddy.dashboard.plateReadyLabel`,`Plates ready to clear`),children:b.map(({printer:e})=>(0,S.jsxs)(`button`,{type:`button`,onClick:()=>w.mutate(e.id),disabled:w.isPending,"data-testid":`plate-clear-button-${e.id}`,title:n(`spoolbuddy.dashboard.plateReady`,`Plate ready: {{name}}`,{name:e.name}),className:`flex items-center gap-1.5 px-2.5 py-1 rounded-lg bg-amber-500/10 hover:bg-amber-500/20 active:bg-amber-500/30 border border-amber-500/30 text-amber-200 transition-colors disabled:opacity-60 disabled:cursor-wait`,children:[(0,S.jsxs)(`svg`,{className:`w-3 h-3 shrink-0`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:[(0,S.jsx)(`path`,{d:`M12 9v4`}),(0,S.jsx)(`path`,{d:`M12 17h.01`}),(0,S.jsx)(`path`,{d:`M10.29 3.86 1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z`})]}),(0,S.jsx)(`span`,{className:`text-xs truncate max-w-[100px]`,children:e.name}),(0,S.jsx)(`span`,{className:`text-xs opacity-70`,"aria-hidden":`true`,children:`·`}),(0,S.jsx)(`span`,{className:`text-xs font-medium`,children:n(`spoolbuddy.dashboard.plateClearAction`,`Clear`)})]},e.id))})]})]}),(0,S.jsx)(`div`,{className:`w-7/12 min-h-0`,children:(0,S.jsxs)(`div`,{className:`border border-dashed border-zinc-700/50 rounded-xl p-6 h-full flex flex-col`,children:[(0,S.jsx)(`h2`,{className:`text-sm font-semibold text-zinc-400 uppercase tracking-wide mb-4 shrink-0`,children:n(`spoolbuddy.dashboard.currentSpool`,`Current Spool`)}),(0,S.jsx)(`div`,{className:`flex-1 flex items-center justify-center min-h-0`,children:e.deviceOnline?(X||e.matchedSpool)&&A&&L!==A?(0,S.jsx)(T,{spool:(()=>{let t=X??e.matchedSpool;return{id:t.id,tag_uid:A,material:t.material,subtype:t.subtype,color_name:t.color_name,color_name_is_synthesized:t.color_name_is_synthesized,rgba:t.rgba,brand:t.brand,label_weight:t.label_weight,core_weight:t.core_weight,weight_used:t.weight_used}})(),scaleWeight:$??F,onSyncWeight:()=>h(),onAssignToAms:()=>B(!0),isAssigned:se,onUnassignFromAms:se&&X?.id!=null?()=>O.mutate(X.id):void 0,onClose:ce}):W&&A&&!X&&!e.matchedSpool&&L!==A?(0,S.jsx)(E,{tagUid:A,scaleWeight:$??F,onLinkSpool:Q.length>0?()=>z(!0):void 0,onAddToInventory:()=>V(!0),onClose:ce}):(0,S.jsx)(te,{}):(0,S.jsx)(j,{})})]})})]}),Z&&!H&&A&&(0,S.jsx)(y,{isOpen:re,onClose:()=>B(!1),spool:Z,printerId:t,variant:`kiosk`,spoolmanMode:p}),A&&(0,S.jsx)(D,{isOpen:ne,onClose:()=>z(!1),tagId:A,untaggedSpools:Q,onLink:le}),ie&&A&&(0,S.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60`,children:(0,S.jsxs)(`div`,{className:`bg-zinc-800 rounded-2xl p-6 mx-4 max-w-sm w-full border border-zinc-700`,children:[(0,S.jsx)(`h3`,{className:`text-lg font-semibold text-zinc-100 mb-3`,children:n(`spoolbuddy.modal.addToInventory`,`Add to Inventory`)}),(0,S.jsxs)(`div`,{className:`flex gap-2.5 p-3 bg-amber-500/10 border border-amber-500/20 rounded-lg mb-4`,children:[(0,S.jsx)(`svg`,{className:`w-5 h-5 text-amber-500 shrink-0 mt-0.5`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,S.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`2`,d:`M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z`})}),(0,S.jsx)(`p`,{className:`text-sm text-amber-200/80`,children:n(`spoolbuddy.modal.quickAddHint`,`For best results, add the spool in the Bambuddy web interface first (with material, color, brand), then use "Assign Spool" here to assign the NFC tag.`)})]}),(0,S.jsx)(`p`,{className:`text-sm text-zinc-400 mb-1`,children:n(`spoolbuddy.modal.quickAddDesc`,`This will create a basic PLA spool entry with this NFC tag. You can edit the details later in Bambuddy.`)}),(0,S.jsx)(`p`,{className:`text-xs text-zinc-500 font-mono mb-5`,children:A}),(0,S.jsxs)(`div`,{className:`flex gap-3`,children:[(0,S.jsx)(`button`,{onClick:()=>V(!1),className:`flex-1 px-4 py-2.5 rounded-lg text-sm font-medium bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors min-h-[44px]`,children:n(`common.cancel`,`Cancel`)}),(0,S.jsx)(`button`,{onClick:ue,disabled:ae,className:`flex-1 px-4 py-2.5 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 disabled:opacity-50 transition-colors min-h-[44px]`,children:ae?n(`common.saving`,`Saving...`):n(`spoolbuddy.modal.addAnyway`,`Add Anyway`)})]})]})})]})}export{M as SpoolBuddyDashboard}; \ No newline at end of file diff --git a/static/assets/SpoolBuddyInventoryPage-DOeFqPsy.js b/static/assets/SpoolBuddyInventoryPage-FFmQ5AMP.js similarity index 98% rename from static/assets/SpoolBuddyInventoryPage-DOeFqPsy.js rename to static/assets/SpoolBuddyInventoryPage-FFmQ5AMP.js index 0565e07be..08cea3bea 100644 --- a/static/assets/SpoolBuddyInventoryPage-DOeFqPsy.js +++ b/static/assets/SpoolBuddyInventoryPage-FFmQ5AMP.js @@ -1 +1 @@ -import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,v as i,w as a}from"./client-DnySrlFv.js";import{n as o}from"./QueryClientProvider-Ce8_sN3w.js";import{t as s}from"./useQuery-BBCjCezC.js";import{t as c}from"./useMutation-B-Tr2hIP.js";import{t as l}from"./check-Ck0cMLU4.js";import{n as u}from"./ToastContext-BRX0SW3C.js";import{t as d}from"./package-BGUevlqS.js";import{t as f}from"./search-0n0CBc74.js";import{t as p}from"./triangle-alert-Dt_1FcBy.js";import{t as m}from"./unlink-C098nwOf.js";import{t as h}from"./x-DR-Trv6U.js";import{H as g,Hn as _,Kt as v,ft as y,lt as b,ot as x,pt as S}from"./index-0t--Yqoi.js";import{n as C,t as w}from"./spoolPaint-CrvpHqdD.js";import{t as T}from"./AssignToAmsModal-CcnpBCWY.js";import{t as E}from"./inventorySearch-C_D57LMP.js";import{n as D,r as O,t as k}from"./SpoolIcon-DE8TbEec.js";var A=e(n(),1),j=t(),M=`spoolbuddy-default-core-weight`;function N(){try{let e=localStorage.getItem(M);if(e){let t=parseInt(e,10);if(t>=0&&t<=500)return t}}catch{}return 250}function P({spool:e,liveScaleWeight:t,persistedGrossWeight:n,onClose:o,onSyncWeight:c,onAssignToAms:u,isAssigned:d,onUnassignFromAms:f,className:h}){let{t:g}=a(),[_,b]=(0,A.useState)(!1),[x,C]=(0,A.useState)(!1),[w,T]=(0,A.useState)(null),{data:E}=s({queryKey:[`spool-k-profiles`,e.id],queryFn:()=>r.getSpoolKProfiles(e.id),enabled:!e.k_profiles||e.k_profiles.length===0,staleTime:300*1e3}),D=e.k_profiles&&e.k_profiles.length>0?e.k_profiles:E,O=S(e.rgba),M=y(e.color_name,e.rgba,e.color_name_is_synthesized),P=e.core_weight&&e.core_weight>0?e.core_weight:N(),F=t===null?null:Math.round(Math.max(0,t)),I=w??(n===void 0?F:n===null?null:Math.round(Math.max(0,n))),L=Math.round(Math.max(0,(e.label_weight||0)-(e.weight_used||0))),R=F!==null&&F>=10?Math.round(Math.max(0,F-P)):L,z=Math.round(e.label_weight||1e3),B=z>0?Math.min(100,Math.round(R/z*100)):null,V=B===null?`#808080`:B>50?`#22c55e`:B>20?`#eab308`:`#ef4444`,H=Math.max(0,(e.label_weight||0)-(e.weight_used||0))+P,U=F===null?null:F-H,W=U===null?null:Math.abs(U)<=50,G=I??Math.round(H),K=e.nozzle_temp_min!=null&&e.nozzle_temp_max!=null?`${e.nozzle_temp_min}-${e.nozzle_temp_max}\u00B0C`:null,q=e.slicer_filament_name||e.slicer_filament||null,J=e.note?.trim()||null,Y=D&&D.length>0?Array.from(new Set(D.map(e=>e.k_value.toFixed(3)))).join(`, `):null,X=async()=>{if(t===null)return;let n=Math.round(Math.max(0,t));b(!0);try{await i.updateSpoolWeight(e.id,n),T(n),C(!0),c?.(),setTimeout(()=>C(!1),3e3)}catch(e){console.error(`Failed to sync weight:`,e)}finally{b(!1)}};return(0,j.jsxs)(`div`,{className:`flex flex-col items-center space-y-4 max-w-md ${h??``}`,children:[(0,j.jsxs)(`div`,{className:`flex items-start gap-5`,children:[(0,j.jsxs)(`div`,{className:`relative shrink-0`,children:[(0,j.jsx)(k,{color:O,isEmpty:!1,size:100,spool:e}),B!==null&&(0,j.jsxs)(`div`,{className:`absolute -bottom-2 -right-2 px-2 py-0.5 rounded-full text-xs font-bold text-white shadow-lg`,style:{backgroundColor:V},children:[B,`%`]})]}),(0,j.jsxs)(`div`,{className:`flex-1 min-w-0 pt-1`,children:[(0,j.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,j.jsx)(`h3`,{className:`text-lg font-semibold text-zinc-100`,children:M||g(`spoolbuddy.spool.unknownColor`)}),(0,j.jsxs)(`span`,{className:`text-xs font-mono text-zinc-500 shrink-0`,children:[`#`,e.id]})]}),(0,j.jsxs)(`p`,{className:`text-sm text-zinc-400`,children:[e.brand,` • `,e.material,e.subtype&&` ${e.subtype}`]}),(0,j.jsxs)(`div`,{className:`mt-3`,children:[(0,j.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,j.jsxs)(`span`,{className:`text-3xl font-bold font-mono text-zinc-100`,children:[R,`g`]}),(0,j.jsxs)(`span`,{className:`text-sm text-zinc-500`,children:[`/ `,z,`g`]})]}),(0,j.jsx)(`p`,{className:`text-xs text-zinc-500 mt-0.5`,children:g(`spoolbuddy.spool.remaining`,`Remaining`)}),(0,j.jsx)(`div`,{className:`mt-2 max-w-xs`,children:(0,j.jsx)(`div`,{className:`h-2 bg-zinc-700 rounded-full overflow-hidden`,children:(0,j.jsx)(`div`,{className:`h-full rounded-full transition-all duration-500`,style:{width:`${B??0}%`,backgroundColor:V}})})})]})]})]}),(0,j.jsxs)(`div`,{className:`grid grid-cols-2 gap-x-6 gap-y-2 text-sm bg-zinc-800 rounded-lg p-4 w-full`,children:[(0,j.jsxs)(`div`,{className:`flex justify-between`,children:[(0,j.jsx)(`span`,{className:`text-zinc-500`,children:g(`spoolbuddy.dashboard.grossWeight`,`Gross weight`)}),(0,j.jsxs)(`span`,{className:`font-mono text-zinc-300`,children:[G,`g`]})]}),(0,j.jsxs)(`div`,{className:`flex justify-between`,children:[(0,j.jsx)(`span`,{className:`text-zinc-500`,children:g(`spoolbuddy.spool.coreWeight`,`Core`)}),(0,j.jsxs)(`span`,{className:`font-mono text-zinc-300`,children:[P,`g`]})]}),(0,j.jsxs)(`div`,{className:`flex justify-between`,children:[(0,j.jsx)(`span`,{className:`text-zinc-500`,children:g(`spoolbuddy.dashboard.spoolSize`,`Spool size`)}),(0,j.jsxs)(`span`,{className:`font-mono text-zinc-300`,children:[z,`g`]})]}),(0,j.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,j.jsx)(`span`,{className:`text-zinc-500`,children:g(`spoolbuddy.spool.scaleWeight`,`Scale`)}),F===null?(0,j.jsx)(`span`,{className:`text-zinc-500`,children:`—`}):(0,j.jsxs)(`span`,{className:`flex items-center gap-1 font-mono ${W?`text-green-500`:`text-yellow-500`}`,children:[F,`g`,W?(0,j.jsx)(l,{className:`w-3.5 h-3.5`}):(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(p,{className:`w-3.5 h-3.5`}),(0,j.jsx)(`button`,{onClick:X,className:`p-1 hover:bg-green-500/20 rounded transition-colors text-green-500`,title:g(`spoolbuddy.dashboard.syncWeight`,`Sync Weight`),children:(0,j.jsx)(v,{className:`w-4 h-4`})})]})]})]}),(0,j.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,j.jsx)(`span`,{className:`text-zinc-500`,children:g(`spoolbuddy.dashboard.tagId`,`Tag`)}),(0,j.jsx)(`span`,{className:`font-mono text-xs text-zinc-400 truncate max-w-[120px]`,title:e.tag_uid||``,children:e.tag_uid?e.tag_uid.slice(-8):`—`})]}),K&&(0,j.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,j.jsx)(`span`,{className:`text-zinc-500`,children:g(`spoolbuddy.inventory.nozzleTemp`,`Nozzle`)}),(0,j.jsx)(`span`,{className:`font-mono text-zinc-300`,children:K})]}),e.cost_per_kg!=null&&e.cost_per_kg>0&&(0,j.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,j.jsx)(`span`,{className:`text-zinc-500`,children:g(`spoolbuddy.inventory.costPerKg`,`Cost/kg`)}),(0,j.jsxs)(`span`,{className:`font-mono text-zinc-300`,children:[e.cost_per_kg.toFixed(2),`/kg`]})]}),Y&&(0,j.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,j.jsx)(`span`,{className:`text-zinc-500`,children:g(`spoolbuddy.inventory.kProfiles`,`K-Profile`)}),(0,j.jsx)(`span`,{className:`font-mono text-zinc-300 truncate max-w-[220px] text-right`,title:Y,children:Y})]}),q&&(0,j.jsxs)(`div`,{className:`min-w-0`,children:[(0,j.jsx)(`p`,{className:`text-xs text-zinc-500 mb-1`,children:g(`spoolbuddy.inventory.slicerFilament`,`Slicer Filament`)}),(0,j.jsx)(`p`,{className:`text-sm text-zinc-300 whitespace-pre-wrap break-words`,children:q})]}),J&&(0,j.jsxs)(`div`,{className:`col-span-2`,children:[(0,j.jsx)(`p`,{className:`text-xs text-zinc-500 mb-1`,children:g(`spoolbuddy.inventory.note`,`Note`)}),(0,j.jsx)(`p`,{className:`text-sm leading-5 text-zinc-300 whitespace-pre-wrap break-words max-h-[3.75rem] overflow-y-auto pr-1`,children:J})]})]}),(0,j.jsxs)(`div`,{className:`flex gap-2 justify-center`,children:[u&&(0,j.jsx)(`button`,{onClick:d?void 0:u,disabled:!!d,className:`px-5 py-2.5 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 transition-colors min-h-[44px] disabled:opacity-50 disabled:cursor-not-allowed`,children:g(`spoolbuddy.modal.assignToAms`,`Assign to AMS`)}),f&&(0,j.jsxs)(`button`,{onClick:f,className:`px-5 py-2.5 rounded-lg text-sm font-medium bg-red-600/20 text-red-400 hover:bg-red-600/30 transition-colors min-h-[44px]`,children:[(0,j.jsx)(m,{className:`w-4 h-4 inline mr-1`}),g(`inventory.unassignSpool`)]}),(0,j.jsx)(`button`,{onClick:X,disabled:t===null||_,className:`px-5 py-2.5 rounded-lg text-sm font-medium transition-colors min-h-[44px] ${x?`bg-green-600/20 text-green-400`:u?`bg-zinc-700 text-zinc-300 hover:bg-zinc-600 disabled:opacity-40 disabled:cursor-not-allowed`:`bg-green-600 text-white hover:bg-green-700 disabled:opacity-40 disabled:cursor-not-allowed`}`,children:_?`...`:x?g(`spoolbuddy.dashboard.weightSynced`,`Synced!`):g(`spoolbuddy.dashboard.syncWeight`,`Sync Weight`)}),o&&(0,j.jsx)(`button`,{onClick:o,className:`px-5 py-2.5 rounded-lg text-sm font-medium bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors min-h-[44px]`,children:g(`spoolbuddy.dashboard.close`,`Close`)})]})]})}function F(e){return S(e.rgba)}function I(e){return Math.max(0,e.label_weight-e.weight_used)}function L(e){return e.label_weight<=0?0:Math.max(0,Math.min(100,(e.label_weight-e.weight_used)/e.label_weight*100))}function R(e){let t=[e.material];return e.subtype&&t.push(e.subtype),t.join(` `)}function z(e){let t=e.ams_id===254||e.ams_id===255,n=!t&&e.ams_id>=128;return g(e.ams_id,e.tray_id,n,t)}function B({color:e,spool:t,size:n=56}){return w(t)?(0,j.jsxs)(`div`,{className:`relative shrink-0`,style:{width:n,height:n},children:[(0,j.jsx)(D,{spool:t,size:n,inset:2/56}),(0,j.jsx)(O,{inset:8/56}),(0,j.jsxs)(`svg`,{className:`absolute inset-0`,width:n,height:n,viewBox:`0 0 56 56`,children:[(0,j.jsx)(`ellipse`,{cx:`20`,cy:`20`,rx:`6`,ry:`4`,fill:`white`,opacity:`0.3`}),(0,j.jsx)(`circle`,{cx:`28`,cy:`28`,r:`8`,fill:`#2d2d2d`}),(0,j.jsx)(`circle`,{cx:`28`,cy:`28`,r:`5`,fill:`#1a1a1a`})]})]}):(0,j.jsxs)(`svg`,{width:n,height:n,viewBox:`0 0 56 56`,children:[(0,j.jsx)(`circle`,{cx:`28`,cy:`28`,r:`26`,fill:e}),(0,j.jsx)(`circle`,{cx:`28`,cy:`28`,r:`20`,fill:e,style:{filter:`brightness(0.85)`}}),(0,j.jsx)(`ellipse`,{cx:`20`,cy:`20`,rx:`6`,ry:`4`,fill:`white`,opacity:`0.3`}),(0,j.jsx)(`circle`,{cx:`28`,cy:`28`,r:`8`,fill:`#2d2d2d`}),(0,j.jsx)(`circle`,{cx:`28`,cy:`28`,r:`5`,fill:`#1a1a1a`})]})}function V(){let{sbState:e,selectedPrinterId:t}=_(),{t:n}=a(),i=x(),{showToast:l}=u(),p=o(),[m,g]=(0,A.useState)(``),[v,y]=(0,A.useState)(`all`),[b,S]=(0,A.useState)(null),[C,w]=(0,A.useState)(!1),{data:D}=s({queryKey:[`spoolman-settings`],queryFn:r.getSpoolmanSettings,staleTime:300*1e3}),O=D?.spoolman_enabled===`true`&&!!D?.spoolman_url,{data:k=[],isLoading:M,refetch:N}=s({queryKey:O?[`spoolman-inventory-spools`]:[`inventory-spools`],queryFn:()=>O?r.getSpoolmanInventorySpools(!1):r.getSpools(!1),enabled:D!==void 0,refetchInterval:3e4}),{data:P=[]}=s({queryKey:[`spool-assignments`],queryFn:()=>r.getAssignments(),refetchInterval:3e4,enabled:!O}),{data:F=[]}=s({queryKey:[`spoolman-slot-assignments`],queryFn:()=>r.getSpoolmanSlotAssignments(),refetchInterval:3e4,enabled:O}),I=c({mutationFn:e=>r.unassignSpoolmanSlot(e),onSuccess:()=>{p.invalidateQueries({queryKey:[`spoolman-slot-assignments`]}),p.invalidateQueries({queryKey:[`spoolman-inventory-spools`]})},onError:()=>l(n(`inventory.unassignFailed`,`Failed to unassign spool`),`error`)}),L=(0,A.useMemo)(()=>{if(O){let e={};return F.forEach(t=>{e[t.spoolman_spool_id]={ams_id:t.ams_id,tray_id:t.tray_id}}),e}let e={};return P.forEach(t=>{e[t.spool_id]={ams_id:t.ams_id,tray_id:t.tray_id,printer_name:t.printer_name}}),e},[O,P,F]),R=(0,A.useMemo)(()=>k.filter(e=>!e.archived_at),[k]),z=(0,A.useMemo)(()=>new Set(Object.keys(L).map(Number)),[L]),B=(0,A.useMemo)(()=>R.filter(e=>z.has(e.id)).length,[R,z]),V=(0,A.useMemo)(()=>{let e=new Set;return R.forEach(t=>e.add(t.material)),Array.from(e).sort()},[R]),G=(0,A.useMemo)(()=>{let e=R;return v===`in_ams`?e=e.filter(e=>z.has(e.id)):v!==`all`&&(e=e.filter(e=>e.material===v)),e=E(e,m.trim()),[...e].sort((e,t)=>{let n=+!z.has(e.id),r=+!z.has(t.id);return n===r?new Date(t.updated_at).getTime()-new Date(e.updated_at).getTime():n-r})},[R,v,m,z,i]);return(0,j.jsxs)(`div`,{className:`h-full flex flex-col`,children:[(0,j.jsxs)(`div`,{className:`px-3 pt-3 pb-2 space-y-2.5`,children:[(0,j.jsxs)(`div`,{className:`relative`,children:[(0,j.jsx)(f,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-white/40`}),(0,j.jsx)(`input`,{type:`text`,value:m,onChange:e=>g(e.target.value),placeholder:n(`spoolbuddy.inventory.searchPlaceholder`,`Search spools...`),className:`w-full pl-9 pr-8 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-sm text-white placeholder-white/30 focus:outline-none focus:border-bambu-green`}),m&&(0,j.jsx)(`button`,{onClick:()=>g(``),className:`absolute right-2 top-1/2 -translate-y-1/2 text-white/40 hover:text-white/60`,children:(0,j.jsx)(h,{className:`w-4 h-4`})})]}),(0,j.jsxs)(`div`,{className:`flex gap-1.5 overflow-x-auto no-scrollbar`,children:[(0,j.jsx)(H,{active:v===`all`,onClick:()=>y(`all`),label:`${n(`spoolbuddy.inventory.all`,`All`)} (${R.length})`,green:!0}),B>0&&(0,j.jsx)(H,{active:v===`in_ams`,onClick:()=>y(`in_ams`),label:`${n(`spoolbuddy.inventory.inAms`,`In AMS`)} (${B})`}),V.map(e=>(0,j.jsx)(H,{active:v===e,onClick:()=>y(v===e?`all`:e),label:e},e))]})]}),(0,j.jsx)(`div`,{className:`flex-1 overflow-y-auto px-3 pb-3`,children:M?(0,j.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,j.jsx)(`div`,{className:`w-8 h-8 border-2 border-bambu-green border-t-transparent rounded-full animate-spin`})}):G.length===0?(0,j.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-16 text-white/30`,children:[(0,j.jsx)(d,{className:`w-12 h-12 mb-3`}),(0,j.jsx)(`p`,{className:`text-sm`,children:m||v!==`all`?n(`spoolbuddy.inventory.noResults`,`No spools match your filters`):n(`spoolbuddy.inventory.empty`,`No spools in inventory`)})]}):(0,j.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(130px,1fr))] gap-2`,children:G.map(e=>(0,j.jsx)(U,{spool:e,assignment:L[e.id],onClick:()=>S(e.id)},e.id))})}),b!=null&&(()=>{let n=k.find(e=>e.id===b);return n?(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(W,{spool:n,assignment:L[n.id],sbState:e,onSyncWeight:()=>{N()},onAssignToAms:()=>w(!0),onUnassignFromAms:O&&L[n.id]?()=>I.mutate(n.id):void 0,onClose:()=>{S(null),w(!1)}}),(0,j.jsx)(T,{isOpen:C,onClose:()=>w(!1),spool:n,printerId:t,variant:`kiosk`,spoolmanMode:O})]}):null})()]})}function H({active:e,onClick:t,label:n,green:r}){return(0,j.jsx)(`button`,{onClick:t,className:`px-4 py-1.5 rounded-full text-sm font-medium border whitespace-nowrap shrink-0 transition-colors ${e?r?`bg-bambu-green/20 text-bambu-green border-bambu-green/50`:`bg-white/10 text-white border-white/20`:`bg-transparent text-white/40 border-bambu-dark-tertiary hover:text-white/60`}`,children:n})}function U({spool:e,assignment:t,onClick:n}){let r=F(e),i=L(e),a=I(e),o=y(e.color_name,e.rgba,e.color_name_is_synthesized);return(0,j.jsxs)(`button`,{onClick:n,className:`bg-bambu-dark-secondary rounded-xl p-3 flex flex-col items-center text-center gap-1.5 border border-transparent hover:border-bambu-green/50 transition-colors`,children:[(0,j.jsx)(B,{color:r,spool:e,size:56}),(0,j.jsx)(`p`,{className:`text-xs font-semibold text-white leading-tight truncate w-full`,children:R(e)}),(0,j.jsxs)(`div`,{className:`flex items-center gap-1 min-w-0 max-w-full`,children:[(0,j.jsx)(`span`,{className:`w-2.5 h-2.5 rounded-full shrink-0 border border-white/10`,style:C(e)??b(e.rgba)}),(0,j.jsx)(`span`,{className:`text-[11px] text-white/50 truncate`,children:o||`-`})]}),(0,j.jsxs)(`div`,{className:`w-full space-y-0.5`,children:[(0,j.jsx)(`div`,{className:`h-1.5 bg-bambu-dark-tertiary rounded-full overflow-hidden`,children:(0,j.jsx)(`div`,{className:`h-full rounded-full ${i>50?`bg-bambu-green`:i>20?`bg-yellow-500`:`bg-red-500`}`,style:{width:`${Math.min(i,100)}%`}})}),(0,j.jsxs)(`p`,{className:`text-[11px] text-white/40`,children:[Math.round(a),`g (`,Math.round(i),`%)`]})]}),t&&(0,j.jsx)(`span`,{className:`px-2 py-0.5 rounded text-[10px] font-bold bg-bambu-green/20 text-bambu-green`,children:z(t)})]})}function W({spool:e,assignment:t,sbState:n,onSyncWeight:r,onAssignToAms:i,onUnassignFromAms:a,onClose:o}){let s=n.deviceOnline&&n.weight!==null?Math.round(n.weight):null,c=e.last_scale_weight==null?null:Math.round(e.last_scale_weight);return(0,j.jsx)(`div`,{className:`fixed inset-0 z-50 bg-black/70 flex items-center justify-center p-4`,onClick:o,children:(0,j.jsx)(`div`,{className:`w-full max-w-md bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-2xl p-4 overflow-y-auto max-h-[90vh]`,onClick:e=>e.stopPropagation(),children:(0,j.jsxs)(`div`,{className:`space-y-3`,children:[t&&(0,j.jsxs)(`div`,{className:`flex items-center justify-center gap-2`,children:[(0,j.jsx)(`span`,{className:`px-2.5 py-1 rounded-md text-xs font-bold bg-bambu-green/20 text-bambu-green`,children:z(t)}),t.printer_name&&(0,j.jsx)(`span`,{className:`text-xs text-zinc-400`,children:t.printer_name})]}),(0,j.jsx)(`div`,{className:`flex justify-center`,children:(0,j.jsx)(P,{spool:e,liveScaleWeight:s,persistedGrossWeight:c,onSyncWeight:r,onAssignToAms:i,isAssigned:!!t,onUnassignFromAms:a,onClose:o,className:`max-w-md`})})]})})})}export{V as SpoolBuddyInventoryPage}; \ No newline at end of file +import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,v as i,w as a}from"./client-DnySrlFv.js";import{n as o}from"./QueryClientProvider-Ce8_sN3w.js";import{t as s}from"./useQuery-BBCjCezC.js";import{t as c}from"./useMutation-B-Tr2hIP.js";import{t as l}from"./check-Ck0cMLU4.js";import{n as u}from"./ToastContext-BRX0SW3C.js";import{t as d}from"./package-BGUevlqS.js";import{t as f}from"./search-0n0CBc74.js";import{t as p}from"./triangle-alert-Dt_1FcBy.js";import{t as m}from"./unlink-C098nwOf.js";import{t as h}from"./x-DR-Trv6U.js";import{H as g,Hn as _,Kt as v,ft as y,lt as b,ot as x,pt as S}from"./index-Cxa-KVmA.js";import{n as C,t as w}from"./spoolPaint-CrvpHqdD.js";import{t as T}from"./AssignToAmsModal-dWQ_DHhy.js";import{t as E}from"./inventorySearch-TJiB5tGt.js";import{n as D,r as O,t as k}from"./SpoolIcon-DE8TbEec.js";var A=e(n(),1),j=t(),M=`spoolbuddy-default-core-weight`;function N(){try{let e=localStorage.getItem(M);if(e){let t=parseInt(e,10);if(t>=0&&t<=500)return t}}catch{}return 250}function P({spool:e,liveScaleWeight:t,persistedGrossWeight:n,onClose:o,onSyncWeight:c,onAssignToAms:u,isAssigned:d,onUnassignFromAms:f,className:h}){let{t:g}=a(),[_,b]=(0,A.useState)(!1),[x,C]=(0,A.useState)(!1),[w,T]=(0,A.useState)(null),{data:E}=s({queryKey:[`spool-k-profiles`,e.id],queryFn:()=>r.getSpoolKProfiles(e.id),enabled:!e.k_profiles||e.k_profiles.length===0,staleTime:300*1e3}),D=e.k_profiles&&e.k_profiles.length>0?e.k_profiles:E,O=S(e.rgba),M=y(e.color_name,e.rgba,e.color_name_is_synthesized),P=e.core_weight&&e.core_weight>0?e.core_weight:N(),F=t===null?null:Math.round(Math.max(0,t)),I=w??(n===void 0?F:n===null?null:Math.round(Math.max(0,n))),L=Math.round(Math.max(0,(e.label_weight||0)-(e.weight_used||0))),R=F!==null&&F>=10?Math.round(Math.max(0,F-P)):L,z=Math.round(e.label_weight||1e3),B=z>0?Math.min(100,Math.round(R/z*100)):null,V=B===null?`#808080`:B>50?`#22c55e`:B>20?`#eab308`:`#ef4444`,H=Math.max(0,(e.label_weight||0)-(e.weight_used||0))+P,U=F===null?null:F-H,W=U===null?null:Math.abs(U)<=50,G=I??Math.round(H),K=e.nozzle_temp_min!=null&&e.nozzle_temp_max!=null?`${e.nozzle_temp_min}-${e.nozzle_temp_max}\u00B0C`:null,q=e.slicer_filament_name||e.slicer_filament||null,J=e.note?.trim()||null,Y=D&&D.length>0?Array.from(new Set(D.map(e=>e.k_value.toFixed(3)))).join(`, `):null,X=async()=>{if(t===null)return;let n=Math.round(Math.max(0,t));b(!0);try{await i.updateSpoolWeight(e.id,n),T(n),C(!0),c?.(),setTimeout(()=>C(!1),3e3)}catch(e){console.error(`Failed to sync weight:`,e)}finally{b(!1)}};return(0,j.jsxs)(`div`,{className:`flex flex-col items-center space-y-4 max-w-md ${h??``}`,children:[(0,j.jsxs)(`div`,{className:`flex items-start gap-5`,children:[(0,j.jsxs)(`div`,{className:`relative shrink-0`,children:[(0,j.jsx)(k,{color:O,isEmpty:!1,size:100,spool:e}),B!==null&&(0,j.jsxs)(`div`,{className:`absolute -bottom-2 -right-2 px-2 py-0.5 rounded-full text-xs font-bold text-white shadow-lg`,style:{backgroundColor:V},children:[B,`%`]})]}),(0,j.jsxs)(`div`,{className:`flex-1 min-w-0 pt-1`,children:[(0,j.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,j.jsx)(`h3`,{className:`text-lg font-semibold text-zinc-100`,children:M||g(`spoolbuddy.spool.unknownColor`)}),(0,j.jsxs)(`span`,{className:`text-xs font-mono text-zinc-500 shrink-0`,children:[`#`,e.id]})]}),(0,j.jsxs)(`p`,{className:`text-sm text-zinc-400`,children:[e.brand,` • `,e.material,e.subtype&&` ${e.subtype}`]}),(0,j.jsxs)(`div`,{className:`mt-3`,children:[(0,j.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,j.jsxs)(`span`,{className:`text-3xl font-bold font-mono text-zinc-100`,children:[R,`g`]}),(0,j.jsxs)(`span`,{className:`text-sm text-zinc-500`,children:[`/ `,z,`g`]})]}),(0,j.jsx)(`p`,{className:`text-xs text-zinc-500 mt-0.5`,children:g(`spoolbuddy.spool.remaining`,`Remaining`)}),(0,j.jsx)(`div`,{className:`mt-2 max-w-xs`,children:(0,j.jsx)(`div`,{className:`h-2 bg-zinc-700 rounded-full overflow-hidden`,children:(0,j.jsx)(`div`,{className:`h-full rounded-full transition-all duration-500`,style:{width:`${B??0}%`,backgroundColor:V}})})})]})]})]}),(0,j.jsxs)(`div`,{className:`grid grid-cols-2 gap-x-6 gap-y-2 text-sm bg-zinc-800 rounded-lg p-4 w-full`,children:[(0,j.jsxs)(`div`,{className:`flex justify-between`,children:[(0,j.jsx)(`span`,{className:`text-zinc-500`,children:g(`spoolbuddy.dashboard.grossWeight`,`Gross weight`)}),(0,j.jsxs)(`span`,{className:`font-mono text-zinc-300`,children:[G,`g`]})]}),(0,j.jsxs)(`div`,{className:`flex justify-between`,children:[(0,j.jsx)(`span`,{className:`text-zinc-500`,children:g(`spoolbuddy.spool.coreWeight`,`Core`)}),(0,j.jsxs)(`span`,{className:`font-mono text-zinc-300`,children:[P,`g`]})]}),(0,j.jsxs)(`div`,{className:`flex justify-between`,children:[(0,j.jsx)(`span`,{className:`text-zinc-500`,children:g(`spoolbuddy.dashboard.spoolSize`,`Spool size`)}),(0,j.jsxs)(`span`,{className:`font-mono text-zinc-300`,children:[z,`g`]})]}),(0,j.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,j.jsx)(`span`,{className:`text-zinc-500`,children:g(`spoolbuddy.spool.scaleWeight`,`Scale`)}),F===null?(0,j.jsx)(`span`,{className:`text-zinc-500`,children:`—`}):(0,j.jsxs)(`span`,{className:`flex items-center gap-1 font-mono ${W?`text-green-500`:`text-yellow-500`}`,children:[F,`g`,W?(0,j.jsx)(l,{className:`w-3.5 h-3.5`}):(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(p,{className:`w-3.5 h-3.5`}),(0,j.jsx)(`button`,{onClick:X,className:`p-1 hover:bg-green-500/20 rounded transition-colors text-green-500`,title:g(`spoolbuddy.dashboard.syncWeight`,`Sync Weight`),children:(0,j.jsx)(v,{className:`w-4 h-4`})})]})]})]}),(0,j.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,j.jsx)(`span`,{className:`text-zinc-500`,children:g(`spoolbuddy.dashboard.tagId`,`Tag`)}),(0,j.jsx)(`span`,{className:`font-mono text-xs text-zinc-400 truncate max-w-[120px]`,title:e.tag_uid||``,children:e.tag_uid?e.tag_uid.slice(-8):`—`})]}),K&&(0,j.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,j.jsx)(`span`,{className:`text-zinc-500`,children:g(`spoolbuddy.inventory.nozzleTemp`,`Nozzle`)}),(0,j.jsx)(`span`,{className:`font-mono text-zinc-300`,children:K})]}),e.cost_per_kg!=null&&e.cost_per_kg>0&&(0,j.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,j.jsx)(`span`,{className:`text-zinc-500`,children:g(`spoolbuddy.inventory.costPerKg`,`Cost/kg`)}),(0,j.jsxs)(`span`,{className:`font-mono text-zinc-300`,children:[e.cost_per_kg.toFixed(2),`/kg`]})]}),Y&&(0,j.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,j.jsx)(`span`,{className:`text-zinc-500`,children:g(`spoolbuddy.inventory.kProfiles`,`K-Profile`)}),(0,j.jsx)(`span`,{className:`font-mono text-zinc-300 truncate max-w-[220px] text-right`,title:Y,children:Y})]}),q&&(0,j.jsxs)(`div`,{className:`min-w-0`,children:[(0,j.jsx)(`p`,{className:`text-xs text-zinc-500 mb-1`,children:g(`spoolbuddy.inventory.slicerFilament`,`Slicer Filament`)}),(0,j.jsx)(`p`,{className:`text-sm text-zinc-300 whitespace-pre-wrap break-words`,children:q})]}),J&&(0,j.jsxs)(`div`,{className:`col-span-2`,children:[(0,j.jsx)(`p`,{className:`text-xs text-zinc-500 mb-1`,children:g(`spoolbuddy.inventory.note`,`Note`)}),(0,j.jsx)(`p`,{className:`text-sm leading-5 text-zinc-300 whitespace-pre-wrap break-words max-h-[3.75rem] overflow-y-auto pr-1`,children:J})]})]}),(0,j.jsxs)(`div`,{className:`flex gap-2 justify-center`,children:[u&&(0,j.jsx)(`button`,{onClick:d?void 0:u,disabled:!!d,className:`px-5 py-2.5 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 transition-colors min-h-[44px] disabled:opacity-50 disabled:cursor-not-allowed`,children:g(`spoolbuddy.modal.assignToAms`,`Assign to AMS`)}),f&&(0,j.jsxs)(`button`,{onClick:f,className:`px-5 py-2.5 rounded-lg text-sm font-medium bg-red-600/20 text-red-400 hover:bg-red-600/30 transition-colors min-h-[44px]`,children:[(0,j.jsx)(m,{className:`w-4 h-4 inline mr-1`}),g(`inventory.unassignSpool`)]}),(0,j.jsx)(`button`,{onClick:X,disabled:t===null||_,className:`px-5 py-2.5 rounded-lg text-sm font-medium transition-colors min-h-[44px] ${x?`bg-green-600/20 text-green-400`:u?`bg-zinc-700 text-zinc-300 hover:bg-zinc-600 disabled:opacity-40 disabled:cursor-not-allowed`:`bg-green-600 text-white hover:bg-green-700 disabled:opacity-40 disabled:cursor-not-allowed`}`,children:_?`...`:x?g(`spoolbuddy.dashboard.weightSynced`,`Synced!`):g(`spoolbuddy.dashboard.syncWeight`,`Sync Weight`)}),o&&(0,j.jsx)(`button`,{onClick:o,className:`px-5 py-2.5 rounded-lg text-sm font-medium bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors min-h-[44px]`,children:g(`spoolbuddy.dashboard.close`,`Close`)})]})]})}function F(e){return S(e.rgba)}function I(e){return Math.max(0,e.label_weight-e.weight_used)}function L(e){return e.label_weight<=0?0:Math.max(0,Math.min(100,(e.label_weight-e.weight_used)/e.label_weight*100))}function R(e){let t=[e.material];return e.subtype&&t.push(e.subtype),t.join(` `)}function z(e){let t=e.ams_id===254||e.ams_id===255,n=!t&&e.ams_id>=128;return g(e.ams_id,e.tray_id,n,t)}function B({color:e,spool:t,size:n=56}){return w(t)?(0,j.jsxs)(`div`,{className:`relative shrink-0`,style:{width:n,height:n},children:[(0,j.jsx)(D,{spool:t,size:n,inset:2/56}),(0,j.jsx)(O,{inset:8/56}),(0,j.jsxs)(`svg`,{className:`absolute inset-0`,width:n,height:n,viewBox:`0 0 56 56`,children:[(0,j.jsx)(`ellipse`,{cx:`20`,cy:`20`,rx:`6`,ry:`4`,fill:`white`,opacity:`0.3`}),(0,j.jsx)(`circle`,{cx:`28`,cy:`28`,r:`8`,fill:`#2d2d2d`}),(0,j.jsx)(`circle`,{cx:`28`,cy:`28`,r:`5`,fill:`#1a1a1a`})]})]}):(0,j.jsxs)(`svg`,{width:n,height:n,viewBox:`0 0 56 56`,children:[(0,j.jsx)(`circle`,{cx:`28`,cy:`28`,r:`26`,fill:e}),(0,j.jsx)(`circle`,{cx:`28`,cy:`28`,r:`20`,fill:e,style:{filter:`brightness(0.85)`}}),(0,j.jsx)(`ellipse`,{cx:`20`,cy:`20`,rx:`6`,ry:`4`,fill:`white`,opacity:`0.3`}),(0,j.jsx)(`circle`,{cx:`28`,cy:`28`,r:`8`,fill:`#2d2d2d`}),(0,j.jsx)(`circle`,{cx:`28`,cy:`28`,r:`5`,fill:`#1a1a1a`})]})}function V(){let{sbState:e,selectedPrinterId:t}=_(),{t:n}=a(),i=x(),{showToast:l}=u(),p=o(),[m,g]=(0,A.useState)(``),[v,y]=(0,A.useState)(`all`),[b,S]=(0,A.useState)(null),[C,w]=(0,A.useState)(!1),{data:D}=s({queryKey:[`spoolman-settings`],queryFn:r.getSpoolmanSettings,staleTime:300*1e3}),O=D?.spoolman_enabled===`true`&&!!D?.spoolman_url,{data:k=[],isLoading:M,refetch:N}=s({queryKey:O?[`spoolman-inventory-spools`]:[`inventory-spools`],queryFn:()=>O?r.getSpoolmanInventorySpools(!1):r.getSpools(!1),enabled:D!==void 0,refetchInterval:3e4}),{data:P=[]}=s({queryKey:[`spool-assignments`],queryFn:()=>r.getAssignments(),refetchInterval:3e4,enabled:!O}),{data:F=[]}=s({queryKey:[`spoolman-slot-assignments`],queryFn:()=>r.getSpoolmanSlotAssignments(),refetchInterval:3e4,enabled:O}),I=c({mutationFn:e=>r.unassignSpoolmanSlot(e),onSuccess:()=>{p.invalidateQueries({queryKey:[`spoolman-slot-assignments`]}),p.invalidateQueries({queryKey:[`spoolman-inventory-spools`]})},onError:()=>l(n(`inventory.unassignFailed`,`Failed to unassign spool`),`error`)}),L=(0,A.useMemo)(()=>{if(O){let e={};return F.forEach(t=>{e[t.spoolman_spool_id]={ams_id:t.ams_id,tray_id:t.tray_id}}),e}let e={};return P.forEach(t=>{e[t.spool_id]={ams_id:t.ams_id,tray_id:t.tray_id,printer_name:t.printer_name}}),e},[O,P,F]),R=(0,A.useMemo)(()=>k.filter(e=>!e.archived_at),[k]),z=(0,A.useMemo)(()=>new Set(Object.keys(L).map(Number)),[L]),B=(0,A.useMemo)(()=>R.filter(e=>z.has(e.id)).length,[R,z]),V=(0,A.useMemo)(()=>{let e=new Set;return R.forEach(t=>e.add(t.material)),Array.from(e).sort()},[R]),G=(0,A.useMemo)(()=>{let e=R;return v===`in_ams`?e=e.filter(e=>z.has(e.id)):v!==`all`&&(e=e.filter(e=>e.material===v)),e=E(e,m.trim()),[...e].sort((e,t)=>{let n=+!z.has(e.id),r=+!z.has(t.id);return n===r?new Date(t.updated_at).getTime()-new Date(e.updated_at).getTime():n-r})},[R,v,m,z,i]);return(0,j.jsxs)(`div`,{className:`h-full flex flex-col`,children:[(0,j.jsxs)(`div`,{className:`px-3 pt-3 pb-2 space-y-2.5`,children:[(0,j.jsxs)(`div`,{className:`relative`,children:[(0,j.jsx)(f,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-white/40`}),(0,j.jsx)(`input`,{type:`text`,value:m,onChange:e=>g(e.target.value),placeholder:n(`spoolbuddy.inventory.searchPlaceholder`,`Search spools...`),className:`w-full pl-9 pr-8 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-sm text-white placeholder-white/30 focus:outline-none focus:border-bambu-green`}),m&&(0,j.jsx)(`button`,{onClick:()=>g(``),className:`absolute right-2 top-1/2 -translate-y-1/2 text-white/40 hover:text-white/60`,children:(0,j.jsx)(h,{className:`w-4 h-4`})})]}),(0,j.jsxs)(`div`,{className:`flex gap-1.5 overflow-x-auto no-scrollbar`,children:[(0,j.jsx)(H,{active:v===`all`,onClick:()=>y(`all`),label:`${n(`spoolbuddy.inventory.all`,`All`)} (${R.length})`,green:!0}),B>0&&(0,j.jsx)(H,{active:v===`in_ams`,onClick:()=>y(`in_ams`),label:`${n(`spoolbuddy.inventory.inAms`,`In AMS`)} (${B})`}),V.map(e=>(0,j.jsx)(H,{active:v===e,onClick:()=>y(v===e?`all`:e),label:e},e))]})]}),(0,j.jsx)(`div`,{className:`flex-1 overflow-y-auto px-3 pb-3`,children:M?(0,j.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,j.jsx)(`div`,{className:`w-8 h-8 border-2 border-bambu-green border-t-transparent rounded-full animate-spin`})}):G.length===0?(0,j.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-16 text-white/30`,children:[(0,j.jsx)(d,{className:`w-12 h-12 mb-3`}),(0,j.jsx)(`p`,{className:`text-sm`,children:m||v!==`all`?n(`spoolbuddy.inventory.noResults`,`No spools match your filters`):n(`spoolbuddy.inventory.empty`,`No spools in inventory`)})]}):(0,j.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(130px,1fr))] gap-2`,children:G.map(e=>(0,j.jsx)(U,{spool:e,assignment:L[e.id],onClick:()=>S(e.id)},e.id))})}),b!=null&&(()=>{let n=k.find(e=>e.id===b);return n?(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(W,{spool:n,assignment:L[n.id],sbState:e,onSyncWeight:()=>{N()},onAssignToAms:()=>w(!0),onUnassignFromAms:O&&L[n.id]?()=>I.mutate(n.id):void 0,onClose:()=>{S(null),w(!1)}}),(0,j.jsx)(T,{isOpen:C,onClose:()=>w(!1),spool:n,printerId:t,variant:`kiosk`,spoolmanMode:O})]}):null})()]})}function H({active:e,onClick:t,label:n,green:r}){return(0,j.jsx)(`button`,{onClick:t,className:`px-4 py-1.5 rounded-full text-sm font-medium border whitespace-nowrap shrink-0 transition-colors ${e?r?`bg-bambu-green/20 text-bambu-green border-bambu-green/50`:`bg-white/10 text-white border-white/20`:`bg-transparent text-white/40 border-bambu-dark-tertiary hover:text-white/60`}`,children:n})}function U({spool:e,assignment:t,onClick:n}){let r=F(e),i=L(e),a=I(e),o=y(e.color_name,e.rgba,e.color_name_is_synthesized);return(0,j.jsxs)(`button`,{onClick:n,className:`bg-bambu-dark-secondary rounded-xl p-3 flex flex-col items-center text-center gap-1.5 border border-transparent hover:border-bambu-green/50 transition-colors`,children:[(0,j.jsx)(B,{color:r,spool:e,size:56}),(0,j.jsx)(`p`,{className:`text-xs font-semibold text-white leading-tight truncate w-full`,children:R(e)}),(0,j.jsxs)(`div`,{className:`flex items-center gap-1 min-w-0 max-w-full`,children:[(0,j.jsx)(`span`,{className:`w-2.5 h-2.5 rounded-full shrink-0 border border-white/10`,style:C(e)??b(e.rgba)}),(0,j.jsx)(`span`,{className:`text-[11px] text-white/50 truncate`,children:o||`-`})]}),(0,j.jsxs)(`div`,{className:`w-full space-y-0.5`,children:[(0,j.jsx)(`div`,{className:`h-1.5 bg-bambu-dark-tertiary rounded-full overflow-hidden`,children:(0,j.jsx)(`div`,{className:`h-full rounded-full ${i>50?`bg-bambu-green`:i>20?`bg-yellow-500`:`bg-red-500`}`,style:{width:`${Math.min(i,100)}%`}})}),(0,j.jsxs)(`p`,{className:`text-[11px] text-white/40`,children:[Math.round(a),`g (`,Math.round(i),`%)`]})]}),t&&(0,j.jsx)(`span`,{className:`px-2 py-0.5 rounded text-[10px] font-bold bg-bambu-green/20 text-bambu-green`,children:z(t)})]})}function W({spool:e,assignment:t,sbState:n,onSyncWeight:r,onAssignToAms:i,onUnassignFromAms:a,onClose:o}){let s=n.deviceOnline&&n.weight!==null?Math.round(n.weight):null,c=e.last_scale_weight==null?null:Math.round(e.last_scale_weight);return(0,j.jsx)(`div`,{className:`fixed inset-0 z-50 bg-black/70 flex items-center justify-center p-4`,onClick:o,children:(0,j.jsx)(`div`,{className:`w-full max-w-md bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-2xl p-4 overflow-y-auto max-h-[90vh]`,onClick:e=>e.stopPropagation(),children:(0,j.jsxs)(`div`,{className:`space-y-3`,children:[t&&(0,j.jsxs)(`div`,{className:`flex items-center justify-center gap-2`,children:[(0,j.jsx)(`span`,{className:`px-2.5 py-1 rounded-md text-xs font-bold bg-bambu-green/20 text-bambu-green`,children:z(t)}),t.printer_name&&(0,j.jsx)(`span`,{className:`text-xs text-zinc-400`,children:t.printer_name})]}),(0,j.jsx)(`div`,{className:`flex justify-center`,children:(0,j.jsx)(P,{spool:e,liveScaleWeight:s,persistedGrossWeight:c,onSyncWeight:r,onAssignToAms:i,isAssigned:!!t,onUnassignFromAms:a,onClose:o,className:`max-w-md`})})]})})})}export{V as SpoolBuddyInventoryPage}; \ No newline at end of file diff --git a/static/assets/SpoolBuddySettingsPage-FUv2PkN1.js b/static/assets/SpoolBuddySettingsPage-dHNHNIW3.js similarity index 99% rename from static/assets/SpoolBuddySettingsPage-FUv2PkN1.js rename to static/assets/SpoolBuddySettingsPage-dHNHNIW3.js index 1f2fdeffc..5d7fc632a 100644 --- a/static/assets/SpoolBuddySettingsPage-FUv2PkN1.js +++ b/static/assets/SpoolBuddySettingsPage-dHNHNIW3.js @@ -1,2 +1,2 @@ -import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,v as r,w as i}from"./client-DnySrlFv.js";import{n as a}from"./QueryClientProvider-Ce8_sN3w.js";import{t as o}from"./useQuery-BBCjCezC.js";import{t as s}from"./play-DIDYtk2S.js";import{t as c}from"./x-DR-Trv6U.js";import{v as l}from"./date-G9KUauqz.js";import{Hn as u,Tt as d,Wt as f,bt as p,xn as m}from"./index-0t--Yqoi.js";var h=e(n(),1),g=t();function _({type:e,deviceId:t,onClose:n}){let{t:a}=i(),[o,l]=(0,h.useState)(!1),[u,d]=(0,h.useState)(``),[p,m]=(0,h.useState)(``),[_,v]=(0,h.useState)(!1);(0,h.useEffect)(()=>{let e=e=>{e.key===`Escape`&&!o&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[o,n]);let y=(0,h.useCallback)(async()=>{l(!0),d(``),m(``),v(!0);try{d(a(`spoolbuddy.diagnostic.queuing`,`Queuing diagnostic on device... +import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,v as r,w as i}from"./client-DnySrlFv.js";import{n as a}from"./QueryClientProvider-Ce8_sN3w.js";import{t as o}from"./useQuery-BBCjCezC.js";import{t as s}from"./play-DIDYtk2S.js";import{t as c}from"./x-DR-Trv6U.js";import{v as l}from"./date-G9KUauqz.js";import{Hn as u,Tt as d,Wt as f,bt as p,xn as m}from"./index-Cxa-KVmA.js";var h=e(n(),1),g=t();function _({type:e,deviceId:t,onClose:n}){let{t:a}=i(),[o,l]=(0,h.useState)(!1),[u,d]=(0,h.useState)(``),[p,m]=(0,h.useState)(``),[_,v]=(0,h.useState)(!1);(0,h.useEffect)(()=>{let e=e=>{e.key===`Escape`&&!o&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[o,n]);let y=(0,h.useCallback)(async()=>{l(!0),d(``),m(``),v(!0);try{d(a(`spoolbuddy.diagnostic.queuing`,`Queuing diagnostic on device... `)),await r.queueDiagnostics(t,e);let n=null,i=0;for(;i<60&&!n;){await new Promise(e=>setTimeout(e,500));try{n=await r.getDiagnosticResult(t,e);break}catch{i++,i%4==0&&d(e=>e+`.`)}}if(!n)throw Error(`Diagnostic timed out - device did not report results`);d(n.output),n.success||m(`Exit code: ${n.exit_code}`)}catch(e){m(e instanceof Error?e.message:`Unknown error`),d(``)}finally{l(!1)}},[e,t,a]);return(0,g.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/70 animate-fade-in`,onClick:n,children:(0,g.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg shadow-xl w-full max-w-2xl mx-4 max-h-[80vh] flex flex-col animate-slide-up`,onClick:e=>e.stopPropagation(),children:[(0,g.jsxs)(`div`,{className:`flex justify-between items-center p-4 border-b border-zinc-700`,children:[(0,g.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e===`scale`?a(`spoolbuddy.diagnostic.scaleTitle`,`Scale Diagnostic`):e===`read_tag`?a(`spoolbuddy.diagnostic.readTagTitle`,`Read Tag Diagnostic`):a(`spoolbuddy.diagnostic.nfcTitle`,`NFC Reader Diagnostic`)}),(0,g.jsx)(`button`,{onClick:n,className:`text-zinc-400 hover:text-white transition-colors`,"aria-label":`Close`,children:(0,g.jsx)(c,{size:20})})]}),(0,g.jsx)(`div`,{className:`flex-1 overflow-auto p-4 bg-black/50 font-mono text-sm`,children:o?(0,g.jsxs)(`div`,{className:`flex items-center gap-2 text-green-400`,children:[(0,g.jsx)(`div`,{className:`animate-spin w-4 h-4 border-2 border-green-400 border-t-transparent rounded-full`}),(0,g.jsx)(`span`,{children:a(`spoolbuddy.diagnostic.running`,`Running diagnostic on device...`)})]}):u?(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(`div`,{className:`text-green-400 whitespace-pre-wrap break-words`,children:u}),p&&(0,g.jsxs)(`div`,{className:`text-red-400 mt-2`,children:[`❌ `,p]})]}):_?(0,g.jsx)(`div`,{children:p?(0,g.jsxs)(`div`,{className:`text-red-400`,children:[`ERROR: `,p]}):(0,g.jsx)(`span`,{className:`text-green-400`,children:a(`spoolbuddy.diagnostic.completed`,`Diagnostic completed successfully.`)})}):(0,g.jsxs)(`div`,{className:`text-zinc-500`,children:[a(`spoolbuddy.diagnostic.clickStart`,`Click "Run Diagnostic" to start the hardware diagnostic on`),` `,t,`.`]})}),(0,g.jsxs)(`div`,{className:`flex gap-2 p-4 border-t border-zinc-700 bg-zinc-800`,children:[(0,g.jsx)(`button`,{onClick:y,disabled:o,className:`flex-1 flex items-center justify-center gap-2 bg-green-600 hover:bg-green-700 disabled:bg-gray-600 disabled:cursor-not-allowed px-4 py-2 rounded font-semibold text-white transition-colors`,children:o?(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(`div`,{className:`animate-spin w-4 h-4 border-2 border-white border-t-transparent rounded-full`}),a(`spoolbuddy.diagnostic.runningBtn`,`Running...`)]}):_?(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(f,{size:16}),a(`spoolbuddy.diagnostic.runAgain`,`Run Again`)]}):(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(s,{size:16}),a(`spoolbuddy.diagnostic.runBtn`,`Run Diagnostic`)]})}),(0,g.jsx)(`button`,{onClick:n,className:`px-4 py-2 rounded bg-zinc-700 hover:bg-zinc-600 text-white font-semibold transition-colors`,children:a(`spoolbuddy.diagnostic.close`,`Close`)})]})]})})}function v(e){return e<60?`${e}s`:e<3600?`${Math.floor(e/60)}m`:`${Math.floor(e/3600)}h ${Math.floor(e%3600/60)}m`}function y(e){if(!e)return`-`;let t=l(e);return t?t.toLocaleDateString(void 0,{month:`short`,day:`numeric`})+` `+t.toLocaleTimeString(void 0,{hour:`2-digit`,minute:`2-digit`}):`-`}var b=[{label:`Off`,value:0},{label:`1m`,value:60},{label:`2m`,value:120},{label:`5m`,value:300},{label:`10m`,value:600},{label:`30m`,value:1800}];function x({device:e}){let{t}=i(),[n,a]=(0,h.useState)(null),[o,s]=(0,h.useState)(``),[c,l]=(0,h.useState)(``),[u,f]=(0,h.useState)(!1),[y,b]=(0,h.useState)(null);return(0,h.useEffect)(()=>{!o&&e.backend_url&&s(e.backend_url)},[e.backend_url,o]),(0,g.jsxs)(`div`,{className:`space-y-2`,children:[(0,g.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,g.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-3`,children:[(0,g.jsx)(`h3`,{className:`text-sm font-semibold text-zinc-300 mb-2`,children:t(`spoolbuddy.settings.nfcReader`,`NFC Reader`)}),(0,g.jsxs)(`div`,{className:`space-y-1.5 text-xs`,children:[(0,g.jsxs)(`div`,{className:`flex justify-between`,children:[(0,g.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.type`,`Type`)}),(0,g.jsx)(`span`,{className:`text-zinc-300 font-mono`,children:e.nfc_reader_type||`N/A`})]}),(0,g.jsxs)(`div`,{className:`flex justify-between`,children:[(0,g.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.connection`,`Connection`)}),(0,g.jsx)(`span`,{className:`text-zinc-300 font-mono`,children:e.nfc_connection||`N/A`})]}),(0,g.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,g.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.status.status`,`Status`)}),(0,g.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,g.jsx)(`div`,{className:`w-2 h-2 rounded-full ${e.nfc_ok?`bg-green-500`:e.nfc_reader_type?`bg-red-500`:`bg-zinc-600`}`}),(0,g.jsx)(`span`,{className:e.nfc_ok?`text-green-400`:e.nfc_reader_type?`text-red-400`:`text-zinc-500`,children:e.nfc_ok?t(`spoolbuddy.status.nfcReady`,`Ready`):e.nfc_reader_type?t(`common.error`,`Error`):t(`spoolbuddy.settings.notConnected`,`N/A`)})]})]})]})]}),(0,g.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-3`,children:[(0,g.jsx)(`h3`,{className:`text-sm font-semibold text-zinc-300 mb-2`,children:t(`spoolbuddy.settings.deviceInfo`,`Device Info`)}),(0,g.jsxs)(`div`,{className:`space-y-1.5 text-xs`,children:[(0,g.jsxs)(`div`,{className:`flex justify-between`,children:[(0,g.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.hostname`,`Host`)}),(0,g.jsx)(`span`,{className:`text-zinc-300 truncate ml-2`,children:e.hostname})]}),(0,g.jsxs)(`div`,{className:`flex justify-between`,children:[(0,g.jsx)(`span`,{className:`text-zinc-500`,children:`IP`}),(0,g.jsx)(`span`,{className:`text-zinc-300`,children:e.ip_address})]}),(0,g.jsxs)(`div`,{className:`flex justify-between`,children:[(0,g.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.uptime`,`Uptime`)}),(0,g.jsx)(`span`,{className:`text-zinc-300`,children:v(e.uptime_s)})]}),(0,g.jsxs)(`div`,{className:`flex justify-between`,children:[(0,g.jsx)(`span`,{className:`text-zinc-500`,children:`ID`}),(0,g.jsx)(`span`,{className:`text-zinc-400 font-mono truncate ml-2`,children:e.device_id})]})]})]})]}),(0,g.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,g.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-3 space-y-2`,children:[(0,g.jsx)(`h3`,{className:`text-sm font-semibold text-zinc-300`,children:t(`spoolbuddy.settings.systemConfig`,`Backend & Auth`)}),(0,g.jsx)(`input`,{value:o,onChange:e=>s(e.target.value),placeholder:`http://192.168.1.100:5000`,className:`w-full px-2 py-1.5 rounded bg-zinc-900 border border-zinc-700 text-zinc-100 text-xs`}),(0,g.jsxs)(`div`,{className:`flex gap-2`,children:[(0,g.jsx)(`input`,{type:`password`,value:c,onChange:e=>l(e.target.value),placeholder:t(`spoolbuddy.settings.apiTokenPlaceholder`,`API token`),className:`flex-1 px-2 py-1.5 rounded bg-zinc-900 border border-zinc-700 text-zinc-100 text-xs`}),(0,g.jsx)(`button`,{onClick:async()=>{if(!o.trim()){b({type:`error`,text:t(`spoolbuddy.settings.systemFieldsRequired`,`Backend URL is required.`)});return}f(!0),b(null);try{await r.updateSystemConfig(e.device_id,o.trim(),c.trim()||void 0),b({type:`ok`,text:t(`spoolbuddy.settings.systemQueued`,`Config queued.`)})}catch(e){b({type:`error`,text:e instanceof Error?e.message:t(`common.error`,`Error`)})}finally{f(!1)}},disabled:u,className:`px-3 py-1.5 rounded bg-green-700 hover:bg-green-600 disabled:bg-zinc-700 text-xs font-medium text-zinc-100`,children:t(`spoolbuddy.settings.saveConfig`,`Save`)})]}),y&&(0,g.jsx)(`div`,{className:`text-xs ${y.type===`ok`?`text-green-400`:`text-red-400`}`,children:y.text})]}),(0,g.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-3 flex flex-col gap-2`,children:[(0,g.jsxs)(`button`,{onClick:()=>a(`nfc`),className:`flex-1 bg-blue-700 hover:bg-blue-600 transition-colors rounded-lg p-2 flex items-center gap-2`,children:[(0,g.jsx)(d,{className:`w-4 h-4 text-blue-300 shrink-0`}),(0,g.jsx)(`span`,{className:`text-xs font-medium text-blue-100`,children:t(`spoolbuddy.settings.nfcDiagnostic`,`NFC Diagnostic`)})]}),(0,g.jsxs)(`button`,{onClick:()=>a(`scale`),className:`flex-1 bg-yellow-700 hover:bg-yellow-600 transition-colors rounded-lg p-2 flex items-center gap-2`,children:[(0,g.jsx)(p,{className:`w-4 h-4 text-yellow-300 shrink-0`}),(0,g.jsx)(`span`,{className:`text-xs font-medium text-yellow-100`,children:t(`spoolbuddy.settings.scaleDiagnostic`,`Scale Diagnostic`)})]}),(0,g.jsxs)(`button`,{onClick:()=>a(`read_tag`),className:`flex-1 bg-emerald-700 hover:bg-emerald-600 transition-colors rounded-lg p-2 flex items-center gap-2`,children:[(0,g.jsx)(m,{className:`w-4 h-4 text-emerald-300 shrink-0`}),(0,g.jsx)(`span`,{className:`text-xs font-medium text-emerald-100`,children:t(`spoolbuddy.settings.readTagDiagnostic`,`Read Tag`)})]})]})]}),n&&e&&(0,g.jsx)(_,{type:n,deviceId:e.device_id,onClose:()=>a(null)})]})}function S({device:e,onBrightnessChange:t}){let{t:n}=i(),[a,o]=(0,h.useState)(e.display_brightness),[s,c]=(0,h.useState)(e.display_blank_timeout),[l,u]=(0,h.useState)(!1),d=(0,h.useRef)(void 0),f=(0,h.useRef)(void 0);(0,h.useEffect)(()=>{o(e.display_brightness),c(e.display_blank_timeout)},[e.display_brightness,e.display_blank_timeout]);let p=(0,h.useCallback)(()=>{u(!0),f.current&&clearTimeout(f.current),f.current=setTimeout(()=>u(!1),1500)},[]),m=(0,h.useCallback)((t,n)=>{d.current&&clearTimeout(d.current),d.current=setTimeout(()=>{r.updateDisplay(e.device_id,t,n).then(()=>p()).catch(e=>console.error(`Failed to update display:`,e))},300)},[e.device_id,p]),_=e=>{o(e),t(e),m(e,s)},v=e=>{c(e),m(a,e)};return(0,g.jsxs)(`div`,{className:`space-y-4`,children:[(0,g.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-4`,children:[(0,g.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,g.jsx)(`h3`,{className:`text-sm font-semibold text-zinc-300`,children:n(`spoolbuddy.settings.brightness`,`Brightness`)}),l&&(0,g.jsxs)(`span`,{className:`text-xs text-green-400 flex items-center gap-1 animate-pulse`,children:[(0,g.jsx)(`svg`,{className:`w-3 h-3`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:3,children:(0,g.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M5 13l4 4L19 7`})}),n(`spoolbuddy.settings.saved`,`Saved`)]})]}),(0,g.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,g.jsx)(`svg`,{className:`w-4 h-4 text-zinc-500 flex-shrink-0`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:2,children:(0,g.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M12 3v1m0 16v1m9-9h-1M4 12H3m15.364 6.364l-.707-.707M6.343 6.343l-.707-.707m12.728 0l-.707.707M6.343 17.657l-.707.707M16 12a4 4 0 11-8 0 4 4 0 018 0z`})}),(0,g.jsx)(`input`,{type:`range`,min:0,max:100,value:a,onChange:e=>_(parseInt(e.target.value)),className:`flex-1 h-2 bg-zinc-700 rounded-lg appearance-none cursor-pointer accent-green-500`}),(0,g.jsxs)(`span`,{className:`text-sm font-mono text-zinc-400 w-10 text-right`,children:[a,`%`]})]}),!e.has_backlight&&(0,g.jsx)(`p`,{className:`text-xs text-zinc-600 mt-2`,children:n(`spoolbuddy.settings.noBacklight`,`No DSI backlight detected. Brightness control requires a DSI display.`)})]}),(0,g.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-4`,children:[(0,g.jsx)(`h3`,{className:`text-sm font-semibold text-zinc-300 mb-1`,children:n(`spoolbuddy.settings.screenBlank`,`Screen Blank Timeout`)}),(0,g.jsx)(`p`,{className:`text-xs text-zinc-500 mb-3`,children:n(`spoolbuddy.settings.screenBlankDesc`,`Screen turns off after inactivity. Touch to wake.`)}),(0,g.jsx)(`div`,{className:`grid grid-cols-3 gap-2`,children:b.map(e=>(0,g.jsx)(`button`,{onClick:()=>v(e.value),className:`px-3 py-2 rounded-lg text-sm font-medium transition-colors min-h-[40px] ${s===e.value?`bg-green-600 text-white`:`bg-zinc-700 text-zinc-300 hover:bg-zinc-600`}`,children:e.label},e.value))})]}),(0,g.jsx)(`p`,{className:`text-xs text-zinc-600 text-center`,children:n(`spoolbuddy.settings.displayNote`,`Brightness is applied as a software filter.`)})]})}function C({step:e,labels:t}){return(0,g.jsxs)(`div`,{className:`flex flex-col items-center w-16 shrink-0 pt-1`,children:[(0,g.jsx)(`div`,{className:`flex items-center justify-center w-7 h-7 rounded-full text-xs font-bold ${e===`tare`?`bg-green-600 text-white`:`bg-green-600/20 text-green-400`}`,children:e===`weight`?(0,g.jsx)(`svg`,{className:`w-3.5 h-3.5`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:3,children:(0,g.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M5 13l4 4L19 7`})}):`1`}),(0,g.jsx)(`span`,{className:`text-[10px] mt-0.5 ${e===`tare`?`text-green-400 font-medium`:`text-green-400/60`}`,children:t.tare}),(0,g.jsx)(`div`,{className:`w-px h-5 my-1 ${e===`weight`?`bg-green-600/40`:`bg-zinc-700`}`}),(0,g.jsx)(`div`,{className:`flex items-center justify-center w-7 h-7 rounded-full text-xs font-bold ${e===`weight`?`bg-green-600 text-white`:`bg-zinc-700 text-zinc-500`}`,children:`2`}),(0,g.jsx)(`span`,{className:`text-[10px] mt-0.5 ${e===`weight`?`text-green-400 font-medium`:`text-zinc-600`}`,children:t.weight})]})}function w({device:e,weight:t,weightStable:n,rawAdc:o}){let{t:s}=i(),c=a(),[l,u]=(0,h.useState)(`idle`),[d,f]=(0,h.useState)(`500`),[p,m]=(0,h.useState)(null),[_,v]=(0,h.useState)(!1),[b,x]=(0,h.useState)(null),[S,w]=(0,h.useState)(null),T=(0,h.useRef)(null);(0,h.useEffect)(()=>()=>{T.current&&clearTimeout(T.current)},[]);let E=(0,h.useCallback)(e=>{T.current&&clearTimeout(T.current),T.current=setTimeout(()=>x(null),e)},[]);(0,h.useEffect)(()=>{if(!S)return;let e=()=>Date.now()-S.startedAtMs,t=setInterval(()=>{c.invalidateQueries({queryKey:[`spoolbuddy-devices`]})},1e3),n=setTimeout(()=>{w(null),x({type:`error`,msg:s(`spoolbuddy.settings.tareTimedOut`,`Tare timed out — is the SpoolBuddy daemon running?`)}),E(5e3)},Math.max(0,15e3-e()));return()=>{clearInterval(t),clearTimeout(n)}},[S,c,s,E]),(0,h.useEffect)(()=>{S&&(e?.last_calibrated_at??null)!==S.snapshot&&(w(null),x({type:`ok`,msg:s(`spoolbuddy.settings.tareComplete`,`Tare complete!`)}),E(3e3))},[e?.last_calibrated_at,S,s,E]);let D=e=>{e===`backspace`?f(e=>e.slice(0,-1)||``):e===`.`&&!d.includes(`.`)?f(e=>e+`.`):e>=`0`&&e<=`9`&&f(t=>t===`0`?e:t+e)};return l===`idle`?(0,g.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,g.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-3 mb-3`,children:[(0,g.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,g.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,g.jsx)(`div`,{className:`w-2 h-2 rounded-full ${n?`bg-green-500`:`bg-amber-500 animate-pulse`}`}),(0,g.jsx)(`span`,{className:`text-lg font-mono text-zinc-200`,children:t===null?`-- g`:`${t.toFixed(1)} g`})]}),(0,g.jsxs)(`div`,{className:`text-xs text-zinc-500 text-right`,children:[(0,g.jsxs)(`span`,{children:[s(`spoolbuddy.settings.tareOffset`,`Tare`),`: `,e.tare_offset]}),(0,g.jsx)(`span`,{className:`mx-1.5`,children:`·`}),(0,g.jsxs)(`span`,{children:[s(`spoolbuddy.settings.calFactor`,`Factor`),`: `,e.calibration_factor.toFixed(2)]})]})]}),e.last_calibrated_at&&(0,g.jsxs)(`div`,{className:`text-xs text-zinc-600 mt-1`,children:[s(`spoolbuddy.settings.lastCalibrated`,`Last calibrated`),`: `,y(e.last_calibrated_at)]})]}),b&&(0,g.jsx)(`div`,{className:`rounded-lg px-3 py-2 mb-3 text-sm ${b.type===`ok`?`bg-green-900/30 text-green-300 border border-green-800`:`bg-red-900/30 text-red-300 border border-red-800`}`,children:b.msg}),(0,g.jsxs)(`div`,{className:`flex gap-2`,children:[(0,g.jsxs)(`button`,{onClick:async()=>{v(!0),x(null),T.current&&=(clearTimeout(T.current),null);let t=e?.last_calibrated_at??null;try{await r.tare(e.device_id),x({type:`ok`,msg:s(`spoolbuddy.settings.tareSet`,`Tare command sent. Waiting for device...`)}),w({snapshot:t,startedAtMs:Date.now()})}catch{x({type:`error`,msg:s(`spoolbuddy.settings.tareFailed`,`Failed to send tare command`)}),E(5e3)}finally{v(!1)}},disabled:_,className:`flex-1 px-4 py-2.5 rounded-lg text-sm font-medium bg-zinc-700 text-zinc-200 hover:bg-zinc-600 disabled:opacity-40 transition-colors min-h-[44px] flex items-center justify-center gap-2`,children:[_&&(0,g.jsxs)(`svg`,{className:`w-4 h-4 animate-spin`,viewBox:`0 0 24 24`,fill:`none`,children:[(0,g.jsx)(`circle`,{className:`opacity-25`,cx:`12`,cy:`12`,r:`10`,stroke:`currentColor`,strokeWidth:`4`}),(0,g.jsx)(`path`,{className:`opacity-75`,fill:`currentColor`,d:`M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z`})]}),s(`spoolbuddy.weight.tare`,`Tare`)]}),(0,g.jsx)(`button`,{onClick:()=>{u(`tare`),x(null)},className:`flex-1 px-4 py-2.5 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 transition-colors min-h-[44px]`,children:s(`spoolbuddy.weight.calibrate`,`Calibrate`)})]})]}):(0,g.jsxs)(`div`,{className:`flex gap-3`,children:[(0,g.jsx)(C,{step:l,labels:{tare:s(`spoolbuddy.weight.tare`,`Tare`),weight:s(`spoolbuddy.settings.knownWeight`,`Known weight`)}}),(0,g.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,g.jsxs)(`div`,{className:`flex items-center gap-2 bg-zinc-800 rounded-lg px-3 py-1.5 mb-1.5`,children:[(0,g.jsx)(`div`,{className:`w-2 h-2 rounded-full shrink-0 ${n?`bg-green-500`:`bg-amber-500 animate-pulse`}`}),(0,g.jsx)(`span`,{className:`text-sm font-mono text-zinc-200`,children:t===null?`-- g`:`${t.toFixed(1)} g`}),(0,g.jsx)(`span`,{className:`text-xs ml-auto ${n?`text-green-400`:`text-amber-400`}`,children:n?s(`spoolbuddy.settings.stable`,`Stable`):s(`spoolbuddy.settings.settling`,`Settling...`)})]}),b&&(0,g.jsx)(`div`,{className:`rounded-lg px-3 py-1.5 mb-1.5 text-xs ${b.type===`ok`?`bg-green-900/30 text-green-300 border border-green-800`:`bg-red-900/30 text-red-300 border border-red-800`}`,children:b.msg}),l===`tare`?(0,g.jsx)(`p`,{className:`text-sm text-zinc-300 mb-3`,children:s(`spoolbuddy.settings.calStep1`,`Remove all items from the scale and press Set Zero.`)}):(0,g.jsxs)(g.Fragment,{children:[(0,g.jsxs)(`div`,{className:`flex items-center gap-2 mb-1.5`,children:[(0,g.jsx)(`span`,{className:`text-xs text-zinc-400 shrink-0`,children:s(`spoolbuddy.settings.knownWeight`,`Known weight`)}),(0,g.jsxs)(`div`,{className:`flex-1 bg-zinc-900 border border-zinc-600 rounded px-3 py-1 text-right text-lg font-mono text-zinc-100`,children:[d||`0`,(0,g.jsx)(`span`,{className:`text-zinc-500 ml-1`,children:`g`})]})]}),(0,g.jsx)(`div`,{className:`grid grid-cols-4 gap-1 mb-1.5`,children:[`7`,`8`,`9`,`backspace`,`4`,`5`,`6`,`.`,`1`,`2`,`3`,`0`].map(e=>(0,g.jsx)(`button`,{onClick:()=>D(e),className:`rounded text-lg font-medium transition-colors h-[48px] active:scale-95 ${e===`backspace`?`bg-zinc-700 text-zinc-300 hover:bg-zinc-600`:`bg-zinc-800 text-zinc-100 hover:bg-zinc-700 border border-zinc-700`}`,children:e===`backspace`?`⌫`:e},e))})]}),(0,g.jsxs)(`div`,{className:`flex gap-2`,children:[(0,g.jsx)(`button`,{onClick:()=>{u(`idle`),x(null)},className:`flex-1 px-4 py-2 rounded-lg text-sm bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors h-[40px]`,children:s(`common.cancel`,`Cancel`)}),(0,g.jsxs)(`button`,{onClick:async()=>{if(l===`tare`){v(!0),x(null);try{m(o),await r.tare(e.device_id),x({type:`ok`,msg:s(`spoolbuddy.settings.zeroSet`,`Zero point set. Place known weight on scale.`)}),u(`weight`)}catch{x({type:`error`,msg:s(`spoolbuddy.settings.tareFailed`,`Failed to send tare command`)})}finally{v(!1)}}else if(l===`weight`){let t=parseFloat(d);if(o===null||!t||t<=0)return;v(!0),x(null);try{await r.setCalibrationFactor(e.device_id,t,o,p??void 0),x({type:`ok`,msg:s(`spoolbuddy.settings.calibrationDone`,`Calibration complete!`)}),E(3e3),u(`idle`)}catch{x({type:`error`,msg:s(`spoolbuddy.settings.calibrationFailed`,`Calibration failed`)}),E(5e3)}finally{v(!1)}}},disabled:_,className:`flex-1 px-4 py-2 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 disabled:opacity-40 transition-colors h-[40px] flex items-center justify-center gap-2`,children:[_&&(0,g.jsxs)(`svg`,{className:`w-4 h-4 animate-spin`,viewBox:`0 0 24 24`,fill:`none`,children:[(0,g.jsx)(`circle`,{className:`opacity-25`,cx:`12`,cy:`12`,r:`10`,stroke:`currentColor`,strokeWidth:`4`}),(0,g.jsx)(`path`,{className:`opacity-75`,fill:`currentColor`,d:`M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z`})]}),l===`tare`?s(`spoolbuddy.settings.setZero`,`Set Zero`):s(`spoolbuddy.settings.calibrateNow`,`Calibrate`)]})]})]})]})}function T({device:e}){let{t}=i(),[n,a]=(0,h.useState)(null),[s,c]=(0,h.useState)(null),[l,u]=(0,h.useState)(!1),[d,f]=(0,h.useState)(!1),p=e.update_status===`pending`||e.update_status===`updating`;(0,h.useEffect)(()=>{p&&n===`applying`&&a(null)},[p,n]),(0,h.useEffect)(()=>{let e=()=>{p&&setTimeout(()=>window.location.reload(),1e3)};return window.addEventListener(`spoolbuddy-online`,e),()=>window.removeEventListener(`spoolbuddy-online`,e)},[p]);let{data:m,refetch:_}=o({queryKey:[`spoolbuddy-update-check`,e.device_id],queryFn:()=>r.checkDaemonUpdate(e.device_id),staleTime:0}),{data:v}=o({queryKey:[`spoolbuddy-ssh-key`],queryFn:()=>r.getSSHPublicKey(),enabled:l,staleTime:1/0}),y=async()=>{a(`checking`),c(null);try{await _()}finally{a(null)}},b=async()=>{a(`applying`),c(null);try{await r.triggerUpdate(e.device_id)}catch(e){c(e instanceof Error?e.message:`Failed to trigger update`),a(null)}},x=n!=null||p,S=()=>{v?.public_key&&(navigator.clipboard.writeText(v.public_key),f(!0),setTimeout(()=>f(!1),2e3))},C=e.firmware_version||(m?.current_version&&m.current_version!==`0.0.0`?m.current_version:null);return(0,g.jsxs)(`div`,{className:`space-y-3`,children:[(0,g.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-3 space-y-3`,children:[(0,g.jsxs)(`div`,{className:`flex justify-between items-center text-sm`,children:[(0,g.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.currentVersion`,`Current Version`)}),(0,g.jsx)(`span`,{className:`text-zinc-200 font-mono`,children:C||(0,g.jsx)(`span`,{className:`text-zinc-500 italic text-xs`,children:t(`spoolbuddy.settings.versionPending`,`Waiting for daemon...`)})})]}),x?(0,g.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,g.jsxs)(`svg`,{className:`w-4 h-4 animate-spin text-green-400 flex-shrink-0`,viewBox:`0 0 24 24`,fill:`none`,children:[(0,g.jsx)(`circle`,{className:`opacity-25`,cx:`12`,cy:`12`,r:`10`,stroke:`currentColor`,strokeWidth:`4`}),(0,g.jsx)(`path`,{className:`opacity-75`,fill:`currentColor`,d:`M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z`})]}),(0,g.jsx)(`span`,{className:`text-green-300 text-xs`,children:n===`checking`?t(`spoolbuddy.settings.checking`,`Checking for updates...`):e.update_message||t(`spoolbuddy.settings.updateWaiting`,`Updating...`)})]}):e.update_status===`error`?(0,g.jsx)(`p`,{className:`text-xs text-red-300`,children:e.update_message||t(`spoolbuddy.settings.updateFailed`,`Update failed`)}):s?(0,g.jsx)(`p`,{className:`text-xs text-red-300`,children:s}):m?.update_available?(0,g.jsxs)(`p`,{className:`text-xs text-green-300`,children:[t(`spoolbuddy.settings.updateAvailable`,`Update available`),`: `,C,` → `,m.latest_version]}):null,!x&&(m?.update_available?(0,g.jsx)(`button`,{onClick:b,disabled:!e.online,className:`w-full px-3 py-2 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 disabled:opacity-40 transition-colors`,children:e.online?t(`spoolbuddy.settings.applyUpdate`,`Apply Update`):t(`spoolbuddy.settings.deviceOffline`,`Device Offline`)}):(0,g.jsxs)(`div`,{className:`flex gap-2`,children:[(0,g.jsx)(`button`,{onClick:y,className:`flex-1 px-3 py-2 rounded-lg text-xs font-medium bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors`,children:t(`spoolbuddy.settings.checkUpdates`,`Check for Updates`)}),(0,g.jsx)(`button`,{onClick:b,disabled:!e.online,className:`px-3 py-2 rounded-lg text-xs font-medium bg-zinc-700 text-zinc-400 hover:bg-zinc-600 hover:text-zinc-200 disabled:opacity-40 transition-colors`,children:t(`spoolbuddy.settings.forceUpdate`,`Force Update`)})]}))]}),(0,g.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-3`,children:[(0,g.jsxs)(`button`,{onClick:()=>u(!l),className:`w-full flex justify-between items-center text-xs`,children:[(0,g.jsx)(`span`,{className:`font-medium text-zinc-400`,children:t(`spoolbuddy.settings.sshSetup`,`SSH Setup`)}),(0,g.jsx)(`svg`,{className:`w-3 h-3 text-zinc-500 transition-transform ${l?`rotate-180`:``}`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:2,children:(0,g.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M19 9l-7 7-7-7`})})]}),l&&(0,g.jsxs)(`div`,{className:`mt-2 space-y-2`,children:[(0,g.jsx)(`p`,{className:`text-xs text-zinc-500`,children:t(`spoolbuddy.settings.sshDescription`,`SSH key is deployed automatically. For manual setup, add this key to ~/.ssh/authorized_keys on the device.`)}),v?.public_key?(0,g.jsxs)(`div`,{className:`relative`,children:[(0,g.jsx)(`pre`,{className:`bg-zinc-900 rounded p-2 text-[10px] text-zinc-400 font-mono break-all whitespace-pre-wrap`,children:v.public_key}),(0,g.jsx)(`button`,{onClick:S,className:`absolute top-1 right-1 px-1.5 py-0.5 rounded text-[10px] bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors`,children:d?t(`common.copied`,`Copied!`):t(`common.copy`,`Copy`)})]}):(0,g.jsx)(`span`,{className:`text-[10px] text-zinc-500 italic`,children:t(`spoolbuddy.settings.sshKeyLoading`,`Loading...`)})]})]})]})}function E({percent:e,color:t}){return(0,g.jsx)(`div`,{className:`w-full h-2 bg-zinc-700 rounded-full overflow-hidden`,children:(0,g.jsx)(`div`,{className:`h-full rounded-full transition-all ${t}`,style:{width:`${Math.min(100,Math.max(0,e))}%`}})})}function D(e){let t=Math.floor(e/86400),n=Math.floor(e%86400/3600),r=Math.floor(e%3600/60);return t>0?`${t}d ${n}h ${r}m`:n>0?`${n}h ${r}m`:`${r}m`}function O({device:e}){let{t}=i(),n=e.system_stats;if(!n)return(0,g.jsx)(`div`,{className:`flex items-center justify-center h-32`,children:(0,g.jsx)(`p`,{className:`text-sm text-zinc-500`,children:t(`spoolbuddy.settings.systemStatsWaiting`,`Waiting for system stats...`)})});let r=n.memory,a=n.disk,o=(n.cpu_temp_c??0)>=80?`text-red-400`:(n.cpu_temp_c??0)>=65?`text-amber-400`:`text-green-400`,s=(r?.percent??0)>=90?`bg-red-500`:(r?.percent??0)>=70?`bg-amber-500`:`bg-green-500`,c=(a?.percent??0)>=90?`bg-red-500`:(a?.percent??0)>=70?`bg-amber-500`:`bg-green-500`;return(0,g.jsxs)(`div`,{className:`space-y-2`,children:[(0,g.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,g.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-3`,children:[(0,g.jsx)(`h3`,{className:`text-sm font-semibold text-zinc-300 mb-2`,children:`CPU`}),(0,g.jsxs)(`div`,{className:`space-y-1.5 text-xs`,children:[(0,g.jsxs)(`div`,{className:`flex justify-between`,children:[(0,g.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.cores`,`Cores`)}),(0,g.jsx)(`span`,{className:`text-zinc-300 font-mono`,children:n.cpu_count??`-`})]}),(0,g.jsxs)(`div`,{className:`flex justify-between`,children:[(0,g.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.loadAvg`,`Load Avg`)}),(0,g.jsx)(`span`,{className:`text-zinc-300 font-mono`,children:n.load_avg?n.load_avg.join(` / `):`-`})]}),(0,g.jsxs)(`div`,{className:`flex justify-between`,children:[(0,g.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.temp`,`Temp`)}),(0,g.jsx)(`span`,{className:`font-mono font-medium ${o}`,children:n.cpu_temp_c==null?`-`:`${n.cpu_temp_c}\u00B0C`})]})]})]}),(0,g.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-3`,children:[(0,g.jsx)(`h3`,{className:`text-sm font-semibold text-zinc-300 mb-2`,children:t(`spoolbuddy.settings.memory`,`Memory`)}),r?(0,g.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,g.jsx)(E,{percent:r.percent??0,color:s}),(0,g.jsxs)(`div`,{className:`space-y-1 text-xs`,children:[(0,g.jsxs)(`div`,{className:`flex justify-between`,children:[(0,g.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.used`,`Used`)}),(0,g.jsxs)(`span`,{className:`text-zinc-300 font-mono`,children:[r.used_mb,` / `,r.total_mb,` MB`]})]}),(0,g.jsxs)(`div`,{className:`flex justify-between`,children:[(0,g.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.available`,`Free`)}),(0,g.jsxs)(`span`,{className:`text-zinc-300 font-mono`,children:[r.available_mb,` MB`]})]})]})]}):(0,g.jsx)(`span`,{className:`text-xs text-zinc-500`,children:`-`})]})]}),(0,g.jsx)(`div`,{className:`bg-zinc-800 rounded-lg px-3 py-2`,children:(0,g.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,g.jsx)(`h3`,{className:`text-sm font-semibold text-zinc-300 shrink-0`,children:t(`spoolbuddy.settings.disk`,`Disk`)}),a?(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(`div`,{className:`flex-1`,children:(0,g.jsx)(E,{percent:a.percent??0,color:c})}),(0,g.jsxs)(`span`,{className:`text-xs text-zinc-300 font-mono shrink-0`,children:[a.used_gb,` / `,a.total_gb,` GB`]})]}):(0,g.jsx)(`span`,{className:`text-xs text-zinc-500`,children:`-`})]})}),(0,g.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,g.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-3`,children:[(0,g.jsx)(`h3`,{className:`text-sm font-semibold text-zinc-300 mb-1.5`,children:t(`spoolbuddy.settings.osInfo`,`OS`)}),(0,g.jsxs)(`div`,{className:`space-y-1 text-xs`,children:[n.os?.os&&(0,g.jsxs)(`div`,{className:`flex justify-between`,children:[(0,g.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.distro`,`Distro`)}),(0,g.jsx)(`span`,{className:`text-zinc-300 truncate ml-2`,children:n.os.os})]}),n.os?.kernel&&(0,g.jsxs)(`div`,{className:`flex justify-between`,children:[(0,g.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.kernel`,`Kernel`)}),(0,g.jsx)(`span`,{className:`text-zinc-300 font-mono truncate ml-2`,children:n.os.kernel})]}),n.os?.arch&&(0,g.jsxs)(`div`,{className:`flex justify-between`,children:[(0,g.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.arch`,`Arch`)}),(0,g.jsx)(`span`,{className:`text-zinc-300 font-mono`,children:n.os.arch})]})]})]}),(0,g.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-3`,children:[(0,g.jsx)(`h3`,{className:`text-sm font-semibold text-zinc-300 mb-1.5`,children:t(`spoolbuddy.settings.runtime`,`Runtime`)}),(0,g.jsxs)(`div`,{className:`space-y-1 text-xs`,children:[n.os?.python&&(0,g.jsxs)(`div`,{className:`flex justify-between`,children:[(0,g.jsx)(`span`,{className:`text-zinc-500`,children:`Python`}),(0,g.jsx)(`span`,{className:`text-zinc-300 font-mono`,children:n.os.python})]}),n.system_uptime_s!=null&&(0,g.jsxs)(`div`,{className:`flex justify-between`,children:[(0,g.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.systemUptime`,`Uptime`)}),(0,g.jsx)(`span`,{className:`text-zinc-300`,children:D(n.system_uptime_s)})]})]})]})]})]})}function k(){let{sbState:e,setDisplayBrightness:t}=u(),{t:n}=i(),[a,s]=(0,h.useState)(`device`),{data:c=[]}=o({queryKey:[`spoolbuddy-devices`],queryFn:()=>r.getDevices(),refetchInterval:1e4}),l=e.deviceId?c.find(t=>t.device_id===e.deviceId)??c[0]:c[0],d=[{id:`device`,label:n(`spoolbuddy.settings.tabDevice`,`Device`)},{id:`display`,label:n(`spoolbuddy.settings.tabDisplay`,`Display`)},{id:`scale`,label:n(`spoolbuddy.settings.tabScale`,`Scale`)},{id:`updates`,label:n(`spoolbuddy.settings.tabUpdates`,`Updates`)},{id:`system`,label:n(`spoolbuddy.settings.tabSystem`,`System`)}];return(0,g.jsxs)(`div`,{className:`h-full flex flex-col p-4`,children:[(0,g.jsx)(`h1`,{className:`text-xl font-semibold text-zinc-100 mb-3`,children:n(`spoolbuddy.nav.settings`,`Settings`)}),(0,g.jsx)(`div`,{className:`flex gap-1 bg-zinc-800/50 rounded-lg p-1 mb-4`,children:d.map(e=>(0,g.jsx)(`button`,{onClick:()=>s(e.id),className:`flex-1 px-2 py-2 rounded-md text-sm font-medium transition-colors min-h-[36px] ${a===e.id?`bg-zinc-700 text-zinc-100`:`text-zinc-500 hover:text-zinc-300`}`,children:e.label},e.id))}),(0,g.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto`,children:l?(0,g.jsxs)(g.Fragment,{children:[a===`device`&&(0,g.jsx)(x,{device:l}),a===`display`&&(0,g.jsx)(S,{device:l,onBrightnessChange:t}),a===`scale`&&(0,g.jsx)(w,{device:l,weight:e.weight,weightStable:e.weightStable,rawAdc:e.rawAdc}),a===`updates`&&(0,g.jsx)(T,{device:l}),a===`system`&&(0,g.jsx)(O,{device:l})]}):(0,g.jsx)(`div`,{className:`flex items-center justify-center h-32`,children:(0,g.jsx)(`div`,{className:`text-center text-zinc-500`,children:(0,g.jsx)(`p`,{className:`text-sm`,children:n(`spoolbuddy.settings.noDevice`,`No SpoolBuddy device found`)})})})})]})}export{k as SpoolBuddySettingsPage}; \ No newline at end of file diff --git a/static/assets/SpoolBuddyWriteTagPage-DwfWgHhK.js b/static/assets/SpoolBuddyWriteTagPage-CQovcCoW.js similarity index 99% rename from static/assets/SpoolBuddyWriteTagPage-DwfWgHhK.js rename to static/assets/SpoolBuddyWriteTagPage-CQovcCoW.js index 1299774b3..141e30d50 100644 --- a/static/assets/SpoolBuddyWriteTagPage-DwfWgHhK.js +++ b/static/assets/SpoolBuddyWriteTagPage-CQovcCoW.js @@ -1 +1 @@ -import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,v as i,w as a}from"./client-DnySrlFv.js";import{t as o}from"./useQuery-BBCjCezC.js";import{a as s}from"./info-ROUoQhJR.js";import{n as c}from"./ToastContext-BRX0SW3C.js";import{t as l}from"./sparkles-DRqKNlhr.js";import{Hn as u,Mn as d,N as f,at as p,ft as m,lt as h,ot as g}from"./index-0t--Yqoi.js";import{n as _,o as v,r as y,s as ee,t as b}from"./AdditionalSection-BgleEt_Y.js";import{c as x,f as S,i as te,m as C,n as ne,o as w,r as T,s as re,t as E,u as D,v as O}from"./utils-DVekehs6.js";import{n as k}from"./spoolPaint-CrvpHqdD.js";var A=e(n(),1),j=t();function ie({formData:e,printersWithCalibrations:t,selectedProfiles:n,setSelectedProfiles:r,expandedPrinters:i,setExpandedPrinters:o}){let{t:c}=a(),u=e=>{o(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},f=(e,t,n)=>{let i=`${e}:${t}:${n??`null`}`,a=`${e}:${n??`null`}`;r(e=>{let t=new Set(e);if(t.has(i))t.delete(i);else{for(let e of Array.from(t)){let n=e.split(`:`);`${n[0]}:${n[2]}`===a&&t.delete(e)}t.add(i)}return t})},p=()=>{let n=new Set;for(let{printer:r,calibrations:i}of t){if(!r.connected)continue;let t=i.filter(t=>w(t,e)),a=new Map;for(let e of t){let t=`${e.extruder_id??`null`}`;a.has(t)||a.set(t,[]),a.get(t).push(e)}for(let[e,t]of a)if(t.length>0){let i=[...t].sort((e,t)=>t.k_value-e.k_value)[0];n.add(`${r.id}:${i.cali_idx}:${e}`)}}r(n)};if(!e.material)return(0,j.jsx)(`div`,{className:`p-6 bg-bambu-dark rounded-lg text-center`,children:(0,j.jsx)(`p`,{className:`text-bambu-gray`,children:c(`inventory.selectMaterialFirst`)})});if(t.length===0)return(0,j.jsx)(`div`,{className:`p-6 bg-bambu-dark rounded-lg text-center`,children:(0,j.jsx)(`p`,{className:`text-bambu-gray`,children:c(`inventory.noPrintersConfigured`)})});let m=t.reduce((t,{printer:n,calibrations:r})=>n.connected?t+r.filter(t=>w(t,e)).length:t,0),h=(e,t)=>{let r=`${e.id}:${t.cali_idx}:${t.extruder_id??`null`}`,i=n.has(r);return(0,j.jsxs)(`label`,{className:`flex items-center gap-3 p-3 rounded-lg cursor-pointer transition-all border ${i?`bg-bambu-green/10 border-bambu-green/30`:`bg-bambu-dark border-transparent hover:bg-bambu-dark/80`}`,children:[(0,j.jsx)(`input`,{type:`checkbox`,checked:i,onChange:()=>f(String(e.id),t.cali_idx,t.extruder_id),className:`w-4 h-4 rounded border-bambu-dark-tertiary text-bambu-green focus:ring-bambu-green`}),(0,j.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,j.jsx)(`span`,{className:`text-sm font-medium ${i?`text-bambu-green`:`text-white`}`,children:t.name||t.filament_id})}),(0,j.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[t.nozzle_diameter&&(0,j.jsxs)(`span`,{className:`text-xs font-mono px-2 py-0.5 rounded bg-bambu-dark text-bambu-gray`,children:[t.nozzle_diameter,`mm`]}),(0,j.jsxs)(`span`,{className:`text-xs font-mono px-2 py-0.5 rounded bg-bambu-dark text-bambu-gray`,children:[`K=`,t.k_value.toFixed(3)]})]})]},`${t.cali_idx}-${t.extruder_id}`)};return(0,j.jsxs)(`div`,{className:`space-y-4`,children:[(0,j.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,j.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[c(`inventory.matchingFilter`),`: `,e.brand||c(`inventory.anyBrand`),` / `,e.material,` / `,e.subtype||c(`inventory.anyVariant`)]}),m>0&&(0,j.jsxs)(`button`,{type:`button`,onClick:p,className:`flex items-center gap-1.5 px-2 py-1 text-xs bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white hover:border-bambu-green transition-colors`,children:[(0,j.jsx)(l,{className:`w-3.5 h-3.5`}),c(`inventory.autoSelect`),` (`,m,`)`]})]}),(0,j.jsx)(`div`,{className:`space-y-3`,children:t.map(({printer:t,calibrations:n})=>{let r=i.has(String(t.id)),a=n.filter(t=>w(t,e)),o=a.length,l=a.some(e=>e.extruder_id!==void 0&&e.extruder_id!==null&&e.extruder_id>0),f=a.filter(e=>e.extruder_id===1),p=a.filter(e=>e.extruder_id===0||e.extruder_id===void 0||e.extruder_id===null);return(0,j.jsxs)(`div`,{className:`border border-bambu-dark-tertiary rounded-lg overflow-hidden`,children:[(0,j.jsxs)(`button`,{type:`button`,onClick:()=>u(String(t.id)),className:`w-full px-4 py-3 flex items-center justify-between bg-bambu-dark-secondary hover:bg-bambu-dark-tertiary transition-colors`,children:[(0,j.jsxs)(`div`,{className:`flex items-center gap-3`,children:[r?(0,j.jsx)(s,{className:`w-4 h-4 text-bambu-gray`}):(0,j.jsx)(d,{className:`w-4 h-4 text-bambu-gray`}),(0,j.jsx)(`span`,{className:`font-medium text-white`,children:t.name}),o>0?(0,j.jsxs)(`span`,{className:`text-xs px-2 py-0.5 rounded-full bg-bambu-green/20 text-bambu-green`,children:[o,` `,c(o===1?`inventory.match`:`inventory.matches`)]}):(0,j.jsx)(`span`,{className:`text-xs px-2 py-0.5 rounded-full bg-bambu-dark-tertiary text-bambu-gray`,children:c(`inventory.noMatches`)})]}),(0,j.jsx)(`span`,{className:`text-xs px-2 py-1 rounded-full ${t.connected?`bg-green-500/20 text-green-500`:`bg-bambu-gray/20 text-bambu-gray`}`,children:t.connected?c(`inventory.connected`):c(`inventory.offline`)})]}),r&&(0,j.jsx)(`div`,{className:`px-4 py-3 space-y-3 bg-bambu-dark border-t border-bambu-dark-tertiary`,children:t.connected?o===0?(0,j.jsx)(`p`,{className:`text-sm text-bambu-gray italic py-2`,children:c(`inventory.noKProfilesMatch`)}):l?(0,j.jsxs)(j.Fragment,{children:[f.length>0&&(0,j.jsxs)(`div`,{className:`space-y-2`,children:[(0,j.jsx)(`p`,{className:`text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:c(`inventory.leftNozzle`)}),(0,j.jsx)(`div`,{className:`space-y-2`,children:f.map(e=>h(t,e))})]}),p.length>0&&(0,j.jsxs)(`div`,{className:`space-y-2`,children:[(0,j.jsx)(`p`,{className:`text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:c(`inventory.rightNozzle`)}),(0,j.jsx)(`div`,{className:`space-y-2`,children:p.map(e=>h(t,e))})]})]}):(0,j.jsx)(`div`,{className:`space-y-2`,children:a.map(e=>h(t,e))}):(0,j.jsx)(`p`,{className:`text-sm text-bambu-gray italic py-2`,children:c(`inventory.printerOffline`)})})]},t.id)})}),n.size>0&&(0,j.jsx)(`div`,{className:`p-3 bg-bambu-green/10 border border-bambu-green/30 rounded-lg`,children:(0,j.jsxs)(`p`,{className:`text-sm text-white`,children:[(0,j.jsx)(`span`,{className:`font-semibold`,children:n.size}),` `,c(`inventory.profilesSelected`)]})})]})}function M(e){return m(e.color_name,e.rgba,e.color_name_is_synthesized)}var N=[`PLA`,`PETG`,`ABS`,`ASA`,`TPU`,`PA`,`PC`,`PVA`,`HIPS`];function P(){let{t:e}=a(),t=g(),{showToast:n}=c(),{sbState:s}=u(),[l,d]=(0,A.useState)(`existing`),[f,m]=(0,A.useState)(null),[h,_]=(0,A.useState)(``),[v,y]=(0,A.useState)(`idle`),[ee,b]=(0,A.useState)(``),[x,S]=(0,A.useState)(!1),[te,C]=(0,A.useState)(!1),[ne,w]=(0,A.useState)(null),{data:T}=o({queryKey:[`spoolman-settings`],queryFn:r.getSpoolmanSettings,staleTime:300*1e3}),re=T!==void 0,E=T?.spoolman_enabled===`true`&&!!T?.spoolman_url,{data:D=[],refetch:O}=o({queryKey:[E?`spoolman-inventory-spools`:`inventory-spools`,`write-tag`],queryFn:()=>E?r.getSpoolmanInventorySpools(!1):r.getSpools(!1),refetchInterval:1e4,enabled:re}),{data:k=[]}=o({queryKey:[`spoolbuddy-devices`],queryFn:()=>i.getDevices(),refetchInterval:5e3}),{data:ie}=o({queryKey:[`settings`],queryFn:r.getSettings}),N=k[0],P=s.deviceOnline,R=p(ie?.currency||`USD`),z=(0,A.useMemo)(()=>{let e;if(l===`existing`)e=D.filter(e=>!e.tag_uid&&!e.archived_at);else if(l===`replace`)e=D.filter(e=>(e.tag_uid||e.tray_uuid)&&!e.archived_at);else return[];if(h){let t=h.toLowerCase();e=e.filter(e=>e.material?.toLowerCase().includes(t)||M(e)?.toLowerCase().includes(t)||e.color_name?.toLowerCase().includes(t)||e.brand?.toLowerCase().includes(t)||e.subtype?.toLowerCase().includes(t))}return e},[D,l,h,t]),B=(0,A.useCallback)(e=>{let t=e.detail;(t.sak??t.data?.sak)===0&&(C(!0),w(t.tag_uid??t.data?.tag_uid??null))},[]),V=(0,A.useCallback)(e=>{let t=e.detail;C(!0),w(t.tag_uid??t.data?.tag_uid??null)},[]),H=(0,A.useCallback)(()=>{C(!1),w(null)},[]),U=(0,A.useCallback)(t=>{let n=t.detail;(n.spool_id===f?.id||n.data?.spool_id===f?.id)&&(y(`success`),b(e(`spoolbuddy.writeTag.writeSuccess`,`Tag written successfully!`)),O(),setTimeout(()=>{y(`idle`),m(null),b(``)},5e3))},[f,e,O]),W=(0,A.useCallback)(t=>{let n=t.detail;(n.spool_id===f?.id||n.data?.spool_id===f?.id)&&(y(`error`),b(n.message??n.data?.message??e(`spoolbuddy.writeTag.writeFailed`,`Write failed`)))},[f,e]);(0,A.useEffect)(()=>(window.addEventListener(`spoolbuddy-unknown-tag`,B),window.addEventListener(`spoolbuddy-tag-matched`,V),window.addEventListener(`spoolbuddy-tag-removed`,H),window.addEventListener(`spoolbuddy-tag-written`,U),window.addEventListener(`spoolbuddy-tag-write-failed`,W),()=>{window.removeEventListener(`spoolbuddy-unknown-tag`,B),window.removeEventListener(`spoolbuddy-tag-matched`,V),window.removeEventListener(`spoolbuddy-tag-removed`,H),window.removeEventListener(`spoolbuddy-tag-written`,U),window.removeEventListener(`spoolbuddy-tag-write-failed`,W)}),[B,V,H,U,W]),(0,A.useEffect)(()=>{m(null),y(`idle`),b(``),_(``)},[l]);let G=async()=>{if(!(!f||!N)){y(`writing`),b(e(`spoolbuddy.writeTag.waiting`,`Waiting for SpoolBuddy...`));try{let e=await i.writeTag(N.device_id,f.id);if(e?.warnings?.length)for(let t of e.warnings)n(t,`warning`)}catch{y(`error`),b(e(`spoolbuddy.writeTag.queueFailed`,`Failed to queue write command`))}}},oe=async()=>{if(N){try{await i.cancelWrite(N.device_id)}catch{}y(`idle`),b(``)}},K=async()=>{if(!(!f||!F(f))){S(!0),y(`idle`),b(``);try{E?await r.linkTagToSpoolmanSpool(f.id,{tag_uid:``,tray_uuid:``}):await r.linkTagToSpool(f.id,{tag_uid:``,tray_uuid:``,data_origin:`manual`}),await O(),m(null),y(`success`),b(e(`spoolbuddy.writeTag.untagSuccess`,`Tag removed from spool`)),setTimeout(()=>{y(`idle`),b(``)},2500)}catch{y(`error`),b(e(`spoolbuddy.writeTag.untagFailed`,`Failed to remove tag from spool`))}finally{S(!1)}}},q=(0,A.useCallback)(e=>{m(e),y(`idle`),b(``),O()},[O]),se=f&&P&&v!==`writing`&&v!==`success`;return(0,j.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,j.jsx)(`div`,{className:`flex border-b border-bambu-dark-tertiary shrink-0`,children:[{key:`existing`,label:e(`spoolbuddy.writeTag.tabExisting`,`Existing Spool`)},{key:`new`,label:e(`spoolbuddy.writeTag.tabNew`,`New Spool`)},{key:`replace`,label:e(`spoolbuddy.writeTag.tabReplace`,`Replace Tag`)}].map(e=>(0,j.jsx)(`button`,{onClick:()=>d(e.key),className:`flex-1 py-3 text-sm font-medium transition-colors ${l===e.key?`text-bambu-green border-b-2 border-bambu-green bg-bambu-dark`:`text-zinc-400 hover:text-zinc-200 hover:bg-bambu-dark-tertiary`}`,children:e.label},e.key))}),(0,j.jsxs)(`div`,{className:`flex flex-1 overflow-hidden`,children:[(0,j.jsx)(`div`,{className:`flex-1 flex flex-col overflow-hidden border-r border-bambu-dark-tertiary`,children:l===`new`?(0,j.jsx)(L,{currencySymbol:R,onCreated:q,selectedSpool:f,spoolmanMode:E,t:e}):(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(`div`,{className:`p-3 shrink-0`,children:(0,j.jsx)(`input`,{type:`text`,value:h,onChange:e=>_(e.target.value),placeholder:e(`spoolbuddy.writeTag.searchPlaceholder`,`Search by material, color, brand...`),className:`w-full px-3 py-2 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-sm text-white placeholder-zinc-500 focus:outline-none focus:border-bambu-green`})}),(0,j.jsx)(`div`,{className:`flex-1 overflow-y-auto px-3 pb-3 space-y-2`,children:z.length===0?(0,j.jsx)(`div`,{className:`text-center text-zinc-500 py-8 text-sm`,children:l===`existing`?e(`spoolbuddy.writeTag.noUntaggedSpools`,`No spools without tags`):e(`spoolbuddy.writeTag.noTaggedSpools`,`No spools with tags`)}):z.map(e=>(0,j.jsx)(I,{spool:e,selected:f?.id===e.id,showTag:l===`replace`,onClick:()=>{m(e),y(`idle`),b(``)}},e.id))})]})}),(0,j.jsx)(`div`,{className:`w-[340px] flex flex-col items-center justify-center p-6 shrink-0`,children:(0,j.jsx)(ae,{writeStatus:v,writeMessage:ee,selectedSpool:f,tagOnReader:te,tagUid:ne,deviceOnline:P,canWrite:!!se,isReplace:l===`replace`,canUntag:l===`replace`&&!!f&&F(f),untagging:x,onWrite:G,onUntag:K,onCancel:oe,onRetry:()=>{y(`idle`),b(``)},t:e})})]})]})}function F(e){return!!(e.tag_uid||e.tray_uuid)}function I({spool:e,selected:t,showTag:n,onClick:r}){let i=Math.max(0,e.label_weight-e.weight_used),a=e.label_weight>0?Math.round(i/e.label_weight*100):0;return(0,j.jsxs)(`button`,{onClick:r,className:`w-full flex items-center gap-3 p-3 rounded-lg text-left transition-colors ${t?`bg-bambu-green/15 border border-bambu-green/50`:`bg-bambu-dark-secondary hover:bg-bambu-dark-tertiary border border-transparent`}`,children:[(0,j.jsx)(`div`,{className:`w-8 h-8 rounded-full shrink-0 border border-white/10`,style:k(e)??(e.rgba?h(e.rgba):{backgroundColor:`#666`})}),(0,j.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,j.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,j.jsxs)(`span`,{className:`text-sm font-medium text-white truncate`,children:[e.brand?`${e.brand} `:``,e.material,e.subtype?` ${e.subtype}`:``]}),(0,j.jsxs)(`span`,{className:`text-[10px] font-mono text-zinc-500 shrink-0`,children:[`#`,e.id]})]}),(0,j.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-zinc-400`,children:[M(e)&&(0,j.jsx)(`span`,{children:M(e)}),(0,j.jsxs)(`span`,{children:[i,`g / `,e.label_weight,`g (`,a,`%)`]})]}),n&&e.tag_uid&&(0,j.jsx)(`div`,{className:`text-xs text-zinc-500 mt-0.5 font-mono`,children:e.tag_uid})]}),t&&(0,j.jsx)(`svg`,{className:`w-5 h-5 text-bambu-green shrink-0`,fill:`currentColor`,viewBox:`0 0 20 20`,children:(0,j.jsx)(`path`,{fillRule:`evenodd`,d:`M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z`,clipRule:`evenodd`})})]})}function L({currencySymbol:e,onCreated:t,selectedSpool:n,spoolmanMode:i,t:a}){let{data:s=[]}=o({queryKey:[i?`spoolman-inventory-spools`:`inventory-spools`,`write-tag-form`],queryFn:()=>i?r.getSpoolmanInventorySpools(!0):r.getSpools(!0)}),{data:c}=o({queryKey:[`settings`],queryFn:r.getSettings}),[l,u]=(0,A.useState)(`simple`),[d,p]=(0,A.useState)(`filament`),[m,g]=(0,A.useState)(v),[w,P]=(0,A.useState)(!1),[F,I]=(0,A.useState)({}),[L,ae]=(0,A.useState)(!1),[R,z]=(0,A.useState)(1),[B,V]=(0,A.useState)(!1),[H,U]=(0,A.useState)(null),[W,G]=(0,A.useState)(!1),[oe,K]=(0,A.useState)(!1),[q,se]=(0,A.useState)([]),[J,ce]=(0,A.useState)([]),[le,ue]=(0,A.useState)([]),[de,fe]=(0,A.useState)([]),[Y,pe]=(0,A.useState)([]),[me,he]=(0,A.useState)(``),[ge,_e]=(0,A.useState)([]),[X,ve]=(0,A.useState)([]),[Z,ye]=(0,A.useState)(new Set),[be,xe]=(0,A.useState)(new Set);(0,A.useEffect)(()=>{_e(re())},[]),(0,A.useEffect)(()=>{let e=!1;return(async()=>{if(l===`full`){K(!0);try{let[t,n]=await Promise.allSettled([(async()=>(await r.getCloudStatus()).is_authenticated?{connected:!0,presets:await r.getFilamentPresets()}:{connected:!1,presets:[]})(),(async()=>(await r.orcaCloudStatus()).connected?{connected:!0,presets:(await r.orcaCloudListProfiles()).filament}:{connected:!1,presets:[]})()]);if(e)return;let i=t.status===`fulfilled`&&t.value.connected,a=n.status===`fulfilled`&&n.value.connected,o=t.status===`fulfilled`?t.value.presets:[],s=n.status===`fulfilled`?n.value.presets:[];G(i||a),se([...o,...s])}catch{e||G(!1)}finally{e||K(!1)}r.getSpoolCatalog().then(t=>{e||fe(t)}).catch(()=>void 0),r.getColorCatalog().then(t=>{e||pe(t)}).catch(()=>void 0),r.getLocalPresets().then(t=>{e||ce(t.filament)}).catch(()=>void 0),r.getBuiltinFilaments().then(t=>{e||ue(t)}).catch(()=>void 0);try{let t=await r.getPrinters(),n=await Promise.all(t.map(e=>r.getPrinterStatus(e.id).catch(()=>null))),i=[];for(let e=0;e{e=!0}},[l]),(0,A.useEffect)(()=>{X.length>0&&xe(new Set(X.map(e=>String(e.printer.id))))},[X]);let Se=(0,A.useMemo)(()=>E(q,new Set,J,le),[q,J,le]),Ce=(0,A.useMemo)(()=>te(m.slicer_filament,Se),[m.slicer_filament,Se]),we=(0,A.useMemo)(()=>{let e=ne(q,J),t=Y.map(e=>e.manufacturer?.trim()).filter(e=>!!e);return Array.from(new Set([...e,...t])).sort((e,t)=>e.localeCompare(t))},[q,J,Y]),Te=(0,A.useMemo)(()=>{let e=Y.map(e=>e.material?.trim()).filter(e=>!!e);return Array.from(new Set([...O,...e])).sort((e,t)=>e.localeCompare(t))},[Y]),Q=(0,A.useMemo)(()=>{let e=[];for(let t of Y){let n=t.manufacturer?.trim(),r=t.material?.trim();n&&r&&e.push({brand:n,material:r})}for(let t of q){let n=D(t.name);n.brand&&n.material&&e.push({brand:n.brand,material:n.material})}for(let t of J){let n=D(t.name),r=t.filament_vendor?.trim()||n.brand,i=n.material;r&&i&&e.push({brand:r,material:i})}return e},[q,Y,J]),Ee=(0,A.useMemo)(()=>{let e=new Map;for(let t of Q){let n=t.brand.toLowerCase(),r=t.material.toLowerCase();e.has(n)||e.set(n,new Set),e.get(n).add(r)}return e},[Q]),De=(0,A.useMemo)(()=>{let e=new Map;for(let t of Q){let n=t.brand.toLowerCase(),r=t.material.toLowerCase();e.has(r)||e.set(r,new Set),e.get(r).add(n)}return e},[Q]),Oe=(0,A.useMemo)(()=>C(we,m.brand),[we,m.brand]),ke=(0,A.useMemo)(()=>C(Te,m.material),[Te,m.material]),Ae=(0,A.useMemo)(()=>x(Oe,m.material,De),[Oe,m.material,De]),je=(0,A.useMemo)(()=>x(ke,m.brand,Ee),[ke,m.brand,Ee]),$=(e,t)=>{g(n=>({...n,[e]:t})),e===`core_weight`&&P(!0),F[e]&&I(t=>({...t,[e]:void 0}))},Me=e=>{_e(t=>S(e,t))},Ne=async e=>{let t=i?r.saveSpoolmanKProfiles:r.saveSpoolKProfiles;if(Z.size===0){try{await t(e,[])}catch{}return}let n=[];for(let e of Z){let[t,r,i]=e.split(`:`),a=parseInt(t),o=parseInt(r),s=i===`null`?0:parseInt(i),c=X.find(e=>e.printer.id===a);if(c){let e=c.calibrations.find(e=>e.cali_idx===o&&(e.extruder_id??0)===s);e&&n.push({printer_id:a,extruder:s,nozzle_diameter:e.nozzle_diameter||`0.4`,k_value:e.k_value,name:e.name||null,cali_idx:e.cali_idx,setting_id:e.setting_id||null})}}n.length>0&&await t(e,n)},Pe=async()=>{U(null);let e=ee(m,l===`simple`?!0:L);if(!e.isValid){I(e.errors),p(`filament`);return}let n=Ce?.displayName||me||null,o={material:m.material,subtype:m.subtype||null,brand:m.brand||null,color_name:m.color_name||null,rgba:m.rgba||null,extra_colors:m.extra_colors||null,effect_type:m.effect_type||null,label_weight:m.label_weight,...i?w?{core_weight:m.core_weight}:{}:{core_weight:m.core_weight,core_weight_catalog_id:m.core_weight_catalog_id},weight_used:m.weight_used,slicer_filament:m.slicer_filament||null,slicer_filament_name:n,nozzle_temp_min:null,nozzle_temp_max:null,note:m.note||null,cost_per_kg:m.cost_per_kg,added_full:null,last_used:null,encode_time:null,tag_uid:null,tray_uuid:null,data_origin:null,tag_type:null,last_scale_weight:null,last_weighed_at:null,category:m.category.trim()||null,low_stock_threshold_pct:m.low_stock_threshold_pct,material_number:m.material_number.trim()||null};V(!0);try{if(R>1){let e=i?await r.bulkCreateSpoolmanInventorySpools(o,R):await r.bulkCreateSpools(o,R),n=i&&e&&typeof e==`object`&&`created`in e?e.created:e;for(let e of n)await Ne(e.id);n.length>0&&t(n[0])}else{let e=i?await r.createSpoolmanInventorySpool(o):await r.createSpool(o);await Ne(e.id),t(e)}}catch{U(a(`spoolbuddy.writeTag.createFailed`,`Failed to create spool`))}finally{V(!1)}},Fe=`#${(m.rgba||`808080FF`).slice(0,6)}`;return(0,j.jsxs)(`div`,{className:`p-3 space-y-3 overflow-y-auto h-full`,children:[(0,j.jsxs)(`div`,{className:`flex items-center justify-between px-2 py-2 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary`,children:[(0,j.jsx)(`span`,{className:`text-sm text-zinc-200`,children:a(`spoolbuddy.writeTag.viewMode`,`View`)}),(0,j.jsxs)(`div`,{className:`flex rounded-lg overflow-hidden border border-bambu-dark-tertiary`,children:[(0,j.jsx)(`button`,{type:`button`,onClick:()=>u(`simple`),className:`px-3 py-1.5 text-xs font-medium ${l===`simple`?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark text-zinc-400`}`,children:a(`spoolbuddy.writeTag.simpleView`,`Simple`)}),(0,j.jsx)(`button`,{type:`button`,onClick:()=>u(`full`),className:`px-3 py-1.5 text-xs font-medium ${l===`full`?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark text-zinc-400`}`,children:a(`spoolbuddy.writeTag.fullView`,`Full`)})]})]}),l===`simple`?n?(0,j.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full p-6 text-center bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg`,children:[(0,j.jsx)(`div`,{className:`w-12 h-12 rounded-full mb-4 border border-white/10`,style:k(n,`preview`)??(n.rgba?h(n.rgba):{backgroundColor:`#666`})}),(0,j.jsxs)(`p`,{className:`text-white font-medium`,children:[n.brand?`${n.brand} `:``,n.material]}),M(n)&&(0,j.jsx)(`p`,{className:`text-zinc-400 text-sm`,children:M(n)}),(0,j.jsxs)(`p`,{className:`text-zinc-500 text-xs mt-1`,children:[n.label_weight,`g`]}),(0,j.jsx)(`p`,{className:`text-bambu-green text-sm mt-4`,children:a(`spoolbuddy.writeTag.spoolCreated`,`Spool created! Ready to write.`)})]}):(0,j.jsxs)(`div`,{className:`p-4 space-y-4 overflow-y-auto bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg`,children:[(0,j.jsxs)(`div`,{children:[(0,j.jsx)(`label`,{className:`block text-xs text-zinc-400 mb-1`,children:a(`spoolbuddy.writeTag.material`,`Material`)}),(0,j.jsx)(`select`,{value:m.material,onChange:e=>$(`material`,e.target.value),className:`w-full px-3 py-2 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-sm text-white focus:outline-none focus:border-bambu-green`,children:N.map(e=>(0,j.jsx)(`option`,{value:e,children:e},e))})]}),(0,j.jsxs)(`div`,{className:`flex gap-3`,children:[(0,j.jsxs)(`div`,{className:`flex-1`,children:[(0,j.jsx)(`label`,{className:`block text-xs text-zinc-400 mb-1`,children:a(`spoolbuddy.writeTag.colorName`,`Color Name`)}),(0,j.jsx)(`input`,{type:`text`,value:m.color_name,onChange:e=>$(`color_name`,e.target.value),placeholder:`Jade White`,className:`w-full px-3 py-2 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-sm text-white placeholder-zinc-500 focus:outline-none focus:border-bambu-green`})]}),(0,j.jsxs)(`div`,{children:[(0,j.jsx)(`label`,{className:`block text-xs text-zinc-400 mb-1`,children:a(`spoolbuddy.writeTag.color`,`Color`)}),(0,j.jsx)(`input`,{type:`color`,value:Fe,onChange:e=>$(`rgba`,e.target.value.replace(`#`,``).toUpperCase()+`FF`),className:`w-10 h-9 bg-transparent border border-bambu-dark-tertiary rounded cursor-pointer`})]})]}),(0,j.jsxs)(`div`,{children:[(0,j.jsx)(`label`,{className:`block text-xs text-zinc-400 mb-1`,children:a(`spoolbuddy.writeTag.brand`,`Brand`)}),(0,j.jsx)(`input`,{type:`text`,value:m.brand,onChange:e=>$(`brand`,e.target.value),placeholder:`Polymaker`,className:`w-full px-3 py-2 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-sm text-white placeholder-zinc-500 focus:outline-none focus:border-bambu-green`})]}),(0,j.jsxs)(`div`,{children:[(0,j.jsx)(`label`,{className:`block text-xs text-zinc-400 mb-1`,children:a(`spoolbuddy.writeTag.weight`,`Weight (g)`)}),(0,j.jsx)(f,{value:m.label_weight,onChange:e=>$(`label_weight`,e),fallback:0,min:0,max:1e4,className:`w-full px-3 py-2 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-sm text-white focus:outline-none focus:border-bambu-green`})]}),(0,j.jsx)(`button`,{onClick:Pe,disabled:B||!m.material,className:`w-full py-2.5 bg-bambu-green hover:bg-bambu-green/80 disabled:opacity-50 disabled:cursor-not-allowed text-white text-sm font-medium rounded transition-colors`,children:B?a(`spoolbuddy.writeTag.creating`,`Creating...`):a(`spoolbuddy.writeTag.createSpool`,`Create Spool`)})]}):(0,j.jsxs)(j.Fragment,{children:[(0,j.jsxs)(`div`,{className:`flex items-center justify-between px-2 py-2 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary`,children:[(0,j.jsx)(`span`,{className:`text-sm text-zinc-200`,children:a(`inventory.quickAdd`,`Quick Add`)}),(0,j.jsx)(`button`,{type:`button`,onClick:()=>ae(e=>!e),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors ${L?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,children:(0,j.jsx)(`span`,{className:`inline-block h-4.5 w-4.5 rounded-full bg-white transition-transform ${L?`translate-x-6`:`translate-x-1`}`})})]}),(0,j.jsxs)(`div`,{className:`flex border border-bambu-dark-tertiary rounded-lg overflow-hidden`,children:[(0,j.jsx)(`button`,{onClick:()=>p(`filament`),className:`flex-1 py-2.5 text-sm font-medium ${d===`filament`?`bg-bambu-green/15 text-bambu-green`:`bg-bambu-dark-secondary text-zinc-400`}`,children:a(`inventory.filamentInfoTab`,`Filament`)}),!L&&(0,j.jsx)(`button`,{onClick:()=>p(`pa-profile`),className:`flex-1 py-2.5 text-sm font-medium ${d===`pa-profile`?`bg-bambu-green/15 text-bambu-green`:`bg-bambu-dark-secondary text-zinc-400`}`,children:a(`inventory.paProfileTab`,`PA Profile`)})]}),(0,j.jsx)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg p-3`,children:d===`filament`?(0,j.jsxs)(`div`,{className:`space-y-4`,children:[(0,j.jsx)(y,{formData:m,updateField:$,cloudAuthenticated:W,loadingCloudPresets:oe,presetInputValue:me,setPresetInputValue:he,selectedPresetOption:Ce,filamentOptions:Se,availableBrands:Oe,availableMaterials:ke,suggestedBrands:Ae,suggestedMaterials:je,quickAdd:L,detailsRequired:!L,quantity:R,onQuantityChange:z,errors:F}),(0,j.jsx)(_,{formData:m,updateField:$,recentColors:ge,onColorUsed:Me,catalogColors:Y}),(0,j.jsx)(b,{formData:m,updateField:$,spoolCatalog:de,currencySymbol:e,availableCategories:Array.from(new Set(s.map(e=>e.category?.trim()).filter(e=>!!e))).sort((e,t)=>e.localeCompare(t)),availableMaterialNumbers:Array.from(new Set(s.map(e=>e.material_number?.trim()).filter(e=>!!e))).sort((e,t)=>e.localeCompare(t,void 0,{numeric:!0})),globalLowStockThreshold:c?.low_stock_threshold??20,spoolmanMode:i})]}):(0,j.jsx)(ie,{formData:m,updateField:$,printersWithCalibrations:X,selectedProfiles:Z,setSelectedProfiles:ye,expandedPrinters:be,setExpandedPrinters:xe})})]}),H&&(0,j.jsx)(`div`,{className:`text-sm text-red-400 bg-red-900/20 border border-red-900/40 rounded-lg px-3 py-2`,children:H}),l===`full`&&(0,j.jsx)(`button`,{onClick:Pe,disabled:B,className:`w-full py-3 bg-bambu-green hover:bg-bambu-green/80 disabled:opacity-50 disabled:cursor-not-allowed text-white text-sm font-medium rounded transition-colors`,children:B?a(`spoolbuddy.writeTag.creating`,`Creating...`):a(`spoolbuddy.writeTag.createSpool`,`Create Spool`)}),l===`full`&&n&&(0,j.jsxs)(`div`,{className:`flex flex-col items-center justify-center p-4 text-center bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg`,children:[(0,j.jsx)(`div`,{className:`w-12 h-12 rounded-full mb-4 border border-white/10`,style:k(n,`preview`)??(n.rgba?h(n.rgba):{backgroundColor:`#666`})}),(0,j.jsxs)(`p`,{className:`text-white font-medium`,children:[n.brand?`${n.brand} `:``,n.material]}),M(n)&&(0,j.jsx)(`p`,{className:`text-zinc-400 text-sm`,children:M(n)}),(0,j.jsxs)(`p`,{className:`text-zinc-500 text-xs mt-1`,children:[n.label_weight,`g`]}),(0,j.jsx)(`p`,{className:`text-bambu-green text-sm mt-4`,children:a(`spoolbuddy.writeTag.spoolCreated`,`Spool created! Ready to write.`)})]})]})}function ae({writeStatus:e,writeMessage:t,selectedSpool:n,tagOnReader:r,tagUid:i,deviceOnline:a,canWrite:o,isReplace:s,canUntag:c,untagging:l,onWrite:u,onUntag:d,onCancel:f,onRetry:p,t:m}){if(e===`success`)return(0,j.jsxs)(`div`,{className:`flex flex-col items-center text-center space-y-4`,children:[(0,j.jsx)(`div`,{className:`w-16 h-16 rounded-full bg-green-500/20 flex items-center justify-center`,children:(0,j.jsx)(`svg`,{className:`w-8 h-8 text-green-400`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,j.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M5 13l4 4L19 7`})})}),(0,j.jsx)(`p`,{className:`text-green-400 font-medium`,children:t}),n&&(0,j.jsxs)(`p`,{className:`text-zinc-400 text-sm`,children:[n.brand?`${n.brand} `:``,n.material,n.subtype?` ${n.subtype}`:``,M(n)?` - ${M(n)}`:``]})]});if(e===`error`)return(0,j.jsxs)(`div`,{className:`flex flex-col items-center text-center space-y-4`,children:[(0,j.jsx)(`div`,{className:`w-16 h-16 rounded-full bg-red-500/20 flex items-center justify-center`,children:(0,j.jsx)(`svg`,{className:`w-8 h-8 text-red-400`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,j.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M6 18L18 6M6 6l12 12`})})}),(0,j.jsx)(`p`,{className:`text-red-400 font-medium`,children:t}),(0,j.jsx)(`button`,{onClick:p,className:`px-4 py-2 bg-bambu-dark-tertiary hover:bg-bambu-dark-secondary text-white text-sm rounded transition-colors`,children:m(`spoolbuddy.writeTag.tryAgain`,`Try Again`)})]});if(e===`writing`)return(0,j.jsxs)(`div`,{className:`flex flex-col items-center text-center space-y-4`,children:[(0,j.jsxs)(`div`,{className:`relative w-16 h-16`,children:[(0,j.jsx)(`div`,{className:`absolute inset-0 rounded-full border-2 border-bambu-green/30 animate-ping`}),(0,j.jsx)(`div`,{className:`absolute inset-2 rounded-full border-2 border-bambu-green/50 animate-pulse`}),(0,j.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center`,children:(0,j.jsx)(R,{className:`w-8 h-8 text-bambu-green`})})]}),(0,j.jsx)(`p`,{className:`text-bambu-green font-medium`,children:m(`spoolbuddy.writeTag.writing`,`Writing tag...`)}),(0,j.jsx)(`p`,{className:`text-zinc-500 text-xs`,children:t}),(0,j.jsx)(`button`,{onClick:f,className:`px-4 py-2 bg-bambu-dark-tertiary hover:bg-bambu-dark-secondary text-zinc-400 text-sm rounded transition-colors`,children:m(`spoolbuddy.writeTag.cancel`,`Cancel`)})]});if(!a)return(0,j.jsxs)(`div`,{className:`flex flex-col items-center text-center space-y-3`,children:[(0,j.jsx)(R,{className:`w-12 h-12 text-zinc-600`}),(0,j.jsx)(`p`,{className:`text-zinc-500 text-sm`,children:m(`spoolbuddy.writeTag.deviceOffline`,`SpoolBuddy is offline`)})]});if(!n)return(0,j.jsxs)(`div`,{className:`flex flex-col items-center text-center space-y-3`,children:[(0,j.jsx)(R,{className:`w-12 h-12 text-zinc-600`}),(0,j.jsx)(`p`,{className:`text-zinc-400 text-sm`,children:m(`spoolbuddy.writeTag.selectSpool`,`Select a spool, then place a blank NTAG on the reader`)})]});let g=k(n,`preview`)??(n.rgba?h(n.rgba):{backgroundColor:`#666`});return(0,j.jsxs)(`div`,{className:`flex flex-col items-center text-center space-y-4 w-full`,children:[(0,j.jsx)(`div`,{className:`relative w-16 h-16`,children:r?(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(`div`,{className:`absolute inset-0 rounded-full bg-bambu-green/10`}),(0,j.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center`,children:(0,j.jsx)(R,{className:`w-8 h-8 text-bambu-green`})})]}):(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(`div`,{className:`absolute inset-0 rounded-full border-2 border-zinc-600 animate-pulse`}),(0,j.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center`,children:(0,j.jsx)(R,{className:`w-8 h-8 text-zinc-500`})})]})}),r?(0,j.jsxs)(`div`,{className:`space-y-1`,children:[(0,j.jsx)(`p`,{className:`text-bambu-green text-sm font-medium`,children:m(`spoolbuddy.writeTag.tagReady`,`Tag detected — ready to write`)}),i&&(0,j.jsx)(`p`,{className:`text-zinc-500 text-xs font-mono`,children:i})]}):(0,j.jsx)(`p`,{className:`text-zinc-400 text-sm`,children:m(`spoolbuddy.writeTag.placeTag`,`Place an NTAG on the reader`)}),(0,j.jsxs)(`div`,{className:`w-full bg-bambu-dark-secondary rounded-lg p-3 space-y-2`,children:[(0,j.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,j.jsx)(`div`,{className:`w-8 h-8 rounded-full border border-white/10 shrink-0`,style:g}),(0,j.jsxs)(`div`,{className:`text-left min-w-0`,children:[(0,j.jsxs)(`p`,{className:`text-white text-sm font-medium truncate`,children:[n.brand?`${n.brand} `:``,n.material]}),M(n)&&(0,j.jsx)(`p`,{className:`text-zinc-400 text-xs`,children:M(n)})]})]}),(0,j.jsxs)(`div`,{className:`text-xs text-zinc-500`,children:[n.label_weight,`g`]})]}),s&&n.tag_uid&&(0,j.jsx)(`p`,{className:`text-yellow-500/80 text-xs`,children:m(`spoolbuddy.writeTag.replaceWarning`,`Old tag will be unlinked. New tag will replace it.`)}),(0,j.jsx)(`button`,{onClick:u,disabled:!o,className:`w-full py-3 bg-bambu-green hover:bg-bambu-green/80 disabled:opacity-40 disabled:cursor-not-allowed text-white font-medium rounded-lg transition-colors text-sm`,children:s?m(`spoolbuddy.writeTag.replaceTag`,`Replace Tag`):m(`spoolbuddy.writeTag.writeTag`,`Write Tag`)}),s&&c&&(0,j.jsx)(`button`,{onClick:d,disabled:l,className:`w-full py-2.5 bg-bambu-dark-tertiary hover:bg-bambu-dark-secondary disabled:opacity-40 disabled:cursor-not-allowed text-zinc-200 rounded-lg transition-colors text-sm`,children:l?m(`spoolbuddy.writeTag.untagging`,`Removing tag...`):m(`spoolbuddy.writeTag.untagSpool`,`Untag Selected Spool`)})]})}function R({className:e}){return(0,j.jsxs)(`svg`,{className:e,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:1.5,children:[(0,j.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M8.288 15.038a5.25 5.25 0 017.424 0M5.106 11.856c3.807-3.808 9.98-3.808 13.788 0M1.924 8.674c5.565-5.565 14.587-5.565 20.152 0`}),(0,j.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M12.53 18.22l-.53.53-.53-.53a.75.75 0 011.06 0z`})]})}export{P as SpoolBuddyWriteTagPage}; \ No newline at end of file +import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,v as i,w as a}from"./client-DnySrlFv.js";import{t as o}from"./useQuery-BBCjCezC.js";import{a as s}from"./info-ROUoQhJR.js";import{n as c}from"./ToastContext-BRX0SW3C.js";import{t as l}from"./sparkles-DRqKNlhr.js";import{Hn as u,Mn as d,N as f,at as p,ft as m,lt as h,ot as g}from"./index-Cxa-KVmA.js";import{n as _,o as v,r as y,s as ee,t as b}from"./AdditionalSection-9uxxm13d.js";import{c as x,f as S,i as te,m as C,n as ne,o as w,r as T,s as re,t as E,u as D,v as O}from"./utils-subfXwl6.js";import{n as k}from"./spoolPaint-CrvpHqdD.js";var A=e(n(),1),j=t();function ie({formData:e,printersWithCalibrations:t,selectedProfiles:n,setSelectedProfiles:r,expandedPrinters:i,setExpandedPrinters:o}){let{t:c}=a(),u=e=>{o(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},f=(e,t,n)=>{let i=`${e}:${t}:${n??`null`}`,a=`${e}:${n??`null`}`;r(e=>{let t=new Set(e);if(t.has(i))t.delete(i);else{for(let e of Array.from(t)){let n=e.split(`:`);`${n[0]}:${n[2]}`===a&&t.delete(e)}t.add(i)}return t})},p=()=>{let n=new Set;for(let{printer:r,calibrations:i}of t){if(!r.connected)continue;let t=i.filter(t=>w(t,e)),a=new Map;for(let e of t){let t=`${e.extruder_id??`null`}`;a.has(t)||a.set(t,[]),a.get(t).push(e)}for(let[e,t]of a)if(t.length>0){let i=[...t].sort((e,t)=>t.k_value-e.k_value)[0];n.add(`${r.id}:${i.cali_idx}:${e}`)}}r(n)};if(!e.material)return(0,j.jsx)(`div`,{className:`p-6 bg-bambu-dark rounded-lg text-center`,children:(0,j.jsx)(`p`,{className:`text-bambu-gray`,children:c(`inventory.selectMaterialFirst`)})});if(t.length===0)return(0,j.jsx)(`div`,{className:`p-6 bg-bambu-dark rounded-lg text-center`,children:(0,j.jsx)(`p`,{className:`text-bambu-gray`,children:c(`inventory.noPrintersConfigured`)})});let m=t.reduce((t,{printer:n,calibrations:r})=>n.connected?t+r.filter(t=>w(t,e)).length:t,0),h=(e,t)=>{let r=`${e.id}:${t.cali_idx}:${t.extruder_id??`null`}`,i=n.has(r);return(0,j.jsxs)(`label`,{className:`flex items-center gap-3 p-3 rounded-lg cursor-pointer transition-all border ${i?`bg-bambu-green/10 border-bambu-green/30`:`bg-bambu-dark border-transparent hover:bg-bambu-dark/80`}`,children:[(0,j.jsx)(`input`,{type:`checkbox`,checked:i,onChange:()=>f(String(e.id),t.cali_idx,t.extruder_id),className:`w-4 h-4 rounded border-bambu-dark-tertiary text-bambu-green focus:ring-bambu-green`}),(0,j.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,j.jsx)(`span`,{className:`text-sm font-medium ${i?`text-bambu-green`:`text-white`}`,children:t.name||t.filament_id})}),(0,j.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[t.nozzle_diameter&&(0,j.jsxs)(`span`,{className:`text-xs font-mono px-2 py-0.5 rounded bg-bambu-dark text-bambu-gray`,children:[t.nozzle_diameter,`mm`]}),(0,j.jsxs)(`span`,{className:`text-xs font-mono px-2 py-0.5 rounded bg-bambu-dark text-bambu-gray`,children:[`K=`,t.k_value.toFixed(3)]})]})]},`${t.cali_idx}-${t.extruder_id}`)};return(0,j.jsxs)(`div`,{className:`space-y-4`,children:[(0,j.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,j.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[c(`inventory.matchingFilter`),`: `,e.brand||c(`inventory.anyBrand`),` / `,e.material,` / `,e.subtype||c(`inventory.anyVariant`)]}),m>0&&(0,j.jsxs)(`button`,{type:`button`,onClick:p,className:`flex items-center gap-1.5 px-2 py-1 text-xs bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white hover:border-bambu-green transition-colors`,children:[(0,j.jsx)(l,{className:`w-3.5 h-3.5`}),c(`inventory.autoSelect`),` (`,m,`)`]})]}),(0,j.jsx)(`div`,{className:`space-y-3`,children:t.map(({printer:t,calibrations:n})=>{let r=i.has(String(t.id)),a=n.filter(t=>w(t,e)),o=a.length,l=a.some(e=>e.extruder_id!==void 0&&e.extruder_id!==null&&e.extruder_id>0),f=a.filter(e=>e.extruder_id===1),p=a.filter(e=>e.extruder_id===0||e.extruder_id===void 0||e.extruder_id===null);return(0,j.jsxs)(`div`,{className:`border border-bambu-dark-tertiary rounded-lg overflow-hidden`,children:[(0,j.jsxs)(`button`,{type:`button`,onClick:()=>u(String(t.id)),className:`w-full px-4 py-3 flex items-center justify-between bg-bambu-dark-secondary hover:bg-bambu-dark-tertiary transition-colors`,children:[(0,j.jsxs)(`div`,{className:`flex items-center gap-3`,children:[r?(0,j.jsx)(s,{className:`w-4 h-4 text-bambu-gray`}):(0,j.jsx)(d,{className:`w-4 h-4 text-bambu-gray`}),(0,j.jsx)(`span`,{className:`font-medium text-white`,children:t.name}),o>0?(0,j.jsxs)(`span`,{className:`text-xs px-2 py-0.5 rounded-full bg-bambu-green/20 text-bambu-green`,children:[o,` `,c(o===1?`inventory.match`:`inventory.matches`)]}):(0,j.jsx)(`span`,{className:`text-xs px-2 py-0.5 rounded-full bg-bambu-dark-tertiary text-bambu-gray`,children:c(`inventory.noMatches`)})]}),(0,j.jsx)(`span`,{className:`text-xs px-2 py-1 rounded-full ${t.connected?`bg-green-500/20 text-green-500`:`bg-bambu-gray/20 text-bambu-gray`}`,children:t.connected?c(`inventory.connected`):c(`inventory.offline`)})]}),r&&(0,j.jsx)(`div`,{className:`px-4 py-3 space-y-3 bg-bambu-dark border-t border-bambu-dark-tertiary`,children:t.connected?o===0?(0,j.jsx)(`p`,{className:`text-sm text-bambu-gray italic py-2`,children:c(`inventory.noKProfilesMatch`)}):l?(0,j.jsxs)(j.Fragment,{children:[f.length>0&&(0,j.jsxs)(`div`,{className:`space-y-2`,children:[(0,j.jsx)(`p`,{className:`text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:c(`inventory.leftNozzle`)}),(0,j.jsx)(`div`,{className:`space-y-2`,children:f.map(e=>h(t,e))})]}),p.length>0&&(0,j.jsxs)(`div`,{className:`space-y-2`,children:[(0,j.jsx)(`p`,{className:`text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:c(`inventory.rightNozzle`)}),(0,j.jsx)(`div`,{className:`space-y-2`,children:p.map(e=>h(t,e))})]})]}):(0,j.jsx)(`div`,{className:`space-y-2`,children:a.map(e=>h(t,e))}):(0,j.jsx)(`p`,{className:`text-sm text-bambu-gray italic py-2`,children:c(`inventory.printerOffline`)})})]},t.id)})}),n.size>0&&(0,j.jsx)(`div`,{className:`p-3 bg-bambu-green/10 border border-bambu-green/30 rounded-lg`,children:(0,j.jsxs)(`p`,{className:`text-sm text-white`,children:[(0,j.jsx)(`span`,{className:`font-semibold`,children:n.size}),` `,c(`inventory.profilesSelected`)]})})]})}function M(e){return m(e.color_name,e.rgba,e.color_name_is_synthesized)}var N=[`PLA`,`PETG`,`ABS`,`ASA`,`TPU`,`PA`,`PC`,`PVA`,`HIPS`];function P(){let{t:e}=a(),t=g(),{showToast:n}=c(),{sbState:s}=u(),[l,d]=(0,A.useState)(`existing`),[f,m]=(0,A.useState)(null),[h,_]=(0,A.useState)(``),[v,y]=(0,A.useState)(`idle`),[ee,b]=(0,A.useState)(``),[x,S]=(0,A.useState)(!1),[te,C]=(0,A.useState)(!1),[ne,w]=(0,A.useState)(null),{data:T}=o({queryKey:[`spoolman-settings`],queryFn:r.getSpoolmanSettings,staleTime:300*1e3}),re=T!==void 0,E=T?.spoolman_enabled===`true`&&!!T?.spoolman_url,{data:D=[],refetch:O}=o({queryKey:[E?`spoolman-inventory-spools`:`inventory-spools`,`write-tag`],queryFn:()=>E?r.getSpoolmanInventorySpools(!1):r.getSpools(!1),refetchInterval:1e4,enabled:re}),{data:k=[]}=o({queryKey:[`spoolbuddy-devices`],queryFn:()=>i.getDevices(),refetchInterval:5e3}),{data:ie}=o({queryKey:[`settings`],queryFn:r.getSettings}),N=k[0],P=s.deviceOnline,R=p(ie?.currency||`USD`),z=(0,A.useMemo)(()=>{let e;if(l===`existing`)e=D.filter(e=>!e.tag_uid&&!e.archived_at);else if(l===`replace`)e=D.filter(e=>(e.tag_uid||e.tray_uuid)&&!e.archived_at);else return[];if(h){let t=h.toLowerCase();e=e.filter(e=>e.material?.toLowerCase().includes(t)||M(e)?.toLowerCase().includes(t)||e.color_name?.toLowerCase().includes(t)||e.brand?.toLowerCase().includes(t)||e.subtype?.toLowerCase().includes(t))}return e},[D,l,h,t]),B=(0,A.useCallback)(e=>{let t=e.detail;(t.sak??t.data?.sak)===0&&(C(!0),w(t.tag_uid??t.data?.tag_uid??null))},[]),V=(0,A.useCallback)(e=>{let t=e.detail;C(!0),w(t.tag_uid??t.data?.tag_uid??null)},[]),H=(0,A.useCallback)(()=>{C(!1),w(null)},[]),U=(0,A.useCallback)(t=>{let n=t.detail;(n.spool_id===f?.id||n.data?.spool_id===f?.id)&&(y(`success`),b(e(`spoolbuddy.writeTag.writeSuccess`,`Tag written successfully!`)),O(),setTimeout(()=>{y(`idle`),m(null),b(``)},5e3))},[f,e,O]),W=(0,A.useCallback)(t=>{let n=t.detail;(n.spool_id===f?.id||n.data?.spool_id===f?.id)&&(y(`error`),b(n.message??n.data?.message??e(`spoolbuddy.writeTag.writeFailed`,`Write failed`)))},[f,e]);(0,A.useEffect)(()=>(window.addEventListener(`spoolbuddy-unknown-tag`,B),window.addEventListener(`spoolbuddy-tag-matched`,V),window.addEventListener(`spoolbuddy-tag-removed`,H),window.addEventListener(`spoolbuddy-tag-written`,U),window.addEventListener(`spoolbuddy-tag-write-failed`,W),()=>{window.removeEventListener(`spoolbuddy-unknown-tag`,B),window.removeEventListener(`spoolbuddy-tag-matched`,V),window.removeEventListener(`spoolbuddy-tag-removed`,H),window.removeEventListener(`spoolbuddy-tag-written`,U),window.removeEventListener(`spoolbuddy-tag-write-failed`,W)}),[B,V,H,U,W]),(0,A.useEffect)(()=>{m(null),y(`idle`),b(``),_(``)},[l]);let G=async()=>{if(!(!f||!N)){y(`writing`),b(e(`spoolbuddy.writeTag.waiting`,`Waiting for SpoolBuddy...`));try{let e=await i.writeTag(N.device_id,f.id);if(e?.warnings?.length)for(let t of e.warnings)n(t,`warning`)}catch{y(`error`),b(e(`spoolbuddy.writeTag.queueFailed`,`Failed to queue write command`))}}},oe=async()=>{if(N){try{await i.cancelWrite(N.device_id)}catch{}y(`idle`),b(``)}},K=async()=>{if(!(!f||!F(f))){S(!0),y(`idle`),b(``);try{E?await r.linkTagToSpoolmanSpool(f.id,{tag_uid:``,tray_uuid:``}):await r.linkTagToSpool(f.id,{tag_uid:``,tray_uuid:``,data_origin:`manual`}),await O(),m(null),y(`success`),b(e(`spoolbuddy.writeTag.untagSuccess`,`Tag removed from spool`)),setTimeout(()=>{y(`idle`),b(``)},2500)}catch{y(`error`),b(e(`spoolbuddy.writeTag.untagFailed`,`Failed to remove tag from spool`))}finally{S(!1)}}},q=(0,A.useCallback)(e=>{m(e),y(`idle`),b(``),O()},[O]),se=f&&P&&v!==`writing`&&v!==`success`;return(0,j.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,j.jsx)(`div`,{className:`flex border-b border-bambu-dark-tertiary shrink-0`,children:[{key:`existing`,label:e(`spoolbuddy.writeTag.tabExisting`,`Existing Spool`)},{key:`new`,label:e(`spoolbuddy.writeTag.tabNew`,`New Spool`)},{key:`replace`,label:e(`spoolbuddy.writeTag.tabReplace`,`Replace Tag`)}].map(e=>(0,j.jsx)(`button`,{onClick:()=>d(e.key),className:`flex-1 py-3 text-sm font-medium transition-colors ${l===e.key?`text-bambu-green border-b-2 border-bambu-green bg-bambu-dark`:`text-zinc-400 hover:text-zinc-200 hover:bg-bambu-dark-tertiary`}`,children:e.label},e.key))}),(0,j.jsxs)(`div`,{className:`flex flex-1 overflow-hidden`,children:[(0,j.jsx)(`div`,{className:`flex-1 flex flex-col overflow-hidden border-r border-bambu-dark-tertiary`,children:l===`new`?(0,j.jsx)(L,{currencySymbol:R,onCreated:q,selectedSpool:f,spoolmanMode:E,t:e}):(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(`div`,{className:`p-3 shrink-0`,children:(0,j.jsx)(`input`,{type:`text`,value:h,onChange:e=>_(e.target.value),placeholder:e(`spoolbuddy.writeTag.searchPlaceholder`,`Search by material, color, brand...`),className:`w-full px-3 py-2 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-sm text-white placeholder-zinc-500 focus:outline-none focus:border-bambu-green`})}),(0,j.jsx)(`div`,{className:`flex-1 overflow-y-auto px-3 pb-3 space-y-2`,children:z.length===0?(0,j.jsx)(`div`,{className:`text-center text-zinc-500 py-8 text-sm`,children:l===`existing`?e(`spoolbuddy.writeTag.noUntaggedSpools`,`No spools without tags`):e(`spoolbuddy.writeTag.noTaggedSpools`,`No spools with tags`)}):z.map(e=>(0,j.jsx)(I,{spool:e,selected:f?.id===e.id,showTag:l===`replace`,onClick:()=>{m(e),y(`idle`),b(``)}},e.id))})]})}),(0,j.jsx)(`div`,{className:`w-[340px] flex flex-col items-center justify-center p-6 shrink-0`,children:(0,j.jsx)(ae,{writeStatus:v,writeMessage:ee,selectedSpool:f,tagOnReader:te,tagUid:ne,deviceOnline:P,canWrite:!!se,isReplace:l===`replace`,canUntag:l===`replace`&&!!f&&F(f),untagging:x,onWrite:G,onUntag:K,onCancel:oe,onRetry:()=>{y(`idle`),b(``)},t:e})})]})]})}function F(e){return!!(e.tag_uid||e.tray_uuid)}function I({spool:e,selected:t,showTag:n,onClick:r}){let i=Math.max(0,e.label_weight-e.weight_used),a=e.label_weight>0?Math.round(i/e.label_weight*100):0;return(0,j.jsxs)(`button`,{onClick:r,className:`w-full flex items-center gap-3 p-3 rounded-lg text-left transition-colors ${t?`bg-bambu-green/15 border border-bambu-green/50`:`bg-bambu-dark-secondary hover:bg-bambu-dark-tertiary border border-transparent`}`,children:[(0,j.jsx)(`div`,{className:`w-8 h-8 rounded-full shrink-0 border border-white/10`,style:k(e)??(e.rgba?h(e.rgba):{backgroundColor:`#666`})}),(0,j.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,j.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,j.jsxs)(`span`,{className:`text-sm font-medium text-white truncate`,children:[e.brand?`${e.brand} `:``,e.material,e.subtype?` ${e.subtype}`:``]}),(0,j.jsxs)(`span`,{className:`text-[10px] font-mono text-zinc-500 shrink-0`,children:[`#`,e.id]})]}),(0,j.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-zinc-400`,children:[M(e)&&(0,j.jsx)(`span`,{children:M(e)}),(0,j.jsxs)(`span`,{children:[i,`g / `,e.label_weight,`g (`,a,`%)`]})]}),n&&e.tag_uid&&(0,j.jsx)(`div`,{className:`text-xs text-zinc-500 mt-0.5 font-mono`,children:e.tag_uid})]}),t&&(0,j.jsx)(`svg`,{className:`w-5 h-5 text-bambu-green shrink-0`,fill:`currentColor`,viewBox:`0 0 20 20`,children:(0,j.jsx)(`path`,{fillRule:`evenodd`,d:`M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z`,clipRule:`evenodd`})})]})}function L({currencySymbol:e,onCreated:t,selectedSpool:n,spoolmanMode:i,t:a}){let{data:s=[]}=o({queryKey:[i?`spoolman-inventory-spools`:`inventory-spools`,`write-tag-form`],queryFn:()=>i?r.getSpoolmanInventorySpools(!0):r.getSpools(!0)}),{data:c}=o({queryKey:[`settings`],queryFn:r.getSettings}),[l,u]=(0,A.useState)(`simple`),[d,p]=(0,A.useState)(`filament`),[m,g]=(0,A.useState)(v),[w,P]=(0,A.useState)(!1),[F,I]=(0,A.useState)({}),[L,ae]=(0,A.useState)(!1),[R,z]=(0,A.useState)(1),[B,V]=(0,A.useState)(!1),[H,U]=(0,A.useState)(null),[W,G]=(0,A.useState)(!1),[oe,K]=(0,A.useState)(!1),[q,se]=(0,A.useState)([]),[J,ce]=(0,A.useState)([]),[le,ue]=(0,A.useState)([]),[de,fe]=(0,A.useState)([]),[Y,pe]=(0,A.useState)([]),[me,he]=(0,A.useState)(``),[ge,_e]=(0,A.useState)([]),[X,ve]=(0,A.useState)([]),[Z,ye]=(0,A.useState)(new Set),[be,xe]=(0,A.useState)(new Set);(0,A.useEffect)(()=>{_e(re())},[]),(0,A.useEffect)(()=>{let e=!1;return(async()=>{if(l===`full`){K(!0);try{let[t,n]=await Promise.allSettled([(async()=>(await r.getCloudStatus()).is_authenticated?{connected:!0,presets:await r.getFilamentPresets()}:{connected:!1,presets:[]})(),(async()=>(await r.orcaCloudStatus()).connected?{connected:!0,presets:(await r.orcaCloudListProfiles()).filament}:{connected:!1,presets:[]})()]);if(e)return;let i=t.status===`fulfilled`&&t.value.connected,a=n.status===`fulfilled`&&n.value.connected,o=t.status===`fulfilled`?t.value.presets:[],s=n.status===`fulfilled`?n.value.presets:[];G(i||a),se([...o,...s])}catch{e||G(!1)}finally{e||K(!1)}r.getSpoolCatalog().then(t=>{e||fe(t)}).catch(()=>void 0),r.getColorCatalog().then(t=>{e||pe(t)}).catch(()=>void 0),r.getLocalPresets().then(t=>{e||ce(t.filament)}).catch(()=>void 0),r.getBuiltinFilaments().then(t=>{e||ue(t)}).catch(()=>void 0);try{let t=await r.getPrinters(),n=await Promise.all(t.map(e=>r.getPrinterStatus(e.id).catch(()=>null))),i=[];for(let e=0;e{e=!0}},[l]),(0,A.useEffect)(()=>{X.length>0&&xe(new Set(X.map(e=>String(e.printer.id))))},[X]);let Se=(0,A.useMemo)(()=>E(q,new Set,J,le),[q,J,le]),Ce=(0,A.useMemo)(()=>te(m.slicer_filament,Se),[m.slicer_filament,Se]),we=(0,A.useMemo)(()=>{let e=ne(q,J),t=Y.map(e=>e.manufacturer?.trim()).filter(e=>!!e);return Array.from(new Set([...e,...t])).sort((e,t)=>e.localeCompare(t))},[q,J,Y]),Te=(0,A.useMemo)(()=>{let e=Y.map(e=>e.material?.trim()).filter(e=>!!e);return Array.from(new Set([...O,...e])).sort((e,t)=>e.localeCompare(t))},[Y]),Q=(0,A.useMemo)(()=>{let e=[];for(let t of Y){let n=t.manufacturer?.trim(),r=t.material?.trim();n&&r&&e.push({brand:n,material:r})}for(let t of q){let n=D(t.name);n.brand&&n.material&&e.push({brand:n.brand,material:n.material})}for(let t of J){let n=D(t.name),r=t.filament_vendor?.trim()||n.brand,i=n.material;r&&i&&e.push({brand:r,material:i})}return e},[q,Y,J]),Ee=(0,A.useMemo)(()=>{let e=new Map;for(let t of Q){let n=t.brand.toLowerCase(),r=t.material.toLowerCase();e.has(n)||e.set(n,new Set),e.get(n).add(r)}return e},[Q]),De=(0,A.useMemo)(()=>{let e=new Map;for(let t of Q){let n=t.brand.toLowerCase(),r=t.material.toLowerCase();e.has(r)||e.set(r,new Set),e.get(r).add(n)}return e},[Q]),Oe=(0,A.useMemo)(()=>C(we,m.brand),[we,m.brand]),ke=(0,A.useMemo)(()=>C(Te,m.material),[Te,m.material]),Ae=(0,A.useMemo)(()=>x(Oe,m.material,De),[Oe,m.material,De]),je=(0,A.useMemo)(()=>x(ke,m.brand,Ee),[ke,m.brand,Ee]),$=(e,t)=>{g(n=>({...n,[e]:t})),e===`core_weight`&&P(!0),F[e]&&I(t=>({...t,[e]:void 0}))},Me=e=>{_e(t=>S(e,t))},Ne=async e=>{let t=i?r.saveSpoolmanKProfiles:r.saveSpoolKProfiles;if(Z.size===0){try{await t(e,[])}catch{}return}let n=[];for(let e of Z){let[t,r,i]=e.split(`:`),a=parseInt(t),o=parseInt(r),s=i===`null`?0:parseInt(i),c=X.find(e=>e.printer.id===a);if(c){let e=c.calibrations.find(e=>e.cali_idx===o&&(e.extruder_id??0)===s);e&&n.push({printer_id:a,extruder:s,nozzle_diameter:e.nozzle_diameter||`0.4`,k_value:e.k_value,name:e.name||null,cali_idx:e.cali_idx,setting_id:e.setting_id||null})}}n.length>0&&await t(e,n)},Pe=async()=>{U(null);let e=ee(m,l===`simple`?!0:L);if(!e.isValid){I(e.errors),p(`filament`);return}let n=Ce?.displayName||me||null,o={material:m.material,subtype:m.subtype||null,brand:m.brand||null,color_name:m.color_name||null,rgba:m.rgba||null,extra_colors:m.extra_colors||null,effect_type:m.effect_type||null,label_weight:m.label_weight,...i?w?{core_weight:m.core_weight}:{}:{core_weight:m.core_weight,core_weight_catalog_id:m.core_weight_catalog_id},weight_used:m.weight_used,slicer_filament:m.slicer_filament||null,slicer_filament_name:n,nozzle_temp_min:null,nozzle_temp_max:null,note:m.note||null,cost_per_kg:m.cost_per_kg,added_full:null,last_used:null,encode_time:null,tag_uid:null,tray_uuid:null,data_origin:null,tag_type:null,last_scale_weight:null,last_weighed_at:null,category:m.category.trim()||null,low_stock_threshold_pct:m.low_stock_threshold_pct,material_number:m.material_number.trim()||null};V(!0);try{if(R>1){let e=i?await r.bulkCreateSpoolmanInventorySpools(o,R):await r.bulkCreateSpools(o,R),n=i&&e&&typeof e==`object`&&`created`in e?e.created:e;for(let e of n)await Ne(e.id);n.length>0&&t(n[0])}else{let e=i?await r.createSpoolmanInventorySpool(o):await r.createSpool(o);await Ne(e.id),t(e)}}catch{U(a(`spoolbuddy.writeTag.createFailed`,`Failed to create spool`))}finally{V(!1)}},Fe=`#${(m.rgba||`808080FF`).slice(0,6)}`;return(0,j.jsxs)(`div`,{className:`p-3 space-y-3 overflow-y-auto h-full`,children:[(0,j.jsxs)(`div`,{className:`flex items-center justify-between px-2 py-2 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary`,children:[(0,j.jsx)(`span`,{className:`text-sm text-zinc-200`,children:a(`spoolbuddy.writeTag.viewMode`,`View`)}),(0,j.jsxs)(`div`,{className:`flex rounded-lg overflow-hidden border border-bambu-dark-tertiary`,children:[(0,j.jsx)(`button`,{type:`button`,onClick:()=>u(`simple`),className:`px-3 py-1.5 text-xs font-medium ${l===`simple`?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark text-zinc-400`}`,children:a(`spoolbuddy.writeTag.simpleView`,`Simple`)}),(0,j.jsx)(`button`,{type:`button`,onClick:()=>u(`full`),className:`px-3 py-1.5 text-xs font-medium ${l===`full`?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark text-zinc-400`}`,children:a(`spoolbuddy.writeTag.fullView`,`Full`)})]})]}),l===`simple`?n?(0,j.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full p-6 text-center bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg`,children:[(0,j.jsx)(`div`,{className:`w-12 h-12 rounded-full mb-4 border border-white/10`,style:k(n,`preview`)??(n.rgba?h(n.rgba):{backgroundColor:`#666`})}),(0,j.jsxs)(`p`,{className:`text-white font-medium`,children:[n.brand?`${n.brand} `:``,n.material]}),M(n)&&(0,j.jsx)(`p`,{className:`text-zinc-400 text-sm`,children:M(n)}),(0,j.jsxs)(`p`,{className:`text-zinc-500 text-xs mt-1`,children:[n.label_weight,`g`]}),(0,j.jsx)(`p`,{className:`text-bambu-green text-sm mt-4`,children:a(`spoolbuddy.writeTag.spoolCreated`,`Spool created! Ready to write.`)})]}):(0,j.jsxs)(`div`,{className:`p-4 space-y-4 overflow-y-auto bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg`,children:[(0,j.jsxs)(`div`,{children:[(0,j.jsx)(`label`,{className:`block text-xs text-zinc-400 mb-1`,children:a(`spoolbuddy.writeTag.material`,`Material`)}),(0,j.jsx)(`select`,{value:m.material,onChange:e=>$(`material`,e.target.value),className:`w-full px-3 py-2 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-sm text-white focus:outline-none focus:border-bambu-green`,children:N.map(e=>(0,j.jsx)(`option`,{value:e,children:e},e))})]}),(0,j.jsxs)(`div`,{className:`flex gap-3`,children:[(0,j.jsxs)(`div`,{className:`flex-1`,children:[(0,j.jsx)(`label`,{className:`block text-xs text-zinc-400 mb-1`,children:a(`spoolbuddy.writeTag.colorName`,`Color Name`)}),(0,j.jsx)(`input`,{type:`text`,value:m.color_name,onChange:e=>$(`color_name`,e.target.value),placeholder:`Jade White`,className:`w-full px-3 py-2 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-sm text-white placeholder-zinc-500 focus:outline-none focus:border-bambu-green`})]}),(0,j.jsxs)(`div`,{children:[(0,j.jsx)(`label`,{className:`block text-xs text-zinc-400 mb-1`,children:a(`spoolbuddy.writeTag.color`,`Color`)}),(0,j.jsx)(`input`,{type:`color`,value:Fe,onChange:e=>$(`rgba`,e.target.value.replace(`#`,``).toUpperCase()+`FF`),className:`w-10 h-9 bg-transparent border border-bambu-dark-tertiary rounded cursor-pointer`})]})]}),(0,j.jsxs)(`div`,{children:[(0,j.jsx)(`label`,{className:`block text-xs text-zinc-400 mb-1`,children:a(`spoolbuddy.writeTag.brand`,`Brand`)}),(0,j.jsx)(`input`,{type:`text`,value:m.brand,onChange:e=>$(`brand`,e.target.value),placeholder:`Polymaker`,className:`w-full px-3 py-2 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-sm text-white placeholder-zinc-500 focus:outline-none focus:border-bambu-green`})]}),(0,j.jsxs)(`div`,{children:[(0,j.jsx)(`label`,{className:`block text-xs text-zinc-400 mb-1`,children:a(`spoolbuddy.writeTag.weight`,`Weight (g)`)}),(0,j.jsx)(f,{value:m.label_weight,onChange:e=>$(`label_weight`,e),fallback:0,min:0,max:1e4,className:`w-full px-3 py-2 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-sm text-white focus:outline-none focus:border-bambu-green`})]}),(0,j.jsx)(`button`,{onClick:Pe,disabled:B||!m.material,className:`w-full py-2.5 bg-bambu-green hover:bg-bambu-green/80 disabled:opacity-50 disabled:cursor-not-allowed text-white text-sm font-medium rounded transition-colors`,children:B?a(`spoolbuddy.writeTag.creating`,`Creating...`):a(`spoolbuddy.writeTag.createSpool`,`Create Spool`)})]}):(0,j.jsxs)(j.Fragment,{children:[(0,j.jsxs)(`div`,{className:`flex items-center justify-between px-2 py-2 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary`,children:[(0,j.jsx)(`span`,{className:`text-sm text-zinc-200`,children:a(`inventory.quickAdd`,`Quick Add`)}),(0,j.jsx)(`button`,{type:`button`,onClick:()=>ae(e=>!e),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors ${L?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,children:(0,j.jsx)(`span`,{className:`inline-block h-4.5 w-4.5 rounded-full bg-white transition-transform ${L?`translate-x-6`:`translate-x-1`}`})})]}),(0,j.jsxs)(`div`,{className:`flex border border-bambu-dark-tertiary rounded-lg overflow-hidden`,children:[(0,j.jsx)(`button`,{onClick:()=>p(`filament`),className:`flex-1 py-2.5 text-sm font-medium ${d===`filament`?`bg-bambu-green/15 text-bambu-green`:`bg-bambu-dark-secondary text-zinc-400`}`,children:a(`inventory.filamentInfoTab`,`Filament`)}),!L&&(0,j.jsx)(`button`,{onClick:()=>p(`pa-profile`),className:`flex-1 py-2.5 text-sm font-medium ${d===`pa-profile`?`bg-bambu-green/15 text-bambu-green`:`bg-bambu-dark-secondary text-zinc-400`}`,children:a(`inventory.paProfileTab`,`PA Profile`)})]}),(0,j.jsx)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg p-3`,children:d===`filament`?(0,j.jsxs)(`div`,{className:`space-y-4`,children:[(0,j.jsx)(y,{formData:m,updateField:$,cloudAuthenticated:W,loadingCloudPresets:oe,presetInputValue:me,setPresetInputValue:he,selectedPresetOption:Ce,filamentOptions:Se,availableBrands:Oe,availableMaterials:ke,suggestedBrands:Ae,suggestedMaterials:je,quickAdd:L,detailsRequired:!L,quantity:R,onQuantityChange:z,errors:F}),(0,j.jsx)(_,{formData:m,updateField:$,recentColors:ge,onColorUsed:Me,catalogColors:Y}),(0,j.jsx)(b,{formData:m,updateField:$,spoolCatalog:de,currencySymbol:e,availableCategories:Array.from(new Set(s.map(e=>e.category?.trim()).filter(e=>!!e))).sort((e,t)=>e.localeCompare(t)),availableMaterialNumbers:Array.from(new Set(s.map(e=>e.material_number?.trim()).filter(e=>!!e))).sort((e,t)=>e.localeCompare(t,void 0,{numeric:!0})),globalLowStockThreshold:c?.low_stock_threshold??20,spoolmanMode:i})]}):(0,j.jsx)(ie,{formData:m,updateField:$,printersWithCalibrations:X,selectedProfiles:Z,setSelectedProfiles:ye,expandedPrinters:be,setExpandedPrinters:xe})})]}),H&&(0,j.jsx)(`div`,{className:`text-sm text-red-400 bg-red-900/20 border border-red-900/40 rounded-lg px-3 py-2`,children:H}),l===`full`&&(0,j.jsx)(`button`,{onClick:Pe,disabled:B,className:`w-full py-3 bg-bambu-green hover:bg-bambu-green/80 disabled:opacity-50 disabled:cursor-not-allowed text-white text-sm font-medium rounded transition-colors`,children:B?a(`spoolbuddy.writeTag.creating`,`Creating...`):a(`spoolbuddy.writeTag.createSpool`,`Create Spool`)}),l===`full`&&n&&(0,j.jsxs)(`div`,{className:`flex flex-col items-center justify-center p-4 text-center bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg`,children:[(0,j.jsx)(`div`,{className:`w-12 h-12 rounded-full mb-4 border border-white/10`,style:k(n,`preview`)??(n.rgba?h(n.rgba):{backgroundColor:`#666`})}),(0,j.jsxs)(`p`,{className:`text-white font-medium`,children:[n.brand?`${n.brand} `:``,n.material]}),M(n)&&(0,j.jsx)(`p`,{className:`text-zinc-400 text-sm`,children:M(n)}),(0,j.jsxs)(`p`,{className:`text-zinc-500 text-xs mt-1`,children:[n.label_weight,`g`]}),(0,j.jsx)(`p`,{className:`text-bambu-green text-sm mt-4`,children:a(`spoolbuddy.writeTag.spoolCreated`,`Spool created! Ready to write.`)})]})]})}function ae({writeStatus:e,writeMessage:t,selectedSpool:n,tagOnReader:r,tagUid:i,deviceOnline:a,canWrite:o,isReplace:s,canUntag:c,untagging:l,onWrite:u,onUntag:d,onCancel:f,onRetry:p,t:m}){if(e===`success`)return(0,j.jsxs)(`div`,{className:`flex flex-col items-center text-center space-y-4`,children:[(0,j.jsx)(`div`,{className:`w-16 h-16 rounded-full bg-green-500/20 flex items-center justify-center`,children:(0,j.jsx)(`svg`,{className:`w-8 h-8 text-green-400`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,j.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M5 13l4 4L19 7`})})}),(0,j.jsx)(`p`,{className:`text-green-400 font-medium`,children:t}),n&&(0,j.jsxs)(`p`,{className:`text-zinc-400 text-sm`,children:[n.brand?`${n.brand} `:``,n.material,n.subtype?` ${n.subtype}`:``,M(n)?` - ${M(n)}`:``]})]});if(e===`error`)return(0,j.jsxs)(`div`,{className:`flex flex-col items-center text-center space-y-4`,children:[(0,j.jsx)(`div`,{className:`w-16 h-16 rounded-full bg-red-500/20 flex items-center justify-center`,children:(0,j.jsx)(`svg`,{className:`w-8 h-8 text-red-400`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,j.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M6 18L18 6M6 6l12 12`})})}),(0,j.jsx)(`p`,{className:`text-red-400 font-medium`,children:t}),(0,j.jsx)(`button`,{onClick:p,className:`px-4 py-2 bg-bambu-dark-tertiary hover:bg-bambu-dark-secondary text-white text-sm rounded transition-colors`,children:m(`spoolbuddy.writeTag.tryAgain`,`Try Again`)})]});if(e===`writing`)return(0,j.jsxs)(`div`,{className:`flex flex-col items-center text-center space-y-4`,children:[(0,j.jsxs)(`div`,{className:`relative w-16 h-16`,children:[(0,j.jsx)(`div`,{className:`absolute inset-0 rounded-full border-2 border-bambu-green/30 animate-ping`}),(0,j.jsx)(`div`,{className:`absolute inset-2 rounded-full border-2 border-bambu-green/50 animate-pulse`}),(0,j.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center`,children:(0,j.jsx)(R,{className:`w-8 h-8 text-bambu-green`})})]}),(0,j.jsx)(`p`,{className:`text-bambu-green font-medium`,children:m(`spoolbuddy.writeTag.writing`,`Writing tag...`)}),(0,j.jsx)(`p`,{className:`text-zinc-500 text-xs`,children:t}),(0,j.jsx)(`button`,{onClick:f,className:`px-4 py-2 bg-bambu-dark-tertiary hover:bg-bambu-dark-secondary text-zinc-400 text-sm rounded transition-colors`,children:m(`spoolbuddy.writeTag.cancel`,`Cancel`)})]});if(!a)return(0,j.jsxs)(`div`,{className:`flex flex-col items-center text-center space-y-3`,children:[(0,j.jsx)(R,{className:`w-12 h-12 text-zinc-600`}),(0,j.jsx)(`p`,{className:`text-zinc-500 text-sm`,children:m(`spoolbuddy.writeTag.deviceOffline`,`SpoolBuddy is offline`)})]});if(!n)return(0,j.jsxs)(`div`,{className:`flex flex-col items-center text-center space-y-3`,children:[(0,j.jsx)(R,{className:`w-12 h-12 text-zinc-600`}),(0,j.jsx)(`p`,{className:`text-zinc-400 text-sm`,children:m(`spoolbuddy.writeTag.selectSpool`,`Select a spool, then place a blank NTAG on the reader`)})]});let g=k(n,`preview`)??(n.rgba?h(n.rgba):{backgroundColor:`#666`});return(0,j.jsxs)(`div`,{className:`flex flex-col items-center text-center space-y-4 w-full`,children:[(0,j.jsx)(`div`,{className:`relative w-16 h-16`,children:r?(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(`div`,{className:`absolute inset-0 rounded-full bg-bambu-green/10`}),(0,j.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center`,children:(0,j.jsx)(R,{className:`w-8 h-8 text-bambu-green`})})]}):(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(`div`,{className:`absolute inset-0 rounded-full border-2 border-zinc-600 animate-pulse`}),(0,j.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center`,children:(0,j.jsx)(R,{className:`w-8 h-8 text-zinc-500`})})]})}),r?(0,j.jsxs)(`div`,{className:`space-y-1`,children:[(0,j.jsx)(`p`,{className:`text-bambu-green text-sm font-medium`,children:m(`spoolbuddy.writeTag.tagReady`,`Tag detected — ready to write`)}),i&&(0,j.jsx)(`p`,{className:`text-zinc-500 text-xs font-mono`,children:i})]}):(0,j.jsx)(`p`,{className:`text-zinc-400 text-sm`,children:m(`spoolbuddy.writeTag.placeTag`,`Place an NTAG on the reader`)}),(0,j.jsxs)(`div`,{className:`w-full bg-bambu-dark-secondary rounded-lg p-3 space-y-2`,children:[(0,j.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,j.jsx)(`div`,{className:`w-8 h-8 rounded-full border border-white/10 shrink-0`,style:g}),(0,j.jsxs)(`div`,{className:`text-left min-w-0`,children:[(0,j.jsxs)(`p`,{className:`text-white text-sm font-medium truncate`,children:[n.brand?`${n.brand} `:``,n.material]}),M(n)&&(0,j.jsx)(`p`,{className:`text-zinc-400 text-xs`,children:M(n)})]})]}),(0,j.jsxs)(`div`,{className:`text-xs text-zinc-500`,children:[n.label_weight,`g`]})]}),s&&n.tag_uid&&(0,j.jsx)(`p`,{className:`text-yellow-500/80 text-xs`,children:m(`spoolbuddy.writeTag.replaceWarning`,`Old tag will be unlinked. New tag will replace it.`)}),(0,j.jsx)(`button`,{onClick:u,disabled:!o,className:`w-full py-3 bg-bambu-green hover:bg-bambu-green/80 disabled:opacity-40 disabled:cursor-not-allowed text-white font-medium rounded-lg transition-colors text-sm`,children:s?m(`spoolbuddy.writeTag.replaceTag`,`Replace Tag`):m(`spoolbuddy.writeTag.writeTag`,`Write Tag`)}),s&&c&&(0,j.jsx)(`button`,{onClick:d,disabled:l,className:`w-full py-2.5 bg-bambu-dark-tertiary hover:bg-bambu-dark-secondary disabled:opacity-40 disabled:cursor-not-allowed text-zinc-200 rounded-lg transition-colors text-sm`,children:l?m(`spoolbuddy.writeTag.untagging`,`Removing tag...`):m(`spoolbuddy.writeTag.untagSpool`,`Untag Selected Spool`)})]})}function R({className:e}){return(0,j.jsxs)(`svg`,{className:e,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:1.5,children:[(0,j.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M8.288 15.038a5.25 5.25 0 017.424 0M5.106 11.856c3.807-3.808 9.98-3.808 13.788 0M1.924 8.674c5.565-5.565 14.587-5.565 20.152 0`}),(0,j.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M12.53 18.22l-.53.53-.53-.53a.75.75 0 011.06 0z`})]})}export{P as SpoolBuddyWriteTagPage}; \ No newline at end of file diff --git a/static/assets/SpreadsheetPreviewModal-CVALSyS0.js b/static/assets/SpreadsheetPreviewModal-KGR-XjV_.js similarity index 98% rename from static/assets/SpreadsheetPreviewModal-CVALSyS0.js rename to static/assets/SpreadsheetPreviewModal-KGR-XjV_.js index 19b7e8cba..8fcf71288 100644 --- a/static/assets/SpreadsheetPreviewModal-CVALSyS0.js +++ b/static/assets/SpreadsheetPreviewModal-KGR-XjV_.js @@ -1,2 +1,2 @@ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/papaparse.min-CR43Mv99.js","assets/chunk-aKtaBQYM.js"])))=>i.map(i=>d[i]); -import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,l as i,w as a}from"./client-DnySrlFv.js";import{t as o}from"./file-spreadsheet-WxOA9vYy.js";import{t as s}from"./loader-circle-BEmFtawu.js";import{t as c}from"./file-DDkFXH-b.js";import{Kn as l}from"./index-0t--Yqoi.js";import{n as u,t as d}from"./usePreviewFullscreen-ButueZqN.js";var f=e(n(),1),p=t(),m=500,h=40;function g(e){let t=``,n=e;for(;n>=0;)t=String.fromCharCode(65+n%26)+t,n=Math.floor(n/26)-1;return t}function _(e){let t=document.createElement(`canvas`);t.width=256,t.height=256;let n=t.getContext(`2d`);if(!n)return Promise.resolve(null);let r=256/5,i=256/9;n.fillStyle=`#1a1a1a`,n.fillRect(0,0,256,256),n.fillStyle=`rgba(0, 174, 66, 0.25)`,n.fillRect(0,0,256,i),n.strokeStyle=`#333333`,n.lineWidth=1;for(let e=1;e<5;e++)n.beginPath(),n.moveTo(e*r+.5,0),n.lineTo(e*r+.5,256),n.stroke();for(let e=1;e<9;e++)n.beginPath(),n.moveTo(0,e*i+.5),n.lineTo(256,e*i+.5),n.stroke();n.fillStyle=`#d4d4d4`,n.font=`11px sans-serif`,n.textBaseline=`middle`;for(let t=0;t<9;t++)for(let a=0;a<5;a++){let o=e[t]?.[a];o&&n.fillText(String(o),a*r+4,t*i+i/2,r-8)}return new Promise(e=>t.toBlob(e,`image/png`))}function v({libraryFileId:t,filename:n,fileType:v,fileSize:y,onClose:b,onSnapshot:x}){let{t:S}=a(),[C,w]=(0,f.useState)(null),[T,E]=(0,f.useState)(0),[D,O]=(0,f.useState)(null),k=(0,f.useRef)(!1),A=(0,f.useRef)(x);(0,f.useEffect)(()=>{A.current=x});let j=d(),{isFullscreen:M,toggleFullscreen:N}=j;(0,f.useEffect)(()=>{let a=!1;if(w(null),O(null),E(0),y>20971520){O(S(`fileManager.preview.tooLarge`,{size:c(y)}));return}let o={},s=i();return s&&(o.Authorization=`Bearer ${s}`),(async()=>{let i=await fetch(r.getLibraryFileDownloadUrl(t),{headers:o});if(!i.ok)throw Error(`HTTP ${i.status}`);let s=await i.arrayBuffer(),c;if(v===`csv`){let t=(await l(async()=>{let{default:t}=await import(`./papaparse.min-CR43Mv99.js`).then(t=>e(t.default,1));return{default:t}},__vite__mapDeps([0,1]))).default,r=new TextDecoder().decode(s),i=[],a=0,o=0,u=[],d=e=>{a+=1,o=Math.max(o,e.length),i.lengthe??``))};t.parse(r,{skipEmptyLines:!1,step:({data:e})=>{if(Array.isArray(e)){if(e.every(e=>!e)){u.push(e);return}u.forEach(d),u=[],d(e)}}}),c=[{name:n,rows:i,totalRows:a,totalCols:o}]}else{let e=await l(()=>import(`./xlsx-CKkngM-o.js`),[]),t=e.read(s,{dense:!0});c=t.SheetNames.map(n=>{let r=t.Sheets[n],i=r?.[`!ref`];if(!r||!i)return{name:n,rows:[],totalRows:0,totalCols:0};let a=e.utils.decode_range(i),o=a.e.r-a.s.r+1,s=a.e.c-a.s.c+1,c={s:a.s,e:{r:Math.min(a.e.r,a.s.r+m-1),c:Math.min(a.e.c,a.s.c+h-1)}};return{name:n,rows:e.utils.sheet_to_json(r,{header:1,raw:!1,defval:``,range:e.utils.encode_range(c)}),totalRows:o,totalCols:s}})}if(!a&&(w(c),A.current&&!k.current)){let e=c.find(e=>e.rows.length>0);if(e){k.current=!0;let t=await _(e.rows);t&&!a&&A.current?.(t)}}})().catch(e=>{console.error(`[sheet-preview] load failed`,e),a||O(S(`fileManager.preview.error`))}),()=>{a=!0}},[t,v,y,n,S]);let P=C?.[T]??null,F=P!=null&&P.totalRows>P.rows.length,I=P!=null&&P.totalCols>h,L=P==null?0:Math.min(P.totalCols,h);return(0,p.jsxs)(u,{title:n,fullscreen:j,onClose:b,icon:(0,p.jsx)(o,{className:`w-5 h-5 text-bambu-green flex-shrink-0`}),children:[C&&C.length>1&&(0,p.jsx)(`div`,{className:`flex gap-1 px-4 pt-2 overflow-x-auto flex-shrink-0`,children:C.map((e,t)=>(0,p.jsx)(`button`,{onClick:()=>E(t),className:`px-3 py-1.5 text-sm rounded-t whitespace-nowrap transition-colors ${t===T?`bg-bambu-dark text-white border border-b-0 border-bambu-dark-tertiary`:`text-bambu-gray hover:text-white hover:bg-bambu-dark/50`}`,children:e.name},`${e.name}-${t}`))}),(0,p.jsx)(`div`,{"data-testid":`spreadsheet-preview-content`,className:`flex-1 min-h-0 overflow-auto bg-bambu-dark ${M?``:`rounded-b-lg`}`,onDoubleClick:N,children:D?(0,p.jsx)(`div`,{className:`h-full flex items-center justify-center p-6`,children:(0,p.jsx)(`p`,{className:`text-bambu-gray text-center`,children:D})}):C?!P||P.rows.length===0?(0,p.jsx)(`div`,{className:`h-full flex items-center justify-center p-6`,children:(0,p.jsx)(`p`,{className:`text-bambu-gray`,children:S(`fileManager.preview.emptySheet`)})}):(0,p.jsxs)(`table`,{className:`border-collapse text-xs min-w-full`,children:[(0,p.jsx)(`thead`,{children:(0,p.jsxs)(`tr`,{children:[(0,p.jsx)(`th`,{className:`sticky top-0 bg-bambu-dark-secondary border border-bambu-dark-tertiary px-2 py-1 text-bambu-gray font-medium w-10`}),Array.from({length:L},(e,t)=>(0,p.jsx)(`th`,{className:`sticky top-0 bg-bambu-dark-secondary border border-bambu-dark-tertiary px-2 py-1 text-bambu-gray font-medium text-left min-w-[80px]`,children:g(t)},t))]})}),(0,p.jsx)(`tbody`,{children:P.rows.map((e,t)=>(0,p.jsxs)(`tr`,{children:[(0,p.jsx)(`td`,{className:`border border-bambu-dark-tertiary px-2 py-1 text-bambu-gray text-right bg-bambu-dark-secondary/50`,children:t+1}),Array.from({length:L},(t,n)=>(0,p.jsx)(`td`,{className:`border border-bambu-dark-tertiary px-2 py-1 text-bambu-gray-light whitespace-nowrap max-w-[280px] overflow-hidden text-ellipsis`,title:e[n]||void 0,children:e[n]??``},n))]},t))})]}):(0,p.jsx)(`div`,{className:`h-full flex items-center justify-center`,children:(0,p.jsx)(s,{className:`w-8 h-8 text-bambu-green animate-spin`})})}),(F||I)&&P&&(0,p.jsxs)(`div`,{className:`px-4 py-2 border-t border-bambu-dark-tertiary text-xs text-bambu-gray flex gap-4 flex-shrink-0`,children:[F&&(0,p.jsx)(`span`,{children:S(`fileManager.preview.truncatedRows`,{shown:P.rows.length,total:P.totalRows})}),I&&(0,p.jsx)(`span`,{children:S(`fileManager.preview.truncatedCols`,{shown:L,total:P.totalCols})})]})]})}export{v as SpreadsheetPreviewModal}; \ No newline at end of file +import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,l as i,w as a}from"./client-DnySrlFv.js";import{t as o}from"./file-spreadsheet-WxOA9vYy.js";import{t as s}from"./loader-circle-BEmFtawu.js";import{t as c}from"./file-DDkFXH-b.js";import{Kn as l}from"./index-Cxa-KVmA.js";import{n as u,t as d}from"./usePreviewFullscreen-ButueZqN.js";var f=e(n(),1),p=t(),m=500,h=40;function g(e){let t=``,n=e;for(;n>=0;)t=String.fromCharCode(65+n%26)+t,n=Math.floor(n/26)-1;return t}function _(e){let t=document.createElement(`canvas`);t.width=256,t.height=256;let n=t.getContext(`2d`);if(!n)return Promise.resolve(null);let r=256/5,i=256/9;n.fillStyle=`#1a1a1a`,n.fillRect(0,0,256,256),n.fillStyle=`rgba(0, 174, 66, 0.25)`,n.fillRect(0,0,256,i),n.strokeStyle=`#333333`,n.lineWidth=1;for(let e=1;e<5;e++)n.beginPath(),n.moveTo(e*r+.5,0),n.lineTo(e*r+.5,256),n.stroke();for(let e=1;e<9;e++)n.beginPath(),n.moveTo(0,e*i+.5),n.lineTo(256,e*i+.5),n.stroke();n.fillStyle=`#d4d4d4`,n.font=`11px sans-serif`,n.textBaseline=`middle`;for(let t=0;t<9;t++)for(let a=0;a<5;a++){let o=e[t]?.[a];o&&n.fillText(String(o),a*r+4,t*i+i/2,r-8)}return new Promise(e=>t.toBlob(e,`image/png`))}function v({libraryFileId:t,filename:n,fileType:v,fileSize:y,onClose:b,onSnapshot:x}){let{t:S}=a(),[C,w]=(0,f.useState)(null),[T,E]=(0,f.useState)(0),[D,O]=(0,f.useState)(null),k=(0,f.useRef)(!1),A=(0,f.useRef)(x);(0,f.useEffect)(()=>{A.current=x});let j=d(),{isFullscreen:M,toggleFullscreen:N}=j;(0,f.useEffect)(()=>{let a=!1;if(w(null),O(null),E(0),y>20971520){O(S(`fileManager.preview.tooLarge`,{size:c(y)}));return}let o={},s=i();return s&&(o.Authorization=`Bearer ${s}`),(async()=>{let i=await fetch(r.getLibraryFileDownloadUrl(t),{headers:o});if(!i.ok)throw Error(`HTTP ${i.status}`);let s=await i.arrayBuffer(),c;if(v===`csv`){let t=(await l(async()=>{let{default:t}=await import(`./papaparse.min-CR43Mv99.js`).then(t=>e(t.default,1));return{default:t}},__vite__mapDeps([0,1]))).default,r=new TextDecoder().decode(s),i=[],a=0,o=0,u=[],d=e=>{a+=1,o=Math.max(o,e.length),i.lengthe??``))};t.parse(r,{skipEmptyLines:!1,step:({data:e})=>{if(Array.isArray(e)){if(e.every(e=>!e)){u.push(e);return}u.forEach(d),u=[],d(e)}}}),c=[{name:n,rows:i,totalRows:a,totalCols:o}]}else{let e=await l(()=>import(`./xlsx-CKkngM-o.js`),[]),t=e.read(s,{dense:!0});c=t.SheetNames.map(n=>{let r=t.Sheets[n],i=r?.[`!ref`];if(!r||!i)return{name:n,rows:[],totalRows:0,totalCols:0};let a=e.utils.decode_range(i),o=a.e.r-a.s.r+1,s=a.e.c-a.s.c+1,c={s:a.s,e:{r:Math.min(a.e.r,a.s.r+m-1),c:Math.min(a.e.c,a.s.c+h-1)}};return{name:n,rows:e.utils.sheet_to_json(r,{header:1,raw:!1,defval:``,range:e.utils.encode_range(c)}),totalRows:o,totalCols:s}})}if(!a&&(w(c),A.current&&!k.current)){let e=c.find(e=>e.rows.length>0);if(e){k.current=!0;let t=await _(e.rows);t&&!a&&A.current?.(t)}}})().catch(e=>{console.error(`[sheet-preview] load failed`,e),a||O(S(`fileManager.preview.error`))}),()=>{a=!0}},[t,v,y,n,S]);let P=C?.[T]??null,F=P!=null&&P.totalRows>P.rows.length,I=P!=null&&P.totalCols>h,L=P==null?0:Math.min(P.totalCols,h);return(0,p.jsxs)(u,{title:n,fullscreen:j,onClose:b,icon:(0,p.jsx)(o,{className:`w-5 h-5 text-bambu-green flex-shrink-0`}),children:[C&&C.length>1&&(0,p.jsx)(`div`,{className:`flex gap-1 px-4 pt-2 overflow-x-auto flex-shrink-0`,children:C.map((e,t)=>(0,p.jsx)(`button`,{onClick:()=>E(t),className:`px-3 py-1.5 text-sm rounded-t whitespace-nowrap transition-colors ${t===T?`bg-bambu-dark text-white border border-b-0 border-bambu-dark-tertiary`:`text-bambu-gray hover:text-white hover:bg-bambu-dark/50`}`,children:e.name},`${e.name}-${t}`))}),(0,p.jsx)(`div`,{"data-testid":`spreadsheet-preview-content`,className:`flex-1 min-h-0 overflow-auto bg-bambu-dark ${M?``:`rounded-b-lg`}`,onDoubleClick:N,children:D?(0,p.jsx)(`div`,{className:`h-full flex items-center justify-center p-6`,children:(0,p.jsx)(`p`,{className:`text-bambu-gray text-center`,children:D})}):C?!P||P.rows.length===0?(0,p.jsx)(`div`,{className:`h-full flex items-center justify-center p-6`,children:(0,p.jsx)(`p`,{className:`text-bambu-gray`,children:S(`fileManager.preview.emptySheet`)})}):(0,p.jsxs)(`table`,{className:`border-collapse text-xs min-w-full`,children:[(0,p.jsx)(`thead`,{children:(0,p.jsxs)(`tr`,{children:[(0,p.jsx)(`th`,{className:`sticky top-0 bg-bambu-dark-secondary border border-bambu-dark-tertiary px-2 py-1 text-bambu-gray font-medium w-10`}),Array.from({length:L},(e,t)=>(0,p.jsx)(`th`,{className:`sticky top-0 bg-bambu-dark-secondary border border-bambu-dark-tertiary px-2 py-1 text-bambu-gray font-medium text-left min-w-[80px]`,children:g(t)},t))]})}),(0,p.jsx)(`tbody`,{children:P.rows.map((e,t)=>(0,p.jsxs)(`tr`,{children:[(0,p.jsx)(`td`,{className:`border border-bambu-dark-tertiary px-2 py-1 text-bambu-gray text-right bg-bambu-dark-secondary/50`,children:t+1}),Array.from({length:L},(t,n)=>(0,p.jsx)(`td`,{className:`border border-bambu-dark-tertiary px-2 py-1 text-bambu-gray-light whitespace-nowrap max-w-[280px] overflow-hidden text-ellipsis`,title:e[n]||void 0,children:e[n]??``},n))]},t))})]}):(0,p.jsx)(`div`,{className:`h-full flex items-center justify-center`,children:(0,p.jsx)(s,{className:`w-8 h-8 text-bambu-green animate-spin`})})}),(F||I)&&P&&(0,p.jsxs)(`div`,{className:`px-4 py-2 border-t border-bambu-dark-tertiary text-xs text-bambu-gray flex gap-4 flex-shrink-0`,children:[F&&(0,p.jsx)(`span`,{children:S(`fileManager.preview.truncatedRows`,{shown:P.rows.length,total:P.totalRows})}),I&&(0,p.jsx)(`span`,{children:S(`fileManager.preview.truncatedCols`,{shown:L,total:P.totalCols})})]})]})}export{v as SpreadsheetPreviewModal}; \ No newline at end of file diff --git a/static/assets/StatsPage-CHDgcYiv.js b/static/assets/StatsPage-E-fXkkLD.js similarity index 99% rename from static/assets/StatsPage-CHDgcYiv.js rename to static/assets/StatsPage-E-fXkkLD.js index 599ae62c5..2e61f600c 100644 --- a/static/assets/StatsPage-CHDgcYiv.js +++ b/static/assets/StatsPage-E-fXkkLD.js @@ -1 +1 @@ -import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,w as i}from"./client-DnySrlFv.js";import{t as a}from"./useQuery-BBCjCezC.js";import{t as o}from"./createLucideIcon-DvBYJlWL.js";import{a as s,d as c,f as l,h as u,i as d,l as f,m as p,n as m,p as h,r as g,s as _,t as v,u as y}from"./sortable.esm-D2bGix-3.js";import{t as b}from"./calendar-BLKPnWqV.js";import{a as x,n as S}from"./info-ROUoQhJR.js";import{n as C,r as w}from"./ToastContext-BRX0SW3C.js";import{t as T}from"./dollar-sign-Cj_Yhud4.js";import{t as E}from"./eye-off-6CkaxYwP.js";import{t as ee}from"./file-spreadsheet-WxOA9vYy.js";import{t as D}from"./grip-vertical-C_1RDxRw.js";import{t as O}from"./loader-circle-BEmFtawu.js";import{t as k}from"./maximize-2-kPQ77q72.js";import{t as A}from"./minimize-2-dqT-k7oI.js";import{t as j}from"./package-BGUevlqS.js";import{t as M}from"./target-B40GQtrA.js";import{$ as te,$t as ne,A as re,An as ie,At as ae,Bt as oe,C as se,Cn as ce,Ct as le,D as ue,Dn as N,Dt as de,E as fe,En as pe,Et as me,Fn as he,G as ge,H as _e,I as ve,In as ye,It as be,J as xe,K as Se,Kt as Ce,L as P,Ln as we,Lt as Te,M as Ee,Mn as F,N as De,Nt as Oe,O as ke,On as Ae,Ot as je,Pt as Me,Q as Ne,Qt as Pe,R as Fe,Rn as Ie,S as Le,Sn as I,St as Re,T as ze,U as Be,Ut as L,V as Ve,W as He,X as Ue,Xt as R,Y as We,Z as Ge,Zt as Ke,_t as qe,a as Je,at as Ye,bt as Xe,c as Ze,cn as z,ct as Qe,d as $e,dn as et,dt as tt,en as nt,et as rt,f as it,ft as at,gn as B,hn as ot,i as st,in as ct,j as lt,kt as ut,l as dt,lt as ft,mn as V,mt as pt,n as mt,nn as ht,nt as gt,o as _t,on as vt,ot as H,p as yt,pt as bt,q as xt,r as St,rn as Ct,rt as wt,s as Tt,sn as Et,st as Dt,t as Ot,tn as kt,tt as At,un as jt,ut as Mt,v as Nt,vn as Pt,vt as Ft,w as It,wn as Lt,wt as Rt,xn as U,xt as zt,yn as Bt,yt as Vt,z as Ht}from"./CartesianChart-BAcHzPFb.js";import{t as Ut}from"./triangle-alert-Dt_1FcBy.js";import{t as W}from"./Button-DDr6eAFy.js";import{h as Wt,o as Gt,v as Kt}from"./date-G9KUauqz.js";import{Dt as qt,Gt as Jt,Nn as Yt,On as Xt,Sn as Zt,at as Qt,bt as $t,xn as en,xt as tn,yt as nn}from"./index-0t--Yqoi.js";import{t as rn}from"./filamentTypes-Dysa4k6j.js";import{n as an,t as on}from"./ErrorBarContext-CcijMMkA.js";import{i as G,n as sn,r as K,t as cn}from"./AreaChart-DJpIJXxF.js";var ln=o(`calculator`,[[`rect`,{width:`16`,height:`20`,x:`4`,y:`2`,rx:`2`,key:`1nb95v`}],[`line`,{x1:`8`,x2:`16`,y1:`6`,y2:`6`,key:`x4nwl0`}],[`line`,{x1:`16`,x2:`16`,y1:`14`,y2:`18`,key:`wjye3r`}],[`path`,{d:`M16 10h.01`,key:`1m94wz`}],[`path`,{d:`M12 10h.01`,key:`1nrarc`}],[`path`,{d:`M8 10h.01`,key:`19clt8`}],[`path`,{d:`M12 14h.01`,key:`1etili`}],[`path`,{d:`M8 14h.01`,key:`6423bh`}],[`path`,{d:`M12 18h.01`,key:`mhygvu`}],[`path`,{d:`M8 18h.01`,key:`lrp35t`}]]),un=e=>null;un.displayName=`Cell`;var dn=e=>e.graphicalItems.polarItems,fn=V([dn,H,V([zt,Xe],gt)],te),pn=V([V([fn],Ne),ut],Ue),mn=V([pn,H,fn],xt);V([pn,H,fn],(e,t,n)=>n.length>0?e.flatMap(e=>n.flatMap(n=>({value:z(e,t.dataKey??n.dataKey),errorDomain:[]}))).filter(Boolean):t?.dataKey==null?e.map(e=>({value:e,errorDomain:[]})):e.map(e=>({value:z(e,t.dataKey),errorDomain:[]})));var hn=()=>void 0,gn=V([H,L,pn,mn,je,zt,V([H,Qe,ft,hn,V([pn,H,fn,wt,zt],Ge),hn,L,zt],At)],xe);V([Mt,V([H,gn,V([gn,tt,Mt],rt),zt],We)],qe);function _n(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function vn(e){for(var t=1;tt],(e,t)=>e.filter(e=>e.type===`pie`).find(e=>e.id===t)),Cn=[],wn=(e,t,n)=>n?.length===0?Cn:n,Tn=V([ut,Sn,wn],(e,t,n)=>{var{chartData:r}=e;if(t!=null){var i=t?.data!=null&&t.data.length>0?t.data:r;if((!i||!i.length)&&n!=null&&(i=n.map(e=>vn(vn({},t.presentationProps),e.props))),i!=null)return i}}),En=V([Tn,Sn,wn],(e,t,n)=>{if(!(e==null||t==null))return e.map((e,r)=>{var i,a=z(e,t.nameKey,t.name),o=n!=null&&(i=n[r])!=null&&(i=i.props)!=null&&i.fill?n[r].props.fill:typeof e==`object`&&e&&`fill`in e?e.fill:t.fill;return{value:Et(a,t.dataKey),color:o,payload:e,type:t.legendType}})}),Dn=V([Tn,Sn,wn,ne],(e,t,n,r)=>{if(!(t==null||e==null))return $n({offset:r,pieSettings:t,displayedData:e,cells:n})}),On=(e,t,n)=>{var r=ot();return(i,a)=>o=>{e?.(i,a,o),r(Se({activeIndex:String(a),activeDataKey:t,activeCoordinate:i.tooltipPosition,activeGraphicalItemId:n}))}},kn=e=>{var t=ot();return(n,r)=>i=>{e?.(n,r,i),t(He())}},An=(e,t,n)=>{var r=ot();return(i,a)=>o=>{e?.(i,a,o),r(ge({activeIndex:String(a),activeDataKey:t,activeCoordinate:i.tooltipPosition,activeGraphicalItemId:n}))}},q=e(n()),jn=e(ie()),Mn=[`key`],Nn=[`onMouseEnter`,`onClick`,`onMouseLeave`],Pn=[`id`],Fn=[`id`];function In(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function J(e){for(var t=1;tke(e.children,un),[e.children]),n=B(n=>En(n,e.id,t));return n==null?null:q.createElement(fe,{legendPayload:n})}var Un=q.memo(e=>{var{dataKey:t,nameKey:n,sectors:r,stroke:i,strokeWidth:a,fill:o,name:s,hide:c,tooltipType:l,id:u}=e,d={dataDefinedOnItem:r.map(e=>e.tooltipPayload),getPosition:e=>r[Number(e)]?.tooltipPosition,settings:{stroke:i,strokeWidth:a,fill:o,dataKey:t,nameKey:n,name:Et(s,t),hide:c,type:l,color:o,unit:``,graphicalItemId:u}};return q.createElement(ue,{tooltipEntrySettings:d})}),Wn=(e,t)=>e>t?`start`:eU(typeof t==`function`?t(e):t,n,n*.8),Kn=(e,t,n)=>{var{top:r,left:i,width:a,height:o}=t,s=Oe(a,o);return{cx:i+U(e.cx,a,a/2),cy:r+U(e.cy,o,o/2),innerRadius:U(e.innerRadius,s,0),outerRadius:Gn(n,e.outerRadius,s),maxRadius:e.maxRadius||Math.sqrt(a*a+o*o)/2}},qn=(e,t)=>N(t-e)*Math.min(Math.abs(t-e),360),Jn=(e,t)=>{if(q.isValidElement(e))return q.cloneElement(e,t);if(typeof e==`function`)return e(t);var n=we(`recharts-pie-label-line`,typeof e==`boolean`?``:e.className),{key:r}=t,i=Bn(t,Mn);return q.createElement(oe,Y({},i,{type:`linear`,className:n}))},Yn=(e,t,n)=>{if(q.isValidElement(e))return q.cloneElement(e,t);var r=n;if(typeof e==`function`&&(r=e(t),q.isValidElement(r)))return r;var i=we(`recharts-pie-label-text`,re(e));return q.createElement(ve,Y({},t,{alignmentBaseline:`middle`,className:i}),r)};function Xn(e){var{sectors:t,props:n,showLabels:r}=e,{label:i,labelLine:a,dataKey:o}=n;if(!r||!i||!t)return null;var s=he(n),c=ye(i),l=ye(a),u=typeof i==`object`&&`offsetRadius`in i&&typeof i.offsetRadius==`number`&&i.offsetRadius||20,d=t.map((e,t)=>{var n=(e.startAngle+e.endAngle)/2,r=Me(e.cx,e.cy,e.outerRadius+u,n),d=J(J(J(J({},s),e),{},{stroke:`none`},c),{},{index:t,textAnchor:Wn(r.x,e.cx)},r),f=J(J(J(J({},s),e),{},{fill:`none`,stroke:e.fill},l),{},{index:t,points:[Me(e.cx,e.cy,e.outerRadius,n),r],key:`line`});return q.createElement(Ht,{zIndex:Re.label,key:`label-${e.startAngle}-${e.endAngle}-${e.midAngle}-${t}`},q.createElement(F,null,a&&Jn(a,f),Yn(i,d,z(e,o))))});return q.createElement(F,{className:`recharts-pie-labels`},d)}function Zn(e){var{sectors:t,props:n,showLabels:r}=e,{label:i}=n;return typeof i==`object`&&i&&`position`in i?q.createElement(Ee,{label:i}):q.createElement(Xn,{sectors:t,props:n,showLabels:r})}function Qn(e){var{sectors:t,activeShape:n,inactiveShape:r,allOtherPieProps:i,shape:a,id:o}=e,s=B(Be),c=B(Ve),l=B(_e),{onMouseEnter:u,onClick:d,onMouseLeave:f}=i,p=Bn(i,Nn),m=On(u,i.dataKey,o),h=kn(f),g=An(d,i.dataKey,o);return t==null||t.length===0?null:q.createElement(q.Fragment,null,t.map((e,u)=>{if(e?.startAngle===0&&e?.endAngle===0&&t.length!==1)return null;var d=l==null||l===o,f=String(u)===s&&(c==null||i.dataKey===c)&&d,_=n&&f?n:s?r:null,v=J(J({},e),{},{stroke:e.stroke,tabIndex:-1,[kt]:u,[nt]:o});return q.createElement(F,Y({key:`sector-${e?.startAngle}-${e?.endAngle}-${e.midAngle}-${u}`,tabIndex:-1,className:`recharts-pie-sector`},Bt(p,e,u),{onMouseEnter:m(e,u),onMouseLeave:h(e,u),onClick:g(e,u)}),q.createElement(an,Y({option:a??_,index:u,shapeType:`sector`,isActive:f},v)))}))}function $n(e){var{pieSettings:t,displayedData:n,cells:r,offset:i}=e,{cornerRadius:a,startAngle:o,endAngle:s,dataKey:c,nameKey:l,tooltipType:u}=t,d=Math.abs(t.minAngle),f=qn(o,s),p=Math.abs(f),m=n.length<=1?0:t.paddingAngle??0,h=n.filter(e=>z(e,c,0)!==0).length,g=(p>=360?h:h-1)*m,_=p-h*d-g,v=n.reduce((e,t)=>{var n=z(t,c,0);return e+(pe(n)?n:0)},0),y;if(v>0){var b;y=n.map((e,n)=>{var s=z(e,c,0),p=z(e,l,n),h=Kn(t,i,e),g=(pe(s)?s:0)/v,y,x=J(J({},e),r&&r[n]&&r[n].props);y=n?b.endAngle+N(f)*m*(s===0?0:1):o;var S=y+N(f)*((s===0?0:d)+g*_),C=(y+S)/2,w=(h.innerRadius+h.outerRadius)/2,T=[{name:p,value:s,payload:x,dataKey:c,type:u,graphicalItemId:t.id}],E=Me(h.cx,h.cy,w,C);return b=J(J(J(J({},t.presentationProps),{},{percent:g,cornerRadius:typeof a==`string`?parseFloat(a):a,name:p,tooltipPayload:T,midAngle:C,middleRadius:w,tooltipPosition:E},x),h),{},{value:s,dataKey:c,startAngle:y,endAngle:S,payload:x,paddingAngle:N(f)*m}),b})}return y}function er(e){var{showLabels:t,sectors:n,children:r}=e,i=(0,q.useMemo)(()=>!t||!n?[]:n.map(e=>({value:e.value,payload:e.payload,clockWise:!1,parentViewBox:void 0,viewBox:{cx:e.cx,cy:e.cy,innerRadius:e.innerRadius,outerRadius:e.outerRadius,startAngle:e.startAngle,endAngle:e.endAngle,clockWise:!1},fill:e.fill})),[n,t]);return q.createElement(De,{value:t?i:void 0},r)}function tr(e){var{props:t,previousSectorsRef:n,id:r}=e,{sectors:i,isAnimationActive:a,animationBegin:o,animationDuration:s,animationEasing:c,activeShape:l,inactiveShape:u,onAnimationStart:d,onAnimationEnd:f}=t,p=be(t,`recharts-pie-`),m=n.current,[h,g]=(0,q.useState)(!1),_=(0,q.useCallback)(()=>{typeof f==`function`&&f(),g(!1)},[f]),v=(0,q.useCallback)(()=>{typeof d==`function`&&d(),g(!0)},[d]);return q.createElement(er,{showLabels:!h,sectors:i},q.createElement(Te,{animationId:p,begin:o,duration:s,isActive:a,easing:c,onAnimationStart:v,onAnimationEnd:_,key:p},e=>{var a=[],o=(i&&i[0])?.startAngle??0;return i?.forEach((t,n)=>{var r=m&&m[n],i=n>0?(0,jn.default)(t,`paddingAngle`,0):0;if(r){var s=I(r.endAngle-r.startAngle,t.endAngle-t.startAngle,e),c=J(J({},t),{},{startAngle:o+i,endAngle:o+s+i});a.push(c),o=c.endAngle}else{var{endAngle:l,startAngle:u}=t,d=I(0,l-u,e),f=J(J({},t),{},{startAngle:o+i,endAngle:o+d+i});a.push(f),o=f.endAngle}}),n.current=a,q.createElement(F,null,q.createElement(Qn,{sectors:a,activeShape:l,inactiveShape:u,allOtherPieProps:t,shape:t.shape,id:r}))}),q.createElement(Zn,{showLabels:!h,sectors:i,props:t}),t.children)}var nr={animationBegin:400,animationDuration:1500,animationEasing:`ease`,cx:`50%`,cy:`50%`,dataKey:`value`,endAngle:360,fill:`#808080`,hide:!1,innerRadius:0,isAnimationActive:`auto`,label:!1,labelLine:!0,legendType:`rect`,minAngle:0,nameKey:`name`,outerRadius:`80%`,paddingAngle:0,rootTabIndex:0,startAngle:0,stroke:`#fff`,zIndex:Re.area};function rr(e){var{id:t}=e,n=Bn(e,Pn),{hide:r,className:i,rootTabIndex:a}=e,o=(0,q.useMemo)(()=>ke(e.children,un),[e.children]),s=B(e=>Dn(e,t,o)),c=(0,q.useRef)(null),l=we(`recharts-pie`,i);return r||s==null?(c.current=null,q.createElement(F,{tabIndex:a,className:l})):q.createElement(Ht,{zIndex:e.zIndex},q.createElement(Un,{dataKey:e.dataKey,nameKey:e.nameKey,sectors:s,stroke:e.stroke,strokeWidth:e.strokeWidth,fill:e.fill,name:e.name,hide:e.hide,tooltipType:e.tooltipType,id:t}),q.createElement(F,{tabIndex:a,className:l},q.createElement(tr,{props:J(J({},n),{},{sectors:s}),previousSectorsRef:c,id:t})))}function ir(e){var t=Pt(e,nr),{id:n}=t,r=Bn(t,Fn),i=he(r);return q.createElement(It,{id:n,type:`pie`},e=>q.createElement(q.Fragment,null,q.createElement(se,{type:`pie`,id:e,data:r.data,dataKey:r.dataKey,hide:r.hide,angleAxisId:0,radiusAxisId:0,name:r.name,nameKey:r.nameKey,tooltipType:r.tooltipType,legendType:r.legendType,fill:r.fill,cx:r.cx,cy:r.cy,startAngle:r.startAngle,endAngle:r.endAngle,paddingAngle:r.paddingAngle,minAngle:r.minAngle,innerRadius:r.innerRadius,outerRadius:r.outerRadius,cornerRadius:r.cornerRadius,presentationProps:i,maxRadius:t.maxRadius}),q.createElement(Hn,Y({},r,{id:e})),q.createElement(rr,Y({},r,{id:e}))))}ir.displayName=`Pie`;var ar=(e,t,n)=>{var r=n??e;if(!Lt(r))return U(r,t,0)},or=(e,t,n)=>{var r={},i=e.filter(Ft),a=e.filter(e=>e.stackId==null),o=i.reduce((e,t)=>{var n=e[t.stackId];return n??=[],n.push(t),e[t.stackId]=n,e},r),s=Object.entries(o).map(e=>{var[r,i]=e;return{stackId:r,dataKeys:i.map(e=>e.dataKey),barSize:ar(t,n,i[0]?.barSize)}}),c=a.map(e=>({stackId:void 0,dataKeys:[e.dataKey].filter(e=>e!=null),barSize:ar(t,n,e.barSize)}));return[...s,...c]};function sr(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function cr(e){for(var t=1;te+(t.barSize||0),0);d+=(a-1)*o,d>=n&&(d-=(a-1)*o,o=0),d>=n&&u>0&&(l=!0,u*=.9,d=a*u);var f={offset:((n-d)/2>>0)-o,size:0};s=r.reduce((e,t)=>{var n={stackId:t.stackId,dataKeys:t.dataKeys,position:{offset:f.offset+f.size+o,size:l?u:t.barSize??0}},r=[...e,n];return f=n.position,r},c)}else{var p=U(t,n,0,!0);n-2*p-(a-1)*o<=0&&(o=0);var m=(n-2*p-(a-1)*o)/a;m>1&&(m>>=0);var h=et(i)?Math.min(m,i):m;s=r.reduce((e,t,n)=>[...e,{stackId:t.stackId,dataKeys:t.dataKeys,position:{offset:p+(m+o)*n+(m-h)/2,size:h}}],c)}return s}}var pr=(e,t,n,r,i,a,o)=>{var s=Lt(o)?t:o,c=fr(n,r,i===a?a:i,e,s);return i!==a&&c!=null&&(c=c.map(e=>cr(cr({},e),{},{position:cr(cr({},e.position),{},{offset:e.position.offset-i/2})}))),c},mr=(e,t)=>{var n=Vt(t);if(!(!e||n==null||t==null)){var{stackId:r}=t;if(r!=null){var i=e[r];if(i){var{stackedData:a}=i;if(a)return a.find(e=>e.key===n)}}}},hr=(e,t)=>{if(!(e==null||t==null)){var n=e.find(e=>e.stackId===t.stackId&&t.dataKey!=null&&e.dataKeys.includes(t.dataKey));if(n!=null)return n.position}};function gr(e,t){return e&&typeof e==`object`&&`zIndex`in e&&typeof e.zIndex==`number`&&et(e.zIndex)?e.zIndex:t}var _r=!0,vr=`Invariant failed`;function yr(e,t){if(!e){if(_r)throw Error(vr);var n=typeof t==`function`?t():t,r=n?`${vr}: ${n}`:vr;throw Error(r)}}function br(){return br=Object.assign?Object.assign.bind():function(e){for(var t=1;t1&&arguments[1]!==void 0?arguments[1]:0;return(n,r)=>{if(pe(e))return e;var i=pe(n)||Lt(n);return i?e(n,r):(!i&&yr(!1,`minPointSize callback function received a value with type of ${typeof n}. Currently only numbers or null/undefined are supported.`),t)}},Cr=(e,t,n)=>n,wr=V([pt,(e,t)=>t],(e,t)=>e.filter(e=>e.type===`bar`).find(e=>e.id===t)),Tr=V([wr],e=>e?.maxBarSize),Er=(e,t,n,r)=>r,Dr=V([L,pt,K,G,Cr],(e,t,n,r,i)=>t.filter(t=>e===`horizontal`?t.xAxisId===n:t.yAxisId===r).filter(e=>e.isPanorama===i).filter(e=>e.hide===!1).filter(e=>e.type===`bar`)),Or=(e,t,n)=>{var r=L(e),i=K(e,t),a=G(e,t);if(!(i==null||a==null))return r===`horizontal`?at(e,`yAxis`,a,n):at(e,`xAxis`,i,n)},kr=V([Dr,me,(e,t)=>{var n=L(e),r=K(e,t),i=G(e,t);if(!(r==null||i==null))return n===`horizontal`?Dt(e,`xAxis`,r):Dt(e,`yAxis`,i)}],or),Ar=(e,t,n)=>{var r=wr(e,t);if(r==null)return 0;var i=K(e,t),a=G(e,t);if(i==null||a==null)return 0;var o=L(e),s=de(e),{maxBarSize:c}=r,l=Lt(c)?s:c,u,d;return o===`horizontal`?(u=Ye(e,`xAxis`,i,n),d=bt(e,`xAxis`,i,n)):(u=Ye(e,`yAxis`,a,n),d=bt(e,`yAxis`,a,n)),ht(u,d,!0)??l??0},jr=(e,t,n)=>{var r=L(e),i=K(e,t),a=G(e,t);if(!(i==null||a==null)){var o,s;return r===`horizontal`?(o=Ye(e,`xAxis`,i,n),s=bt(e,`xAxis`,i,n)):(o=Ye(e,`yAxis`,a,n),s=bt(e,`yAxis`,a,n)),ht(o,s)}},Mr=V([ne,Pe,(e,t,n)=>{var r=K(e,t);if(r!=null)return Ye(e,`xAxis`,r,n)},(e,t,n)=>{var r=G(e,t);if(r!=null)return Ye(e,`yAxis`,r,n)},(e,t,n)=>{var r=K(e,t);if(r!=null)return bt(e,`xAxis`,r,n)},(e,t,n)=>{var r=G(e,t);if(r!=null)return bt(e,`yAxis`,r,n)},V([V([kr,de,Rt,le,Ar,jr,Tr],pr),wr],hr),L,ae,jr,V([Or,wr],mr),wr,Er],(e,t,n,r,i,a,o,s,c,l,u,d,f)=>{var{chartData:p,dataStartIndex:m,dataEndIndex:h}=c;if(!(d==null||o==null||t==null||s!==`horizontal`&&s!==`vertical`||n==null||r==null||i==null||a==null||l==null)){var{data:g}=d,_=g!=null&&g.length>0?g:p?.slice(m,h+1);if(_!=null)return fi({layout:s,barSettings:d,pos:o,parentViewBox:t,bandSize:l,xAxis:n,yAxis:r,xAxisTicks:i,yAxisTicks:a,stackedData:u,displayedData:_,offset:e,cells:f,dataStartIndex:m})}}),Nr=[`index`];function Pr(){return Pr=Object.assign?Object.assign.bind():function(e){for(var t=1;t{var t=(0,q.useContext)(Lr);if(t!=null)return t.stackId;if(e!=null)return vt(e)},zr=(e,t)=>`recharts-bar-stack-clip-path-${e}-${t}`,Br=e=>{var t=(0,q.useContext)(Lr);if(t!=null){var{stackId:n}=t;return`url(#${zr(n,e)})`}},Vr=e=>{var{index:t}=e,n=Fr(e,Nr),r=Br(t);return q.createElement(F,Pr({className:`recharts-bar-stack-layer`,clipPath:r},n))},Hr=[`onMouseEnter`,`onMouseLeave`,`onClick`],Ur=[`value`,`background`,`tooltipPosition`],Wr=[`id`],Gr=[`onMouseEnter`,`onClick`,`onMouseLeave`];function X(){return X=Object.assign?Object.assign.bind():function(e){for(var t=1;t{var{dataKey:t,name:n,fill:r,legendType:i,hide:a}=e;return[{inactive:a,dataKey:t,type:i,color:r,value:Et(n,t),payload:e}]},$r=q.memo(e=>{var{dataKey:t,stroke:n,strokeWidth:r,fill:i,name:a,hide:o,unit:s,tooltipType:c,id:l}=e,u={dataDefinedOnItem:void 0,getPosition:Ae,settings:{stroke:n,strokeWidth:r,fill:i,dataKey:t,nameKey:void 0,name:Et(a,t),hide:o,type:c,color:i,unit:s,graphicalItemId:l}};return q.createElement(ue,{tooltipEntrySettings:u})});function ei(e){var t=B(Be),{data:n,dataKey:r,background:i,allOtherBarProps:a}=e,{onMouseEnter:o,onMouseLeave:s,onClick:c}=a,l=Xr(a,Hr),u=On(o,r,a.id),d=kn(s),f=An(c,r,a.id);if(!i||n==null)return null;var p=ye(i);return q.createElement(Ht,{zIndex:gr(i,Re.barBackground)},n.map((e,n)=>{var{value:a,background:o,tooltipPosition:s}=e,c=Xr(e,Ur);if(!o)return null;var m=u(e,n),h=d(e,n),g=f(e,n),_=Z(Z(Z(Z(Z({option:i,isActive:String(n)===t},c),{},{fill:`#eee`},o),p),Bt(l,e,n)),{},{onMouseEnter:m,onMouseLeave:h,onClick:g,dataKey:r,index:n,className:`recharts-bar-background-rectangle`});return q.createElement(xr,X({key:`background-bar-${n}`},_))}))}function ti(e){var{showLabels:t,children:n,rects:r}=e,i=r?.map(e=>{var t={x:e.x,y:e.y,width:e.width,lowerWidth:e.width,upperWidth:e.width,height:e.height};return Z(Z({},t),{},{value:e.value,payload:e.payload,parentViewBox:e.parentViewBox,viewBox:t,fill:e.fill})});return q.createElement(lt,{value:t?i:void 0},n)}function ni(e){var{shape:t,activeBar:n,baseProps:r,entry:i,index:a,dataKey:o}=e,s=B(Be),c=B(Ve),l=n&&String(a)===s&&(c==null||o===c),u=l?n:t;return l?q.createElement(Ht,{zIndex:Re.activeBar},q.createElement(Vr,{index:a},q.createElement(xr,X({},r,{name:String(r.name)},i,{isActive:l,option:u,index:a,dataKey:o})))):q.createElement(xr,X({},r,{name:String(r.name)},i,{isActive:l,option:u,index:a,dataKey:o}))}function ri(e){var{shape:t,baseProps:n,entry:r,index:i,dataKey:a}=e;return q.createElement(xr,X({},n,{name:String(n.name)},r,{isActive:!1,option:t,index:i,dataKey:a}))}function ii(e){var{data:t,props:n}=e,r=he(n)??{},{id:i}=r,a=Xr(r,Wr),{shape:o,dataKey:s,activeBar:c}=n,{onMouseEnter:l,onClick:u,onMouseLeave:d}=n,f=Xr(n,Gr),p=On(l,s,i),m=kn(d),h=An(u,s,i);return t?q.createElement(q.Fragment,null,t.map((e,t)=>q.createElement(Vr,X({index:t,key:`rectangle-${e?.x}-${e?.y}-${e?.value}-${t}`,className:`recharts-bar-rectangle`},Bt(f,e,t),{onMouseEnter:p(e,t),onMouseLeave:m(e,t),onClick:h(e,t)}),c?q.createElement(ni,{shape:o,activeBar:c,baseProps:a,entry:e,index:t,dataKey:s}):q.createElement(ri,{shape:o,baseProps:a,entry:e,index:t,dataKey:s})))):null}function ai(e){var{props:t,previousRectanglesRef:n}=e,{data:r,layout:i,isAnimationActive:a,animationBegin:o,animationDuration:s,animationEasing:c,onAnimationEnd:l,onAnimationStart:u}=t,d=n.current,f=be(t,`recharts-bar-`),[p,m]=(0,q.useState)(!1),h=!p,g=(0,q.useCallback)(()=>{typeof l==`function`&&l(),m(!1)},[l]),_=(0,q.useCallback)(()=>{typeof u==`function`&&u(),m(!0)},[u]);return q.createElement(ti,{showLabels:h,rects:r},q.createElement(Te,{animationId:f,begin:o,duration:s,isActive:a,easing:c,onAnimationEnd:g,onAnimationStart:_,key:f},e=>{var a=e===1?r:r?.map((t,n)=>{var r=d&&d[n];if(r)return Z(Z({},t),{},{x:I(r.x,t.x,e),y:I(r.y,t.y,e),width:I(r.width,t.width,e),height:I(r.height,t.height,e)});if(i===`horizontal`){var a=I(0,t.height,e),o=I(t.stackedBarStart,t.y,e);return Z(Z({},t),{},{y:o,height:a})}var s=I(0,t.width,e),c=I(t.stackedBarStart,t.x,e);return Z(Z({},t),{},{width:s,x:c})});return e>0&&(n.current=a??null),a==null?null:q.createElement(F,null,q.createElement(ii,{props:t,data:a}))}),q.createElement(Ee,{label:t.label}),t.children)}function oi(e){var t=(0,q.useRef)(null);return q.createElement(ai,{previousRectanglesRef:t,props:e})}var si=0,ci=(e,t)=>{var n=Array.isArray(e.value)?e.value[1]:e.value;return{x:e.x,y:e.y,value:n,errorVal:z(e,t)}},li=class extends q.PureComponent{render(){var{hide:e,data:t,dataKey:n,className:r,xAxisId:i,yAxisId:a,needClip:o,background:s,id:c}=this.props;if(e||t==null)return null;var l=we(`recharts-bar`,r),u=c;return q.createElement(F,{className:l,id:c},o&&q.createElement(`defs`,null,q.createElement($e,{clipPathId:u,xAxisId:i,yAxisId:a})),q.createElement(F,{className:`recharts-bar-rectangles`,clipPath:o?`url(#clipPath-${u})`:void 0},q.createElement(ei,{data:t,dataKey:n,background:s,allOtherBarProps:this.props}),q.createElement(oi,this.props)))}},ui={activeBar:!1,animationBegin:0,animationDuration:400,animationEasing:`ease`,background:!1,hide:!1,isAnimationActive:`auto`,label:!1,legendType:`rect`,minPointSize:si,xAxisId:0,yAxisId:0,zIndex:Re.bar};function di(e){var{xAxisId:t,yAxisId:n,hide:r,legendType:i,minPointSize:a,activeBar:o,animationBegin:s,animationDuration:c,animationEasing:l,isAnimationActive:u}=e,{needClip:d}=it(t,n),f=Ce(),p=Ke(),m=ke(e.children,un),h=B(t=>Mr(t,e.id,p,m));if(f!==`vertical`&&f!==`horizontal`)return null;var g,_=h?.[0];return g=_==null||_.height==null||_.width==null?0:f===`vertical`?_.height/2:_.width/2,q.createElement(on,{xAxisId:t,yAxisId:n,data:h,dataPointFormatter:ci,errorBarOffset:g},q.createElement(li,X({},e,{layout:f,needClip:d,data:h,xAxisId:t,yAxisId:n,hide:r,legendType:i,minPointSize:a,activeBar:o,animationBegin:s,animationDuration:c,animationEasing:l,isAnimationActive:u})))}function fi(e){var{layout:t,barSettings:{dataKey:n,minPointSize:r},pos:i,bandSize:a,xAxis:o,yAxis:s,xAxisTicks:c,yAxisTicks:l,stackedData:u,displayedData:d,offset:f,cells:p,parentViewBox:m,dataStartIndex:h}=e,g=t===`horizontal`?s:o,_=u?g.scale.domain():null,v=Ct({numericAxis:g}),y=g.scale.map(v);return d.map((e,d)=>{var g,b,x,S,C,w;if(u){var T=u[d+h];if(T==null)return null;g=jt(T,_)}else g=z(e,n),Array.isArray(g)||(g=[v,g]);var E=Sr(r,si)(g[1],d);if(t===`horizontal`){var ee=s.scale.map(g[0]),D=s.scale.map(g[1]);if(ee==null||D==null)return null;b=ct({axis:o,ticks:c,bandSize:a,offset:i.offset,entry:e,index:d}),x=D??ee??void 0,S=i.size;var O=ee-D;if(C=ce(O)?0:O,w={x:b,y:f.top,width:S,height:f.height},Math.abs(E)>0&&Math.abs(C)0&&Math.abs(S)q.createElement(q.Fragment,null,q.createElement(ze,{legendPayload:Qr(t)}),q.createElement($r,{dataKey:t.dataKey,stroke:t.stroke,strokeWidth:t.strokeWidth,fill:t.fill,name:t.name,hide:t.hide,unit:t.unit,tooltipType:t.tooltipType,id:e}),q.createElement(Le,{type:`bar`,id:e,data:void 0,xAxisId:t.xAxisId,yAxisId:t.yAxisId,zAxisId:0,dataKey:t.dataKey,stackId:n,hide:t.hide,barSize:t.barSize,minPointSize:t.minPointSize,maxBarSize:t.maxBarSize,isPanorama:r}),q.createElement(Ht,{zIndex:t.zIndex},q.createElement(di,X({},t,{id:e})))))}var mi=q.memo(pi,dt);mi.displayName=`Bar`;var hi=[`axis`,`item`],gi=(0,q.forwardRef)((e,t)=>q.createElement(Ot,{chartName:`BarChart`,defaultTooltipEventType:`axis`,validateTooltipEventTypes:hi,tooltipPayloadSearcher:Fe,categoricalChartProps:e,ref:t}));function _i(e){var t=ot();return(0,q.useEffect)(()=>{t(_t(e))},[t,e]),null}var vi=[`layout`];function yi(){return yi=Object.assign?Object.assign.bind():function(e){for(var t=1;t{var n=Pt(e,Ai);return q.createElement(Ci,{chartName:`PieChart`,defaultTooltipEventType:`item`,validateTooltipEventTypes:ki,tooltipPayloadSearcher:Fe,categoricalChartProps:n,ref:t})}),Q=t();function Mi({printDates:e,months:t=3}){let n=(0,q.useRef)(null),[r,i]=(0,q.useState)(0);(0,q.useEffect)(()=>{let e=n.current;if(!e)return;let t=new ResizeObserver(e=>{i(e[0]?.contentRect.width||0)});return t.observe(e),()=>t.disconnect()},[]);let{weeks:a,monthLabels:o,printCounts:s}=(0,q.useMemo)(()=>{let n={};e.forEach(e=>{let t=Wt(e);t&&(n[t]=(n[t]||0)+1)});let r=new Date,i=new Date(r);i.setMonth(i.getMonth()-t),i.setDate(i.getDate()-i.getDay());let a=[],o=[],s=[],c=-1,l=new Date(i),u=0;for(;l<=r;)l.getDay()===0&&s.length>0&&(a.push(s),s=[],u++),l.getMonth()!==c&&(o.push({month:l.toLocaleDateString(`en-US`,{month:`short`}),weekIndex:u}),c=l.getMonth()),s.push(new Date(l)),l.setDate(l.getDate()+1);return s.length>0&&a.push(s),{weeks:a,monthLabels:o,printCounts:n}},[e,t]),c=Math.max(1,...Object.values(s)),l=e=>{if(e===0)return`bg-bambu-dark`;let t=e/c;return t<=.25?`bg-bambu-green/30`:t<=.5?`bg-bambu-green/50`:t<=.75?`bg-bambu-green/75`:`bg-bambu-green`},u=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`],d=a.length,f=r-32-16,p=d>0?Math.floor((f-(d-1)*2)/d):12,m=Math.max(8,Math.min(20,p)),h=m<=10?10:12;return(0,Q.jsx)(`div`,{ref:n,className:`w-full flex justify-center`,children:r>0&&(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`div`,{className:`flex mb-1`,style:{marginLeft:36},children:o.map(({month:e,weekIndex:t},n)=>(0,Q.jsx)(`div`,{className:`text-bambu-gray`,style:{fontSize:h,marginLeft:n===0?0:`${(t-(o[n-1]?.weekIndex||0))*(m+2)-24}px`},children:e},n))}),(0,Q.jsxs)(`div`,{className:`flex`,style:{gap:2},children:[(0,Q.jsx)(`div`,{className:`flex flex-col`,style:{gap:2,marginRight:4,width:32},children:u.map((e,t)=>(0,Q.jsx)(`div`,{className:`text-bambu-gray flex items-center`,style:{width:32,height:m,fontSize:h,visibility:t%2==1?`visible`:`hidden`},children:e},e))}),a.map((e,t)=>(0,Q.jsx)(`div`,{className:`flex flex-col`,style:{gap:2},children:[0,1,2,3,4,5,6].map(t=>{let n=e.find(e=>e.getDay()===t);if(!n)return(0,Q.jsx)(`div`,{style:{width:m,height:m}},t);let r=Wt(n),i=s[r]||0,a=r===Wt(new Date);return(0,Q.jsx)(`div`,{className:`rounded-sm ${l(i)} ${a?`ring-1 ring-white`:``}`,style:{width:m,height:m},title:`${n.toLocaleDateString()}: ${i} print${i===1?``:`s`}`},t)})},t))]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 mt-3 text-bambu-gray`,style:{fontSize:h},children:[(0,Q.jsx)(`span`,{children:`Less`}),(0,Q.jsxs)(`div`,{className:`flex`,style:{gap:2},children:[(0,Q.jsx)(`div`,{className:`rounded-sm bg-bambu-dark`,style:{width:m,height:m}}),(0,Q.jsx)(`div`,{className:`rounded-sm bg-bambu-green/30`,style:{width:m,height:m}}),(0,Q.jsx)(`div`,{className:`rounded-sm bg-bambu-green/50`,style:{width:m,height:m}}),(0,Q.jsx)(`div`,{className:`rounded-sm bg-bambu-green/75`,style:{width:m,height:m}}),(0,Q.jsx)(`div`,{className:`rounded-sm bg-bambu-green`,style:{width:m,height:m}})]}),(0,Q.jsx)(`span`,{children:`More`})]})]})})}var Ni=[`weight`,`prints`,`time`];function Pi({value:e,onChange:t,exclude:n}){let{t:r}=i(),a={weight:r(`stats.filamentByWeight`),prints:r(`stats.filamentByPrints`),time:r(`stats.filamentByTime`)};return(0,Q.jsx)(`div`,{className:`flex gap-0.5 bg-bambu-dark rounded-lg p-0.5`,children:(n?Ni.filter(e=>!n.includes(e)):Ni).map(n=>(0,Q.jsx)(`button`,{onClick:()=>t(n),className:`px-2 py-0.5 text-xs rounded-md transition-colors ${e===n?`bg-bambu-green text-white`:`text-bambu-gray hover:text-white`}`,children:a[n]},n))})}function $(e){if(e>=1e6){let t=e/1e6;return`${t%1==0?t.toFixed(0):t.toFixed(1)}t`}if(e>=1e3){let t=e/1e3;return`${t%1==0?t.toFixed(0):t.toFixed(1)}kg`}return`${Math.round(e)}g`}function Fi(e){let t=rn(e);return t.length?t:[`Unknown`]}var Ii=[`#00ae42`,`#3b82f6`,`#f59e0b`,`#ef4444`,`#8b5cf6`,`#ec4899`,`#14b8a6`,`#f97316`],Li=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`],Ri=[`12am`,`1am`,`2am`,`3am`,`4am`,`5am`,`6am`,`7am`,`8am`,`9am`,`10am`,`11am`,`12pm`,`1pm`,`2pm`,`3pm`,`4pm`,`5pm`,`6pm`,`7pm`,`8pm`,`9pm`,`10pm`,`11pm`];function zi({archives:e,currency:t=`$`,dateFrom:n,dateTo:r}){let{t:a}=i(),[o,s]=(0,q.useState)(`weight`),[c,l]=(0,q.useState)(`weight`),u=(0,q.useMemo)(()=>{let t=new Map;return e.forEach(e=>{let n=Kt(e.completed_at||e.created_at)||new Date,r=`${n.getFullYear()}-${String(n.getMonth()+1).padStart(2,`0`)}-${String(n.getDate()).padStart(2,`0`)}`,i=t.get(r)||{date:r,filament:0,cost:0,energy:0,prints:0};i.filament+=e.filament_used_grams||0,i.cost+=e.cost||0,i.energy+=e.energy_kwh||0,i.prints+=e.quantity??1,t.set(r,i)}),Array.from(t.values()).sort((e,t)=>e.date.localeCompare(t.date)).map(e=>({...e,dateLabel:new Date(e.date).toLocaleDateString(`en-US`,{month:`short`,day:`numeric`})}))},[e]),d=(0,q.useMemo)(()=>{if(n&&r)return Math.max((new Date(r).getTime()-new Date(n).getTime())/864e5,0)+1;if(n)return Math.max((Date.now()-new Date(n).getTime())/864e5,0)+1;if(e.length<2)return 0;let t=e.map(e=>new Date(e.completed_at||e.created_at).getTime());return(Math.max(...t)-Math.min(...t))/864e5},[e,n,r]),f=(0,q.useMemo)(()=>{if(d>7)return[];let t=new Map,n=d>1;return e.forEach(e=>{let n=Kt(e.completed_at||e.created_at)||new Date,r=n.getHours(),i=`${n.getFullYear()}-${String(n.getMonth()+1).padStart(2,`0`)}-${String(n.getDate()).padStart(2,`0`)}T${String(r).padStart(2,`0`)}`,a=t.get(i)||{date:i,filament:0,cost:0,energy:0,prints:0};a.filament+=e.filament_used_grams||0,a.cost+=e.cost||0,a.energy+=e.energy_kwh||0,a.prints+=e.quantity??1,t.set(i,a)}),Array.from(t.values()).sort((e,t)=>e.date.localeCompare(t.date)).map(e=>{let[t,r]=e.date.split(`T`),i=new Date(t),a=parseInt(r,10),o=n?`${Li[i.getDay()]} ${Ri[a]}`:Ri[a];return{...e,dateLabel:o}})},[e,d]),p=(0,q.useMemo)(()=>{if(u.length<=60)return u;let e=new Map;return u.forEach(t=>{let n=new Date(t.date),r=new Date(n);r.setDate(n.getDate()-n.getDay());let i=`${r.getFullYear()}-${String(r.getMonth()+1).padStart(2,`0`)}-${String(r.getDate()).padStart(2,`0`)}`,a=e.get(i)||{week:i,filament:0,cost:0,energy:0,prints:0};a.filament+=t.filament,a.cost+=t.cost,a.energy+=t.energy,a.prints+=t.prints,e.set(i,a)}),Array.from(e.values()).sort((e,t)=>e.week.localeCompare(t.week)).map(e=>({date:e.week,dateLabel:`Week of ${new Date(e.week).toLocaleDateString(`en-US`,{month:`short`,day:`numeric`})}`,...e}))},[u]),m=(0,q.useMemo)(()=>{let t=new Map;return e.forEach(e=>{let n=Fi(e.filament_type);n.forEach(r=>{let i=(e.filament_used_grams||0)/n.length;t.set(r,(t.get(r)||0)+i)})}),Array.from(t.entries()).map(([e,t])=>({name:e,value:Math.round(t)})).sort((e,t)=>t.value-e.value)},[e]),h=(0,q.useMemo)(()=>{let t=new Map;return e.forEach(e=>{Fi(e.filament_type).forEach(e=>{t.set(e,(t.get(e)||0)+1)})}),Array.from(t.entries()).map(([e,t])=>({name:e,value:t})).sort((e,t)=>t.value-e.value)},[e]),g=(0,q.useMemo)(()=>{let t=new Map;return e.forEach(e=>{let n=Fi(e.filament_type),r=(e.actual_time_seconds||e.print_time_seconds||0)/n.length;n.forEach(e=>{t.set(e,(t.get(e)||0)+r)})}),Array.from(t.entries()).map(([e,t])=>({name:e,value:Math.round(t/3600*10)/10})).sort((e,t)=>t.value-e.value)},[e]),_=(0,q.useMemo)(()=>{let t=new Map;return e.forEach(e=>{e.status!==`completed`&&e.status!==`failed`||Fi(e.filament_type).forEach(n=>{let r=t.get(n)||{completed:0,failed:0};e.status===`completed`?r.completed++:r.failed++,t.set(n,r)})}),Array.from(t.entries()).filter(([,e])=>e.completed+e.failed>=2).map(([e,t])=>{let n=t.completed+t.failed;return{name:e,rate:Math.round(t.completed/n*100),total:n}}).sort((e,t)=>t.rate-e.rate)},[e]),v=(0,q.useMemo)(()=>{let t=new Map;return e.forEach(e=>{if(!e.filament_color)return;let n=e.filament_color.split(`,`).map(e=>e.trim()),r=(e.filament_used_grams||0)/n.length;n.forEach(e=>{let n=t.get(e)||{count:0,weight:0};n.count++,n.weight+=r,t.set(e,n)})}),Array.from(t.entries()).map(([e,t])=>({hex:e,value:c===`prints`?t.count:Math.round(t.weight)})).sort((e,t)=>t.value-e.value)},[e,c]),y=o===`weight`?m:o===`prints`?h:g,b=d<=7&&f.length>0?f:p,x=e.reduce((e,t)=>e+(t.filament_used_grams||0),0),S=e.reduce((e,t)=>e+(t.cost||0),0),C=e.reduce((e,t)=>e+(t.energy_kwh||0),0),w=e.reduce((e,t)=>e+(t.energy_cost||0),0),T=e.reduce((e,t)=>e+(t.quantity??1),0),E=new Set(e.map(e=>e.printer_id).filter(Boolean)).size;return(0,Q.jsxs)(`div`,{className:`space-y-4`,children:[(0,Q.jsxs)(`div`,{className:`grid grid-cols-3 gap-2 max-[640px]:grid-cols-1`,children:[(0,Q.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Q.jsx)(`p`,{className:`text-sm text-bambu-gray leading-none`,children:a(`stats.periodFilament`)}),(0,Q.jsx)(`p`,{className:`text-2xl font-bold text-white leading-none`,children:$(x)})]}),(0,Q.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[E,` `,a(`nav.printers`).toLowerCase()]})]}),(0,Q.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Q.jsx)(`p`,{className:`text-sm text-bambu-gray leading-none`,children:a(`stats.periodCost`)}),(0,Q.jsxs)(`p`,{className:`text-2xl font-bold text-white leading-none`,children:[t,S.toFixed(2)]})]}),(0,Q.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[T,` `,a(`common.prints`)]})]}),(0,Q.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Q.jsx)(`p`,{className:`text-sm text-bambu-gray leading-none`,children:a(`stats.avgPerPrint`)}),(0,Q.jsxs)(`p`,{className:`text-2xl font-bold text-white leading-none`,children:[T>0?(x/T).toFixed(0):0,`g`]})]}),(0,Q.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[t,T>0?(S/T).toFixed(2):`0.00`,` avg`]})]})]}),b.length>0?(0,Q.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,Q.jsx)(`h4`,{className:`text-sm font-medium text-bambu-gray mb-4`,children:a(`stats.usageOverTime`)}),(0,Q.jsx)(R,{width:`100%`,height:250,children:(0,Q.jsxs)(cn,{data:b,children:[(0,Q.jsx)(`defs`,{children:(0,Q.jsxs)(`linearGradient`,{id:`colorFilament`,x1:`0`,y1:`0`,x2:`0`,y2:`1`,children:[(0,Q.jsx)(`stop`,{offset:`5%`,stopColor:`#00ae42`,stopOpacity:.3}),(0,Q.jsx)(`stop`,{offset:`95%`,stopColor:`#00ae42`,stopOpacity:0})]})}),(0,Q.jsx)(yt,{strokeDasharray:`3 3`,stroke:`#3d3d3d`}),(0,Q.jsx)(Ze,{dataKey:`dateLabel`,stroke:`#9ca3af`,tick:{fontSize:12},interval:`preserveStartEnd`}),(0,Q.jsx)(Tt,{stroke:`#9ca3af`,tick:{fontSize:12},tickFormatter:e=>`${e}g`}),(0,Q.jsx)(P,{contentStyle:{backgroundColor:`#2d2d2d`,border:`1px solid #3d3d3d`,borderRadius:`8px`},labelStyle:{color:`#fff`},formatter:e=>[`${Number(e??0).toFixed(0)}g`,`Filament`]}),(0,Q.jsx)(sn,{type:`monotone`,dataKey:`filament`,stroke:`#00ae42`,strokeWidth:2,fillOpacity:1,fill:`url(#colorFilament)`})]})})]}):(0,Q.jsx)(`div`,{className:`bg-bambu-dark rounded-lg p-8 text-center text-bambu-gray`,children:a(`stats.noPrintDataInRange`)}),C>0&&b.length>0&&(0,Q.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between mb-4`,children:[(0,Q.jsx)(`h4`,{className:`text-sm font-medium text-bambu-gray`,children:a(`stats.energyOverTime`)}),(0,Q.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[C.toFixed(3),` kWh · `,t,w.toFixed(2)]})]}),(0,Q.jsx)(R,{width:`100%`,height:250,children:(0,Q.jsxs)(cn,{data:b,children:[(0,Q.jsx)(`defs`,{children:(0,Q.jsxs)(`linearGradient`,{id:`colorEnergy`,x1:`0`,y1:`0`,x2:`0`,y2:`1`,children:[(0,Q.jsx)(`stop`,{offset:`5%`,stopColor:`#f59e0b`,stopOpacity:.3}),(0,Q.jsx)(`stop`,{offset:`95%`,stopColor:`#f59e0b`,stopOpacity:0})]})}),(0,Q.jsx)(yt,{strokeDasharray:`3 3`,stroke:`#3d3d3d`}),(0,Q.jsx)(Ze,{dataKey:`dateLabel`,stroke:`#9ca3af`,tick:{fontSize:12},interval:`preserveStartEnd`}),(0,Q.jsx)(Tt,{stroke:`#9ca3af`,tick:{fontSize:12},tickFormatter:e=>`${e}kWh`}),(0,Q.jsx)(P,{contentStyle:{backgroundColor:`#2d2d2d`,border:`1px solid #3d3d3d`,borderRadius:`8px`},labelStyle:{color:`#fff`},formatter:e=>[`${Number(e??0).toFixed(3)} kWh`,a(`stats.energyUsed`)]}),(0,Q.jsx)(sn,{type:`monotone`,dataKey:`energy`,stroke:`#f59e0b`,strokeWidth:2,fillOpacity:1,fill:`url(#colorEnergy)`})]})})]}),(0,Q.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-3 gap-4`,children:[(0,Q.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between mb-4`,children:[(0,Q.jsx)(`h4`,{className:`text-sm font-medium text-bambu-gray`,children:a(`stats.byMaterial`)}),(0,Q.jsx)(Pi,{value:o,onChange:s})]}),y.length>0?(0,Q.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,Q.jsx)(R,{width:160,height:160,children:(0,Q.jsxs)(ji,{children:[(0,Q.jsx)(ir,{data:y,cx:`50%`,cy:`50%`,innerRadius:40,outerRadius:70,paddingAngle:2,dataKey:`value`,children:y.map((e,t)=>(0,Q.jsx)(un,{fill:Ii[t%Ii.length]},`cell-${t}`))}),(0,Q.jsx)(P,{contentStyle:{backgroundColor:`#2d2d2d`,border:`1px solid #3d3d3d`,borderRadius:`8px`},formatter:e=>[o===`weight`?$(Number(e??0)):o===`time`?`${Number(e??0)}h`:`${e??0}`,o===`weight`?`Usage`:o===`time`?`Time`:`Prints`]})]})}),(0,Q.jsx)(`div`,{className:`flex-1 space-y-2 overflow-hidden`,children:y.map((e,t)=>{let n=y.reduce((e,t)=>e+t.value,0),r=n>0?(e.value/n*100).toFixed(0):0;return(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,Q.jsx)(`div`,{className:`w-3 h-3 rounded-sm flex-shrink-0`,style:{backgroundColor:Ii[t%Ii.length]}}),(0,Q.jsx)(`span`,{className:`text-white truncate flex-1`,children:e.name}),(0,Q.jsxs)(`span`,{className:`text-bambu-gray flex-shrink-0`,children:[o===`weight`?$(e.value):o===`time`?`${e.value}h`:e.value,` · `,r,`%`]})]},e.name)})})]}):(0,Q.jsx)(`div`,{className:`h-[160px] flex items-center justify-center text-bambu-gray`,children:a(`stats.noFilamentData`)})]}),(0,Q.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,Q.jsx)(`h4`,{className:`text-sm font-medium text-bambu-gray mb-4`,children:a(`stats.filamentSuccess`)}),_.length>0?(0,Q.jsx)(`div`,{className:`space-y-1.5`,children:_.map(e=>(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,Q.jsx)(`span`,{className:`text-white truncate w-20 flex-shrink-0`,children:e.name}),(0,Q.jsx)(`div`,{className:`flex-1 h-1.5 bg-bambu-dark-secondary rounded-full`,children:(0,Q.jsx)(`div`,{className:`h-full rounded-full transition-all ${e.rate>=90?`bg-status-ok`:e.rate>=70?`bg-status-warning`:`bg-status-error`}`,style:{width:`${e.rate}%`}})}),(0,Q.jsxs)(`span`,{className:`font-medium flex-shrink-0 tabular-nums ${e.rate>=90?`text-status-ok`:e.rate>=70?`text-status-warning`:`text-status-error`}`,children:[e.rate,`%`]}),(0,Q.jsxs)(`span`,{className:`text-bambu-gray flex-shrink-0 text-xs`,children:[`(`,e.total,`)`]})]},e.name))}):(0,Q.jsx)(`div`,{className:`h-[160px] flex items-center justify-center text-bambu-gray`,children:a(`stats.noArchiveData`)})]}),(0,Q.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between mb-4`,children:[(0,Q.jsx)(`h4`,{className:`text-sm font-medium text-bambu-gray`,children:a(`stats.colorDistribution`)}),(0,Q.jsx)(Pi,{value:c,onChange:l,exclude:[`time`]})]}),v.length>0?(()=>{let e=v.reduce((e,t)=>e+t.value,0);return(0,Q.jsxs)(`div`,{children:[(0,Q.jsxs)(`div`,{className:`relative mx-auto`,style:{width:160,height:160},children:[(0,Q.jsx)(R,{width:`100%`,height:`100%`,children:(0,Q.jsxs)(ji,{children:[(0,Q.jsx)(ir,{data:v,cx:`50%`,cy:`50%`,innerRadius:45,outerRadius:70,paddingAngle:2,dataKey:`value`,children:v.map((e,t)=>(0,Q.jsx)(un,{fill:e.hex,stroke:`#1a1a1a`,strokeWidth:1},`color-${t}`))}),(0,Q.jsx)(P,{contentStyle:{backgroundColor:`#2d2d2d`,border:`1px solid #3d3d3d`,borderRadius:`8px`},formatter:e=>[c===`weight`?$(Number(e??0)):`${e??0}`,a(c===`weight`?`stats.filamentByWeight`:`stats.filamentByPrints`)]})]})}),(0,Q.jsxs)(`div`,{className:`absolute inset-0 flex flex-col items-center justify-center`,children:[(0,Q.jsx)(`span`,{className:`text-lg font-bold text-white`,children:c===`weight`?$(e):e}),(0,Q.jsxs)(`span`,{className:`text-[10px] text-bambu-gray`,children:[v.length,` `,v.length===1?`color`:`colors`]})]})]}),(0,Q.jsx)(`div`,{className:`grid grid-cols-2 gap-x-3 gap-y-1 mt-2`,children:v.slice(0,8).map(t=>{let n=e>0?(t.value/e*100).toFixed(0):0;return(0,Q.jsxs)(`div`,{className:`flex items-center gap-1.5 text-xs min-w-0`,children:[(0,Q.jsx)(`div`,{className:`w-2.5 h-2.5 rounded-full flex-shrink-0 border border-black/20`,style:{backgroundColor:t.hex}}),(0,Q.jsxs)(`span`,{className:`text-bambu-gray truncate`,children:[n,`%`]})]},t.hex)})}),v.length>8&&(0,Q.jsxs)(`p`,{className:`text-[10px] text-bambu-gray mt-1 text-center`,children:[`+`,v.length-8,` more`]})]})})():(0,Q.jsx)(`div`,{className:`h-[160px] flex items-center justify-center text-bambu-gray`,children:a(`stats.noColorData`)})]})]})]})}function Bi(e){return Math.abs(e)>=1e3?`${(e/1e3).toFixed(2)} kg`:`${Math.round(e)} g`}function Vi({currency:e,dateFrom:t,dateTo:n}){let{t:o}=i(),{data:s,isLoading:c,isError:l}=a({queryKey:[`supplier-stats`,t??`all`,n??`all`],queryFn:()=>r.getSupplierStats(t,n)});return c?(0,Q.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,Q.jsx)(O,{className:`w-6 h-6 text-bambu-green animate-spin`})}):l?(0,Q.jsxs)(`p`,{className:`flex items-center gap-2 text-sm text-red-400 py-4`,children:[(0,Q.jsx)(Ut,{className:`w-4 h-4`}),o(`stats.suppliers.error`)]}):!s||s.length===0?(0,Q.jsx)(`p`,{className:`text-sm text-bambu-gray py-4`,children:o(`stats.suppliers.empty`)}):(0,Q.jsx)(`div`,{className:`overflow-x-auto`,children:(0,Q.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,Q.jsx)(`thead`,{children:(0,Q.jsxs)(`tr`,{className:`text-left text-xs text-bambu-gray border-b border-bambu-dark-tertiary`,children:[(0,Q.jsx)(`th`,{className:`py-2 pr-4 font-medium`,children:o(`stats.suppliers.supplier`)}),(0,Q.jsx)(`th`,{className:`py-2 pr-4 font-medium text-right`,children:o(`stats.suppliers.spools`)}),(0,Q.jsx)(`th`,{className:`py-2 pr-4 font-medium text-right`,children:o(`stats.suppliers.remaining`)}),(0,Q.jsx)(`th`,{className:`py-2 pr-4 font-medium text-right`,children:o(`stats.suppliers.consumed`)}),(0,Q.jsx)(`th`,{className:`py-2 font-medium text-right`,children:o(`stats.suppliers.cost`)})]})}),(0,Q.jsx)(`tbody`,{children:s.map(t=>(0,Q.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/50 last:border-b-0`,children:[(0,Q.jsx)(`td`,{className:`py-2 pr-4 text-white font-medium`,children:t.supplier_name}),(0,Q.jsx)(`td`,{className:`py-2 pr-4 text-bambu-gray text-right`,children:t.spool_count}),(0,Q.jsx)(`td`,{className:`py-2 pr-4 text-bambu-gray text-right`,children:Bi(t.remaining_g)}),(0,Q.jsx)(`td`,{className:`py-2 pr-4 text-bambu-gray text-right`,children:Bi(t.consumed_g)}),(0,Q.jsxs)(`td`,{className:`py-2 text-bambu-gray text-right`,children:[e,` `,t.cost.toFixed(2)]})]},t.supplier_id))})]})})}function Hi(e){return Math.abs(e)>=1e3?`${(e/1e3).toFixed(2)} kg`:`${Math.round(e)} g`}function Ui({currency:e,dateFrom:t,dateTo:n}){let{t:o}=i(),{data:s,isLoading:c,isError:l}=a({queryKey:[`material-number-stats`,t??null,n??null],queryFn:()=>r.getMaterialNumberStats({dateFrom:t,dateTo:n})});return c?(0,Q.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,Q.jsx)(O,{className:`w-6 h-6 text-bambu-green animate-spin`})}):l?(0,Q.jsx)(`p`,{className:`text-sm text-red-700 dark:text-red-400 py-4`,children:o(`stats.materialNumbers.loadFailed`)}):!s||s.length===0?(0,Q.jsx)(`p`,{className:`text-sm text-bambu-gray py-4`,children:o(`stats.materialNumbers.empty`)}):(0,Q.jsx)(`div`,{className:`overflow-x-auto`,children:(0,Q.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,Q.jsx)(`thead`,{children:(0,Q.jsxs)(`tr`,{className:`text-left text-xs text-bambu-gray border-b border-bambu-dark-tertiary`,children:[(0,Q.jsx)(`th`,{className:`py-2 pr-4 font-medium`,children:o(`inventory.materialNumber`)}),(0,Q.jsx)(`th`,{className:`py-2 pr-4 font-medium text-right`,children:o(`stats.materialNumbers.spools`)}),(0,Q.jsx)(`th`,{className:`py-2 pr-4 font-medium text-right`,children:o(`stats.materialNumbers.remaining`)}),(0,Q.jsx)(`th`,{className:`py-2 pr-4 font-medium text-right`,children:o(`stats.materialNumbers.consumed`)}),(0,Q.jsx)(`th`,{className:`py-2 font-medium text-right`,children:o(`stats.materialNumbers.cost`)})]})}),(0,Q.jsx)(`tbody`,{children:s.map(t=>(0,Q.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/50 last:border-b-0`,children:[(0,Q.jsx)(`td`,{className:`py-2 pr-4 text-white font-medium`,children:t.material_number}),(0,Q.jsx)(`td`,{className:`py-2 pr-4 text-bambu-gray text-right`,children:t.spool_count}),(0,Q.jsx)(`td`,{className:`py-2 pr-4 text-bambu-gray text-right`,children:Hi(t.remaining_g)}),(0,Q.jsx)(`td`,{className:`py-2 pr-4 text-bambu-gray text-right`,children:Hi(t.consumed_g)}),(0,Q.jsxs)(`td`,{className:`py-2 text-bambu-gray text-right`,children:[e,` `,t.cost.toFixed(2)]})]},t.material_number))})]})})}function Wi({id:e,title:t,component:n,isHidden:r,size:i,columnSpan:a,onToggleVisibility:o,onToggleSize:c}){let{attributes:l,listeners:u,setNodeRef:d,transform:f,transition:m,isDragging:h}=s({id:e}),g={transform:p.Transform.toString(f),transition:m,opacity:h?.5:1};return r?null:(0,Q.jsxs)(`div`,{ref:d,style:{...g,gridColumn:`span ${a}`},className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary overflow-hidden ${h?`ring-2 ring-bambu-green shadow-lg`:``}`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 border-b border-bambu-dark-tertiary bg-bambu-dark/30`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`button`,{...l,...u,className:`cursor-grab active:cursor-grabbing p-1 hover:bg-bambu-dark-tertiary rounded transition-colors`,title:`Drag to reorder`,children:(0,Q.jsx)(D,{className:`w-6 h-6 md:w-4 md:h-4 text-bambu-gray`})}),(0,Q.jsx)(`h3`,{className:`text-sm font-medium text-white`,children:t})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Q.jsx)(`button`,{onClick:c,className:`p-1 hover:bg-bambu-dark-tertiary rounded transition-colors`,title:`Size: ${i===1?`1/4`:i===2?`1/2`:`Full`} - Click to cycle`,children:i===4?(0,Q.jsx)(A,{className:`w-4 h-4 text-bambu-gray hover:text-white`}):(0,Q.jsx)(k,{className:`w-4 h-4 text-bambu-gray hover:text-white`})}),(0,Q.jsx)(`button`,{onClick:o,className:`p-1 hover:bg-bambu-dark-tertiary rounded transition-colors`,title:`Hide widget`,children:(0,Q.jsx)(E,{className:`w-4 h-4 text-bambu-gray hover:text-white`})})]})]}),(0,Q.jsx)(`div`,{className:`p-4`,children:typeof n==`function`?n(i):n})]})}function Gi({widgets:e,storageKey:t,columns:n=4,stackBelow:r,hideControls:i=!1,onResetLayout:a,renderControls:o}){let s=()=>{let t={};return e.forEach(e=>{t[e.id]=e.defaultSize||4}),t},[u,p]=(0,q.useState)(()=>{let n=localStorage.getItem(t);if(n)try{let e=JSON.parse(n);if(!e.sizes)e.sizes=s();else{let t=s();for(let n in t)n in e.sizes||(e.sizes[n]=t[n])}return e}catch{}return{order:e.map(e=>e.id),hidden:e.filter(e=>e.defaultVisible===!1).map(e=>e.id),sizes:s()}}),[b,x]=(0,q.useState)(!1),[S,C]=(0,q.useState)(!1);(0,q.useEffect)(()=>{if(!r)return;let e=window.matchMedia(`(max-width: ${r}px)`),t=e=>{C(e.matches)};t(e);let n=e=>t(e);return e.addEventListener?e.addEventListener(`change`,n):e.addListener(n),()=>{e.removeEventListener?e.removeEventListener(`change`,n):e.removeListener(n)}},[r]);let w=r&&S?1:n;(0,q.useEffect)(()=>{let e=()=>x(e=>!e);return window.addEventListener(`toggle-hidden-panel`,e),()=>window.removeEventListener(`toggle-hidden-panel`,e)},[]),(0,q.useEffect)(()=>{localStorage.setItem(t,JSON.stringify(u))},[u,t]),(0,q.useEffect)(()=>{let t=e.map(e=>e.id).filter(e=>!u.order.includes(e));t.length>0&&p(e=>({...e,order:[...e.order,...t]}))},[e,u.order]);let T=h(l(y,{activationConstraint:{distance:8}}),l(f,{coordinateGetter:d})),E=e=>{let{active:t,over:n}=e;n&&t.id!==n.id&&p(e=>{let r=e.order.indexOf(t.id),i=e.order.indexOf(n.id);return{...e,order:m(e.order,r,i)}})},ee=e=>{p(t=>({...t,hidden:t.hidden.includes(e)?t.hidden.filter(t=>t!==e):[...t.hidden,e]}))},D=e=>{p(t=>{let n=t.sizes[e]||4,r=n===1?2:n===2?4:1;return{...t,sizes:{...t.sizes,[e]:r}}})},O=()=>{p({order:e.map(e=>e.id),hidden:e.filter(e=>e.defaultVisible===!1).map(e=>e.id),sizes:s()}),a?.()},k=u.order.map(t=>e.find(e=>e.id===t)).filter(Boolean),A=k.filter(e=>!u.hidden.includes(e.id)),j=k.filter(e=>u.hidden.includes(e.id)),M=o?.({hiddenCount:j.length,showHiddenPanel:b,setShowHiddenPanel:x,resetLayout:O});return(0,Q.jsxs)(`div`,{className:`space-y-4`,children:[M,!i&&!o&&(0,Q.jsxs)(`div`,{className:`flex items-center justify-end gap-2`,children:[(0,Q.jsxs)(W,{variant:`secondary`,size:`sm`,onClick:O,children:[(0,Q.jsx)(Jt,{className:`w-4 h-4`}),`Reset Layout`]}),j.length>0&&(0,Q.jsxs)(W,{variant:`secondary`,size:`sm`,onClick:()=>x(!b),children:[(0,Q.jsx)(Zt,{className:`w-4 h-4`}),j.length,` Hidden`]})]}),b&&j.length>0&&(0,Q.jsxs)(`div`,{className:`p-4 bg-bambu-dark rounded-xl border border-bambu-dark-tertiary`,children:[(0,Q.jsx)(`p`,{className:`text-sm text-bambu-gray mb-3`,children:`Hidden widgets (click to show):`}),(0,Q.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:j.map(e=>(0,Q.jsxs)(`button`,{onClick:()=>ee(e.id),className:`px-3 py-1.5 bg-bambu-dark-tertiary hover:bg-bambu-green/20 rounded-lg text-sm text-white transition-colors flex items-center gap-2`,children:[(0,Q.jsx)(Zt,{className:`w-3 h-3`}),e.title]},e.id))})]}),(0,Q.jsx)(_,{sensors:T,collisionDetection:c,onDragEnd:E,children:(0,Q.jsx)(v,{items:A.map(e=>e.id),strategy:g,children:(0,Q.jsx)(`div`,{className:`grid gap-6`,style:{gridTemplateColumns:`repeat(${w}, minmax(0, 1fr))`},children:A.map(e=>{let t=u.sizes[e.id]||2,n=Math.min(t,w);return(0,Q.jsx)(Wi,{id:e.id,title:e.title,component:e.component,isHidden:u.hidden.includes(e.id),size:t,columnSpan:n,onToggleVisibility:()=>ee(e.id),onToggleSize:()=>D(e.id)},e.id)})})})}),A.length===0&&(0,Q.jsxs)(`div`,{className:`text-center py-12 text-bambu-gray`,children:[(0,Q.jsx)(`p`,{children:`All widgets are hidden.`}),(0,Q.jsx)(W,{className:`mt-4`,onClick:O,children:`Reset Layout`})]})]})}function Ki(e){let t=new Date,n=t.getUTCFullYear(),r=t.getUTCMonth(),i=t.getUTCDate(),a=e=>e.toISOString().split(`T`)[0],o=a(t);switch(e){case`today`:return{dateFrom:o,dateTo:o};case`this-week`:{let e=t.getUTCDay();return{dateFrom:a(new Date(Date.UTC(n,r,i-(e===0?6:e-1)))),dateTo:o}}case`this-month`:return{dateFrom:a(new Date(Date.UTC(n,r,1))),dateTo:o};case`last-7`:return{dateFrom:a(new Date(Date.UTC(n,r,i-6))),dateTo:o};case`last-30`:return{dateFrom:a(new Date(Date.UTC(n,r,i-29))),dateTo:o};case`last-90`:return{dateFrom:a(new Date(Date.UTC(n,r,i-89))),dateTo:o};case`this-year`:return{dateFrom:a(new Date(Date.UTC(n,0,1))),dateTo:o};case`all-time`:return{dateFrom:void 0,dateTo:void 0};case`custom`:return{}}}var qi=[`today`,`this-week`,`this-month`,`last-7`,`last-30`,`last-90`,`this-year`,`all-time`],Ji=[`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`,`Sun`],Yi=[`12am`,`1am`,`2am`,`3am`,`4am`,`5am`,`6am`,`7am`,`8am`,`9am`,`10am`,`11am`,`12pm`,`1pm`,`2pm`,`3pm`,`4pm`,`5pm`,`6pm`,`7pm`,`8pm`,`9pm`,`10pm`,`11pm`],Xi=[{key:`<30m`,max:1800},{key:`30m-1h`,max:3600},{key:`1-2h`,max:7200},{key:`2-4h`,max:14400},{key:`4-8h`,max:28800},{key:`8-12h`,max:43200},{key:`12-24h`,max:86400},{key:`24h+`,max:1/0}],Zi={backgroundColor:`#2d2d2d`,border:`1px solid #3d3d3d`,borderRadius:`8px`};function Qi({stats:e,currency:t}){let{t:n}=i(),r=e?.energy_data_warming_up===!0,a=r?n(`stats.energyWarmingUpTooltip`):void 0;return(0,Q.jsx)(`div`,{className:`grid grid-cols-2 sm:grid-cols-3 gap-4`,children:[{icon:j,color:`text-bambu-green`,label:n(`stats.totalPrints`),value:`${e?.total_prints||0}`},{icon:Xt,color:`text-blue-600 dark:text-blue-400`,label:n(`stats.printTime`),value:`${e?.total_print_time_hours?.toFixed(1)??`0`}h`},{icon:j,color:`text-orange-600 dark:text-orange-400`,label:n(`stats.filamentUsed`),value:$(e?.total_filament_grams||0)},{icon:T,color:`text-green-600 dark:text-green-400`,label:n(`stats.filamentCost`),value:`${t} ${e?.total_cost?.toFixed(2)??`0.00`}`},{icon:$t,color:`text-yellow-600 dark:text-yellow-400`,label:n(`stats.energyUsed`),value:`${e?.total_energy_kwh?.toFixed(3)??`0.000`} kWh`,warning:r,tooltip:a},{icon:T,color:`text-yellow-500`,label:n(`stats.energyCost`),value:`${t} ${e?.total_energy_cost?.toFixed(2)??`0.00`}`,warning:r,tooltip:a},...(e?.total_wear_cost??0)>0?[{icon:tn,color:`text-slate-500 dark:text-slate-300`,label:n(`stats.wearCost`),value:`${t} ${e?.total_wear_cost?.toFixed(2)??`0.00`}`,warning:!1,tooltip:void 0}]:[]].map(e=>(0,Q.jsxs)(`div`,{className:`flex items-start gap-3`,title:e.tooltip,children:[(0,Q.jsx)(`div`,{className:`p-2 rounded-lg bg-bambu-dark ${e.color}`,children:(0,Q.jsx)(e.icon,{className:`w-5 h-5`})}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsxs)(`p`,{className:`text-xs text-bambu-gray flex items-center gap-1`,children:[e.label,e.warning&&(0,Q.jsx)(Ut,{className:`w-3 h-3 text-yellow-600 dark:text-yellow-400`,"aria-label":e.tooltip})]}),(0,Q.jsx)(`p`,{className:`text-xl font-bold text-white`,children:e.value})]})]},e.label))})}function $i({stats:e,printerMap:t,size:n=1}){let{t:r}=i(),a=(e?.successful_prints||0)+(e?.failed_prints||0),o=a?Math.round((e?.successful_prints||0)/a*100):0,s=n===1?112:n===2?128:144,c=s/2-8,l=c*2*Math.PI;return(0,Q.jsxs)(`div`,{className:`flex items-center gap-6`,children:[(0,Q.jsxs)(`div`,{className:`relative flex-shrink-0`,style:{width:s,height:s},children:[(0,Q.jsxs)(`svg`,{className:`w-full h-full -rotate-90`,children:[(0,Q.jsx)(`circle`,{cx:s/2,cy:s/2,r:c,fill:`none`,stroke:`#3d3d3d`,strokeWidth:`10`}),(0,Q.jsx)(`circle`,{cx:s/2,cy:s/2,r:c,fill:`none`,stroke:`#00ae42`,strokeWidth:`10`,strokeLinecap:`round`,strokeDasharray:`${o/100*l} ${l}`})]}),(0,Q.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center`,children:(0,Q.jsxs)(`span`,{className:`font-bold text-white ${n>=2?`text-2xl`:`text-xl`}`,children:[o,`%`]})})]}),(0,Q.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(w,{className:`w-4 h-4 text-status-ok flex-shrink-0`}),(0,Q.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:r(`stats.successful`)}),(0,Q.jsx)(`span`,{className:`text-sm text-white font-medium`,children:e?.successful_prints||0})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(S,{className:`w-4 h-4 text-status-error flex-shrink-0`}),(0,Q.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:r(`stats.failed`)}),(0,Q.jsx)(`span`,{className:`text-sm text-white font-medium`,children:e?.failed_prints||0})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(u,{className:`w-4 h-4 text-status-warning flex-shrink-0`}),(0,Q.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:r(`stats.cancelled`)}),(0,Q.jsx)(`span`,{className:`text-sm text-white font-medium`,children:e?.cancelled_prints||0})]})]}),n>=2&&e?.prints_by_printer&&Object.keys(e.prints_by_printer).length>0&&(0,Q.jsxs)(`div`,{className:`mt-4 pt-4 border-t border-bambu-dark-tertiary`,children:[(0,Q.jsx)(`p`,{className:`text-xs text-bambu-gray font-medium mb-2`,children:r(`stats.printsByPrinter`)}),(0,Q.jsx)(`div`,{className:`grid gap-x-6 gap-y-1 ${n===4?`grid-cols-3`:`grid-cols-2`}`,style:{width:`fit-content`},children:Object.entries(e.prints_by_printer).map(([e,n])=>(0,Q.jsxs)(`div`,{className:`flex items-center gap-3 text-sm`,children:[(0,Q.jsx)(`span`,{className:`text-bambu-gray truncate max-w-[120px]`,children:t.get(e)||`${r(`common.printer`)} ${e}`}),(0,Q.jsx)(`span`,{className:`text-white font-medium`,children:n})]},e))})]})]})]})}function ea({stats:e,printerMap:t,size:n=1}){let{t:r}=i(),a=e?.average_time_accuracy;if(a==null)return(0,Q.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,Q.jsx)(`p`,{className:`text-bambu-gray text-center py-4`,children:r(`stats.noTimeAccuracyData`)})});let o=(Math.min(150,Math.max(50,a))-50)/100*100,s=(e=>e>=95&&e<=105?`#00ae42`:e>105?`#3b82f6`:`#f97316`)(a),c=a-100,l=n===1?112:n===2?128:144,u=l/2-8,d=u*2*Math.PI,f=n===1?3:n===2?6:999,p=e?.time_accuracy_by_printer?Object.entries(e.time_accuracy_by_printer).slice(0,f):[];return(0,Q.jsxs)(`div`,{className:`flex items-center gap-6`,children:[(0,Q.jsxs)(`div`,{className:`relative flex-shrink-0`,style:{width:l,height:l},children:[(0,Q.jsxs)(`svg`,{className:`w-full h-full -rotate-90`,children:[(0,Q.jsx)(`circle`,{cx:l/2,cy:l/2,r:u,fill:`none`,stroke:`#3d3d3d`,strokeWidth:`10`}),(0,Q.jsx)(`circle`,{cx:l/2,cy:l/2,r:u,fill:`none`,stroke:s,strokeWidth:`10`,strokeLinecap:`round`,strokeDasharray:`${o/100*d} ${d}`})]}),(0,Q.jsxs)(`div`,{className:`absolute inset-0 flex flex-col items-center justify-center`,children:[(0,Q.jsxs)(`span`,{className:`font-bold text-white ${n>=2?`text-2xl`:`text-xl`}`,children:[a.toFixed(0),`%`]}),(0,Q.jsxs)(`span`,{className:`text-xs ${c>=0?`text-blue-700 dark:text-blue-400`:`text-orange-700 dark:text-orange-400`}`,children:[c>=0?`+`:``,c.toFixed(0),`%`]})]})]}),(0,Q.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-bambu-gray`,children:[(0,Q.jsx)(M,{className:`w-3 h-3 flex-shrink-0`}),(0,Q.jsx)(`span`,{children:r(`stats.perfectEstimate`)})]}),p.length>0&&(0,Q.jsx)(`div`,{className:`mt-2 ${n===4?`grid grid-cols-3 gap-x-6 gap-y-1`:n===2?`grid grid-cols-2 gap-x-6 gap-y-1`:`space-y-1`}`,style:{width:`fit-content`},children:p.map(([e,n])=>(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-xs`,children:[(0,Q.jsx)(`span`,{className:`text-bambu-gray truncate max-w-[100px]`,children:t.get(e)||`${r(`common.printer`)} ${e}`}),(0,Q.jsxs)(`span`,{className:`font-medium ${n>=95&&n<=105?`text-status-ok`:n>105?`text-blue-700 dark:text-blue-400`:`text-status-warning`}`,children:[n.toFixed(0),`%`]})]},e))})]})]})}function ta({printDates:e,dateFrom:t,dateTo:n}){let{days:r,hourlyCounts:i,maxCount:a}=(0,q.useMemo)(()=>{let r=new Date(t+`T00:00:00`),i=new Date(n+`T00:00:00`),a=[],o=e=>`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,`0`)}-${String(e.getDate()).padStart(2,`0`)}`,s=new Date(r);for(;s<=i;)a.push({key:o(s),label:s.toLocaleDateString(void 0,{weekday:`short`,month:`short`,day:`numeric`})}),s.setDate(s.getDate()+1);let c={},l=0;return e.forEach(e=>{let t=Kt(e);if(!t)return;let n=`${`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,`0`)}-${String(t.getDate()).padStart(2,`0`)}`}-${t.getHours()}`;c[n]=(c[n]||0)+1,c[n]>l&&(l=c[n])}),{days:a,hourlyCounts:c,maxCount:Math.max(1,l)}},[e,t,n]),o=e=>{if(e===0)return`bg-bambu-dark`;let t=e/a;return t<=.25?`bg-bambu-green/30`:t<=.5?`bg-bambu-green/50`:t<=.75?`bg-bambu-green/75`:`bg-bambu-green`};return(0,Q.jsxs)(`div`,{className:`w-full overflow-x-auto`,children:[(0,Q.jsxs)(`div`,{className:`inline-flex flex-col`,style:{gap:2},children:[(0,Q.jsx)(`div`,{className:`flex`,style:{gap:2,marginLeft:84},children:Yi.map((e,t)=>(0,Q.jsx)(`div`,{className:`text-bambu-gray text-[10px] text-center`,style:{width:20,visibility:t%2==0?`visible`:`hidden`},children:e},t))}),r.map(e=>(0,Q.jsxs)(`div`,{className:`flex items-center`,style:{gap:2},children:[(0,Q.jsx)(`div`,{className:`text-bambu-gray text-[10px] flex-shrink-0 truncate`,style:{width:80},children:e.label}),Array.from({length:24},(t,n)=>{let r=i[`${e.key}-${n}`]||0;return(0,Q.jsx)(`div`,{className:`rounded-sm ${o(r)}`,style:{width:20,height:20},title:`${e.label} ${Yi[n]}: ${r} print${r===1?``:`s`}`},n)})]},e.key))]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 mt-3 text-bambu-gray text-xs`,children:[(0,Q.jsx)(`span`,{children:`Less`}),(0,Q.jsxs)(`div`,{className:`flex`,style:{gap:2},children:[(0,Q.jsx)(`div`,{className:`rounded-sm bg-bambu-dark`,style:{width:20,height:20}}),(0,Q.jsx)(`div`,{className:`rounded-sm bg-bambu-green/30`,style:{width:20,height:20}}),(0,Q.jsx)(`div`,{className:`rounded-sm bg-bambu-green/50`,style:{width:20,height:20}}),(0,Q.jsx)(`div`,{className:`rounded-sm bg-bambu-green/75`,style:{width:20,height:20}}),(0,Q.jsx)(`div`,{className:`rounded-sm bg-bambu-green`,style:{width:20,height:20}})]}),(0,Q.jsx)(`span`,{children:`More`})]})]})}function na({printDates:e,size:t=2,dateFrom:n,dateTo:r}){let i=(0,q.useMemo)(()=>n&&r?Math.max((new Date(r).getTime()-new Date(n).getTime())/864e5,0)+1:n?Math.max((Date.now()-new Date(n).getTime())/864e5,0)+1:1/0,[n,r]);return i<=7&&n&&r?(0,Q.jsx)(ta,{printDates:e,dateFrom:n,dateTo:r}):(0,Q.jsx)(Mi,{printDates:e,months:i===1/0?t===1?3:t===2?6:12:Math.max(1,Math.ceil(i/30))})}function ra({stats:e,archives:t,printerMap:n}){let{t:r}=i(),[a,o]=(0,q.useState)(`weight`),[s,c]=(0,q.useState)(`weight`),l=(0,q.useMemo)(()=>{let i=new Map;return e?.prints_by_printer&&Object.entries(e.prints_by_printer).forEach(([e,t])=>{let n=i.get(e)||{prints:0,weight:0,time:0};n.prints=t,i.set(e,n)}),t.forEach(t=>{if(!t.printer_id)return;let n=String(t.printer_id),r=i.get(n)||{prints:0,weight:0,time:0};r.weight+=t.filament_used_grams||0,r.time+=t.actual_time_seconds||t.print_time_seconds||0,e?.prints_by_printer||r.prints++,i.set(n,r)}),Array.from(i.entries()).map(([e,t])=>({name:n.get(e)||`${r(`common.printer`)} ${e}`,value:a===`prints`?t.prints:a===`weight`?Math.round(t.weight):Math.round(t.time/3600*10)/10})).sort((e,t)=>t.value-e.value)},[e,t,n,a,r]),u=(0,q.useMemo)(()=>{let e=Array.from({length:24},(e,t)=>({hour:t,label:Yi[t],total:0,failures:0}));return t.forEach(t=>{if(!t.started_at)return;let n=Kt(t.started_at);if(!n)return;let r=n.getHours();e[r].total++,t.status===`failed`&&e[r].failures++}),e},[t]),d=(0,q.useMemo)(()=>{let e=Xi.map(e=>({name:e.key,count:0}));return t.forEach(t=>{let n=t.actual_time_seconds||t.print_time_seconds;if(!(!n||n<=0)){for(let t=0;t{let e=[0,0,0,0,0,0,0],n=new Set;t.forEach(t=>{let r=Kt(t.created_at)||new Date(t.created_at),i=r.getDay()-1;i<0&&(i=6),s===`prints`?e[i]++:s===`weight`?e[i]+=t.filament_used_grams||0:e[i]+=(t.actual_time_seconds||t.print_time_seconds||0)/3600;let a=new Date(r);a.setDate(r.getDate()-(r.getDay()+6)%7),n.add(`${a.getFullYear()}-${String(a.getMonth()+1).padStart(2,`0`)}-${String(a.getDate()).padStart(2,`0`)}`)});let r=Math.max(n.size,1);return Ji.map((t,n)=>({name:t,avg:Math.round(e[n]/r*10)/10}))},[t,s]),p=e=>({unit:e===`weight`?`g`:e===`time`?`h`:``,color:e===`weight`?`#00ae42`:e===`time`?`#3b82f6`:`#f59e0b`}),m=p(a),h=r(a===`weight`?`stats.filamentByWeight`:a===`time`?`stats.hours`:`common.prints`),g=p(s),_=r(s===`weight`?`stats.avgWeight`:s===`time`?`stats.avgTime`:`stats.avgPrints`);return(0,Q.jsxs)(`div`,{className:`space-y-4`,children:[(0,Q.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,Q.jsx)(`h4`,{className:`text-sm font-medium text-bambu-gray`,children:r(`stats.printsByPrinter`)}),(0,Q.jsx)(Pi,{value:a,onChange:o})]}),l.length>0?(0,Q.jsx)(R,{width:`100%`,height:Math.max(140,l.length*40),children:(0,Q.jsxs)(gi,{data:l,layout:`vertical`,margin:{left:10},children:[(0,Q.jsx)(yt,{strokeDasharray:`3 3`,stroke:`#3d3d3d`}),(0,Q.jsx)(Ze,{type:`number`,stroke:`#9ca3af`,tick:{fontSize:11},unit:m.unit}),(0,Q.jsx)(Tt,{type:`category`,dataKey:`name`,stroke:`#9ca3af`,tick:{fontSize:11},width:100}),(0,Q.jsx)(P,{contentStyle:Zi,formatter:e=>[a===`weight`?$(Number(e??0)):`${e??0}${m.unit}`,h]}),(0,Q.jsx)(mi,{dataKey:`value`,fill:m.color,radius:[0,4,4,0]})]})}):(0,Q.jsx)(`p`,{className:`text-bambu-gray text-center py-4`,children:r(`stats.noPrinterData`)})]}),(0,Q.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-3 gap-4`,children:[(0,Q.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,Q.jsx)(`h4`,{className:`text-sm font-medium text-bambu-gray mb-3`,children:r(`stats.printDuration`)}),t.length>0?(0,Q.jsx)(R,{width:`100%`,height:160,children:(0,Q.jsxs)(gi,{data:d,children:[(0,Q.jsx)(yt,{strokeDasharray:`3 3`,stroke:`#3d3d3d`}),(0,Q.jsx)(Ze,{dataKey:`name`,stroke:`#9ca3af`,tick:{fontSize:11}}),(0,Q.jsx)(Tt,{stroke:`#9ca3af`,tick:{fontSize:11},allowDecimals:!1}),(0,Q.jsx)(P,{contentStyle:Zi}),(0,Q.jsx)(mi,{dataKey:`count`,name:r(`common.prints`),fill:`#00ae42`,radius:[4,4,0,0]})]})}):(0,Q.jsx)(`p`,{className:`text-bambu-gray text-center py-4`,children:r(`stats.noArchiveData`)})]}),(0,Q.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,Q.jsx)(`h4`,{className:`text-sm font-medium text-bambu-gray`,children:r(`stats.printHabits`)}),(0,Q.jsx)(Pi,{value:s,onChange:c})]}),t.length>0?(0,Q.jsx)(R,{width:`100%`,height:160,children:(0,Q.jsxs)(gi,{data:f,children:[(0,Q.jsx)(yt,{strokeDasharray:`3 3`,stroke:`#3d3d3d`}),(0,Q.jsx)(Ze,{dataKey:`name`,stroke:`#9ca3af`,tick:{fontSize:11}}),(0,Q.jsx)(Tt,{stroke:`#9ca3af`,tick:{fontSize:11},unit:g.unit}),(0,Q.jsx)(P,{contentStyle:Zi,formatter:e=>[`${e??0}${g.unit}`,_]}),(0,Q.jsx)(mi,{dataKey:`avg`,fill:g.color,radius:[4,4,0,0]})]})}):(0,Q.jsx)(`p`,{className:`text-bambu-gray text-center py-4`,children:r(`stats.noArchiveData`)})]}),(0,Q.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,Q.jsx)(`h4`,{className:`text-sm font-medium text-bambu-gray mb-3`,children:r(`stats.printTimeOfDay`)}),t.length>0?(0,Q.jsx)(R,{width:`100%`,height:160,children:(0,Q.jsxs)(gi,{data:u,children:[(0,Q.jsx)(yt,{strokeDasharray:`3 3`,stroke:`#3d3d3d`}),(0,Q.jsx)(Ze,{dataKey:`label`,stroke:`#9ca3af`,tick:{fontSize:10},interval:5}),(0,Q.jsx)(Tt,{stroke:`#9ca3af`,tick:{fontSize:11},allowDecimals:!1}),(0,Q.jsx)(P,{contentStyle:Zi}),(0,Q.jsx)(mi,{dataKey:`total`,name:r(`stats.totalPrints`),fill:`#00ae42`,radius:[2,2,0,0]}),(0,Q.jsx)(mi,{dataKey:`failures`,name:r(`stats.failed`),fill:`#ef4444`,radius:[2,2,0,0]})]})}):(0,Q.jsx)(`p`,{className:`text-bambu-gray text-center py-4`,children:r(`stats.noArchiveData`)})]})]})]})}function ia({archives:e,currency:t,dateFrom:n,dateTo:r}){let{t:a}=i();return!e||e.length===0?(0,Q.jsx)(`p`,{className:`text-bambu-gray text-center py-4`,children:a(`stats.noPrintData`)}):(0,Q.jsx)(zi,{archives:e,currency:t,dateFrom:n,dateTo:r})}function aa({size:e=1,dateFrom:t,dateTo:n,createdById:o}){let{t:s}=i(),c=!!(t||n),{data:l,isLoading:u}=a({queryKey:[`failureAnalysis`,t,n,o??`all`],queryFn:()=>r.getFailureAnalysis({...c?{dateFrom:t,dateTo:n}:{days:30},createdById:o})});if(u)return(0,Q.jsx)(`div`,{className:`flex justify-center py-4`,children:(0,Q.jsx)(O,{className:`w-6 h-6 text-bambu-green animate-spin`})});if(!l||l.total_prints===0)return(0,Q.jsx)(`p`,{className:`text-bambu-gray text-center py-4`,children:s(c?`stats.noPrintDataInRange`:`stats.noPrintDataLast30Days`)});let d=e===1?5:e===2?8:999,f=Object.entries(l.failures_by_reason).sort(([,e],[,t])=>t-e),p=f.slice(0,d),m=f.length>d;return(0,Q.jsxs)(`div`,{className:`${e>=2?`flex gap-8`:`space-y-4`}`,children:[(0,Q.jsxs)(`div`,{className:e>=2?`flex-shrink-0`:``,children:[(0,Q.jsx)(`div`,{className:`flex items-center gap-4`,children:(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(Ut,{className:`w-5 h-5 ${l.failure_rate>20?`text-status-error`:l.failure_rate>10?`text-status-warning`:`text-status-ok`}`}),(0,Q.jsxs)(`span`,{className:`font-bold text-white ${e>=2?`text-3xl`:`text-2xl`}`,children:[l.failure_rate.toFixed(1),`%`]})]})}),(0,Q.jsx)(`div`,{className:`text-sm text-bambu-gray mt-1`,children:s(`stats.failedPrintsCount`,{failed:l.failed_prints,total:l.total_prints})}),(l.rejected_prints??0)>0&&(0,Q.jsxs)(`div`,{className:`text-sm mt-1`,children:[(0,Q.jsx)(`span`,{className:`text-status-warning`,children:s(`stats.rejectedPrintsCount`,{rejected:l.rejected_prints})}),(0,Q.jsx)(`span`,{className:`text-bambu-gray ml-2`,children:s(`stats.yieldRate`,{rate:(l.yield_rate??0).toFixed(1)})})]}),l.trend&&l.trend.length>=2&&(0,Q.jsx)(`div`,{className:`${e>=2?`mt-4`:`mt-2 pt-2 border-t border-bambu-dark-tertiary`}`,children:(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,Q.jsx)(Ie,{className:`w-4 h-4 ${l.trend[l.trend.length-1].failure_rate0&&(0,Q.jsxs)(`div`,{className:`flex-1 ${e>=2?`border-l border-bambu-dark-tertiary pl-8`:`pt-2`}`,children:[(0,Q.jsx)(`p`,{className:`text-xs text-bambu-gray font-medium mb-2`,children:s(e>=2?`stats.failureReasons`:`stats.topFailureReasons`)}),(0,Q.jsx)(`div`,{className:`${e===4?`grid grid-cols-2 gap-x-6 gap-y-1`:`space-y-1`}`,children:p.map(([t,n])=>(0,Q.jsxs)(`div`,{className:`flex items-center justify-between text-sm`,children:[(0,Q.jsx)(`span`,{className:`text-white truncate ${e===4?`max-w-[200px]`:`max-w-[160px]`}`,children:t?s(`editArchive.failureReasons.${t}`,{defaultValue:t}):s(`common.unknown`)}),(0,Q.jsx)(`span`,{className:`text-bambu-gray ml-2`,children:n})]},t))}),m&&(0,Q.jsx)(`p`,{className:`text-xs text-bambu-gray mt-2`,children:s(`common.more`,{count:f.length-d})})]})]})}function oa({archives:e,currency:t}){let{t:n}=i(),r=(0,q.useMemo)(()=>{let r=[];if(e.length===0)return r;let i=t=>{let n=null,r=0;return e.forEach(e=>{let i=t(e);i&&i>r&&(r=i,n=e)}),{archive:n,value:r}},a=i(e=>e.status===`completed`?e.actual_time_seconds:null);a.archive&&r.push({icon:Xt,iconColor:`text-blue-600 dark:text-blue-400`,label:n(`stats.longestPrint`),value:Gt(a.value),detail:a.archive.print_name||null});let o=i(e=>e.filament_used_grams);o.archive&&r.push({icon:j,iconColor:`text-orange-600 dark:text-orange-400`,label:n(`stats.heaviestPrint`),value:$(o.value),detail:o.archive.print_name||null});let s=i(e=>(e.cost??0)+(e.energy_cost??0)+(e.wear_cost??0));s.archive&&r.push({icon:T,iconColor:`text-green-600 dark:text-green-400`,label:n(`stats.mostExpensivePrint`),value:`${t}${s.value.toFixed(2)}`,detail:s.archive.print_name||null});let c=new Map;e.forEach(e=>{let t=Kt(e.created_at)||new Date(e.created_at),n=`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,`0`)}-${String(t.getDate()).padStart(2,`0`)}`;c.set(n,(c.get(n)||0)+1)});let l=``,u=0;c.forEach((e,t)=>{e>u&&(u=e,l=t)}),u>1&&r.push({icon:b,iconColor:`text-purple-600 dark:text-purple-400`,label:n(`stats.busiestDay`),value:`${u} ${n(`common.prints`)}`,detail:(()=>{let[e,t,n]=l.split(`-`).map(Number);return new Date(e,t-1,n).toLocaleDateString(void 0,{month:`short`,day:`numeric`,year:`numeric`})})()});let d=[...e].filter(e=>e.status===`completed`||e.status===`failed`).sort((e,t)=>new Date(t.completed_at||t.created_at).getTime()-new Date(e.completed_at||e.created_at).getTime()),f=0;for(let e of d)if(e.status===`completed`)f++;else break;return f>0&&r.push({icon:$t,iconColor:`text-yellow-600 dark:text-yellow-400`,label:n(`stats.successStreak`),value:`${f}`,detail:f===1?n(`stats.streakPrint`):n(`stats.streakPrints`,{count:f})}),r},[e,t,n]);return r.length===0?(0,Q.jsx)(`p`,{className:`text-bambu-gray text-center py-4`,children:n(`stats.noArchiveData`)}):(0,Q.jsx)(`div`,{className:`space-y-3`,children:r.map((e,t)=>(0,Q.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Q.jsx)(`div`,{className:`p-1.5 rounded-lg bg-bambu-dark ${e.iconColor}`,children:(0,Q.jsx)(e.icon,{className:`w-4 h-4`})}),(0,Q.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Q.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:e.label}),(0,Q.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,Q.jsx)(`span`,{className:`text-sm font-bold text-white`,children:e.value}),e.detail&&(0,Q.jsx)(`span`,{className:`text-xs text-bambu-gray truncate`,children:e.detail})]})]})]},t))})}function sa(){let{t:e}=i(),{showToast:t}=C(),{hasPermission:n,authEnabled:o}=nn(),[s,c]=(0,q.useState)(!1),[l,u]=(0,q.useState)(!1),[d,f]=(0,q.useState)(0),[p,m]=(0,q.useState)(0),[h,g]=(0,q.useState)(!1),[_,v]=(0,q.useState)(null),[y,S]=(0,q.useState)(!1),w=o&&n(`stats:filter_by_user`),[T,E]=(0,q.useState)(()=>{try{let e=localStorage.getItem(`bambusy-stats-timeframe`);if(e){let t=JSON.parse(e);if(t.preset)return t}}catch{}return{preset:`all-time`,dateFrom:void 0,dateTo:void 0}}),[D,k]=(0,q.useState)(!1);(0,q.useEffect)(()=>{localStorage.setItem(`bambusy-stats-timeframe`,JSON.stringify(T))},[T]);let A=(0,q.useMemo)(()=>T.preset===`custom`?{dateFrom:T.dateFrom,dateTo:T.dateTo}:Ki(T.preset),[T]);(0,q.useEffect)(()=>{let e=()=>{try{let e=localStorage.getItem(`bambusy-dashboard-layout-v2`);e&&m(JSON.parse(e).hidden?.length||0)}catch{m(0)}};e(),window.addEventListener(`storage`,e);let t=setInterval(e,2e3);return()=>{window.removeEventListener(`storage`,e),clearInterval(t)}},[d]);let j=_===null?void 0:_,{data:M,isLoading:te,isFetching:ne,refetch:re}=a({queryKey:[`archiveStats`,A.dateFrom,A.dateTo,j??`all`],queryFn:()=>r.getArchiveStats({dateFrom:A.dateFrom,dateTo:A.dateTo,createdById:j})}),{data:ie}=a({queryKey:[`printers`],queryFn:r.getPrinters}),{data:ae,isFetching:oe,refetch:se}=a({queryKey:[`archivesSlim`,A.dateFrom,A.dateTo,j??`all`],queryFn:()=>r.getArchivesSlim(A.dateFrom,A.dateTo,j)}),{data:ce}=a({queryKey:[`settings`],queryFn:r.getSettings}),{data:le,isPending:ue}=a({queryKey:[`spoolman-settings`],queryFn:r.getSpoolmanSettings,staleTime:300*1e3}),N=!ue,de=le?.spoolman_enabled===`true`&&!!le?.spoolman_url,{data:fe}=a({queryKey:[`users`,`slim`],queryFn:r.getUsersSlim,enabled:w}),pe=(0,q.useMemo)(()=>_===null?e(`stats.allUsers`,`All Users`):_===-1?e(`stats.noUser`,`No User (System)`):fe?.find(e=>e.id===_)?.username??`?`,[_,fe,e]),me=async n=>{u(!1),c(!0);try{let{blob:i,filename:a}=await r.exportStats({format:n,days:90,createdById:j}),o=URL.createObjectURL(i),s=document.createElement(`a`);s.href=o,s.download=a,s.click(),URL.revokeObjectURL(o),t(e(`stats.exportDownloaded`))}catch{t(e(`stats.exportFailed`),`error`)}finally{c(!1)}},he=async()=>{g(!0);try{let n=await r.recalculateCosts();await Promise.all([re(),se()]),t(e(`stats.recalculatedCosts`,{count:n.updated}))}catch{t(e(`stats.recalculateFailed`),`error`)}finally{g(!1)}},ge=(ne||oe)&&!te,_e=Qt(ce?.currency||`USD`),ve=(0,q.useMemo)(()=>new Map([...Object.entries(M?.printer_names||{}),...ie?.map(e=>[String(e.id),e.name])||[]]),[M?.printer_names,ie]),ye=(0,q.useMemo)(()=>ae?.map(e=>e.created_at)||[],[ae]);if(te)return(0,Q.jsx)(`div`,{className:`p-4 md:p-8`,children:(0,Q.jsx)(`div`,{className:`text-center py-12 text-bambu-gray`,children:e(`stats.loadingStats`)})});let be=[{id:`quick-stats`,title:e(`stats.quickStats`),component:(0,Q.jsx)(Qi,{stats:M,currency:_e}),defaultSize:2},{id:`success-rate`,title:e(`stats.successRate`),component:e=>(0,Q.jsx)($i,{stats:M,printerMap:ve,size:e}),defaultSize:1},{id:`time-accuracy`,title:e(`stats.timeAccuracy`),component:e=>(0,Q.jsx)(ea,{stats:M,printerMap:ve,size:e}),defaultSize:1},{id:`failure-analysis`,title:e(`stats.failureAnalysis`),component:e=>(0,Q.jsx)(aa,{size:e,dateFrom:A.dateFrom,dateTo:A.dateTo,createdById:j}),defaultSize:1},{id:`print-activity`,title:e(`stats.printActivity`),component:e=>(0,Q.jsx)(na,{printDates:ye,size:e,dateFrom:A.dateFrom,dateTo:A.dateTo}),defaultSize:2},{id:`records`,title:e(`stats.records`),component:(0,Q.jsx)(oa,{archives:ae||[],currency:_e}),defaultSize:1},{id:`printer-stats`,title:e(`stats.printerStats`),component:(0,Q.jsx)(ra,{stats:M,archives:ae||[],printerMap:ve}),defaultSize:4},{id:`filament-trends`,title:e(`stats.filamentTrends`),component:(0,Q.jsx)(ia,{archives:ae||[],currency:_e,dateFrom:A.dateFrom,dateTo:A.dateTo}),defaultSize:4},...!N||de?[]:[{id:`suppliers`,title:e(`stats.suppliers.title`),component:(0,Q.jsx)(Vi,{currency:_e,dateFrom:A.dateFrom,dateTo:A.dateTo}),defaultSize:2}],...!N||de?[]:[{id:`material-numbers`,title:e(`stats.materialNumbers.title`),component:(0,Q.jsx)(Ui,{currency:_e,dateFrom:A.dateFrom,dateTo:A.dateTo}),defaultSize:2}]];return(0,Q.jsxs)(`div`,{className:`p-4 md:p-8`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4 mb-6`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,Q.jsx)(Yt,{className:`w-7 h-7 text-bambu-green`}),e(`stats.title`)]}),ge&&(0,Q.jsx)(O,{className:`w-5 h-5 text-bambu-green animate-spin`})]}),(0,Q.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:e(`stats.subtitle`)})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[p>0&&(0,Q.jsxs)(W,{variant:`secondary`,onClick:()=>{window.dispatchEvent(new CustomEvent(`toggle-hidden-panel`))},children:[(0,Q.jsx)(Zt,{className:`w-4 h-4`}),e(`stats.hiddenCount`,{count:p})]}),(0,Q.jsxs)(W,{variant:`secondary`,onClick:()=>{localStorage.removeItem(`bambusy-dashboard-layout-v2`),f(e=>e+1),t(e(`stats.layoutReset`))},disabled:!n(`settings:update`),title:n(`settings:update`)?void 0:e(`stats.noPermissionResetLayout`),children:[(0,Q.jsx)(Jt,{className:`w-4 h-4`}),e(`stats.resetLayout`)]}),(0,Q.jsxs)(W,{variant:`secondary`,onClick:he,disabled:h||!n(`archives:update_all`),title:n(`archives:update_all`)?e(`stats.recalculateCostsHint`):e(`stats.noPermissionRecalculate`),children:[h?(0,Q.jsx)(O,{className:`w-4 h-4 animate-spin`}):(0,Q.jsx)(ln,{className:`w-4 h-4`}),e(`stats.recalculateCosts`)]}),(0,Q.jsxs)(`div`,{className:`relative`,children:[(0,Q.jsxs)(W,{variant:`secondary`,onClick:()=>u(!l),disabled:s,children:[s?(0,Q.jsx)(O,{className:`w-4 h-4 animate-spin`}):(0,Q.jsx)(ee,{className:`w-4 h-4`}),e(`stats.exportStats`)]}),l&&(0,Q.jsxs)(`div`,{className:`absolute right-0 top-full mt-1 w-48 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl z-20`,children:[(0,Q.jsxs)(`button`,{className:`w-full px-4 py-2 text-left text-white hover:bg-bambu-dark-tertiary transition-colors flex items-center gap-2 rounded-t-lg`,onClick:()=>me(`csv`),children:[(0,Q.jsx)(en,{className:`w-4 h-4`}),e(`stats.exportAsCsv`)]}),(0,Q.jsxs)(`button`,{className:`w-full px-4 py-2 text-left text-white hover:bg-bambu-dark-tertiary transition-colors flex items-center gap-2 rounded-b-lg`,onClick:()=>me(`xlsx`),children:[(0,Q.jsx)(ee,{className:`w-4 h-4`}),e(`stats.exportAsExcel`)]})]})]}),w&&fe&&fe.length>0&&(0,Q.jsxs)(`div`,{className:`relative`,children:[(0,Q.jsxs)(W,{variant:`secondary`,onClick:()=>S(!y),children:[(0,Q.jsx)(qt,{className:`w-4 h-4`}),pe,(0,Q.jsx)(x,{className:`w-3 h-3`})]}),y&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>S(!1)}),(0,Q.jsxs)(`div`,{className:`absolute right-0 top-full mt-1 w-48 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl z-20 p-2 max-h-64 overflow-y-auto`,children:[(0,Q.jsx)(`button`,{className:`w-full px-3 py-2 text-left text-sm rounded-md transition-colors ${_===null?`bg-bambu-green text-white`:`text-white hover:bg-bambu-dark-tertiary`}`,onClick:()=>{v(null),S(!1)},children:e(`stats.allUsers`,`All Users`)}),(0,Q.jsx)(`button`,{className:`w-full px-3 py-2 text-left text-sm rounded-md transition-colors ${_===-1?`bg-bambu-green text-white`:`text-white hover:bg-bambu-dark-tertiary`}`,onClick:()=>{v(-1),S(!1)},children:e(`stats.noUser`,`No User (System)`)}),(0,Q.jsx)(`div`,{className:`border-t border-bambu-dark-tertiary my-1`}),fe.map(e=>(0,Q.jsx)(`button`,{className:`w-full px-3 py-2 text-left text-sm rounded-md transition-colors ${_===e.id?`bg-bambu-green text-white`:`text-white hover:bg-bambu-dark-tertiary`}`,onClick:()=>{v(e.id),S(!1)},children:e.username},e.id))]})]})]}),(0,Q.jsxs)(`div`,{className:`relative`,children:[(0,Q.jsxs)(W,{variant:`secondary`,onClick:()=>k(!D),children:[(0,Q.jsx)(b,{className:`w-4 h-4`}),e(`stats.timeframe.${T.preset}`),(0,Q.jsx)(x,{className:`w-3 h-3`})]}),D&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>k(!1)}),(0,Q.jsxs)(`div`,{className:`absolute right-0 top-full mt-1 w-64 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl z-20 p-2`,children:[qi.map(t=>(0,Q.jsx)(`button`,{className:`w-full px-3 py-2 text-left text-sm rounded-md transition-colors ${T.preset===t?`bg-bambu-green text-white`:`text-white hover:bg-bambu-dark-tertiary`}`,onClick:()=>{E({preset:t,dateFrom:void 0,dateTo:void 0}),k(!1)},children:e(`stats.timeframe.${t}`)},t)),(0,Q.jsx)(`div`,{className:`border-t border-bambu-dark-tertiary my-2`}),(0,Q.jsx)(`button`,{className:`w-full px-3 py-2 text-left text-sm rounded-md transition-colors ${T.preset===`custom`?`bg-bambu-green text-white`:`text-white hover:bg-bambu-dark-tertiary`}`,onClick:()=>E(e=>({...e,preset:`custom`})),children:e(`stats.timeframe.custom`)}),T.preset===`custom`&&(0,Q.jsxs)(`div`,{className:`mt-2 px-1 pb-1 space-y-2`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`label`,{className:`text-xs text-bambu-gray block mb-1`,children:e(`stats.timeframe.from`)}),(0,Q.jsx)(`input`,{type:`date`,value:T.dateFrom||``,max:T.dateTo||new Date().toISOString().split(`T`)[0],onChange:e=>E(t=>({...t,dateFrom:e.target.value||void 0})),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded-md px-3 py-1.5 text-sm text-white`})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`label`,{className:`text-xs text-bambu-gray block mb-1`,children:e(`stats.timeframe.to`)}),(0,Q.jsx)(`input`,{type:`date`,value:T.dateTo||``,min:T.dateFrom,max:new Date().toISOString().split(`T`)[0],onChange:e=>E(t=>({...t,dateTo:e.target.value||void 0})),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded-md px-3 py-1.5 text-sm text-white`})]}),(0,Q.jsx)(W,{variant:`primary`,onClick:()=>k(!1),className:`w-full`,children:e(`common.apply`)})]})]})]})]})]})]}),(0,Q.jsx)(Gi,{widgets:be,storageKey:`bambusy-dashboard-layout-v2`,stackBelow:640,hideControls:!0},d)]})}export{sa as StatsPage}; \ No newline at end of file +import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,w as i}from"./client-DnySrlFv.js";import{t as a}from"./useQuery-BBCjCezC.js";import{t as o}from"./createLucideIcon-DvBYJlWL.js";import{a as s,d as c,f as l,h as u,i as d,l as f,m as p,n as m,p as h,r as g,s as _,t as v,u as y}from"./sortable.esm-D2bGix-3.js";import{t as b}from"./calendar-BLKPnWqV.js";import{a as x,n as S}from"./info-ROUoQhJR.js";import{n as C,r as w}from"./ToastContext-BRX0SW3C.js";import{t as T}from"./dollar-sign-Cj_Yhud4.js";import{t as E}from"./eye-off-6CkaxYwP.js";import{t as ee}from"./file-spreadsheet-WxOA9vYy.js";import{t as D}from"./grip-vertical-C_1RDxRw.js";import{t as O}from"./loader-circle-BEmFtawu.js";import{t as k}from"./maximize-2-kPQ77q72.js";import{t as A}from"./minimize-2-dqT-k7oI.js";import{t as j}from"./package-BGUevlqS.js";import{t as M}from"./target-B40GQtrA.js";import{$ as te,$t as ne,A as re,An as ie,At as ae,Bt as oe,C as se,Cn as ce,Ct as le,D as ue,Dn as N,Dt as de,E as fe,En as pe,Et as me,Fn as he,G as ge,H as _e,I as ve,In as ye,It as be,J as xe,K as Se,Kt as Ce,L as P,Ln as we,Lt as Te,M as Ee,Mn as F,N as De,Nt as Oe,O as ke,On as Ae,Ot as je,Pt as Me,Q as Ne,Qt as Pe,R as Fe,Rn as Ie,S as Le,Sn as I,St as Re,T as ze,U as Be,Ut as L,V as Ve,W as He,X as Ue,Xt as R,Y as We,Z as Ge,Zt as Ke,_t as qe,a as Je,at as Ye,bt as Xe,c as Ze,cn as z,ct as Qe,d as $e,dn as et,dt as tt,en as nt,et as rt,f as it,ft as at,gn as B,hn as ot,i as st,in as ct,j as lt,kt as ut,l as dt,lt as ft,mn as V,mt as pt,n as mt,nn as ht,nt as gt,o as _t,on as vt,ot as H,p as yt,pt as bt,q as xt,r as St,rn as Ct,rt as wt,s as Tt,sn as Et,st as Dt,t as Ot,tn as kt,tt as At,un as jt,ut as Mt,v as Nt,vn as Pt,vt as Ft,w as It,wn as Lt,wt as Rt,xn as U,xt as zt,yn as Bt,yt as Vt,z as Ht}from"./CartesianChart-BAcHzPFb.js";import{t as Ut}from"./triangle-alert-Dt_1FcBy.js";import{t as W}from"./Button-DDr6eAFy.js";import{h as Wt,o as Gt,v as Kt}from"./date-G9KUauqz.js";import{Dt as qt,Gt as Jt,Nn as Yt,On as Xt,Sn as Zt,at as Qt,bt as $t,xn as en,xt as tn,yt as nn}from"./index-Cxa-KVmA.js";import{t as rn}from"./filamentTypes-Dysa4k6j.js";import{n as an,t as on}from"./ErrorBarContext-CcijMMkA.js";import{i as G,n as sn,r as K,t as cn}from"./AreaChart-DJpIJXxF.js";var ln=o(`calculator`,[[`rect`,{width:`16`,height:`20`,x:`4`,y:`2`,rx:`2`,key:`1nb95v`}],[`line`,{x1:`8`,x2:`16`,y1:`6`,y2:`6`,key:`x4nwl0`}],[`line`,{x1:`16`,x2:`16`,y1:`14`,y2:`18`,key:`wjye3r`}],[`path`,{d:`M16 10h.01`,key:`1m94wz`}],[`path`,{d:`M12 10h.01`,key:`1nrarc`}],[`path`,{d:`M8 10h.01`,key:`19clt8`}],[`path`,{d:`M12 14h.01`,key:`1etili`}],[`path`,{d:`M8 14h.01`,key:`6423bh`}],[`path`,{d:`M12 18h.01`,key:`mhygvu`}],[`path`,{d:`M8 18h.01`,key:`lrp35t`}]]),un=e=>null;un.displayName=`Cell`;var dn=e=>e.graphicalItems.polarItems,fn=V([dn,H,V([zt,Xe],gt)],te),pn=V([V([fn],Ne),ut],Ue),mn=V([pn,H,fn],xt);V([pn,H,fn],(e,t,n)=>n.length>0?e.flatMap(e=>n.flatMap(n=>({value:z(e,t.dataKey??n.dataKey),errorDomain:[]}))).filter(Boolean):t?.dataKey==null?e.map(e=>({value:e,errorDomain:[]})):e.map(e=>({value:z(e,t.dataKey),errorDomain:[]})));var hn=()=>void 0,gn=V([H,L,pn,mn,je,zt,V([H,Qe,ft,hn,V([pn,H,fn,wt,zt],Ge),hn,L,zt],At)],xe);V([Mt,V([H,gn,V([gn,tt,Mt],rt),zt],We)],qe);function _n(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function vn(e){for(var t=1;tt],(e,t)=>e.filter(e=>e.type===`pie`).find(e=>e.id===t)),Cn=[],wn=(e,t,n)=>n?.length===0?Cn:n,Tn=V([ut,Sn,wn],(e,t,n)=>{var{chartData:r}=e;if(t!=null){var i=t?.data!=null&&t.data.length>0?t.data:r;if((!i||!i.length)&&n!=null&&(i=n.map(e=>vn(vn({},t.presentationProps),e.props))),i!=null)return i}}),En=V([Tn,Sn,wn],(e,t,n)=>{if(!(e==null||t==null))return e.map((e,r)=>{var i,a=z(e,t.nameKey,t.name),o=n!=null&&(i=n[r])!=null&&(i=i.props)!=null&&i.fill?n[r].props.fill:typeof e==`object`&&e&&`fill`in e?e.fill:t.fill;return{value:Et(a,t.dataKey),color:o,payload:e,type:t.legendType}})}),Dn=V([Tn,Sn,wn,ne],(e,t,n,r)=>{if(!(t==null||e==null))return $n({offset:r,pieSettings:t,displayedData:e,cells:n})}),On=(e,t,n)=>{var r=ot();return(i,a)=>o=>{e?.(i,a,o),r(Se({activeIndex:String(a),activeDataKey:t,activeCoordinate:i.tooltipPosition,activeGraphicalItemId:n}))}},kn=e=>{var t=ot();return(n,r)=>i=>{e?.(n,r,i),t(He())}},An=(e,t,n)=>{var r=ot();return(i,a)=>o=>{e?.(i,a,o),r(ge({activeIndex:String(a),activeDataKey:t,activeCoordinate:i.tooltipPosition,activeGraphicalItemId:n}))}},q=e(n()),jn=e(ie()),Mn=[`key`],Nn=[`onMouseEnter`,`onClick`,`onMouseLeave`],Pn=[`id`],Fn=[`id`];function In(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function J(e){for(var t=1;tke(e.children,un),[e.children]),n=B(n=>En(n,e.id,t));return n==null?null:q.createElement(fe,{legendPayload:n})}var Un=q.memo(e=>{var{dataKey:t,nameKey:n,sectors:r,stroke:i,strokeWidth:a,fill:o,name:s,hide:c,tooltipType:l,id:u}=e,d={dataDefinedOnItem:r.map(e=>e.tooltipPayload),getPosition:e=>r[Number(e)]?.tooltipPosition,settings:{stroke:i,strokeWidth:a,fill:o,dataKey:t,nameKey:n,name:Et(s,t),hide:c,type:l,color:o,unit:``,graphicalItemId:u}};return q.createElement(ue,{tooltipEntrySettings:d})}),Wn=(e,t)=>e>t?`start`:eU(typeof t==`function`?t(e):t,n,n*.8),Kn=(e,t,n)=>{var{top:r,left:i,width:a,height:o}=t,s=Oe(a,o);return{cx:i+U(e.cx,a,a/2),cy:r+U(e.cy,o,o/2),innerRadius:U(e.innerRadius,s,0),outerRadius:Gn(n,e.outerRadius,s),maxRadius:e.maxRadius||Math.sqrt(a*a+o*o)/2}},qn=(e,t)=>N(t-e)*Math.min(Math.abs(t-e),360),Jn=(e,t)=>{if(q.isValidElement(e))return q.cloneElement(e,t);if(typeof e==`function`)return e(t);var n=we(`recharts-pie-label-line`,typeof e==`boolean`?``:e.className),{key:r}=t,i=Bn(t,Mn);return q.createElement(oe,Y({},i,{type:`linear`,className:n}))},Yn=(e,t,n)=>{if(q.isValidElement(e))return q.cloneElement(e,t);var r=n;if(typeof e==`function`&&(r=e(t),q.isValidElement(r)))return r;var i=we(`recharts-pie-label-text`,re(e));return q.createElement(ve,Y({},t,{alignmentBaseline:`middle`,className:i}),r)};function Xn(e){var{sectors:t,props:n,showLabels:r}=e,{label:i,labelLine:a,dataKey:o}=n;if(!r||!i||!t)return null;var s=he(n),c=ye(i),l=ye(a),u=typeof i==`object`&&`offsetRadius`in i&&typeof i.offsetRadius==`number`&&i.offsetRadius||20,d=t.map((e,t)=>{var n=(e.startAngle+e.endAngle)/2,r=Me(e.cx,e.cy,e.outerRadius+u,n),d=J(J(J(J({},s),e),{},{stroke:`none`},c),{},{index:t,textAnchor:Wn(r.x,e.cx)},r),f=J(J(J(J({},s),e),{},{fill:`none`,stroke:e.fill},l),{},{index:t,points:[Me(e.cx,e.cy,e.outerRadius,n),r],key:`line`});return q.createElement(Ht,{zIndex:Re.label,key:`label-${e.startAngle}-${e.endAngle}-${e.midAngle}-${t}`},q.createElement(F,null,a&&Jn(a,f),Yn(i,d,z(e,o))))});return q.createElement(F,{className:`recharts-pie-labels`},d)}function Zn(e){var{sectors:t,props:n,showLabels:r}=e,{label:i}=n;return typeof i==`object`&&i&&`position`in i?q.createElement(Ee,{label:i}):q.createElement(Xn,{sectors:t,props:n,showLabels:r})}function Qn(e){var{sectors:t,activeShape:n,inactiveShape:r,allOtherPieProps:i,shape:a,id:o}=e,s=B(Be),c=B(Ve),l=B(_e),{onMouseEnter:u,onClick:d,onMouseLeave:f}=i,p=Bn(i,Nn),m=On(u,i.dataKey,o),h=kn(f),g=An(d,i.dataKey,o);return t==null||t.length===0?null:q.createElement(q.Fragment,null,t.map((e,u)=>{if(e?.startAngle===0&&e?.endAngle===0&&t.length!==1)return null;var d=l==null||l===o,f=String(u)===s&&(c==null||i.dataKey===c)&&d,_=n&&f?n:s?r:null,v=J(J({},e),{},{stroke:e.stroke,tabIndex:-1,[kt]:u,[nt]:o});return q.createElement(F,Y({key:`sector-${e?.startAngle}-${e?.endAngle}-${e.midAngle}-${u}`,tabIndex:-1,className:`recharts-pie-sector`},Bt(p,e,u),{onMouseEnter:m(e,u),onMouseLeave:h(e,u),onClick:g(e,u)}),q.createElement(an,Y({option:a??_,index:u,shapeType:`sector`,isActive:f},v)))}))}function $n(e){var{pieSettings:t,displayedData:n,cells:r,offset:i}=e,{cornerRadius:a,startAngle:o,endAngle:s,dataKey:c,nameKey:l,tooltipType:u}=t,d=Math.abs(t.minAngle),f=qn(o,s),p=Math.abs(f),m=n.length<=1?0:t.paddingAngle??0,h=n.filter(e=>z(e,c,0)!==0).length,g=(p>=360?h:h-1)*m,_=p-h*d-g,v=n.reduce((e,t)=>{var n=z(t,c,0);return e+(pe(n)?n:0)},0),y;if(v>0){var b;y=n.map((e,n)=>{var s=z(e,c,0),p=z(e,l,n),h=Kn(t,i,e),g=(pe(s)?s:0)/v,y,x=J(J({},e),r&&r[n]&&r[n].props);y=n?b.endAngle+N(f)*m*(s===0?0:1):o;var S=y+N(f)*((s===0?0:d)+g*_),C=(y+S)/2,w=(h.innerRadius+h.outerRadius)/2,T=[{name:p,value:s,payload:x,dataKey:c,type:u,graphicalItemId:t.id}],E=Me(h.cx,h.cy,w,C);return b=J(J(J(J({},t.presentationProps),{},{percent:g,cornerRadius:typeof a==`string`?parseFloat(a):a,name:p,tooltipPayload:T,midAngle:C,middleRadius:w,tooltipPosition:E},x),h),{},{value:s,dataKey:c,startAngle:y,endAngle:S,payload:x,paddingAngle:N(f)*m}),b})}return y}function er(e){var{showLabels:t,sectors:n,children:r}=e,i=(0,q.useMemo)(()=>!t||!n?[]:n.map(e=>({value:e.value,payload:e.payload,clockWise:!1,parentViewBox:void 0,viewBox:{cx:e.cx,cy:e.cy,innerRadius:e.innerRadius,outerRadius:e.outerRadius,startAngle:e.startAngle,endAngle:e.endAngle,clockWise:!1},fill:e.fill})),[n,t]);return q.createElement(De,{value:t?i:void 0},r)}function tr(e){var{props:t,previousSectorsRef:n,id:r}=e,{sectors:i,isAnimationActive:a,animationBegin:o,animationDuration:s,animationEasing:c,activeShape:l,inactiveShape:u,onAnimationStart:d,onAnimationEnd:f}=t,p=be(t,`recharts-pie-`),m=n.current,[h,g]=(0,q.useState)(!1),_=(0,q.useCallback)(()=>{typeof f==`function`&&f(),g(!1)},[f]),v=(0,q.useCallback)(()=>{typeof d==`function`&&d(),g(!0)},[d]);return q.createElement(er,{showLabels:!h,sectors:i},q.createElement(Te,{animationId:p,begin:o,duration:s,isActive:a,easing:c,onAnimationStart:v,onAnimationEnd:_,key:p},e=>{var a=[],o=(i&&i[0])?.startAngle??0;return i?.forEach((t,n)=>{var r=m&&m[n],i=n>0?(0,jn.default)(t,`paddingAngle`,0):0;if(r){var s=I(r.endAngle-r.startAngle,t.endAngle-t.startAngle,e),c=J(J({},t),{},{startAngle:o+i,endAngle:o+s+i});a.push(c),o=c.endAngle}else{var{endAngle:l,startAngle:u}=t,d=I(0,l-u,e),f=J(J({},t),{},{startAngle:o+i,endAngle:o+d+i});a.push(f),o=f.endAngle}}),n.current=a,q.createElement(F,null,q.createElement(Qn,{sectors:a,activeShape:l,inactiveShape:u,allOtherPieProps:t,shape:t.shape,id:r}))}),q.createElement(Zn,{showLabels:!h,sectors:i,props:t}),t.children)}var nr={animationBegin:400,animationDuration:1500,animationEasing:`ease`,cx:`50%`,cy:`50%`,dataKey:`value`,endAngle:360,fill:`#808080`,hide:!1,innerRadius:0,isAnimationActive:`auto`,label:!1,labelLine:!0,legendType:`rect`,minAngle:0,nameKey:`name`,outerRadius:`80%`,paddingAngle:0,rootTabIndex:0,startAngle:0,stroke:`#fff`,zIndex:Re.area};function rr(e){var{id:t}=e,n=Bn(e,Pn),{hide:r,className:i,rootTabIndex:a}=e,o=(0,q.useMemo)(()=>ke(e.children,un),[e.children]),s=B(e=>Dn(e,t,o)),c=(0,q.useRef)(null),l=we(`recharts-pie`,i);return r||s==null?(c.current=null,q.createElement(F,{tabIndex:a,className:l})):q.createElement(Ht,{zIndex:e.zIndex},q.createElement(Un,{dataKey:e.dataKey,nameKey:e.nameKey,sectors:s,stroke:e.stroke,strokeWidth:e.strokeWidth,fill:e.fill,name:e.name,hide:e.hide,tooltipType:e.tooltipType,id:t}),q.createElement(F,{tabIndex:a,className:l},q.createElement(tr,{props:J(J({},n),{},{sectors:s}),previousSectorsRef:c,id:t})))}function ir(e){var t=Pt(e,nr),{id:n}=t,r=Bn(t,Fn),i=he(r);return q.createElement(It,{id:n,type:`pie`},e=>q.createElement(q.Fragment,null,q.createElement(se,{type:`pie`,id:e,data:r.data,dataKey:r.dataKey,hide:r.hide,angleAxisId:0,radiusAxisId:0,name:r.name,nameKey:r.nameKey,tooltipType:r.tooltipType,legendType:r.legendType,fill:r.fill,cx:r.cx,cy:r.cy,startAngle:r.startAngle,endAngle:r.endAngle,paddingAngle:r.paddingAngle,minAngle:r.minAngle,innerRadius:r.innerRadius,outerRadius:r.outerRadius,cornerRadius:r.cornerRadius,presentationProps:i,maxRadius:t.maxRadius}),q.createElement(Hn,Y({},r,{id:e})),q.createElement(rr,Y({},r,{id:e}))))}ir.displayName=`Pie`;var ar=(e,t,n)=>{var r=n??e;if(!Lt(r))return U(r,t,0)},or=(e,t,n)=>{var r={},i=e.filter(Ft),a=e.filter(e=>e.stackId==null),o=i.reduce((e,t)=>{var n=e[t.stackId];return n??=[],n.push(t),e[t.stackId]=n,e},r),s=Object.entries(o).map(e=>{var[r,i]=e;return{stackId:r,dataKeys:i.map(e=>e.dataKey),barSize:ar(t,n,i[0]?.barSize)}}),c=a.map(e=>({stackId:void 0,dataKeys:[e.dataKey].filter(e=>e!=null),barSize:ar(t,n,e.barSize)}));return[...s,...c]};function sr(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function cr(e){for(var t=1;te+(t.barSize||0),0);d+=(a-1)*o,d>=n&&(d-=(a-1)*o,o=0),d>=n&&u>0&&(l=!0,u*=.9,d=a*u);var f={offset:((n-d)/2>>0)-o,size:0};s=r.reduce((e,t)=>{var n={stackId:t.stackId,dataKeys:t.dataKeys,position:{offset:f.offset+f.size+o,size:l?u:t.barSize??0}},r=[...e,n];return f=n.position,r},c)}else{var p=U(t,n,0,!0);n-2*p-(a-1)*o<=0&&(o=0);var m=(n-2*p-(a-1)*o)/a;m>1&&(m>>=0);var h=et(i)?Math.min(m,i):m;s=r.reduce((e,t,n)=>[...e,{stackId:t.stackId,dataKeys:t.dataKeys,position:{offset:p+(m+o)*n+(m-h)/2,size:h}}],c)}return s}}var pr=(e,t,n,r,i,a,o)=>{var s=Lt(o)?t:o,c=fr(n,r,i===a?a:i,e,s);return i!==a&&c!=null&&(c=c.map(e=>cr(cr({},e),{},{position:cr(cr({},e.position),{},{offset:e.position.offset-i/2})}))),c},mr=(e,t)=>{var n=Vt(t);if(!(!e||n==null||t==null)){var{stackId:r}=t;if(r!=null){var i=e[r];if(i){var{stackedData:a}=i;if(a)return a.find(e=>e.key===n)}}}},hr=(e,t)=>{if(!(e==null||t==null)){var n=e.find(e=>e.stackId===t.stackId&&t.dataKey!=null&&e.dataKeys.includes(t.dataKey));if(n!=null)return n.position}};function gr(e,t){return e&&typeof e==`object`&&`zIndex`in e&&typeof e.zIndex==`number`&&et(e.zIndex)?e.zIndex:t}var _r=!0,vr=`Invariant failed`;function yr(e,t){if(!e){if(_r)throw Error(vr);var n=typeof t==`function`?t():t,r=n?`${vr}: ${n}`:vr;throw Error(r)}}function br(){return br=Object.assign?Object.assign.bind():function(e){for(var t=1;t1&&arguments[1]!==void 0?arguments[1]:0;return(n,r)=>{if(pe(e))return e;var i=pe(n)||Lt(n);return i?e(n,r):(!i&&yr(!1,`minPointSize callback function received a value with type of ${typeof n}. Currently only numbers or null/undefined are supported.`),t)}},Cr=(e,t,n)=>n,wr=V([pt,(e,t)=>t],(e,t)=>e.filter(e=>e.type===`bar`).find(e=>e.id===t)),Tr=V([wr],e=>e?.maxBarSize),Er=(e,t,n,r)=>r,Dr=V([L,pt,K,G,Cr],(e,t,n,r,i)=>t.filter(t=>e===`horizontal`?t.xAxisId===n:t.yAxisId===r).filter(e=>e.isPanorama===i).filter(e=>e.hide===!1).filter(e=>e.type===`bar`)),Or=(e,t,n)=>{var r=L(e),i=K(e,t),a=G(e,t);if(!(i==null||a==null))return r===`horizontal`?at(e,`yAxis`,a,n):at(e,`xAxis`,i,n)},kr=V([Dr,me,(e,t)=>{var n=L(e),r=K(e,t),i=G(e,t);if(!(r==null||i==null))return n===`horizontal`?Dt(e,`xAxis`,r):Dt(e,`yAxis`,i)}],or),Ar=(e,t,n)=>{var r=wr(e,t);if(r==null)return 0;var i=K(e,t),a=G(e,t);if(i==null||a==null)return 0;var o=L(e),s=de(e),{maxBarSize:c}=r,l=Lt(c)?s:c,u,d;return o===`horizontal`?(u=Ye(e,`xAxis`,i,n),d=bt(e,`xAxis`,i,n)):(u=Ye(e,`yAxis`,a,n),d=bt(e,`yAxis`,a,n)),ht(u,d,!0)??l??0},jr=(e,t,n)=>{var r=L(e),i=K(e,t),a=G(e,t);if(!(i==null||a==null)){var o,s;return r===`horizontal`?(o=Ye(e,`xAxis`,i,n),s=bt(e,`xAxis`,i,n)):(o=Ye(e,`yAxis`,a,n),s=bt(e,`yAxis`,a,n)),ht(o,s)}},Mr=V([ne,Pe,(e,t,n)=>{var r=K(e,t);if(r!=null)return Ye(e,`xAxis`,r,n)},(e,t,n)=>{var r=G(e,t);if(r!=null)return Ye(e,`yAxis`,r,n)},(e,t,n)=>{var r=K(e,t);if(r!=null)return bt(e,`xAxis`,r,n)},(e,t,n)=>{var r=G(e,t);if(r!=null)return bt(e,`yAxis`,r,n)},V([V([kr,de,Rt,le,Ar,jr,Tr],pr),wr],hr),L,ae,jr,V([Or,wr],mr),wr,Er],(e,t,n,r,i,a,o,s,c,l,u,d,f)=>{var{chartData:p,dataStartIndex:m,dataEndIndex:h}=c;if(!(d==null||o==null||t==null||s!==`horizontal`&&s!==`vertical`||n==null||r==null||i==null||a==null||l==null)){var{data:g}=d,_=g!=null&&g.length>0?g:p?.slice(m,h+1);if(_!=null)return fi({layout:s,barSettings:d,pos:o,parentViewBox:t,bandSize:l,xAxis:n,yAxis:r,xAxisTicks:i,yAxisTicks:a,stackedData:u,displayedData:_,offset:e,cells:f,dataStartIndex:m})}}),Nr=[`index`];function Pr(){return Pr=Object.assign?Object.assign.bind():function(e){for(var t=1;t{var t=(0,q.useContext)(Lr);if(t!=null)return t.stackId;if(e!=null)return vt(e)},zr=(e,t)=>`recharts-bar-stack-clip-path-${e}-${t}`,Br=e=>{var t=(0,q.useContext)(Lr);if(t!=null){var{stackId:n}=t;return`url(#${zr(n,e)})`}},Vr=e=>{var{index:t}=e,n=Fr(e,Nr),r=Br(t);return q.createElement(F,Pr({className:`recharts-bar-stack-layer`,clipPath:r},n))},Hr=[`onMouseEnter`,`onMouseLeave`,`onClick`],Ur=[`value`,`background`,`tooltipPosition`],Wr=[`id`],Gr=[`onMouseEnter`,`onClick`,`onMouseLeave`];function X(){return X=Object.assign?Object.assign.bind():function(e){for(var t=1;t{var{dataKey:t,name:n,fill:r,legendType:i,hide:a}=e;return[{inactive:a,dataKey:t,type:i,color:r,value:Et(n,t),payload:e}]},$r=q.memo(e=>{var{dataKey:t,stroke:n,strokeWidth:r,fill:i,name:a,hide:o,unit:s,tooltipType:c,id:l}=e,u={dataDefinedOnItem:void 0,getPosition:Ae,settings:{stroke:n,strokeWidth:r,fill:i,dataKey:t,nameKey:void 0,name:Et(a,t),hide:o,type:c,color:i,unit:s,graphicalItemId:l}};return q.createElement(ue,{tooltipEntrySettings:u})});function ei(e){var t=B(Be),{data:n,dataKey:r,background:i,allOtherBarProps:a}=e,{onMouseEnter:o,onMouseLeave:s,onClick:c}=a,l=Xr(a,Hr),u=On(o,r,a.id),d=kn(s),f=An(c,r,a.id);if(!i||n==null)return null;var p=ye(i);return q.createElement(Ht,{zIndex:gr(i,Re.barBackground)},n.map((e,n)=>{var{value:a,background:o,tooltipPosition:s}=e,c=Xr(e,Ur);if(!o)return null;var m=u(e,n),h=d(e,n),g=f(e,n),_=Z(Z(Z(Z(Z({option:i,isActive:String(n)===t},c),{},{fill:`#eee`},o),p),Bt(l,e,n)),{},{onMouseEnter:m,onMouseLeave:h,onClick:g,dataKey:r,index:n,className:`recharts-bar-background-rectangle`});return q.createElement(xr,X({key:`background-bar-${n}`},_))}))}function ti(e){var{showLabels:t,children:n,rects:r}=e,i=r?.map(e=>{var t={x:e.x,y:e.y,width:e.width,lowerWidth:e.width,upperWidth:e.width,height:e.height};return Z(Z({},t),{},{value:e.value,payload:e.payload,parentViewBox:e.parentViewBox,viewBox:t,fill:e.fill})});return q.createElement(lt,{value:t?i:void 0},n)}function ni(e){var{shape:t,activeBar:n,baseProps:r,entry:i,index:a,dataKey:o}=e,s=B(Be),c=B(Ve),l=n&&String(a)===s&&(c==null||o===c),u=l?n:t;return l?q.createElement(Ht,{zIndex:Re.activeBar},q.createElement(Vr,{index:a},q.createElement(xr,X({},r,{name:String(r.name)},i,{isActive:l,option:u,index:a,dataKey:o})))):q.createElement(xr,X({},r,{name:String(r.name)},i,{isActive:l,option:u,index:a,dataKey:o}))}function ri(e){var{shape:t,baseProps:n,entry:r,index:i,dataKey:a}=e;return q.createElement(xr,X({},n,{name:String(n.name)},r,{isActive:!1,option:t,index:i,dataKey:a}))}function ii(e){var{data:t,props:n}=e,r=he(n)??{},{id:i}=r,a=Xr(r,Wr),{shape:o,dataKey:s,activeBar:c}=n,{onMouseEnter:l,onClick:u,onMouseLeave:d}=n,f=Xr(n,Gr),p=On(l,s,i),m=kn(d),h=An(u,s,i);return t?q.createElement(q.Fragment,null,t.map((e,t)=>q.createElement(Vr,X({index:t,key:`rectangle-${e?.x}-${e?.y}-${e?.value}-${t}`,className:`recharts-bar-rectangle`},Bt(f,e,t),{onMouseEnter:p(e,t),onMouseLeave:m(e,t),onClick:h(e,t)}),c?q.createElement(ni,{shape:o,activeBar:c,baseProps:a,entry:e,index:t,dataKey:s}):q.createElement(ri,{shape:o,baseProps:a,entry:e,index:t,dataKey:s})))):null}function ai(e){var{props:t,previousRectanglesRef:n}=e,{data:r,layout:i,isAnimationActive:a,animationBegin:o,animationDuration:s,animationEasing:c,onAnimationEnd:l,onAnimationStart:u}=t,d=n.current,f=be(t,`recharts-bar-`),[p,m]=(0,q.useState)(!1),h=!p,g=(0,q.useCallback)(()=>{typeof l==`function`&&l(),m(!1)},[l]),_=(0,q.useCallback)(()=>{typeof u==`function`&&u(),m(!0)},[u]);return q.createElement(ti,{showLabels:h,rects:r},q.createElement(Te,{animationId:f,begin:o,duration:s,isActive:a,easing:c,onAnimationEnd:g,onAnimationStart:_,key:f},e=>{var a=e===1?r:r?.map((t,n)=>{var r=d&&d[n];if(r)return Z(Z({},t),{},{x:I(r.x,t.x,e),y:I(r.y,t.y,e),width:I(r.width,t.width,e),height:I(r.height,t.height,e)});if(i===`horizontal`){var a=I(0,t.height,e),o=I(t.stackedBarStart,t.y,e);return Z(Z({},t),{},{y:o,height:a})}var s=I(0,t.width,e),c=I(t.stackedBarStart,t.x,e);return Z(Z({},t),{},{width:s,x:c})});return e>0&&(n.current=a??null),a==null?null:q.createElement(F,null,q.createElement(ii,{props:t,data:a}))}),q.createElement(Ee,{label:t.label}),t.children)}function oi(e){var t=(0,q.useRef)(null);return q.createElement(ai,{previousRectanglesRef:t,props:e})}var si=0,ci=(e,t)=>{var n=Array.isArray(e.value)?e.value[1]:e.value;return{x:e.x,y:e.y,value:n,errorVal:z(e,t)}},li=class extends q.PureComponent{render(){var{hide:e,data:t,dataKey:n,className:r,xAxisId:i,yAxisId:a,needClip:o,background:s,id:c}=this.props;if(e||t==null)return null;var l=we(`recharts-bar`,r),u=c;return q.createElement(F,{className:l,id:c},o&&q.createElement(`defs`,null,q.createElement($e,{clipPathId:u,xAxisId:i,yAxisId:a})),q.createElement(F,{className:`recharts-bar-rectangles`,clipPath:o?`url(#clipPath-${u})`:void 0},q.createElement(ei,{data:t,dataKey:n,background:s,allOtherBarProps:this.props}),q.createElement(oi,this.props)))}},ui={activeBar:!1,animationBegin:0,animationDuration:400,animationEasing:`ease`,background:!1,hide:!1,isAnimationActive:`auto`,label:!1,legendType:`rect`,minPointSize:si,xAxisId:0,yAxisId:0,zIndex:Re.bar};function di(e){var{xAxisId:t,yAxisId:n,hide:r,legendType:i,minPointSize:a,activeBar:o,animationBegin:s,animationDuration:c,animationEasing:l,isAnimationActive:u}=e,{needClip:d}=it(t,n),f=Ce(),p=Ke(),m=ke(e.children,un),h=B(t=>Mr(t,e.id,p,m));if(f!==`vertical`&&f!==`horizontal`)return null;var g,_=h?.[0];return g=_==null||_.height==null||_.width==null?0:f===`vertical`?_.height/2:_.width/2,q.createElement(on,{xAxisId:t,yAxisId:n,data:h,dataPointFormatter:ci,errorBarOffset:g},q.createElement(li,X({},e,{layout:f,needClip:d,data:h,xAxisId:t,yAxisId:n,hide:r,legendType:i,minPointSize:a,activeBar:o,animationBegin:s,animationDuration:c,animationEasing:l,isAnimationActive:u})))}function fi(e){var{layout:t,barSettings:{dataKey:n,minPointSize:r},pos:i,bandSize:a,xAxis:o,yAxis:s,xAxisTicks:c,yAxisTicks:l,stackedData:u,displayedData:d,offset:f,cells:p,parentViewBox:m,dataStartIndex:h}=e,g=t===`horizontal`?s:o,_=u?g.scale.domain():null,v=Ct({numericAxis:g}),y=g.scale.map(v);return d.map((e,d)=>{var g,b,x,S,C,w;if(u){var T=u[d+h];if(T==null)return null;g=jt(T,_)}else g=z(e,n),Array.isArray(g)||(g=[v,g]);var E=Sr(r,si)(g[1],d);if(t===`horizontal`){var ee=s.scale.map(g[0]),D=s.scale.map(g[1]);if(ee==null||D==null)return null;b=ct({axis:o,ticks:c,bandSize:a,offset:i.offset,entry:e,index:d}),x=D??ee??void 0,S=i.size;var O=ee-D;if(C=ce(O)?0:O,w={x:b,y:f.top,width:S,height:f.height},Math.abs(E)>0&&Math.abs(C)0&&Math.abs(S)q.createElement(q.Fragment,null,q.createElement(ze,{legendPayload:Qr(t)}),q.createElement($r,{dataKey:t.dataKey,stroke:t.stroke,strokeWidth:t.strokeWidth,fill:t.fill,name:t.name,hide:t.hide,unit:t.unit,tooltipType:t.tooltipType,id:e}),q.createElement(Le,{type:`bar`,id:e,data:void 0,xAxisId:t.xAxisId,yAxisId:t.yAxisId,zAxisId:0,dataKey:t.dataKey,stackId:n,hide:t.hide,barSize:t.barSize,minPointSize:t.minPointSize,maxBarSize:t.maxBarSize,isPanorama:r}),q.createElement(Ht,{zIndex:t.zIndex},q.createElement(di,X({},t,{id:e})))))}var mi=q.memo(pi,dt);mi.displayName=`Bar`;var hi=[`axis`,`item`],gi=(0,q.forwardRef)((e,t)=>q.createElement(Ot,{chartName:`BarChart`,defaultTooltipEventType:`axis`,validateTooltipEventTypes:hi,tooltipPayloadSearcher:Fe,categoricalChartProps:e,ref:t}));function _i(e){var t=ot();return(0,q.useEffect)(()=>{t(_t(e))},[t,e]),null}var vi=[`layout`];function yi(){return yi=Object.assign?Object.assign.bind():function(e){for(var t=1;t{var n=Pt(e,Ai);return q.createElement(Ci,{chartName:`PieChart`,defaultTooltipEventType:`item`,validateTooltipEventTypes:ki,tooltipPayloadSearcher:Fe,categoricalChartProps:n,ref:t})}),Q=t();function Mi({printDates:e,months:t=3}){let n=(0,q.useRef)(null),[r,i]=(0,q.useState)(0);(0,q.useEffect)(()=>{let e=n.current;if(!e)return;let t=new ResizeObserver(e=>{i(e[0]?.contentRect.width||0)});return t.observe(e),()=>t.disconnect()},[]);let{weeks:a,monthLabels:o,printCounts:s}=(0,q.useMemo)(()=>{let n={};e.forEach(e=>{let t=Wt(e);t&&(n[t]=(n[t]||0)+1)});let r=new Date,i=new Date(r);i.setMonth(i.getMonth()-t),i.setDate(i.getDate()-i.getDay());let a=[],o=[],s=[],c=-1,l=new Date(i),u=0;for(;l<=r;)l.getDay()===0&&s.length>0&&(a.push(s),s=[],u++),l.getMonth()!==c&&(o.push({month:l.toLocaleDateString(`en-US`,{month:`short`}),weekIndex:u}),c=l.getMonth()),s.push(new Date(l)),l.setDate(l.getDate()+1);return s.length>0&&a.push(s),{weeks:a,monthLabels:o,printCounts:n}},[e,t]),c=Math.max(1,...Object.values(s)),l=e=>{if(e===0)return`bg-bambu-dark`;let t=e/c;return t<=.25?`bg-bambu-green/30`:t<=.5?`bg-bambu-green/50`:t<=.75?`bg-bambu-green/75`:`bg-bambu-green`},u=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`],d=a.length,f=r-32-16,p=d>0?Math.floor((f-(d-1)*2)/d):12,m=Math.max(8,Math.min(20,p)),h=m<=10?10:12;return(0,Q.jsx)(`div`,{ref:n,className:`w-full flex justify-center`,children:r>0&&(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`div`,{className:`flex mb-1`,style:{marginLeft:36},children:o.map(({month:e,weekIndex:t},n)=>(0,Q.jsx)(`div`,{className:`text-bambu-gray`,style:{fontSize:h,marginLeft:n===0?0:`${(t-(o[n-1]?.weekIndex||0))*(m+2)-24}px`},children:e},n))}),(0,Q.jsxs)(`div`,{className:`flex`,style:{gap:2},children:[(0,Q.jsx)(`div`,{className:`flex flex-col`,style:{gap:2,marginRight:4,width:32},children:u.map((e,t)=>(0,Q.jsx)(`div`,{className:`text-bambu-gray flex items-center`,style:{width:32,height:m,fontSize:h,visibility:t%2==1?`visible`:`hidden`},children:e},e))}),a.map((e,t)=>(0,Q.jsx)(`div`,{className:`flex flex-col`,style:{gap:2},children:[0,1,2,3,4,5,6].map(t=>{let n=e.find(e=>e.getDay()===t);if(!n)return(0,Q.jsx)(`div`,{style:{width:m,height:m}},t);let r=Wt(n),i=s[r]||0,a=r===Wt(new Date);return(0,Q.jsx)(`div`,{className:`rounded-sm ${l(i)} ${a?`ring-1 ring-white`:``}`,style:{width:m,height:m},title:`${n.toLocaleDateString()}: ${i} print${i===1?``:`s`}`},t)})},t))]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 mt-3 text-bambu-gray`,style:{fontSize:h},children:[(0,Q.jsx)(`span`,{children:`Less`}),(0,Q.jsxs)(`div`,{className:`flex`,style:{gap:2},children:[(0,Q.jsx)(`div`,{className:`rounded-sm bg-bambu-dark`,style:{width:m,height:m}}),(0,Q.jsx)(`div`,{className:`rounded-sm bg-bambu-green/30`,style:{width:m,height:m}}),(0,Q.jsx)(`div`,{className:`rounded-sm bg-bambu-green/50`,style:{width:m,height:m}}),(0,Q.jsx)(`div`,{className:`rounded-sm bg-bambu-green/75`,style:{width:m,height:m}}),(0,Q.jsx)(`div`,{className:`rounded-sm bg-bambu-green`,style:{width:m,height:m}})]}),(0,Q.jsx)(`span`,{children:`More`})]})]})})}var Ni=[`weight`,`prints`,`time`];function Pi({value:e,onChange:t,exclude:n}){let{t:r}=i(),a={weight:r(`stats.filamentByWeight`),prints:r(`stats.filamentByPrints`),time:r(`stats.filamentByTime`)};return(0,Q.jsx)(`div`,{className:`flex gap-0.5 bg-bambu-dark rounded-lg p-0.5`,children:(n?Ni.filter(e=>!n.includes(e)):Ni).map(n=>(0,Q.jsx)(`button`,{onClick:()=>t(n),className:`px-2 py-0.5 text-xs rounded-md transition-colors ${e===n?`bg-bambu-green text-white`:`text-bambu-gray hover:text-white`}`,children:a[n]},n))})}function $(e){if(e>=1e6){let t=e/1e6;return`${t%1==0?t.toFixed(0):t.toFixed(1)}t`}if(e>=1e3){let t=e/1e3;return`${t%1==0?t.toFixed(0):t.toFixed(1)}kg`}return`${Math.round(e)}g`}function Fi(e){let t=rn(e);return t.length?t:[`Unknown`]}var Ii=[`#00ae42`,`#3b82f6`,`#f59e0b`,`#ef4444`,`#8b5cf6`,`#ec4899`,`#14b8a6`,`#f97316`],Li=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`],Ri=[`12am`,`1am`,`2am`,`3am`,`4am`,`5am`,`6am`,`7am`,`8am`,`9am`,`10am`,`11am`,`12pm`,`1pm`,`2pm`,`3pm`,`4pm`,`5pm`,`6pm`,`7pm`,`8pm`,`9pm`,`10pm`,`11pm`];function zi({archives:e,currency:t=`$`,dateFrom:n,dateTo:r}){let{t:a}=i(),[o,s]=(0,q.useState)(`weight`),[c,l]=(0,q.useState)(`weight`),u=(0,q.useMemo)(()=>{let t=new Map;return e.forEach(e=>{let n=Kt(e.completed_at||e.created_at)||new Date,r=`${n.getFullYear()}-${String(n.getMonth()+1).padStart(2,`0`)}-${String(n.getDate()).padStart(2,`0`)}`,i=t.get(r)||{date:r,filament:0,cost:0,energy:0,prints:0};i.filament+=e.filament_used_grams||0,i.cost+=e.cost||0,i.energy+=e.energy_kwh||0,i.prints+=e.quantity??1,t.set(r,i)}),Array.from(t.values()).sort((e,t)=>e.date.localeCompare(t.date)).map(e=>({...e,dateLabel:new Date(e.date).toLocaleDateString(`en-US`,{month:`short`,day:`numeric`})}))},[e]),d=(0,q.useMemo)(()=>{if(n&&r)return Math.max((new Date(r).getTime()-new Date(n).getTime())/864e5,0)+1;if(n)return Math.max((Date.now()-new Date(n).getTime())/864e5,0)+1;if(e.length<2)return 0;let t=e.map(e=>new Date(e.completed_at||e.created_at).getTime());return(Math.max(...t)-Math.min(...t))/864e5},[e,n,r]),f=(0,q.useMemo)(()=>{if(d>7)return[];let t=new Map,n=d>1;return e.forEach(e=>{let n=Kt(e.completed_at||e.created_at)||new Date,r=n.getHours(),i=`${n.getFullYear()}-${String(n.getMonth()+1).padStart(2,`0`)}-${String(n.getDate()).padStart(2,`0`)}T${String(r).padStart(2,`0`)}`,a=t.get(i)||{date:i,filament:0,cost:0,energy:0,prints:0};a.filament+=e.filament_used_grams||0,a.cost+=e.cost||0,a.energy+=e.energy_kwh||0,a.prints+=e.quantity??1,t.set(i,a)}),Array.from(t.values()).sort((e,t)=>e.date.localeCompare(t.date)).map(e=>{let[t,r]=e.date.split(`T`),i=new Date(t),a=parseInt(r,10),o=n?`${Li[i.getDay()]} ${Ri[a]}`:Ri[a];return{...e,dateLabel:o}})},[e,d]),p=(0,q.useMemo)(()=>{if(u.length<=60)return u;let e=new Map;return u.forEach(t=>{let n=new Date(t.date),r=new Date(n);r.setDate(n.getDate()-n.getDay());let i=`${r.getFullYear()}-${String(r.getMonth()+1).padStart(2,`0`)}-${String(r.getDate()).padStart(2,`0`)}`,a=e.get(i)||{week:i,filament:0,cost:0,energy:0,prints:0};a.filament+=t.filament,a.cost+=t.cost,a.energy+=t.energy,a.prints+=t.prints,e.set(i,a)}),Array.from(e.values()).sort((e,t)=>e.week.localeCompare(t.week)).map(e=>({date:e.week,dateLabel:`Week of ${new Date(e.week).toLocaleDateString(`en-US`,{month:`short`,day:`numeric`})}`,...e}))},[u]),m=(0,q.useMemo)(()=>{let t=new Map;return e.forEach(e=>{let n=Fi(e.filament_type);n.forEach(r=>{let i=(e.filament_used_grams||0)/n.length;t.set(r,(t.get(r)||0)+i)})}),Array.from(t.entries()).map(([e,t])=>({name:e,value:Math.round(t)})).sort((e,t)=>t.value-e.value)},[e]),h=(0,q.useMemo)(()=>{let t=new Map;return e.forEach(e=>{Fi(e.filament_type).forEach(e=>{t.set(e,(t.get(e)||0)+1)})}),Array.from(t.entries()).map(([e,t])=>({name:e,value:t})).sort((e,t)=>t.value-e.value)},[e]),g=(0,q.useMemo)(()=>{let t=new Map;return e.forEach(e=>{let n=Fi(e.filament_type),r=(e.actual_time_seconds||e.print_time_seconds||0)/n.length;n.forEach(e=>{t.set(e,(t.get(e)||0)+r)})}),Array.from(t.entries()).map(([e,t])=>({name:e,value:Math.round(t/3600*10)/10})).sort((e,t)=>t.value-e.value)},[e]),_=(0,q.useMemo)(()=>{let t=new Map;return e.forEach(e=>{e.status!==`completed`&&e.status!==`failed`||Fi(e.filament_type).forEach(n=>{let r=t.get(n)||{completed:0,failed:0};e.status===`completed`?r.completed++:r.failed++,t.set(n,r)})}),Array.from(t.entries()).filter(([,e])=>e.completed+e.failed>=2).map(([e,t])=>{let n=t.completed+t.failed;return{name:e,rate:Math.round(t.completed/n*100),total:n}}).sort((e,t)=>t.rate-e.rate)},[e]),v=(0,q.useMemo)(()=>{let t=new Map;return e.forEach(e=>{if(!e.filament_color)return;let n=e.filament_color.split(`,`).map(e=>e.trim()),r=(e.filament_used_grams||0)/n.length;n.forEach(e=>{let n=t.get(e)||{count:0,weight:0};n.count++,n.weight+=r,t.set(e,n)})}),Array.from(t.entries()).map(([e,t])=>({hex:e,value:c===`prints`?t.count:Math.round(t.weight)})).sort((e,t)=>t.value-e.value)},[e,c]),y=o===`weight`?m:o===`prints`?h:g,b=d<=7&&f.length>0?f:p,x=e.reduce((e,t)=>e+(t.filament_used_grams||0),0),S=e.reduce((e,t)=>e+(t.cost||0),0),C=e.reduce((e,t)=>e+(t.energy_kwh||0),0),w=e.reduce((e,t)=>e+(t.energy_cost||0),0),T=e.reduce((e,t)=>e+(t.quantity??1),0),E=new Set(e.map(e=>e.printer_id).filter(Boolean)).size;return(0,Q.jsxs)(`div`,{className:`space-y-4`,children:[(0,Q.jsxs)(`div`,{className:`grid grid-cols-3 gap-2 max-[640px]:grid-cols-1`,children:[(0,Q.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Q.jsx)(`p`,{className:`text-sm text-bambu-gray leading-none`,children:a(`stats.periodFilament`)}),(0,Q.jsx)(`p`,{className:`text-2xl font-bold text-white leading-none`,children:$(x)})]}),(0,Q.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[E,` `,a(`nav.printers`).toLowerCase()]})]}),(0,Q.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Q.jsx)(`p`,{className:`text-sm text-bambu-gray leading-none`,children:a(`stats.periodCost`)}),(0,Q.jsxs)(`p`,{className:`text-2xl font-bold text-white leading-none`,children:[t,S.toFixed(2)]})]}),(0,Q.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[T,` `,a(`common.prints`)]})]}),(0,Q.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Q.jsx)(`p`,{className:`text-sm text-bambu-gray leading-none`,children:a(`stats.avgPerPrint`)}),(0,Q.jsxs)(`p`,{className:`text-2xl font-bold text-white leading-none`,children:[T>0?(x/T).toFixed(0):0,`g`]})]}),(0,Q.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[t,T>0?(S/T).toFixed(2):`0.00`,` avg`]})]})]}),b.length>0?(0,Q.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,Q.jsx)(`h4`,{className:`text-sm font-medium text-bambu-gray mb-4`,children:a(`stats.usageOverTime`)}),(0,Q.jsx)(R,{width:`100%`,height:250,children:(0,Q.jsxs)(cn,{data:b,children:[(0,Q.jsx)(`defs`,{children:(0,Q.jsxs)(`linearGradient`,{id:`colorFilament`,x1:`0`,y1:`0`,x2:`0`,y2:`1`,children:[(0,Q.jsx)(`stop`,{offset:`5%`,stopColor:`#00ae42`,stopOpacity:.3}),(0,Q.jsx)(`stop`,{offset:`95%`,stopColor:`#00ae42`,stopOpacity:0})]})}),(0,Q.jsx)(yt,{strokeDasharray:`3 3`,stroke:`#3d3d3d`}),(0,Q.jsx)(Ze,{dataKey:`dateLabel`,stroke:`#9ca3af`,tick:{fontSize:12},interval:`preserveStartEnd`}),(0,Q.jsx)(Tt,{stroke:`#9ca3af`,tick:{fontSize:12},tickFormatter:e=>`${e}g`}),(0,Q.jsx)(P,{contentStyle:{backgroundColor:`#2d2d2d`,border:`1px solid #3d3d3d`,borderRadius:`8px`},labelStyle:{color:`#fff`},formatter:e=>[`${Number(e??0).toFixed(0)}g`,`Filament`]}),(0,Q.jsx)(sn,{type:`monotone`,dataKey:`filament`,stroke:`#00ae42`,strokeWidth:2,fillOpacity:1,fill:`url(#colorFilament)`})]})})]}):(0,Q.jsx)(`div`,{className:`bg-bambu-dark rounded-lg p-8 text-center text-bambu-gray`,children:a(`stats.noPrintDataInRange`)}),C>0&&b.length>0&&(0,Q.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between mb-4`,children:[(0,Q.jsx)(`h4`,{className:`text-sm font-medium text-bambu-gray`,children:a(`stats.energyOverTime`)}),(0,Q.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[C.toFixed(3),` kWh · `,t,w.toFixed(2)]})]}),(0,Q.jsx)(R,{width:`100%`,height:250,children:(0,Q.jsxs)(cn,{data:b,children:[(0,Q.jsx)(`defs`,{children:(0,Q.jsxs)(`linearGradient`,{id:`colorEnergy`,x1:`0`,y1:`0`,x2:`0`,y2:`1`,children:[(0,Q.jsx)(`stop`,{offset:`5%`,stopColor:`#f59e0b`,stopOpacity:.3}),(0,Q.jsx)(`stop`,{offset:`95%`,stopColor:`#f59e0b`,stopOpacity:0})]})}),(0,Q.jsx)(yt,{strokeDasharray:`3 3`,stroke:`#3d3d3d`}),(0,Q.jsx)(Ze,{dataKey:`dateLabel`,stroke:`#9ca3af`,tick:{fontSize:12},interval:`preserveStartEnd`}),(0,Q.jsx)(Tt,{stroke:`#9ca3af`,tick:{fontSize:12},tickFormatter:e=>`${e}kWh`}),(0,Q.jsx)(P,{contentStyle:{backgroundColor:`#2d2d2d`,border:`1px solid #3d3d3d`,borderRadius:`8px`},labelStyle:{color:`#fff`},formatter:e=>[`${Number(e??0).toFixed(3)} kWh`,a(`stats.energyUsed`)]}),(0,Q.jsx)(sn,{type:`monotone`,dataKey:`energy`,stroke:`#f59e0b`,strokeWidth:2,fillOpacity:1,fill:`url(#colorEnergy)`})]})})]}),(0,Q.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-3 gap-4`,children:[(0,Q.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between mb-4`,children:[(0,Q.jsx)(`h4`,{className:`text-sm font-medium text-bambu-gray`,children:a(`stats.byMaterial`)}),(0,Q.jsx)(Pi,{value:o,onChange:s})]}),y.length>0?(0,Q.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,Q.jsx)(R,{width:160,height:160,children:(0,Q.jsxs)(ji,{children:[(0,Q.jsx)(ir,{data:y,cx:`50%`,cy:`50%`,innerRadius:40,outerRadius:70,paddingAngle:2,dataKey:`value`,children:y.map((e,t)=>(0,Q.jsx)(un,{fill:Ii[t%Ii.length]},`cell-${t}`))}),(0,Q.jsx)(P,{contentStyle:{backgroundColor:`#2d2d2d`,border:`1px solid #3d3d3d`,borderRadius:`8px`},formatter:e=>[o===`weight`?$(Number(e??0)):o===`time`?`${Number(e??0)}h`:`${e??0}`,o===`weight`?`Usage`:o===`time`?`Time`:`Prints`]})]})}),(0,Q.jsx)(`div`,{className:`flex-1 space-y-2 overflow-hidden`,children:y.map((e,t)=>{let n=y.reduce((e,t)=>e+t.value,0),r=n>0?(e.value/n*100).toFixed(0):0;return(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,Q.jsx)(`div`,{className:`w-3 h-3 rounded-sm flex-shrink-0`,style:{backgroundColor:Ii[t%Ii.length]}}),(0,Q.jsx)(`span`,{className:`text-white truncate flex-1`,children:e.name}),(0,Q.jsxs)(`span`,{className:`text-bambu-gray flex-shrink-0`,children:[o===`weight`?$(e.value):o===`time`?`${e.value}h`:e.value,` · `,r,`%`]})]},e.name)})})]}):(0,Q.jsx)(`div`,{className:`h-[160px] flex items-center justify-center text-bambu-gray`,children:a(`stats.noFilamentData`)})]}),(0,Q.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,Q.jsx)(`h4`,{className:`text-sm font-medium text-bambu-gray mb-4`,children:a(`stats.filamentSuccess`)}),_.length>0?(0,Q.jsx)(`div`,{className:`space-y-1.5`,children:_.map(e=>(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,Q.jsx)(`span`,{className:`text-white truncate w-20 flex-shrink-0`,children:e.name}),(0,Q.jsx)(`div`,{className:`flex-1 h-1.5 bg-bambu-dark-secondary rounded-full`,children:(0,Q.jsx)(`div`,{className:`h-full rounded-full transition-all ${e.rate>=90?`bg-status-ok`:e.rate>=70?`bg-status-warning`:`bg-status-error`}`,style:{width:`${e.rate}%`}})}),(0,Q.jsxs)(`span`,{className:`font-medium flex-shrink-0 tabular-nums ${e.rate>=90?`text-status-ok`:e.rate>=70?`text-status-warning`:`text-status-error`}`,children:[e.rate,`%`]}),(0,Q.jsxs)(`span`,{className:`text-bambu-gray flex-shrink-0 text-xs`,children:[`(`,e.total,`)`]})]},e.name))}):(0,Q.jsx)(`div`,{className:`h-[160px] flex items-center justify-center text-bambu-gray`,children:a(`stats.noArchiveData`)})]}),(0,Q.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between mb-4`,children:[(0,Q.jsx)(`h4`,{className:`text-sm font-medium text-bambu-gray`,children:a(`stats.colorDistribution`)}),(0,Q.jsx)(Pi,{value:c,onChange:l,exclude:[`time`]})]}),v.length>0?(()=>{let e=v.reduce((e,t)=>e+t.value,0);return(0,Q.jsxs)(`div`,{children:[(0,Q.jsxs)(`div`,{className:`relative mx-auto`,style:{width:160,height:160},children:[(0,Q.jsx)(R,{width:`100%`,height:`100%`,children:(0,Q.jsxs)(ji,{children:[(0,Q.jsx)(ir,{data:v,cx:`50%`,cy:`50%`,innerRadius:45,outerRadius:70,paddingAngle:2,dataKey:`value`,children:v.map((e,t)=>(0,Q.jsx)(un,{fill:e.hex,stroke:`#1a1a1a`,strokeWidth:1},`color-${t}`))}),(0,Q.jsx)(P,{contentStyle:{backgroundColor:`#2d2d2d`,border:`1px solid #3d3d3d`,borderRadius:`8px`},formatter:e=>[c===`weight`?$(Number(e??0)):`${e??0}`,a(c===`weight`?`stats.filamentByWeight`:`stats.filamentByPrints`)]})]})}),(0,Q.jsxs)(`div`,{className:`absolute inset-0 flex flex-col items-center justify-center`,children:[(0,Q.jsx)(`span`,{className:`text-lg font-bold text-white`,children:c===`weight`?$(e):e}),(0,Q.jsxs)(`span`,{className:`text-[10px] text-bambu-gray`,children:[v.length,` `,v.length===1?`color`:`colors`]})]})]}),(0,Q.jsx)(`div`,{className:`grid grid-cols-2 gap-x-3 gap-y-1 mt-2`,children:v.slice(0,8).map(t=>{let n=e>0?(t.value/e*100).toFixed(0):0;return(0,Q.jsxs)(`div`,{className:`flex items-center gap-1.5 text-xs min-w-0`,children:[(0,Q.jsx)(`div`,{className:`w-2.5 h-2.5 rounded-full flex-shrink-0 border border-black/20`,style:{backgroundColor:t.hex}}),(0,Q.jsxs)(`span`,{className:`text-bambu-gray truncate`,children:[n,`%`]})]},t.hex)})}),v.length>8&&(0,Q.jsxs)(`p`,{className:`text-[10px] text-bambu-gray mt-1 text-center`,children:[`+`,v.length-8,` more`]})]})})():(0,Q.jsx)(`div`,{className:`h-[160px] flex items-center justify-center text-bambu-gray`,children:a(`stats.noColorData`)})]})]})]})}function Bi(e){return Math.abs(e)>=1e3?`${(e/1e3).toFixed(2)} kg`:`${Math.round(e)} g`}function Vi({currency:e,dateFrom:t,dateTo:n}){let{t:o}=i(),{data:s,isLoading:c,isError:l}=a({queryKey:[`supplier-stats`,t??`all`,n??`all`],queryFn:()=>r.getSupplierStats(t,n)});return c?(0,Q.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,Q.jsx)(O,{className:`w-6 h-6 text-bambu-green animate-spin`})}):l?(0,Q.jsxs)(`p`,{className:`flex items-center gap-2 text-sm text-red-400 py-4`,children:[(0,Q.jsx)(Ut,{className:`w-4 h-4`}),o(`stats.suppliers.error`)]}):!s||s.length===0?(0,Q.jsx)(`p`,{className:`text-sm text-bambu-gray py-4`,children:o(`stats.suppliers.empty`)}):(0,Q.jsx)(`div`,{className:`overflow-x-auto`,children:(0,Q.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,Q.jsx)(`thead`,{children:(0,Q.jsxs)(`tr`,{className:`text-left text-xs text-bambu-gray border-b border-bambu-dark-tertiary`,children:[(0,Q.jsx)(`th`,{className:`py-2 pr-4 font-medium`,children:o(`stats.suppliers.supplier`)}),(0,Q.jsx)(`th`,{className:`py-2 pr-4 font-medium text-right`,children:o(`stats.suppliers.spools`)}),(0,Q.jsx)(`th`,{className:`py-2 pr-4 font-medium text-right`,children:o(`stats.suppliers.remaining`)}),(0,Q.jsx)(`th`,{className:`py-2 pr-4 font-medium text-right`,children:o(`stats.suppliers.consumed`)}),(0,Q.jsx)(`th`,{className:`py-2 font-medium text-right`,children:o(`stats.suppliers.cost`)})]})}),(0,Q.jsx)(`tbody`,{children:s.map(t=>(0,Q.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/50 last:border-b-0`,children:[(0,Q.jsx)(`td`,{className:`py-2 pr-4 text-white font-medium`,children:t.supplier_name}),(0,Q.jsx)(`td`,{className:`py-2 pr-4 text-bambu-gray text-right`,children:t.spool_count}),(0,Q.jsx)(`td`,{className:`py-2 pr-4 text-bambu-gray text-right`,children:Bi(t.remaining_g)}),(0,Q.jsx)(`td`,{className:`py-2 pr-4 text-bambu-gray text-right`,children:Bi(t.consumed_g)}),(0,Q.jsxs)(`td`,{className:`py-2 text-bambu-gray text-right`,children:[e,` `,t.cost.toFixed(2)]})]},t.supplier_id))})]})})}function Hi(e){return Math.abs(e)>=1e3?`${(e/1e3).toFixed(2)} kg`:`${Math.round(e)} g`}function Ui({currency:e,dateFrom:t,dateTo:n}){let{t:o}=i(),{data:s,isLoading:c,isError:l}=a({queryKey:[`material-number-stats`,t??null,n??null],queryFn:()=>r.getMaterialNumberStats({dateFrom:t,dateTo:n})});return c?(0,Q.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,Q.jsx)(O,{className:`w-6 h-6 text-bambu-green animate-spin`})}):l?(0,Q.jsx)(`p`,{className:`text-sm text-red-700 dark:text-red-400 py-4`,children:o(`stats.materialNumbers.loadFailed`)}):!s||s.length===0?(0,Q.jsx)(`p`,{className:`text-sm text-bambu-gray py-4`,children:o(`stats.materialNumbers.empty`)}):(0,Q.jsx)(`div`,{className:`overflow-x-auto`,children:(0,Q.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,Q.jsx)(`thead`,{children:(0,Q.jsxs)(`tr`,{className:`text-left text-xs text-bambu-gray border-b border-bambu-dark-tertiary`,children:[(0,Q.jsx)(`th`,{className:`py-2 pr-4 font-medium`,children:o(`inventory.materialNumber`)}),(0,Q.jsx)(`th`,{className:`py-2 pr-4 font-medium text-right`,children:o(`stats.materialNumbers.spools`)}),(0,Q.jsx)(`th`,{className:`py-2 pr-4 font-medium text-right`,children:o(`stats.materialNumbers.remaining`)}),(0,Q.jsx)(`th`,{className:`py-2 pr-4 font-medium text-right`,children:o(`stats.materialNumbers.consumed`)}),(0,Q.jsx)(`th`,{className:`py-2 font-medium text-right`,children:o(`stats.materialNumbers.cost`)})]})}),(0,Q.jsx)(`tbody`,{children:s.map(t=>(0,Q.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/50 last:border-b-0`,children:[(0,Q.jsx)(`td`,{className:`py-2 pr-4 text-white font-medium`,children:t.material_number}),(0,Q.jsx)(`td`,{className:`py-2 pr-4 text-bambu-gray text-right`,children:t.spool_count}),(0,Q.jsx)(`td`,{className:`py-2 pr-4 text-bambu-gray text-right`,children:Hi(t.remaining_g)}),(0,Q.jsx)(`td`,{className:`py-2 pr-4 text-bambu-gray text-right`,children:Hi(t.consumed_g)}),(0,Q.jsxs)(`td`,{className:`py-2 text-bambu-gray text-right`,children:[e,` `,t.cost.toFixed(2)]})]},t.material_number))})]})})}function Wi({id:e,title:t,component:n,isHidden:r,size:i,columnSpan:a,onToggleVisibility:o,onToggleSize:c}){let{attributes:l,listeners:u,setNodeRef:d,transform:f,transition:m,isDragging:h}=s({id:e}),g={transform:p.Transform.toString(f),transition:m,opacity:h?.5:1};return r?null:(0,Q.jsxs)(`div`,{ref:d,style:{...g,gridColumn:`span ${a}`},className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary overflow-hidden ${h?`ring-2 ring-bambu-green shadow-lg`:``}`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 border-b border-bambu-dark-tertiary bg-bambu-dark/30`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`button`,{...l,...u,className:`cursor-grab active:cursor-grabbing p-1 hover:bg-bambu-dark-tertiary rounded transition-colors`,title:`Drag to reorder`,children:(0,Q.jsx)(D,{className:`w-6 h-6 md:w-4 md:h-4 text-bambu-gray`})}),(0,Q.jsx)(`h3`,{className:`text-sm font-medium text-white`,children:t})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Q.jsx)(`button`,{onClick:c,className:`p-1 hover:bg-bambu-dark-tertiary rounded transition-colors`,title:`Size: ${i===1?`1/4`:i===2?`1/2`:`Full`} - Click to cycle`,children:i===4?(0,Q.jsx)(A,{className:`w-4 h-4 text-bambu-gray hover:text-white`}):(0,Q.jsx)(k,{className:`w-4 h-4 text-bambu-gray hover:text-white`})}),(0,Q.jsx)(`button`,{onClick:o,className:`p-1 hover:bg-bambu-dark-tertiary rounded transition-colors`,title:`Hide widget`,children:(0,Q.jsx)(E,{className:`w-4 h-4 text-bambu-gray hover:text-white`})})]})]}),(0,Q.jsx)(`div`,{className:`p-4`,children:typeof n==`function`?n(i):n})]})}function Gi({widgets:e,storageKey:t,columns:n=4,stackBelow:r,hideControls:i=!1,onResetLayout:a,renderControls:o}){let s=()=>{let t={};return e.forEach(e=>{t[e.id]=e.defaultSize||4}),t},[u,p]=(0,q.useState)(()=>{let n=localStorage.getItem(t);if(n)try{let e=JSON.parse(n);if(!e.sizes)e.sizes=s();else{let t=s();for(let n in t)n in e.sizes||(e.sizes[n]=t[n])}return e}catch{}return{order:e.map(e=>e.id),hidden:e.filter(e=>e.defaultVisible===!1).map(e=>e.id),sizes:s()}}),[b,x]=(0,q.useState)(!1),[S,C]=(0,q.useState)(!1);(0,q.useEffect)(()=>{if(!r)return;let e=window.matchMedia(`(max-width: ${r}px)`),t=e=>{C(e.matches)};t(e);let n=e=>t(e);return e.addEventListener?e.addEventListener(`change`,n):e.addListener(n),()=>{e.removeEventListener?e.removeEventListener(`change`,n):e.removeListener(n)}},[r]);let w=r&&S?1:n;(0,q.useEffect)(()=>{let e=()=>x(e=>!e);return window.addEventListener(`toggle-hidden-panel`,e),()=>window.removeEventListener(`toggle-hidden-panel`,e)},[]),(0,q.useEffect)(()=>{localStorage.setItem(t,JSON.stringify(u))},[u,t]),(0,q.useEffect)(()=>{let t=e.map(e=>e.id).filter(e=>!u.order.includes(e));t.length>0&&p(e=>({...e,order:[...e.order,...t]}))},[e,u.order]);let T=h(l(y,{activationConstraint:{distance:8}}),l(f,{coordinateGetter:d})),E=e=>{let{active:t,over:n}=e;n&&t.id!==n.id&&p(e=>{let r=e.order.indexOf(t.id),i=e.order.indexOf(n.id);return{...e,order:m(e.order,r,i)}})},ee=e=>{p(t=>({...t,hidden:t.hidden.includes(e)?t.hidden.filter(t=>t!==e):[...t.hidden,e]}))},D=e=>{p(t=>{let n=t.sizes[e]||4,r=n===1?2:n===2?4:1;return{...t,sizes:{...t.sizes,[e]:r}}})},O=()=>{p({order:e.map(e=>e.id),hidden:e.filter(e=>e.defaultVisible===!1).map(e=>e.id),sizes:s()}),a?.()},k=u.order.map(t=>e.find(e=>e.id===t)).filter(Boolean),A=k.filter(e=>!u.hidden.includes(e.id)),j=k.filter(e=>u.hidden.includes(e.id)),M=o?.({hiddenCount:j.length,showHiddenPanel:b,setShowHiddenPanel:x,resetLayout:O});return(0,Q.jsxs)(`div`,{className:`space-y-4`,children:[M,!i&&!o&&(0,Q.jsxs)(`div`,{className:`flex items-center justify-end gap-2`,children:[(0,Q.jsxs)(W,{variant:`secondary`,size:`sm`,onClick:O,children:[(0,Q.jsx)(Jt,{className:`w-4 h-4`}),`Reset Layout`]}),j.length>0&&(0,Q.jsxs)(W,{variant:`secondary`,size:`sm`,onClick:()=>x(!b),children:[(0,Q.jsx)(Zt,{className:`w-4 h-4`}),j.length,` Hidden`]})]}),b&&j.length>0&&(0,Q.jsxs)(`div`,{className:`p-4 bg-bambu-dark rounded-xl border border-bambu-dark-tertiary`,children:[(0,Q.jsx)(`p`,{className:`text-sm text-bambu-gray mb-3`,children:`Hidden widgets (click to show):`}),(0,Q.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:j.map(e=>(0,Q.jsxs)(`button`,{onClick:()=>ee(e.id),className:`px-3 py-1.5 bg-bambu-dark-tertiary hover:bg-bambu-green/20 rounded-lg text-sm text-white transition-colors flex items-center gap-2`,children:[(0,Q.jsx)(Zt,{className:`w-3 h-3`}),e.title]},e.id))})]}),(0,Q.jsx)(_,{sensors:T,collisionDetection:c,onDragEnd:E,children:(0,Q.jsx)(v,{items:A.map(e=>e.id),strategy:g,children:(0,Q.jsx)(`div`,{className:`grid gap-6`,style:{gridTemplateColumns:`repeat(${w}, minmax(0, 1fr))`},children:A.map(e=>{let t=u.sizes[e.id]||2,n=Math.min(t,w);return(0,Q.jsx)(Wi,{id:e.id,title:e.title,component:e.component,isHidden:u.hidden.includes(e.id),size:t,columnSpan:n,onToggleVisibility:()=>ee(e.id),onToggleSize:()=>D(e.id)},e.id)})})})}),A.length===0&&(0,Q.jsxs)(`div`,{className:`text-center py-12 text-bambu-gray`,children:[(0,Q.jsx)(`p`,{children:`All widgets are hidden.`}),(0,Q.jsx)(W,{className:`mt-4`,onClick:O,children:`Reset Layout`})]})]})}function Ki(e){let t=new Date,n=t.getUTCFullYear(),r=t.getUTCMonth(),i=t.getUTCDate(),a=e=>e.toISOString().split(`T`)[0],o=a(t);switch(e){case`today`:return{dateFrom:o,dateTo:o};case`this-week`:{let e=t.getUTCDay();return{dateFrom:a(new Date(Date.UTC(n,r,i-(e===0?6:e-1)))),dateTo:o}}case`this-month`:return{dateFrom:a(new Date(Date.UTC(n,r,1))),dateTo:o};case`last-7`:return{dateFrom:a(new Date(Date.UTC(n,r,i-6))),dateTo:o};case`last-30`:return{dateFrom:a(new Date(Date.UTC(n,r,i-29))),dateTo:o};case`last-90`:return{dateFrom:a(new Date(Date.UTC(n,r,i-89))),dateTo:o};case`this-year`:return{dateFrom:a(new Date(Date.UTC(n,0,1))),dateTo:o};case`all-time`:return{dateFrom:void 0,dateTo:void 0};case`custom`:return{}}}var qi=[`today`,`this-week`,`this-month`,`last-7`,`last-30`,`last-90`,`this-year`,`all-time`],Ji=[`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`,`Sun`],Yi=[`12am`,`1am`,`2am`,`3am`,`4am`,`5am`,`6am`,`7am`,`8am`,`9am`,`10am`,`11am`,`12pm`,`1pm`,`2pm`,`3pm`,`4pm`,`5pm`,`6pm`,`7pm`,`8pm`,`9pm`,`10pm`,`11pm`],Xi=[{key:`<30m`,max:1800},{key:`30m-1h`,max:3600},{key:`1-2h`,max:7200},{key:`2-4h`,max:14400},{key:`4-8h`,max:28800},{key:`8-12h`,max:43200},{key:`12-24h`,max:86400},{key:`24h+`,max:1/0}],Zi={backgroundColor:`#2d2d2d`,border:`1px solid #3d3d3d`,borderRadius:`8px`};function Qi({stats:e,currency:t}){let{t:n}=i(),r=e?.energy_data_warming_up===!0,a=r?n(`stats.energyWarmingUpTooltip`):void 0;return(0,Q.jsx)(`div`,{className:`grid grid-cols-2 sm:grid-cols-3 gap-4`,children:[{icon:j,color:`text-bambu-green`,label:n(`stats.totalPrints`),value:`${e?.total_prints||0}`},{icon:Xt,color:`text-blue-600 dark:text-blue-400`,label:n(`stats.printTime`),value:`${e?.total_print_time_hours?.toFixed(1)??`0`}h`},{icon:j,color:`text-orange-600 dark:text-orange-400`,label:n(`stats.filamentUsed`),value:$(e?.total_filament_grams||0)},{icon:T,color:`text-green-600 dark:text-green-400`,label:n(`stats.filamentCost`),value:`${t} ${e?.total_cost?.toFixed(2)??`0.00`}`},{icon:$t,color:`text-yellow-600 dark:text-yellow-400`,label:n(`stats.energyUsed`),value:`${e?.total_energy_kwh?.toFixed(3)??`0.000`} kWh`,warning:r,tooltip:a},{icon:T,color:`text-yellow-500`,label:n(`stats.energyCost`),value:`${t} ${e?.total_energy_cost?.toFixed(2)??`0.00`}`,warning:r,tooltip:a},...(e?.total_wear_cost??0)>0?[{icon:tn,color:`text-slate-500 dark:text-slate-300`,label:n(`stats.wearCost`),value:`${t} ${e?.total_wear_cost?.toFixed(2)??`0.00`}`,warning:!1,tooltip:void 0}]:[]].map(e=>(0,Q.jsxs)(`div`,{className:`flex items-start gap-3`,title:e.tooltip,children:[(0,Q.jsx)(`div`,{className:`p-2 rounded-lg bg-bambu-dark ${e.color}`,children:(0,Q.jsx)(e.icon,{className:`w-5 h-5`})}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsxs)(`p`,{className:`text-xs text-bambu-gray flex items-center gap-1`,children:[e.label,e.warning&&(0,Q.jsx)(Ut,{className:`w-3 h-3 text-yellow-600 dark:text-yellow-400`,"aria-label":e.tooltip})]}),(0,Q.jsx)(`p`,{className:`text-xl font-bold text-white`,children:e.value})]})]},e.label))})}function $i({stats:e,printerMap:t,size:n=1}){let{t:r}=i(),a=(e?.successful_prints||0)+(e?.failed_prints||0),o=a?Math.round((e?.successful_prints||0)/a*100):0,s=n===1?112:n===2?128:144,c=s/2-8,l=c*2*Math.PI;return(0,Q.jsxs)(`div`,{className:`flex items-center gap-6`,children:[(0,Q.jsxs)(`div`,{className:`relative flex-shrink-0`,style:{width:s,height:s},children:[(0,Q.jsxs)(`svg`,{className:`w-full h-full -rotate-90`,children:[(0,Q.jsx)(`circle`,{cx:s/2,cy:s/2,r:c,fill:`none`,stroke:`#3d3d3d`,strokeWidth:`10`}),(0,Q.jsx)(`circle`,{cx:s/2,cy:s/2,r:c,fill:`none`,stroke:`#00ae42`,strokeWidth:`10`,strokeLinecap:`round`,strokeDasharray:`${o/100*l} ${l}`})]}),(0,Q.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center`,children:(0,Q.jsxs)(`span`,{className:`font-bold text-white ${n>=2?`text-2xl`:`text-xl`}`,children:[o,`%`]})})]}),(0,Q.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(w,{className:`w-4 h-4 text-status-ok flex-shrink-0`}),(0,Q.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:r(`stats.successful`)}),(0,Q.jsx)(`span`,{className:`text-sm text-white font-medium`,children:e?.successful_prints||0})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(S,{className:`w-4 h-4 text-status-error flex-shrink-0`}),(0,Q.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:r(`stats.failed`)}),(0,Q.jsx)(`span`,{className:`text-sm text-white font-medium`,children:e?.failed_prints||0})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(u,{className:`w-4 h-4 text-status-warning flex-shrink-0`}),(0,Q.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:r(`stats.cancelled`)}),(0,Q.jsx)(`span`,{className:`text-sm text-white font-medium`,children:e?.cancelled_prints||0})]})]}),n>=2&&e?.prints_by_printer&&Object.keys(e.prints_by_printer).length>0&&(0,Q.jsxs)(`div`,{className:`mt-4 pt-4 border-t border-bambu-dark-tertiary`,children:[(0,Q.jsx)(`p`,{className:`text-xs text-bambu-gray font-medium mb-2`,children:r(`stats.printsByPrinter`)}),(0,Q.jsx)(`div`,{className:`grid gap-x-6 gap-y-1 ${n===4?`grid-cols-3`:`grid-cols-2`}`,style:{width:`fit-content`},children:Object.entries(e.prints_by_printer).map(([e,n])=>(0,Q.jsxs)(`div`,{className:`flex items-center gap-3 text-sm`,children:[(0,Q.jsx)(`span`,{className:`text-bambu-gray truncate max-w-[120px]`,children:t.get(e)||`${r(`common.printer`)} ${e}`}),(0,Q.jsx)(`span`,{className:`text-white font-medium`,children:n})]},e))})]})]})]})}function ea({stats:e,printerMap:t,size:n=1}){let{t:r}=i(),a=e?.average_time_accuracy;if(a==null)return(0,Q.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,Q.jsx)(`p`,{className:`text-bambu-gray text-center py-4`,children:r(`stats.noTimeAccuracyData`)})});let o=(Math.min(150,Math.max(50,a))-50)/100*100,s=(e=>e>=95&&e<=105?`#00ae42`:e>105?`#3b82f6`:`#f97316`)(a),c=a-100,l=n===1?112:n===2?128:144,u=l/2-8,d=u*2*Math.PI,f=n===1?3:n===2?6:999,p=e?.time_accuracy_by_printer?Object.entries(e.time_accuracy_by_printer).slice(0,f):[];return(0,Q.jsxs)(`div`,{className:`flex items-center gap-6`,children:[(0,Q.jsxs)(`div`,{className:`relative flex-shrink-0`,style:{width:l,height:l},children:[(0,Q.jsxs)(`svg`,{className:`w-full h-full -rotate-90`,children:[(0,Q.jsx)(`circle`,{cx:l/2,cy:l/2,r:u,fill:`none`,stroke:`#3d3d3d`,strokeWidth:`10`}),(0,Q.jsx)(`circle`,{cx:l/2,cy:l/2,r:u,fill:`none`,stroke:s,strokeWidth:`10`,strokeLinecap:`round`,strokeDasharray:`${o/100*d} ${d}`})]}),(0,Q.jsxs)(`div`,{className:`absolute inset-0 flex flex-col items-center justify-center`,children:[(0,Q.jsxs)(`span`,{className:`font-bold text-white ${n>=2?`text-2xl`:`text-xl`}`,children:[a.toFixed(0),`%`]}),(0,Q.jsxs)(`span`,{className:`text-xs ${c>=0?`text-blue-700 dark:text-blue-400`:`text-orange-700 dark:text-orange-400`}`,children:[c>=0?`+`:``,c.toFixed(0),`%`]})]})]}),(0,Q.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-bambu-gray`,children:[(0,Q.jsx)(M,{className:`w-3 h-3 flex-shrink-0`}),(0,Q.jsx)(`span`,{children:r(`stats.perfectEstimate`)})]}),p.length>0&&(0,Q.jsx)(`div`,{className:`mt-2 ${n===4?`grid grid-cols-3 gap-x-6 gap-y-1`:n===2?`grid grid-cols-2 gap-x-6 gap-y-1`:`space-y-1`}`,style:{width:`fit-content`},children:p.map(([e,n])=>(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-xs`,children:[(0,Q.jsx)(`span`,{className:`text-bambu-gray truncate max-w-[100px]`,children:t.get(e)||`${r(`common.printer`)} ${e}`}),(0,Q.jsxs)(`span`,{className:`font-medium ${n>=95&&n<=105?`text-status-ok`:n>105?`text-blue-700 dark:text-blue-400`:`text-status-warning`}`,children:[n.toFixed(0),`%`]})]},e))})]})]})}function ta({printDates:e,dateFrom:t,dateTo:n}){let{days:r,hourlyCounts:i,maxCount:a}=(0,q.useMemo)(()=>{let r=new Date(t+`T00:00:00`),i=new Date(n+`T00:00:00`),a=[],o=e=>`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,`0`)}-${String(e.getDate()).padStart(2,`0`)}`,s=new Date(r);for(;s<=i;)a.push({key:o(s),label:s.toLocaleDateString(void 0,{weekday:`short`,month:`short`,day:`numeric`})}),s.setDate(s.getDate()+1);let c={},l=0;return e.forEach(e=>{let t=Kt(e);if(!t)return;let n=`${`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,`0`)}-${String(t.getDate()).padStart(2,`0`)}`}-${t.getHours()}`;c[n]=(c[n]||0)+1,c[n]>l&&(l=c[n])}),{days:a,hourlyCounts:c,maxCount:Math.max(1,l)}},[e,t,n]),o=e=>{if(e===0)return`bg-bambu-dark`;let t=e/a;return t<=.25?`bg-bambu-green/30`:t<=.5?`bg-bambu-green/50`:t<=.75?`bg-bambu-green/75`:`bg-bambu-green`};return(0,Q.jsxs)(`div`,{className:`w-full overflow-x-auto`,children:[(0,Q.jsxs)(`div`,{className:`inline-flex flex-col`,style:{gap:2},children:[(0,Q.jsx)(`div`,{className:`flex`,style:{gap:2,marginLeft:84},children:Yi.map((e,t)=>(0,Q.jsx)(`div`,{className:`text-bambu-gray text-[10px] text-center`,style:{width:20,visibility:t%2==0?`visible`:`hidden`},children:e},t))}),r.map(e=>(0,Q.jsxs)(`div`,{className:`flex items-center`,style:{gap:2},children:[(0,Q.jsx)(`div`,{className:`text-bambu-gray text-[10px] flex-shrink-0 truncate`,style:{width:80},children:e.label}),Array.from({length:24},(t,n)=>{let r=i[`${e.key}-${n}`]||0;return(0,Q.jsx)(`div`,{className:`rounded-sm ${o(r)}`,style:{width:20,height:20},title:`${e.label} ${Yi[n]}: ${r} print${r===1?``:`s`}`},n)})]},e.key))]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 mt-3 text-bambu-gray text-xs`,children:[(0,Q.jsx)(`span`,{children:`Less`}),(0,Q.jsxs)(`div`,{className:`flex`,style:{gap:2},children:[(0,Q.jsx)(`div`,{className:`rounded-sm bg-bambu-dark`,style:{width:20,height:20}}),(0,Q.jsx)(`div`,{className:`rounded-sm bg-bambu-green/30`,style:{width:20,height:20}}),(0,Q.jsx)(`div`,{className:`rounded-sm bg-bambu-green/50`,style:{width:20,height:20}}),(0,Q.jsx)(`div`,{className:`rounded-sm bg-bambu-green/75`,style:{width:20,height:20}}),(0,Q.jsx)(`div`,{className:`rounded-sm bg-bambu-green`,style:{width:20,height:20}})]}),(0,Q.jsx)(`span`,{children:`More`})]})]})}function na({printDates:e,size:t=2,dateFrom:n,dateTo:r}){let i=(0,q.useMemo)(()=>n&&r?Math.max((new Date(r).getTime()-new Date(n).getTime())/864e5,0)+1:n?Math.max((Date.now()-new Date(n).getTime())/864e5,0)+1:1/0,[n,r]);return i<=7&&n&&r?(0,Q.jsx)(ta,{printDates:e,dateFrom:n,dateTo:r}):(0,Q.jsx)(Mi,{printDates:e,months:i===1/0?t===1?3:t===2?6:12:Math.max(1,Math.ceil(i/30))})}function ra({stats:e,archives:t,printerMap:n}){let{t:r}=i(),[a,o]=(0,q.useState)(`weight`),[s,c]=(0,q.useState)(`weight`),l=(0,q.useMemo)(()=>{let i=new Map;return e?.prints_by_printer&&Object.entries(e.prints_by_printer).forEach(([e,t])=>{let n=i.get(e)||{prints:0,weight:0,time:0};n.prints=t,i.set(e,n)}),t.forEach(t=>{if(!t.printer_id)return;let n=String(t.printer_id),r=i.get(n)||{prints:0,weight:0,time:0};r.weight+=t.filament_used_grams||0,r.time+=t.actual_time_seconds||t.print_time_seconds||0,e?.prints_by_printer||r.prints++,i.set(n,r)}),Array.from(i.entries()).map(([e,t])=>({name:n.get(e)||`${r(`common.printer`)} ${e}`,value:a===`prints`?t.prints:a===`weight`?Math.round(t.weight):Math.round(t.time/3600*10)/10})).sort((e,t)=>t.value-e.value)},[e,t,n,a,r]),u=(0,q.useMemo)(()=>{let e=Array.from({length:24},(e,t)=>({hour:t,label:Yi[t],total:0,failures:0}));return t.forEach(t=>{if(!t.started_at)return;let n=Kt(t.started_at);if(!n)return;let r=n.getHours();e[r].total++,t.status===`failed`&&e[r].failures++}),e},[t]),d=(0,q.useMemo)(()=>{let e=Xi.map(e=>({name:e.key,count:0}));return t.forEach(t=>{let n=t.actual_time_seconds||t.print_time_seconds;if(!(!n||n<=0)){for(let t=0;t{let e=[0,0,0,0,0,0,0],n=new Set;t.forEach(t=>{let r=Kt(t.created_at)||new Date(t.created_at),i=r.getDay()-1;i<0&&(i=6),s===`prints`?e[i]++:s===`weight`?e[i]+=t.filament_used_grams||0:e[i]+=(t.actual_time_seconds||t.print_time_seconds||0)/3600;let a=new Date(r);a.setDate(r.getDate()-(r.getDay()+6)%7),n.add(`${a.getFullYear()}-${String(a.getMonth()+1).padStart(2,`0`)}-${String(a.getDate()).padStart(2,`0`)}`)});let r=Math.max(n.size,1);return Ji.map((t,n)=>({name:t,avg:Math.round(e[n]/r*10)/10}))},[t,s]),p=e=>({unit:e===`weight`?`g`:e===`time`?`h`:``,color:e===`weight`?`#00ae42`:e===`time`?`#3b82f6`:`#f59e0b`}),m=p(a),h=r(a===`weight`?`stats.filamentByWeight`:a===`time`?`stats.hours`:`common.prints`),g=p(s),_=r(s===`weight`?`stats.avgWeight`:s===`time`?`stats.avgTime`:`stats.avgPrints`);return(0,Q.jsxs)(`div`,{className:`space-y-4`,children:[(0,Q.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,Q.jsx)(`h4`,{className:`text-sm font-medium text-bambu-gray`,children:r(`stats.printsByPrinter`)}),(0,Q.jsx)(Pi,{value:a,onChange:o})]}),l.length>0?(0,Q.jsx)(R,{width:`100%`,height:Math.max(140,l.length*40),children:(0,Q.jsxs)(gi,{data:l,layout:`vertical`,margin:{left:10},children:[(0,Q.jsx)(yt,{strokeDasharray:`3 3`,stroke:`#3d3d3d`}),(0,Q.jsx)(Ze,{type:`number`,stroke:`#9ca3af`,tick:{fontSize:11},unit:m.unit}),(0,Q.jsx)(Tt,{type:`category`,dataKey:`name`,stroke:`#9ca3af`,tick:{fontSize:11},width:100}),(0,Q.jsx)(P,{contentStyle:Zi,formatter:e=>[a===`weight`?$(Number(e??0)):`${e??0}${m.unit}`,h]}),(0,Q.jsx)(mi,{dataKey:`value`,fill:m.color,radius:[0,4,4,0]})]})}):(0,Q.jsx)(`p`,{className:`text-bambu-gray text-center py-4`,children:r(`stats.noPrinterData`)})]}),(0,Q.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-3 gap-4`,children:[(0,Q.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,Q.jsx)(`h4`,{className:`text-sm font-medium text-bambu-gray mb-3`,children:r(`stats.printDuration`)}),t.length>0?(0,Q.jsx)(R,{width:`100%`,height:160,children:(0,Q.jsxs)(gi,{data:d,children:[(0,Q.jsx)(yt,{strokeDasharray:`3 3`,stroke:`#3d3d3d`}),(0,Q.jsx)(Ze,{dataKey:`name`,stroke:`#9ca3af`,tick:{fontSize:11}}),(0,Q.jsx)(Tt,{stroke:`#9ca3af`,tick:{fontSize:11},allowDecimals:!1}),(0,Q.jsx)(P,{contentStyle:Zi}),(0,Q.jsx)(mi,{dataKey:`count`,name:r(`common.prints`),fill:`#00ae42`,radius:[4,4,0,0]})]})}):(0,Q.jsx)(`p`,{className:`text-bambu-gray text-center py-4`,children:r(`stats.noArchiveData`)})]}),(0,Q.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,Q.jsx)(`h4`,{className:`text-sm font-medium text-bambu-gray`,children:r(`stats.printHabits`)}),(0,Q.jsx)(Pi,{value:s,onChange:c})]}),t.length>0?(0,Q.jsx)(R,{width:`100%`,height:160,children:(0,Q.jsxs)(gi,{data:f,children:[(0,Q.jsx)(yt,{strokeDasharray:`3 3`,stroke:`#3d3d3d`}),(0,Q.jsx)(Ze,{dataKey:`name`,stroke:`#9ca3af`,tick:{fontSize:11}}),(0,Q.jsx)(Tt,{stroke:`#9ca3af`,tick:{fontSize:11},unit:g.unit}),(0,Q.jsx)(P,{contentStyle:Zi,formatter:e=>[`${e??0}${g.unit}`,_]}),(0,Q.jsx)(mi,{dataKey:`avg`,fill:g.color,radius:[4,4,0,0]})]})}):(0,Q.jsx)(`p`,{className:`text-bambu-gray text-center py-4`,children:r(`stats.noArchiveData`)})]}),(0,Q.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,Q.jsx)(`h4`,{className:`text-sm font-medium text-bambu-gray mb-3`,children:r(`stats.printTimeOfDay`)}),t.length>0?(0,Q.jsx)(R,{width:`100%`,height:160,children:(0,Q.jsxs)(gi,{data:u,children:[(0,Q.jsx)(yt,{strokeDasharray:`3 3`,stroke:`#3d3d3d`}),(0,Q.jsx)(Ze,{dataKey:`label`,stroke:`#9ca3af`,tick:{fontSize:10},interval:5}),(0,Q.jsx)(Tt,{stroke:`#9ca3af`,tick:{fontSize:11},allowDecimals:!1}),(0,Q.jsx)(P,{contentStyle:Zi}),(0,Q.jsx)(mi,{dataKey:`total`,name:r(`stats.totalPrints`),fill:`#00ae42`,radius:[2,2,0,0]}),(0,Q.jsx)(mi,{dataKey:`failures`,name:r(`stats.failed`),fill:`#ef4444`,radius:[2,2,0,0]})]})}):(0,Q.jsx)(`p`,{className:`text-bambu-gray text-center py-4`,children:r(`stats.noArchiveData`)})]})]})]})}function ia({archives:e,currency:t,dateFrom:n,dateTo:r}){let{t:a}=i();return!e||e.length===0?(0,Q.jsx)(`p`,{className:`text-bambu-gray text-center py-4`,children:a(`stats.noPrintData`)}):(0,Q.jsx)(zi,{archives:e,currency:t,dateFrom:n,dateTo:r})}function aa({size:e=1,dateFrom:t,dateTo:n,createdById:o}){let{t:s}=i(),c=!!(t||n),{data:l,isLoading:u}=a({queryKey:[`failureAnalysis`,t,n,o??`all`],queryFn:()=>r.getFailureAnalysis({...c?{dateFrom:t,dateTo:n}:{days:30},createdById:o})});if(u)return(0,Q.jsx)(`div`,{className:`flex justify-center py-4`,children:(0,Q.jsx)(O,{className:`w-6 h-6 text-bambu-green animate-spin`})});if(!l||l.total_prints===0)return(0,Q.jsx)(`p`,{className:`text-bambu-gray text-center py-4`,children:s(c?`stats.noPrintDataInRange`:`stats.noPrintDataLast30Days`)});let d=e===1?5:e===2?8:999,f=Object.entries(l.failures_by_reason).sort(([,e],[,t])=>t-e),p=f.slice(0,d),m=f.length>d;return(0,Q.jsxs)(`div`,{className:`${e>=2?`flex gap-8`:`space-y-4`}`,children:[(0,Q.jsxs)(`div`,{className:e>=2?`flex-shrink-0`:``,children:[(0,Q.jsx)(`div`,{className:`flex items-center gap-4`,children:(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(Ut,{className:`w-5 h-5 ${l.failure_rate>20?`text-status-error`:l.failure_rate>10?`text-status-warning`:`text-status-ok`}`}),(0,Q.jsxs)(`span`,{className:`font-bold text-white ${e>=2?`text-3xl`:`text-2xl`}`,children:[l.failure_rate.toFixed(1),`%`]})]})}),(0,Q.jsx)(`div`,{className:`text-sm text-bambu-gray mt-1`,children:s(`stats.failedPrintsCount`,{failed:l.failed_prints,total:l.total_prints})}),(l.rejected_prints??0)>0&&(0,Q.jsxs)(`div`,{className:`text-sm mt-1`,children:[(0,Q.jsx)(`span`,{className:`text-status-warning`,children:s(`stats.rejectedPrintsCount`,{rejected:l.rejected_prints})}),(0,Q.jsx)(`span`,{className:`text-bambu-gray ml-2`,children:s(`stats.yieldRate`,{rate:(l.yield_rate??0).toFixed(1)})})]}),l.trend&&l.trend.length>=2&&(0,Q.jsx)(`div`,{className:`${e>=2?`mt-4`:`mt-2 pt-2 border-t border-bambu-dark-tertiary`}`,children:(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,Q.jsx)(Ie,{className:`w-4 h-4 ${l.trend[l.trend.length-1].failure_rate0&&(0,Q.jsxs)(`div`,{className:`flex-1 ${e>=2?`border-l border-bambu-dark-tertiary pl-8`:`pt-2`}`,children:[(0,Q.jsx)(`p`,{className:`text-xs text-bambu-gray font-medium mb-2`,children:s(e>=2?`stats.failureReasons`:`stats.topFailureReasons`)}),(0,Q.jsx)(`div`,{className:`${e===4?`grid grid-cols-2 gap-x-6 gap-y-1`:`space-y-1`}`,children:p.map(([t,n])=>(0,Q.jsxs)(`div`,{className:`flex items-center justify-between text-sm`,children:[(0,Q.jsx)(`span`,{className:`text-white truncate ${e===4?`max-w-[200px]`:`max-w-[160px]`}`,children:t?s(`editArchive.failureReasons.${t}`,{defaultValue:t}):s(`common.unknown`)}),(0,Q.jsx)(`span`,{className:`text-bambu-gray ml-2`,children:n})]},t))}),m&&(0,Q.jsx)(`p`,{className:`text-xs text-bambu-gray mt-2`,children:s(`common.more`,{count:f.length-d})})]})]})}function oa({archives:e,currency:t}){let{t:n}=i(),r=(0,q.useMemo)(()=>{let r=[];if(e.length===0)return r;let i=t=>{let n=null,r=0;return e.forEach(e=>{let i=t(e);i&&i>r&&(r=i,n=e)}),{archive:n,value:r}},a=i(e=>e.status===`completed`?e.actual_time_seconds:null);a.archive&&r.push({icon:Xt,iconColor:`text-blue-600 dark:text-blue-400`,label:n(`stats.longestPrint`),value:Gt(a.value),detail:a.archive.print_name||null});let o=i(e=>e.filament_used_grams);o.archive&&r.push({icon:j,iconColor:`text-orange-600 dark:text-orange-400`,label:n(`stats.heaviestPrint`),value:$(o.value),detail:o.archive.print_name||null});let s=i(e=>(e.cost??0)+(e.energy_cost??0)+(e.wear_cost??0));s.archive&&r.push({icon:T,iconColor:`text-green-600 dark:text-green-400`,label:n(`stats.mostExpensivePrint`),value:`${t}${s.value.toFixed(2)}`,detail:s.archive.print_name||null});let c=new Map;e.forEach(e=>{let t=Kt(e.created_at)||new Date(e.created_at),n=`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,`0`)}-${String(t.getDate()).padStart(2,`0`)}`;c.set(n,(c.get(n)||0)+1)});let l=``,u=0;c.forEach((e,t)=>{e>u&&(u=e,l=t)}),u>1&&r.push({icon:b,iconColor:`text-purple-600 dark:text-purple-400`,label:n(`stats.busiestDay`),value:`${u} ${n(`common.prints`)}`,detail:(()=>{let[e,t,n]=l.split(`-`).map(Number);return new Date(e,t-1,n).toLocaleDateString(void 0,{month:`short`,day:`numeric`,year:`numeric`})})()});let d=[...e].filter(e=>e.status===`completed`||e.status===`failed`).sort((e,t)=>new Date(t.completed_at||t.created_at).getTime()-new Date(e.completed_at||e.created_at).getTime()),f=0;for(let e of d)if(e.status===`completed`)f++;else break;return f>0&&r.push({icon:$t,iconColor:`text-yellow-600 dark:text-yellow-400`,label:n(`stats.successStreak`),value:`${f}`,detail:f===1?n(`stats.streakPrint`):n(`stats.streakPrints`,{count:f})}),r},[e,t,n]);return r.length===0?(0,Q.jsx)(`p`,{className:`text-bambu-gray text-center py-4`,children:n(`stats.noArchiveData`)}):(0,Q.jsx)(`div`,{className:`space-y-3`,children:r.map((e,t)=>(0,Q.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Q.jsx)(`div`,{className:`p-1.5 rounded-lg bg-bambu-dark ${e.iconColor}`,children:(0,Q.jsx)(e.icon,{className:`w-4 h-4`})}),(0,Q.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Q.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:e.label}),(0,Q.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,Q.jsx)(`span`,{className:`text-sm font-bold text-white`,children:e.value}),e.detail&&(0,Q.jsx)(`span`,{className:`text-xs text-bambu-gray truncate`,children:e.detail})]})]})]},t))})}function sa(){let{t:e}=i(),{showToast:t}=C(),{hasPermission:n,authEnabled:o}=nn(),[s,c]=(0,q.useState)(!1),[l,u]=(0,q.useState)(!1),[d,f]=(0,q.useState)(0),[p,m]=(0,q.useState)(0),[h,g]=(0,q.useState)(!1),[_,v]=(0,q.useState)(null),[y,S]=(0,q.useState)(!1),w=o&&n(`stats:filter_by_user`),[T,E]=(0,q.useState)(()=>{try{let e=localStorage.getItem(`bambusy-stats-timeframe`);if(e){let t=JSON.parse(e);if(t.preset)return t}}catch{}return{preset:`all-time`,dateFrom:void 0,dateTo:void 0}}),[D,k]=(0,q.useState)(!1);(0,q.useEffect)(()=>{localStorage.setItem(`bambusy-stats-timeframe`,JSON.stringify(T))},[T]);let A=(0,q.useMemo)(()=>T.preset===`custom`?{dateFrom:T.dateFrom,dateTo:T.dateTo}:Ki(T.preset),[T]);(0,q.useEffect)(()=>{let e=()=>{try{let e=localStorage.getItem(`bambusy-dashboard-layout-v2`);e&&m(JSON.parse(e).hidden?.length||0)}catch{m(0)}};e(),window.addEventListener(`storage`,e);let t=setInterval(e,2e3);return()=>{window.removeEventListener(`storage`,e),clearInterval(t)}},[d]);let j=_===null?void 0:_,{data:M,isLoading:te,isFetching:ne,refetch:re}=a({queryKey:[`archiveStats`,A.dateFrom,A.dateTo,j??`all`],queryFn:()=>r.getArchiveStats({dateFrom:A.dateFrom,dateTo:A.dateTo,createdById:j})}),{data:ie}=a({queryKey:[`printers`],queryFn:r.getPrinters}),{data:ae,isFetching:oe,refetch:se}=a({queryKey:[`archivesSlim`,A.dateFrom,A.dateTo,j??`all`],queryFn:()=>r.getArchivesSlim(A.dateFrom,A.dateTo,j)}),{data:ce}=a({queryKey:[`settings`],queryFn:r.getSettings}),{data:le,isPending:ue}=a({queryKey:[`spoolman-settings`],queryFn:r.getSpoolmanSettings,staleTime:300*1e3}),N=!ue,de=le?.spoolman_enabled===`true`&&!!le?.spoolman_url,{data:fe}=a({queryKey:[`users`,`slim`],queryFn:r.getUsersSlim,enabled:w}),pe=(0,q.useMemo)(()=>_===null?e(`stats.allUsers`,`All Users`):_===-1?e(`stats.noUser`,`No User (System)`):fe?.find(e=>e.id===_)?.username??`?`,[_,fe,e]),me=async n=>{u(!1),c(!0);try{let{blob:i,filename:a}=await r.exportStats({format:n,days:90,createdById:j}),o=URL.createObjectURL(i),s=document.createElement(`a`);s.href=o,s.download=a,s.click(),URL.revokeObjectURL(o),t(e(`stats.exportDownloaded`))}catch{t(e(`stats.exportFailed`),`error`)}finally{c(!1)}},he=async()=>{g(!0);try{let n=await r.recalculateCosts();await Promise.all([re(),se()]),t(e(`stats.recalculatedCosts`,{count:n.updated}))}catch{t(e(`stats.recalculateFailed`),`error`)}finally{g(!1)}},ge=(ne||oe)&&!te,_e=Qt(ce?.currency||`USD`),ve=(0,q.useMemo)(()=>new Map([...Object.entries(M?.printer_names||{}),...ie?.map(e=>[String(e.id),e.name])||[]]),[M?.printer_names,ie]),ye=(0,q.useMemo)(()=>ae?.map(e=>e.created_at)||[],[ae]);if(te)return(0,Q.jsx)(`div`,{className:`p-4 md:p-8`,children:(0,Q.jsx)(`div`,{className:`text-center py-12 text-bambu-gray`,children:e(`stats.loadingStats`)})});let be=[{id:`quick-stats`,title:e(`stats.quickStats`),component:(0,Q.jsx)(Qi,{stats:M,currency:_e}),defaultSize:2},{id:`success-rate`,title:e(`stats.successRate`),component:e=>(0,Q.jsx)($i,{stats:M,printerMap:ve,size:e}),defaultSize:1},{id:`time-accuracy`,title:e(`stats.timeAccuracy`),component:e=>(0,Q.jsx)(ea,{stats:M,printerMap:ve,size:e}),defaultSize:1},{id:`failure-analysis`,title:e(`stats.failureAnalysis`),component:e=>(0,Q.jsx)(aa,{size:e,dateFrom:A.dateFrom,dateTo:A.dateTo,createdById:j}),defaultSize:1},{id:`print-activity`,title:e(`stats.printActivity`),component:e=>(0,Q.jsx)(na,{printDates:ye,size:e,dateFrom:A.dateFrom,dateTo:A.dateTo}),defaultSize:2},{id:`records`,title:e(`stats.records`),component:(0,Q.jsx)(oa,{archives:ae||[],currency:_e}),defaultSize:1},{id:`printer-stats`,title:e(`stats.printerStats`),component:(0,Q.jsx)(ra,{stats:M,archives:ae||[],printerMap:ve}),defaultSize:4},{id:`filament-trends`,title:e(`stats.filamentTrends`),component:(0,Q.jsx)(ia,{archives:ae||[],currency:_e,dateFrom:A.dateFrom,dateTo:A.dateTo}),defaultSize:4},...!N||de?[]:[{id:`suppliers`,title:e(`stats.suppliers.title`),component:(0,Q.jsx)(Vi,{currency:_e,dateFrom:A.dateFrom,dateTo:A.dateTo}),defaultSize:2}],...!N||de?[]:[{id:`material-numbers`,title:e(`stats.materialNumbers.title`),component:(0,Q.jsx)(Ui,{currency:_e,dateFrom:A.dateFrom,dateTo:A.dateTo}),defaultSize:2}]];return(0,Q.jsxs)(`div`,{className:`p-4 md:p-8`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4 mb-6`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,Q.jsx)(Yt,{className:`w-7 h-7 text-bambu-green`}),e(`stats.title`)]}),ge&&(0,Q.jsx)(O,{className:`w-5 h-5 text-bambu-green animate-spin`})]}),(0,Q.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:e(`stats.subtitle`)})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[p>0&&(0,Q.jsxs)(W,{variant:`secondary`,onClick:()=>{window.dispatchEvent(new CustomEvent(`toggle-hidden-panel`))},children:[(0,Q.jsx)(Zt,{className:`w-4 h-4`}),e(`stats.hiddenCount`,{count:p})]}),(0,Q.jsxs)(W,{variant:`secondary`,onClick:()=>{localStorage.removeItem(`bambusy-dashboard-layout-v2`),f(e=>e+1),t(e(`stats.layoutReset`))},disabled:!n(`settings:update`),title:n(`settings:update`)?void 0:e(`stats.noPermissionResetLayout`),children:[(0,Q.jsx)(Jt,{className:`w-4 h-4`}),e(`stats.resetLayout`)]}),(0,Q.jsxs)(W,{variant:`secondary`,onClick:he,disabled:h||!n(`archives:update_all`),title:n(`archives:update_all`)?e(`stats.recalculateCostsHint`):e(`stats.noPermissionRecalculate`),children:[h?(0,Q.jsx)(O,{className:`w-4 h-4 animate-spin`}):(0,Q.jsx)(ln,{className:`w-4 h-4`}),e(`stats.recalculateCosts`)]}),(0,Q.jsxs)(`div`,{className:`relative`,children:[(0,Q.jsxs)(W,{variant:`secondary`,onClick:()=>u(!l),disabled:s,children:[s?(0,Q.jsx)(O,{className:`w-4 h-4 animate-spin`}):(0,Q.jsx)(ee,{className:`w-4 h-4`}),e(`stats.exportStats`)]}),l&&(0,Q.jsxs)(`div`,{className:`absolute right-0 top-full mt-1 w-48 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl z-20`,children:[(0,Q.jsxs)(`button`,{className:`w-full px-4 py-2 text-left text-white hover:bg-bambu-dark-tertiary transition-colors flex items-center gap-2 rounded-t-lg`,onClick:()=>me(`csv`),children:[(0,Q.jsx)(en,{className:`w-4 h-4`}),e(`stats.exportAsCsv`)]}),(0,Q.jsxs)(`button`,{className:`w-full px-4 py-2 text-left text-white hover:bg-bambu-dark-tertiary transition-colors flex items-center gap-2 rounded-b-lg`,onClick:()=>me(`xlsx`),children:[(0,Q.jsx)(ee,{className:`w-4 h-4`}),e(`stats.exportAsExcel`)]})]})]}),w&&fe&&fe.length>0&&(0,Q.jsxs)(`div`,{className:`relative`,children:[(0,Q.jsxs)(W,{variant:`secondary`,onClick:()=>S(!y),children:[(0,Q.jsx)(qt,{className:`w-4 h-4`}),pe,(0,Q.jsx)(x,{className:`w-3 h-3`})]}),y&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>S(!1)}),(0,Q.jsxs)(`div`,{className:`absolute right-0 top-full mt-1 w-48 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl z-20 p-2 max-h-64 overflow-y-auto`,children:[(0,Q.jsx)(`button`,{className:`w-full px-3 py-2 text-left text-sm rounded-md transition-colors ${_===null?`bg-bambu-green text-white`:`text-white hover:bg-bambu-dark-tertiary`}`,onClick:()=>{v(null),S(!1)},children:e(`stats.allUsers`,`All Users`)}),(0,Q.jsx)(`button`,{className:`w-full px-3 py-2 text-left text-sm rounded-md transition-colors ${_===-1?`bg-bambu-green text-white`:`text-white hover:bg-bambu-dark-tertiary`}`,onClick:()=>{v(-1),S(!1)},children:e(`stats.noUser`,`No User (System)`)}),(0,Q.jsx)(`div`,{className:`border-t border-bambu-dark-tertiary my-1`}),fe.map(e=>(0,Q.jsx)(`button`,{className:`w-full px-3 py-2 text-left text-sm rounded-md transition-colors ${_===e.id?`bg-bambu-green text-white`:`text-white hover:bg-bambu-dark-tertiary`}`,onClick:()=>{v(e.id),S(!1)},children:e.username},e.id))]})]})]}),(0,Q.jsxs)(`div`,{className:`relative`,children:[(0,Q.jsxs)(W,{variant:`secondary`,onClick:()=>k(!D),children:[(0,Q.jsx)(b,{className:`w-4 h-4`}),e(`stats.timeframe.${T.preset}`),(0,Q.jsx)(x,{className:`w-3 h-3`})]}),D&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>k(!1)}),(0,Q.jsxs)(`div`,{className:`absolute right-0 top-full mt-1 w-64 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl z-20 p-2`,children:[qi.map(t=>(0,Q.jsx)(`button`,{className:`w-full px-3 py-2 text-left text-sm rounded-md transition-colors ${T.preset===t?`bg-bambu-green text-white`:`text-white hover:bg-bambu-dark-tertiary`}`,onClick:()=>{E({preset:t,dateFrom:void 0,dateTo:void 0}),k(!1)},children:e(`stats.timeframe.${t}`)},t)),(0,Q.jsx)(`div`,{className:`border-t border-bambu-dark-tertiary my-2`}),(0,Q.jsx)(`button`,{className:`w-full px-3 py-2 text-left text-sm rounded-md transition-colors ${T.preset===`custom`?`bg-bambu-green text-white`:`text-white hover:bg-bambu-dark-tertiary`}`,onClick:()=>E(e=>({...e,preset:`custom`})),children:e(`stats.timeframe.custom`)}),T.preset===`custom`&&(0,Q.jsxs)(`div`,{className:`mt-2 px-1 pb-1 space-y-2`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`label`,{className:`text-xs text-bambu-gray block mb-1`,children:e(`stats.timeframe.from`)}),(0,Q.jsx)(`input`,{type:`date`,value:T.dateFrom||``,max:T.dateTo||new Date().toISOString().split(`T`)[0],onChange:e=>E(t=>({...t,dateFrom:e.target.value||void 0})),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded-md px-3 py-1.5 text-sm text-white`})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`label`,{className:`text-xs text-bambu-gray block mb-1`,children:e(`stats.timeframe.to`)}),(0,Q.jsx)(`input`,{type:`date`,value:T.dateTo||``,min:T.dateFrom,max:new Date().toISOString().split(`T`)[0],onChange:e=>E(t=>({...t,dateTo:e.target.value||void 0})),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded-md px-3 py-1.5 text-sm text-white`})]}),(0,Q.jsx)(W,{variant:`primary`,onClick:()=>k(!1),className:`w-full`,children:e(`common.apply`)})]})]})]})]})]})]}),(0,Q.jsx)(Gi,{widgets:be,storageKey:`bambusy-dashboard-layout-v2`,stackBelow:640,hideControls:!0},d)]})}export{sa as StatsPage}; \ No newline at end of file diff --git a/static/assets/StreamOverlayPage-BDnwgk_X.js b/static/assets/StreamOverlayPage-H9AqKpdI.js similarity index 99% rename from static/assets/StreamOverlayPage-BDnwgk_X.js rename to static/assets/StreamOverlayPage-H9AqKpdI.js index 2417bbaf8..8e92ea83b 100644 --- a/static/assets/StreamOverlayPage-BDnwgk_X.js +++ b/static/assets/StreamOverlayPage-H9AqKpdI.js @@ -1 +1 @@ -import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,S as r,a as i,t as a,w as o}from"./client-DnySrlFv.js";import{n as s}from"./QueryClientProvider-Ce8_sN3w.js";import{t as c}from"./useQuery-BBCjCezC.js";import{t as l}from"./box-DAdKb9s5.js";import{t as u}from"./timer-GUTR9dAu.js";import{c as d,o as f}from"./date-G9KUauqz.js";import{Jt as ee,Lt as p,On as m,Un as h,Wn as g,bn as _,cn as te}from"./index-0t--Yqoi.js";import{t as v}from"./printerModel-DrNvERGQ.js";import{a as y,n as b,o as x,s as S,t as C}from"./OverlayFrame-fLmufrTC.js";var w=e(n(),1),T=t();function E(e,t){let[n,r]=(0,w.useState)(null);return(0,w.useLayoutEffect)(()=>{let n=e.current;if(!t||!n)return;let i=()=>{let e=n.clientWidth,t=n.clientHeight;e>0&&t>0&&r(n=>n&&n.width===e&&n.height===t?n:{width:e,height:t})};if(i(),typeof ResizeObserver>`u`)return window.addEventListener(`resize`,i),()=>window.removeEventListener(`resize`,i);let a=new ResizeObserver(i);return a.observe(n),()=>a.disconnect()},[e,t]),t?n:null}function D(e){let[t,n]=(0,w.useState)(()=>window.matchMedia(`(orientation: portrait)`).matches);return(0,w.useEffect)(()=>{if(e)return;let t=window.matchMedia(`(orientation: portrait)`),r=e=>n(e.matches);return n(t.matches),t.addEventListener(`change`,r),()=>t.removeEventListener(`change`,r)},[e]),e??(t?`portrait`:`landscape`)}function O(e){let{t}=o(),n=1-(e.backgroundTransparency??0)/100,r={"--overlay-background-alpha":n,"--overlay-identity-alpha":n*.9,"--overlay-panel-alpha":n*.88};(0,w.useLayoutEffect)(()=>{if(n===1)return;let e=document.body.style.backgroundColor;return document.body.style.backgroundColor=`transparent`,()=>{document.body.style.backgroundColor=e}},[n]);let i=D(e.layout),{camera:a,name:s,model:c,filename:l,status:d,state:f,progress:p,layers:h,remaining:g,eta:_,temperatures:v}=e,y=x(e.progressBackground),b=l||d||p!=null||h||g||_||v.length>0,S=a?.rotation??0,C=Math.abs(S%180)===90,O=(0,w.useRef)(null),k=E(O,C&&a!=null),A=[{key:`layers`,icon:(0,T.jsx)(te,{}),label:t(`streamOverlay.layer`),value:h},{key:`remaining`,icon:(0,T.jsx)(u,{}),label:t(`streamOverlay.remaining`),value:g},{key:`eta`,icon:(0,T.jsx)(m,{}),label:t(`streamOverlay.eta`),value:_}].filter(e=>e.value!=null);return(0,T.jsxs)(`div`,{className:`updated-overlay`,"data-size":e.size,"data-layout":i,"data-state":f,style:r,children:[(0,T.jsxs)(`header`,{className:`updated-overlay__header`,children:[(s||c)&&(0,T.jsxs)(`div`,{className:`updated-overlay__identity`,children:[(0,T.jsx)(ee,{"aria-hidden":`true`}),(0,T.jsxs)(`div`,{children:[s&&(0,T.jsx)(`strong`,{children:s}),c&&(0,T.jsx)(`span`,{children:c})]})]}),(0,T.jsxs)(`div`,{className:`updated-overlay__logo flex flex-col items-end`,children:[e.customLogo,(0,T.jsx)(`a`,{href:`https://github.com/maziggy/bambuddy`,target:`_blank`,rel:`noopener noreferrer`,children:(0,T.jsx)(`img`,{src:`/img/bambuddy_logo_powered_by.png`,alt:`Bambuddy`})})]})]}),a&&(0,T.jsx)(`div`,{className:`updated-overlay__camera`,ref:O,children:(0,T.jsx)(`img`,{src:a.url,alt:t(`streamOverlay.cameraStream`),style:{transform:`translate(-50%, -50%) rotate(${S}deg)`,...C&&k?{width:k.height,height:k.width}:{}},onError:a.onError},a.url)}),b&&(0,T.jsxs)(`section`,{className:`updated-overlay__panel`,children:[(l||d)&&(0,T.jsxs)(`div`,{className:`updated-overlay__summary`,children:[l&&(0,T.jsx)(`h1`,{children:l}),d&&(0,T.jsxs)(`div`,{className:`updated-overlay__status`,children:[(0,T.jsx)(`span`,{"aria-hidden":`true`}),d]})]}),p!=null&&(0,T.jsxs)(`div`,{className:`updated-overlay__progress`,children:[(0,T.jsx)(`span`,{style:y,children:t(`streamOverlay.progress`)}),(0,T.jsx)(`div`,{role:`progressbar`,"aria-label":t(`streamOverlay.progress`),"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":p,children:(0,T.jsx)(`div`,{style:{width:`${p}%`,background:e.progressBackground}})}),(0,T.jsxs)(`strong`,{style:y,children:[Math.round(p),`%`]})]}),(A.length>0||v.length>0)&&(0,T.jsxs)(`div`,{className:`updated-overlay__readings`,children:[A.length>0&&(0,T.jsx)(`div`,{className:`updated-overlay__stats`,children:A.map(e=>(0,T.jsxs)(`div`,{className:`updated-overlay__reading`,children:[e.icon,(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`span`,{children:e.label}),(0,T.jsx)(`strong`,{children:e.value})]})]},e.key))}),v.length>0&&(0,T.jsx)(`div`,{className:`updated-overlay__temperatures`,children:v.map(e=>(0,T.jsxs)(`div`,{className:`updated-overlay__reading`,children:[e.icon,(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`span`,{children:e.label}),(0,T.jsxs)(`strong`,{children:[Math.round(e.current),`°C`,e.target!=null&&e.target>0&&Math.round(e.target)!==Math.round(e.current)&&(0,T.jsxs)(`small`,{children:[` / `,Math.round(e.target),`°C`]})]})]})]},e.key))})]})]})]})}var k=6e4,A=3e3;function ne(e){let[t,n]=(0,w.useState)(Date.now),r=(0,w.useRef)(null),i=(0,w.useCallback)(()=>{r.current!==null&&(clearTimeout(r.current),r.current=null),n(e=>e+1)},[]);return(0,w.useEffect)(()=>{if(!e)return;let t=setTimeout(i,k);return()=>{clearTimeout(t),r.current!==null&&(clearTimeout(r.current),r.current=null)}},[e,t,i]),{imageKey:t,handleStreamError:(0,w.useCallback)(()=>{!e||r.current!==null||(r.current=setTimeout(i,A))},[e,i])}}function j(e,t,n){if(!e)return``;if(!t)return e;let r=t.match(/plate_(\d+)\.gcode/);return r&&parseInt(r[1],10)>1?`${e} — ${n(`printers.plateNumber`,`Plate {{number}}`,{number:r[1]})}`:e}function re(e){let t=e.get(`show`)?.split(`,`)||[`progress`,`layers`,`eta`,`filename`,`status`],n=parseInt(e.get(`fps`)||`15`,10),r=Math.min(Math.max(isNaN(n)?15:n,1),30),i=e.get(`camera`),a=i!==`false`&&i!==`0`,o=Number(e.get(`backgroundTransparency`)),s=Number.isFinite(o)?Math.min(100,Math.max(0,o)):0,c=e.get(`layout`);return{layout:c===`portrait`||c===`landscape`?c:null,backgroundTransparency:s,size:e.get(`size`)||`medium`,fps:r,updatedArtwork:e.get(`artwork`)===`2`,showCamera:a,showProgress:t.includes(`progress`),showLayers:t.includes(`layers`),showEta:t.includes(`eta`),showFilename:t.includes(`filename`),showStatus:t.includes(`status`),showPrinter:t.includes(`printer`),showModel:t.includes(`model`),showNozzle:t.includes(`nozzle`),showBed:t.includes(`bed`),showChamber:t.includes(`chamber`)}}function M(e,t){if(e.stg_cur_name)return e.stg_cur_name;switch(e.state){case`RUNNING`:return t(`streamOverlay.status.printing`);case`PAUSE`:return t(`streamOverlay.status.paused`);case`FINISH`:return t(`streamOverlay.status.finished`);case`FAILED`:return t(`streamOverlay.status.failed`);case`IDLE`:return t(`streamOverlay.status.idle`);default:return e.state||t(`streamOverlay.status.unknown`)}}function N(e,t){let n=e[t];return typeof n==`number`?n:null}function ie({icon:e,label:t,current:n,target:r,sizes:i}){let a=r!=null&&r>0&&Math.round(r)!==Math.round(n);return(0,T.jsxs)(`div`,{className:`flex items-center ${i.gap} text-white/70`,children:[e,(0,T.jsxs)(`span`,{className:`classic-overlay__text ${i.text}`,children:[(0,T.jsx)(`span`,{className:`mr-1`,children:t}),(0,T.jsxs)(`span`,{className:`text-white`,children:[Math.round(n),`°C`]}),a&&(0,T.jsxs)(T.Fragment,{children:[(0,T.jsx)(`span`,{className:`mx-1`,children:`/`}),(0,T.jsxs)(`span`,{children:[Math.round(r),`°C`]})]})]})]})}function ae(e){switch(e){case`small`:return{container:`p-3`,text:`text-sm`,textLarge:`text-lg`,progressHeight:`h-2`,icon:`w-3 h-3`,gap:`gap-2`,logoHeight:`h-12`};case`large`:return{container:`p-6`,text:`text-xl`,textLarge:`text-3xl`,progressHeight:`h-4`,icon:`w-6 h-6`,gap:`gap-4`,logoHeight:`h-24`};default:return{container:`p-4`,text:`text-base`,textLarge:`text-xl`,progressHeight:`h-3`,icon:`w-4 h-4`,gap:`gap-3`,logoHeight:`h-16`}}}function P(){let{printerId:e}=h(),[t]=g(),{t:n}=o(),E=s(),D=parseInt(e||`0`,10),k=(0,w.useMemo)(()=>re(t),[t]),A=ae(k.size),P=t.get(`token`),F=P!=null&&P!==``,I=S(t.get(`logo`)===`1`,P),L=y(t.get(`progressFrom`),t.get(`progressTo`)),R=x(L),z=I?(0,T.jsx)(`img`,{src:I,alt:n(`streamOverlay.branding.logo`),className:`mb-2 object-contain`,style:{maxHeight:k.layout?b[k.layout].height*.14:`14vh`,maxWidth:k.layout?b[k.layout].width*.2:`20vw`}}):null,{data:B}=c({queryKey:[`overlayStatus`,D,P],queryFn:()=>i.getOverlayStatus(D,P??void 0),enabled:D>0&&F,refetchInterval:2e3}),{data:V}=c({queryKey:[`printer`,D],queryFn:()=>i.getPrinter(D),enabled:D>0&&!F}),{data:oe}=c({queryKey:[`printerStatus`,D],queryFn:()=>i.getPrinterStatus(D),enabled:D>0&&!F,refetchInterval:2e3}),{data:se}=c({queryKey:[`settings`],queryFn:i.getSettings,enabled:!F}),H=(0,w.useMemo)(()=>F?B&&{name:B.name,model:B.model,camera_rotation:B.camera_rotation}:V,[F,B,V]),U=[k.showPrinter?H?.name:null,k.showModel?v(H?.model??null):null].filter(Boolean).join(` · `),W=F?B:oe,{imageKey:G,handleStreamError:K}=ne(D>0&&k.showCamera&&W!=null),q=(F?B?.time_format:se?.time_format)||`system`;if((0,w.useEffect)(()=>{if(!D||F)return;let e=null,t=!1;return(async()=>{let n;try{n=(await i.getWebSocketToken()).token}catch(e){let t=e instanceof a?e.status:0;if(t===401||t===403)return}if(t)return;let r=window.location.protocol===`https:`?`wss:`:`ws:`,o=n?`?token=${encodeURIComponent(n)}`:``,s=`${r}//${window.location.host}/api/v1/ws${o}`;e=new WebSocket(s),e.onmessage=e=>{try{let t=JSON.parse(e.data);t.type===`printer_status`&&t.printer_id===D&&E.setQueryData([`printerStatus`,D],t.status)}catch{}},e.onerror=()=>{}})(),()=>{t=!0,e&&e.close()}},[D,F,E]),(0,w.useEffect)(()=>(document.title=H?`${H.name} - ${n(`streamOverlay.title`)}`:n(`streamOverlay.title`),()=>{document.title=`Bambuddy`}),[H,n]),!D)return(0,T.jsx)(`div`,{className:`min-h-screen bg-black flex items-center justify-center`,children:(0,T.jsx)(`p`,{className:`text-white`,children:n(`streamOverlay.invalidPrinterId`)})});if(!W)return(0,T.jsx)(`div`,{className:`min-h-screen bg-black flex items-center justify-center`,children:(0,T.jsx)(`p`,{className:`text-gray-400`,children:n(`common.loading`)})});let J=W.connected&&(W.state===`RUNNING`||W.state===`PAUSE`),Y=W.progress||0,X=W.temperatures??{},Z=[];if(k.showNozzle){let e=N(X,`nozzle`),t=N(X,`nozzle_2`);e!=null&&Z.push({key:`nozzle`,icon:(0,T.jsx)(_,{className:`classic-overlay__icon ${A.icon}`}),label:n(`printers.heaterHistory.nozzle`,`Nozzle`),current:e,target:N(X,`nozzle_target`)}),t!=null&&Z.push({key:`nozzle_2`,icon:(0,T.jsx)(_,{className:`classic-overlay__icon ${A.icon}`}),label:n(`printers.heaterHistory.nozzle2`,`Nozzle 2`),current:t,target:N(X,`nozzle_2_target`)})}if(k.showBed){let e=N(X,`bed`);e!=null&&Z.push({key:`bed`,icon:(0,T.jsx)(p,{className:`classic-overlay__icon ${A.icon}`}),label:n(`printers.heaterHistory.bed`,`Bed`),current:e,target:N(X,`bed_target`)})}if(k.showChamber){let e=N(X,`chamber`);e!=null&&Z.push({key:`chamber`,icon:(0,T.jsx)(l,{className:`classic-overlay__icon ${A.icon}`}),label:n(`printers.heaterHistory.chamber`,`Chamber`),current:e,target:N(X,`chamber_target`)})}let ce=`/api/v1/printers/${D}/camera/stream?fps=${k.fps}&t=${G}`,le=F&&P?`${ce}&token=${encodeURIComponent(P)}`:r(ce);if(k.updatedArtwork){let e=W.connected&&J,t=W.remaining_time,r=e&&k.showEta&&t!=null&&t>0,i=(0,T.jsx)(O,{layout:k.layout??void 0,backgroundTransparency:k.backgroundTransparency,customLogo:z,progressBackground:L,size:k.size,camera:k.showCamera?{url:le,rotation:H?.camera_rotation??0,onError:K}:null,name:k.showPrinter?H?.name??null:null,model:k.showModel&&v(H?.model??null)||null,filename:k.showFilename&&W.current_print?j(W.current_print.replace(/\.gcode\.3mf$|\.3mf$|\.gcode$/i,``),W.gcode_file,n):null,status:k.showStatus?W.connected?M(W,n):n(`streamOverlay.printerOffline`):null,state:W.connected?W.state:null,progress:e&&k.showProgress?Math.min(100,Math.max(0,Number.isFinite(Y)?Y:0)):null,layers:e&&k.showLayers&&W.layer_num!=null&&W.total_layers!=null&&W.total_layers>0?`${W.layer_num} / ${W.total_layers}`:null,remaining:r?f(t*60):null,eta:r?d(t,q,n):null,temperatures:W.connected?Z:[]});return k.layout?(0,T.jsx)(C,{layout:k.layout,children:i}):i}let Q=k.layout?b[k.layout]:null,$=H?.camera_rotation??0,ue=Math.abs($%180)===90,de=(0,T.jsxs)(`div`,{className:`classic-overlay min-h-screen bg-black relative overflow-hidden`,"data-layout":k.layout??void 0,"data-size":k.size,children:[k.showCamera&&(0,T.jsx)(`img`,{src:le,alt:n(`streamOverlay.cameraStream`),className:`absolute inset-0 w-full h-full object-contain`,style:Q?{left:`50%`,top:`50%`,maxWidth:`none`,width:ue?Q.height:Q.width,height:ue?Q.width:Q.height,transform:`translate(-50%, -50%) rotate(${$}deg)`}:$?{transform:`rotate(${$}deg)`}:void 0,onError:K},G),(0,T.jsxs)(`div`,{className:`absolute top-4 right-4 z-10 flex flex-col items-end`,children:[z,(0,T.jsx)(`a`,{href:`https://github.com/maziggy/bambuddy`,target:`_blank`,rel:`noopener noreferrer`,children:(0,T.jsx)(`img`,{src:`/img/bambuddy_logo_dark_transparent.png`,alt:`Bambuddy`,className:`classic-overlay__logo ${A.logoHeight} object-contain drop-shadow-lg hover:scale-105 transition-transform`})})]}),(0,T.jsx)(`div`,{className:`absolute bottom-0 left-0 right-0 z-10 bg-gradient-to-t from-black/80 via-black/60 to-transparent`,children:(0,T.jsxs)(`div`,{className:`classic-overlay__panel ${A.container}`,children:[U&&(0,T.jsxs)(`div`,{className:`flex items-center ${A.gap} mb-2`,children:[(0,T.jsx)(ee,{className:`classic-overlay__icon ${A.icon} shrink-0 text-white/70`}),(0,T.jsx)(`span`,{className:`classic-overlay__text ${A.text} min-w-0 truncate text-white font-medium`,children:U})]}),k.showFilename&&W.current_print&&(0,T.jsx)(`div`,{className:`classic-overlay__filename ${A.textLarge} text-white font-semibold mb-2 truncate drop-shadow-md`,children:j(W.current_print.replace(/\.gcode\.3mf$|\.3mf$|\.gcode$/i,``),W.gcode_file,n)}),k.showStatus&&(0,T.jsx)(`div`,{className:`classic-overlay__text ${A.text} text-white/70 mb-2`,children:W.connected?M(W,n):n(`streamOverlay.printerOffline`)}),k.showProgress&&J&&(0,T.jsxs)(`div`,{className:`mb-3`,children:[(0,T.jsxs)(`div`,{className:`flex items-center justify-between mb-1 classic-overlay__text ${A.text}`,children:[(0,T.jsx)(`span`,{className:`text-white/70`,style:R,children:n(`streamOverlay.progress`)}),(0,T.jsxs)(`span`,{className:`text-white font-bold`,style:R,children:[Math.round(Y),`%`]})]}),(0,T.jsx)(`div`,{className:`w-full bg-white/20 rounded-full ${A.progressHeight}`,children:(0,T.jsx)(`div`,{className:`bg-bambu-green ${A.progressHeight} rounded-full transition-all duration-500`,style:{width:`${Y}%`,background:L}})})]}),J&&(k.showLayers||k.showEta)&&(0,T.jsxs)(`div`,{className:`flex items-center ${A.gap} flex-wrap`,children:[k.showLayers&&W.layer_num!=null&&W.total_layers!=null&&W.total_layers>0&&(0,T.jsxs)(`div`,{className:`flex items-center ${A.gap} text-white/70`,children:[(0,T.jsx)(te,{className:`classic-overlay__icon ${A.icon}`}),(0,T.jsxs)(`span`,{className:`classic-overlay__text ${A.text}`,children:[(0,T.jsx)(`span`,{className:`text-white`,children:W.layer_num}),(0,T.jsx)(`span`,{className:`mx-1`,children:`/`}),(0,T.jsx)(`span`,{children:W.total_layers})]})]}),k.showEta&&W.remaining_time!=null&&W.remaining_time>0&&(0,T.jsxs)(T.Fragment,{children:[(0,T.jsxs)(`div`,{className:`flex items-center ${A.gap} text-white/70`,children:[(0,T.jsx)(u,{className:`classic-overlay__icon ${A.icon}`}),(0,T.jsx)(`span`,{className:`classic-overlay__text ${A.text} text-white`,children:f(W.remaining_time*60)})]}),(0,T.jsxs)(`div`,{className:`flex items-center ${A.gap} text-white/70`,children:[(0,T.jsx)(m,{className:`classic-overlay__icon ${A.icon}`}),(0,T.jsxs)(`span`,{className:`classic-overlay__text ${A.text} text-white`,children:[n(`streamOverlay.eta`),` `,d(W.remaining_time,q,n)]})]})]})]}),Z.length>0&&W.connected&&(0,T.jsx)(`div`,{className:`flex items-center ${A.gap} flex-wrap mt-2`,children:Z.map(e=>(0,T.jsx)(ie,{icon:e.icon,label:e.label,current:e.current,target:e.target,sizes:A},e.key))})]})})]});return k.layout?(0,T.jsx)(C,{layout:k.layout,children:de}):de}export{P as StreamOverlayPage}; \ No newline at end of file +import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,S as r,a as i,t as a,w as o}from"./client-DnySrlFv.js";import{n as s}from"./QueryClientProvider-Ce8_sN3w.js";import{t as c}from"./useQuery-BBCjCezC.js";import{t as l}from"./box-DAdKb9s5.js";import{t as u}from"./timer-GUTR9dAu.js";import{c as d,o as f}from"./date-G9KUauqz.js";import{Jt as ee,Lt as p,On as m,Un as h,Wn as g,bn as _,cn as te}from"./index-Cxa-KVmA.js";import{t as v}from"./printerModel-DrNvERGQ.js";import{a as y,n as b,o as x,s as S,t as C}from"./OverlayFrame-fLmufrTC.js";var w=e(n(),1),T=t();function E(e,t){let[n,r]=(0,w.useState)(null);return(0,w.useLayoutEffect)(()=>{let n=e.current;if(!t||!n)return;let i=()=>{let e=n.clientWidth,t=n.clientHeight;e>0&&t>0&&r(n=>n&&n.width===e&&n.height===t?n:{width:e,height:t})};if(i(),typeof ResizeObserver>`u`)return window.addEventListener(`resize`,i),()=>window.removeEventListener(`resize`,i);let a=new ResizeObserver(i);return a.observe(n),()=>a.disconnect()},[e,t]),t?n:null}function D(e){let[t,n]=(0,w.useState)(()=>window.matchMedia(`(orientation: portrait)`).matches);return(0,w.useEffect)(()=>{if(e)return;let t=window.matchMedia(`(orientation: portrait)`),r=e=>n(e.matches);return n(t.matches),t.addEventListener(`change`,r),()=>t.removeEventListener(`change`,r)},[e]),e??(t?`portrait`:`landscape`)}function O(e){let{t}=o(),n=1-(e.backgroundTransparency??0)/100,r={"--overlay-background-alpha":n,"--overlay-identity-alpha":n*.9,"--overlay-panel-alpha":n*.88};(0,w.useLayoutEffect)(()=>{if(n===1)return;let e=document.body.style.backgroundColor;return document.body.style.backgroundColor=`transparent`,()=>{document.body.style.backgroundColor=e}},[n]);let i=D(e.layout),{camera:a,name:s,model:c,filename:l,status:d,state:f,progress:p,layers:h,remaining:g,eta:_,temperatures:v}=e,y=x(e.progressBackground),b=l||d||p!=null||h||g||_||v.length>0,S=a?.rotation??0,C=Math.abs(S%180)===90,O=(0,w.useRef)(null),k=E(O,C&&a!=null),A=[{key:`layers`,icon:(0,T.jsx)(te,{}),label:t(`streamOverlay.layer`),value:h},{key:`remaining`,icon:(0,T.jsx)(u,{}),label:t(`streamOverlay.remaining`),value:g},{key:`eta`,icon:(0,T.jsx)(m,{}),label:t(`streamOverlay.eta`),value:_}].filter(e=>e.value!=null);return(0,T.jsxs)(`div`,{className:`updated-overlay`,"data-size":e.size,"data-layout":i,"data-state":f,style:r,children:[(0,T.jsxs)(`header`,{className:`updated-overlay__header`,children:[(s||c)&&(0,T.jsxs)(`div`,{className:`updated-overlay__identity`,children:[(0,T.jsx)(ee,{"aria-hidden":`true`}),(0,T.jsxs)(`div`,{children:[s&&(0,T.jsx)(`strong`,{children:s}),c&&(0,T.jsx)(`span`,{children:c})]})]}),(0,T.jsxs)(`div`,{className:`updated-overlay__logo flex flex-col items-end`,children:[e.customLogo,(0,T.jsx)(`a`,{href:`https://github.com/maziggy/bambuddy`,target:`_blank`,rel:`noopener noreferrer`,children:(0,T.jsx)(`img`,{src:`/img/bambuddy_logo_powered_by.png`,alt:`Bambuddy`})})]})]}),a&&(0,T.jsx)(`div`,{className:`updated-overlay__camera`,ref:O,children:(0,T.jsx)(`img`,{src:a.url,alt:t(`streamOverlay.cameraStream`),style:{transform:`translate(-50%, -50%) rotate(${S}deg)`,...C&&k?{width:k.height,height:k.width}:{}},onError:a.onError},a.url)}),b&&(0,T.jsxs)(`section`,{className:`updated-overlay__panel`,children:[(l||d)&&(0,T.jsxs)(`div`,{className:`updated-overlay__summary`,children:[l&&(0,T.jsx)(`h1`,{children:l}),d&&(0,T.jsxs)(`div`,{className:`updated-overlay__status`,children:[(0,T.jsx)(`span`,{"aria-hidden":`true`}),d]})]}),p!=null&&(0,T.jsxs)(`div`,{className:`updated-overlay__progress`,children:[(0,T.jsx)(`span`,{style:y,children:t(`streamOverlay.progress`)}),(0,T.jsx)(`div`,{role:`progressbar`,"aria-label":t(`streamOverlay.progress`),"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":p,children:(0,T.jsx)(`div`,{style:{width:`${p}%`,background:e.progressBackground}})}),(0,T.jsxs)(`strong`,{style:y,children:[Math.round(p),`%`]})]}),(A.length>0||v.length>0)&&(0,T.jsxs)(`div`,{className:`updated-overlay__readings`,children:[A.length>0&&(0,T.jsx)(`div`,{className:`updated-overlay__stats`,children:A.map(e=>(0,T.jsxs)(`div`,{className:`updated-overlay__reading`,children:[e.icon,(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`span`,{children:e.label}),(0,T.jsx)(`strong`,{children:e.value})]})]},e.key))}),v.length>0&&(0,T.jsx)(`div`,{className:`updated-overlay__temperatures`,children:v.map(e=>(0,T.jsxs)(`div`,{className:`updated-overlay__reading`,children:[e.icon,(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`span`,{children:e.label}),(0,T.jsxs)(`strong`,{children:[Math.round(e.current),`°C`,e.target!=null&&e.target>0&&Math.round(e.target)!==Math.round(e.current)&&(0,T.jsxs)(`small`,{children:[` / `,Math.round(e.target),`°C`]})]})]})]},e.key))})]})]})]})}var k=6e4,A=3e3;function ne(e){let[t,n]=(0,w.useState)(Date.now),r=(0,w.useRef)(null),i=(0,w.useCallback)(()=>{r.current!==null&&(clearTimeout(r.current),r.current=null),n(e=>e+1)},[]);return(0,w.useEffect)(()=>{if(!e)return;let t=setTimeout(i,k);return()=>{clearTimeout(t),r.current!==null&&(clearTimeout(r.current),r.current=null)}},[e,t,i]),{imageKey:t,handleStreamError:(0,w.useCallback)(()=>{!e||r.current!==null||(r.current=setTimeout(i,A))},[e,i])}}function j(e,t,n){if(!e)return``;if(!t)return e;let r=t.match(/plate_(\d+)\.gcode/);return r&&parseInt(r[1],10)>1?`${e} — ${n(`printers.plateNumber`,`Plate {{number}}`,{number:r[1]})}`:e}function re(e){let t=e.get(`show`)?.split(`,`)||[`progress`,`layers`,`eta`,`filename`,`status`],n=parseInt(e.get(`fps`)||`15`,10),r=Math.min(Math.max(isNaN(n)?15:n,1),30),i=e.get(`camera`),a=i!==`false`&&i!==`0`,o=Number(e.get(`backgroundTransparency`)),s=Number.isFinite(o)?Math.min(100,Math.max(0,o)):0,c=e.get(`layout`);return{layout:c===`portrait`||c===`landscape`?c:null,backgroundTransparency:s,size:e.get(`size`)||`medium`,fps:r,updatedArtwork:e.get(`artwork`)===`2`,showCamera:a,showProgress:t.includes(`progress`),showLayers:t.includes(`layers`),showEta:t.includes(`eta`),showFilename:t.includes(`filename`),showStatus:t.includes(`status`),showPrinter:t.includes(`printer`),showModel:t.includes(`model`),showNozzle:t.includes(`nozzle`),showBed:t.includes(`bed`),showChamber:t.includes(`chamber`)}}function M(e,t){if(e.stg_cur_name)return e.stg_cur_name;switch(e.state){case`RUNNING`:return t(`streamOverlay.status.printing`);case`PAUSE`:return t(`streamOverlay.status.paused`);case`FINISH`:return t(`streamOverlay.status.finished`);case`FAILED`:return t(`streamOverlay.status.failed`);case`IDLE`:return t(`streamOverlay.status.idle`);default:return e.state||t(`streamOverlay.status.unknown`)}}function N(e,t){let n=e[t];return typeof n==`number`?n:null}function ie({icon:e,label:t,current:n,target:r,sizes:i}){let a=r!=null&&r>0&&Math.round(r)!==Math.round(n);return(0,T.jsxs)(`div`,{className:`flex items-center ${i.gap} text-white/70`,children:[e,(0,T.jsxs)(`span`,{className:`classic-overlay__text ${i.text}`,children:[(0,T.jsx)(`span`,{className:`mr-1`,children:t}),(0,T.jsxs)(`span`,{className:`text-white`,children:[Math.round(n),`°C`]}),a&&(0,T.jsxs)(T.Fragment,{children:[(0,T.jsx)(`span`,{className:`mx-1`,children:`/`}),(0,T.jsxs)(`span`,{children:[Math.round(r),`°C`]})]})]})]})}function ae(e){switch(e){case`small`:return{container:`p-3`,text:`text-sm`,textLarge:`text-lg`,progressHeight:`h-2`,icon:`w-3 h-3`,gap:`gap-2`,logoHeight:`h-12`};case`large`:return{container:`p-6`,text:`text-xl`,textLarge:`text-3xl`,progressHeight:`h-4`,icon:`w-6 h-6`,gap:`gap-4`,logoHeight:`h-24`};default:return{container:`p-4`,text:`text-base`,textLarge:`text-xl`,progressHeight:`h-3`,icon:`w-4 h-4`,gap:`gap-3`,logoHeight:`h-16`}}}function P(){let{printerId:e}=h(),[t]=g(),{t:n}=o(),E=s(),D=parseInt(e||`0`,10),k=(0,w.useMemo)(()=>re(t),[t]),A=ae(k.size),P=t.get(`token`),F=P!=null&&P!==``,I=S(t.get(`logo`)===`1`,P),L=y(t.get(`progressFrom`),t.get(`progressTo`)),R=x(L),z=I?(0,T.jsx)(`img`,{src:I,alt:n(`streamOverlay.branding.logo`),className:`mb-2 object-contain`,style:{maxHeight:k.layout?b[k.layout].height*.14:`14vh`,maxWidth:k.layout?b[k.layout].width*.2:`20vw`}}):null,{data:B}=c({queryKey:[`overlayStatus`,D,P],queryFn:()=>i.getOverlayStatus(D,P??void 0),enabled:D>0&&F,refetchInterval:2e3}),{data:V}=c({queryKey:[`printer`,D],queryFn:()=>i.getPrinter(D),enabled:D>0&&!F}),{data:oe}=c({queryKey:[`printerStatus`,D],queryFn:()=>i.getPrinterStatus(D),enabled:D>0&&!F,refetchInterval:2e3}),{data:se}=c({queryKey:[`settings`],queryFn:i.getSettings,enabled:!F}),H=(0,w.useMemo)(()=>F?B&&{name:B.name,model:B.model,camera_rotation:B.camera_rotation}:V,[F,B,V]),U=[k.showPrinter?H?.name:null,k.showModel?v(H?.model??null):null].filter(Boolean).join(` · `),W=F?B:oe,{imageKey:G,handleStreamError:K}=ne(D>0&&k.showCamera&&W!=null),q=(F?B?.time_format:se?.time_format)||`system`;if((0,w.useEffect)(()=>{if(!D||F)return;let e=null,t=!1;return(async()=>{let n;try{n=(await i.getWebSocketToken()).token}catch(e){let t=e instanceof a?e.status:0;if(t===401||t===403)return}if(t)return;let r=window.location.protocol===`https:`?`wss:`:`ws:`,o=n?`?token=${encodeURIComponent(n)}`:``,s=`${r}//${window.location.host}/api/v1/ws${o}`;e=new WebSocket(s),e.onmessage=e=>{try{let t=JSON.parse(e.data);t.type===`printer_status`&&t.printer_id===D&&E.setQueryData([`printerStatus`,D],t.status)}catch{}},e.onerror=()=>{}})(),()=>{t=!0,e&&e.close()}},[D,F,E]),(0,w.useEffect)(()=>(document.title=H?`${H.name} - ${n(`streamOverlay.title`)}`:n(`streamOverlay.title`),()=>{document.title=`Bambuddy`}),[H,n]),!D)return(0,T.jsx)(`div`,{className:`min-h-screen bg-black flex items-center justify-center`,children:(0,T.jsx)(`p`,{className:`text-white`,children:n(`streamOverlay.invalidPrinterId`)})});if(!W)return(0,T.jsx)(`div`,{className:`min-h-screen bg-black flex items-center justify-center`,children:(0,T.jsx)(`p`,{className:`text-gray-400`,children:n(`common.loading`)})});let J=W.connected&&(W.state===`RUNNING`||W.state===`PAUSE`),Y=W.progress||0,X=W.temperatures??{},Z=[];if(k.showNozzle){let e=N(X,`nozzle`),t=N(X,`nozzle_2`);e!=null&&Z.push({key:`nozzle`,icon:(0,T.jsx)(_,{className:`classic-overlay__icon ${A.icon}`}),label:n(`printers.heaterHistory.nozzle`,`Nozzle`),current:e,target:N(X,`nozzle_target`)}),t!=null&&Z.push({key:`nozzle_2`,icon:(0,T.jsx)(_,{className:`classic-overlay__icon ${A.icon}`}),label:n(`printers.heaterHistory.nozzle2`,`Nozzle 2`),current:t,target:N(X,`nozzle_2_target`)})}if(k.showBed){let e=N(X,`bed`);e!=null&&Z.push({key:`bed`,icon:(0,T.jsx)(p,{className:`classic-overlay__icon ${A.icon}`}),label:n(`printers.heaterHistory.bed`,`Bed`),current:e,target:N(X,`bed_target`)})}if(k.showChamber){let e=N(X,`chamber`);e!=null&&Z.push({key:`chamber`,icon:(0,T.jsx)(l,{className:`classic-overlay__icon ${A.icon}`}),label:n(`printers.heaterHistory.chamber`,`Chamber`),current:e,target:N(X,`chamber_target`)})}let ce=`/api/v1/printers/${D}/camera/stream?fps=${k.fps}&t=${G}`,le=F&&P?`${ce}&token=${encodeURIComponent(P)}`:r(ce);if(k.updatedArtwork){let e=W.connected&&J,t=W.remaining_time,r=e&&k.showEta&&t!=null&&t>0,i=(0,T.jsx)(O,{layout:k.layout??void 0,backgroundTransparency:k.backgroundTransparency,customLogo:z,progressBackground:L,size:k.size,camera:k.showCamera?{url:le,rotation:H?.camera_rotation??0,onError:K}:null,name:k.showPrinter?H?.name??null:null,model:k.showModel&&v(H?.model??null)||null,filename:k.showFilename&&W.current_print?j(W.current_print.replace(/\.gcode\.3mf$|\.3mf$|\.gcode$/i,``),W.gcode_file,n):null,status:k.showStatus?W.connected?M(W,n):n(`streamOverlay.printerOffline`):null,state:W.connected?W.state:null,progress:e&&k.showProgress?Math.min(100,Math.max(0,Number.isFinite(Y)?Y:0)):null,layers:e&&k.showLayers&&W.layer_num!=null&&W.total_layers!=null&&W.total_layers>0?`${W.layer_num} / ${W.total_layers}`:null,remaining:r?f(t*60):null,eta:r?d(t,q,n):null,temperatures:W.connected?Z:[]});return k.layout?(0,T.jsx)(C,{layout:k.layout,children:i}):i}let Q=k.layout?b[k.layout]:null,$=H?.camera_rotation??0,ue=Math.abs($%180)===90,de=(0,T.jsxs)(`div`,{className:`classic-overlay min-h-screen bg-black relative overflow-hidden`,"data-layout":k.layout??void 0,"data-size":k.size,children:[k.showCamera&&(0,T.jsx)(`img`,{src:le,alt:n(`streamOverlay.cameraStream`),className:`absolute inset-0 w-full h-full object-contain`,style:Q?{left:`50%`,top:`50%`,maxWidth:`none`,width:ue?Q.height:Q.width,height:ue?Q.width:Q.height,transform:`translate(-50%, -50%) rotate(${$}deg)`}:$?{transform:`rotate(${$}deg)`}:void 0,onError:K},G),(0,T.jsxs)(`div`,{className:`absolute top-4 right-4 z-10 flex flex-col items-end`,children:[z,(0,T.jsx)(`a`,{href:`https://github.com/maziggy/bambuddy`,target:`_blank`,rel:`noopener noreferrer`,children:(0,T.jsx)(`img`,{src:`/img/bambuddy_logo_dark_transparent.png`,alt:`Bambuddy`,className:`classic-overlay__logo ${A.logoHeight} object-contain drop-shadow-lg hover:scale-105 transition-transform`})})]}),(0,T.jsx)(`div`,{className:`absolute bottom-0 left-0 right-0 z-10 bg-gradient-to-t from-black/80 via-black/60 to-transparent`,children:(0,T.jsxs)(`div`,{className:`classic-overlay__panel ${A.container}`,children:[U&&(0,T.jsxs)(`div`,{className:`flex items-center ${A.gap} mb-2`,children:[(0,T.jsx)(ee,{className:`classic-overlay__icon ${A.icon} shrink-0 text-white/70`}),(0,T.jsx)(`span`,{className:`classic-overlay__text ${A.text} min-w-0 truncate text-white font-medium`,children:U})]}),k.showFilename&&W.current_print&&(0,T.jsx)(`div`,{className:`classic-overlay__filename ${A.textLarge} text-white font-semibold mb-2 truncate drop-shadow-md`,children:j(W.current_print.replace(/\.gcode\.3mf$|\.3mf$|\.gcode$/i,``),W.gcode_file,n)}),k.showStatus&&(0,T.jsx)(`div`,{className:`classic-overlay__text ${A.text} text-white/70 mb-2`,children:W.connected?M(W,n):n(`streamOverlay.printerOffline`)}),k.showProgress&&J&&(0,T.jsxs)(`div`,{className:`mb-3`,children:[(0,T.jsxs)(`div`,{className:`flex items-center justify-between mb-1 classic-overlay__text ${A.text}`,children:[(0,T.jsx)(`span`,{className:`text-white/70`,style:R,children:n(`streamOverlay.progress`)}),(0,T.jsxs)(`span`,{className:`text-white font-bold`,style:R,children:[Math.round(Y),`%`]})]}),(0,T.jsx)(`div`,{className:`w-full bg-white/20 rounded-full ${A.progressHeight}`,children:(0,T.jsx)(`div`,{className:`bg-bambu-green ${A.progressHeight} rounded-full transition-all duration-500`,style:{width:`${Y}%`,background:L}})})]}),J&&(k.showLayers||k.showEta)&&(0,T.jsxs)(`div`,{className:`flex items-center ${A.gap} flex-wrap`,children:[k.showLayers&&W.layer_num!=null&&W.total_layers!=null&&W.total_layers>0&&(0,T.jsxs)(`div`,{className:`flex items-center ${A.gap} text-white/70`,children:[(0,T.jsx)(te,{className:`classic-overlay__icon ${A.icon}`}),(0,T.jsxs)(`span`,{className:`classic-overlay__text ${A.text}`,children:[(0,T.jsx)(`span`,{className:`text-white`,children:W.layer_num}),(0,T.jsx)(`span`,{className:`mx-1`,children:`/`}),(0,T.jsx)(`span`,{children:W.total_layers})]})]}),k.showEta&&W.remaining_time!=null&&W.remaining_time>0&&(0,T.jsxs)(T.Fragment,{children:[(0,T.jsxs)(`div`,{className:`flex items-center ${A.gap} text-white/70`,children:[(0,T.jsx)(u,{className:`classic-overlay__icon ${A.icon}`}),(0,T.jsx)(`span`,{className:`classic-overlay__text ${A.text} text-white`,children:f(W.remaining_time*60)})]}),(0,T.jsxs)(`div`,{className:`flex items-center ${A.gap} text-white/70`,children:[(0,T.jsx)(m,{className:`classic-overlay__icon ${A.icon}`}),(0,T.jsxs)(`span`,{className:`classic-overlay__text ${A.text} text-white`,children:[n(`streamOverlay.eta`),` `,d(W.remaining_time,q,n)]})]})]})]}),Z.length>0&&W.connected&&(0,T.jsx)(`div`,{className:`flex items-center ${A.gap} flex-wrap mt-2`,children:Z.map(e=>(0,T.jsx)(ie,{icon:e.icon,label:e.label,current:e.current,target:e.target,sizes:A},e.key))})]})})]});return k.layout?(0,T.jsx)(C,{layout:k.layout,children:de}):de}export{P as StreamOverlayPage}; \ No newline at end of file diff --git a/static/assets/SystemInfoPage-CjmM6f9Q.js b/static/assets/SystemInfoPage-J8sIDAyN.js similarity index 99% rename from static/assets/SystemInfoPage-CjmM6f9Q.js rename to static/assets/SystemInfoPage-J8sIDAyN.js index 68f134c8e..d7c0da97e 100644 --- a/static/assets/SystemInfoPage-CjmM6f9Q.js +++ b/static/assets/SystemInfoPage-J8sIDAyN.js @@ -1,3 +1,3 @@ -import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,w as i,y as a}from"./client-DnySrlFv.js";import{n as o}from"./QueryClientProvider-Ce8_sN3w.js";import{t as s}from"./useQuery-BBCjCezC.js";import{t as c}from"./useMutation-B-Tr2hIP.js";import{t as l}from"./createLucideIcon-DvBYJlWL.js";import{a as u,i as d,n as f,r as p,t as m}from"./info-ROUoQhJR.js";import{t as h}from"./cpu-BKWEtc8k.js";import{t as g}from"./hard-drive-CgXAHN37.js";import{t as _}from"./loader-circle-BEmFtawu.js";import{t as v}from"./play-DIDYtk2S.js";import{t as y}from"./search-0n0CBc74.js";import{t as b}from"./triangle-alert-Dt_1FcBy.js";import{t as x}from"./x-DR-Trv6U.js";import{t as S}from"./Card-Bzc64K35.js";import{a as C}from"./date-G9KUauqz.js";import{An as w,At as T,Fn as E,Ft as D,Ht as O,Jt as k,Kt as A,Ln as j,Lt as M,On as N,Qt as P,Tn as F,_ as I,en as L,g as R,vn as z,wn as B,yn as V}from"./index-0t--Yqoi.js";var H=l(`headphones`,[[`path`,{d:`M3 14h3a2 2 0 0 1 2 2v3a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-7a9 9 0 0 1 18 0v7a2 2 0 0 1-2 2h-1a2 2 0 0 1-2-2v-3a2 2 0 0 1 2-2h3`,key:`1xhozi`}]]),U=l(`heart-pulse`,[[`path`,{d:`M2 9.5a5.5 5.5 0 0 1 9.591-3.676.56.56 0 0 0 .818 0A5.49 5.49 0 0 1 22 9.5c0 2.29-1.5 4-3 5.5l-5.492 5.313a2 2 0 0 1-3 .019L5 15c-1.5-1.5-3-3.2-3-5.5`,key:`mvr1a0`}],[`path`,{d:`M3.22 13H9.5l.5-1 2 4.5 2-7 1.5 3.5h5.27`,key:`auskq0`}]]),ee=l(`memory-stick`,[[`path`,{d:`M6 19v-3`,key:`1nvgqn`}],[`path`,{d:`M10 19v-3`,key:`iu8nkm`}],[`path`,{d:`M14 19v-3`,key:`kcehxu`}],[`path`,{d:`M18 19v-3`,key:`1vh91z`}],[`path`,{d:`M8 11V9`,key:`63erz4`}],[`path`,{d:`M16 11V9`,key:`fru6f3`}],[`path`,{d:`M12 11V9`,key:`ha00sb`}],[`path`,{d:`M2 15h20`,key:`16ne18`}],[`path`,{d:`M2 7a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v1.1a2 2 0 0 0 0 3.837V17a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2v-5.1a2 2 0 0 0 0-3.837Z`,key:`lhddv3`}]]),W=e(n(),1),G=t(),K=[`DEBUG`,`INFO`,`WARNING`,`ERROR`],q={DEBUG:`text-gray-400`,INFO:`text-blue-400`,WARNING:`text-yellow-400`,ERROR:`text-red-400`},J={DEBUG:E,INFO:m,WARNING:b,ERROR:p};function te(){let e=o(),[t,n]=(0,W.useState)(!0),[r,i]=(0,W.useState)(new Set),[l,f]=(0,W.useState)(``),[p,h]=(0,W.useState)(`ALL`),[g,_]=(0,W.useState)(!1),[b,S]=(0,W.useState)(!1),C=(0,W.useRef)(null),{data:w,isLoading:D,refetch:O}=s({queryKey:[`application-logs`,p,l],queryFn:()=>a.getLogs({limit:200,level:p===`ALL`?void 0:p,search:l||void 0}),refetchInterval:b?2e3:!1,enabled:g});(0,W.useEffect)(()=>{g||S(!1)},[g]);let k=c({mutationFn:()=>a.clearLogs(),onSuccess:()=>{e.invalidateQueries({queryKey:[`application-logs`]})}});(0,W.useEffect)(()=>{t&&C.current&&w?.entries&&(C.current.scrollTop=C.current.scrollHeight)},[w?.entries,t]);let j=e=>{i(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},N=e=>{let t=e.split(` `);return t.length>=2?t[1]:e},P=(0,W.useMemo)(()=>w?.entries??[],[w?.entries]),F=(0,W.useMemo)(()=>[...P].reverse(),[P]),I=({level:e})=>(0,G.jsx)(J[e]||m,{className:`w-3.5 h-3.5 ${q[e]||`text-gray-400`}`});return(0,G.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg overflow-hidden`,children:[(0,G.jsxs)(`button`,{onClick:()=>_(!g),className:`w-full flex items-center justify-between p-4 hover:bg-bambu-dark-tertiary/50 transition-colors`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`p-2 rounded-lg ${b?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark-tertiary text-bambu-gray`}`,children:(0,G.jsx)(E,{className:`w-5 h-5`})}),(0,G.jsxs)(`div`,{className:`text-left`,children:[(0,G.jsx)(`p`,{className:`font-medium text-white`,children:`Application Logs`}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:b?`Live streaming - ${w?.filtered_count??0} entries`:`View and filter application logs`})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[b&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1.5 px-2 py-1 bg-bambu-green/20 rounded text-bambu-green text-xs`,children:[(0,G.jsx)(`span`,{className:`w-1.5 h-1.5 bg-bambu-green rounded-full animate-pulse`}),`Live`]}),g?(0,G.jsx)(d,{className:`w-5 h-5 text-bambu-gray`}):(0,G.jsx)(u,{className:`w-5 h-5 text-bambu-gray`})]})]}),g&&(0,G.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex flex-col gap-2 p-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[b?(0,G.jsxs)(`button`,{onClick:e=>{e.stopPropagation(),S(!1)},className:`flex items-center gap-1.5 px-3 py-1.5 text-sm bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400 hover:bg-red-200 dark:hover:bg-red-500/30 rounded transition-colors`,children:[(0,G.jsx)(M,{className:`w-4 h-4`}),`Stop`]}):(0,G.jsxs)(`button`,{onClick:e=>{e.stopPropagation(),S(!0),O()},className:`flex items-center gap-1.5 px-3 py-1.5 text-sm bg-bambu-green/20 text-bambu-green hover:bg-bambu-green/30 rounded transition-colors`,children:[(0,G.jsx)(v,{className:`w-4 h-4`}),`Start`]}),(0,G.jsxs)(`button`,{onClick:()=>k.mutate(),disabled:k.isPending||P.length===0,className:`flex items-center gap-1.5 px-3 py-1.5 text-sm bg-bambu-dark-tertiary text-bambu-gray hover:text-white hover:bg-bambu-dark-secondary rounded transition-colors disabled:opacity-50`,children:[(0,G.jsx)(T,{className:`w-4 h-4`}),`Clear`]}),(0,G.jsx)(`button`,{onClick:()=>O(),disabled:D,className:`flex items-center gap-1.5 px-3 py-1.5 text-sm bg-bambu-dark-tertiary text-bambu-gray hover:text-white hover:bg-bambu-dark-secondary rounded transition-colors disabled:opacity-50`,children:(0,G.jsx)(A,{className:`w-4 h-4 ${D?`animate-spin`:``}`})}),(0,G.jsx)(`div`,{className:`flex-1`}),(0,G.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-bambu-gray cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:t,onChange:e=>n(e.target.checked),className:`rounded border-bambu-dark-tertiary bg-bambu-dark-tertiary`}),`Auto-scroll`]}),(0,G.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[w?.filtered_count??0,`/`,w?.total_in_file??0]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`div`,{className:`relative flex-1`,children:[(0,G.jsx)(y,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,G.jsx)(`input`,{type:`text`,placeholder:`Search message or logger name...`,value:l,onChange:e=>f(e.target.value),className:`w-full pl-8 pr-8 py-1.5 text-sm bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`}),l&&(0,G.jsx)(`button`,{onClick:()=>f(``),className:`absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white`,children:(0,G.jsx)(x,{className:`w-4 h-4`})})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1 bg-bambu-dark-secondary rounded border border-bambu-dark-tertiary`,children:[(0,G.jsx)(`button`,{onClick:()=>h(`ALL`),className:`px-2 py-1.5 text-xs rounded-l transition-colors ${p===`ALL`?`bg-bambu-green text-white`:`text-bambu-gray hover:text-white`}`,children:`All`}),K.map((e,t)=>(0,G.jsx)(`button`,{onClick:()=>h(e),className:`px-2 py-1.5 text-xs transition-colors flex items-center gap-1 ${t===K.length-1?`rounded-r`:``} ${p===e?`${q[e]} bg-bambu-dark-tertiary`:`text-bambu-gray hover:text-white`}`,children:e},e))]})]})]}),(0,G.jsx)(`div`,{ref:C,className:`overflow-auto font-mono text-xs bg-black min-h-[300px] max-h-[500px]`,children:P.length===0?(0,G.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-[300px] text-bambu-gray`,children:[(0,G.jsx)(`p`,{className:`mb-2`,children:`No log entries found`}),(0,G.jsx)(`p`,{className:`text-sm`,children:`Log file may be empty or cleared`})]}):(0,G.jsx)(`div`,{className:`divide-y divide-bambu-dark-tertiary/30`,children:F.map((e,t)=>{let n=r.has(t),i=e.message.includes(` +import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,w as i,y as a}from"./client-DnySrlFv.js";import{n as o}from"./QueryClientProvider-Ce8_sN3w.js";import{t as s}from"./useQuery-BBCjCezC.js";import{t as c}from"./useMutation-B-Tr2hIP.js";import{t as l}from"./createLucideIcon-DvBYJlWL.js";import{a as u,i as d,n as f,r as p,t as m}from"./info-ROUoQhJR.js";import{t as h}from"./cpu-BKWEtc8k.js";import{t as g}from"./hard-drive-CgXAHN37.js";import{t as _}from"./loader-circle-BEmFtawu.js";import{t as v}from"./play-DIDYtk2S.js";import{t as y}from"./search-0n0CBc74.js";import{t as b}from"./triangle-alert-Dt_1FcBy.js";import{t as x}from"./x-DR-Trv6U.js";import{t as S}from"./Card-Bzc64K35.js";import{a as C}from"./date-G9KUauqz.js";import{An as w,At as T,Fn as E,Ft as D,Ht as O,Jt as k,Kt as A,Ln as j,Lt as M,On as N,Qt as P,Tn as F,_ as I,en as L,g as R,vn as z,wn as B,yn as V}from"./index-Cxa-KVmA.js";var H=l(`headphones`,[[`path`,{d:`M3 14h3a2 2 0 0 1 2 2v3a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-7a9 9 0 0 1 18 0v7a2 2 0 0 1-2 2h-1a2 2 0 0 1-2-2v-3a2 2 0 0 1 2-2h3`,key:`1xhozi`}]]),U=l(`heart-pulse`,[[`path`,{d:`M2 9.5a5.5 5.5 0 0 1 9.591-3.676.56.56 0 0 0 .818 0A5.49 5.49 0 0 1 22 9.5c0 2.29-1.5 4-3 5.5l-5.492 5.313a2 2 0 0 1-3 .019L5 15c-1.5-1.5-3-3.2-3-5.5`,key:`mvr1a0`}],[`path`,{d:`M3.22 13H9.5l.5-1 2 4.5 2-7 1.5 3.5h5.27`,key:`auskq0`}]]),ee=l(`memory-stick`,[[`path`,{d:`M6 19v-3`,key:`1nvgqn`}],[`path`,{d:`M10 19v-3`,key:`iu8nkm`}],[`path`,{d:`M14 19v-3`,key:`kcehxu`}],[`path`,{d:`M18 19v-3`,key:`1vh91z`}],[`path`,{d:`M8 11V9`,key:`63erz4`}],[`path`,{d:`M16 11V9`,key:`fru6f3`}],[`path`,{d:`M12 11V9`,key:`ha00sb`}],[`path`,{d:`M2 15h20`,key:`16ne18`}],[`path`,{d:`M2 7a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v1.1a2 2 0 0 0 0 3.837V17a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2v-5.1a2 2 0 0 0 0-3.837Z`,key:`lhddv3`}]]),W=e(n(),1),G=t(),K=[`DEBUG`,`INFO`,`WARNING`,`ERROR`],q={DEBUG:`text-gray-400`,INFO:`text-blue-400`,WARNING:`text-yellow-400`,ERROR:`text-red-400`},J={DEBUG:E,INFO:m,WARNING:b,ERROR:p};function te(){let e=o(),[t,n]=(0,W.useState)(!0),[r,i]=(0,W.useState)(new Set),[l,f]=(0,W.useState)(``),[p,h]=(0,W.useState)(`ALL`),[g,_]=(0,W.useState)(!1),[b,S]=(0,W.useState)(!1),C=(0,W.useRef)(null),{data:w,isLoading:D,refetch:O}=s({queryKey:[`application-logs`,p,l],queryFn:()=>a.getLogs({limit:200,level:p===`ALL`?void 0:p,search:l||void 0}),refetchInterval:b?2e3:!1,enabled:g});(0,W.useEffect)(()=>{g||S(!1)},[g]);let k=c({mutationFn:()=>a.clearLogs(),onSuccess:()=>{e.invalidateQueries({queryKey:[`application-logs`]})}});(0,W.useEffect)(()=>{t&&C.current&&w?.entries&&(C.current.scrollTop=C.current.scrollHeight)},[w?.entries,t]);let j=e=>{i(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},N=e=>{let t=e.split(` `);return t.length>=2?t[1]:e},P=(0,W.useMemo)(()=>w?.entries??[],[w?.entries]),F=(0,W.useMemo)(()=>[...P].reverse(),[P]),I=({level:e})=>(0,G.jsx)(J[e]||m,{className:`w-3.5 h-3.5 ${q[e]||`text-gray-400`}`});return(0,G.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg overflow-hidden`,children:[(0,G.jsxs)(`button`,{onClick:()=>_(!g),className:`w-full flex items-center justify-between p-4 hover:bg-bambu-dark-tertiary/50 transition-colors`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`p-2 rounded-lg ${b?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark-tertiary text-bambu-gray`}`,children:(0,G.jsx)(E,{className:`w-5 h-5`})}),(0,G.jsxs)(`div`,{className:`text-left`,children:[(0,G.jsx)(`p`,{className:`font-medium text-white`,children:`Application Logs`}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:b?`Live streaming - ${w?.filtered_count??0} entries`:`View and filter application logs`})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[b&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1.5 px-2 py-1 bg-bambu-green/20 rounded text-bambu-green text-xs`,children:[(0,G.jsx)(`span`,{className:`w-1.5 h-1.5 bg-bambu-green rounded-full animate-pulse`}),`Live`]}),g?(0,G.jsx)(d,{className:`w-5 h-5 text-bambu-gray`}):(0,G.jsx)(u,{className:`w-5 h-5 text-bambu-gray`})]})]}),g&&(0,G.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex flex-col gap-2 p-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[b?(0,G.jsxs)(`button`,{onClick:e=>{e.stopPropagation(),S(!1)},className:`flex items-center gap-1.5 px-3 py-1.5 text-sm bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400 hover:bg-red-200 dark:hover:bg-red-500/30 rounded transition-colors`,children:[(0,G.jsx)(M,{className:`w-4 h-4`}),`Stop`]}):(0,G.jsxs)(`button`,{onClick:e=>{e.stopPropagation(),S(!0),O()},className:`flex items-center gap-1.5 px-3 py-1.5 text-sm bg-bambu-green/20 text-bambu-green hover:bg-bambu-green/30 rounded transition-colors`,children:[(0,G.jsx)(v,{className:`w-4 h-4`}),`Start`]}),(0,G.jsxs)(`button`,{onClick:()=>k.mutate(),disabled:k.isPending||P.length===0,className:`flex items-center gap-1.5 px-3 py-1.5 text-sm bg-bambu-dark-tertiary text-bambu-gray hover:text-white hover:bg-bambu-dark-secondary rounded transition-colors disabled:opacity-50`,children:[(0,G.jsx)(T,{className:`w-4 h-4`}),`Clear`]}),(0,G.jsx)(`button`,{onClick:()=>O(),disabled:D,className:`flex items-center gap-1.5 px-3 py-1.5 text-sm bg-bambu-dark-tertiary text-bambu-gray hover:text-white hover:bg-bambu-dark-secondary rounded transition-colors disabled:opacity-50`,children:(0,G.jsx)(A,{className:`w-4 h-4 ${D?`animate-spin`:``}`})}),(0,G.jsx)(`div`,{className:`flex-1`}),(0,G.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-bambu-gray cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:t,onChange:e=>n(e.target.checked),className:`rounded border-bambu-dark-tertiary bg-bambu-dark-tertiary`}),`Auto-scroll`]}),(0,G.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[w?.filtered_count??0,`/`,w?.total_in_file??0]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`div`,{className:`relative flex-1`,children:[(0,G.jsx)(y,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,G.jsx)(`input`,{type:`text`,placeholder:`Search message or logger name...`,value:l,onChange:e=>f(e.target.value),className:`w-full pl-8 pr-8 py-1.5 text-sm bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`}),l&&(0,G.jsx)(`button`,{onClick:()=>f(``),className:`absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white`,children:(0,G.jsx)(x,{className:`w-4 h-4`})})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1 bg-bambu-dark-secondary rounded border border-bambu-dark-tertiary`,children:[(0,G.jsx)(`button`,{onClick:()=>h(`ALL`),className:`px-2 py-1.5 text-xs rounded-l transition-colors ${p===`ALL`?`bg-bambu-green text-white`:`text-bambu-gray hover:text-white`}`,children:`All`}),K.map((e,t)=>(0,G.jsx)(`button`,{onClick:()=>h(e),className:`px-2 py-1.5 text-xs transition-colors flex items-center gap-1 ${t===K.length-1?`rounded-r`:``} ${p===e?`${q[e]} bg-bambu-dark-tertiary`:`text-bambu-gray hover:text-white`}`,children:e},e))]})]})]}),(0,G.jsx)(`div`,{ref:C,className:`overflow-auto font-mono text-xs bg-black min-h-[300px] max-h-[500px]`,children:P.length===0?(0,G.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-[300px] text-bambu-gray`,children:[(0,G.jsx)(`p`,{className:`mb-2`,children:`No log entries found`}),(0,G.jsx)(`p`,{className:`text-sm`,children:`Log file may be empty or cleared`})]}):(0,G.jsx)(`div`,{className:`divide-y divide-bambu-dark-tertiary/30`,children:F.map((e,t)=>{let n=r.has(t),i=e.message.includes(` `);return(0,G.jsx)(`div`,{className:`p-2 cursor-pointer hover:bg-bambu-dark-secondary/50 transition-colors ${n?`bg-bambu-dark-secondary/30`:``}`,onClick:()=>i&&j(t),children:(0,G.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray/70 shrink-0 w-20`,children:N(e.timestamp)}),(0,G.jsx)(`span`,{className:`shrink-0`,children:(0,G.jsx)(I,{level:e.level})}),(0,G.jsxs)(`span`,{className:`text-purple-400/80 shrink-0 max-w-[200px] truncate`,title:e.logger_name,children:[`[`,e.logger_name,`]`]}),(0,G.jsx)(`span`,{className:`flex-1 ${q[e.level]||`text-white/80`} ${!n&&i?`truncate`:``}`,children:n?(0,G.jsx)(`pre`,{className:`whitespace-pre-wrap break-all`,children:e.message}):e.message.split(` `)[0]}),i&&(0,G.jsx)(`span`,{className:`text-bambu-gray/50 shrink-0`,children:n?(0,G.jsx)(d,{className:`w-3.5 h-3.5`}):(0,G.jsx)(u,{className:`w-3.5 h-3.5`})})]})},t)})})}),(0,G.jsx)(`div`,{className:`flex items-center justify-between p-3 border-t border-bambu-dark-tertiary text-sm text-bambu-gray`,children:b?(0,G.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`w-2 h-2 bg-green-500 rounded-full animate-pulse`}),`Auto-refreshing every 2 seconds`]}):(0,G.jsx)(`span`,{children:`Click Start to enable live log streaming`})})]})]})}function ne(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:e<1024*1024*1024?`${(e/(1024*1024)).toFixed(1)} MB`:`${(e/(1024*1024*1024)).toFixed(2)} GB`}function Y({icon:e,label:t,value:n,subValue:r,color:i=`text-bambu-green`}){return(0,G.jsxs)(`div`,{className:`flex items-start gap-3 p-4 bg-bambu-dark rounded-lg`,children:[(0,G.jsx)(`div`,{className:`p-2 rounded-lg bg-bambu-dark-tertiary ${i}`,children:(0,G.jsx)(e,{className:`w-5 h-5`})}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:t}),(0,G.jsx)(`p`,{className:`text-lg font-semibold text-white truncate`,children:n}),r&&(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:r})]})]})}function X({percent:e,color:t=`bg-bambu-green`}){return(0,G.jsx)(`div`,{className:`w-full h-2 bg-bambu-dark rounded-full overflow-hidden`,children:(0,G.jsx)(`div`,{className:`h-full ${t} transition-all duration-300`,style:{width:`${Math.min(100,e)}%`}})})}function Z({title:e,icon:t,children:n}){return(0,G.jsxs)(S,{className:`p-6`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-4`,children:[(0,G.jsx)(t,{className:`w-5 h-5 text-bambu-green`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e})]}),n]})}function Q(){let{t:e}=i(),t=o(),[n,c]=(0,W.useState)(null),[l,u]=(0,W.useState)(!1),[d,p]=(0,W.useState)(!1),[m,v]=(0,W.useState)(null),{data:y,isLoading:b,refetch:x,isFetching:S}=s({queryKey:[`systemInfo`],queryFn:r.getSystemInfo,refetchInterval:3e4}),{data:T}=s({queryKey:[`debugLogging`],queryFn:a.getDebugLoggingState,staleTime:10*1e3,refetchInterval:10*1e3}),{data:M}=s({queryKey:[`settings`],queryFn:r.getSettings}),{data:K}=s({queryKey:[`library-stats`],queryFn:r.getLibraryStats}),{data:q}=s({queryKey:[`printers`],queryFn:r.getPrinters}),{data:J,refetch:Q,isFetching:$}=s({queryKey:[`systemHealth`],queryFn:r.getSystemHealth,staleTime:60*1e3}),re=M?.time_format||`system`,ie=async()=>{p(!0);try{let e=await a.setDebugLogging(!T?.enabled);t.setQueryData([`debugLogging`],e)}catch(e){console.error(`Failed to toggle debug logging:`,e)}finally{p(!1)}},ae=async()=>{c(null),u(!0);try{await a.downloadSupportBundle()}catch(e){c(e instanceof Error?e.message:`Failed to download support bundle`)}finally{u(!1)}};if(b)return(0,G.jsx)(`div`,{className:`flex items-center justify-center h-64`,children:(0,G.jsx)(_,{className:`w-8 h-8 text-bambu-green animate-spin`})});if(!y)return(0,G.jsx)(`div`,{className:`p-6 text-center text-bambu-gray`,children:e(`system.failedToLoad`,`Failed to load system information`)});let oe=y.storage.disk_percent_used>90?`bg-red-500`:y.storage.disk_percent_used>75?`bg-yellow-500`:`bg-bambu-green`,se=y.memory.percent_used>90?`bg-red-500`:y.memory.percent_used>75?`bg-yellow-500`:`bg-bambu-green`;return(0,G.jsxs)(`div`,{className:`p-6 space-y-6`,children:[(0,G.jsxs)(`div`,{className:`flex flex-col items-start gap-4 sm:flex-row sm:items-center sm:justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h1`,{className:`text-2xl font-bold text-white`,children:e(`system.title`,`System Information`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:e(`system.subtitle`,`Monitor system resources and database statistics`)})]}),(0,G.jsxs)(`button`,{onClick:()=>x(),disabled:S,className:`flex items-center gap-2 px-4 py-2 bg-bambu-dark-secondary hover:bg-bambu-dark-tertiary rounded-lg transition-colors disabled:opacity-50`,children:[(0,G.jsx)(A,{className:`w-4 h-4 ${S?`animate-spin`:``}`}),e(`common.refresh`,`Refresh`)]})]}),(0,G.jsx)(Z,{title:e(`system.application`,`Application`),icon:O,children:(0,G.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-4`,children:[(0,G.jsx)(Y,{icon:O,label:e(`system.version`,`Version`),value:`v${y.app.version}`}),(0,G.jsx)(Y,{icon:N,label:e(`system.uptime`,`System Uptime`),value:y.system.uptime_formatted}),(0,G.jsx)(Y,{icon:O,label:e(`system.hostname`,`Hostname`),value:y.system.hostname})]})}),(0,G.jsx)(Z,{title:e(`support.title`,`Support & Troubleshooting`),icon:H,children:(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`support.description`,`Enable debug logging to capture detailed information, then download a support bundle to share when reporting issues.`)}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-4 bg-bambu-dark rounded-lg`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`p-2 rounded-lg ${T?.enabled?`bg-amber-500/20 text-amber-500`:`bg-bambu-dark-tertiary text-bambu-gray`}`,children:(0,G.jsx)(E,{className:`w-5 h-5`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`font-medium text-white`,children:e(`support.debugLogging`,`Debug Logging`)}),(0,G.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[T?.enabled?e(`support.debugLoggingEnabled`,`Capturing detailed logs`):e(`support.debugLoggingDisabled`,`Normal logging level`),T?.enabled&&T.duration_seconds!==null&&(0,G.jsxs)(`span`,{className:`text-amber-700 dark:text-amber-400 ml-2`,children:[`(`,Math.floor(T.duration_seconds/60),`m `,T.duration_seconds%60,`s)`]})]})]})]}),(0,G.jsxs)(`button`,{onClick:ie,disabled:d,className:`px-4 py-2 rounded-lg font-medium transition-colors flex items-center gap-2 ${T?.enabled?`bg-amber-100 text-amber-700 hover:bg-amber-200 dark:bg-amber-500/20 dark:text-amber-400 dark:hover:bg-amber-500/30`:`bg-bambu-green/20 text-bambu-green hover:bg-bambu-green/30`} disabled:opacity-50`,children:[d&&(0,G.jsx)(_,{className:`w-4 h-4 animate-spin`}),T?.enabled?e(`support.disableDebug`,`Disable`):e(`support.enableDebug`,`Enable`)]})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-4 bg-bambu-dark rounded-lg`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`p-2 rounded-lg bg-bambu-dark-tertiary text-bambu-green`,children:(0,G.jsx)(B,{className:`w-5 h-5`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`font-medium text-white`,children:e(`support.supportBundle`,`Support Bundle`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`support.supportBundleDescription`,`Download system info and logs as a ZIP file`)})]})]}),(0,G.jsxs)(`button`,{onClick:ae,disabled:l||!T?.enabled,className:`px-4 py-2 rounded-lg font-medium bg-bambu-green/20 text-bambu-green hover:bg-bambu-green/30 transition-colors flex items-center gap-2 disabled:opacity-50 disabled:cursor-not-allowed`,title:T?.enabled?void 0:e(`support.enableDebugFirst`,`Enable debug logging first`),children:[l&&(0,G.jsx)(_,{className:`w-4 h-4 animate-spin`}),l?e(`support.bundleGenerating`,`Generating...`):e(`common.download`,`Download`)]})]}),l&&(0,G.jsxs)(`div`,{className:`p-3 bg-bambu-dark-tertiary/40 rounded-lg space-y-1`,children:[(0,G.jsxs)(`p`,{className:`text-sm font-medium text-white flex items-center gap-2`,children:[(0,G.jsx)(_,{className:`w-3.5 h-3.5 animate-spin text-bambu-green`}),e(`support.bundleGenerating`,`Generating...`)]}),(0,G.jsxs)(`ul`,{className:`text-xs text-bambu-gray list-disc list-inside space-y-0.5 pl-1`,children:[(0,G.jsx)(`li`,{children:e(`support.bundleStepConnection`,`Running printer connectivity checks`)}),(0,G.jsx)(`li`,{children:e(`support.bundleStepVirtualPrinters`,`Running virtual-printer setup checks`)}),(0,G.jsx)(`li`,{children:e(`support.bundleStepLogScan`,`Scanning recent logs for known issues`)}),(0,G.jsx)(`li`,{children:e(`support.bundleStepBuild`,`Building the support bundle ZIP`)})]})]}),n&&(0,G.jsx)(`div`,{className:`p-3 bg-red-100 border border-red-300 rounded-lg text-red-700 dark:bg-red-500/20 dark:border-red-500/30 dark:text-red-400 text-sm`,children:n}),!T?.enabled&&(0,G.jsx)(`div`,{className:`p-4 bg-bambu-dark-tertiary/50 rounded-lg`,children:(0,G.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[(0,G.jsx)(`span`,{className:`text-amber-700 dark:text-amber-400 font-medium`,children:e(`support.instructions`,`To report an issue:`)}),(0,G.jsx)(`br`,{}),`1. `,e(`support.step1`,`Enable debug logging`),(0,G.jsx)(`br`,{}),`2. `,e(`support.step2`,`Reproduce the issue`),(0,G.jsx)(`br`,{}),`3. `,e(`support.step3`,`Download the support bundle`),(0,G.jsx)(`br`,{}),`4. `,e(`support.step4`,`Attach the ZIP file to your issue report`)]})}),(0,G.jsxs)(`div`,{className:`p-4 bg-bambu-dark rounded-lg space-y-3`,children:[(0,G.jsx)(`p`,{className:`text-sm font-medium text-white`,children:e(`support.privacyTitle`,`What's in the support bundle?`)}),(0,G.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4 text-sm`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-bambu-green font-medium mb-1`,children:e(`support.collected`,`Collected:`)}),(0,G.jsxs)(`ul`,{className:`text-bambu-gray space-y-0.5`,children:[(0,G.jsxs)(`li`,{children:[`• `,e(`support.collectItem1`,`App version and debug mode`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.collectItem2`,`OS, architecture, Python version`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.collectItem3`,`Database statistics (counts only)`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.collectItem4`,`Printer models and nozzle counts`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.collectItem5`,`Non-sensitive settings (themes, formats)`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.collectItem6`,`Debug logs (sanitized)`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.collectItem7`,`Printer connectivity and firmware versions`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.collectItem8`,`Integration status (Spoolman, MQTT, HA)`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.collectItem9`,`Network interfaces (subnets only)`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.collectItem10`,`Python package versions`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.collectItem11`,`Database health checks`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.collectItem12`,`Docker environment details`)]})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-red-700 dark:text-red-400 font-medium mb-1`,children:e(`support.notCollected`,`NOT collected:`)}),(0,G.jsxs)(`ul`,{className:`text-bambu-gray space-y-0.5`,children:[(0,G.jsxs)(`li`,{children:[`• `,e(`support.notItem1`,`Printer names and serial numbers`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.notItem2`,`Access codes and passwords`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.notItem3`,`Email addresses`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.notItem4`,`API keys and tokens`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.notItem5`,`Webhook URLs`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.notItem6`,`Your hostname or username`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.notItem7`,`IP addresses`)]})]})]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray/70`,children:e(`support.privacyNote`,`Email addresses in logs are replaced with [EMAIL], printer names with [PRINTER], serial numbers with [SERIAL], and IP addresses with [IP].`)})]}),(0,G.jsx)(te,{})]})}),(0,G.jsxs)(Z,{title:e(`diagnostic.sectionTitle`,`Connection Diagnostic`),icon:D,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4`,children:e(`diagnostic.sectionDescription`,`Check why a printer won't connect or won't print — port reachability, LAN developer mode, Docker network mode, and credentials.`)}),q&&q.length>0?(0,G.jsx)(`div`,{className:`space-y-2`,children:q.map(t=>(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-3 bg-bambu-dark rounded-lg`,children:[(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(`span`,{className:`font-medium text-white`,children:t.name}),(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray ml-2`,children:t.ip_address})]}),(0,G.jsxs)(`button`,{onClick:()=>v(t),className:`flex items-center gap-2 px-3 py-1.5 text-sm bg-bambu-dark-secondary hover:bg-bambu-dark-tertiary text-white rounded-lg transition-colors flex-shrink-0`,children:[(0,G.jsx)(D,{className:`w-4 h-4`}),e(`diagnostic.runButton`,`Run diagnostic`)]})]},t.id))}):(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:e(`diagnostic.noPrinters`,`No printers configured.`)})]}),(0,G.jsxs)(Z,{title:e(`systemHealth.sectionTitle`),icon:U,children:[(0,G.jsxs)(`div`,{className:`flex items-start justify-between gap-3 mb-3`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`systemHealth.sectionDescription`)}),(0,G.jsxs)(`button`,{onClick:()=>Q(),disabled:$,className:`flex items-center gap-2 px-3 py-1.5 text-sm bg-bambu-dark-secondary hover:bg-bambu-dark-tertiary text-white rounded-lg transition-colors flex-shrink-0 disabled:opacity-50`,children:[(0,G.jsx)(A,{className:`w-4 h-4 ${$?`animate-spin`:``}`}),e(`systemHealth.rescan`)]})]}),J?(0,G.jsx)(R,{result:J}):(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`common.loading`)})]}),(0,G.jsxs)(Z,{title:e(`system.database`,`Database`),icon:F,children:[(0,G.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4 mb-4`,children:[(0,G.jsx)(Y,{icon:F,label:e(`system.dbEngine`,`Database Engine`),value:y.database.engine||`SQLite`}),(0,G.jsx)(Y,{icon:F,label:e(`system.dbVersion`,`Version`),value:y.database.version||`unknown`})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-4 mb-4`,children:[(0,G.jsx)(Y,{icon:j,label:e(`system.totalArchives`,`Total Archives`),value:y.database.archives}),(0,G.jsx)(Y,{icon:w,label:e(`system.completed`,`Completed`),value:y.database.archives_completed,color:`text-green-500`}),(0,G.jsx)(Y,{icon:f,label:e(`system.failed`,`Failed`),value:y.database.archives_failed,color:`text-red-500`}),(0,G.jsx)(Y,{icon:_,label:e(`system.printing`,`Printing`),value:y.database.archives_printing,color:`text-yellow-500`})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-4`,children:[(0,G.jsx)(Y,{icon:k,label:e(`system.printers`,`Printers`),value:y.database.printers}),(0,G.jsx)(Y,{icon:L,label:e(`system.filaments`,`Filaments`),value:y.database.filaments}),(0,G.jsx)(Y,{icon:V,label:e(`system.projects`,`Projects`),value:y.database.projects}),(0,G.jsx)(Y,{icon:P,label:e(`system.smartPlugs`,`Smart Plugs`),value:y.database.smart_plugs})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4 mt-4`,children:[(0,G.jsx)(Y,{icon:N,label:e(`system.totalPrintTime`,`Total Print Time`),value:y.database.total_print_time_formatted}),(0,G.jsx)(Y,{icon:j,label:e(`system.totalFilament`,`Total Filament Used`),value:`${y.database.total_filament_kg} kg`,subValue:`${y.database.total_filament_grams.toLocaleString()} g`})]})]}),(0,G.jsxs)(Z,{title:e(`system.connectedPrinters`,`Connected Printers`),icon:k,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-4 mb-4`,children:[(0,G.jsx)(`div`,{className:`text-3xl font-bold text-bambu-green`,children:y.printers.connected}),(0,G.jsx)(`div`,{className:`text-bambu-gray`,children:e(`system.ofTotal`,`of {{total}} printers connected`,{total:y.printers.total})})]}),y.printers.connected_list.length>0?(0,G.jsx)(`div`,{className:`space-y-2`,children:y.printers.connected_list.map(e=>(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-3 bg-bambu-dark rounded-lg`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-bambu-green`}),(0,G.jsx)(`span`,{className:`font-medium text-white`,children:e.name})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-4 text-sm text-bambu-gray`,children:[(0,G.jsx)(`span`,{children:e.model}),(0,G.jsx)(`span`,{className:`px-2 py-0.5 rounded ${e.state===`RUNNING`?`bg-bambu-green/20 text-bambu-green`:e.state===`IDLE`?`bg-blue-100 text-blue-700 dark:bg-blue-500/20 dark:text-blue-400`:`bg-bambu-dark-tertiary`}`,children:e.state})]})]},e.id))}):(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:e(`system.noPrintersConnected`,`No printers connected`)})]}),(0,G.jsx)(Z,{title:e(`system.storage`,`Storage`),icon:g,children:(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex justify-between text-sm mb-1`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:e(`system.diskUsage`,`Disk Usage`)}),(0,G.jsxs)(`span`,{className:`text-white`,children:[y.storage.disk_used_formatted,` / `,y.storage.disk_total_formatted]})]}),(0,G.jsx)(X,{percent:y.storage.disk_percent_used,color:oe}),(0,G.jsxs)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:[y.storage.disk_free_formatted,` `,e(`system.free`,`free`),` (`,(100-y.storage.disk_percent_used).toFixed(1),`%)`]})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-4`,children:[(0,G.jsx)(Y,{icon:j,label:e(`system.archiveStorage`,`Archive Storage`),value:y.storage.archive_size_formatted}),(0,G.jsx)(Y,{icon:F,label:e(`system.databaseSize`,`Database Size`),value:y.storage.database_size_formatted}),K&&(0,G.jsx)(Y,{icon:z,label:e(`system.fileManagerStorage`,`File Manager`),value:ne(K.total_size_bytes),subValue:`${K.total_files} files, ${K.total_folders} folders`})]})]})}),(0,G.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-6`,children:[(0,G.jsx)(Z,{title:e(`system.memory`,`Memory`),icon:ee,children:(0,G.jsx)(`div`,{className:`space-y-4`,children:(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex justify-between text-sm mb-1`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:e(`system.memoryUsage`,`Memory Usage`)}),(0,G.jsxs)(`span`,{className:`text-white`,children:[y.memory.used_formatted,` / `,y.memory.total_formatted]})]}),(0,G.jsx)(X,{percent:y.memory.percent_used,color:se}),(0,G.jsxs)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:[y.memory.available_formatted,` `,e(`system.available`,`available`)]})]})})}),(0,G.jsx)(Z,{title:e(`system.cpu`,`CPU`),icon:h,children:(0,G.jsx)(`div`,{className:`space-y-4`,children:(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,G.jsx)(Y,{icon:h,label:e(`system.cores`,`Cores`),value:y.cpu.count,subValue:`${y.cpu.count_logical} logical`}),(0,G.jsx)(Y,{icon:h,label:e(`system.usage`,`Usage`),value:`${y.cpu.percent}%`})]})})})]}),(0,G.jsx)(Z,{title:e(`system.systemDetails`,`System Details`),icon:O,children:(0,G.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-4`,children:[(0,G.jsx)(Y,{icon:O,label:e(`system.os`,`Operating System`),value:y.system.platform,subValue:y.system.platform_release}),(0,G.jsx)(Y,{icon:h,label:e(`system.architecture`,`Architecture`),value:y.system.architecture}),(0,G.jsx)(Y,{icon:O,label:e(`system.python`,`Python`),value:y.system.python_version}),(0,G.jsx)(Y,{icon:N,label:e(`system.bootTime`,`Boot Time`),value:C(y.system.boot_time,re)})]})}),m&&(0,G.jsx)(I,{printerId:m.id,printerName:m.name,onClose:()=>v(null)})]})}export{Q as SystemInfoPage}; \ No newline at end of file diff --git a/static/assets/index-0t--Yqoi.js b/static/assets/index-Cxa-KVmA.js similarity index 99% rename from static/assets/index-0t--Yqoi.js rename to static/assets/index-Cxa-KVmA.js index da90e03a7..c1289605d 100644 --- a/static/assets/index-0t--Yqoi.js +++ b/static/assets/index-Cxa-KVmA.js @@ -1,4 +1,4 @@ -const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/PrintersPage-Dsyz3sPW.js","assets/chunk-aKtaBQYM.js","assets/CartesianChart-BAcHzPFb.js","assets/createLucideIcon-DvBYJlWL.js","assets/client-DnySrlFv.js","assets/react-dom-B8Dg6xzp.js","assets/with-selector-CsEuXInf.js","assets/QueryClientProvider-Ce8_sN3w.js","assets/useMutation-B-Tr2hIP.js","assets/useQuery-BBCjCezC.js","assets/ErrorBarContext-CcijMMkA.js","assets/FileUploadModal-CpDg524n.js","assets/info-ROUoQhJR.js","assets/ToastContext-BRX0SW3C.js","assets/loader-circle-BEmFtawu.js","assets/x-DR-Trv6U.js","assets/file-DDkFXH-b.js","assets/ContextMenu-BOFgRmSk.js","assets/search-0n0CBc74.js","assets/zoom-out-DNNe6DMN.js","assets/OrbitControls-Bbqf07B-.js","assets/Button-DDr6eAFy.js","assets/haSensorDisplay-lPbcOxD8.js","assets/gauge-D21zgWMb.js","assets/lock-MLqgWH4Q.js","assets/wind-CI8UoBMf.js","assets/triangle-alert-Dt_1FcBy.js","assets/arrow-down-Cj0DZhNf.js","assets/arrow-left-0Q6F2rjC.js","assets/arrow-right-DedpIMhP.js","assets/arrow-up-down-BdyOV_2F.js","assets/arrow-up-D-pfJ3WZ.js","assets/ReferenceLine-clJprXoH.js","assets/box-DAdKb9s5.js","assets/fan-D6AmXZMv.js","assets/calendar-BLKPnWqV.js","assets/check-Ck0cMLU4.js","assets/copy-Cu_0GKCU.js","assets/ellipsis-vertical-t2D7cYyp.js","assets/eye-off-6CkaxYwP.js","assets/file-box-04V4jZ9_.js","assets/GcodeToolpathViewer-Cg6UnTDw.js","assets/scan-search-BDoNAXzz.js","assets/funnel-C3dyAMK9.js","assets/grip-vertical-C_1RDxRw.js","assets/hard-drive-CgXAHN37.js","assets/layout-grid-DkD3u6wa.js","assets/log-in-n0ckHxnD.js","assets/maximize-2-kPQ77q72.js","assets/minimize-2-dqT-k7oI.js","assets/CameraDiagnoseModal-38LtfiVu.js","assets/minus-DypeGjGR.js","assets/CopyButton-C5In5weo.js","assets/move-Bc1EIjTD.js","assets/package-BGUevlqS.js","assets/pause-DFb6GX_6.js","assets/play-DIDYtk2S.js","assets/settings-2-Cvn837lh.js","assets/unlink-C098nwOf.js","assets/CameraWall-Cv6o1Fp5.js","assets/useQueries-Be6PMvSC.js","assets/date-G9KUauqz.js","assets/ConfigureAmsSlotModal-D0mYskEf.js","assets/utils-DVekehs6.js","assets/useCancellableTimeout-3XQzNJkJ.js","assets/inventorySearch-C_D57LMP.js","assets/slicerPrinterMatch-CUdoNag2.js","assets/Card-Bzc64K35.js","assets/Toggle-KiqA_5fU.js","assets/filamentSwatchHelpers-D3oXQSGk.js","assets/printerModel-DrNvERGQ.js","assets/queueItemName-UFY7kpjG.js","assets/ArchivesPage-CSganGGR.js","assets/RichTextEditor-BBu-zZie.js","assets/list-CLcpeoSz.js","assets/purify.es-F_7NWVtX.js","assets/chevrons-right-DTJgqnxZ.js","assets/cog-Dol1I0kq.js","assets/coins-4u6IPkR-.js","assets/columns-2-DVEObeDC.js","assets/file-spreadsheet-WxOA9vYy.js","assets/git-compare-J4KX0xAJ.js","assets/SliceModal-TzmWgODN.js","assets/cloud-off-DfYbNG2N.js","assets/history-B4lOLL01.js","assets/pen-line-BWR04BX-.js","assets/qr-code-CCCo2-Br.js","assets/skip-forward-BsuMfFkw.js","assets/sticky-note-BH0LPqRx.js","assets/ColumnConfigModal-DrIkn1Rf.js","assets/PhotoGalleryModal-C8-A6a4s.js","assets/filamentTypes-Dysa4k6j.js","assets/slicer-DgCA7cW6.js","assets/QueuePage-CjROU5dj.js","assets/sortable.esm-D2bGix-3.js","assets/timer-GUTR9dAu.js","assets/workflow-BgT0wW83.js","assets/StatsPage-CHDgcYiv.js","assets/dollar-sign-Cj_Yhud4.js","assets/target-B40GQtrA.js","assets/AreaChart-DJpIJXxF.js","assets/SettingsPage-CF4BZl3e.js","assets/briefcase-Dau7xqMY.js","assets/cpu-BKWEtc8k.js","assets/link-2-MI-QCMh8.js","assets/locationSensorDefaults-Bb4u9P8m.js","assets/scale-CD6XdXUk.js","assets/shield-bODVqOJd.js","assets/smartphone-DaDGaGLT.js","assets/OverlayFrame-fLmufrTC.js","assets/FinancePage-WsLEQ1fC.js","assets/ProfilesPage-CqnWMUyc.js","assets/droplet-CqYXMF2u.js","assets/sparkles-DRqKNlhr.js","assets/MaintenancePage-GtlPlRFZ.js","assets/ProjectsPage--qAFcLFS.js","assets/ProjectDetailPage-BMGYb4NN.js","assets/libraryFiles-B0B1SFfn.js","assets/FileManagerPage-FtcjfbEh.js","assets/usePreviewFullscreen-ButueZqN.js","assets/LibraryTrashPage-GKtQzVNm.js","assets/CameraPage-2mgwi0u3.js","assets/CamWallPage-B93EYwGu.js","assets/StreamOverlayPage-BDnwgk_X.js","assets/StreamOverlayPage-CA9KpVK8.css","assets/ExternalLinkPage--eeDFa4j.js","assets/GroupEditPage-BfkGtN0q.js","assets/PrinterLocationsPage-BmifXYE1.js","assets/InventoryPage-CPx98yw-.js","assets/AdditionalSection-BgleEt_Y.js","assets/AssignToAmsModal-CcnpBCWY.js","assets/AmsUnitCard-Dim7pnZ8.js","assets/spoolPaint-CrvpHqdD.js","assets/ModelSourcesPage-Crhk7_mU.js","assets/SystemInfoPage-CjmM6f9Q.js","assets/LoginPage-rGUF5BC3.js","assets/ConnectAuthorizePage-m6XXoE23.js","assets/SetupPage-C42DVxS_.js","assets/NotificationsPage-B3GOs-as.js","assets/GCodeViewerPage-CAOZmPME.js","assets/SpoolBuddyDashboard-BEpEFke6.js","assets/SpoolIcon-DE8TbEec.js","assets/SpoolBuddyAmsPage-CUILYofw.js","assets/SpoolBuddySettingsPage-FUv2PkN1.js","assets/SpoolBuddyCalibrationPage-BqJCOceW.js","assets/SpoolBuddyWriteTagPage-DwfWgHhK.js","assets/SpoolBuddyInventoryPage-DOeFqPsy.js"])))=>i.map(i=>d[i]); +const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/PrintersPage-CLG7I78P.js","assets/chunk-aKtaBQYM.js","assets/CartesianChart-BAcHzPFb.js","assets/createLucideIcon-DvBYJlWL.js","assets/client-DnySrlFv.js","assets/react-dom-B8Dg6xzp.js","assets/with-selector-CsEuXInf.js","assets/QueryClientProvider-Ce8_sN3w.js","assets/useMutation-B-Tr2hIP.js","assets/useQuery-BBCjCezC.js","assets/ErrorBarContext-CcijMMkA.js","assets/FileUploadModal-Dee1GxH_.js","assets/info-ROUoQhJR.js","assets/ToastContext-BRX0SW3C.js","assets/loader-circle-BEmFtawu.js","assets/x-DR-Trv6U.js","assets/file-DDkFXH-b.js","assets/ContextMenu-CwroFwVJ.js","assets/search-0n0CBc74.js","assets/zoom-out-DNNe6DMN.js","assets/OrbitControls-Bbqf07B-.js","assets/Button-DDr6eAFy.js","assets/haSensorDisplay-lPbcOxD8.js","assets/gauge-D21zgWMb.js","assets/lock-MLqgWH4Q.js","assets/wind-CI8UoBMf.js","assets/triangle-alert-Dt_1FcBy.js","assets/arrow-down-Cj0DZhNf.js","assets/arrow-left-0Q6F2rjC.js","assets/arrow-right-DedpIMhP.js","assets/arrow-up-down-BdyOV_2F.js","assets/arrow-up-D-pfJ3WZ.js","assets/ReferenceLine-clJprXoH.js","assets/box-DAdKb9s5.js","assets/fan-D6AmXZMv.js","assets/calendar-BLKPnWqV.js","assets/check-Ck0cMLU4.js","assets/copy-Cu_0GKCU.js","assets/ellipsis-vertical-t2D7cYyp.js","assets/eye-off-6CkaxYwP.js","assets/file-box-04V4jZ9_.js","assets/GcodeToolpathViewer-Cg6UnTDw.js","assets/scan-search-BDoNAXzz.js","assets/funnel-C3dyAMK9.js","assets/grip-vertical-C_1RDxRw.js","assets/hard-drive-CgXAHN37.js","assets/layout-grid-DkD3u6wa.js","assets/log-in-n0ckHxnD.js","assets/maximize-2-kPQ77q72.js","assets/minimize-2-dqT-k7oI.js","assets/CameraDiagnoseModal-BwHHipUP.js","assets/minus-DypeGjGR.js","assets/CopyButton-C5In5weo.js","assets/move-Bc1EIjTD.js","assets/package-BGUevlqS.js","assets/pause-DFb6GX_6.js","assets/play-DIDYtk2S.js","assets/settings-2-Cvn837lh.js","assets/unlink-C098nwOf.js","assets/CameraWall-D-W28jK-.js","assets/useQueries-Be6PMvSC.js","assets/date-G9KUauqz.js","assets/ConfigureAmsSlotModal-BgpDvjjX.js","assets/utils-subfXwl6.js","assets/useCancellableTimeout-3XQzNJkJ.js","assets/inventorySearch-TJiB5tGt.js","assets/slicerPrinterMatch-CUdoNag2.js","assets/Card-Bzc64K35.js","assets/Toggle-KiqA_5fU.js","assets/filamentSwatchHelpers-D3oXQSGk.js","assets/printerModel-DrNvERGQ.js","assets/queueItemName-UFY7kpjG.js","assets/ArchivesPage-BrcJqnr-.js","assets/RichTextEditor-CsfJOD7X.js","assets/list-CLcpeoSz.js","assets/purify.es-F_7NWVtX.js","assets/chevrons-right-DTJgqnxZ.js","assets/cog-Dol1I0kq.js","assets/coins-4u6IPkR-.js","assets/columns-2-DVEObeDC.js","assets/file-spreadsheet-WxOA9vYy.js","assets/git-compare-J4KX0xAJ.js","assets/SliceModal-YlJTMEj6.js","assets/cloud-off-DfYbNG2N.js","assets/history-B4lOLL01.js","assets/pen-line-BWR04BX-.js","assets/qr-code-CCCo2-Br.js","assets/skip-forward-BsuMfFkw.js","assets/sticky-note-BH0LPqRx.js","assets/ColumnConfigModal-BBpKz9m6.js","assets/PhotoGalleryModal-BPFizk3N.js","assets/filamentTypes-Dysa4k6j.js","assets/slicer-DgCA7cW6.js","assets/QueuePage-NR_JuCMy.js","assets/sortable.esm-D2bGix-3.js","assets/timer-GUTR9dAu.js","assets/workflow-BgT0wW83.js","assets/StatsPage-E-fXkkLD.js","assets/dollar-sign-Cj_Yhud4.js","assets/target-B40GQtrA.js","assets/AreaChart-DJpIJXxF.js","assets/SettingsPage-DCvPzv7P.js","assets/briefcase-Dau7xqMY.js","assets/cpu-BKWEtc8k.js","assets/link-2-MI-QCMh8.js","assets/locationSensorDefaults-DcLWzMwe.js","assets/scale-CD6XdXUk.js","assets/shield-bODVqOJd.js","assets/smartphone-DaDGaGLT.js","assets/OverlayFrame-fLmufrTC.js","assets/FinancePage-D-k9CqTS.js","assets/ProfilesPage-FzXKlAbc.js","assets/droplet-CqYXMF2u.js","assets/sparkles-DRqKNlhr.js","assets/MaintenancePage-B6wtSJnR.js","assets/ProjectsPage-CBeO6wA6.js","assets/ProjectDetailPage-Cg8wQL8j.js","assets/libraryFiles-B0B1SFfn.js","assets/FileManagerPage-BASV0fq8.js","assets/usePreviewFullscreen-ButueZqN.js","assets/LibraryTrashPage-zY9GRWm9.js","assets/CameraPage-D1WovNYe.js","assets/CamWallPage-BDGEzKQE.js","assets/StreamOverlayPage-H9AqKpdI.js","assets/StreamOverlayPage-CA9KpVK8.css","assets/ExternalLinkPage-BN4q7Gs-.js","assets/GroupEditPage-CMQ5Sk5q.js","assets/PrinterLocationsPage-Dj61FxW8.js","assets/InventoryPage-o24Ni0S2.js","assets/AdditionalSection-9uxxm13d.js","assets/AssignToAmsModal-dWQ_DHhy.js","assets/AmsUnitCard-CeSWF1rR.js","assets/spoolPaint-CrvpHqdD.js","assets/ModelSourcesPage-CI9pVpjC.js","assets/SystemInfoPage-J8sIDAyN.js","assets/LoginPage-DXBBHPDD.js","assets/ConnectAuthorizePage-CIbOgIV8.js","assets/SetupPage-D-ymjFl3.js","assets/NotificationsPage-DTBdRJe1.js","assets/GCodeViewerPage-BZpj3rht.js","assets/SpoolBuddyDashboard-0Mnwe1xw.js","assets/SpoolIcon-DE8TbEec.js","assets/SpoolBuddyAmsPage-BzUFeU61.js","assets/SpoolBuddySettingsPage-dHNHNIW3.js","assets/SpoolBuddyCalibrationPage-C9Vz9h1f.js","assets/SpoolBuddyWriteTagPage-CQovcCoW.js","assets/SpoolBuddyInventoryPage-FFmQ5AMP.js"])))=>i.map(i=>d[i]); import{i as e,t}from"./chunk-aKtaBQYM.js";import{C as n,D as r,E as i,_ as a,a as o,d as s,g as c,h as l,i as u,l as d,m as f,o as p,p as m,t as h,u as g,v as _,w as v,x as y,y as b}from"./client-DnySrlFv.js";import{t as x}from"./react-dom-B8Dg6xzp.js";import{A as S,C,D as w,N as T,S as E,_ as D,b as O,c as k,d as A,f as j,g as M,h as N,m as P,n as F,p as I,s as ee,t as te,u as ne,x as L}from"./QueryClientProvider-Ce8_sN3w.js";import{f as R,t as z}from"./useQuery-BBCjCezC.js";import{n as re,t as ie}from"./useMutation-B-Tr2hIP.js";import{t as B}from"./useQueries-Be6PMvSC.js";import{t as V}from"./createLucideIcon-DvBYJlWL.js";import{t as ae}from"./arrow-down-Cj0DZhNf.js";import{t as oe}from"./arrow-up-D-pfJ3WZ.js";import{t as se}from"./calendar-BLKPnWqV.js";import{t as ce}from"./check-Ck0cMLU4.js";import{a as le,i as H,n as ue,r as de,t as U}from"./info-ROUoQhJR.js";import{n as fe,r as pe,t as me}from"./ToastContext-BRX0SW3C.js";import{t as he}from"./loader-circle-BEmFtawu.js";import{t as ge}from"./triangle-alert-Dt_1FcBy.js";import{t as _e}from"./x-DR-Trv6U.js";import{i as ve,n as ye,t as be}from"./Card-Bzc64K35.js";import{t as xe}from"./Button-DDr6eAFy.js";import{_ as Se,d as Ce,f as we,g as Te,i as Ee,m as De,o as Oe,p as ke,r as Ae,v as je,y as Me}from"./date-G9KUauqz.js";import{n as Ne,r as Pe}from"./filamentSwatchHelpers-D3oXQSGk.js";(function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),e.crossOrigin===`use-credentials`?t.credentials=`include`:e.crossOrigin===`anonymous`?t.credentials=`omit`:t.credentials=`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();var Fe=t((e=>{function t(e,t){var n=e.length;e.push(t);a:for(;0>>1,a=e[r];if(0>>1;ri(c,n))li(u,c)?(e[r]=u,e[l]=n,r=l):(e[r]=c,e[s]=n,r=s);else if(li(u,n))e[r]=u,e[l]=n,r=l;else break a}}return t}function i(e,t){var n=e.sortIndex-t.sortIndex;return n===0?e.id-t.id:n}if(e.unstable_now=void 0,typeof performance==`object`&&typeof performance.now==`function`){var a=performance;e.unstable_now=function(){return a.now()}}else{var o=Date,s=o.now();e.unstable_now=function(){return o.now()-s}}var c=[],l=[],u=1,d=null,f=3,p=!1,m=!1,h=!1,g=!1,_=typeof setTimeout==`function`?setTimeout:null,v=typeof clearTimeout==`function`?clearTimeout:null,y=typeof setImmediate<`u`?setImmediate:null;function b(e){for(var i=n(l);i!==null;){if(i.callback===null)r(l);else if(i.startTime<=e)r(l),i.sortIndex=i.expirationTime,t(c,i);else break;i=n(l)}}function x(e){if(h=!1,b(e),!m)if(n(c)!==null)m=!0,S||(S=!0,O());else{var t=n(l);t!==null&&j(x,t.startTime-e)}}var S=!1,C=-1,w=5,T=-1;function E(){return g?!0:!(e.unstable_now()-Tt&&E());){var o=d.callback;if(typeof o==`function`){d.callback=null,f=d.priorityLevel;var s=o(d.expirationTime<=t);if(t=e.unstable_now(),typeof s==`function`){d.callback=s,b(t),i=!0;break b}d===n(c)&&r(c),b(t)}else r(c);d=n(c)}if(d!==null)i=!0;else{var u=n(l);u!==null&&j(x,u.startTime-t),i=!1}}break a}finally{d=null,f=a,p=!1}i=void 0}}finally{i?O():S=!1}}}var O;if(typeof y==`function`)O=function(){y(D)};else if(typeof MessageChannel<`u`){var k=new MessageChannel,A=k.port2;k.port1.onmessage=D,O=function(){A.postMessage(null)}}else O=function(){_(D,0)};function j(t,n){C=_(function(){t(e.unstable_now())},n)}e.unstable_IdlePriority=5,e.unstable_ImmediatePriority=1,e.unstable_LowPriority=4,e.unstable_NormalPriority=3,e.unstable_Profiling=null,e.unstable_UserBlockingPriority=2,e.unstable_cancelCallback=function(e){e.callback=null},e.unstable_forceFrameRate=function(e){0>e||125o?(r.sortIndex=a,t(l,r),n(c)===null&&r===n(l)&&(h?(v(C),C=-1):h=!0,j(x,a-o))):(r.sortIndex=s,t(c,r),m||p||(m=!0,S||(S=!0,O()))),r},e.unstable_shouldYield=E,e.unstable_wrapCallback=function(e){var t=f;return function(){var n=f;f=t;try{return e.apply(this,arguments)}finally{f=n}}}})),Ie=t(((e,t)=>{t.exports=Fe()})),Le=t((e=>{var t=Ie(),n=r(),i=x();function a(e){var t=`https://react.dev/errors/`+e;if(1ne||(e.current=te[ne],te[ne]=null,ne--)}function z(e,t){ne++,te[ne]=e.current,e.current=t}var re=L(null),ie=L(null),B=L(null),V=L(null);function ae(e,t){switch(z(B,t),z(ie,e),z(re,null),t.nodeType){case 9:case 11:e=(e=t.documentElement)&&(e=e.namespaceURI)?Vd(e):0;break;default:if(e=t.tagName,t=t.namespaceURI)t=Vd(t),e=Hd(t,e);else switch(e){case`svg`:e=1;break;case`math`:e=2;break;default:e=0}}R(re),z(re,e)}function oe(){R(re),R(ie),R(B)}function se(e){e.memoizedState!==null&&z(V,e);var t=re.current,n=Hd(t,e.type);t!==n&&(z(ie,e),z(re,n))}function ce(e){ie.current===e&&(R(re),R(ie)),V.current===e&&(R(V),Qf._currentValue=ee)}var le,H;function ue(e){if(le===void 0)try{throw Error()}catch(e){var t=e.stack.trim().match(/\n( *(at )?)/);le=t&&t[1]||``,H=-1)`:-1 to 2&&arguments[2]!==void 0&&arguments[2]?Object.assign({},this.getDefaultDiplay(),t):t||this.getDefaultDiplay())[e]||e}},{key:`getUpdatedInput`,value:function(e,t,n){var r=arguments.length>3&&arguments[3]!==void 0?arguments[3]:n,i=arguments.length>4&&arguments[4]!==void 0&&arguments[4],a=this.getOptions(),o=[n,r,i],s=t;return(e===`{bksp}`||e===`{backspace}`)&&s.length>0?s=this.removeAt.apply(this,[s].concat(o)):(e===`{delete}`||e===`{forwarddelete}`)&&s.length>0?s=this.removeForwardsAt.apply(this,[s].concat(o)):e===`{space}`?s=this.addStringAt.apply(this,[s,` `].concat(o)):e!==`{tab}`||typeof a.tabCharOnTab==`boolean`&&!1===a.tabCharOnTab?e!==`{enter}`&&e!==`{numpadenter}`||!a.newLineOnEnter?e.includes(`numpad`)&&Number.isInteger(Number(e[e.length-2]))?s=this.addStringAt.apply(this,[s,e[e.length-2]].concat(o)):e===`{numpaddivide}`?s=this.addStringAt.apply(this,[s,`/`].concat(o)):e===`{numpadmultiply}`?s=this.addStringAt.apply(this,[s,`*`].concat(o)):e===`{numpadsubtract}`?s=this.addStringAt.apply(this,[s,`-`].concat(o)):e===`{numpadadd}`?s=this.addStringAt.apply(this,[s,`+`].concat(o)):e===`{numpaddecimal}`?s=this.addStringAt.apply(this,[s,`.`].concat(o)):e===`{`||e===`}`?s=this.addStringAt.apply(this,[s,e].concat(o)):e.includes(`{`)||e.includes(`}`)||(s=this.addStringAt.apply(this,[s,e].concat(o))):s=this.addStringAt.apply(this,[s,` `].concat(o)):s=this.addStringAt.apply(this,[s,` `].concat(o)),a.debug&&console.log(`Input will be: `+s),s}},{key:`updateCaretPos`,value:function(e){var t=arguments.length>1&&arguments[1]!==void 0&&arguments[1],n=this.updateCaretPosAction(e,t);this.dispatch((function(e){e.setCaretPosition(n)}))}},{key:`updateCaretPosAction`,value:function(e){var t=arguments.length>1&&arguments[1]!==void 0&&arguments[1],n=this.getOptions(),r=this.getCaretPosition();return r!=null&&(t?r>0&&(r-=e):r+=e),n.debug&&console.log(`Caret at:`,r),r}},{key:`addStringAt`,value:function(e,t){var n,r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:e.length,i=arguments.length>3&&arguments[3]!==void 0?arguments[3]:e.length,a=arguments.length>4&&arguments[4]!==void 0&&arguments[4];return r||r===0?(n=[e.slice(0,r),t,e.slice(i)].join(``),this.isMaxLengthReached()||a&&this.updateCaretPos(t.length)):n=e+t,n}},{key:`removeAt`,value:function(e){var t,n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:e.length,r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:e.length,i=arguments.length>3&&arguments[3]!==void 0&&arguments[3];if(n===0&&r===0)return e;if(n===r){var a=/([\uD800-\uDBFF][\uDC00-\uDFFF])/g;n&&n>=0?e.substring(n-2,n).match(a)?(t=e.substr(0,n-2)+e.substr(n),i&&this.updateCaretPos(2,!0)):(t=e.substr(0,n-1)+e.substr(n),i&&this.updateCaretPos(1,!0)):e.slice(-2).match(a)?(t=e.slice(0,-2),i&&this.updateCaretPos(2,!0)):(t=e.slice(0,-1),i&&this.updateCaretPos(1,!0))}else t=e.slice(0,n)+e.slice(r),i&&this.dispatch((function(e){e.setCaretPosition(n)}));return t}},{key:`removeForwardsAt`,value:function(e){var t,n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:e.length,r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:e.length,i=arguments.length>3&&arguments[3]!==void 0&&arguments[3];return e!=null&&e.length&&n!==null?(n===r?t=e.substring(n,n+2).match(/([\uD800-\uDBFF][\uDC00-\uDFFF])/g)?e.substr(0,n)+e.substr(n+2):e.substr(0,n)+e.substr(n+1):(t=e.slice(0,n)+e.slice(r),i&&this.dispatch((function(e){e.setCaretPosition(n)}))),t):e}},{key:`handleMaxLength`,value:function(e,t){var n=this.getOptions(),r=n.maxLength,i=e[n.inputName||`default`],a=t.length-1>=r;if(t.length<=i.length)return!1;if(Number.isInteger(r))return n.debug&&console.log(`maxLength (num) reached:`,a),a?(this.maxLengthReached=!0,!0):(this.maxLengthReached=!1,!1);if(s(r)===`object`){var o=t.length-1>=r[n.inputName||`default`];return n.debug&&console.log(`maxLength (obj) reached:`,o),o?(this.maxLengthReached=!0,!0):(this.maxLengthReached=!1,!1)}}},{key:`isMaxLengthReached`,value:function(){return!!this.maxLengthReached}},{key:`isTouchDevice`,value:function(){return`ontouchstart`in window||navigator.maxTouchPoints}},{key:`pointerEventsSupported`,value:function(){return!!window.PointerEvent}},{key:`camelCase`,value:function(e){return e?e.toLowerCase().trim().split(/[.\-_\s]/g).reduce((function(e,t){return t.length?e+t[0].toUpperCase()+t.slice(1):e})):``}},{key:`chunkArray`,value:function(e,t){return i(Array(Math.ceil(e.length/t))).map((function(n,r){return e.slice(t*r,t+t*r)}))}},{key:`escapeRegex`,value:function(e){return e.replace(/[-\/\\^$*+?.()|[\]{}]/g,`\\$&`)}},{key:`getRtlOffset`,value:function(e,t){var n=e,r=t.indexOf(`‫`);return r=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw TypeError(`Invalid attempt to iterate non-iterable instance. In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var o,s=!0,c=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return s=e.done,e},e:function(e){c=!0,o=e},f:function(){try{s||n.return==null||n.return()}finally{if(c)throw o}}}}(Object.getOwnPropertyNames(e.prototype));try{for(r.s();!(n=r.n()).done;){var i=n.value;i===`constructor`||i===`bindMethods`||(t[i]=t[i].bind(t))}}catch(e){r.e(e)}finally{r.f()}}}],t&&c(e.prototype,t),n&&c(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,n}();l(d,`noop`,(function(){}));var f=d;function p(e){return p=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},p(e)}function m(e,t){for(var n=0;n1?t?.toLowerCase():t}},{key:`keyCodeToKey`,value:function(e){return{8:`Backspace`,9:`Tab`,13:`Enter`,16:`Shift`,17:`Ctrl`,18:`Alt`,19:`Pause`,20:`CapsLock`,27:`Esc`,32:`Space`,33:`PageUp`,34:`PageDown`,35:`End`,36:`Home`,37:`ArrowLeft`,38:`ArrowUp`,39:`ArrowRight`,40:`ArrowDown`,45:`Insert`,46:`Delete`,48:`0`,49:`1`,50:`2`,51:`3`,52:`4`,53:`5`,54:`6`,55:`7`,56:`8`,57:`9`,65:`A`,66:`B`,67:`C`,68:`D`,69:`E`,70:`F`,71:`G`,72:`H`,73:`I`,74:`J`,75:`K`,76:`L`,77:`M`,78:`N`,79:`O`,80:`P`,81:`Q`,82:`R`,83:`S`,84:`T`,85:`U`,86:`V`,87:`W`,88:`X`,89:`Y`,90:`Z`,91:`Meta`,96:`Numpad0`,97:`Numpad1`,98:`Numpad2`,99:`Numpad3`,100:`Numpad4`,101:`Numpad5`,102:`Numpad6`,103:`Numpad7`,104:`Numpad8`,105:`Numpad9`,106:`NumpadMultiply`,107:`NumpadAdd`,109:`NumpadSubtract`,110:`NumpadDecimal`,111:`NumpadDivide`,112:`F1`,113:`F2`,114:`F3`,115:`F4`,116:`F5`,117:`F6`,118:`F7`,119:`F8`,120:`F9`,121:`F10`,122:`F11`,123:`F12`,144:`NumLock`,145:`ScrollLock`,186:`;`,187:`=`,188:`,`,189:`-`,190:`.`,191:`/`,192:"`",219:`[`,220:`\\`,221:`]`,222:`'`}[e]||``}}],t&&m(e.prototype,t),n&&m(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,n}();function v(e){return v=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},v(e)}function y(e,t){for(var n=0;n0&&arguments[0]!==void 0?arguments[0]:r())},c.appendChild(t)}));var l=a>0,u=document.createElement(`div`);u.classList.add(`hg-candidate-box-prev`),l&&u.classList.add(`hg-candidate-box-btn-active`);var d=function(){l&&n.renderPage({candidateListPages:r,targetElement:i,pageIndex:a-1,nbPages:o,onItemSelected:s})};this.options.useTouchEvents?u.ontouchstart=d:u.onclick=d,this.candidateBoxElement.appendChild(u),this.candidateBoxElement.appendChild(c);var f=ae.length)&&(t=e.length);for(var n=0,r=Array(t);n1&&arguments[1]!==void 0?arguments[1]:e;this.caretPosition=e,this.caretPositionEnd=t}},{key:`getInputCandidates`,value:function(e){var t=this,n=this.options,r=n.layoutCandidates,i=n.layoutCandidatesCaseSensitiveMatch;if(!r||T(r)!==`object`)return{};var a=Object.keys(r).filter((function(n){var r=e.substring(0,t.getCaretPositionEnd()||0)||e,a=RegExp(`${t.utilities.escapeRegex(n)}\$`,i?`g`:`gi`);return!!C(r.matchAll(a)).length}));if(a.length>1){var o=a.sort((function(e,t){return t.length-e.length}))[0];return{candidateKey:o,candidateValue:r[o]}}if(a.length){var s=a[0];return{candidateKey:s,candidateValue:r[s]}}return{}}},{key:`showCandidatesBox`,value:function(e,t,n){var r=this;this.candidateBox&&this.candidateBox.show({candidateValue:t,targetElement:n,onSelect:function(t,n){var i=r.options,a=i.layoutCandidatesCaseSensitiveMatch,o=i.disableCandidateNormalization,s=i.enableLayoutCandidatesKeyPress,c=t;o||(c=t.normalize(`NFD`)),typeof r.options.beforeInputUpdate==`function`&&r.options.beforeInputUpdate(r);var l=r.getInput(r.options.inputName,!0),u=r.getCaretPositionEnd()||0,d=l.substring(0,u||0)||l,f=RegExp(`${r.utilities.escapeRegex(e)}\$`,a?`g`:`gi`),p=d.replace(f,c),m=l.replace(d,p),h=p.length-d.length,g=(u||l.length)+h;g<0&&(g=0),r.setInput(m,r.options.inputName,!0),r.setCaretPosition(g),s&&typeof r.options.onKeyPress==`function`&&r.options.onKeyPress(t,n),typeof r.options.onChange==`function`&&r.options.onChange(r.getInput(r.options.inputName,!0),n),typeof r.options.onChangeAll==`function`&&r.options.onChangeAll(r.getAllInputs(),n)}})}},{key:`handleButtonClicked`,value:function(e,t){var n=this.options,r=n.inputName,i=r===void 0?this.defaultName:r,a=n.debug;if(e!==`{//}`){this.input[i]||(this.input[i]=``),typeof this.options.beforeInputUpdate==`function`&&this.options.beforeInputUpdate(this);var o=this.utilities.getUpdatedInput(e,this.input[i],this.caretPosition,this.caretPositionEnd);if(this.utilities.isStandardButton(e)&&this.activeInputElement&&this.input[i]&&this.input[i]===o&&this.caretPosition===0&&this.caretPositionEnd===o.length)return this.setInput(``,this.options.inputName,!0),this.setCaretPosition(0),this.activeInputElement.value=``,this.activeInputElement.setSelectionRange(0,0),void this.handleButtonClicked(e,t);if(typeof this.options.onKeyPress==`function`&&this.options.onKeyPress(e,t),this.input[i]!==o&&(!this.options.inputPattern||this.options.inputPattern&&this.inputPatternIsValid(o))){if(this.options.maxLength&&this.utilities.handleMaxLength(this.input,o))return;var s=this.utilities.getUpdatedInput(e,this.input[i],this.caretPosition,this.caretPositionEnd,!0);if(this.setInput(s,this.options.inputName,!0),a&&console.log(`Input changed:`,this.getAllInputs()),this.options.debug&&console.log(`Caret at: `,this.getCaretPosition(),this.getCaretPositionEnd(),`(${this.keyboardDOMClass})`,t?.type),this.options.syncInstanceInputs&&this.syncInstanceInputs(),typeof this.options.onChange==`function`&&this.options.onChange(this.getInput(this.options.inputName,!0),t),typeof this.options.onChangeAll==`function`&&this.options.onChangeAll(this.getAllInputs(),t),t!=null&&t.target&&this.options.enableLayoutCandidates){var c,l=this.getInputCandidates(o),u=l.candidateKey,d=l.candidateValue;u&&d?this.showCandidatesBox(u,d,this.keyboardDOM):(c=this.candidateBox)==null||c.destroy()}}this.caretPositionEnd&&this.caretPosition!==this.caretPositionEnd&&(this.setCaretPosition(this.caretPositionEnd,this.caretPositionEnd),this.activeInputElement&&this.activeInputElement.setSelectionRange(this.caretPositionEnd,this.caretPositionEnd),this.options.debug&&console.log(`Caret position aligned`,this.caretPosition)),a&&console.log(`Key pressed:`,e)}}},{key:`getMouseHold`,value:function(){return this.isMouseHold}},{key:`setMouseHold`,value:function(e){this.options.syncInstanceInputs?this.dispatch((function(t){t.isMouseHold=e})):this.isMouseHold=e}},{key:`handleButtonMouseDown`,value:function(e,t){var n=this;t&&(this.options.preventMouseDownDefault&&t.preventDefault(),this.options.stopMouseDownPropagation&&t.stopPropagation(),t.target.classList.add(this.activeButtonClass)),this.holdInteractionTimeout&&clearTimeout(this.holdInteractionTimeout),this.holdTimeout&&clearTimeout(this.holdTimeout),this.setMouseHold(!0),this.options.disableButtonHold||(this.holdTimeout=window.setTimeout((function(){(n.getMouseHold()&&(!e.includes(`{`)&&!e.includes(`}`)||e===`{delete}`||e===`{backspace}`||e===`{bksp}`||e===`{space}`||e===`{tab}`)||e===`{arrowright}`||e===`{arrowleft}`||e===`{arrowup}`||e===`{arrowdown}`)&&(n.options.debug&&console.log(`Button held:`,e),n.handleButtonHold(e)),clearTimeout(n.holdTimeout)}),500))}},{key:`handleButtonMouseUp`,value:function(e,t){var n=this;t&&(this.options.preventMouseUpDefault&&t.preventDefault&&t.preventDefault(),this.options.stopMouseUpPropagation&&t.stopPropagation&&t.stopPropagation(),!(t.target===this.keyboardDOM||t.target&&this.keyboardDOM.contains(t.target)||this.candidateBox&&this.candidateBox.candidateBoxElement&&(t.target===this.candidateBox.candidateBoxElement||t.target&&this.candidateBox.candidateBoxElement.contains(t.target)))&&this.candidateBox&&this.candidateBox.destroy()),this.recurseButtons((function(e){e.classList.remove(n.activeButtonClass)})),this.setMouseHold(!1),this.holdInteractionTimeout&&clearTimeout(this.holdInteractionTimeout),e&&typeof this.options.onKeyReleased==`function`&&this.options.onKeyReleased(e,t)}},{key:`handleKeyboardContainerMouseDown`,value:function(e){this.options.preventMouseDownDefault&&e.preventDefault()}},{key:`handleButtonHold`,value:function(e){var t=this;this.holdInteractionTimeout&&clearTimeout(this.holdInteractionTimeout),this.holdInteractionTimeout=window.setTimeout((function(){t.getMouseHold()?(t.handleButtonClicked(e),t.handleButtonHold(e)):clearTimeout(t.holdInteractionTimeout)}),100)}},{key:`syncInstanceInputs`,value:function(){var e=this;this.dispatch((function(t){t.replaceInput(e.input),t.setCaretPosition(e.caretPosition,e.caretPositionEnd)}))}},{key:`clearInput`,value:function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.options.inputName||this.defaultName;this.input[e]=``,this.setCaretPosition(0),this.options.syncInstanceInputs&&this.syncInstanceInputs()}},{key:`getInput`,value:function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.options.inputName||this.defaultName,t=arguments.length>1&&arguments[1]!==void 0&&arguments[1];return this.options.syncInstanceInputs&&!t&&this.syncInstanceInputs(),this.options.rtl?`‫`+this.input[e].replace(`‫`,``).replace(`‬`,``)+`‬`:this.input[e]}},{key:`getAllInputs`,value:function(){var e=this,t={};return Object.keys(this.input).forEach((function(n){t[n]=e.getInput(n,!0)})),t}},{key:`setInput`,value:function(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:this.options.inputName||this.defaultName,n=arguments.length>2?arguments[2]:void 0;this.input[t]=e,!n&&this.options.syncInstanceInputs&&this.syncInstanceInputs()}},{key:`replaceInput`,value:function(e){this.input=e}},{key:`setOptions`,value:function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},t=this.changedOptions(e);this.options=Object.assign(this.options,e),t.length&&(this.options.debug&&console.log(`changedOptions`,t),this.onSetOptions(t),this.render())}},{key:`changedOptions`,value:function(e){var t=this;return Object.keys(e).filter((function(n){return JSON.stringify(e[n])!==JSON.stringify(t.options[n])}))}},{key:`onSetOptions`,value:function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];e.includes(`layoutName`)&&this.candidateBox&&this.candidateBox.destroy(),(e.includes(`layoutCandidatesPageSize`)||e.includes(`layoutCandidates`))&&this.candidateBox&&(this.candidateBox.destroy(),this.candidateBox=new S({utilities:this.utilities,options:this.options}))}},{key:`resetRows`,value:function(){this.keyboardRowsDOM&&this.keyboardRowsDOM.remove(),this.keyboardDOM.className=this.keyboardDOMClass,this.keyboardDOM.setAttribute(`data-skInstance`,this.currentInstanceName),this.buttonElements={}}},{key:`dispatch`,value:function(e){if(!window.SimpleKeyboardInstances)throw console.warn(`SimpleKeyboardInstances is not defined. Dispatch cannot be called.`),Error(`INSTANCES_VAR_ERROR`);return Object.keys(window.SimpleKeyboardInstances).forEach((function(t){e(window.SimpleKeyboardInstances[t],t)}))}},{key:`addButtonTheme`,value:function(e,t){var n=this;t&&e&&(e.split(` `).forEach((function(r){t.split(` `).forEach((function(t){n.options.buttonTheme||(n.options.buttonTheme=[]);var i=!1;n.options.buttonTheme.map((function(e){if(e!=null&&e.class.split(` `).includes(t)){i=!0;var n=e.buttons.split(` `);n.includes(r)||(i=!0,n.push(r),e.buttons=n.join(` `))}return e})),i||n.options.buttonTheme.push({class:t,buttons:e})}))})),this.render())}},{key:`removeButtonTheme`,value:function(e,t){var n=this;if(!e&&!t)return this.options.buttonTheme=[],void this.render();e&&Array.isArray(this.options.buttonTheme)&&this.options.buttonTheme.length&&(e.split(` `).forEach((function(e){var r;(r=n.options)==null||(r=r.buttonTheme)==null||r.map((function(r,i){if(r&&t&&t.includes(r.class)||!t){var a,o=r?.buttons.split(` `).filter((function(t){return t!==e}));r&&o!=null&&o.length?r.buttons=o.join(` `):((a=n.options.buttonTheme)==null||a.splice(i,1),r=null)}return r}))})),this.render())}},{key:`getButtonElement`,value:function(e){var t,n=this.buttonElements[e];return n&&(t=n.length>1?n:n[0]),t}},{key:`inputPatternIsValid`,value:function(e){var t,n=this.options.inputPattern;if((t=n instanceof RegExp?n:n[this.options.inputName||this.defaultName])&&e){var r=t.test(e);return this.options.debug&&console.log(`inputPattern ("${t}"): ${r?`passed`:`did not pass!`}`),r}return!0}},{key:`setEventListeners`,value:function(){if(this.isFirstKeyboardInstance||!this.allKeyboardInstances){this.options.debug&&console.log(`Caret handling started (${this.keyboardDOMClass})`);var e=this.options.physicalKeyboardHighlightPreventDefault,t=e!==void 0&&e;document.addEventListener(`keyup`,this.handleKeyUp,t),document.addEventListener(`keydown`,this.handleKeyDown,t),document.addEventListener(`mouseup`,this.handleMouseUp),document.addEventListener(`touchend`,this.handleTouchEnd),this.options.updateCaretOnSelectionChange&&document.addEventListener(`selectionchange`,this.handleSelectionChange),document.addEventListener(`select`,this.handleSelect)}}},{key:`handleKeyUp`,value:function(e){this.caretEventHandler(e),this.options.physicalKeyboardHighlight&&this.physicalKeyboard.handleHighlightKeyUp(e)}},{key:`handleKeyDown`,value:function(e){this.options.physicalKeyboardHighlight&&this.physicalKeyboard.handleHighlightKeyDown(e)}},{key:`handleMouseUp`,value:function(e){this.caretEventHandler(e)}},{key:`handleTouchEnd`,value:function(e){this.caretEventHandler(e)}},{key:`handleSelect`,value:function(e){this.caretEventHandler(e)}},{key:`handleSelectionChange`,value:function(e){navigator.userAgent.includes(`Firefox`)||this.caretEventHandler(e)}},{key:`caretEventHandler`,value:function(e){var t,n=this;e.target.tagName&&(t=e.target.tagName.toLowerCase()),this.dispatch((function(r){var i=e.target===r.keyboardDOM||e.target&&r.keyboardDOM.contains(e.target);if(n.options.syncInstanceInputs&&Array.isArray(e.path)&&(i=e.path.some((function(e){var t;return e==null||(t=e.hasAttribute)==null?void 0:t.call(e,`data-skInstance`)}))),(t===`textarea`||t===`input`&&[`text`,`search`,`url`,`tel`,`password`].includes(e.target.type))&&!r.options.disableCaretPositioning){var a=e.target.selectionStart,o=e.target.selectionEnd;r.options.rtl&&(a=r.utilities.getRtlOffset(a,r.getInput()),o=r.utilities.getRtlOffset(o,r.getInput())),r.setCaretPosition(a,o),r.activeInputElement=e.target,r.options.debug&&console.log(`Caret at: `,r.getCaretPosition(),r.getCaretPositionEnd(),e&&e.target.tagName.toLowerCase(),`(${r.keyboardDOMClass})`,e?.type)}else !r.options.disableCaretPositioning&&i||e?.type===`selectionchange`||(r.setCaretPosition(null),r.activeInputElement=null,r.options.debug&&console.log(`Caret position reset due to "${e?.type}" event`,e))}))}},{key:`recurseButtons`,value:function(e){var t=this;e&&Object.keys(this.buttonElements).forEach((function(n){return t.buttonElements[n].forEach(e)}))}},{key:`destroy`,value:function(){this.options.debug&&console.log(`Destroying simple-keyboard instance: ${this.currentInstanceName}`);var e=this.options.physicalKeyboardHighlightPreventDefault,t=e!==void 0&&e;document.removeEventListener(`keyup`,this.handleKeyUp,t),document.removeEventListener(`keydown`,this.handleKeyDown,t),document.removeEventListener(`mouseup`,this.handleMouseUp),document.removeEventListener(`touchend`,this.handleTouchEnd),document.removeEventListener(`select`,this.handleSelect),this.options.updateCaretOnSelectionChange&&document.removeEventListener(`selectionchange`,this.handleSelectionChange),document.onpointerup=null,document.ontouchend=null,document.ontouchcancel=null,document.onmouseup=null,this.recurseButtons((function(e){e&&=(e.onpointerdown=null,e.onpointerup=null,e.onpointercancel=null,e.ontouchstart=null,e.ontouchend=null,e.ontouchcancel=null,e.onclick=null,e.onmousedown=null,e.onmouseup=null,e.remove(),null)})),this.keyboardDOM.onpointerdown=null,this.keyboardDOM.ontouchstart=null,this.keyboardDOM.onmousedown=null,this.resetRows(),this.candidateBox&&=(this.candidateBox.destroy(),null),this.activeInputElement=null,this.keyboardDOM.removeAttribute(`data-skInstance`),this.keyboardDOM.innerHTML=``,window.SimpleKeyboardInstances[this.currentInstanceName]=null,delete window.SimpleKeyboardInstances[this.currentInstanceName],this.initialized=!1}},{key:`getButtonThemeClasses`,value:function(e){var t=this.options.buttonTheme,n=[];return Array.isArray(t)&&t.forEach((function(t){if(t&&t.class&&typeof t.class==`string`&&t.buttons&&typeof t.buttons==`string`){var r=t.class.split(` `);t.buttons.split(` `).includes(e)&&(n=[].concat(C(n),C(r)))}else console.warn(`Incorrect "buttonTheme". Please check the documentation.`,t)})),n}},{key:`setDOMButtonAttributes`,value:function(e,t){var n=this.options.buttonAttributes;Array.isArray(n)&&n.forEach((function(n){n.attribute&&typeof n.attribute==`string`&&n.value&&typeof n.value==`string`?n.buttons&&typeof n.buttons==`string`?n.buttons.split(` `).includes(e)&&t(n.attribute,n.value):t(n.attribute,n.value):console.warn(`Incorrect "buttonAttributes". Please check the documentation.`,n)}))}},{key:`onTouchDeviceDetected`,value:function(){this.processAutoTouchEvents(),this.disableContextualWindow()}},{key:`disableContextualWindow`,value:function(){window.oncontextmenu=function(e){var t;if((t=e.target.classList)!=null&&t.contains(`hg-button`))return e.preventDefault(),e.stopPropagation(),!1}}},{key:`processAutoTouchEvents`,value:function(){this.options.autoUseTouchEvents&&(this.options.useTouchEvents=!0,this.options.debug&&console.log(`autoUseTouchEvents: Touch device detected, useTouchEvents enabled.`))}},{key:`onInit`,value:function(){this.options.debug&&console.log(`${this.keyboardDOMClass} Initialized`),this.setEventListeners(),typeof this.options.onInit==`function`&&this.options.onInit(this)}},{key:`beforeFirstRender`,value:function(){this.utilities.isTouchDevice()&&this.onTouchDeviceDetected(),typeof this.options.beforeFirstRender==`function`&&this.options.beforeFirstRender(this),this.isFirstKeyboardInstance&&this.utilities.pointerEventsSupported()&&!this.options.useTouchEvents&&!this.options.useMouseEvents&&this.options.debug&&console.log(`Using PointerEvents as it is supported by this browser`),this.options.useTouchEvents&&this.options.debug&&console.log(`useTouchEvents has been enabled. Only touch events will be used.`)}},{key:`beforeRender`,value:function(){typeof this.options.beforeRender==`function`&&this.options.beforeRender(this)}},{key:`onRender`,value:function(){typeof this.options.onRender==`function`&&this.options.onRender(this)}},{key:`onModulesLoaded`,value:function(){typeof this.options.onModulesLoaded==`function`&&this.options.onModulesLoaded(this)}},{key:`loadModules`,value:function(){var e=this;Array.isArray(this.options.modules)&&(this.options.modules.forEach((function(t){var n=e.utilities.isConstructor(t)?new t(e):t(e);n.init&&n.init(e)})),this.keyboardPluginClasses=`modules-loaded`,this.render(),this.onModulesLoaded())}},{key:`getModuleProp`,value:function(e,t){return!!this.modules[e]&&this.modules[e][t]}},{key:`getModulesList`,value:function(){return Object.keys(this.modules)}},{key:`parseRowDOMContainers`,value:function(e,t,n,r){var i=this,a=Array.from(e.children),o=0;return a.length&&n.forEach((function(n,s){var c=r[s];if(!(c&&c>n))return!1;var l=n-o,u=c-o,d=document.createElement(`div`);d.className+=`hg-button-container`;var f=`${i.options.layoutName}-r${t}c${s}`;d.setAttribute(`data-skUID`,f);var p=a.splice(l,u-l+1);o+=u-l,p.forEach((function(e){return d.appendChild(e)})),a.splice(l,0,d),e.innerHTML=``,a.forEach((function(t){return e.appendChild(t)})),i.options.debug&&console.log(`rowDOMContainer`,p,l,u,o+1)})),e}},{key:`render`,value:function(){var e=this;this.resetRows(),this.initialized||this.beforeFirstRender(),this.beforeRender();var t=`hg-layout-${this.options.layoutName}`,n=this.options.layout||{default:["` 1 2 3 4 5 6 7 8 9 0 - = {bksp}",`{tab} q w e r t y u i o p [ ] \\`,`{lock} a s d f g h j k l ; ' {enter}`,`{shift} z x c v b n m , . / {shift}`,`.com @ {space}`],shift:[`~ ! @ # $ % ^ & * ( ) _ + {bksp}`,`{tab} Q W E R T Y U I O P { } |`,`{lock} A S D F G H J K L : " {enter}`,`{shift} Z X C V B N M < > ? {shift}`,`.com @ {space}`]},r=this.options.useTouchEvents||!1,i=r?`hg-touch-events`:``,a=this.options.useMouseEvents||!1,o=this.options.disableRowButtonContainers;this.keyboardDOM.className=this.getKeyboardClassString(this.options.theme,t,this.keyboardPluginClasses,i),this.keyboardDOM.setAttribute(`data-skInstance`,this.currentInstanceName),this.keyboardRowsDOM=document.createElement(`div`),this.keyboardRowsDOM.className=`hg-rows`,n[this.options.layoutName||this.defaultName].forEach((function(t,n){var i=t.split(` `);e.options.excludeFromLayout&&e.options.excludeFromLayout[e.options.layoutName||e.defaultName]&&(i=i.filter((function(t){return e.options.excludeFromLayout&&!e.options.excludeFromLayout[e.options.layoutName||e.defaultName].includes(t)})));var s=document.createElement(`div`);s.className+=`hg-row`;var c=[],l=[];i.forEach((function(t,i){var u,d=!o&&typeof t==`string`&&t.length>1&&t.indexOf(`[`)===0,f=!o&&typeof t==`string`&&t.length>1&&t.indexOf(`]`)===t.length-1;d&&(c.push(i),t=t.replace(/\[/g,``)),f&&(l.push(i),t=t.replace(/\]/g,``));var p=e.utilities.getButtonClass(t),m=e.utilities.getButtonDisplayName(t,e.options.display,e.options.mergeDisplay),h=e.options.useButtonTag?`button`:`div`,g=document.createElement(h);g.className+=`hg-button ${p}`,(u=g.classList).add.apply(u,C(e.getButtonThemeClasses(t))),e.setDOMButtonAttributes(t,(function(e,t){g.setAttribute(e,t)})),e.activeButtonClass=`hg-activeButton`,!e.utilities.pointerEventsSupported()||r||a?r?(g.ontouchstart=function(n){e.handleButtonClicked(t,n),e.handleButtonMouseDown(t,n)},g.ontouchend=function(n){e.handleButtonMouseUp(t,n)},g.ontouchcancel=function(n){e.handleButtonMouseUp(t,n)}):(g.onclick=function(n){e.setMouseHold(!1),typeof e.options.onKeyReleased==`function`||e.options.useMouseEvents&&e.options.clickOnMouseDown||e.handleButtonClicked(t,n)},g.onmousedown=function(n){(typeof e.options.onKeyReleased==`function`||e.options.useMouseEvents&&e.options.clickOnMouseDown)&&!e.isMouseHold&&e.handleButtonClicked(t,n),e.handleButtonMouseDown(t,n)},g.onmouseup=function(n){e.handleButtonMouseUp(t,n)}):(g.onpointerdown=function(n){e.handleButtonClicked(t,n),e.handleButtonMouseDown(t,n)},g.onpointerup=function(n){e.handleButtonMouseUp(t,n)},g.onpointercancel=function(n){e.handleButtonMouseUp(t,n)}),g.setAttribute(`data-skBtn`,t);var _=`${e.options.layoutName}-r${n}b${i}`;g.setAttribute(`data-skBtnUID`,_);var v=document.createElement(`span`);v.innerHTML=m,g.appendChild(v),e.buttonElements[t]||(e.buttonElements[t]=[]),e.buttonElements[t].push(g),s.appendChild(g)})),s=e.parseRowDOMContainers(s,n,c,l),e.keyboardRowsDOM.appendChild(s)})),this.keyboardDOM.appendChild(this.keyboardRowsDOM),this.onRender(),this.initialized||(this.initialized=!0,!this.utilities.pointerEventsSupported()||r||a?r?(document.ontouchend=function(t){return e.handleButtonMouseUp(void 0,t)},document.ontouchcancel=function(t){return e.handleButtonMouseUp(void 0,t)},this.keyboardDOM.ontouchstart=function(t){return e.handleKeyboardContainerMouseDown(t)}):r||(document.onmouseup=function(t){return e.handleButtonMouseUp(void 0,t)},this.keyboardDOM.onmousedown=function(t){return e.handleKeyboardContainerMouseDown(t)}):(document.onpointerup=function(t){return e.handleButtonMouseUp(void 0,t)},this.keyboardDOM.onpointerdown=function(t){return e.handleKeyboardContainerMouseDown(t)}),this.onInit())}}],t&&D(e.prototype,t),n&&D(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,n}(),j=A;return r}()},442:function(t){t.exports=e}},n={};function r(e){var i=n[e];if(i!==void 0)return i.exports;var a=n[e]={exports:{}};return t[e].call(a.exports,a,a.exports,r),a.exports}r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,{a:t}),t},r.d=function(e,t){for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.r=function(e){typeof Symbol<`u`&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:`Module`}),Object.defineProperty(e,"__esModule",{value:!0})};var i={};return function(){r.r(i),r.d(i,{KeyboardReact:function(){return u},default:function(){return d}}),r(981);var e=r(442),t=r(548),n=r.n(t);function a(e){return a=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},a(e)}function o(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function s(e){for(var t=1;t{e?.(t)},[t,e]);let d=(0,W.useCallback)(e=>{if(a.current)return;let t=e.target;if(!t.closest(`[data-vkb="false"]`)){if(t instanceof HTMLInputElement){if(!Qd.has(t.type))return}else if(!(t instanceof HTMLTextAreaElement))return;c.current=t,n(!0),s(`default`),l.current?.setInput?.(c.current.value),setTimeout(()=>{(t.closest(`.bg-zinc-800, .rounded-lg, [data-vkb-group]`)??t).scrollIntoView({behavior:`smooth`,block:`nearest`})},100)}},[]),f=(0,W.useCallback)(()=>{setTimeout(()=>{let e=document.activeElement;e&&(u.current?.contains(e)||e===c.current)||(n(!1),c.current=null)},150)},[]);(0,W.useEffect)(()=>(document.addEventListener(`focusin`,d),document.addEventListener(`focusout`,f),()=>{document.removeEventListener(`focusin`,d),document.removeEventListener(`focusout`,f)}),[d,f]);let p=(0,W.useCallback)(()=>{a.current=!0,i(!0),c.current?.blur(),c.current=null,setTimeout(()=>{n(!1),i(!1),a.current=!1},400)},[]),m=(0,W.useCallback)(e=>{let t=c.current;if(t){if(e===`{shift}`){s(e=>e==="default"?`shift`:`default`);return}if(e===`{lock}`){s(e=>e==="default"?`shift`:`default`);return}if(e===`{close}`){p();return}e===`{bksp}`?$d(t,t.value.slice(0,-1)):e===`{space}`?$d(t,t.value+` `):($d(t,t.value+e),o===`shift`&&s(`default`)),t.focus(),l.current?.setInput?.(t.value)}},[o,p]);return t?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`div`,{className:`fixed inset-0 z-[9998] bg-transparent`,onMouseDown:e=>{e.preventDefault(),e.stopPropagation(),r||p()},onTouchStart:e=>{e.preventDefault(),e.stopPropagation(),r||p()},onClick:e=>{e.preventDefault(),e.stopPropagation()}}),!r&&(0,Z.jsx)(`div`,{ref:u,className:`relative z-[9999] shrink-0`,onMouseDown:e=>e.preventDefault(),onTouchStart:e=>{e.target.closest(`.hg-button`)||e.preventDefault()},children:(0,Z.jsx)(Zd,{keyboardRef:e=>{l.current=e},layoutName:o,onKeyPress:m,theme:`simple-keyboard vkb-theme`,layout:{default:[`1 2 3 4 5 6 7 8 9 0 {bksp}`,`q w e r t y u i o p`,`{lock} a s d f g h j k l`,`{shift} z x c v b n m . @`,`{space} {close}`],shift:[`! @ # $ % ^ & * ( ) {bksp}`,`Q W E R T Y U I O P`,`{lock} A S D F G H J K L`,`{shift} Z X C V B N M , _`,`{space} {close}`]},display:{"{bksp}":`⌫`,"{close}":`✕ Close`,"{shift}":`⇧`,"{lock}":`⇪`,"{space}":` `}})})]}):null}function tf(){dc();let[e,t]=(0,W.useState)(null),[n,r]=(0,W.useState)(null),[i,a]=(0,W.useState)(100),{i18n:s}=v(),c=Xr(),l=qr(),u=qd(),{setViewportSuppressed:d}=fe();(0,W.useEffect)(()=>(d(!0),()=>d(!1)),[d]);let{data:f}=z({queryKey:[`settings`],queryFn:o.getSettings});(0,W.useEffect)(()=>{f?.language&&f.language!==s.language&&s.changeLanguage(f.language)},[f?.language,s]);let{data:p=[]}=z({queryKey:[`spoolbuddy-devices`],queryFn:()=>_.getDevices(),refetchInterval:3e4}),m=p[0],h=u.deviceOnline||!!m?.online,g=(0,W.useMemo)(()=>({...u,deviceOnline:h}),[u,h]),y=(0,W.useRef)(!1);(0,W.useEffect)(()=>{m&&!y.current&&(a(m.display_brightness),y.current=!0)},[m]),(0,W.useEffect)(()=>{let e=document.documentElement,t=e.classList.contains(`dark`);return e.classList.add(`dark`),()=>{t||e.classList.remove(`dark`)}},[]);let{data:b}=z({queryKey:[`spoolbuddy-update-check`,m?.device_id],queryFn:()=>m?_.checkDaemonUpdate(m.device_id):Promise.resolve(null),enabled:!!m,refetchInterval:300*1e3,staleTime:0}),x=(0,W.useRef)(null);(0,W.useEffect)(()=>{if(!h){let e=`SpoolBuddy device disconnected`;r({type:`warning`,message:e}),x.current=e}else if(b?.update_available&&b.latest_version){let e=`Update available: v${b.latest_version}`;r({type:`info`,message:e}),x.current=e}else x.current&&=(r(null),null)},[h,b?.update_available,b?.latest_version]);let S=!!(u.matchedSpool||u.unknownTagUid||u.unknownTrayUuid),C=(0,W.useRef)(!1);(0,W.useEffect)(()=>{S&&!C.current&&l.pathname!==`/spoolbuddy`&&c(`/spoolbuddy`),C.current=S},[S,l.pathname,c]);let{data:w=[]}=z({queryKey:[`printers`],queryFn:()=>o.getPrinters()}),T=B({queries:w.map(e=>({queryKey:[`printerStatus`,e.id],queryFn:()=>o.getPrinterStatus(e.id),refetchInterval:1e4,select:e=>({connected:e?.connected})}))}),E=(0,W.useMemo)(()=>w.filter((e,t)=>T[t]?.data?.connected),[w,T]),D=(0,W.useRef)(null),O=(0,W.useRef)(!1),k=(0,W.useRef)(null),A=(0,W.useCallback)(e=>{D.current={x:e.touches[0].clientX,y:e.touches[0].clientY},O.current=!1},[]),j=(0,W.useCallback)(n=>{if(!D.current)return;let r=n.changedTouches[0].clientX-D.current.x,i=n.changedTouches[0].clientY-D.current.y,a=D.current.y;if(D.current=null,O.current=!1,i>=50&&Math.abs(i)>Math.abs(r)&&a<120){F(!0);return}if(E.length<2||Math.abs(r)<50||Math.abs(i)>Math.abs(r))return;let o=E.findIndex(t=>t.id===e);t(E[r<0?(o+1)%E.length:(o-1+E.length)%E.length].id)},[E,e,t]);(0,W.useEffect)(()=>{let e=k.current;if(!e)return;let t=e=>{if(!D.current)return;let t=Math.abs(e.touches[0].clientX-D.current.x),n=Math.abs(e.touches[0].clientY-D.current.y);if(O.current){e.preventDefault();return}t>10&&t>n&&(O.current=!0,e.preventDefault())};return e.addEventListener(`touchmove`,t,{passive:!1}),()=>e.removeEventListener(`touchmove`,t)},[]);let[M,N]=(0,W.useState)(!1),[P,F]=(0,W.useState)(!1);return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{ref:k,"data-spoolbuddy-kiosk":!0,className:`w-screen h-screen bg-bambu-dark text-white flex flex-col overflow-hidden`,style:{...i<100?{filter:`brightness(${i/100})`}:void 0,overscrollBehaviorX:`none`},onTouchStart:A,onTouchEnd:j,children:[(0,Z.jsx)(`button`,{onClick:()=>F(!0),className:`w-full h-1.5 bg-bambu-dark-secondary flex justify-center items-center shrink-0 touch-none`,"aria-label":`Open quick menu`,children:(0,Z.jsx)(`div`,{className:`w-8 h-0.5 rounded-full bg-zinc-600`})}),(0,Z.jsx)(zd,{selectedPrinterId:e,onPrinterChange:t,deviceOnline:h}),(0,Z.jsx)(`main`,{className:`flex-1 overflow-y-auto`,children:(0,Z.jsx)(W.Suspense,{fallback:(0,Z.jsx)(Ts,{}),children:(0,Z.jsx)(J,{context:{selectedPrinterId:e,setSelectedPrinterId:t,sbState:g,setAlert:r,displayBrightness:i,setDisplayBrightness:a}})})}),!M&&(0,Z.jsx)(Hd,{alert:n}),!M&&(0,Z.jsx)(Vd,{}),(0,Z.jsx)(ef,{onVisibilityChange:N})]}),(0,Z.jsx)(Ud,{isOpen:P,onClose:()=>F(!1),deviceId:m?.device_id??null,deviceOnline:h})]})}var nf=K(()=>q(()=>import(`./PrintersPage-Dsyz3sPW.js`),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71])),`PrintersPage`),rf=K(()=>q(()=>import(`./ArchivesPage-CSganGGR.js`),__vite__mapDeps([72,1,7,4,8,9,73,3,74,58,5,6,75,30,33,35,36,12,76,13,14,15,16,77,78,79,37,38,40,80,17,18,42,43,23,81,82,83,61,66,84,46,54,55,85,56,86,87,88,26,21,67,89,39,44,90,91,92])),`ArchivesPage`),af=K(()=>q(()=>import(`./QueuePage-CjROU5dj.js`),__vite__mapDeps([93,1,94,3,4,5,7,8,60,9,27,31,35,36,12,13,14,15,16,78,43,44,74,54,55,56,87,95,26,96,21,67,61,71])),`QueuePage`),of=K(()=>q(()=>import(`./StatsPage-CHDgcYiv.js`),__vite__mapDeps([97,1,94,3,4,5,2,6,9,7,10,35,12,13,14,15,16,98,39,80,44,48,49,54,99,26,100,21,61,91])),`StatsPage`),sf=K(()=>q(()=>import(`./SettingsPage-CF4BZl3e.js`),__vite__mapDeps([101,1,7,4,8,60,9,3,22,23,24,25,26,102,35,36,12,13,14,15,16,77,37,103,98,39,44,45,84,46,104,105,21,52,54,56,86,106,18,57,107,87,108,96,67,109,68,69,61])),`SettingsPage`),cf=K(()=>q(()=>import(`./FinancePage-WsLEQ1fC.js`),__vite__mapDeps([110,1,7,4,8,9,3,76,13,12,14,15,16,21,67,61])),`FinancePage`),lf=K(()=>q(()=>import(`./ProfilesPage-CqnWMUyc.js`),__vite__mapDeps([111,1,7,4,8,9,3,29,31,36,12,13,14,15,16,37,112,39,43,23,81,45,74,47,51,18,57,113,88,26,21,67,63,64,61])),`ProfilesPage`),uf=K(()=>q(()=>import(`./MaintenancePage-GtlPlRFZ.js`),__vite__mapDeps([114,1,7,4,8,9,3,33,34,35,36,12,13,14,15,16,77,112,43,85,113,99,25,95,26,21,67,68])),`MaintenancePage`),df=K(()=>q(()=>import(`./ProjectsPage--qAFcLFS.js`),__vite__mapDeps([115,1,7,4,8,9,3,12,13,14,15,16,38,54,85,26,5,21])),`ProjectsPage`),ff=K(()=>q(()=>import(`./ProjectDetailPage-BMGYb4NN.js`),__vite__mapDeps([116,1,7,4,8,9,73,3,74,58,5,6,75,28,35,12,13,14,15,16,37,40,115,38,54,85,26,21,84,67,61,117,92])),`ProjectDetailPage`),pf=K(()=>q(()=>import(`./FileManagerPage-FtcjfbEh.js`),__vite__mapDeps([118,1,7,4,8,60,9,11,12,3,13,14,15,16,17,18,19,20,21,33,102,36,77,79,38,40,80,43,82,83,61,66,45,46,104,74,24,56,88,26,58,90,119,48,49,117,92])),`FileManagerPage`),mf=K(()=>q(()=>import(`./LibraryTrashPage-GKtQzVNm.js`),__vite__mapDeps([120,1,7,4,8,9,28,3,13,12,14,15,16,21,61])),`LibraryTrashPage`),hf=K(()=>q(()=>import(`./CameraPage-2mgwi0u3.js`),__vite__mapDeps([121,1,7,4,8,9,3,13,12,14,15,16,50,33,48,26,19])),`CameraPage`),gf=K(()=>q(()=>import(`./CamWallPage-B93EYwGu.js`),__vite__mapDeps([122,1,9,7,4,59,8,60,3,12,13,14,15,16,26,61])),`CamWallPage`),_f=K(()=>q(()=>import(`./StreamOverlayPage-BDnwgk_X.js`),__vite__mapDeps([123,1,7,4,9,33,3,95,109,61,70,124])),`StreamOverlayPage`),vf=K(()=>q(()=>import(`./ExternalLinkPage--eeDFa4j.js`),__vite__mapDeps([125,1,9,7,4,14,3,26])),`ExternalLinkPage`),yf=K(()=>q(()=>import(`./GroupEditPage-BfkGtN0q.js`),__vite__mapDeps([126,1,7,4,8,9,28,3,36,13,12,14,15,16,51,18,107,26,21,67])),`GroupEditPage`),bf=K(()=>q(()=>import(`./PrinterLocationsPage-BmifXYE1.js`),__vite__mapDeps([127,1,7,4,8,60,9,3,28,33,12,13,14,15,16,53,18,21,67])),`PrinterLocationsPage`),xf=K(()=>q(()=>import(`./InventoryPage-CPx98yw-.js`),__vite__mapDeps([128,1,2,3,4,5,6,7,8,60,9,22,23,24,25,26,27,30,31,32,36,12,76,13,14,15,16,79,37,46,104,105,21,54,18,113,58,100,89,39,44,67,69,129,83,106,63,61,130,131,132,65,66])),`default`),Sf=K(()=>q(()=>import(`./ModelSourcesPage-Crhk7_mU.js`),__vite__mapDeps([133,1,7,4,8,9,75,3,28,29,33,36,12,13,14,15,16,77,82,83,18,61,66,21,67,117,92])),`ModelSourcesPage`),Cf=K(()=>q(()=>import(`./SystemInfoPage-CjmM6f9Q.js`),__vite__mapDeps([134,1,7,4,8,9,3,12,103,45,14,56,18,26,15,67,61])),`SystemInfoPage`),wf=K(()=>q(()=>import(`./LoginPage-rGUF5BC3.js`),__vite__mapDeps([135,1,8,7,4,9,13,3,12,14,15,16,107,108,21,67])),`LoginPage`),Tf=K(()=>q(()=>import(`./ConnectAuthorizePage-m6XXoE23.js`),__vite__mapDeps([136,1,104,3,4,14,26])),`ConnectAuthorizePage`),Ef=K(()=>q(()=>import(`./SetupPage-C42DVxS_.js`),__vite__mapDeps([137,1,8,7,4,12,3,13,14,15,16])),`SetupPage`),Df=K(()=>q(()=>import(`./NotificationsPage-B3GOs-as.js`),__vite__mapDeps([138,1,7,4,8,9,13,3,12,14,15,16,21,67])),`NotificationsPage`),Of=K(()=>q(()=>import(`./GCodeViewerPage-CAOZmPME.js`),__vite__mapDeps([139,1,9,7,4,28,3,41,14,20])),`GCodeViewerPage`),kf=K(()=>q(()=>import(`./SpoolBuddyDashboard-BEpEFke6.js`),__vite__mapDeps([140,1,7,4,8,60,9,36,3,13,12,14,15,16,26,58,130,131,132,69,141])),`SpoolBuddyDashboard`),Af=K(()=>q(()=>import(`./SpoolBuddyAmsPage-CUILYofw.js`),__vite__mapDeps([142,1,7,4,8,9,13,3,12,14,15,16,104,54,57,58,62,18,21,63,64,65,66,131,132,69,70])),`SpoolBuddyAmsPage`),jf=K(()=>q(()=>import(`./SpoolBuddySettingsPage-FUv2PkN1.js`),__vite__mapDeps([143,1,7,4,9,56,3,15,61])),`SpoolBuddySettingsPage`),Mf=K(()=>q(()=>import(`./SpoolBuddyCalibrationPage-BqJCOceW.js`),__vite__mapDeps([144,1,9,7,4])),`SpoolBuddyCalibrationPage`),Nf=K(()=>q(()=>import(`./SpoolBuddyWriteTagPage-DwfWgHhK.js`),__vite__mapDeps([145,1,9,7,4,12,3,13,14,15,16,113,129,83,106,18,69,63,61,132])),`SpoolBuddyWriteTagPage`),Pf=K(()=>q(()=>import(`./SpoolBuddyInventoryPage-DOeFqPsy.js`),__vite__mapDeps([146,1,7,4,8,9,36,3,13,12,14,15,16,54,18,26,58,130,131,132,69,141,65])),`SpoolBuddyInventoryPage`),Ff=class extends W.Component{state={error:null,errorInfo:null};static getDerivedStateFromError(e){return{error:e}}componentDidCatch(e,t){this.setState({errorInfo:t}),console.error(`React crash:`,e,t)}render(){return this.state.error?(0,Z.jsxs)(`div`,{style:{padding:24,color:`#ef4444`,backgroundColor:`#18181b`,minHeight:`100vh`,fontFamily:`monospace`},children:[(0,Z.jsx)(`h1`,{style:{fontSize:20,marginBottom:12},children:`UI Crash`}),(0,Z.jsx)(`pre`,{style:{whiteSpace:`pre-wrap`,fontSize:14},children:this.state.error.message}),(0,Z.jsx)(`pre`,{style:{whiteSpace:`pre-wrap`,fontSize:12,color:`#a1a1aa`,marginTop:12},children:this.state.error.stack}),(0,Z.jsx)(`button`,{onClick:()=>{this.setState({error:null,errorInfo:null})},style:{marginTop:16,padding:`8px 16px`,backgroundColor:`#3b82f6`,color:`#fff`,border:`none`,borderRadius:8,cursor:`pointer`},children:`Retry`})]}):this.props.children}},If=new Ua({defaultOptions:{queries:{staleTime:1e3*60,retry:1}}});function Lf(){return Od(),null}function Rf({children:e}){return yd(),Td(),(0,Z.jsx)(Z.Fragment,{children:e})}function zf({children:e}){let{authEnabled:t,loading:n,user:r}=Os(),i=qr();return n?(0,Z.jsx)(`div`,{className:`min-h-screen flex items-center justify-center`,children:`Loading...`}):t&&!r?(0,Z.jsx)(Ti,{to:`/login`,replace:!0,state:{from:i}}):(0,Z.jsx)(Z.Fragment,{children:e})}function Bf({permission:e,children:t}){let{authEnabled:n,loading:r,user:i,hasPermission:a}=Os(),o=qr();return r?(0,Z.jsx)(`div`,{className:`min-h-screen flex items-center justify-center`,children:`Loading...`}):n?i?(Array.isArray(e)?e:[e]).some(e=>a(e))?(0,Z.jsx)(Z.Fragment,{children:t}):(0,Z.jsx)(Ti,{to:`/`,replace:!0}):(0,Z.jsx)(Ti,{to:`/login`,replace:!0,state:{from:o}}):(0,Z.jsx)(Z.Fragment,{children:t})}function Vf({children:e}){let{authEnabled:t,loading:n}=Os();return n?(0,Z.jsx)(`div`,{className:`min-h-screen flex items-center justify-center`,children:`Loading...`}):t?(0,Z.jsx)(Ti,{to:`/login`,replace:!0}):(0,Z.jsx)(Z.Fragment,{children:e})}function Hf(){return(0,Z.jsx)(Ff,{children:(0,Z.jsx)(me,{children:(0,Z.jsx)(te,{client:If,children:(0,Z.jsx)(Ds,{children:(0,Z.jsx)(As,{children:(0,Z.jsx)(Rd,{children:(0,Z.jsxs)(Id,{children:[(0,Z.jsx)(Lf,{}),(0,Z.jsx)(ga,{children:(0,Z.jsx)(W.Suspense,{fallback:(0,Z.jsx)(Ts,{fullScreen:!0}),children:(0,Z.jsxs)(Di,{children:[(0,Z.jsx)(Y,{path:`/setup`,element:(0,Z.jsx)(Vf,{children:(0,Z.jsx)(Ef,{})})}),(0,Z.jsx)(Y,{path:`/login`,element:(0,Z.jsx)(wf,{})}),(0,Z.jsx)(Y,{path:`/connect/authorize`,element:(0,Z.jsx)(zf,{children:(0,Z.jsx)(Tf,{})})}),(0,Z.jsx)(Y,{path:`/camera/:printerId`,element:(0,Z.jsx)(hf,{})}),(0,Z.jsx)(Y,{path:`/overlay/:printerId`,element:(0,Z.jsx)(_f,{})}),(0,Z.jsx)(Y,{path:`/camwall`,element:(0,Z.jsx)(gf,{})}),(0,Z.jsxs)(Y,{element:(0,Z.jsx)(zf,{children:(0,Z.jsx)(Rf,{children:(0,Z.jsx)(tf,{})})}),children:[(0,Z.jsx)(Y,{path:`spoolbuddy`,element:(0,Z.jsx)(kf,{})}),(0,Z.jsx)(Y,{path:`spoolbuddy/ams`,element:(0,Z.jsx)(Af,{})}),(0,Z.jsx)(Y,{path:`spoolbuddy/write-tag`,element:(0,Z.jsx)(Nf,{})}),(0,Z.jsx)(Y,{path:`spoolbuddy/inventory`,element:(0,Z.jsx)(Pf,{})}),(0,Z.jsx)(Y,{path:`spoolbuddy/settings`,element:(0,Z.jsx)(jf,{})}),(0,Z.jsx)(Y,{path:`spoolbuddy/calibration`,element:(0,Z.jsx)(Mf,{})})]}),(0,Z.jsxs)(Y,{element:(0,Z.jsx)(zf,{children:(0,Z.jsx)(Rf,{children:(0,Z.jsx)(pd,{})})}),children:[(0,Z.jsx)(Y,{index:!0,element:(0,Z.jsx)(nf,{})}),(0,Z.jsx)(Y,{path:`archives`,element:(0,Z.jsx)(rf,{})}),(0,Z.jsx)(Y,{path:`queue`,element:(0,Z.jsx)(af,{})}),(0,Z.jsx)(Y,{path:`pipelines/runs`,element:(0,Z.jsx)(Ti,{to:`/queue?tab=pipelines`,replace:!0})}),(0,Z.jsx)(Y,{path:`stats`,element:(0,Z.jsx)(of,{})}),(0,Z.jsx)(Y,{path:`profiles`,element:(0,Z.jsx)(lf,{})}),(0,Z.jsx)(Y,{path:`finance`,element:(0,Z.jsx)(Bf,{permission:`cost_centers:read_own`,children:(0,Z.jsx)(cf,{})})}),(0,Z.jsx)(Y,{path:`maintenance`,element:(0,Z.jsx)(uf,{})}),(0,Z.jsx)(Y,{path:`projects`,element:(0,Z.jsx)(df,{})}),(0,Z.jsx)(Y,{path:`projects/:id`,element:(0,Z.jsx)(ff,{})}),(0,Z.jsx)(Y,{path:`inventory`,element:(0,Z.jsx)(xf,{})}),(0,Z.jsx)(Y,{path:`files`,element:(0,Z.jsx)(pf,{})}),(0,Z.jsx)(Y,{path:`files/trash`,element:(0,Z.jsx)(mf,{})}),(0,Z.jsx)(Y,{path:`model-sources`,element:(0,Z.jsx)(Bf,{permission:[`makerworld:view`,`manyfold:view`],children:(0,Z.jsx)(Sf,{})})}),(0,Z.jsx)(Y,{path:`makerworld`,element:(0,Z.jsx)(Ti,{to:`/model-sources?tab=makerworld`,replace:!0})}),(0,Z.jsx)(Y,{path:`settings`,element:(0,Z.jsx)(Bf,{permission:`settings:read`,children:(0,Z.jsx)(sf,{})})}),(0,Z.jsx)(Y,{path:`groups/new`,element:(0,Z.jsx)(Bf,{permission:`groups:create`,children:(0,Z.jsx)(yf,{})})}),(0,Z.jsx)(Y,{path:`groups/:id/edit`,element:(0,Z.jsx)(Bf,{permission:`groups:update`,children:(0,Z.jsx)(yf,{})})}),(0,Z.jsx)(Y,{path:`printer-locations`,element:(0,Z.jsx)(Bf,{permission:`printers:read`,children:(0,Z.jsx)(bf,{})})}),(0,Z.jsx)(Y,{path:`users`,element:(0,Z.jsx)(Ti,{to:`/settings?tab=users`,replace:!0})}),(0,Z.jsx)(Y,{path:`groups`,element:(0,Z.jsx)(Ti,{to:`/settings?tab=users`,replace:!0})}),(0,Z.jsx)(Y,{path:`system`,element:(0,Z.jsx)(Cf,{})}),(0,Z.jsx)(Y,{path:`notifications`,element:(0,Z.jsx)(Df,{})}),(0,Z.jsx)(Y,{path:`gcode-viewer`,element:(0,Z.jsx)(Of,{})}),(0,Z.jsx)(Y,{path:`external/:id`,element:(0,Z.jsx)(vf,{})}),(0,Z.jsx)(Y,{path:`camera-tokens`,element:(0,Z.jsx)(Ti,{to:`/settings?tab=camera#card-camera-tokens`,replace:!0})})]})]})})})]})})})})})})})}var Uf=3e3;Promise.race([Sn,new Promise(e=>setTimeout(e,Uf))]).catch(()=>{}).then(()=>{(0,ze.createRoot)(document.getElementById(`root`)).render((0,Z.jsx)(W.StrictMode,{children:(0,Z.jsx)(Hf,{})}))});export{Dc as $,Vo as $t,El as A,eo as An,ms as At,Nc as B,qr as Bn,rs as Bt,mu as C,uo as Cn,xs as Ct,Il as D,ro as Dn,_s as Dt,Vl as E,io as En,vs as Et,_l as F,Ja as Fn,cs as Ft,qc as G,wn as Gn,Zo as Gt,Vc as H,$r as Hn,ts as Ht,gl as I,Ga as In,ss as It,Wc as J,qo as Jt,Uc as K,q as Kn,Xo as Kt,hl as L,Wa as Ln,os as Lt,xl as M,Za as Mn,fs as Mt,bl as N,Xa as Nn,ds as Nt,zl as O,X as On,gs as Ot,yl as P,Ya as Pn,us as Pt,wc as Q,Uo as Qt,fl as R,va as Rn,as as Rt,pu as S,fo as Sn,Ss as St,Wl as T,so as Tn,ys as Tt,Oc as U,ti as Un,$o as Ut,ol as V,Xr as Vn,ns as Vt,Bc as W,Ea as Wn,Qo as Wt,rl as X,Go as Xt,tl as Y,Ko as Yt,Cc as Z,Wo as Zt,ku as _,_o as _n,Is as _t,vd as a,Mo as an,pc as at,wu as b,mo as bn,ws as bt,ud as c,ko as cn,rc as ct,cd as d,To as dn,lc as dt,Bo as en,nl as et,od as f,wo as fn,ac as ft,Nu as g,yo as gn,Bs as gt,Pu as h,bo as hn,Vs as ht,_d as i,No as in,mc as it,wl as j,Qa as jn,ps as jt,Bl as k,to as kn,hs as kt,dd as l,Do as ln,cc as lt,sd as m,xo as mn,zs as mt,Od as n,Ro as nn,hc as nt,md as o,jo as on,dc as ot,ld as p,Co as pn,oc as pt,Hc as q,Jo as qt,hd as r,Lo as rn,gc as rt,gd as s,Ao as sn,nc as st,Ld as t,zo as tn,il as tt,fd as u,Eo as un,uc as ut,Du as v,go as vn,js as vt,ql as w,lo as wn,bs as wt,fu as x,po as xn,Cs as xt,Tu as y,ho as yn,Os as yt,Tc as z,Ti as zn,is as zt}; \ No newline at end of file +In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}()}function w(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n1&&arguments[1]!==void 0?arguments[1]:e;this.caretPosition=e,this.caretPositionEnd=t}},{key:`getInputCandidates`,value:function(e){var t=this,n=this.options,r=n.layoutCandidates,i=n.layoutCandidatesCaseSensitiveMatch;if(!r||T(r)!==`object`)return{};var a=Object.keys(r).filter((function(n){var r=e.substring(0,t.getCaretPositionEnd()||0)||e,a=RegExp(`${t.utilities.escapeRegex(n)}\$`,i?`g`:`gi`);return!!C(r.matchAll(a)).length}));if(a.length>1){var o=a.sort((function(e,t){return t.length-e.length}))[0];return{candidateKey:o,candidateValue:r[o]}}if(a.length){var s=a[0];return{candidateKey:s,candidateValue:r[s]}}return{}}},{key:`showCandidatesBox`,value:function(e,t,n){var r=this;this.candidateBox&&this.candidateBox.show({candidateValue:t,targetElement:n,onSelect:function(t,n){var i=r.options,a=i.layoutCandidatesCaseSensitiveMatch,o=i.disableCandidateNormalization,s=i.enableLayoutCandidatesKeyPress,c=t;o||(c=t.normalize(`NFD`)),typeof r.options.beforeInputUpdate==`function`&&r.options.beforeInputUpdate(r);var l=r.getInput(r.options.inputName,!0),u=r.getCaretPositionEnd()||0,d=l.substring(0,u||0)||l,f=RegExp(`${r.utilities.escapeRegex(e)}\$`,a?`g`:`gi`),p=d.replace(f,c),m=l.replace(d,p),h=p.length-d.length,g=(u||l.length)+h;g<0&&(g=0),r.setInput(m,r.options.inputName,!0),r.setCaretPosition(g),s&&typeof r.options.onKeyPress==`function`&&r.options.onKeyPress(t,n),typeof r.options.onChange==`function`&&r.options.onChange(r.getInput(r.options.inputName,!0),n),typeof r.options.onChangeAll==`function`&&r.options.onChangeAll(r.getAllInputs(),n)}})}},{key:`handleButtonClicked`,value:function(e,t){var n=this.options,r=n.inputName,i=r===void 0?this.defaultName:r,a=n.debug;if(e!==`{//}`){this.input[i]||(this.input[i]=``),typeof this.options.beforeInputUpdate==`function`&&this.options.beforeInputUpdate(this);var o=this.utilities.getUpdatedInput(e,this.input[i],this.caretPosition,this.caretPositionEnd);if(this.utilities.isStandardButton(e)&&this.activeInputElement&&this.input[i]&&this.input[i]===o&&this.caretPosition===0&&this.caretPositionEnd===o.length)return this.setInput(``,this.options.inputName,!0),this.setCaretPosition(0),this.activeInputElement.value=``,this.activeInputElement.setSelectionRange(0,0),void this.handleButtonClicked(e,t);if(typeof this.options.onKeyPress==`function`&&this.options.onKeyPress(e,t),this.input[i]!==o&&(!this.options.inputPattern||this.options.inputPattern&&this.inputPatternIsValid(o))){if(this.options.maxLength&&this.utilities.handleMaxLength(this.input,o))return;var s=this.utilities.getUpdatedInput(e,this.input[i],this.caretPosition,this.caretPositionEnd,!0);if(this.setInput(s,this.options.inputName,!0),a&&console.log(`Input changed:`,this.getAllInputs()),this.options.debug&&console.log(`Caret at: `,this.getCaretPosition(),this.getCaretPositionEnd(),`(${this.keyboardDOMClass})`,t?.type),this.options.syncInstanceInputs&&this.syncInstanceInputs(),typeof this.options.onChange==`function`&&this.options.onChange(this.getInput(this.options.inputName,!0),t),typeof this.options.onChangeAll==`function`&&this.options.onChangeAll(this.getAllInputs(),t),t!=null&&t.target&&this.options.enableLayoutCandidates){var c,l=this.getInputCandidates(o),u=l.candidateKey,d=l.candidateValue;u&&d?this.showCandidatesBox(u,d,this.keyboardDOM):(c=this.candidateBox)==null||c.destroy()}}this.caretPositionEnd&&this.caretPosition!==this.caretPositionEnd&&(this.setCaretPosition(this.caretPositionEnd,this.caretPositionEnd),this.activeInputElement&&this.activeInputElement.setSelectionRange(this.caretPositionEnd,this.caretPositionEnd),this.options.debug&&console.log(`Caret position aligned`,this.caretPosition)),a&&console.log(`Key pressed:`,e)}}},{key:`getMouseHold`,value:function(){return this.isMouseHold}},{key:`setMouseHold`,value:function(e){this.options.syncInstanceInputs?this.dispatch((function(t){t.isMouseHold=e})):this.isMouseHold=e}},{key:`handleButtonMouseDown`,value:function(e,t){var n=this;t&&(this.options.preventMouseDownDefault&&t.preventDefault(),this.options.stopMouseDownPropagation&&t.stopPropagation(),t.target.classList.add(this.activeButtonClass)),this.holdInteractionTimeout&&clearTimeout(this.holdInteractionTimeout),this.holdTimeout&&clearTimeout(this.holdTimeout),this.setMouseHold(!0),this.options.disableButtonHold||(this.holdTimeout=window.setTimeout((function(){(n.getMouseHold()&&(!e.includes(`{`)&&!e.includes(`}`)||e===`{delete}`||e===`{backspace}`||e===`{bksp}`||e===`{space}`||e===`{tab}`)||e===`{arrowright}`||e===`{arrowleft}`||e===`{arrowup}`||e===`{arrowdown}`)&&(n.options.debug&&console.log(`Button held:`,e),n.handleButtonHold(e)),clearTimeout(n.holdTimeout)}),500))}},{key:`handleButtonMouseUp`,value:function(e,t){var n=this;t&&(this.options.preventMouseUpDefault&&t.preventDefault&&t.preventDefault(),this.options.stopMouseUpPropagation&&t.stopPropagation&&t.stopPropagation(),!(t.target===this.keyboardDOM||t.target&&this.keyboardDOM.contains(t.target)||this.candidateBox&&this.candidateBox.candidateBoxElement&&(t.target===this.candidateBox.candidateBoxElement||t.target&&this.candidateBox.candidateBoxElement.contains(t.target)))&&this.candidateBox&&this.candidateBox.destroy()),this.recurseButtons((function(e){e.classList.remove(n.activeButtonClass)})),this.setMouseHold(!1),this.holdInteractionTimeout&&clearTimeout(this.holdInteractionTimeout),e&&typeof this.options.onKeyReleased==`function`&&this.options.onKeyReleased(e,t)}},{key:`handleKeyboardContainerMouseDown`,value:function(e){this.options.preventMouseDownDefault&&e.preventDefault()}},{key:`handleButtonHold`,value:function(e){var t=this;this.holdInteractionTimeout&&clearTimeout(this.holdInteractionTimeout),this.holdInteractionTimeout=window.setTimeout((function(){t.getMouseHold()?(t.handleButtonClicked(e),t.handleButtonHold(e)):clearTimeout(t.holdInteractionTimeout)}),100)}},{key:`syncInstanceInputs`,value:function(){var e=this;this.dispatch((function(t){t.replaceInput(e.input),t.setCaretPosition(e.caretPosition,e.caretPositionEnd)}))}},{key:`clearInput`,value:function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.options.inputName||this.defaultName;this.input[e]=``,this.setCaretPosition(0),this.options.syncInstanceInputs&&this.syncInstanceInputs()}},{key:`getInput`,value:function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.options.inputName||this.defaultName,t=arguments.length>1&&arguments[1]!==void 0&&arguments[1];return this.options.syncInstanceInputs&&!t&&this.syncInstanceInputs(),this.options.rtl?`‫`+this.input[e].replace(`‫`,``).replace(`‬`,``)+`‬`:this.input[e]}},{key:`getAllInputs`,value:function(){var e=this,t={};return Object.keys(this.input).forEach((function(n){t[n]=e.getInput(n,!0)})),t}},{key:`setInput`,value:function(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:this.options.inputName||this.defaultName,n=arguments.length>2?arguments[2]:void 0;this.input[t]=e,!n&&this.options.syncInstanceInputs&&this.syncInstanceInputs()}},{key:`replaceInput`,value:function(e){this.input=e}},{key:`setOptions`,value:function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},t=this.changedOptions(e);this.options=Object.assign(this.options,e),t.length&&(this.options.debug&&console.log(`changedOptions`,t),this.onSetOptions(t),this.render())}},{key:`changedOptions`,value:function(e){var t=this;return Object.keys(e).filter((function(n){return JSON.stringify(e[n])!==JSON.stringify(t.options[n])}))}},{key:`onSetOptions`,value:function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];e.includes(`layoutName`)&&this.candidateBox&&this.candidateBox.destroy(),(e.includes(`layoutCandidatesPageSize`)||e.includes(`layoutCandidates`))&&this.candidateBox&&(this.candidateBox.destroy(),this.candidateBox=new S({utilities:this.utilities,options:this.options}))}},{key:`resetRows`,value:function(){this.keyboardRowsDOM&&this.keyboardRowsDOM.remove(),this.keyboardDOM.className=this.keyboardDOMClass,this.keyboardDOM.setAttribute(`data-skInstance`,this.currentInstanceName),this.buttonElements={}}},{key:`dispatch`,value:function(e){if(!window.SimpleKeyboardInstances)throw console.warn(`SimpleKeyboardInstances is not defined. Dispatch cannot be called.`),Error(`INSTANCES_VAR_ERROR`);return Object.keys(window.SimpleKeyboardInstances).forEach((function(t){e(window.SimpleKeyboardInstances[t],t)}))}},{key:`addButtonTheme`,value:function(e,t){var n=this;t&&e&&(e.split(` `).forEach((function(r){t.split(` `).forEach((function(t){n.options.buttonTheme||(n.options.buttonTheme=[]);var i=!1;n.options.buttonTheme.map((function(e){if(e!=null&&e.class.split(` `).includes(t)){i=!0;var n=e.buttons.split(` `);n.includes(r)||(i=!0,n.push(r),e.buttons=n.join(` `))}return e})),i||n.options.buttonTheme.push({class:t,buttons:e})}))})),this.render())}},{key:`removeButtonTheme`,value:function(e,t){var n=this;if(!e&&!t)return this.options.buttonTheme=[],void this.render();e&&Array.isArray(this.options.buttonTheme)&&this.options.buttonTheme.length&&(e.split(` `).forEach((function(e){var r;(r=n.options)==null||(r=r.buttonTheme)==null||r.map((function(r,i){if(r&&t&&t.includes(r.class)||!t){var a,o=r?.buttons.split(` `).filter((function(t){return t!==e}));r&&o!=null&&o.length?r.buttons=o.join(` `):((a=n.options.buttonTheme)==null||a.splice(i,1),r=null)}return r}))})),this.render())}},{key:`getButtonElement`,value:function(e){var t,n=this.buttonElements[e];return n&&(t=n.length>1?n:n[0]),t}},{key:`inputPatternIsValid`,value:function(e){var t,n=this.options.inputPattern;if((t=n instanceof RegExp?n:n[this.options.inputName||this.defaultName])&&e){var r=t.test(e);return this.options.debug&&console.log(`inputPattern ("${t}"): ${r?`passed`:`did not pass!`}`),r}return!0}},{key:`setEventListeners`,value:function(){if(this.isFirstKeyboardInstance||!this.allKeyboardInstances){this.options.debug&&console.log(`Caret handling started (${this.keyboardDOMClass})`);var e=this.options.physicalKeyboardHighlightPreventDefault,t=e!==void 0&&e;document.addEventListener(`keyup`,this.handleKeyUp,t),document.addEventListener(`keydown`,this.handleKeyDown,t),document.addEventListener(`mouseup`,this.handleMouseUp),document.addEventListener(`touchend`,this.handleTouchEnd),this.options.updateCaretOnSelectionChange&&document.addEventListener(`selectionchange`,this.handleSelectionChange),document.addEventListener(`select`,this.handleSelect)}}},{key:`handleKeyUp`,value:function(e){this.caretEventHandler(e),this.options.physicalKeyboardHighlight&&this.physicalKeyboard.handleHighlightKeyUp(e)}},{key:`handleKeyDown`,value:function(e){this.options.physicalKeyboardHighlight&&this.physicalKeyboard.handleHighlightKeyDown(e)}},{key:`handleMouseUp`,value:function(e){this.caretEventHandler(e)}},{key:`handleTouchEnd`,value:function(e){this.caretEventHandler(e)}},{key:`handleSelect`,value:function(e){this.caretEventHandler(e)}},{key:`handleSelectionChange`,value:function(e){navigator.userAgent.includes(`Firefox`)||this.caretEventHandler(e)}},{key:`caretEventHandler`,value:function(e){var t,n=this;e.target.tagName&&(t=e.target.tagName.toLowerCase()),this.dispatch((function(r){var i=e.target===r.keyboardDOM||e.target&&r.keyboardDOM.contains(e.target);if(n.options.syncInstanceInputs&&Array.isArray(e.path)&&(i=e.path.some((function(e){var t;return e==null||(t=e.hasAttribute)==null?void 0:t.call(e,`data-skInstance`)}))),(t===`textarea`||t===`input`&&[`text`,`search`,`url`,`tel`,`password`].includes(e.target.type))&&!r.options.disableCaretPositioning){var a=e.target.selectionStart,o=e.target.selectionEnd;r.options.rtl&&(a=r.utilities.getRtlOffset(a,r.getInput()),o=r.utilities.getRtlOffset(o,r.getInput())),r.setCaretPosition(a,o),r.activeInputElement=e.target,r.options.debug&&console.log(`Caret at: `,r.getCaretPosition(),r.getCaretPositionEnd(),e&&e.target.tagName.toLowerCase(),`(${r.keyboardDOMClass})`,e?.type)}else !r.options.disableCaretPositioning&&i||e?.type===`selectionchange`||(r.setCaretPosition(null),r.activeInputElement=null,r.options.debug&&console.log(`Caret position reset due to "${e?.type}" event`,e))}))}},{key:`recurseButtons`,value:function(e){var t=this;e&&Object.keys(this.buttonElements).forEach((function(n){return t.buttonElements[n].forEach(e)}))}},{key:`destroy`,value:function(){this.options.debug&&console.log(`Destroying simple-keyboard instance: ${this.currentInstanceName}`);var e=this.options.physicalKeyboardHighlightPreventDefault,t=e!==void 0&&e;document.removeEventListener(`keyup`,this.handleKeyUp,t),document.removeEventListener(`keydown`,this.handleKeyDown,t),document.removeEventListener(`mouseup`,this.handleMouseUp),document.removeEventListener(`touchend`,this.handleTouchEnd),document.removeEventListener(`select`,this.handleSelect),this.options.updateCaretOnSelectionChange&&document.removeEventListener(`selectionchange`,this.handleSelectionChange),document.onpointerup=null,document.ontouchend=null,document.ontouchcancel=null,document.onmouseup=null,this.recurseButtons((function(e){e&&=(e.onpointerdown=null,e.onpointerup=null,e.onpointercancel=null,e.ontouchstart=null,e.ontouchend=null,e.ontouchcancel=null,e.onclick=null,e.onmousedown=null,e.onmouseup=null,e.remove(),null)})),this.keyboardDOM.onpointerdown=null,this.keyboardDOM.ontouchstart=null,this.keyboardDOM.onmousedown=null,this.resetRows(),this.candidateBox&&=(this.candidateBox.destroy(),null),this.activeInputElement=null,this.keyboardDOM.removeAttribute(`data-skInstance`),this.keyboardDOM.innerHTML=``,window.SimpleKeyboardInstances[this.currentInstanceName]=null,delete window.SimpleKeyboardInstances[this.currentInstanceName],this.initialized=!1}},{key:`getButtonThemeClasses`,value:function(e){var t=this.options.buttonTheme,n=[];return Array.isArray(t)&&t.forEach((function(t){if(t&&t.class&&typeof t.class==`string`&&t.buttons&&typeof t.buttons==`string`){var r=t.class.split(` `);t.buttons.split(` `).includes(e)&&(n=[].concat(C(n),C(r)))}else console.warn(`Incorrect "buttonTheme". Please check the documentation.`,t)})),n}},{key:`setDOMButtonAttributes`,value:function(e,t){var n=this.options.buttonAttributes;Array.isArray(n)&&n.forEach((function(n){n.attribute&&typeof n.attribute==`string`&&n.value&&typeof n.value==`string`?n.buttons&&typeof n.buttons==`string`?n.buttons.split(` `).includes(e)&&t(n.attribute,n.value):t(n.attribute,n.value):console.warn(`Incorrect "buttonAttributes". Please check the documentation.`,n)}))}},{key:`onTouchDeviceDetected`,value:function(){this.processAutoTouchEvents(),this.disableContextualWindow()}},{key:`disableContextualWindow`,value:function(){window.oncontextmenu=function(e){var t;if((t=e.target.classList)!=null&&t.contains(`hg-button`))return e.preventDefault(),e.stopPropagation(),!1}}},{key:`processAutoTouchEvents`,value:function(){this.options.autoUseTouchEvents&&(this.options.useTouchEvents=!0,this.options.debug&&console.log(`autoUseTouchEvents: Touch device detected, useTouchEvents enabled.`))}},{key:`onInit`,value:function(){this.options.debug&&console.log(`${this.keyboardDOMClass} Initialized`),this.setEventListeners(),typeof this.options.onInit==`function`&&this.options.onInit(this)}},{key:`beforeFirstRender`,value:function(){this.utilities.isTouchDevice()&&this.onTouchDeviceDetected(),typeof this.options.beforeFirstRender==`function`&&this.options.beforeFirstRender(this),this.isFirstKeyboardInstance&&this.utilities.pointerEventsSupported()&&!this.options.useTouchEvents&&!this.options.useMouseEvents&&this.options.debug&&console.log(`Using PointerEvents as it is supported by this browser`),this.options.useTouchEvents&&this.options.debug&&console.log(`useTouchEvents has been enabled. Only touch events will be used.`)}},{key:`beforeRender`,value:function(){typeof this.options.beforeRender==`function`&&this.options.beforeRender(this)}},{key:`onRender`,value:function(){typeof this.options.onRender==`function`&&this.options.onRender(this)}},{key:`onModulesLoaded`,value:function(){typeof this.options.onModulesLoaded==`function`&&this.options.onModulesLoaded(this)}},{key:`loadModules`,value:function(){var e=this;Array.isArray(this.options.modules)&&(this.options.modules.forEach((function(t){var n=e.utilities.isConstructor(t)?new t(e):t(e);n.init&&n.init(e)})),this.keyboardPluginClasses=`modules-loaded`,this.render(),this.onModulesLoaded())}},{key:`getModuleProp`,value:function(e,t){return!!this.modules[e]&&this.modules[e][t]}},{key:`getModulesList`,value:function(){return Object.keys(this.modules)}},{key:`parseRowDOMContainers`,value:function(e,t,n,r){var i=this,a=Array.from(e.children),o=0;return a.length&&n.forEach((function(n,s){var c=r[s];if(!(c&&c>n))return!1;var l=n-o,u=c-o,d=document.createElement(`div`);d.className+=`hg-button-container`;var f=`${i.options.layoutName}-r${t}c${s}`;d.setAttribute(`data-skUID`,f);var p=a.splice(l,u-l+1);o+=u-l,p.forEach((function(e){return d.appendChild(e)})),a.splice(l,0,d),e.innerHTML=``,a.forEach((function(t){return e.appendChild(t)})),i.options.debug&&console.log(`rowDOMContainer`,p,l,u,o+1)})),e}},{key:`render`,value:function(){var e=this;this.resetRows(),this.initialized||this.beforeFirstRender(),this.beforeRender();var t=`hg-layout-${this.options.layoutName}`,n=this.options.layout||{default:["` 1 2 3 4 5 6 7 8 9 0 - = {bksp}",`{tab} q w e r t y u i o p [ ] \\`,`{lock} a s d f g h j k l ; ' {enter}`,`{shift} z x c v b n m , . / {shift}`,`.com @ {space}`],shift:[`~ ! @ # $ % ^ & * ( ) _ + {bksp}`,`{tab} Q W E R T Y U I O P { } |`,`{lock} A S D F G H J K L : " {enter}`,`{shift} Z X C V B N M < > ? {shift}`,`.com @ {space}`]},r=this.options.useTouchEvents||!1,i=r?`hg-touch-events`:``,a=this.options.useMouseEvents||!1,o=this.options.disableRowButtonContainers;this.keyboardDOM.className=this.getKeyboardClassString(this.options.theme,t,this.keyboardPluginClasses,i),this.keyboardDOM.setAttribute(`data-skInstance`,this.currentInstanceName),this.keyboardRowsDOM=document.createElement(`div`),this.keyboardRowsDOM.className=`hg-rows`,n[this.options.layoutName||this.defaultName].forEach((function(t,n){var i=t.split(` `);e.options.excludeFromLayout&&e.options.excludeFromLayout[e.options.layoutName||e.defaultName]&&(i=i.filter((function(t){return e.options.excludeFromLayout&&!e.options.excludeFromLayout[e.options.layoutName||e.defaultName].includes(t)})));var s=document.createElement(`div`);s.className+=`hg-row`;var c=[],l=[];i.forEach((function(t,i){var u,d=!o&&typeof t==`string`&&t.length>1&&t.indexOf(`[`)===0,f=!o&&typeof t==`string`&&t.length>1&&t.indexOf(`]`)===t.length-1;d&&(c.push(i),t=t.replace(/\[/g,``)),f&&(l.push(i),t=t.replace(/\]/g,``));var p=e.utilities.getButtonClass(t),m=e.utilities.getButtonDisplayName(t,e.options.display,e.options.mergeDisplay),h=e.options.useButtonTag?`button`:`div`,g=document.createElement(h);g.className+=`hg-button ${p}`,(u=g.classList).add.apply(u,C(e.getButtonThemeClasses(t))),e.setDOMButtonAttributes(t,(function(e,t){g.setAttribute(e,t)})),e.activeButtonClass=`hg-activeButton`,!e.utilities.pointerEventsSupported()||r||a?r?(g.ontouchstart=function(n){e.handleButtonClicked(t,n),e.handleButtonMouseDown(t,n)},g.ontouchend=function(n){e.handleButtonMouseUp(t,n)},g.ontouchcancel=function(n){e.handleButtonMouseUp(t,n)}):(g.onclick=function(n){e.setMouseHold(!1),typeof e.options.onKeyReleased==`function`||e.options.useMouseEvents&&e.options.clickOnMouseDown||e.handleButtonClicked(t,n)},g.onmousedown=function(n){(typeof e.options.onKeyReleased==`function`||e.options.useMouseEvents&&e.options.clickOnMouseDown)&&!e.isMouseHold&&e.handleButtonClicked(t,n),e.handleButtonMouseDown(t,n)},g.onmouseup=function(n){e.handleButtonMouseUp(t,n)}):(g.onpointerdown=function(n){e.handleButtonClicked(t,n),e.handleButtonMouseDown(t,n)},g.onpointerup=function(n){e.handleButtonMouseUp(t,n)},g.onpointercancel=function(n){e.handleButtonMouseUp(t,n)}),g.setAttribute(`data-skBtn`,t);var _=`${e.options.layoutName}-r${n}b${i}`;g.setAttribute(`data-skBtnUID`,_);var v=document.createElement(`span`);v.innerHTML=m,g.appendChild(v),e.buttonElements[t]||(e.buttonElements[t]=[]),e.buttonElements[t].push(g),s.appendChild(g)})),s=e.parseRowDOMContainers(s,n,c,l),e.keyboardRowsDOM.appendChild(s)})),this.keyboardDOM.appendChild(this.keyboardRowsDOM),this.onRender(),this.initialized||(this.initialized=!0,!this.utilities.pointerEventsSupported()||r||a?r?(document.ontouchend=function(t){return e.handleButtonMouseUp(void 0,t)},document.ontouchcancel=function(t){return e.handleButtonMouseUp(void 0,t)},this.keyboardDOM.ontouchstart=function(t){return e.handleKeyboardContainerMouseDown(t)}):r||(document.onmouseup=function(t){return e.handleButtonMouseUp(void 0,t)},this.keyboardDOM.onmousedown=function(t){return e.handleKeyboardContainerMouseDown(t)}):(document.onpointerup=function(t){return e.handleButtonMouseUp(void 0,t)},this.keyboardDOM.onpointerdown=function(t){return e.handleKeyboardContainerMouseDown(t)}),this.onInit())}}],t&&D(e.prototype,t),n&&D(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,n}(),j=A;return r}()},442:function(t){t.exports=e}},n={};function r(e){var i=n[e];if(i!==void 0)return i.exports;var a=n[e]={exports:{}};return t[e].call(a.exports,a,a.exports,r),a.exports}r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,{a:t}),t},r.d=function(e,t){for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.r=function(e){typeof Symbol<`u`&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:`Module`}),Object.defineProperty(e,"__esModule",{value:!0})};var i={};return function(){r.r(i),r.d(i,{KeyboardReact:function(){return u},default:function(){return d}}),r(981);var e=r(442),t=r(548),n=r.n(t);function a(e){return a=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},a(e)}function o(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function s(e){for(var t=1;t{e?.(t)},[t,e]);let d=(0,W.useCallback)(e=>{if(a.current)return;let t=e.target;if(!t.closest(`[data-vkb="false"]`)){if(t instanceof HTMLInputElement){if(!Qd.has(t.type))return}else if(!(t instanceof HTMLTextAreaElement))return;c.current=t,n(!0),s(`default`),l.current?.setInput?.(c.current.value),setTimeout(()=>{(t.closest(`.bg-zinc-800, .rounded-lg, [data-vkb-group]`)??t).scrollIntoView({behavior:`smooth`,block:`nearest`})},100)}},[]),f=(0,W.useCallback)(()=>{setTimeout(()=>{let e=document.activeElement;e&&(u.current?.contains(e)||e===c.current)||(n(!1),c.current=null)},150)},[]);(0,W.useEffect)(()=>(document.addEventListener(`focusin`,d),document.addEventListener(`focusout`,f),()=>{document.removeEventListener(`focusin`,d),document.removeEventListener(`focusout`,f)}),[d,f]);let p=(0,W.useCallback)(()=>{a.current=!0,i(!0),c.current?.blur(),c.current=null,setTimeout(()=>{n(!1),i(!1),a.current=!1},400)},[]),m=(0,W.useCallback)(e=>{let t=c.current;if(t){if(e===`{shift}`){s(e=>e==="default"?`shift`:`default`);return}if(e===`{lock}`){s(e=>e==="default"?`shift`:`default`);return}if(e===`{close}`){p();return}e===`{bksp}`?$d(t,t.value.slice(0,-1)):e===`{space}`?$d(t,t.value+` `):($d(t,t.value+e),o===`shift`&&s(`default`)),t.focus(),l.current?.setInput?.(t.value)}},[o,p]);return t?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`div`,{className:`fixed inset-0 z-[9998] bg-transparent`,onMouseDown:e=>{e.preventDefault(),e.stopPropagation(),r||p()},onTouchStart:e=>{e.preventDefault(),e.stopPropagation(),r||p()},onClick:e=>{e.preventDefault(),e.stopPropagation()}}),!r&&(0,Z.jsx)(`div`,{ref:u,className:`relative z-[9999] shrink-0`,onMouseDown:e=>e.preventDefault(),onTouchStart:e=>{e.target.closest(`.hg-button`)||e.preventDefault()},children:(0,Z.jsx)(Zd,{keyboardRef:e=>{l.current=e},layoutName:o,onKeyPress:m,theme:`simple-keyboard vkb-theme`,layout:{default:[`1 2 3 4 5 6 7 8 9 0 {bksp}`,`q w e r t y u i o p`,`{lock} a s d f g h j k l`,`{shift} z x c v b n m . @`,`{space} {close}`],shift:[`! @ # $ % ^ & * ( ) {bksp}`,`Q W E R T Y U I O P`,`{lock} A S D F G H J K L`,`{shift} Z X C V B N M , _`,`{space} {close}`]},display:{"{bksp}":`⌫`,"{close}":`✕ Close`,"{shift}":`⇧`,"{lock}":`⇪`,"{space}":` `}})})]}):null}function tf(){dc();let[e,t]=(0,W.useState)(null),[n,r]=(0,W.useState)(null),[i,a]=(0,W.useState)(100),{i18n:s}=v(),c=Xr(),l=qr(),u=qd(),{setViewportSuppressed:d}=fe();(0,W.useEffect)(()=>(d(!0),()=>d(!1)),[d]);let{data:f}=z({queryKey:[`settings`],queryFn:o.getSettings});(0,W.useEffect)(()=>{f?.language&&f.language!==s.language&&s.changeLanguage(f.language)},[f?.language,s]);let{data:p=[]}=z({queryKey:[`spoolbuddy-devices`],queryFn:()=>_.getDevices(),refetchInterval:3e4}),m=p[0],h=u.deviceOnline||!!m?.online,g=(0,W.useMemo)(()=>({...u,deviceOnline:h}),[u,h]),y=(0,W.useRef)(!1);(0,W.useEffect)(()=>{m&&!y.current&&(a(m.display_brightness),y.current=!0)},[m]),(0,W.useEffect)(()=>{let e=document.documentElement,t=e.classList.contains(`dark`);return e.classList.add(`dark`),()=>{t||e.classList.remove(`dark`)}},[]);let{data:b}=z({queryKey:[`spoolbuddy-update-check`,m?.device_id],queryFn:()=>m?_.checkDaemonUpdate(m.device_id):Promise.resolve(null),enabled:!!m,refetchInterval:300*1e3,staleTime:0}),x=(0,W.useRef)(null);(0,W.useEffect)(()=>{if(!h){let e=`SpoolBuddy device disconnected`;r({type:`warning`,message:e}),x.current=e}else if(b?.update_available&&b.latest_version){let e=`Update available: v${b.latest_version}`;r({type:`info`,message:e}),x.current=e}else x.current&&=(r(null),null)},[h,b?.update_available,b?.latest_version]);let S=!!(u.matchedSpool||u.unknownTagUid||u.unknownTrayUuid),C=(0,W.useRef)(!1);(0,W.useEffect)(()=>{S&&!C.current&&l.pathname!==`/spoolbuddy`&&c(`/spoolbuddy`),C.current=S},[S,l.pathname,c]);let{data:w=[]}=z({queryKey:[`printers`],queryFn:()=>o.getPrinters()}),T=B({queries:w.map(e=>({queryKey:[`printerStatus`,e.id],queryFn:()=>o.getPrinterStatus(e.id),refetchInterval:1e4,select:e=>({connected:e?.connected})}))}),E=(0,W.useMemo)(()=>w.filter((e,t)=>T[t]?.data?.connected),[w,T]),D=(0,W.useRef)(null),O=(0,W.useRef)(!1),k=(0,W.useRef)(null),A=(0,W.useCallback)(e=>{D.current={x:e.touches[0].clientX,y:e.touches[0].clientY},O.current=!1},[]),j=(0,W.useCallback)(n=>{if(!D.current)return;let r=n.changedTouches[0].clientX-D.current.x,i=n.changedTouches[0].clientY-D.current.y,a=D.current.y;if(D.current=null,O.current=!1,i>=50&&Math.abs(i)>Math.abs(r)&&a<120){F(!0);return}if(E.length<2||Math.abs(r)<50||Math.abs(i)>Math.abs(r))return;let o=E.findIndex(t=>t.id===e);t(E[r<0?(o+1)%E.length:(o-1+E.length)%E.length].id)},[E,e,t]);(0,W.useEffect)(()=>{let e=k.current;if(!e)return;let t=e=>{if(!D.current)return;let t=Math.abs(e.touches[0].clientX-D.current.x),n=Math.abs(e.touches[0].clientY-D.current.y);if(O.current){e.preventDefault();return}t>10&&t>n&&(O.current=!0,e.preventDefault())};return e.addEventListener(`touchmove`,t,{passive:!1}),()=>e.removeEventListener(`touchmove`,t)},[]);let[M,N]=(0,W.useState)(!1),[P,F]=(0,W.useState)(!1);return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{ref:k,"data-spoolbuddy-kiosk":!0,className:`w-screen h-screen bg-bambu-dark text-white flex flex-col overflow-hidden`,style:{...i<100?{filter:`brightness(${i/100})`}:void 0,overscrollBehaviorX:`none`},onTouchStart:A,onTouchEnd:j,children:[(0,Z.jsx)(`button`,{onClick:()=>F(!0),className:`w-full h-1.5 bg-bambu-dark-secondary flex justify-center items-center shrink-0 touch-none`,"aria-label":`Open quick menu`,children:(0,Z.jsx)(`div`,{className:`w-8 h-0.5 rounded-full bg-zinc-600`})}),(0,Z.jsx)(zd,{selectedPrinterId:e,onPrinterChange:t,deviceOnline:h}),(0,Z.jsx)(`main`,{className:`flex-1 overflow-y-auto`,children:(0,Z.jsx)(W.Suspense,{fallback:(0,Z.jsx)(Ts,{}),children:(0,Z.jsx)(J,{context:{selectedPrinterId:e,setSelectedPrinterId:t,sbState:g,setAlert:r,displayBrightness:i,setDisplayBrightness:a}})})}),!M&&(0,Z.jsx)(Hd,{alert:n}),!M&&(0,Z.jsx)(Vd,{}),(0,Z.jsx)(ef,{onVisibilityChange:N})]}),(0,Z.jsx)(Ud,{isOpen:P,onClose:()=>F(!1),deviceId:m?.device_id??null,deviceOnline:h})]})}var nf=K(()=>q(()=>import(`./PrintersPage-CLG7I78P.js`),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71])),`PrintersPage`),rf=K(()=>q(()=>import(`./ArchivesPage-BrcJqnr-.js`),__vite__mapDeps([72,1,7,4,8,9,73,3,74,58,5,6,75,30,33,35,36,12,76,13,14,15,16,77,78,79,37,38,40,80,17,18,42,43,23,81,82,83,61,66,84,46,54,55,85,56,86,87,88,26,21,67,89,39,44,90,91,92])),`ArchivesPage`),af=K(()=>q(()=>import(`./QueuePage-NR_JuCMy.js`),__vite__mapDeps([93,1,94,3,4,5,7,8,60,9,27,31,35,36,12,13,14,15,16,78,43,44,74,54,55,56,87,95,26,96,21,67,61,71])),`QueuePage`),of=K(()=>q(()=>import(`./StatsPage-E-fXkkLD.js`),__vite__mapDeps([97,1,94,3,4,5,2,6,9,7,10,35,12,13,14,15,16,98,39,80,44,48,49,54,99,26,100,21,61,91])),`StatsPage`),sf=K(()=>q(()=>import(`./SettingsPage-DCvPzv7P.js`),__vite__mapDeps([101,1,7,4,8,60,9,3,22,23,24,25,26,102,35,36,12,13,14,15,16,77,37,103,98,39,44,45,84,46,104,105,21,52,54,56,86,106,18,57,107,87,108,96,67,109,68,69,61])),`SettingsPage`),cf=K(()=>q(()=>import(`./FinancePage-D-k9CqTS.js`),__vite__mapDeps([110,1,7,4,8,9,3,76,13,12,14,15,16,21,67,61])),`FinancePage`),lf=K(()=>q(()=>import(`./ProfilesPage-FzXKlAbc.js`),__vite__mapDeps([111,1,7,4,8,9,3,29,31,36,12,13,14,15,16,37,112,39,43,23,81,45,74,47,51,18,57,113,88,26,21,67,63,64,61])),`ProfilesPage`),uf=K(()=>q(()=>import(`./MaintenancePage-B6wtSJnR.js`),__vite__mapDeps([114,1,7,4,8,9,3,33,34,35,36,12,13,14,15,16,77,112,43,85,113,99,25,95,26,21,67,68])),`MaintenancePage`),df=K(()=>q(()=>import(`./ProjectsPage-CBeO6wA6.js`),__vite__mapDeps([115,1,7,4,8,9,3,12,13,14,15,16,38,54,85,26,5,21])),`ProjectsPage`),ff=K(()=>q(()=>import(`./ProjectDetailPage-Cg8wQL8j.js`),__vite__mapDeps([116,1,7,4,8,9,73,3,74,58,5,6,75,28,35,12,13,14,15,16,37,40,115,38,54,85,26,21,84,67,61,117,92])),`ProjectDetailPage`),pf=K(()=>q(()=>import(`./FileManagerPage-BASV0fq8.js`),__vite__mapDeps([118,1,7,4,8,60,9,11,12,3,13,14,15,16,17,18,19,20,21,33,102,36,77,79,38,40,80,43,82,83,61,66,45,46,104,74,24,56,88,26,58,90,119,48,49,117,92])),`FileManagerPage`),mf=K(()=>q(()=>import(`./LibraryTrashPage-zY9GRWm9.js`),__vite__mapDeps([120,1,7,4,8,9,28,3,13,12,14,15,16,21,61])),`LibraryTrashPage`),hf=K(()=>q(()=>import(`./CameraPage-D1WovNYe.js`),__vite__mapDeps([121,1,7,4,8,9,3,13,12,14,15,16,50,33,48,26,19])),`CameraPage`),gf=K(()=>q(()=>import(`./CamWallPage-BDGEzKQE.js`),__vite__mapDeps([122,1,9,7,4,59,8,60,3,12,13,14,15,16,26,61])),`CamWallPage`),_f=K(()=>q(()=>import(`./StreamOverlayPage-H9AqKpdI.js`),__vite__mapDeps([123,1,7,4,9,33,3,95,109,61,70,124])),`StreamOverlayPage`),vf=K(()=>q(()=>import(`./ExternalLinkPage-BN4q7Gs-.js`),__vite__mapDeps([125,1,9,7,4,14,3,26])),`ExternalLinkPage`),yf=K(()=>q(()=>import(`./GroupEditPage-CMQ5Sk5q.js`),__vite__mapDeps([126,1,7,4,8,9,28,3,36,13,12,14,15,16,51,18,107,26,21,67])),`GroupEditPage`),bf=K(()=>q(()=>import(`./PrinterLocationsPage-Dj61FxW8.js`),__vite__mapDeps([127,1,7,4,8,60,9,3,28,33,12,13,14,15,16,53,18,21,67])),`PrinterLocationsPage`),xf=K(()=>q(()=>import(`./InventoryPage-o24Ni0S2.js`),__vite__mapDeps([128,1,2,3,4,5,6,7,8,60,9,22,23,24,25,26,27,30,31,32,36,12,76,13,14,15,16,79,37,46,104,105,21,54,18,113,58,100,89,39,44,67,69,129,83,106,63,61,130,131,132,65,66])),`default`),Sf=K(()=>q(()=>import(`./ModelSourcesPage-CI9pVpjC.js`),__vite__mapDeps([133,1,7,4,8,9,75,3,28,29,33,36,12,13,14,15,16,77,82,83,18,61,66,21,67,117,92])),`ModelSourcesPage`),Cf=K(()=>q(()=>import(`./SystemInfoPage-J8sIDAyN.js`),__vite__mapDeps([134,1,7,4,8,9,3,12,103,45,14,56,18,26,15,67,61])),`SystemInfoPage`),wf=K(()=>q(()=>import(`./LoginPage-DXBBHPDD.js`),__vite__mapDeps([135,1,8,7,4,9,13,3,12,14,15,16,107,108,21,67])),`LoginPage`),Tf=K(()=>q(()=>import(`./ConnectAuthorizePage-CIbOgIV8.js`),__vite__mapDeps([136,1,104,3,4,14,26])),`ConnectAuthorizePage`),Ef=K(()=>q(()=>import(`./SetupPage-D-ymjFl3.js`),__vite__mapDeps([137,1,8,7,4,12,3,13,14,15,16])),`SetupPage`),Df=K(()=>q(()=>import(`./NotificationsPage-DTBdRJe1.js`),__vite__mapDeps([138,1,7,4,8,9,13,3,12,14,15,16,21,67])),`NotificationsPage`),Of=K(()=>q(()=>import(`./GCodeViewerPage-BZpj3rht.js`),__vite__mapDeps([139,1,9,7,4,28,3,41,14,20])),`GCodeViewerPage`),kf=K(()=>q(()=>import(`./SpoolBuddyDashboard-0Mnwe1xw.js`),__vite__mapDeps([140,1,7,4,8,60,9,36,3,13,12,14,15,16,26,58,130,131,132,69,141])),`SpoolBuddyDashboard`),Af=K(()=>q(()=>import(`./SpoolBuddyAmsPage-BzUFeU61.js`),__vite__mapDeps([142,1,7,4,8,9,13,3,12,14,15,16,104,54,57,58,62,18,21,63,64,65,66,131,132,69,70])),`SpoolBuddyAmsPage`),jf=K(()=>q(()=>import(`./SpoolBuddySettingsPage-dHNHNIW3.js`),__vite__mapDeps([143,1,7,4,9,56,3,15,61])),`SpoolBuddySettingsPage`),Mf=K(()=>q(()=>import(`./SpoolBuddyCalibrationPage-C9Vz9h1f.js`),__vite__mapDeps([144,1,9,7,4])),`SpoolBuddyCalibrationPage`),Nf=K(()=>q(()=>import(`./SpoolBuddyWriteTagPage-CQovcCoW.js`),__vite__mapDeps([145,1,9,7,4,12,3,13,14,15,16,113,129,83,106,18,69,63,61,132])),`SpoolBuddyWriteTagPage`),Pf=K(()=>q(()=>import(`./SpoolBuddyInventoryPage-FFmQ5AMP.js`),__vite__mapDeps([146,1,7,4,8,9,36,3,13,12,14,15,16,54,18,26,58,130,131,132,69,141,65])),`SpoolBuddyInventoryPage`),Ff=class extends W.Component{state={error:null,errorInfo:null};static getDerivedStateFromError(e){return{error:e}}componentDidCatch(e,t){this.setState({errorInfo:t}),console.error(`React crash:`,e,t)}render(){return this.state.error?(0,Z.jsxs)(`div`,{style:{padding:24,color:`#ef4444`,backgroundColor:`#18181b`,minHeight:`100vh`,fontFamily:`monospace`},children:[(0,Z.jsx)(`h1`,{style:{fontSize:20,marginBottom:12},children:`UI Crash`}),(0,Z.jsx)(`pre`,{style:{whiteSpace:`pre-wrap`,fontSize:14},children:this.state.error.message}),(0,Z.jsx)(`pre`,{style:{whiteSpace:`pre-wrap`,fontSize:12,color:`#a1a1aa`,marginTop:12},children:this.state.error.stack}),(0,Z.jsx)(`button`,{onClick:()=>{this.setState({error:null,errorInfo:null})},style:{marginTop:16,padding:`8px 16px`,backgroundColor:`#3b82f6`,color:`#fff`,border:`none`,borderRadius:8,cursor:`pointer`},children:`Retry`})]}):this.props.children}},If=new Ua({defaultOptions:{queries:{staleTime:1e3*60,retry:1}}});function Lf(){return Od(),null}function Rf({children:e}){return yd(),Td(),(0,Z.jsx)(Z.Fragment,{children:e})}function zf({children:e}){let{authEnabled:t,loading:n,user:r}=Os(),i=qr();return n?(0,Z.jsx)(`div`,{className:`min-h-screen flex items-center justify-center`,children:`Loading...`}):t&&!r?(0,Z.jsx)(Ti,{to:`/login`,replace:!0,state:{from:i}}):(0,Z.jsx)(Z.Fragment,{children:e})}function Bf({permission:e,children:t}){let{authEnabled:n,loading:r,user:i,hasPermission:a}=Os(),o=qr();return r?(0,Z.jsx)(`div`,{className:`min-h-screen flex items-center justify-center`,children:`Loading...`}):n?i?(Array.isArray(e)?e:[e]).some(e=>a(e))?(0,Z.jsx)(Z.Fragment,{children:t}):(0,Z.jsx)(Ti,{to:`/`,replace:!0}):(0,Z.jsx)(Ti,{to:`/login`,replace:!0,state:{from:o}}):(0,Z.jsx)(Z.Fragment,{children:t})}function Vf({children:e}){let{authEnabled:t,loading:n}=Os();return n?(0,Z.jsx)(`div`,{className:`min-h-screen flex items-center justify-center`,children:`Loading...`}):t?(0,Z.jsx)(Ti,{to:`/login`,replace:!0}):(0,Z.jsx)(Z.Fragment,{children:e})}function Hf(){return(0,Z.jsx)(Ff,{children:(0,Z.jsx)(me,{children:(0,Z.jsx)(te,{client:If,children:(0,Z.jsx)(Ds,{children:(0,Z.jsx)(As,{children:(0,Z.jsx)(Rd,{children:(0,Z.jsxs)(Id,{children:[(0,Z.jsx)(Lf,{}),(0,Z.jsx)(ga,{children:(0,Z.jsx)(W.Suspense,{fallback:(0,Z.jsx)(Ts,{fullScreen:!0}),children:(0,Z.jsxs)(Di,{children:[(0,Z.jsx)(Y,{path:`/setup`,element:(0,Z.jsx)(Vf,{children:(0,Z.jsx)(Ef,{})})}),(0,Z.jsx)(Y,{path:`/login`,element:(0,Z.jsx)(wf,{})}),(0,Z.jsx)(Y,{path:`/connect/authorize`,element:(0,Z.jsx)(zf,{children:(0,Z.jsx)(Tf,{})})}),(0,Z.jsx)(Y,{path:`/camera/:printerId`,element:(0,Z.jsx)(hf,{})}),(0,Z.jsx)(Y,{path:`/overlay/:printerId`,element:(0,Z.jsx)(_f,{})}),(0,Z.jsx)(Y,{path:`/camwall`,element:(0,Z.jsx)(gf,{})}),(0,Z.jsxs)(Y,{element:(0,Z.jsx)(zf,{children:(0,Z.jsx)(Rf,{children:(0,Z.jsx)(tf,{})})}),children:[(0,Z.jsx)(Y,{path:`spoolbuddy`,element:(0,Z.jsx)(kf,{})}),(0,Z.jsx)(Y,{path:`spoolbuddy/ams`,element:(0,Z.jsx)(Af,{})}),(0,Z.jsx)(Y,{path:`spoolbuddy/write-tag`,element:(0,Z.jsx)(Nf,{})}),(0,Z.jsx)(Y,{path:`spoolbuddy/inventory`,element:(0,Z.jsx)(Pf,{})}),(0,Z.jsx)(Y,{path:`spoolbuddy/settings`,element:(0,Z.jsx)(jf,{})}),(0,Z.jsx)(Y,{path:`spoolbuddy/calibration`,element:(0,Z.jsx)(Mf,{})})]}),(0,Z.jsxs)(Y,{element:(0,Z.jsx)(zf,{children:(0,Z.jsx)(Rf,{children:(0,Z.jsx)(pd,{})})}),children:[(0,Z.jsx)(Y,{index:!0,element:(0,Z.jsx)(nf,{})}),(0,Z.jsx)(Y,{path:`archives`,element:(0,Z.jsx)(rf,{})}),(0,Z.jsx)(Y,{path:`queue`,element:(0,Z.jsx)(af,{})}),(0,Z.jsx)(Y,{path:`pipelines/runs`,element:(0,Z.jsx)(Ti,{to:`/queue?tab=pipelines`,replace:!0})}),(0,Z.jsx)(Y,{path:`stats`,element:(0,Z.jsx)(of,{})}),(0,Z.jsx)(Y,{path:`profiles`,element:(0,Z.jsx)(lf,{})}),(0,Z.jsx)(Y,{path:`finance`,element:(0,Z.jsx)(Bf,{permission:`cost_centers:read_own`,children:(0,Z.jsx)(cf,{})})}),(0,Z.jsx)(Y,{path:`maintenance`,element:(0,Z.jsx)(uf,{})}),(0,Z.jsx)(Y,{path:`projects`,element:(0,Z.jsx)(df,{})}),(0,Z.jsx)(Y,{path:`projects/:id`,element:(0,Z.jsx)(ff,{})}),(0,Z.jsx)(Y,{path:`inventory`,element:(0,Z.jsx)(xf,{})}),(0,Z.jsx)(Y,{path:`files`,element:(0,Z.jsx)(pf,{})}),(0,Z.jsx)(Y,{path:`files/trash`,element:(0,Z.jsx)(mf,{})}),(0,Z.jsx)(Y,{path:`model-sources`,element:(0,Z.jsx)(Bf,{permission:[`makerworld:view`,`manyfold:view`],children:(0,Z.jsx)(Sf,{})})}),(0,Z.jsx)(Y,{path:`makerworld`,element:(0,Z.jsx)(Ti,{to:`/model-sources?tab=makerworld`,replace:!0})}),(0,Z.jsx)(Y,{path:`settings`,element:(0,Z.jsx)(Bf,{permission:`settings:read`,children:(0,Z.jsx)(sf,{})})}),(0,Z.jsx)(Y,{path:`groups/new`,element:(0,Z.jsx)(Bf,{permission:`groups:create`,children:(0,Z.jsx)(yf,{})})}),(0,Z.jsx)(Y,{path:`groups/:id/edit`,element:(0,Z.jsx)(Bf,{permission:`groups:update`,children:(0,Z.jsx)(yf,{})})}),(0,Z.jsx)(Y,{path:`printer-locations`,element:(0,Z.jsx)(Bf,{permission:`printers:read`,children:(0,Z.jsx)(bf,{})})}),(0,Z.jsx)(Y,{path:`users`,element:(0,Z.jsx)(Ti,{to:`/settings?tab=users`,replace:!0})}),(0,Z.jsx)(Y,{path:`groups`,element:(0,Z.jsx)(Ti,{to:`/settings?tab=users`,replace:!0})}),(0,Z.jsx)(Y,{path:`system`,element:(0,Z.jsx)(Cf,{})}),(0,Z.jsx)(Y,{path:`notifications`,element:(0,Z.jsx)(Df,{})}),(0,Z.jsx)(Y,{path:`gcode-viewer`,element:(0,Z.jsx)(Of,{})}),(0,Z.jsx)(Y,{path:`external/:id`,element:(0,Z.jsx)(vf,{})}),(0,Z.jsx)(Y,{path:`camera-tokens`,element:(0,Z.jsx)(Ti,{to:`/settings?tab=camera#card-camera-tokens`,replace:!0})})]})]})})})]})})})})})})})}var Uf=3e3;Promise.race([Sn,new Promise(e=>setTimeout(e,Uf))]).catch(()=>{}).then(()=>{(0,ze.createRoot)(document.getElementById(`root`)).render((0,Z.jsx)(W.StrictMode,{children:(0,Z.jsx)(Hf,{})}))});export{Dc as $,Vo as $t,El as A,eo as An,ms as At,Nc as B,qr as Bn,rs as Bt,mu as C,uo as Cn,xs as Ct,Il as D,ro as Dn,_s as Dt,Vl as E,io as En,vs as Et,_l as F,Ja as Fn,cs as Ft,qc as G,wn as Gn,Zo as Gt,Vc as H,$r as Hn,ts as Ht,gl as I,Ga as In,ss as It,Wc as J,qo as Jt,Uc as K,q as Kn,Xo as Kt,hl as L,Wa as Ln,os as Lt,xl as M,Za as Mn,fs as Mt,bl as N,Xa as Nn,ds as Nt,zl as O,X as On,gs as Ot,yl as P,Ya as Pn,us as Pt,wc as Q,Uo as Qt,fl as R,va as Rn,as as Rt,pu as S,fo as Sn,Ss as St,Wl as T,so as Tn,ys as Tt,Oc as U,ti as Un,$o as Ut,ol as V,Xr as Vn,ns as Vt,Bc as W,Ea as Wn,Qo as Wt,rl as X,Go as Xt,tl as Y,Ko as Yt,Cc as Z,Wo as Zt,ku as _,_o as _n,Is as _t,vd as a,Mo as an,pc as at,wu as b,mo as bn,ws as bt,ud as c,ko as cn,rc as ct,cd as d,To as dn,lc as dt,Bo as en,nl as et,od as f,wo as fn,ac as ft,Nu as g,yo as gn,Bs as gt,Pu as h,bo as hn,Vs as ht,_d as i,No as in,mc as it,wl as j,Qa as jn,ps as jt,Bl as k,to as kn,hs as kt,dd as l,Do as ln,cc as lt,sd as m,xo as mn,zs as mt,Od as n,Ro as nn,hc as nt,md as o,jo as on,dc as ot,ld as p,Co as pn,oc as pt,Hc as q,Jo as qt,hd as r,Lo as rn,gc as rt,gd as s,Ao as sn,nc as st,Ld as t,zo as tn,il as tt,fd as u,Eo as un,uc as ut,Du as v,go as vn,js as vt,ql as w,lo as wn,bs as wt,fu as x,po as xn,Cs as xt,Tu as y,ho as yn,Os as yt,Tc as z,Ti as zn,is as zt}; \ No newline at end of file diff --git a/static/assets/inventorySearch-C_D57LMP.js b/static/assets/inventorySearch-TJiB5tGt.js similarity index 92% rename from static/assets/inventorySearch-C_D57LMP.js rename to static/assets/inventorySearch-TJiB5tGt.js index 201bba905..16db22175 100644 --- a/static/assets/inventorySearch-C_D57LMP.js +++ b/static/assets/inventorySearch-TJiB5tGt.js @@ -1 +1 @@ -import{ft as e}from"./index-0t--Yqoi.js";function t(t,n){let r=n.trim().toLowerCase();if(!r)return!0;let i=r.match(/^#(\d+)$/);return i?t.id===Number(i[1]):String(t.id).includes(r)||t.material.toLowerCase().includes(r)||(t.brand?.toLowerCase().includes(r)??!1)||(t.color_name?.toLowerCase().includes(r)??!1)||(e(t.color_name,t.rgba,t.color_name_is_synthesized)?.toLowerCase().includes(r)??!1)||(t.subtype?.toLowerCase().includes(r)??!1)||(t.note?.toLowerCase().includes(r)??!1)||(t.slicer_filament_name?.toLowerCase().includes(r)??!1)||(t.storage_location?.toLowerCase().includes(r)??!1)||(t.material_number?.toLowerCase().includes(r)??!1)||(t.suppliers?.some(e=>e.supplier_name.toLowerCase().includes(r)||(e.supplier_article_number?.toLowerCase().includes(r)??!1))??!1)}function n(e,n){return n?e.filter(e=>t(e,n)):e}export{n as t}; \ No newline at end of file +import{ft as e}from"./index-Cxa-KVmA.js";function t(t,n){let r=n.trim().toLowerCase();if(!r)return!0;let i=r.match(/^#(\d+)$/);return i?t.id===Number(i[1]):String(t.id).includes(r)||t.material.toLowerCase().includes(r)||(t.brand?.toLowerCase().includes(r)??!1)||(t.color_name?.toLowerCase().includes(r)??!1)||(e(t.color_name,t.rgba,t.color_name_is_synthesized)?.toLowerCase().includes(r)??!1)||(t.subtype?.toLowerCase().includes(r)??!1)||(t.note?.toLowerCase().includes(r)??!1)||(t.slicer_filament_name?.toLowerCase().includes(r)??!1)||(t.storage_location?.toLowerCase().includes(r)??!1)||(t.material_number?.toLowerCase().includes(r)??!1)||(t.suppliers?.some(e=>e.supplier_name.toLowerCase().includes(r)||(e.supplier_article_number?.toLowerCase().includes(r)??!1))??!1)}function n(e,n){return n?e.filter(e=>t(e,n)):e}export{n as t}; \ No newline at end of file diff --git a/static/assets/locationSensorDefaults-Bb4u9P8m.js b/static/assets/locationSensorDefaults-DcLWzMwe.js similarity index 99% rename from static/assets/locationSensorDefaults-Bb4u9P8m.js rename to static/assets/locationSensorDefaults-DcLWzMwe.js index b7602a88b..c86a4cead 100644 --- a/static/assets/locationSensorDefaults-Bb4u9P8m.js +++ b/static/assets/locationSensorDefaults-DcLWzMwe.js @@ -1 +1 @@ -import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,w as i}from"./client-DnySrlFv.js";import{n as a}from"./QueryClientProvider-Ce8_sN3w.js";import{t as o}from"./useQuery-BBCjCezC.js";import{t as s}from"./useMutation-B-Tr2hIP.js";import{t as c}from"./createLucideIcon-DvBYJlWL.js";import{n as l}from"./ToastContext-BRX0SW3C.js";import{t as u}from"./loader-circle-BEmFtawu.js";import{t as d}from"./x-DR-Trv6U.js";import{t as f}from"./Button-DDr6eAFy.js";import{$t as p,At as m,Zt as h,_t as g,o as _,r as v}from"./index-0t--Yqoi.js";var y=c(`map-pin`,[[`path`,{d:`M20 10c0 4.993-5.539 10.193-7.399 11.799a1 1 0 0 1-1.202 0C9.539 20.193 4 14.993 4 10a8 8 0 0 1 16 0`,key:`1r0f0z`}],[`circle`,{cx:`12`,cy:`10`,r:`3`,key:`ilqhr7`}]]),b=c(`pen`,[[`path`,{d:`M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z`,key:`1a8usu`}]]),x=e(n(),1),S=t();function C({open:e,onClose:t,onPickLocation:n,startCreating:c}){let{t:b}=i(),C=a(),{showToast:w}=l(),[T,E]=(0,x.useState)(!1),[D,O]=(0,x.useState)(null),[k,A]=(0,x.useState)(``),[j,M]=(0,x.useState)(null),{data:N=[],isLoading:P}=o({queryKey:_,queryFn:r.getLocations,enabled:e}),{data:F=[]}=o({queryKey:[`locationHaSensors`],queryFn:()=>r.getLocationHASensors(),enabled:e}),I=F.reduce((e,t)=>(e[t.location_id]=(e[t.location_id]??0)+1,e),{}),L=()=>{v(C),C.invalidateQueries({queryKey:[`inventory-spools`]}),C.invalidateQueries({queryKey:[`spoolman-inventory-spools`]}),C.invalidateQueries({queryKey:[`locationHaSensors`]}),C.invalidateQueries({queryKey:[`locationHaSensorReadings`]})},R=s({mutationFn:async()=>{let e=k.trim();if(!e)throw Error(b(`locations.nameRequired`));return D?r.updateLocation(D.id,{name:e}):r.createLocation({name:e})},onSuccess:e=>{if(w(b(D?`locations.updated`:`locations.created`),`success`),L(),!D&&c){n?.(e.id),t();return}E(!1),O(null),A(``)},onError:e=>{w(e.message||b(`locations.saveFailed`),`error`)}}),z=s({mutationFn:e=>r.deleteLocation(e),onSuccess:()=>{w(b(`locations.deleted`),`success`),M(null),L()},onError:e=>{w(e.message||b(`locations.deleteFailed`),`error`)}}),B=()=>{O(null),A(``),E(!0)};(0,x.useEffect)(()=>{e&&c&&(O(null),A(``),E(!0))},[e,c]);let V=e=>{O(e),A(e.name),E(!0)},H=(0,x.useCallback)(()=>{if(!R.isPending){if(c){t();return}E(!1),O(null),A(``)}},[R.isPending,c,t]);(0,x.useEffect)(()=>{if(!e)return;let n=e=>{e.key===`Escape`&&(R.isPending||z.isPending||(T?H():j||t()))};return document.addEventListener(`keydown`,n),()=>document.removeEventListener(`keydown`,n)},[e,T,j,R.isPending,z.isPending,H,t]);let U=e=>{e.preventDefault(),R.mutate()};if(!e)return null;let W=`locations-modal-title`,G=`location-editor-title`,K=(0,S.jsxs)(`form`,{onSubmit:U,children:[(0,S.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,htmlFor:`location-name`,children:b(`locations.name`)}),(0,S.jsx)(`input`,{id:`location-name`,type:`text`,maxLength:255,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green mb-4`,placeholder:b(`locations.createPlaceholder`),value:k,onChange:e=>A(e.target.value),autoFocus:!0}),(0,S.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,S.jsx)(f,{type:`button`,variant:`secondary`,onClick:H,children:b(`common.cancel`)}),(0,S.jsxs)(f,{type:`submit`,disabled:R.isPending||!k.trim(),children:[R.isPending&&(0,S.jsx)(u,{className:`w-4 h-4 animate-spin`}),b(`common.save`)]})]})]});return c?T?(0,S.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[(0,S.jsx)(`div`,{className:`absolute inset-0 bg-black/60`,onClick:H}),(0,S.jsxs)(`div`,{className:`relative w-full max-w-md mx-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl p-6 shadow-2xl`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":G,children:[(0,S.jsx)(`h3`,{id:G,className:`text-lg font-semibold text-white mb-4`,children:b(`locations.add`)}),K]})]}):null:(0,S.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[(0,S.jsx)(`div`,{className:`absolute inset-0 bg-black/60`,onClick:()=>{R.isPending||z.isPending||t()}}),(0,S.jsxs)(`div`,{className:`relative w-full max-w-2xl 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":W,children:[(0,S.jsxs)(`div`,{className:`flex items-center justify-between gap-4 px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,S.jsxs)(`div`,{children:[(0,S.jsxs)(`h2`,{id:W,className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,S.jsx)(y,{className:`w-5 h-5 text-bambu-green`}),b(`locations.title`)]}),(0,S.jsx)(`p`,{className:`text-bambu-gray text-sm mt-0.5`,children:b(`locations.subtitle`)})]}),(0,S.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,S.jsxs)(f,{onClick:B,children:[(0,S.jsx)(h,{className:`w-4 h-4`}),b(`locations.add`)]}),(0,S.jsx)(`button`,{type:`button`,className:`p-1.5 text-bambu-gray hover:text-white rounded`,onClick:t,"aria-label":b(`common.close`),children:(0,S.jsx)(d,{className:`w-5 h-5`})})]})]}),(0,S.jsx)(`div`,{className:`overflow-y-auto`,children:P?(0,S.jsxs)(`div`,{className:`flex items-center justify-center py-16 text-bambu-gray`,children:[(0,S.jsx)(u,{className:`w-6 h-6 animate-spin mr-2`}),b(`common.loading`)]}):N.length===0?(0,S.jsx)(`div`,{className:`py-16 text-center text-bambu-gray`,children:b(`locations.empty`)}):(0,S.jsxs)(`table`,{className:`w-full text-sm table-fixed`,children:[(0,S.jsx)(`thead`,{children:(0,S.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary text-left text-bambu-gray`,children:[(0,S.jsx)(`th`,{className:`px-4 py-3 font-medium`,children:b(`locations.name`)}),(0,S.jsx)(`th`,{className:`px-2 py-3 font-medium text-right w-24`,children:b(`locations.sensors`)}),(0,S.jsx)(`th`,{className:`pl-[28px] pr-4 py-3 font-medium text-right w-28`,children:b(`locations.spools`)}),(0,S.jsx)(`th`,{className:`px-4 py-3 font-medium text-right w-32`,children:b(`common.actions`)})]})}),(0,S.jsx)(`tbody`,{children:N.map(e=>(0,S.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/60 hover:bg-bambu-dark-tertiary/30 cursor-pointer`,onClick:()=>{n&&(n(e.id),t())},children:[(0,S.jsx)(`td`,{className:`px-4 py-3 text-white font-medium truncate`,children:e.name}),(0,S.jsx)(`td`,{className:`px-2 py-3 text-right text-bambu-gray`,children:I[e.id]??0}),(0,S.jsx)(`td`,{className:`pl-[28px] pr-4 py-3 text-right text-bambu-gray`,children:e.spool_count}),(0,S.jsx)(`td`,{className:`px-4 py-3 text-right`,onClick:e=>e.stopPropagation(),children:(0,S.jsxs)(`div`,{className:`flex items-center justify-end gap-1`,children:[(0,S.jsx)(`button`,{type:`button`,className:`p-1.5 text-bambu-gray hover:text-bambu-green rounded`,onClick:()=>V(e),title:b(`common.edit`),"aria-label":b(`locations.editAria`,{name:e.name,defaultValue:`Edit ${e.name}`}),children:(0,S.jsx)(p,{className:`w-4 h-4`})}),(0,S.jsx)(`button`,{type:`button`,className:`p-1.5 text-bambu-gray hover:text-red-600 dark:hover:text-red-400 rounded disabled:opacity-40`,disabled:e.spool_count>0,onClick:()=>M(e),title:e.spool_count>0?b(`locations.deleteBlocked`):b(`common.delete`),"aria-label":b(`locations.deleteAria`,{name:e.name,defaultValue:`Delete ${e.name}`}),children:(0,S.jsx)(m,{className:`w-4 h-4`})})]})})]},e.id))})]})})]}),T&&(0,S.jsxs)(`div`,{className:`fixed inset-0 z-[60] flex items-center justify-center`,children:[(0,S.jsx)(`div`,{className:`absolute inset-0 bg-black/60`,onClick:H}),(0,S.jsxs)(`div`,{className:`relative w-full max-w-md mx-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl p-6 shadow-2xl`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":G,children:[(0,S.jsx)(`h3`,{id:G,className:`text-lg font-semibold text-white mb-4`,children:b(D?`locations.edit`:`locations.add`)}),K]})]}),j&&(0,S.jsx)(g,{title:b(`locations.confirmDelete`,{name:j.name}),message:I[j.id]?b(`locations.confirmDeleteMessageWithSensors`):b(`locations.confirmDeleteMessage`),confirmText:b(`common.delete`),variant:`danger`,isLoading:z.isPending,onConfirm:()=>z.mutate(j.id),onCancel:()=>M(null)})]})}var w=`bambuddy-location-sensor-show-on-card-defaults`,T={alertAbove:``,alertBelow:``,notifyOnAlert:!1,showOnCard:!0};function E(){return{temperature:{...T,alertAbove:`30`,alertBelow:`20`},humidity:{...T,alertAbove:`30`,alertBelow:`10`},battery:{...T,alertBelow:`10`}}}function D(){try{let e=localStorage.getItem(w);return e?JSON.parse(e):{}}catch{return{}}}function O(e){let t=E();if(e)try{let n=JSON.parse(e);Object.keys(t).forEach(e=>{let r=n[e];r&&(typeof r.alertAbove==`string`&&(t[e].alertAbove=r.alertAbove),typeof r.alertBelow==`string`&&(t[e].alertBelow=r.alertBelow),typeof r.notifyOnAlert==`boolean`&&(t[e].notifyOnAlert=r.notifyOnAlert))})}catch{}let n=D();return Object.keys(t).forEach(e=>{typeof n[e]==`boolean`&&(t[e].showOnCard=n[e])}),t}function k(e){let t={};return Object.keys(e).forEach(n=>{t[n]={alertAbove:e[n].alertAbove,alertBelow:e[n].alertBelow,notifyOnAlert:e[n].notifyOnAlert}}),JSON.stringify(t)}function A(e){try{let t={};Object.keys(e).forEach(n=>{t[n]=e[n].showOnCard}),localStorage.setItem(w,JSON.stringify(t))}catch{return}}var j=`bambuddy-location-sensor-colorize-values`;function M(){try{let e=localStorage.getItem(j);return e?e===`true`:!0}catch{return!0}}var N=`bambuddy:location-sensor-color-prefs-changed`;function P(){window.dispatchEvent(new Event(N))}function F(e){try{localStorage.setItem(j,String(e))}catch{return}P()}var I=[`red`,`orange`,`yellow`,`green`,`blue`,`purple`,`pink`],L={red:`text-red-400`,orange:`text-orange-400`,yellow:`text-yellow-400`,green:`text-green-400`,blue:`text-blue-400`,purple:`text-purple-400`,pink:`text-pink-400`},R=`bambuddy-location-sensor-alert-above-color`,z=`bambuddy-location-sensor-alert-below-color`,B=`bambuddy-location-sensor-alert-optimal-color`;function V(e){return!!e&&I.includes(e)}function H(){try{let e=localStorage.getItem(R);return V(e)?e:`purple`}catch{return`purple`}}function U(e){try{localStorage.setItem(R,e)}catch{return}P()}function W(){try{let e=localStorage.getItem(z);return V(e)?e:`red`}catch{return`red`}}function G(e){try{localStorage.setItem(z,e)}catch{return}P()}function K(){try{let e=localStorage.getItem(B);return V(e)?e:`green`}catch{return`green`}}function q(e){try{localStorage.setItem(B,e)}catch{return}P()}function J(){return{colorize:M(),aboveColor:H(),belowColor:W(),optimalColor:K()}}function Y(){let[e,t]=(0,x.useState)(J);return(0,x.useEffect)(()=>{let e=()=>t(J());return window.addEventListener(N,e),()=>window.removeEventListener(N,e)},[]),e}function X(e){return!e.reachable||e.state===null?null:e.kind===`numeric`?e.alert_above===null&&e.alert_below===null||e.value===null?null:e.alert_above!==null&&e.value>e.alert_above?`above`:e.alert_below!==null&&e.valuer.getLocationHASensors(),enabled:e}),I=F.reduce((e,t)=>(e[t.location_id]=(e[t.location_id]??0)+1,e),{}),L=()=>{v(C),C.invalidateQueries({queryKey:[`inventory-spools`]}),C.invalidateQueries({queryKey:[`spoolman-inventory-spools`]}),C.invalidateQueries({queryKey:[`locationHaSensors`]}),C.invalidateQueries({queryKey:[`locationHaSensorReadings`]})},R=s({mutationFn:async()=>{let e=k.trim();if(!e)throw Error(b(`locations.nameRequired`));return D?r.updateLocation(D.id,{name:e}):r.createLocation({name:e})},onSuccess:e=>{if(w(b(D?`locations.updated`:`locations.created`),`success`),L(),!D&&c){n?.(e.id),t();return}E(!1),O(null),A(``)},onError:e=>{w(e.message||b(`locations.saveFailed`),`error`)}}),z=s({mutationFn:e=>r.deleteLocation(e),onSuccess:()=>{w(b(`locations.deleted`),`success`),M(null),L()},onError:e=>{w(e.message||b(`locations.deleteFailed`),`error`)}}),B=()=>{O(null),A(``),E(!0)};(0,x.useEffect)(()=>{e&&c&&(O(null),A(``),E(!0))},[e,c]);let V=e=>{O(e),A(e.name),E(!0)},H=(0,x.useCallback)(()=>{if(!R.isPending){if(c){t();return}E(!1),O(null),A(``)}},[R.isPending,c,t]);(0,x.useEffect)(()=>{if(!e)return;let n=e=>{e.key===`Escape`&&(R.isPending||z.isPending||(T?H():j||t()))};return document.addEventListener(`keydown`,n),()=>document.removeEventListener(`keydown`,n)},[e,T,j,R.isPending,z.isPending,H,t]);let U=e=>{e.preventDefault(),R.mutate()};if(!e)return null;let W=`locations-modal-title`,G=`location-editor-title`,K=(0,S.jsxs)(`form`,{onSubmit:U,children:[(0,S.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,htmlFor:`location-name`,children:b(`locations.name`)}),(0,S.jsx)(`input`,{id:`location-name`,type:`text`,maxLength:255,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green mb-4`,placeholder:b(`locations.createPlaceholder`),value:k,onChange:e=>A(e.target.value),autoFocus:!0}),(0,S.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,S.jsx)(f,{type:`button`,variant:`secondary`,onClick:H,children:b(`common.cancel`)}),(0,S.jsxs)(f,{type:`submit`,disabled:R.isPending||!k.trim(),children:[R.isPending&&(0,S.jsx)(u,{className:`w-4 h-4 animate-spin`}),b(`common.save`)]})]})]});return c?T?(0,S.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[(0,S.jsx)(`div`,{className:`absolute inset-0 bg-black/60`,onClick:H}),(0,S.jsxs)(`div`,{className:`relative w-full max-w-md mx-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl p-6 shadow-2xl`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":G,children:[(0,S.jsx)(`h3`,{id:G,className:`text-lg font-semibold text-white mb-4`,children:b(`locations.add`)}),K]})]}):null:(0,S.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[(0,S.jsx)(`div`,{className:`absolute inset-0 bg-black/60`,onClick:()=>{R.isPending||z.isPending||t()}}),(0,S.jsxs)(`div`,{className:`relative w-full max-w-2xl 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":W,children:[(0,S.jsxs)(`div`,{className:`flex items-center justify-between gap-4 px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,S.jsxs)(`div`,{children:[(0,S.jsxs)(`h2`,{id:W,className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,S.jsx)(y,{className:`w-5 h-5 text-bambu-green`}),b(`locations.title`)]}),(0,S.jsx)(`p`,{className:`text-bambu-gray text-sm mt-0.5`,children:b(`locations.subtitle`)})]}),(0,S.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,S.jsxs)(f,{onClick:B,children:[(0,S.jsx)(h,{className:`w-4 h-4`}),b(`locations.add`)]}),(0,S.jsx)(`button`,{type:`button`,className:`p-1.5 text-bambu-gray hover:text-white rounded`,onClick:t,"aria-label":b(`common.close`),children:(0,S.jsx)(d,{className:`w-5 h-5`})})]})]}),(0,S.jsx)(`div`,{className:`overflow-y-auto`,children:P?(0,S.jsxs)(`div`,{className:`flex items-center justify-center py-16 text-bambu-gray`,children:[(0,S.jsx)(u,{className:`w-6 h-6 animate-spin mr-2`}),b(`common.loading`)]}):N.length===0?(0,S.jsx)(`div`,{className:`py-16 text-center text-bambu-gray`,children:b(`locations.empty`)}):(0,S.jsxs)(`table`,{className:`w-full text-sm table-fixed`,children:[(0,S.jsx)(`thead`,{children:(0,S.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary text-left text-bambu-gray`,children:[(0,S.jsx)(`th`,{className:`px-4 py-3 font-medium`,children:b(`locations.name`)}),(0,S.jsx)(`th`,{className:`px-2 py-3 font-medium text-right w-24`,children:b(`locations.sensors`)}),(0,S.jsx)(`th`,{className:`pl-[28px] pr-4 py-3 font-medium text-right w-28`,children:b(`locations.spools`)}),(0,S.jsx)(`th`,{className:`px-4 py-3 font-medium text-right w-32`,children:b(`common.actions`)})]})}),(0,S.jsx)(`tbody`,{children:N.map(e=>(0,S.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/60 hover:bg-bambu-dark-tertiary/30 cursor-pointer`,onClick:()=>{n&&(n(e.id),t())},children:[(0,S.jsx)(`td`,{className:`px-4 py-3 text-white font-medium truncate`,children:e.name}),(0,S.jsx)(`td`,{className:`px-2 py-3 text-right text-bambu-gray`,children:I[e.id]??0}),(0,S.jsx)(`td`,{className:`pl-[28px] pr-4 py-3 text-right text-bambu-gray`,children:e.spool_count}),(0,S.jsx)(`td`,{className:`px-4 py-3 text-right`,onClick:e=>e.stopPropagation(),children:(0,S.jsxs)(`div`,{className:`flex items-center justify-end gap-1`,children:[(0,S.jsx)(`button`,{type:`button`,className:`p-1.5 text-bambu-gray hover:text-bambu-green rounded`,onClick:()=>V(e),title:b(`common.edit`),"aria-label":b(`locations.editAria`,{name:e.name,defaultValue:`Edit ${e.name}`}),children:(0,S.jsx)(p,{className:`w-4 h-4`})}),(0,S.jsx)(`button`,{type:`button`,className:`p-1.5 text-bambu-gray hover:text-red-600 dark:hover:text-red-400 rounded disabled:opacity-40`,disabled:e.spool_count>0,onClick:()=>M(e),title:e.spool_count>0?b(`locations.deleteBlocked`):b(`common.delete`),"aria-label":b(`locations.deleteAria`,{name:e.name,defaultValue:`Delete ${e.name}`}),children:(0,S.jsx)(m,{className:`w-4 h-4`})})]})})]},e.id))})]})})]}),T&&(0,S.jsxs)(`div`,{className:`fixed inset-0 z-[60] flex items-center justify-center`,children:[(0,S.jsx)(`div`,{className:`absolute inset-0 bg-black/60`,onClick:H}),(0,S.jsxs)(`div`,{className:`relative w-full max-w-md mx-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl p-6 shadow-2xl`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":G,children:[(0,S.jsx)(`h3`,{id:G,className:`text-lg font-semibold text-white mb-4`,children:b(D?`locations.edit`:`locations.add`)}),K]})]}),j&&(0,S.jsx)(g,{title:b(`locations.confirmDelete`,{name:j.name}),message:I[j.id]?b(`locations.confirmDeleteMessageWithSensors`):b(`locations.confirmDeleteMessage`),confirmText:b(`common.delete`),variant:`danger`,isLoading:z.isPending,onConfirm:()=>z.mutate(j.id),onCancel:()=>M(null)})]})}var w=`bambuddy-location-sensor-show-on-card-defaults`,T={alertAbove:``,alertBelow:``,notifyOnAlert:!1,showOnCard:!0};function E(){return{temperature:{...T,alertAbove:`30`,alertBelow:`20`},humidity:{...T,alertAbove:`30`,alertBelow:`10`},battery:{...T,alertBelow:`10`}}}function D(){try{let e=localStorage.getItem(w);return e?JSON.parse(e):{}}catch{return{}}}function O(e){let t=E();if(e)try{let n=JSON.parse(e);Object.keys(t).forEach(e=>{let r=n[e];r&&(typeof r.alertAbove==`string`&&(t[e].alertAbove=r.alertAbove),typeof r.alertBelow==`string`&&(t[e].alertBelow=r.alertBelow),typeof r.notifyOnAlert==`boolean`&&(t[e].notifyOnAlert=r.notifyOnAlert))})}catch{}let n=D();return Object.keys(t).forEach(e=>{typeof n[e]==`boolean`&&(t[e].showOnCard=n[e])}),t}function k(e){let t={};return Object.keys(e).forEach(n=>{t[n]={alertAbove:e[n].alertAbove,alertBelow:e[n].alertBelow,notifyOnAlert:e[n].notifyOnAlert}}),JSON.stringify(t)}function A(e){try{let t={};Object.keys(e).forEach(n=>{t[n]=e[n].showOnCard}),localStorage.setItem(w,JSON.stringify(t))}catch{return}}var j=`bambuddy-location-sensor-colorize-values`;function M(){try{let e=localStorage.getItem(j);return e?e===`true`:!0}catch{return!0}}var N=`bambuddy:location-sensor-color-prefs-changed`;function P(){window.dispatchEvent(new Event(N))}function F(e){try{localStorage.setItem(j,String(e))}catch{return}P()}var I=[`red`,`orange`,`yellow`,`green`,`blue`,`purple`,`pink`],L={red:`text-red-400`,orange:`text-orange-400`,yellow:`text-yellow-400`,green:`text-green-400`,blue:`text-blue-400`,purple:`text-purple-400`,pink:`text-pink-400`},R=`bambuddy-location-sensor-alert-above-color`,z=`bambuddy-location-sensor-alert-below-color`,B=`bambuddy-location-sensor-alert-optimal-color`;function V(e){return!!e&&I.includes(e)}function H(){try{let e=localStorage.getItem(R);return V(e)?e:`purple`}catch{return`purple`}}function U(e){try{localStorage.setItem(R,e)}catch{return}P()}function W(){try{let e=localStorage.getItem(z);return V(e)?e:`red`}catch{return`red`}}function G(e){try{localStorage.setItem(z,e)}catch{return}P()}function K(){try{let e=localStorage.getItem(B);return V(e)?e:`green`}catch{return`green`}}function q(e){try{localStorage.setItem(B,e)}catch{return}P()}function J(){return{colorize:M(),aboveColor:H(),belowColor:W(),optimalColor:K()}}function Y(){let[e,t]=(0,x.useState)(J);return(0,x.useEffect)(()=>{let e=()=>t(J());return window.addEventListener(N,e),()=>window.removeEventListener(N,e)},[]),e}function X(e){return!e.reachable||e.state===null?null:e.kind===`numeric`?e.alert_above===null&&e.alert_below===null||e.value===null?null:e.alert_above!==null&&e.value>e.alert_above?`above`:e.alert_below!==null&&e.value2?n:r(t),o=new e(a);a>i;)o[i]=t[i++];return o}},9617(e,t,n){var r=n(5397),i=n(5610),a=n(6198),o=function(e){return function(t,n,o){var s=r(t),c=a(s);if(c===0)return!e&&-1;var l=i(o,c),u;if(e&&n!==n){for(;c>l;)if(u=s[l++],u!==u)return!0}else for(;c>l;l++)if((e||l in s)&&s[l]===n)return e||l||0;return!e&&-1}};e.exports={includes:o(!0),indexOf:o(!1)}},4527(e,t,n){var r=n(3724),i=n(4376),a=TypeError,o=Object.getOwnPropertyDescriptor;e.exports=r&&!function(){if(this!==void 0)return!0;try{Object.defineProperty([],"length",{writable:!1}).length=1}catch(e){return e instanceof TypeError}}()?function(e,t){if(i(e)&&!o(e,`length`).writable)throw new a(`Cannot set read only .length`);return e.length=t}:function(e,t){return e.length=t}},7680(e,t,n){e.exports=n(9504)([].slice)},2804(e){var t=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789`,n=t+`+/`,r=t+`-_`,i=function(e){for(var t={},n=0;n<64;n++)t[e.charAt(n)]=n;return t};e.exports={i2c:n,c2i:i(n),i2cUrl:r,c2iUrl:i(r)}},6319(e,t,n){var r=n(8551),i=n(9539);e.exports=function(e,t,n,a){try{return a?t(r(n)[0],n[1]):t(n)}catch(t){i(e,`throw`,t)}}},2195(e,t,n){var r=n(9504),i=r({}.toString),a=r(``.slice);e.exports=function(e){return a(i(e),8,-1)}},6955(e,t,n){var r=n(2140),i=n(4901),a=n(2195),o=n(8227)(`toStringTag`),s=Object,c=a(function(){return arguments}())===`Arguments`,l=function(e,t){try{return e[t]}catch{}};e.exports=r?a:function(e){var t,n,r;return e===void 0?`Undefined`:e===null?`Null`:typeof(n=l(t=s(e),o))==`string`?n:c?a(t):(r=a(t))===`Object`&&i(t.callee)?`Arguments`:r}},7740(e,t,n){var r=n(9297),i=n(5031),a=n(7347),o=n(4913);e.exports=function(e,t,n){for(var s=i(t),c=o.f,l=a.f,u=0;un)throw new t(`Maximum allowed index exceeded`);return e}},5002(e){e.exports={IndexSizeError:{s:`INDEX_SIZE_ERR`,c:1,m:1},DOMStringSizeError:{s:`DOMSTRING_SIZE_ERR`,c:2,m:0},HierarchyRequestError:{s:`HIERARCHY_REQUEST_ERR`,c:3,m:1},WrongDocumentError:{s:`WRONG_DOCUMENT_ERR`,c:4,m:1},InvalidCharacterError:{s:`INVALID_CHARACTER_ERR`,c:5,m:1},NoDataAllowedError:{s:`NO_DATA_ALLOWED_ERR`,c:6,m:0},NoModificationAllowedError:{s:`NO_MODIFICATION_ALLOWED_ERR`,c:7,m:1},NotFoundError:{s:`NOT_FOUND_ERR`,c:8,m:1},NotSupportedError:{s:`NOT_SUPPORTED_ERR`,c:9,m:1},InUseAttributeError:{s:`INUSE_ATTRIBUTE_ERR`,c:10,m:1},InvalidStateError:{s:`INVALID_STATE_ERR`,c:11,m:1},SyntaxError:{s:`SYNTAX_ERR`,c:12,m:1},InvalidModificationError:{s:`INVALID_MODIFICATION_ERR`,c:13,m:1},NamespaceError:{s:`NAMESPACE_ERR`,c:14,m:1},InvalidAccessError:{s:`INVALID_ACCESS_ERR`,c:15,m:1},ValidationError:{s:`VALIDATION_ERR`,c:16,m:0},TypeMismatchError:{s:`TYPE_MISMATCH_ERR`,c:17,m:1},SecurityError:{s:`SECURITY_ERR`,c:18,m:1},NetworkError:{s:`NETWORK_ERR`,c:19,m:1},AbortError:{s:`ABORT_ERR`,c:20,m:1},URLMismatchError:{s:`URL_MISMATCH_ERR`,c:21,m:1},QuotaExceededError:{s:`QUOTA_EXCEEDED_ERR`,c:22,m:1},TimeoutError:{s:`TIMEOUT_ERR`,c:23,m:1},InvalidNodeTypeError:{s:`INVALID_NODE_TYPE_ERR`,c:24,m:1},DataCloneError:{s:`DATA_CLONE_ERR`,c:25,m:1}}},8727(e){e.exports=[`constructor`,`hasOwnProperty`,`isPrototypeOf`,`propertyIsEnumerable`,`toLocaleString`,`toString`,`valueOf`]},2839(e,t,n){var r=n(4576).navigator,i=r&&r.userAgent;e.exports=i?String(i):``},9519(e,t,n){var r=n(4576),i=n(2839),a=r.process,o=r.Deno,s=a&&a.versions||o&&o.version,c=s&&s.v8,l,u;c&&(l=c.split(`.`),u=l[0]>0&&l[0]<4?1:+(l[0]+l[1])),!u&&i&&(l=i.match(/Edge\/(\d+)/),(!l||l[1]>=74)&&(l=i.match(/Chrome\/(\d+)/),l&&(u=+l[1]))),e.exports=u},6193(e,t,n){var r=n(9504),i=Error,a=r(``.replace),o=(function(e){return String(new i(e).stack)})(`zxcasd`),s=/\n\s*at [^:]*:[^\n]*/,c=s.test(o);e.exports=function(e,t){if(c&&typeof e==`string`&&!i.prepareStackTrace)for(;t--;)e=a(e,s,``);return e}},6518(e,t,n){var r=n(4576),i=n(7347).f,a=n(6699),o=n(6840),s=n(9433),c=n(7740),l=n(2796);e.exports=function(e,t){var n=e.target,u=e.global,d=e.stat,f,p=u?r:d?r[n]||s(n,{}):r[n]&&r[n].prototype,m,h,g,_;if(p)for(m in t){if(g=t[m],e.dontCallGetSet?(_=i(p,m),h=_&&_.value):h=p[m],f=l(u?m:n+(d?`.`:`#`)+m,e.forced),!f&&h!==void 0){if(typeof g==typeof h)continue;c(g,h)}(e.sham||h&&h.sham)&&a(g,`sham`,!0),o(p,m,g,e)}}},9039(e){e.exports=function(e){try{return!!e()}catch{return!0}}},8745(e,t,n){var r=n(616),i=Function.prototype,a=i.apply,o=i.call;e.exports=typeof Reflect==`object`&&Reflect.apply||(r?o.bind(a):function(){return o.apply(a,arguments)})},6080(e,t,n){var r=n(7476),i=n(9306),a=n(616),o=r(r.bind);e.exports=function(e,t){return i(e),t===void 0?e:a?o(e,t):function(){return e.apply(t,arguments)}}},616(e,t,n){e.exports=!n(9039)(function(){var e=function(){}.bind();return typeof e!=`function`||e.hasOwnProperty(`prototype`)})},9565(e,t,n){var r=n(616),i=Function.prototype.call;e.exports=r?i.bind(i):function(){return i.apply(i,arguments)}},350(e,t,n){var r=n(3724),i=n(9297),a=Function.prototype,o=r&&Object.getOwnPropertyDescriptor,s=i(a,`name`);e.exports={EXISTS:s,PROPER:s&&function(){}.name===`something`,CONFIGURABLE:s&&(!r||r&&o(a,`name`).configurable)}},6706(e,t,n){var r=n(9504),i=n(9306);e.exports=function(e,t,n){try{return r(i(Object.getOwnPropertyDescriptor(e,t)[n]))}catch{}}},7476(e,t,n){var r=n(2195),i=n(9504);e.exports=function(e){if(r(e)===`Function`)return i(e)}},9504(e,t,n){var r=n(616),i=Function.prototype,a=i.call,o=r&&i.bind.bind(a,a);e.exports=r?o:function(e){return function(){return a.apply(e,arguments)}}},944(e){var t=TypeError;e.exports=function(e){var n=e&&e.alphabet;if(n===void 0||n===`base64`||n===`base64url`)return n||`base64`;throw new t("Incorrect `alphabet` option")}},7751(e,t,n){var r=n(4576),i=n(4901),a=function(e){return i(e)?e:void 0};e.exports=function(e,t){return arguments.length<2?a(r[e]):r[e]&&r[e][t]}},1767(e){e.exports=function(e){return{iterator:e,next:e.next,done:!1}}},8646(e,t,n){var r=n(9565),i=n(8551),a=n(1767),o=n(851);e.exports=function(e,t){(!t||typeof e!=`string`)&&i(e);var n=o(e);return a(i(n===void 0?e:r(n,e)))}},851(e,t,n){var r=n(6955),i=n(5966),a=n(4117),o=n(6269),s=n(8227)(`iterator`);e.exports=function(e){if(!a(e))return i(e,s)||i(e,`@@iterator`)||o[r(e)]}},81(e,t,n){var r=n(9565),i=n(9306),a=n(8551),o=n(6823),s=n(851),c=TypeError;e.exports=function(e,t){var n=arguments.length<2?s(e):t;if(i(n))return a(r(n,e));throw new c(o(e)+` is not iterable`)}},5966(e,t,n){var r=n(9306),i=n(4117);e.exports=function(e,t){var n=e[t];return i(n)?void 0:r(n)}},3789(e,t,n){var r=n(9306),i=n(8551),a=n(9565),o=n(1291),s=n(1767),c=`Invalid size`,l=RangeError,u=TypeError,d=Math.max,f=function(e,t){this.set=e,this.size=d(t,0),this.has=r(e.has),this.keys=r(e.keys)};f.prototype={getIterator:function(){return s(i(a(this.keys,this.set)))},includes:function(e){return a(this.has,this.set,e)}},e.exports=function(e){i(e);var t=+e.size;if(t!==t)throw new u(c);var n=o(t);if(n<0)throw new l(c);return new f(e,n)}},4576(e){var t=function(e){return e&&e.Math===Math&&e};e.exports=t(typeof globalThis==`object`&&globalThis)||t(typeof window==`object`&&window)||t(typeof self==`object`&&self)||t(typeof global==`object`&&global)||t(typeof this==`object`&&this)||(function(){return this})()||Function(`return this`)()},9297(e,t,n){var r=n(9504),i=n(8981),a=r({}.hasOwnProperty);e.exports=Object.hasOwn||function(e,t){return a(i(e),t)}},421(e){e.exports={}},397(e,t,n){e.exports=n(7751)(`document`,`documentElement`)},5917(e,t,n){var r=n(3724),i=n(9039),a=n(4055);e.exports=!r&&!i(function(){return Object.defineProperty(a(`div`),"a",{get:function(){return 7}}).a!==7})},7055(e,t,n){var r=n(9504),i=n(9039),a=n(2195),o=Object,s=r(``.split);e.exports=i(function(){return!o(`z`).propertyIsEnumerable(0)})?function(e){return a(e)===`String`?s(e,``):o(e)}:o},3167(e,t,n){var r=n(4901),i=n(34),a=n(2967);e.exports=function(e,t,n){var o,s;return a&&r(o=t.constructor)&&o!==n&&i(s=o.prototype)&&s!==n.prototype&&a(e,s),e}},3706(e,t,n){var r=n(9504),i=n(4901),a=n(7629),o=r(Function.toString);i(a.inspectSource)||(a.inspectSource=function(e){return o(e)}),e.exports=a.inspectSource},1181(e,t,n){var r=n(8622),i=n(4576),a=n(34),o=n(6699),s=n(9297),c=n(7629),l=n(6119),u=n(421),d=`Object already initialized`,f=i.TypeError,p=i.WeakMap,m,h,g,_=function(e){return g(e)?h(e):m(e,{})},v=function(e){return function(t){var n;if(!a(t)||(n=h(t)).type!==e)throw new f(`Incompatible receiver, `+e+` required`);return n}};if(r||c.state){var y=c.state||=new p;y.get=y.get,y.has=y.has,y.set=y.set,m=function(e,t){if(y.has(e))throw new f(d);return t.facade=e,y.set(e,t),t},h=function(e){return y.get(e)||{}},g=function(e){return y.has(e)}}else{var b=l(`state`);u[b]=!0,m=function(e,t){if(s(e,b))throw new f(d);return t.facade=e,o(e,b,t),t},h=function(e){return s(e,b)?e[b]:{}},g=function(e){return s(e,b)}}e.exports={set:m,get:h,has:g,enforce:_,getterFor:v}},4209(e,t,n){var r=n(8227),i=n(6269),a=r(`iterator`),o=Array.prototype;e.exports=function(e){return e!==void 0&&(i.Array===e||o[a]===e)}},4376(e,t,n){var r=n(2195);e.exports=Array.isArray||function(e){return r(e)===`Array`}},1108(e,t,n){var r=n(6955);e.exports=function(e){var t=r(e);return t===`BigInt64Array`||t===`BigUint64Array`}},4901(e){var t=typeof document==`object`&&document.all;e.exports=t===void 0&&t!==void 0?function(e){return typeof e==`function`||e===t}:function(e){return typeof e==`function`}},2796(e,t,n){var r=n(9039),i=n(4901),a=/#|\.prototype\./,o=function(e,t){var n=c[s(e)];return n===u?!0:n===l?!1:i(t)?r(t):!!t},s=o.normalize=function(e){return String(e).replace(a,`.`).toLowerCase()},c=o.data={},l=o.NATIVE=`N`,u=o.POLYFILL=`P`;e.exports=o},4117(e){e.exports=function(e){return e==null}},34(e,t,n){var r=n(4901);e.exports=function(e){return typeof e==`object`?e!==null:r(e)}},3925(e,t,n){var r=n(34);e.exports=function(e){return r(e)||e===null}},6395(e){e.exports=!1},5810(e,t,n){var r=n(34),i=n(1181).get;e.exports=function(e){if(!r(e))return!1;var t=i(e);return!!t&&t.type===`RawJSON`}},757(e,t,n){var r=n(7751),i=n(4901),a=n(1625),o=n(7040),s=Object;e.exports=o?function(e){return typeof e==`symbol`}:function(e){var t=r(`Symbol`);return i(t)&&a(t.prototype,s(e))}},507(e,t,n){var r=n(9565);e.exports=function(e,t,n){for(var i=n?e:e.iterator,a=e.next,o,s;!(o=r(a,i)).done;)if(s=t(o.value),s!==void 0)return s}},2652(e,t,n){var r=n(6080),i=n(9565),a=n(8551),o=n(6823),s=n(4209),c=n(6198),l=n(1625),u=n(81),d=n(851),f=n(9539),p=TypeError,m=function(e,t){this.stopped=e,this.result=t},h=m.prototype;e.exports=function(e,t,n){var g=n&&n.that,_=!!(n&&n.AS_ENTRIES),v=!!(n&&n.IS_RECORD),y=!!(n&&n.IS_ITERATOR),b=!!(n&&n.INTERRUPTED),x=r(t,g),S,C,w,T,E,D,O,k=function(e){var t=S;return S=void 0,t&&f(t,`normal`),new m(!0,e)},A=function(e){return _?(a(e),b?x(e[0],e[1],k):x(e[0],e[1])):b?x(e,k):x(e)};if(v)S=e.iterator;else if(y)S=e;else{if(C=d(e),!C)throw new p(o(e)+` is not iterable`);if(s(C)){for(w=0,T=c(e);T>w;w++)if(E=A(e[w]),E&&l(h,E))return E;return new m(!1)}S=u(e,C)}for(D=v?e.next:S.next;!(O=i(D,S)).done;){var j=O.value;try{E=A(j)}catch(e){if(S)f(S,`throw`,e);else throw e}if(typeof E==`object`&&E&&l(h,E))return E}return new m(!1)}},1385(e,t,n){var r=n(9539);e.exports=function(e,t,n){for(var i=e.length-1;i>=0;i--)if(e[i]!==void 0)try{n=r(e[i].iterator,t,n)}catch(e){t=`throw`,n=e}if(t===`throw`)throw n;return n}},9539(e,t,n){var r=n(9565),i=n(8551),a=n(5966);e.exports=function(e,t,n){var o,s;i(e);try{if(o=a(e,`return`),!o){if(t===`throw`)throw n;return n}o=r(o,e)}catch(e){s=!0,o=e}if(t===`throw`)throw n;if(s)throw o;return i(o),n}},9462(e,t,n){var r=n(9565),i=n(2360),a=n(6699),o=n(6279),s=n(8227),c=n(1181),l=n(5966),u=n(7657).IteratorPrototype,d=n(2529),f=n(9539),p=n(1385),m=s(`toStringTag`),h=`IteratorHelper`,g=`WrapForValidIterator`,_=`normal`,v=`throw`,y=c.set,b=function(e){var t=c.getterFor(e?g:h);return o(i(u),{next:function(){var n=t(this);if(e)return n.nextHandler();if(n.done)return d(void 0,!0);try{var r=n.nextHandler();return n.returnHandlerResult?r:d(r,n.done)}catch(e){throw n.done=!0,e}},return:function(){var n=t(this),i=n.iterator,a=n.done;if(n.done=!0,e){var o=l(i,`return`);return o?r(o,i):d(void 0,!0)}if(a)return d(void 0,!0);if(n.inner)try{f(n.inner.iterator,_)}catch(e){return f(i,v,e)}if(n.openIters)try{p(n.openIters,_)}catch(e){if(i)return f(i,v,e);throw e}return i&&f(i,_),d(void 0,!0)}})},x=b(!0),S=b(!1);a(S,m,`Iterator Helper`),e.exports=function(e,t,n){var r=function(r,i){i?(i.iterator=r.iterator,i.next=r.next):i=r,i.type=t?g:h,i.returnHandlerResult=!!n,i.nextHandler=e,i.counter=0,i.done=!1,y(this,i)};return r.prototype=t?x:S,r}},684(e){e.exports=function(e,t){var n=typeof Iterator==`function`&&Iterator.prototype[e];if(n)try{n.call({next:null},t).next()}catch{return!0}}},4549(e,t,n){var r=n(4576);e.exports=function(e,t){var n=r.Iterator,i=n&&n.prototype,a=i&&i[e],o=!1;if(a)try{a.call({next:function(){return{done:!0}},return:function(){o=!0}},-1)}catch(e){e instanceof t||(o=!1)}if(!o)return a}},7657(e,t,n){var r=n(9039),i=n(4901),a=n(34),o=n(2360),s=n(2787),c=n(6840),l=n(8227),u=n(6395),d=l(`iterator`),f=!1,p,m,h;[].keys&&(h=[].keys(),`next`in h?(m=s(s(h)),m!==Object.prototype&&(p=m)):f=!0),!a(p)||r(function(){var e={};return p[d].call(e)!==e})?p={}:u&&(p=o(p)),i(p[d])||c(p,d,function(){return this}),e.exports={IteratorPrototype:p,BUGGY_SAFARI_ITERATORS:f}},6269(e){e.exports={}},6198(e,t,n){var r=n(8014);e.exports=function(e){return r(e.length)}},283(e,t,n){var r=n(9504),i=n(9039),a=n(4901),o=n(9297),s=n(3724),c=n(350).CONFIGURABLE,l=n(3706),u=n(1181),d=u.enforce,f=u.get,p=String,m=Object.defineProperty,h=r(``.slice),g=r(``.replace),_=r([].join),v=s&&!i(function(){return m(function(){},`length`,{value:8}).length!==8}),y=String(String).split(`String`),b=e.exports=function(e,t,n){h(p(t),0,7)===`Symbol(`&&(t=`[`+g(p(t),/^Symbol\(([^)]*)\).*$/,`$1`)+`]`),n&&n.getter&&(t=`get `+t),n&&n.setter&&(t=`set `+t),(!o(e,`name`)||c&&e.name!==t)&&(s?m(e,`name`,{value:t,configurable:!0}):e.name=t),v&&n&&o(n,`arity`)&&e.length!==n.arity&&m(e,`length`,{value:n.arity});try{n&&o(n,`constructor`)&&n.constructor?s&&m(e,`prototype`,{writable:!1}):e.prototype&&=void 0}catch{}var r=d(e);return o(r,`source`)||(r.source=_(y,typeof t==`string`?t:``)),e};Function.prototype.toString=b(function(){return a(this)&&f(this).source||l(this)},`toString`)},2248(e,t,n){var r=n(9504),i=Map.prototype;e.exports={Map,set:r(i.set),get:r(i.get),has:r(i.has),remove:r(i.delete),proto:i}},741(e){var t=Math.ceil,n=Math.floor;e.exports=Math.trunc||function(e){var r=+e;return(r>0?n:t)(r)}},7819(e,t,n){e.exports=!n(9039)(function(){var e=`9007199254740993`,t=JSON.rawJSON(e);return!JSON.isRawJSON(t)||JSON.stringify(t)!==e})},6043(e,t,n){var r=n(9306),i=TypeError,a=function(e){var t,n;this.promise=new e(function(e,r){if(t!==void 0||n!==void 0)throw new i(`Bad Promise constructor`);t=e,n=r}),this.resolve=r(t),this.reject=r(n)};e.exports.f=function(e){return new a(e)}},2603(e,t,n){var r=n(655);e.exports=function(e,t){return e===void 0?arguments.length<2?``:t:r(e)}},4149(e){var t=RangeError;e.exports=function(e){if(e===e)return e;throw new t(`NaN is not allowed`)}},2360(e,t,n){var r=n(8551),i=n(6801),a=n(8727),o=n(421),s=n(397),c=n(4055),l=n(6119),u=`>`,d=`<`,f=`prototype`,p=`script`,m=l(`IE_PROTO`),h=function(){},g=function(e){return d+p+u+e+d+`/`+p+u},_=function(e){e.write(g(``)),e.close();var t=e.parentWindow.Object;return e=null,t},v=function(){var e=c(`iframe`),t=`java`+p+`:`,n;return e.style.display=`none`,s.appendChild(e),e.src=String(t),n=e.contentWindow.document,n.open(),n.write(g(`document.F=Object`)),n.close(),n.F},y,b=function(){try{y=new ActiveXObject(`htmlfile`)}catch{}b=typeof document<`u`?document.domain&&y?_(y):v():_(y);for(var e=a.length;e--;)delete b[f][a[e]];return b()};o[m]=!0,e.exports=Object.create||function(e,t){var n;return e===null?n=b():(h[f]=r(e),n=new h,h[f]=null,n[m]=e),t===void 0?n:i.f(n,t)}},6801(e,t,n){var r=n(3724),i=n(8686),a=n(4913),o=n(8551),s=n(5397),c=n(1072);t.f=r&&!i?Object.defineProperties:function(e,t){o(e);for(var n=s(t),r=c(t),i=r.length,l=0,u;i>l;)a.f(e,u=r[l++],n[u]);return e}},4913(e,t,n){var r=n(3724),i=n(5917),a=n(8686),o=n(8551),s=n(6969),c=TypeError,l=Object.defineProperty,u=Object.getOwnPropertyDescriptor,d=`enumerable`,f=`configurable`,p=`writable`;t.f=r?a?function(e,t,n){if(o(e),t=s(t),o(n),typeof e==`function`&&t===`prototype`&&`value`in n&&p in n&&!n[p]){var r=u(e,t);r&&r[p]&&(e[t]=n.value,n={configurable:f in n?n[f]:r[f],enumerable:d in n?n[d]:r[d],writable:!1})}return l(e,t,n)}:l:function(e,t,n){if(o(e),t=s(t),o(n),i)try{return l(e,t,n)}catch{}if(`get`in n||`set`in n)throw new c(`Accessors not supported`);return`value`in n&&(e[t]=n.value),e}},7347(e,t,n){var r=n(3724),i=n(9565),a=n(8773),o=n(6980),s=n(5397),c=n(6969),l=n(9297),u=n(5917),d=Object.getOwnPropertyDescriptor;t.f=r?d:function(e,t){if(e=s(e),t=c(t),u)try{return d(e,t)}catch{}if(l(e,t))return o(!i(a.f,e,t),e[t])}},8480(e,t,n){var r=n(1828),i=n(8727).concat(`length`,`prototype`);t.f=Object.getOwnPropertyNames||function(e){return r(e,i)}},3717(e,t){t.f=Object.getOwnPropertySymbols},2787(e,t,n){var r=n(9297),i=n(4901),a=n(8981),o=n(6119),s=n(2211),c=o(`IE_PROTO`),l=Object,u=l.prototype;e.exports=s?l.getPrototypeOf:function(e){var t=a(e);if(r(t,c))return t[c];var n=t.constructor;return i(n)&&t instanceof n?n.prototype:t instanceof l?u:null}},1625(e,t,n){e.exports=n(9504)({}.isPrototypeOf)},1828(e,t,n){var r=n(9504),i=n(9297),a=n(5397),o=n(9617).indexOf,s=n(421),c=r([].push);e.exports=function(e,t){var n=a(e),r=0,l=[],u;for(u in n)!i(s,u)&&i(n,u)&&c(l,u);for(;t.length>r;)i(n,u=t[r++])&&(~o(l,u)||c(l,u));return l}},1072(e,t,n){var r=n(1828),i=n(8727);e.exports=Object.keys||function(e){return r(e,i)}},8773(e,t){var n={}.propertyIsEnumerable,r=Object.getOwnPropertyDescriptor;t.f=r&&!n.call({1:2},1)?function(e){var t=r(this,e);return!!t&&t.enumerable}:n},2967(e,t,n){var r=n(6706),i=n(34),a=n(7750),o=n(3506);e.exports=Object.setPrototypeOf||(`__proto__`in{}?function(){var e=!1,t={},n;try{n=r(Object.prototype,`__proto__`,`set`),n(t,[]),e=t instanceof Array}catch{}return function(t,r){return a(t),o(r),i(t)&&(e?n(t,r):t.__proto__=r),t}}():void 0)},4270(e,t,n){var r=n(9565),i=n(4901),a=n(34),o=TypeError;e.exports=function(e,t){var n,s;if(t===`string`&&i(n=e.toString)&&!a(s=r(n,e))||i(n=e.valueOf)&&!a(s=r(n,e))||t!==`string`&&i(n=e.toString)&&!a(s=r(n,e)))return s;throw new o(`Can't convert object to primitive value`)}},5031(e,t,n){var r=n(7751),i=n(9504),a=n(8480),o=n(3717),s=n(8551),c=i([].concat);e.exports=r(`Reflect`,`ownKeys`)||function(e){var t=a.f(s(e)),n=o.f;return n?c(t,n(e)):t}},8235(e,t,n){var r=n(9504),i=n(9297),a=SyntaxError,o=parseInt,s=String.fromCharCode,c=r(``.charAt),l=r(``.slice),u=r(/./.exec),d={'\\"':`"`,"\\\\":`\\`,"\\/":`/`,"\\b":`\b`,"\\f":`\f`,"\\n":` +import{Kn as e}from"./index-Cxa-KVmA.js";var t={9306(e,t,n){var r=n(4901),i=n(6823),a=TypeError;e.exports=function(e){if(r(e))return e;throw new a(i(e)+` is not a function`)}},3506(e,t,n){var r=n(3925),i=String,a=TypeError;e.exports=function(e){if(r(e))return e;throw new a(`Can't set `+i(e)+` as a prototype`)}},7080(e,t,n){var r=n(4402).has;e.exports=function(e){return r(e),e}},3463(e){var t=TypeError;e.exports=function(e){if(typeof e==`string`)return e;throw new t(`Argument is not a string`)}},4328(e,t,n){var r=n(4995),i=new r.WeakMap,a=r.set,o=r.remove;e.exports=function(e){return a(i,e,1),o(i,e),e}},6557(e,t,n){var r=n(4995).has;e.exports=function(e){return r(e),e}},6469(e,t,n){var r=n(8227),i=n(2360),a=n(4913).f,o=r(`unscopables`),s=Array.prototype;s[o]===void 0&&a(s,o,{configurable:!0,value:i(null)}),e.exports=function(e){s[o][e]=!0}},679(e,t,n){var r=n(1625),i=TypeError;e.exports=function(e,t){if(r(t,e))return e;throw new i(`Incorrect invocation`)}},3972(e,t,n){var r=n(34),i=String,a=TypeError;e.exports=function(e){if(e===void 0||r(e))return e;throw new a(i(e)+` is not an object or undefined`)}},8551(e,t,n){var r=n(34),i=String,a=TypeError;e.exports=function(e){if(r(e))return e;throw new a(i(e)+` is not an object`)}},4154(e,t,n){var r=n(6955),i=TypeError;e.exports=function(e){if(r(e)===`Uint8Array`)return e;throw new i(`Argument is not an Uint8Array`)}},7811(e){e.exports=typeof ArrayBuffer<`u`&&typeof DataView<`u`},7394(e,t,n){var r=n(4576),i=n(6706),a=n(2195),o=r.ArrayBuffer,s=r.TypeError;e.exports=o&&i(o.prototype,`byteLength`,`get`)||function(e){if(a(e)!==`ArrayBuffer`)throw new s(`ArrayBuffer expected`);return e.byteLength}},3238(e,t,n){var r=n(4576),i=n(7811),a=n(7394),o=r.DataView;e.exports=function(e){if(!i||a(e)!==0)return!1;try{return new o(e),!1}catch{return!0}}},5169(e,t,n){var r=n(3238),i=TypeError;e.exports=function(e){if(r(e))throw new i(`ArrayBuffer is detached`);return e}},4644(e,t,n){var r=n(7811),i=n(3724),a=n(4576),o=n(4901),s=n(34),c=n(9297),l=n(6955),u=n(6823),d=n(6699),f=n(6840),p=n(2106),m=n(1625),h=n(2787),g=n(2967),_=n(8227),v=n(3392),y=n(1181),b=y.enforce,x=y.get,S=a.Int8Array,C=S&&S.prototype,w=a.Uint8ClampedArray,T=w&&w.prototype,E=S&&h(S),D=C&&h(C),O=Object.prototype,k=a.TypeError,A=_(`toStringTag`),j=v(`TYPED_ARRAY_TAG`),M=`TypedArrayConstructor`,N=r&&!!g&&l(a.opera)!==`Opera`,P=!1,F,I,L,R={Int8Array:1,Uint8Array:1,Uint8ClampedArray:1,Int16Array:2,Uint16Array:2,Int32Array:4,Uint32Array:4,Float32Array:4,Float64Array:8},ee={BigInt64Array:8,BigUint64Array:8},te=function(e){if(!s(e))return!1;var t=l(e);return t===`DataView`||c(R,t)||c(ee,t)},ne=function(e){var t=h(e);if(s(t)){var n=x(t);return n&&c(n,M)?n[M]:ne(t)}},re=function(e){if(!s(e))return!1;var t=l(e);return c(R,t)||c(ee,t)},ie=function(e){if(re(e))return e;throw new k(`Target is not a typed array`)},ae=function(e){if(o(e)&&(!g||m(E,e)))return e;throw new k(u(e)+` is not a typed array constructor`)},z=function(e,t,n,r){if(i){if(n)for(var o in R){var s=a[o];if(s&&c(s.prototype,e))try{delete s.prototype[e]}catch{try{s.prototype[e]=t}catch{}}}(!D[e]||n)&&f(D,e,n?t:N&&C[e]||t,r)}},B=function(e,t,n){var r,o;if(i){if(g){if(n){for(r in R)if(o=a[r],o&&c(o,e))try{delete o[e]}catch{}}if(!E[e]||n)try{return f(E,e,n?t:N&&E[e]||t)}catch{}else return}for(r in R)o=a[r],o&&(!o[e]||n)&&f(o,e,t)}};for(F in R)I=a[F],L=I&&I.prototype,L?b(L)[M]=I:N=!1;for(F in ee)I=a[F],L=I&&I.prototype,L&&(b(L)[M]=I);if((!N||!o(E)||E===Function.prototype)&&(E=function(){throw new k(`Incorrect invocation`)},N))for(F in R)a[F]&&g(a[F],E);if((!N||!D||D===O)&&(D=E.prototype,N))for(F in R)a[F]&&g(a[F].prototype,D);if(N&&h(T)!==D&&g(T,D),i&&!c(D,A))for(F in P=!0,p(D,A,{configurable:!0,get:function(){return s(this)?this[j]:void 0}}),R)a[F]&&d(a[F].prototype,j,F);e.exports={NATIVE_ARRAY_BUFFER_VIEWS:N,TYPED_ARRAY_TAG:P&&j,aTypedArray:ie,aTypedArrayConstructor:ae,exportTypedArrayMethod:z,exportTypedArrayStaticMethod:B,getTypedArrayConstructor:ne,isView:te,isTypedArray:re,TypedArray:E,TypedArrayPrototype:D}},5370(e,t,n){var r=n(6198);e.exports=function(e,t,n){for(var i=0,a=arguments.length>2?n:r(t),o=new e(a);a>i;)o[i]=t[i++];return o}},9617(e,t,n){var r=n(5397),i=n(5610),a=n(6198),o=function(e){return function(t,n,o){var s=r(t),c=a(s);if(c===0)return!e&&-1;var l=i(o,c),u;if(e&&n!==n){for(;c>l;)if(u=s[l++],u!==u)return!0}else for(;c>l;l++)if((e||l in s)&&s[l]===n)return e||l||0;return!e&&-1}};e.exports={includes:o(!0),indexOf:o(!1)}},4527(e,t,n){var r=n(3724),i=n(4376),a=TypeError,o=Object.getOwnPropertyDescriptor;e.exports=r&&!function(){if(this!==void 0)return!0;try{Object.defineProperty([],"length",{writable:!1}).length=1}catch(e){return e instanceof TypeError}}()?function(e,t){if(i(e)&&!o(e,`length`).writable)throw new a(`Cannot set read only .length`);return e.length=t}:function(e,t){return e.length=t}},7680(e,t,n){e.exports=n(9504)([].slice)},2804(e){var t=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789`,n=t+`+/`,r=t+`-_`,i=function(e){for(var t={},n=0;n<64;n++)t[e.charAt(n)]=n;return t};e.exports={i2c:n,c2i:i(n),i2cUrl:r,c2iUrl:i(r)}},6319(e,t,n){var r=n(8551),i=n(9539);e.exports=function(e,t,n,a){try{return a?t(r(n)[0],n[1]):t(n)}catch(t){i(e,`throw`,t)}}},2195(e,t,n){var r=n(9504),i=r({}.toString),a=r(``.slice);e.exports=function(e){return a(i(e),8,-1)}},6955(e,t,n){var r=n(2140),i=n(4901),a=n(2195),o=n(8227)(`toStringTag`),s=Object,c=a(function(){return arguments}())===`Arguments`,l=function(e,t){try{return e[t]}catch{}};e.exports=r?a:function(e){var t,n,r;return e===void 0?`Undefined`:e===null?`Null`:typeof(n=l(t=s(e),o))==`string`?n:c?a(t):(r=a(t))===`Object`&&i(t.callee)?`Arguments`:r}},7740(e,t,n){var r=n(9297),i=n(5031),a=n(7347),o=n(4913);e.exports=function(e,t,n){for(var s=i(t),c=o.f,l=a.f,u=0;un)throw new t(`Maximum allowed index exceeded`);return e}},5002(e){e.exports={IndexSizeError:{s:`INDEX_SIZE_ERR`,c:1,m:1},DOMStringSizeError:{s:`DOMSTRING_SIZE_ERR`,c:2,m:0},HierarchyRequestError:{s:`HIERARCHY_REQUEST_ERR`,c:3,m:1},WrongDocumentError:{s:`WRONG_DOCUMENT_ERR`,c:4,m:1},InvalidCharacterError:{s:`INVALID_CHARACTER_ERR`,c:5,m:1},NoDataAllowedError:{s:`NO_DATA_ALLOWED_ERR`,c:6,m:0},NoModificationAllowedError:{s:`NO_MODIFICATION_ALLOWED_ERR`,c:7,m:1},NotFoundError:{s:`NOT_FOUND_ERR`,c:8,m:1},NotSupportedError:{s:`NOT_SUPPORTED_ERR`,c:9,m:1},InUseAttributeError:{s:`INUSE_ATTRIBUTE_ERR`,c:10,m:1},InvalidStateError:{s:`INVALID_STATE_ERR`,c:11,m:1},SyntaxError:{s:`SYNTAX_ERR`,c:12,m:1},InvalidModificationError:{s:`INVALID_MODIFICATION_ERR`,c:13,m:1},NamespaceError:{s:`NAMESPACE_ERR`,c:14,m:1},InvalidAccessError:{s:`INVALID_ACCESS_ERR`,c:15,m:1},ValidationError:{s:`VALIDATION_ERR`,c:16,m:0},TypeMismatchError:{s:`TYPE_MISMATCH_ERR`,c:17,m:1},SecurityError:{s:`SECURITY_ERR`,c:18,m:1},NetworkError:{s:`NETWORK_ERR`,c:19,m:1},AbortError:{s:`ABORT_ERR`,c:20,m:1},URLMismatchError:{s:`URL_MISMATCH_ERR`,c:21,m:1},QuotaExceededError:{s:`QUOTA_EXCEEDED_ERR`,c:22,m:1},TimeoutError:{s:`TIMEOUT_ERR`,c:23,m:1},InvalidNodeTypeError:{s:`INVALID_NODE_TYPE_ERR`,c:24,m:1},DataCloneError:{s:`DATA_CLONE_ERR`,c:25,m:1}}},8727(e){e.exports=[`constructor`,`hasOwnProperty`,`isPrototypeOf`,`propertyIsEnumerable`,`toLocaleString`,`toString`,`valueOf`]},2839(e,t,n){var r=n(4576).navigator,i=r&&r.userAgent;e.exports=i?String(i):``},9519(e,t,n){var r=n(4576),i=n(2839),a=r.process,o=r.Deno,s=a&&a.versions||o&&o.version,c=s&&s.v8,l,u;c&&(l=c.split(`.`),u=l[0]>0&&l[0]<4?1:+(l[0]+l[1])),!u&&i&&(l=i.match(/Edge\/(\d+)/),(!l||l[1]>=74)&&(l=i.match(/Chrome\/(\d+)/),l&&(u=+l[1]))),e.exports=u},6193(e,t,n){var r=n(9504),i=Error,a=r(``.replace),o=(function(e){return String(new i(e).stack)})(`zxcasd`),s=/\n\s*at [^:]*:[^\n]*/,c=s.test(o);e.exports=function(e,t){if(c&&typeof e==`string`&&!i.prepareStackTrace)for(;t--;)e=a(e,s,``);return e}},6518(e,t,n){var r=n(4576),i=n(7347).f,a=n(6699),o=n(6840),s=n(9433),c=n(7740),l=n(2796);e.exports=function(e,t){var n=e.target,u=e.global,d=e.stat,f,p=u?r:d?r[n]||s(n,{}):r[n]&&r[n].prototype,m,h,g,_;if(p)for(m in t){if(g=t[m],e.dontCallGetSet?(_=i(p,m),h=_&&_.value):h=p[m],f=l(u?m:n+(d?`.`:`#`)+m,e.forced),!f&&h!==void 0){if(typeof g==typeof h)continue;c(g,h)}(e.sham||h&&h.sham)&&a(g,`sham`,!0),o(p,m,g,e)}}},9039(e){e.exports=function(e){try{return!!e()}catch{return!0}}},8745(e,t,n){var r=n(616),i=Function.prototype,a=i.apply,o=i.call;e.exports=typeof Reflect==`object`&&Reflect.apply||(r?o.bind(a):function(){return o.apply(a,arguments)})},6080(e,t,n){var r=n(7476),i=n(9306),a=n(616),o=r(r.bind);e.exports=function(e,t){return i(e),t===void 0?e:a?o(e,t):function(){return e.apply(t,arguments)}}},616(e,t,n){e.exports=!n(9039)(function(){var e=function(){}.bind();return typeof e!=`function`||e.hasOwnProperty(`prototype`)})},9565(e,t,n){var r=n(616),i=Function.prototype.call;e.exports=r?i.bind(i):function(){return i.apply(i,arguments)}},350(e,t,n){var r=n(3724),i=n(9297),a=Function.prototype,o=r&&Object.getOwnPropertyDescriptor,s=i(a,`name`);e.exports={EXISTS:s,PROPER:s&&function(){}.name===`something`,CONFIGURABLE:s&&(!r||r&&o(a,`name`).configurable)}},6706(e,t,n){var r=n(9504),i=n(9306);e.exports=function(e,t,n){try{return r(i(Object.getOwnPropertyDescriptor(e,t)[n]))}catch{}}},7476(e,t,n){var r=n(2195),i=n(9504);e.exports=function(e){if(r(e)===`Function`)return i(e)}},9504(e,t,n){var r=n(616),i=Function.prototype,a=i.call,o=r&&i.bind.bind(a,a);e.exports=r?o:function(e){return function(){return a.apply(e,arguments)}}},944(e){var t=TypeError;e.exports=function(e){var n=e&&e.alphabet;if(n===void 0||n===`base64`||n===`base64url`)return n||`base64`;throw new t("Incorrect `alphabet` option")}},7751(e,t,n){var r=n(4576),i=n(4901),a=function(e){return i(e)?e:void 0};e.exports=function(e,t){return arguments.length<2?a(r[e]):r[e]&&r[e][t]}},1767(e){e.exports=function(e){return{iterator:e,next:e.next,done:!1}}},8646(e,t,n){var r=n(9565),i=n(8551),a=n(1767),o=n(851);e.exports=function(e,t){(!t||typeof e!=`string`)&&i(e);var n=o(e);return a(i(n===void 0?e:r(n,e)))}},851(e,t,n){var r=n(6955),i=n(5966),a=n(4117),o=n(6269),s=n(8227)(`iterator`);e.exports=function(e){if(!a(e))return i(e,s)||i(e,`@@iterator`)||o[r(e)]}},81(e,t,n){var r=n(9565),i=n(9306),a=n(8551),o=n(6823),s=n(851),c=TypeError;e.exports=function(e,t){var n=arguments.length<2?s(e):t;if(i(n))return a(r(n,e));throw new c(o(e)+` is not iterable`)}},5966(e,t,n){var r=n(9306),i=n(4117);e.exports=function(e,t){var n=e[t];return i(n)?void 0:r(n)}},3789(e,t,n){var r=n(9306),i=n(8551),a=n(9565),o=n(1291),s=n(1767),c=`Invalid size`,l=RangeError,u=TypeError,d=Math.max,f=function(e,t){this.set=e,this.size=d(t,0),this.has=r(e.has),this.keys=r(e.keys)};f.prototype={getIterator:function(){return s(i(a(this.keys,this.set)))},includes:function(e){return a(this.has,this.set,e)}},e.exports=function(e){i(e);var t=+e.size;if(t!==t)throw new u(c);var n=o(t);if(n<0)throw new l(c);return new f(e,n)}},4576(e){var t=function(e){return e&&e.Math===Math&&e};e.exports=t(typeof globalThis==`object`&&globalThis)||t(typeof window==`object`&&window)||t(typeof self==`object`&&self)||t(typeof global==`object`&&global)||t(typeof this==`object`&&this)||(function(){return this})()||Function(`return this`)()},9297(e,t,n){var r=n(9504),i=n(8981),a=r({}.hasOwnProperty);e.exports=Object.hasOwn||function(e,t){return a(i(e),t)}},421(e){e.exports={}},397(e,t,n){e.exports=n(7751)(`document`,`documentElement`)},5917(e,t,n){var r=n(3724),i=n(9039),a=n(4055);e.exports=!r&&!i(function(){return Object.defineProperty(a(`div`),"a",{get:function(){return 7}}).a!==7})},7055(e,t,n){var r=n(9504),i=n(9039),a=n(2195),o=Object,s=r(``.split);e.exports=i(function(){return!o(`z`).propertyIsEnumerable(0)})?function(e){return a(e)===`String`?s(e,``):o(e)}:o},3167(e,t,n){var r=n(4901),i=n(34),a=n(2967);e.exports=function(e,t,n){var o,s;return a&&r(o=t.constructor)&&o!==n&&i(s=o.prototype)&&s!==n.prototype&&a(e,s),e}},3706(e,t,n){var r=n(9504),i=n(4901),a=n(7629),o=r(Function.toString);i(a.inspectSource)||(a.inspectSource=function(e){return o(e)}),e.exports=a.inspectSource},1181(e,t,n){var r=n(8622),i=n(4576),a=n(34),o=n(6699),s=n(9297),c=n(7629),l=n(6119),u=n(421),d=`Object already initialized`,f=i.TypeError,p=i.WeakMap,m,h,g,_=function(e){return g(e)?h(e):m(e,{})},v=function(e){return function(t){var n;if(!a(t)||(n=h(t)).type!==e)throw new f(`Incompatible receiver, `+e+` required`);return n}};if(r||c.state){var y=c.state||=new p;y.get=y.get,y.has=y.has,y.set=y.set,m=function(e,t){if(y.has(e))throw new f(d);return t.facade=e,y.set(e,t),t},h=function(e){return y.get(e)||{}},g=function(e){return y.has(e)}}else{var b=l(`state`);u[b]=!0,m=function(e,t){if(s(e,b))throw new f(d);return t.facade=e,o(e,b,t),t},h=function(e){return s(e,b)?e[b]:{}},g=function(e){return s(e,b)}}e.exports={set:m,get:h,has:g,enforce:_,getterFor:v}},4209(e,t,n){var r=n(8227),i=n(6269),a=r(`iterator`),o=Array.prototype;e.exports=function(e){return e!==void 0&&(i.Array===e||o[a]===e)}},4376(e,t,n){var r=n(2195);e.exports=Array.isArray||function(e){return r(e)===`Array`}},1108(e,t,n){var r=n(6955);e.exports=function(e){var t=r(e);return t===`BigInt64Array`||t===`BigUint64Array`}},4901(e){var t=typeof document==`object`&&document.all;e.exports=t===void 0&&t!==void 0?function(e){return typeof e==`function`||e===t}:function(e){return typeof e==`function`}},2796(e,t,n){var r=n(9039),i=n(4901),a=/#|\.prototype\./,o=function(e,t){var n=c[s(e)];return n===u?!0:n===l?!1:i(t)?r(t):!!t},s=o.normalize=function(e){return String(e).replace(a,`.`).toLowerCase()},c=o.data={},l=o.NATIVE=`N`,u=o.POLYFILL=`P`;e.exports=o},4117(e){e.exports=function(e){return e==null}},34(e,t,n){var r=n(4901);e.exports=function(e){return typeof e==`object`?e!==null:r(e)}},3925(e,t,n){var r=n(34);e.exports=function(e){return r(e)||e===null}},6395(e){e.exports=!1},5810(e,t,n){var r=n(34),i=n(1181).get;e.exports=function(e){if(!r(e))return!1;var t=i(e);return!!t&&t.type===`RawJSON`}},757(e,t,n){var r=n(7751),i=n(4901),a=n(1625),o=n(7040),s=Object;e.exports=o?function(e){return typeof e==`symbol`}:function(e){var t=r(`Symbol`);return i(t)&&a(t.prototype,s(e))}},507(e,t,n){var r=n(9565);e.exports=function(e,t,n){for(var i=n?e:e.iterator,a=e.next,o,s;!(o=r(a,i)).done;)if(s=t(o.value),s!==void 0)return s}},2652(e,t,n){var r=n(6080),i=n(9565),a=n(8551),o=n(6823),s=n(4209),c=n(6198),l=n(1625),u=n(81),d=n(851),f=n(9539),p=TypeError,m=function(e,t){this.stopped=e,this.result=t},h=m.prototype;e.exports=function(e,t,n){var g=n&&n.that,_=!!(n&&n.AS_ENTRIES),v=!!(n&&n.IS_RECORD),y=!!(n&&n.IS_ITERATOR),b=!!(n&&n.INTERRUPTED),x=r(t,g),S,C,w,T,E,D,O,k=function(e){var t=S;return S=void 0,t&&f(t,`normal`),new m(!0,e)},A=function(e){return _?(a(e),b?x(e[0],e[1],k):x(e[0],e[1])):b?x(e,k):x(e)};if(v)S=e.iterator;else if(y)S=e;else{if(C=d(e),!C)throw new p(o(e)+` is not iterable`);if(s(C)){for(w=0,T=c(e);T>w;w++)if(E=A(e[w]),E&&l(h,E))return E;return new m(!1)}S=u(e,C)}for(D=v?e.next:S.next;!(O=i(D,S)).done;){var j=O.value;try{E=A(j)}catch(e){if(S)f(S,`throw`,e);else throw e}if(typeof E==`object`&&E&&l(h,E))return E}return new m(!1)}},1385(e,t,n){var r=n(9539);e.exports=function(e,t,n){for(var i=e.length-1;i>=0;i--)if(e[i]!==void 0)try{n=r(e[i].iterator,t,n)}catch(e){t=`throw`,n=e}if(t===`throw`)throw n;return n}},9539(e,t,n){var r=n(9565),i=n(8551),a=n(5966);e.exports=function(e,t,n){var o,s;i(e);try{if(o=a(e,`return`),!o){if(t===`throw`)throw n;return n}o=r(o,e)}catch(e){s=!0,o=e}if(t===`throw`)throw n;if(s)throw o;return i(o),n}},9462(e,t,n){var r=n(9565),i=n(2360),a=n(6699),o=n(6279),s=n(8227),c=n(1181),l=n(5966),u=n(7657).IteratorPrototype,d=n(2529),f=n(9539),p=n(1385),m=s(`toStringTag`),h=`IteratorHelper`,g=`WrapForValidIterator`,_=`normal`,v=`throw`,y=c.set,b=function(e){var t=c.getterFor(e?g:h);return o(i(u),{next:function(){var n=t(this);if(e)return n.nextHandler();if(n.done)return d(void 0,!0);try{var r=n.nextHandler();return n.returnHandlerResult?r:d(r,n.done)}catch(e){throw n.done=!0,e}},return:function(){var n=t(this),i=n.iterator,a=n.done;if(n.done=!0,e){var o=l(i,`return`);return o?r(o,i):d(void 0,!0)}if(a)return d(void 0,!0);if(n.inner)try{f(n.inner.iterator,_)}catch(e){return f(i,v,e)}if(n.openIters)try{p(n.openIters,_)}catch(e){if(i)return f(i,v,e);throw e}return i&&f(i,_),d(void 0,!0)}})},x=b(!0),S=b(!1);a(S,m,`Iterator Helper`),e.exports=function(e,t,n){var r=function(r,i){i?(i.iterator=r.iterator,i.next=r.next):i=r,i.type=t?g:h,i.returnHandlerResult=!!n,i.nextHandler=e,i.counter=0,i.done=!1,y(this,i)};return r.prototype=t?x:S,r}},684(e){e.exports=function(e,t){var n=typeof Iterator==`function`&&Iterator.prototype[e];if(n)try{n.call({next:null},t).next()}catch{return!0}}},4549(e,t,n){var r=n(4576);e.exports=function(e,t){var n=r.Iterator,i=n&&n.prototype,a=i&&i[e],o=!1;if(a)try{a.call({next:function(){return{done:!0}},return:function(){o=!0}},-1)}catch(e){e instanceof t||(o=!1)}if(!o)return a}},7657(e,t,n){var r=n(9039),i=n(4901),a=n(34),o=n(2360),s=n(2787),c=n(6840),l=n(8227),u=n(6395),d=l(`iterator`),f=!1,p,m,h;[].keys&&(h=[].keys(),`next`in h?(m=s(s(h)),m!==Object.prototype&&(p=m)):f=!0),!a(p)||r(function(){var e={};return p[d].call(e)!==e})?p={}:u&&(p=o(p)),i(p[d])||c(p,d,function(){return this}),e.exports={IteratorPrototype:p,BUGGY_SAFARI_ITERATORS:f}},6269(e){e.exports={}},6198(e,t,n){var r=n(8014);e.exports=function(e){return r(e.length)}},283(e,t,n){var r=n(9504),i=n(9039),a=n(4901),o=n(9297),s=n(3724),c=n(350).CONFIGURABLE,l=n(3706),u=n(1181),d=u.enforce,f=u.get,p=String,m=Object.defineProperty,h=r(``.slice),g=r(``.replace),_=r([].join),v=s&&!i(function(){return m(function(){},`length`,{value:8}).length!==8}),y=String(String).split(`String`),b=e.exports=function(e,t,n){h(p(t),0,7)===`Symbol(`&&(t=`[`+g(p(t),/^Symbol\(([^)]*)\).*$/,`$1`)+`]`),n&&n.getter&&(t=`get `+t),n&&n.setter&&(t=`set `+t),(!o(e,`name`)||c&&e.name!==t)&&(s?m(e,`name`,{value:t,configurable:!0}):e.name=t),v&&n&&o(n,`arity`)&&e.length!==n.arity&&m(e,`length`,{value:n.arity});try{n&&o(n,`constructor`)&&n.constructor?s&&m(e,`prototype`,{writable:!1}):e.prototype&&=void 0}catch{}var r=d(e);return o(r,`source`)||(r.source=_(y,typeof t==`string`?t:``)),e};Function.prototype.toString=b(function(){return a(this)&&f(this).source||l(this)},`toString`)},2248(e,t,n){var r=n(9504),i=Map.prototype;e.exports={Map,set:r(i.set),get:r(i.get),has:r(i.has),remove:r(i.delete),proto:i}},741(e){var t=Math.ceil,n=Math.floor;e.exports=Math.trunc||function(e){var r=+e;return(r>0?n:t)(r)}},7819(e,t,n){e.exports=!n(9039)(function(){var e=`9007199254740993`,t=JSON.rawJSON(e);return!JSON.isRawJSON(t)||JSON.stringify(t)!==e})},6043(e,t,n){var r=n(9306),i=TypeError,a=function(e){var t,n;this.promise=new e(function(e,r){if(t!==void 0||n!==void 0)throw new i(`Bad Promise constructor`);t=e,n=r}),this.resolve=r(t),this.reject=r(n)};e.exports.f=function(e){return new a(e)}},2603(e,t,n){var r=n(655);e.exports=function(e,t){return e===void 0?arguments.length<2?``:t:r(e)}},4149(e){var t=RangeError;e.exports=function(e){if(e===e)return e;throw new t(`NaN is not allowed`)}},2360(e,t,n){var r=n(8551),i=n(6801),a=n(8727),o=n(421),s=n(397),c=n(4055),l=n(6119),u=`>`,d=`<`,f=`prototype`,p=`script`,m=l(`IE_PROTO`),h=function(){},g=function(e){return d+p+u+e+d+`/`+p+u},_=function(e){e.write(g(``)),e.close();var t=e.parentWindow.Object;return e=null,t},v=function(){var e=c(`iframe`),t=`java`+p+`:`,n;return e.style.display=`none`,s.appendChild(e),e.src=String(t),n=e.contentWindow.document,n.open(),n.write(g(`document.F=Object`)),n.close(),n.F},y,b=function(){try{y=new ActiveXObject(`htmlfile`)}catch{}b=typeof document<`u`?document.domain&&y?_(y):v():_(y);for(var e=a.length;e--;)delete b[f][a[e]];return b()};o[m]=!0,e.exports=Object.create||function(e,t){var n;return e===null?n=b():(h[f]=r(e),n=new h,h[f]=null,n[m]=e),t===void 0?n:i.f(n,t)}},6801(e,t,n){var r=n(3724),i=n(8686),a=n(4913),o=n(8551),s=n(5397),c=n(1072);t.f=r&&!i?Object.defineProperties:function(e,t){o(e);for(var n=s(t),r=c(t),i=r.length,l=0,u;i>l;)a.f(e,u=r[l++],n[u]);return e}},4913(e,t,n){var r=n(3724),i=n(5917),a=n(8686),o=n(8551),s=n(6969),c=TypeError,l=Object.defineProperty,u=Object.getOwnPropertyDescriptor,d=`enumerable`,f=`configurable`,p=`writable`;t.f=r?a?function(e,t,n){if(o(e),t=s(t),o(n),typeof e==`function`&&t===`prototype`&&`value`in n&&p in n&&!n[p]){var r=u(e,t);r&&r[p]&&(e[t]=n.value,n={configurable:f in n?n[f]:r[f],enumerable:d in n?n[d]:r[d],writable:!1})}return l(e,t,n)}:l:function(e,t,n){if(o(e),t=s(t),o(n),i)try{return l(e,t,n)}catch{}if(`get`in n||`set`in n)throw new c(`Accessors not supported`);return`value`in n&&(e[t]=n.value),e}},7347(e,t,n){var r=n(3724),i=n(9565),a=n(8773),o=n(6980),s=n(5397),c=n(6969),l=n(9297),u=n(5917),d=Object.getOwnPropertyDescriptor;t.f=r?d:function(e,t){if(e=s(e),t=c(t),u)try{return d(e,t)}catch{}if(l(e,t))return o(!i(a.f,e,t),e[t])}},8480(e,t,n){var r=n(1828),i=n(8727).concat(`length`,`prototype`);t.f=Object.getOwnPropertyNames||function(e){return r(e,i)}},3717(e,t){t.f=Object.getOwnPropertySymbols},2787(e,t,n){var r=n(9297),i=n(4901),a=n(8981),o=n(6119),s=n(2211),c=o(`IE_PROTO`),l=Object,u=l.prototype;e.exports=s?l.getPrototypeOf:function(e){var t=a(e);if(r(t,c))return t[c];var n=t.constructor;return i(n)&&t instanceof n?n.prototype:t instanceof l?u:null}},1625(e,t,n){e.exports=n(9504)({}.isPrototypeOf)},1828(e,t,n){var r=n(9504),i=n(9297),a=n(5397),o=n(9617).indexOf,s=n(421),c=r([].push);e.exports=function(e,t){var n=a(e),r=0,l=[],u;for(u in n)!i(s,u)&&i(n,u)&&c(l,u);for(;t.length>r;)i(n,u=t[r++])&&(~o(l,u)||c(l,u));return l}},1072(e,t,n){var r=n(1828),i=n(8727);e.exports=Object.keys||function(e){return r(e,i)}},8773(e,t){var n={}.propertyIsEnumerable,r=Object.getOwnPropertyDescriptor;t.f=r&&!n.call({1:2},1)?function(e){var t=r(this,e);return!!t&&t.enumerable}:n},2967(e,t,n){var r=n(6706),i=n(34),a=n(7750),o=n(3506);e.exports=Object.setPrototypeOf||(`__proto__`in{}?function(){var e=!1,t={},n;try{n=r(Object.prototype,`__proto__`,`set`),n(t,[]),e=t instanceof Array}catch{}return function(t,r){return a(t),o(r),i(t)&&(e?n(t,r):t.__proto__=r),t}}():void 0)},4270(e,t,n){var r=n(9565),i=n(4901),a=n(34),o=TypeError;e.exports=function(e,t){var n,s;if(t===`string`&&i(n=e.toString)&&!a(s=r(n,e))||i(n=e.valueOf)&&!a(s=r(n,e))||t!==`string`&&i(n=e.toString)&&!a(s=r(n,e)))return s;throw new o(`Can't convert object to primitive value`)}},5031(e,t,n){var r=n(7751),i=n(9504),a=n(8480),o=n(3717),s=n(8551),c=i([].concat);e.exports=r(`Reflect`,`ownKeys`)||function(e){var t=a.f(s(e)),n=o.f;return n?c(t,n(e)):t}},8235(e,t,n){var r=n(9504),i=n(9297),a=SyntaxError,o=parseInt,s=String.fromCharCode,c=r(``.charAt),l=r(``.slice),u=r(/./.exec),d={'\\"':`"`,"\\\\":`\\`,"\\/":`/`,"\\b":`\b`,"\\f":`\f`,"\\n":` `,"\\r":`\r`,"\\t":` `},f=/^[\da-f]{4}$/i,p=/^[\u0000-\u001F]$/;e.exports=function(e,t){for(var n=!0,r=``;tn.size?c(n.getIterator(),function(e){d(t,e)&&u(i,e)}):s(t,function(e){n.includes(e)&&u(i,e)}),i}},4449(e,t,n){var r=n(7080),i=n(4402).has,a=n(5170),o=n(3789),s=n(8469),c=n(507),l=n(9539);e.exports=function(e){var t=r(this),n=o(e);if(a(t)<=n.size)return s(t,function(e){if(n.includes(e))return!1},!0)!==!1;var u=n.getIterator();return c(u,function(e){if(i(t,e))return l(u.iterator,`normal`,!1)})!==!1}},3838(e,t,n){var r=n(7080),i=n(5170),a=n(8469),o=n(3789);e.exports=function(e){var t=r(this),n=o(e);return i(t)>n.size?!1:a(t,function(e){if(!n.includes(e))return!1},!0)!==!1}},8527(e,t,n){var r=n(7080),i=n(4402).has,a=n(5170),o=n(3789),s=n(507),c=n(9539);e.exports=function(e){var t=r(this),n=o(e);if(a(t)0?i(t,9007199254740991):0}},8981(e,t,n){var r=n(7750),i=Object;e.exports=function(e){return i(r(e))}},9590(e,t,n){var r=n(1291),i=RangeError;e.exports=function(e){var t=r(e);if(t<0)throw new i(`The argument can't be less than 0`);return t}},2777(e,t,n){var r=n(9565),i=n(34),a=n(757),o=n(5966),s=n(4270),c=n(8227),l=TypeError,u=c(`toPrimitive`);e.exports=function(e,t){if(!i(e)||a(e))return e;var n=o(e,u),c;if(n){if(t===void 0&&(t=`default`),c=r(n,e,t),!i(c)||a(c))return c;throw new l(`Can't convert object to primitive value`)}return t===void 0&&(t=`number`),s(e,t)}},6969(e,t,n){var r=n(2777),i=n(757);e.exports=function(e){var t=r(e,`string`);return i(t)?t:t+``}},2140(e,t,n){var r=n(8227)(`toStringTag`),i={};i[r]=`z`,e.exports=String(i)===`[object z]`},655(e,t,n){var r=n(6955),i=String;e.exports=function(e){if(r(e)===`Symbol`)throw TypeError(`Cannot convert a Symbol value to a string`);return i(e)}},6823(e){var t=String;e.exports=function(e){try{return t(e)}catch{return`Object`}}},3392(e,t,n){var r=n(9504),i=0,a=Math.random(),o=r(1.1.toString);e.exports=function(e){return`Symbol(`+(e===void 0?``:e)+`)_`+o(++i+a,36)}},9143(e,t,n){var r=n(4576),i=n(9504),a=n(3972),o=n(3463),s=n(9297),c=n(2804),l=n(944),u=n(5169),d=c.c2i,f=c.c2iUrl,p=r.SyntaxError,m=r.TypeError,h=i(``.charAt),g=function(e,t){for(var n=e.length;t>16&255,i>>8&255,i&255];if(r===2){if(n&&a[1]!==0)throw new p(`Extra bits`);return[a[0]]}if(r===3){if(n&&a[2]!==0)throw new p(`Extra bits`);return[a[0],a[1]]}return a},v=function(e,t,n){for(var r=t.length,i=0;i0){if(c===`stop-before-partial`)break;if(c===`loose`){if(C.length===1)throw new p(`Malformed padding: exactly one additional character`);x=v(b,_(C,i,!1),x)}else throw new p(`Missing padding`)}S=y;break}var T=h(e,w);if(++w,T===`=`){if(C.length<2)throw new p(`Padding is too early`);if(w=g(e,w),C.length===2){if(w===y){if(c===`stop-before-partial`)break;throw new p(`Malformed padding: only one =`)}h(e,w)===`=`&&(++w,w=g(e,w))}if(w>4}return{bytes:i,read:u<<1}}},7416(e,t,n){var r=n(9039),i=n(8227),a=n(3724),o=n(6395),s=i(`iterator`);e.exports=!r(function(){var e=new URL(`b?a=1&b=2&c=3`,`https://a`),t=e.searchParams,n=new URLSearchParams(`a=1&a=2&b=3`),r=``;return e.pathname=`c%20d`,t.forEach(function(e,n){t.delete(`b`),r+=n+e}),n.delete(`a`,2),n.delete(`b`,void 0),o&&(!e.toJSON||!n.has(`a`,1)||n.has(`a`,2)||!n.has(`a`,void 0)||n.has(`b`))||!t.size&&(o||!a)||!t.sort||e.href!==`https://a/c%20d?a=1&c=3`||t.get(`c`)!==`3`||String(new URLSearchParams(`?a=1`))!==`a=1`||!t[s]||new URL(`https://a@b`).username!==`a`||new URLSearchParams(new URLSearchParams(`a=b`)).get(`a`)!==`b`||new URL(`https://тест`).host!==`xn--e1aybc`||new URL(`https://a#б`).hash!==`#%D0%B1`||r!==`a1c3`||new URL(`https://x`,void 0).host!==`x`})},7040(e,t,n){e.exports=n(4495)&&!Symbol.sham&&typeof Symbol.iterator==`symbol`},8686(e,t,n){var r=n(3724),i=n(9039);e.exports=r&&i(function(){return Object.defineProperty(function(){},"prototype",{value:42,writable:!1}).prototype!==42})},2812(e){var t=TypeError;e.exports=function(e,n){if(e1?arguments[1]:void 0)}}),o(`includes`)},4114(e,t,n){var r=n(6518),i=n(8981),a=n(6198),o=n(4527),s=n(6837);r({target:`Array`,proto:!0,arity:1,forced:n(9039)(function(){return[].push.call({length:4294967296},1)!==4294967297})||!function(){try{Object.defineProperty([],"length",{writable:!1}).push()}catch(e){return e instanceof TypeError}}()},{push:function(e){var t=i(this),n=a(t),r=arguments.length;s(n+r);for(var c=0;cm)throw new o(`Maximum allowed index exceeded`);if(typeof e!=`number`)throw new s(`Value is not a number`);r!==_&&(e===e?e===c?r=r===v?_:y:e===-c?r=r===y?_:v:(e!==0||1/e===c)&&(r===b||r===x)&&(r=x,f(t,e)):r=_)}),r){case _:return l;case v:return-c;case y:return c;case b:return-0}for(var i=[],d=0,C,w,T,E,D,O,k=0;k=0?i[N]:0;if(N--,u(d)>1||d>0&&P>0||d<0&&P<0)return d>0?c:-c;if(T=S(d*p,P/2),E=T.hi,D=T.lo,D*=2,u(2*E)===c)return E>0?E===p&&D===-(g/2)&&N>=0&&i[N]<0?h:c:E===-p&&D===g/2&&N>=0&&i[N]>0?-h:-c;D!==0&&(i[++N]=D,D=0),E*=2}for(;N>=0&&(T=S(E,i[N--]),E=T.hi,D=T.lo,D===0););return N>=0&&(D<0&&i[N]<0||D>0&&i[N]>0)&&(w=D*2,C=E+w,w===C-E&&(E=C)),E}})},1689(e,t,n){var r=n(6518),i=n(4576),a=n(8745),o=n(7680),s=n(6043),c=n(9306),l=n(1103),u=i.Promise,d=!1;r({target:`Promise`,stat:!0,forced:!u||!u.try||l(function(){u.try(function(e){d=e===8},8)}).error||!d},{try:function(e){var t=arguments.length>1?o(arguments,1):[],n=s.f(this),r=l(function(){return a(c(e),void 0,t)});return(r.error?n.reject:n.resolve)(r.value),n.promise}})},4628(e,t,n){var r=n(6518),i=n(6043);r({target:`Promise`,stat:!0},{withResolvers:function(){var e=i.f(this);return{promise:e.promise,resolve:e.resolve,reject:e.reject}}})},7642(e,t,n){var r=n(6518),i=n(3440),a=n(9039);r({target:`Set`,proto:!0,real:!0,forced:!n(4916)(`difference`,function(e){return e.size===0})||a(function(){var e={size:1,has:function(){return!0},keys:function(){var e=0;return{next:function(){var n=e++>1;return t.has(1)&&t.clear(),{done:n,value:2}}}}},t=new Set([1,2,3,4]);return t.difference(e).size!==3})},{difference:i})},8004(e,t,n){var r=n(6518),i=n(9039),a=n(8750);r({target:`Set`,proto:!0,real:!0,forced:!n(4916)(`intersection`,function(e){return e.size===2&&e.has(1)&&e.has(2)})||i(function(){return String(Array.from(new Set([1,2,3]).intersection(new Set([3,2]))))!==`3,2`})},{intersection:a})},3853(e,t,n){var r=n(6518),i=n(4449);r({target:`Set`,proto:!0,real:!0,forced:!n(4916)(`isDisjointFrom`,function(e){return!e})},{isDisjointFrom:i})},5876(e,t,n){var r=n(6518),i=n(3838);r({target:`Set`,proto:!0,real:!0,forced:!n(4916)(`isSubsetOf`,function(e){return e})},{isSubsetOf:i})},2475(e,t,n){var r=n(6518),i=n(8527);r({target:`Set`,proto:!0,real:!0,forced:!n(4916)(`isSupersetOf`,function(e){return!e})},{isSupersetOf:i})},5024(e,t,n){var r=n(6518),i=n(3650),a=n(9835);r({target:`Set`,proto:!0,real:!0,forced:!n(4916)(`symmetricDifference`)||!a(`symmetricDifference`)},{symmetricDifference:i})},1698(e,t,n){var r=n(6518),i=n(4204),a=n(9835);r({target:`Set`,proto:!0,real:!0,forced:!n(4916)(`union`)||!a(`union`)},{union:i})},9577(e,t,n){var r=n(4644),i=n(1108),a=n(6198),o=n(1291),s=n(5854),c=r.aTypedArray,l=r.getTypedArrayConstructor,u=r.exportTypedArrayMethod,d=RangeError,f=function(){try{new Int8Array(1).with(2,{valueOf:function(){throw 8}})}catch(e){return e===8}}(),p=f&&function(){try{new Int8Array(1).with(-.5,1)}catch{return!0}}();u(`with`,{with:function(e,t){var n=c(this),r=a(n),u=o(e),f=u<0?r+u:u,p=i(n)?s(t):+t;if(f>=r||f<0)throw new d(`Incorrect index`);for(var m=new(l(n))(r),h=0;h1?arguments[1]:void 0,null,9007199254740991).bytes)}})},6632(e,t,n){var r=n(6518),i=n(4576),a=n(9143),o=n(4154),s=i.Uint8Array,c=!s||!s.prototype.setFromBase64||!function(){var e=new s([255,255,255,255,255]);try{e.setFromBase64(``,null);return}catch{}try{e.setFromBase64(`a`);return}catch{}try{e.setFromBase64(`MjYyZg===`)}catch{return e[0]===50&&e[1]===54&&e[2]===50&&e[3]===255&&e[4]===255}}();s&&r({target:`Uint8Array`,proto:!0,forced:c},{setFromBase64:function(e){o(this);var t=a(e,arguments.length>1?arguments[1]:void 0,this,this.length);return{read:t.read,written:t.written}}})},4226(e,t,n){var r=n(6518),i=n(4576),a=n(3463),o=n(4154),s=n(5169),c=n(2303);function l(){try{new Uint8Array(new ArrayBuffer(16,{maxByteLength:1024})).setFromHex(`cafed00d`)}catch{return!0}}i.Uint8Array&&r({target:`Uint8Array`,proto:!0,forced:l()},{setFromHex:function(e){o(this),a(e),s(this.buffer);var t=c(e,this).read;return{read:t,written:t/2}}})},9486(e,t,n){var r=n(6518),i=n(4576),a=n(9504),o=n(3972),s=n(4154),c=n(5169),l=n(2804),u=n(944),d=l.i2c,f=l.i2cUrl,p=a(``.charAt),m=i.Uint8Array,h=!m||!m.prototype.toBase64||!function(){try{new m().toBase64(null)}catch{return!0}}();m&&r({target:`Uint8Array`,proto:!0,forced:h},{toBase64:function(){var e=s(this),t=arguments.length?o(arguments[0]):void 0,n=u(t)===`base64`?d:f,r=!!t&&!!t.omitPadding;c(this.buffer);for(var i=``,a=0,l=e.length,m,h=function(e){return p(n,m>>6*e&63)};a+2{if(Array.isArray(t))for(var n=0;nObject.prototype.hasOwnProperty.call(e,t),r(4423),r(4114),r(8111),r(2489),r(5367),r(2731),r(7642),r(8004),r(3853),r(5876),r(2475),r(5024),r(1698),r(9577),r(6632),r(4226),r(9486),r(456),r(5781);var i=typeof process==`object`&&process+``==`[object process]`&&!process.versions.nw&&!(process.versions.electron&&process.type&&process.type!==`browser`),a=[1/0,1/0,-1/0,-1/0],o=new Float32Array(a),s=[.001,0,0,.001,0,0],c=`http://www.w3.org/2000/svg`,l={ANY:1,DISPLAY:2,PRINT:4,SAVE:8,ANNOTATIONS_FORMS:16,ANNOTATIONS_STORAGE:32,ANNOTATIONS_DISABLE:64,IS_EDITING:128,OPLIST:256},u={DISABLE:0,ENABLE:1,ENABLE_FORMS:2,ENABLE_STORAGE:3},d=`pdfjs_internal_id_`,f=`pdfjs_internal_editor_`,p={DISABLE:-1,NONE:0,FREETEXT:3,HIGHLIGHT:9,STAMP:13,INK:15,POPUP:16,SIGNATURE:101,COMMENT:102},m={RESIZE:1,CREATE:2,FREETEXT_SIZE:11,FREETEXT_COLOR:12,FREETEXT_OPACITY:13,INK_COLOR:21,INK_THICKNESS:22,INK_OPACITY:23,INK_COLOR_AND_OPACITY:24,HIGHLIGHT_COLOR:31,HIGHLIGHT_THICKNESS:32,HIGHLIGHT_FREE:33,HIGHLIGHT_SHOW_ALL:34,DRAW_STEP:41},h={PRINT:4,MODIFY_CONTENTS:8,COPY:16,MODIFY_ANNOTATIONS:32,FILL_INTERACTIVE_FORMS:256,COPY_FOR_ACCESSIBILITY:512,ASSEMBLE:1024,PRINT_HIGH_QUALITY:2048},g={FILL:0,STROKE:1,FILL_STROKE:2,INVISIBLE:3,FILL_ADD_TO_PATH:4,STROKE_ADD_TO_PATH:5,FILL_STROKE_ADD_TO_PATH:6,ADD_TO_PATH:7,FILL_STROKE_MASK:3,ADD_TO_PATH_FLAG:4},_={GRAYSCALE_1BPP:1,RGB_24BPP:2,RGBA_32BPP:3},v={TEXT:1,LINK:2,FREETEXT:3,LINE:4,SQUARE:5,CIRCLE:6,POLYGON:7,POLYLINE:8,HIGHLIGHT:9,UNDERLINE:10,SQUIGGLY:11,STRIKEOUT:12,STAMP:13,CARET:14,INK:15,POPUP:16,FILEATTACHMENT:17,SOUND:18,MOVIE:19,WIDGET:20,SCREEN:21,PRINTERMARK:22,TRAPNET:23,WATERMARK:24,THREED:25,REDACT:26,RICHMEDIA:27},y={SOLID:1,DASHED:2,BEVELED:3,INSET:4,UNDERLINE:5},b={ERRORS:0,WARNINGS:1,INFOS:5},x={dependency:1,setLineWidth:2,setLineCap:3,setLineJoin:4,setMiterLimit:5,setDash:6,setRenderingIntent:7,setFlatness:8,setGState:9,save:10,restore:11,transform:12,moveTo:13,lineTo:14,curveTo:15,curveTo2:16,curveTo3:17,closePath:18,rectangle:19,stroke:20,closeStroke:21,fill:22,eoFill:23,fillStroke:24,eoFillStroke:25,closeFillStroke:26,closeEOFillStroke:27,endPath:28,clip:29,eoClip:30,beginText:31,endText:32,setCharSpacing:33,setWordSpacing:34,setHScale:35,setLeading:36,setFont:37,setTextRenderingMode:38,setTextRise:39,moveText:40,setLeadingMoveText:41,setTextMatrix:42,nextLine:43,showText:44,showSpacedText:45,nextLineShowText:46,nextLineSetSpacingShowText:47,setCharWidth:48,setCharWidthAndBounds:49,setStrokeColorSpace:50,setFillColorSpace:51,setStrokeColor:52,setStrokeColorN:53,setFillColor:54,setFillColorN:55,setStrokeGray:56,setFillGray:57,setStrokeRGBColor:58,setFillRGBColor:59,setStrokeCMYKColor:60,setFillCMYKColor:61,shadingFill:62,beginInlineImage:63,beginImageData:64,endInlineImage:65,paintXObject:66,markPoint:67,markPointProps:68,beginMarkedContent:69,beginMarkedContentProps:70,endMarkedContent:71,beginCompat:72,endCompat:73,paintFormXObjectBegin:74,paintFormXObjectEnd:75,beginGroup:76,endGroup:77,beginAnnotation:80,endAnnotation:81,paintImageMaskXObject:83,paintImageMaskXObjectGroup:84,paintImageXObject:85,paintInlineImageXObject:86,paintInlineImageXObjectGroup:87,paintImageXObjectRepeat:88,paintImageMaskXObjectRepeat:89,paintSolidColorImageMask:90,constructPath:91,setStrokeTransparent:92,setFillTransparent:93,rawFillPath:94},S={moveTo:0,lineTo:1,curveTo:2,quadraticCurveTo:3,closePath:4},C={NEED_PASSWORD:1,INCORRECT_PASSWORD:2},w=b.WARNINGS;function T(e){Number.isInteger(e)&&(w=e)}function E(){return w}function D(e){w>=b.INFOS&&console.info(`Info: ${e}`)}function O(e){w>=b.WARNINGS&&console.warn(`Warning: ${e}`)}function k(e){throw Error(e)}function A(e,t){e||k(t)}function j(e){switch(e?.protocol){case`http:`:case`https:`:case`ftp:`:case`mailto:`:case`tel:`:return!0;default:return!1}}function M(e,t=null,n=null){if(!e)return null;if(n&&typeof e==`string`&&(n.addDefaultProtocol&&e.startsWith(`www.`)&&e.match(/\./g)?.length>=2&&(e=`http://${e}`),n.tryConvertEncoding))try{e=oe(e)}catch{}let r=t?URL.parse(e,t):URL.parse(e);return j(r)?r:null}function N(e,t,n=!1){let r=URL.parse(e);return r?(r.hash=t,r.href):n&&M(e,`http://example.com`)?e.split(`#`,1)[0]+`${t?`#${t}`:``}`:``}function P(e){return e.substring(e.lastIndexOf(`/`)+1)}function F(e,t,n,r=!1){return Object.defineProperty(e,t,{value:n,enumerable:!r,configurable:!0,writable:!1}),n}var I=function(){function e(e,t){this.message=e,this.name=t}return e.prototype=Error(),e.constructor=e,e}(),L=class extends I{constructor(e,t){super(e,`PasswordException`),this.code=t}},R=class extends I{constructor(e,t){super(e,`UnknownErrorException`),this.details=t}},ee=class extends I{constructor(e){super(e,`InvalidPDFException`)}},te=class extends I{constructor(e,t,n){super(e,`ResponseException`),this.status=t,this.missing=n}},ne=class extends I{constructor(e){super(e,`FormatError`)}},re=class extends I{constructor(e){super(e,`AbortException`)}};function ie(e){(typeof e!=`object`||e?.length===void 0)&&k(`Invalid argument for bytesToString`);let t=e.length,n=8192;if(t`u`)return F(this,`isAlphaColorInputSupported`,!1);let e=document.createElement(`input`);return e.type=`color`,e.setAttribute(`alpha`,``),e.value=`#ff000080`,F(this,`isAlphaColorInputSupported`,e.value!==`#ff0000`)}static get isBackdropFilterSupported(){return F(this,`isBackdropFilterSupported`,typeof CSS<`u`&&CSS.supports(`backdrop-filter`,`blur(1px)`))}},B=class{static get hexNums(){return F(this,`hexNums`,Array.from(Array(256).keys(),e=>e.toString(16).padStart(2,`0`)))}static makeHexColor(e,t,n){return`#${this.hexNums[e]}${this.hexNums[t]}${this.hexNums[n]}`}static transform(e,t){return[e[0]*t[0]+e[2]*t[1],e[1]*t[0]+e[3]*t[1],e[0]*t[2]+e[2]*t[3],e[1]*t[2]+e[3]*t[3],e[0]*t[4]+e[2]*t[5]+e[4],e[1]*t[4]+e[3]*t[5]+e[5]]}static multiplyByDOMMatrix(e,t){return[e[0]*t.a+e[2]*t.b,e[1]*t.a+e[3]*t.b,e[0]*t.c+e[2]*t.d,e[1]*t.c+e[3]*t.d,e[0]*t.e+e[2]*t.f+e[4],e[1]*t.e+e[3]*t.f+e[5]]}static applyTransform(e,t,n=0){let r=e[n],i=e[n+1];e[n]=r*t[0]+i*t[2]+t[4],e[n+1]=r*t[1]+i*t[3]+t[5]}static applyTransformToBezier(e,t,n=0){let r=t[0],i=t[1],a=t[2],o=t[3],s=t[4],c=t[5];for(let t=0;t<6;t+=2){let l=e[n+t],u=e[n+t+1];e[n+t]=l*r+u*a+s,e[n+t+1]=l*i+u*o+c}}static applyInverseTransform(e,t){let n=e[0],r=e[1],i=t[0]*t[3]-t[1]*t[2];e[0]=(n*t[3]-r*t[2]+t[2]*t[5]-t[4]*t[3])/i,e[1]=(-n*t[1]+r*t[0]+t[4]*t[1]-t[5]*t[0])/i}static axialAlignedBoundingBox(e,t,n){let r=t[0],i=t[1],a=t[2],o=t[3],s=t[4],c=t[5],l=e[0],u=e[1],d=e[2],f=e[3],p=r*l+s,m=p,h=r*d+s,g=h,_=o*u+c,v=_,y=o*f+c,b=y;if(i!==0||a!==0){let e=i*l,t=i*d,n=a*u,r=a*f;p+=n,g+=n,h+=r,m+=r,_+=e,b+=e,y+=t,v+=t}n[0]=Math.min(n[0],p,h,m,g),n[1]=Math.min(n[1],_,y,v,b),n[2]=Math.max(n[2],p,h,m,g),n[3]=Math.max(n[3],_,y,v,b)}static inverseTransform(e){let t=e[0]*e[3]-e[1]*e[2];return[e[3]/t,-e[1]/t,-e[2]/t,e[0]/t,(e[2]*e[5]-e[4]*e[3])/t,(e[4]*e[1]-e[5]*e[0])/t]}static singularValueDecompose2dScale(e,t){let n=e[0],r=e[1],i=e[2],a=e[3],o=n**2+r**2,s=n*i+r*a,c=i**2+a**2,l=(o+c)/2,u=Math.sqrt(l**2-(o*c-s**2));t[0]=Math.sqrt(l+u||1),t[1]=Math.sqrt(l-u||1)}static normalizeRect(e){let t=e.slice(0);return e[0]>e[2]&&(t[0]=e[2],t[2]=e[0]),e[1]>e[3]&&(t[1]=e[3],t[3]=e[1]),t}static intersect(e,t){let n=Math.max(Math.min(e[0],e[2]),Math.min(t[0],t[2])),r=Math.min(Math.max(e[0],e[2]),Math.max(t[0],t[2]));if(n>r)return null;let i=Math.max(Math.min(e[1],e[3]),Math.min(t[1],t[3])),a=Math.min(Math.max(e[1],e[3]),Math.max(t[1],t[3]));return i>a?null:[n,i,r,a]}static pointBoundingBox(e,t,n){n[0]=Math.min(n[0],e),n[1]=Math.min(n[1],t),n[2]=Math.max(n[2],e),n[3]=Math.max(n[3],t)}static rectBoundingBox(e,t,n,r,i){i[0]=Math.min(i[0],e,n),i[1]=Math.min(i[1],t,r),i[2]=Math.max(i[2],e,n),i[3]=Math.max(i[3],t,r)}static#e(e,t,n,r,i,a,o,s,c,l){if(c<=0||c>=1)return;let u=1-c,d=c*c,f=d*c,p=u*(u*(u*e+3*c*t)+3*d*n)+f*r,m=u*(u*(u*i+3*c*a)+3*d*o)+f*s;l[0]=Math.min(l[0],p),l[1]=Math.min(l[1],m),l[2]=Math.max(l[2],p),l[3]=Math.max(l[3],m)}static#t(e,t,n,r,i,a,o,s,c,l,u,d){if(Math.abs(c)<1e-12){Math.abs(l)>=1e-12&&this.#e(e,t,n,r,i,a,o,s,-u/l,d);return}let f=l**2-4*u*c;if(f<0)return;let p=Math.sqrt(f),m=2*c;this.#e(e,t,n,r,i,a,o,s,(-l+p)/m,d),this.#e(e,t,n,r,i,a,o,s,(-l-p)/m,d)}static bezierBoundingBox(e,t,n,r,i,a,o,s,c){c[0]=Math.min(c[0],e,o),c[1]=Math.min(c[1],t,s),c[2]=Math.max(c[2],e,o),c[3]=Math.max(c[3],t,s),this.#t(e,n,i,o,t,r,a,s,3*(-e+3*(n-i)+o),6*(e-2*n+i),3*(n-e),c),this.#t(e,n,i,o,t,r,a,s,3*(-t+3*(r-a)+s),6*(t-2*r+a),3*(r-t),c)}};function oe(e){return decodeURIComponent(escape(e))}var se=null,ce=null;function le(e){return se||(se=/([\u00a0\u00b5\u037e\u0eb3\u2000-\u200a\u202f\u2126\ufb00-\ufb04\ufb06\ufb20-\ufb36\ufb38-\ufb3c\ufb3e\ufb40\ufb41\ufb43\ufb44\ufb46-\ufba1\ufba4-\ufba9\ufbae-\ufbb1\ufbd3-\ufbdc\ufbde-\ufbe7\ufbea-\ufbf8\ufbfc\ufbfd\ufc00-\ufc5d\ufc64-\ufcf1\ufcf5-\ufd3d\ufd88\ufdf4\ufdfa\ufdfb\ufe71\ufe77\ufe79\ufe7b\ufe7d]+)|(\ufb05+)/gu,ce=new Map([[`ſt`,`ſt`]])),e.replaceAll(se,(e,t,n)=>t?t.normalize(`NFKC`):ce.get(n))}function ue(){if(typeof crypto.randomUUID==`function`)return crypto.randomUUID();let e=new Uint8Array(32);return crypto.getRandomValues(e),ie(e)}function de(e,t,n){if(!Array.isArray(n)||n.length<2)return!1;let[r,i,...a]=n;if(!e(r)&&!Number.isInteger(r)||!t(i))return!1;let o=a.length,s=!0;switch(i.name){case`XYZ`:if(o<2||o>3)return!1;break;case`Fit`:case`FitB`:return o===0;case`FitH`:case`FitBH`:case`FitV`:case`FitBV`:if(o>1)return!1;break;case`FitR`:if(o!==4)return!1;s=!1;break;default:return!1}for(let e of a)if(!(typeof e==`number`||s&&e===null))return!1;return!0}var fe=()=>[],pe=()=>new Map,me=()=>Object.create(null),he=()=>new Set;typeof Blob.prototype.bytes!=`function`&&(Blob.prototype.bytes=async function(){return new Uint8Array(await this.arrayBuffer())}),typeof Response.prototype.bytes!=`function`&&(Response.prototype.bytes=async function(){return new Uint8Array(await this.arrayBuffer())}),typeof Iterator.prototype.join!=`function`&&(Iterator.prototype.join=function(e){return[...this].join(e)}),r(1701);function V(e,t,n){return Math.min(Math.max(e,t),n)}var ge=class e{constructor({viewBox:e,userUnit:t,scale:n,rotation:r,offsetX:i=0,offsetY:a=0,dontFlip:o=!1}){this.viewBox=e,this.userUnit=t,this.scale=n,this.rotation=r,this.offsetX=i,this.offsetY=a,n*=t;let s=(e[2]+e[0])/2,c=(e[3]+e[1])/2,l,u,d,f;switch(r%=360,r<0&&(r+=360),r){case 180:l=-1,u=0,d=0,f=1;break;case 90:l=0,u=1,d=1,f=0;break;case 270:l=0,u=-1,d=-1,f=0;break;case 0:l=1,u=0,d=0,f=-1;break;default:throw Error(`PageViewport: Invalid rotation, must be a multiple of 90 degrees.`)}o&&(d=-d,f=-f);let p,m,h,g;l===0?(p=Math.abs(c-e[1])*n+i,m=Math.abs(s-e[0])*n+a,h=(e[3]-e[1])*n,g=(e[2]-e[0])*n):(p=Math.abs(s-e[0])*n+i,m=Math.abs(c-e[1])*n+a,h=(e[2]-e[0])*n,g=(e[3]-e[1])*n),this.transform=[l*n,u*n,d*n,f*n,p-l*n*s-d*n*c,m-u*n*s-f*n*c],this.width=h,this.height=g}get rawDims(){let e=this.viewBox;return F(this,`rawDims`,{pageWidth:e[2]-e[0],pageHeight:e[3]-e[1],pageX:e[0],pageY:e[1]})}clone({scale:t=this.scale,rotation:n=this.rotation,offsetX:r=this.offsetX,offsetY:i=this.offsetY,dontFlip:a=!1}={}){return new e({viewBox:this.viewBox.slice(),userUnit:this.userUnit,scale:t,rotation:n,offsetX:r,offsetY:i,dontFlip:a})}convertToViewportPoint(e,t){let n=[e,t];return B.applyTransform(n,this.transform),n}convertToPdfPoint(e,t){let n=[e,t];return B.applyInverseTransform(n,this.transform),n}},_e=class e{static textContent(t){let n=[],r={items:n,styles:Object.create(null)};function i(t){if(!t)return;let r=null,a=t.name;if(a===`#text`)r=t.value;else if(e.shouldBuildText(a))t?.attributes?.textContent?r=t.attributes.textContent:t.value&&(r=t.value);else return;if(r!==null&&n.push({str:r}),t.children)for(let e of t.children)i(e)}return i(t),r}static shouldBuildText(e){return!(e===`textarea`||e===`input`||e===`option`||e===`select`)}},ve=/url\(|image-set\(/i,ye=/^on/i,be=class{static get _allowedHtmlElements(){return F(this,`_allowedHtmlElements`,new Set([`a`,`b`,`br`,`button`,`div`,`i`,`img`,`input`,`label`,`li`,`ol`,`option`,`p`,`select`,`span`,`sub`,`sup`,`textarea`,`ul`]))}static get _allowedSvgElements(){return F(this,`_allowedSvgElements`,new Set([`ellipse`,`line`,`path`,`rect`,`svg`]))}static get _allowedRichTextElements(){return F(this,`_allowedRichTextElements`,new Set([`a`,`b`,`br`,`div`,`i`,`li`,`ol`,`p`,`span`,`sub`,`sup`,`ul`]))}static get _allowedRichTextAttributes(){return F(this,`_allowedRichTextAttributes`,new Set([`class`,`dir`,`style`]))}static get _allowedRichTextStyles(){return F(this,`_allowedRichTextStyles`,new Set(`color.font.fontFamily.fontSize.fontStretch.fontStyle.fontWeight.kerningMode.letterSpacing.lineHeight.margin.marginBottom.marginLeft.marginRight.marginTop.orphans.paddingLeft.paddingRight.breakAfter.breakBefore.breakInside.tabInterval.tabStop.textAlign.textDecoration.textIndent.transform.verticalAlign.widows`.split(`.`)))}static setupStorage(e,t,n,r,i){let a=r.getValue(t,{value:null});switch(n.name){case`textarea`:if(a.value!==null&&(e.textContent=a.value),i===`print`)break;e.addEventListener(`input`,e=>{r.setValue(t,{value:e.target.value})});break;case`input`:if(n.attributes.type===`radio`||n.attributes.type===`checkbox`){if(a.value===n.attributes.xfaOn?e.setAttribute(`checked`,!0):a.value===n.attributes.xfaOff&&e.removeAttribute(`checked`),i===`print`)break;e.addEventListener(`change`,e=>{r.setValue(t,{value:e.target.checked?e.target.getAttribute(`xfaOn`):e.target.getAttribute(`xfaOff`)})})}else{if(a.value!==null&&e.setAttribute(`value`,a.value),i===`print`)break;e.addEventListener(`input`,e=>{r.setValue(t,{value:e.target.value})})}break;case`select`:if(a.value!==null){e.setAttribute(`value`,a.value);for(let e of n.children)e.attributes.value===a.value?e.attributes.selected=!0:Object.hasOwn(e.attributes,`selected`)&&delete e.attributes.selected}e.addEventListener(`input`,e=>{let n=e.target.options,i=n.selectedIndex===-1?``:n[n.selectedIndex].value;r.setValue(t,{value:i})});break}}static setAttributes({html:e,element:t,storage:n=null,intent:r,linkService:i}){let{attributes:a}=t,o=e instanceof HTMLAnchorElement;a.type===`radio`&&(a.name=`${a.name}-${r}`);for(let[t,n]of Object.entries(a))if(n!=null&&!ye.test(t)&&!(r===`richText`&&!this._allowedRichTextAttributes.has(t)))switch(t){case`class`:n.length&&e.setAttribute(t,n.join(` `));break;case`dataId`:break;case`id`:e.setAttribute(`data-element-id`,n);break;case`style`:if(r===`richText`){let t=this._allowedRichTextStyles;for(let[r,i]of Object.entries(n))t.has(r)&&!ve.test(i)&&(e.style[r]=i)}else Object.assign(e.style,n);break;case`textContent`:e.textContent=n;break;default:(!o||t!==`href`&&t!==`newWindow`)&&e.setAttribute(t,n)}o&&i?.addLinkAttributes(e,a.href,a.newWindow),n&&a.dataId&&this.setupStorage(e,a.dataId,t,n)}static#e(e,t,n){return n===`richText`?!t&&this._allowedRichTextElements.has(e)?document.createElement(e):null:t?t===c&&this._allowedSvgElements.has(e)?document.createElementNS(c,e):null:this._allowedHtmlElements.has(e)?document.createElement(e):null}static render(e){let t=e.annotationStorage,n=e.linkService,r=e.xfaHtml,i=e.intent||`display`,a=this.#e(r.name,r.attributes?.xmlns,i)??document.createElement(`div`);r.attributes&&this.setAttributes({html:a,element:r,intent:i,linkService:n});let o=i!==`richText`,s=e.div;if(s.append(a),e.viewport){let t=`matrix(${e.viewport.transform.join(`,`)})`;s.style.transform=t}o&&s.setAttribute(`class`,`xfaLayer xfaFont`);let c=[];if(r.children.length===0){if(r.value){let e=document.createTextNode(r.value);a.append(e),o&&_e.shouldBuildText(r.name)&&c.push(e)}return{textDivs:c}}let l=[[r,-1,a]];for(;l.length>0;){let[e,r,a]=l.at(-1);if(r+1===e.children.length){l.pop();continue}let s=e.children[++l.at(-1)[1]];if(s===null)continue;let{name:u}=s;if(u===`#text`){let e=document.createTextNode(s.value);c.push(e),a.append(e);continue}let d=this.#e(u,s.attributes?.xmlns,i);if(d){if(a.append(d),s.attributes&&this.setAttributes({html:d,element:s,storage:t,intent:i,linkService:n}),s.children?.length>0)l.push([s,-1,d]);else if(s.value){let e=document.createTextNode(s.value);o&&_e.shouldBuildText(u)&&c.push(e),d.append(e)}}}for(let e of s.querySelectorAll(`.xfaNonInteractive input, .xfaNonInteractive textarea`))e.setAttribute(`readOnly`,!0);return{textDivs:c}}static update(e){let t=`matrix(${e.viewport.transform.join(`,`)})`;e.div.style.transform=t,e.div.hidden=!1}static getPageViewport(e,{scale:t=1,rotation:n=0}){let{width:r,height:i}=e.attributes.style;return new ge({viewBox:[0,0,parseInt(r,10),parseInt(i,10)],userUnit:1,scale:t,rotation:n})}},xe=class{static CSS=96;static PDF=72;static PDF_TO_CSS_UNITS=this.CSS/this.PDF};async function Se(e,t=`text`){if(ke(e,document.baseURI)){let n=await fetch(e);if(!n.ok)throw Error(n.statusText);switch(t){case`blob`:return n.blob();case`bytes`:return n.bytes();case`json`:return n.json()}return n.text()}return new Promise((n,r)=>{let i=new XMLHttpRequest;i.open(`GET`,e,!0),i.responseType=t===`bytes`?`arraybuffer`:t,i.onreadystatechange=()=>{if(i.readyState===XMLHttpRequest.DONE){if(i.status===200||i.status===0){switch(t){case`bytes`:n(new Uint8Array(i.response));return;case`blob`:case`json`:n(i.response);return}n(i.responseText);return}r(Error(i.statusText))}},i.send(null)})}var Ce=class extends I{constructor(e,t=0){super(e,`RenderingCancelledException`),this.extraDelay=t}};function we(e){let t=e.length,n=0;for(;n{try{return new URL(e)}catch{}try{return new URL(decodeURIComponent(e))}catch{}try{return new URL(e,`https://foo.bar`)}catch{}try{return new URL(decodeURIComponent(e),`https://foo.bar`)}catch{}return null})(e);if(!n)return t;let r=e=>{try{let t=decodeURIComponent(e);return t.includes(`/`)&&(t=P(t),t.length===4&&i.test(t))?e:t}catch{return e}},i=/\.pdf$/i,a=P(n.pathname);if(i.test(a))return r(a);if(n.searchParams.size>0){let e=e=>[...e].findLast(e=>i.test(e)),t=e(n.searchParams.values())??e(n.searchParams.keys());if(t)return r(t)}if(n.hash){let e=/[^/?#=]+\.pdf\b(?!.*\.pdf\b)/i.exec(n.hash);if(e)return r(e[0])}return t}var Oe=class{#e=new Map;times=[];time(e){this.#e.has(e)&&O(`Timer is already running for ${e}`),this.#e.set(e,Date.now())}timeEnd(e){this.#e.has(e)||O(`Timer has not been started for ${e}`),this.times.push({name:e,start:this.#e.get(e),end:Date.now()}),this.#e.delete(e)}toString(){let e=Math.max(...this.times.map(e=>e.name.length));return this.times.map(t=>`${t.name.padEnd(e)} ${t.end-t.start}ms\n`).join(``)}};function ke(e,t){let n=t?URL.parse(e,t):URL.parse(e);return/https?:/.test(n?.protocol??``)}function H(e){e.preventDefault()}function U(e){e.preventDefault(),e.stopPropagation()}var Ae=class{static#e;static toDateObject(e){if(e instanceof Date)return e;if(!e||typeof e!=`string`)return null;this.#e||=RegExp(`^D:(\\d{4})(\\d{2})?(\\d{2})?(\\d{2})?(\\d{2})?(\\d{2})?([Z|+\\-])?(\\d{2})?'?(\\d{2})?'?`);let t=this.#e.exec(e);if(!t)return null;let n=parseInt(t[1],10),r=parseInt(t[2],10);r=r>=1&&r<=12?r-1:0;let i=parseInt(t[3],10);i=i>=1&&i<=31?i:1;let a=parseInt(t[4],10);a=a>=0&&a<=23?a:0;let o=parseInt(t[5],10);o=o>=0&&o<=59?o:0;let s=parseInt(t[6],10);s=s>=0&&s<=59?s:0;let c=t[7]||`Z`,l=parseInt(t[8],10);l=l>=0&&l<=23?l:0;let u=parseInt(t[9],10)||0;return u=u>=0&&u<=59?u:0,c===`-`?(a+=l,o+=u):c===`+`&&(a-=l,o-=u),new Date(Date.UTC(n,r,i,a,o,s))}};function je(e){if(e.startsWith(`#`)){let t=e.slice(1);return[parseInt(t.slice(0,2),16),parseInt(t.slice(2,4),16),parseInt(t.slice(4,6),16),t.length>=8?parseInt(t.slice(6,8),16)/255:1]}if(e.startsWith(`rgb(`)){let[t,n,r]=e.slice(4,-1).split(`,`).map(e=>parseInt(e,10));return[t,n,r,1]}if(e.startsWith(`rgba(`)){let t=e.slice(5,-1).split(`,`);return[parseInt(t[0],10),parseInt(t[1],10),parseInt(t[2],10),parseFloat(t[3])]}let t=e.match(/^color\(srgb\s+([\d.]+)\s+([\d.]+)\s+([\d.]+)(?:\s*\/\s*([\d.]+|none))?\)$/);return t?[Math.round(parseFloat(t[1])*255),Math.round(parseFloat(t[2])*255),Math.round(parseFloat(t[3])*255),t[4]!==void 0&&t[4]!==`none`?parseFloat(t[4]):1]:null}function Me(e){let t=je(e);return t?t.slice(0,3):(O(`Not a valid color format: "${e}"`),[0,0,0])}function Ne(e){let t=document.createElement(`span`);t.style.visibility=`hidden`,t.style.colorScheme=`only light`,document.body.append(t);for(let n of e.keys()){t.style.color=n;let r=window.getComputedStyle(t).color;e.set(n,Me(r))}t.remove()}function W(e){let{a:t,b:n,c:r,d:i,e:a,f:o}=e.getTransform();return[t,n,r,i,a,o]}function Pe(e){let{a:t,b:n,c:r,d:i,e:a,f:o}=e.getTransform().invertSelf();return[t,n,r,i,a,o]}function Fe(e,t,n=!1,r=!0){if(t instanceof ge){let{pageWidth:r,pageHeight:i}=t.rawDims,{style:a}=e,o=`round(down, var(--total-scale-factor) * ${r}px, var(--scale-round-x))`,s=`round(down, var(--total-scale-factor) * ${i}px, var(--scale-round-y))`;!n||t.rotation%180==0?(a.width=o,a.height=s):(a.width=s,a.height=o)}r&&e.setAttribute(`data-main-rotation`,t.rotation)}var Ie=class e{constructor(){let{pixelRatio:t}=e;this.sx=t,this.sy=t}get scaled(){return this.sx!==1||this.sy!==1}get symmetric(){return this.sx===this.sy}limitCanvas(t,n,r,i,a=-1){let o=1/0,s=1/0,c=1/0;r=e.capPixels(r,a),r>0&&(o=Math.sqrt(r/(t*n))),i!==-1&&(s=i/t,c=i/n);let l=Math.min(o,s,c);return this.sx>l||this.sy>l?(this.sx=l,this.sy=l,!0):!1}static get pixelRatio(){return globalThis.devicePixelRatio||1}static capPixels(e,t){if(t>=0){let n=Math.ceil(window.screen.availWidth*window.screen.availHeight*this.pixelRatio**2*(1+t/100));return e>0?Math.min(e,n):n}return e}},Le=[`image/apng`,`image/avif`,`image/bmp`,`image/gif`,`image/jpeg`,`image/png`,`image/svg+xml`,`image/webp`,`image/x-icon`],Re=class{static get isDarkMode(){return F(this,`isDarkMode`,!!window?.matchMedia?.(`(prefers-color-scheme: dark)`).matches)}},ze=class{static get commentForegroundColor(){let e=document.createElement(`span`);e.classList.add(`comment`,`sidebar`);let{style:t}=e;t.width=t.height=`0`,t.display=`none`,t.color=`var(--comment-fg-color)`,document.body.append(e);let{color:n}=window.getComputedStyle(e);return e.remove(),F(this,`commentForegroundColor`,Me(n))}};function Be(e,t){t=V(t??1,0,1);let n=255*(1-t);return e.map(e=>Math.round(e*t+n))}function Ve(e,t){let n=e[0]/255,r=e[1]/255,i=e[2]/255,a=Math.max(n,r,i),o=Math.min(n,r,i),s=(a+o)/2;if(a===o)t[0]=t[1]=0;else{let e=a-o;switch(t[1]=s<.5?e/(a+o):e/(2-a-o),a){case n:t[0]=((r-i)/e+(ri?(r+.05)/(i+.05):(i+.05)/(r+.05)}var Ge=new Map;function Ke(e,t){let n=e[0]+e[1]*256+e[2]*65536+t[0]*16777216+t[1]*4294967296+t[2]*1099511627776,r=Ge.get(n);if(r)return r;let i=new Float32Array(9),a=i.subarray(0,3),o=i.subarray(3,6);Ve(e,o);let s=i.subarray(6,9);Ve(t,s);let c=s[2]<.5,l=c?12:4.5;if(o[2]=c?Math.sqrt(o[2]):1-Math.sqrt(1-o[2]),We(o,s,a).005;){let n=o[2]=(e+t)/2;c===We(o,s,a){n.delete()},{signal:n._signal}),this.#r.append(r)}get#p(){let e=document.createElement(`div`);return e.className=`divider`,e}async addAltText(e){let t=await e.render();this.#f(t),this.#r.append(t,this.#p),this.#i=e}addComment(e,t=null){if(this.#a)return;let n=e.renderForToolbar();if(!n)return;this.#f(n);let r=this.#o=this.#p;t?(this.#r.insertBefore(n,t),this.#r.insertBefore(r,t)):this.#r.append(n,r),this.#a=e,e.toolbar=this}addColorPicker(e){if(this.#t)return;this.#t=e;let t=e.renderButton();this.#f(t),this.#r.append(t,this.#p)}async addEditSignatureButton(e){let t=this.#s=await e.renderEditButton(this.#n);this.#f(t),this.#r.append(t,this.#p)}removeButton(e){switch(e){case`comment`:this.#a?.removeToolbarCommentButton(),this.#a=null,this.#o?.remove(),this.#o=null;break}}async addButton(e,t){switch(e){case`colorPicker`:t&&this.addColorPicker(t);break;case`altText`:t&&await this.addAltText(t);break;case`editSignature`:t&&await this.addEditSignatureButton(t);break;case`delete`:this.addDeleteButton();break;case`comment`:t&&this.addComment(t);break}}async addButtonBefore(e,t,n){if(!t&&e===`comment`)return;let r=this.#r.querySelector(n);r&&e===`comment`&&this.addComment(t,r)}updateEditSignatureButton(e){this.#s&&(this.#s.title=e)}remove(){this.#e.remove(),this.#t?.destroy(),this.#t=null}},Xe=class{#e=null;#t=null;#n;constructor(e){this.#n=e}#r(){let e=this.#t=document.createElement(`div`);e.className=`editToolbar`,e.setAttribute(`role`,`toolbar`);let t=this.#n._signal;t instanceof AbortSignal&&!t.aborted&&e.addEventListener(`contextmenu`,H,{signal:t});let n=this.#e=document.createElement(`div`);return n.className=`buttons`,e.append(n),this.#n.hasCommentManager()&&this.#a(`commentButton`,`pdfjs-comment-floating-button`,`pdfjs-comment-floating-button-label`,()=>{this.#n.commentSelection(`floating_button`)}),this.#a(`highlightButton`,`pdfjs-highlight-floating-button1`,`pdfjs-highlight-floating-button-label`,()=>{this.#n.highlightSelection(`floating_button`)}),e}#i(e,t){let n=0,r=0;for(let i of e){let e=i.y+i.height;if(en){r=a,n=e;continue}t?a>r&&(r=a):a=1}static clearPointerType(){e.#r=null}static clearPointerIds(){e.#e=NaN,e.#t=null}static clearTimeStamp(){e.#n=NaN}},$e=class{#e=0;get id(){return`${f}${this.#e++}`}},et=class e{#e=ue();#t=0;#n=null;static get _isSVGFittingCanvas(){let e=`data:image/svg+xml;charset=UTF-8,`,t=new OffscreenCanvas(1,3).getContext(`2d`,{willReadFrequently:!0}),n=new Image;n.src=e;let r=n.decode().then(()=>(t.drawImage(n,0,0,1,1,0,0,1,3),new Uint32Array(t.getImageData(0,0,1,1).data.buffer)[0]===0));return F(this,`_isSVGFittingCanvas`,r)}async#r(t,n){this.#n||=new Map;let r=this.#n.get(t);if(r===null)return null;if(r?.bitmap)return r.refCounter+=1,r;try{r||={bitmap:null,id:`image_${this.#e}_${this.#t++}`,refCounter:0,isSvg:!1};let t;if(typeof n==`string`?(r.url=n,t=await Se(n,`blob`)):n instanceof File?t=r.file=n:n instanceof Blob&&(t=n),t.type===`image/svg+xml`){let n=e._isSVGFittingCanvas,i=new FileReader,a=new Image,o=new Promise((e,t)=>{a.onload=()=>{r.bitmap=a,r.isSvg=!0,e()},i.onload=async()=>{let e=r.svgUrl=i.result;a.src=await n?`${e}#svgView(preserveAspectRatio(none))`:e},a.onerror=i.onerror=t});i.readAsDataURL(t),await o}else r.bitmap=await createImageBitmap(t);r.refCounter=1}catch(e){O(e),r=null}return this.#n.set(t,r),r&&this.#n.set(r.id,r),r}async getFromFile(e){let{lastModified:t,name:n,size:r,type:i}=e;return this.#r(`${t}_${n}_${r}_${i}`,e)}async getFromUrl(e){return this.#r(e,e)}async getFromBlob(e,t){let n=await t;return this.#r(e,n)}async getFromId(e){this.#n||=new Map;let t=this.#n.get(e);if(!t)return null;if(t.bitmap)return t.refCounter+=1,t;if(t.file)return this.getFromFile(t.file);if(t.blobPromise){let{blobPromise:e}=t;return delete t.blobPromise,this.getFromBlob(t.id,e)}return this.getFromUrl(t.url)}getFromCanvas(e,t){this.#n||=new Map;let n=this.#n.get(e);if(n?.bitmap)return n.refCounter+=1,n;let r=new OffscreenCanvas(t.width,t.height);return r.getContext(`2d`).drawImage(t,0,0),n={bitmap:r.transferToImageBitmap(),id:`image_${this.#e}_${this.#t++}`,refCounter:1,isSvg:!1},this.#n.set(e,n),this.#n.set(n.id,n),n}getSvgUrl(e){let t=this.#n.get(e);return t?.isSvg?t.svgUrl:null}deleteId(e){this.#n||=new Map;let t=this.#n.get(e);if(!t||(--t.refCounter,t.refCounter!==0))return;let{bitmap:n}=t;if(!t.url&&!t.file){let e=new OffscreenCanvas(n.width,n.height);e.getContext(`bitmaprenderer`).transferFromImageBitmap(n),t.blobPromise=e.convertToBlob()}n.close?.(),t.bitmap=null}isValidId(e){return e.startsWith(`image_${this.#e}_`)}},tt=class{#e=[];#t=!1;#n;#r=-1;constructor(e=128){this.#n=e}add({cmd:e,undo:t,post:n,mustExec:r,type:i=NaN,overwriteIfSameType:a=!1,keepUndo:o=!1}){if(r&&e(),this.#t)return;let s={cmd:e,undo:t,post:n,type:i};if(this.#r===-1){this.#e.length>0&&(this.#e.length=0),this.#r=0,this.#e.push(s);return}if(a&&this.#e[this.#r].type===i){o&&(s.undo=this.#e[this.#r].undo),this.#e[this.#r]=s;return}let c=this.#r+1;c===this.#n?this.#e.splice(0,1):(this.#r=c,c=0;t--)if(this.#e[t].type!==e){this.#e.splice(t+1,this.#r-t),this.#r=t;return}this.#e.length=0,this.#r=-1}}destroy(){this.#e=null}},nt=class e{static ALT=1;static CTRL=2;static META=4;static SHIFT=8;constructor(t){this.callbacks=new Map;let{isMac:n}=z.platform;for(let[r,i,a={}]of t){let t=r.some(e=>e.startsWith(`mac+`));for(let o of r){let r=o;if(t){let e=o.startsWith(`mac+`);if(n!==e)continue;e&&(r=o.slice(4))}let[s,c]=e.#e(r);s!==null&&this.callbacks.getOrInsertComputed(s,fe).push({callback:i,options:a,modifiers:c})}}}static#e(t){let n=null,r=0;for(let i of t.split(`+`)){if(i=i.trim(),!i)continue;let a=i.toUpperCase(),o=e[a];if(o){r|=o;continue}if(n!==null){O(`KeyboardManager: multiple keys in shortcut "${t}"`);break}n=a===`SPACE`?` `:i}return n===null&&O(`KeyboardManager: no key found in shortcut "${t}"`),[n,r]}static#t(e){let t=/^(?:Key([A-Z])|(?:Digit|Numpad)(\d))$/.exec(e);return t?t[1]?.toLowerCase()??t[2]:null}exec(t,n){let r=this.callbacks.get(n.key);if(!r){if(/^[a-z]$/i.test(n.key))return;let t=e.#t(n.code);if(t===null||t===n.key||(r=this.callbacks.get(t),!r))return}let i=(n.altKey?e.ALT:0)|(n.ctrlKey?e.CTRL:0)|(n.metaKey?e.META:0)|(n.shiftKey?e.SHIFT:0),a=r.find(e=>e.modifiers===i);if(!a)return;let{callback:o,options:{bubbles:s=!1,args:c=[],checker:l=null}}=a;l&&!l(t,n)||(o.bind(t,...c,n)(),s||U(n))}},rt=class e{static _colorsMapping=new Map([[`CanvasText`,[0,0,0]],[`Canvas`,[255,255,255]]]);get _colors(){let e=new Map([[`CanvasText`,null],[`Canvas`,null]]);return Ne(e),F(this,`_colors`,e)}convert(t){let n=Me(t);if(!window.matchMedia(`(forced-colors: active)`).matches)return n;for(let[t,r]of this._colors)if(r.every((e,t)=>e===n[t]))return e._colorsMapping.get(t);return n}getHexCode(e){let t=this._colors.get(e);return t?B.makeHexColor(...t):e}},it=class e{#e=new AbortController;#t=null;#n=null;#r=new Map;#i=new Map;#a=null;#o=null;#s=null;#c=null;#l=new tt;#u=null;#d=null;#f=null;#p=0;#m=new Set;#h=null;#g=null;#_=new Set;_editorUndoBar=null;#v=!1;#y=!1;#b=!1;#x=null;#S=null;#C=null;#w=null;#T=!1;#E=null;#D=new $e;#O=!1;#k=!1;#A=!1;#j=null;#M=null;#N=null;#P=null;#F=null;#I=p.NONE;#L=new Set;#R=null;#z=null;#B=null;#V=null;#H=null;#U={isEditing:!1,isEmpty:!0,hasSomethingToUndo:!1,hasSomethingToRedo:!1,hasSelectedEditor:!1,hasSelectedText:!1};#W=[0,0];#G=null;#K=null;#q=null;#J=null;#Y=null;static TRANSLATE_SMALL=1;static TRANSLATE_BIG=10;static get _keyboardManager(){let t=e.prototype,n=e=>e.#K.contains(document.activeElement)&&document.activeElement.tagName!==`BUTTON`&&e.hasSomethingToControl(),r=(e,{target:t})=>{if(t instanceof HTMLInputElement){let{type:e}=t;return e!==`text`&&e!==`number`}return!0},i=this.TRANSLATE_SMALL,a=this.TRANSLATE_BIG;return F(this,`_keyboardManager`,new nt([[[`ctrl+a`,`mac+meta+a`],t.selectAll,{checker:r}],[[`ctrl+z`,`mac+meta+z`],t.undo,{checker:r}],[[`ctrl+y`,`ctrl+shift+z`,`mac+meta+shift+z`,`ctrl+shift+Z`,`mac+meta+shift+Z`],t.redo,{checker:r}],[[`Backspace`,`alt+Backspace`,`ctrl+Backspace`,`shift+Backspace`,`mac+Backspace`,`mac+alt+Backspace`,`mac+ctrl+Backspace`,`Delete`,`ctrl+Delete`,`shift+Delete`,`mac+Delete`],t.delete,{checker:r}],[[`Enter`],t.addNewEditorFromKeyboard,{checker:(e,{target:t})=>!(t instanceof HTMLButtonElement)&&e.#K.contains(t)&&!e.isEnterHandled}],[[`Space`],t.addNewEditorFromKeyboard,{checker:(e,{target:t})=>!(t instanceof HTMLButtonElement)&&e.#K.contains(document.activeElement)}],[[`Escape`],t.unselectAll],[[`ArrowLeft`],t.translateSelectedEditors,{args:[-i,0],checker:n}],[[`ctrl+ArrowLeft`,`mac+shift+ArrowLeft`],t.translateSelectedEditors,{args:[-a,0],checker:n}],[[`ArrowRight`],t.translateSelectedEditors,{args:[i,0],checker:n}],[[`ctrl+ArrowRight`,`mac+shift+ArrowRight`],t.translateSelectedEditors,{args:[a,0],checker:n}],[[`ArrowUp`],t.translateSelectedEditors,{args:[0,-i],checker:n}],[[`ctrl+ArrowUp`,`mac+shift+ArrowUp`],t.translateSelectedEditors,{args:[0,-a],checker:n}],[[`ArrowDown`],t.translateSelectedEditors,{args:[0,i],checker:n}],[[`ctrl+ArrowDown`,`mac+shift+ArrowDown`],t.translateSelectedEditors,{args:[0,a],checker:n}]]))}constructor(e,t,n,r,i,a,o,s,c,l,u,d,f,p,m,h){let g=this._signal=this.#e.signal;this.#K=e,this.#q=t,this.#J=n,this.#o=r,this.#u=i,this.#z=a,this.#H=s,this._eventBus=o;let _={signal:g,...Ze};o.on(`editingaction`,this.onEditingAction.bind(this),_),o.on(`pagechanging`,this.onPageChanging.bind(this),_),o.on(`scalechanging`,this.onScaleChanging.bind(this),_),o.on(`rotationchanging`,this.onRotationChanging.bind(this),_),o.on(`setpreference`,this.onSetPreference.bind(this),_),o.on(`switchannotationeditorparams`,e=>this.updateParams(e.type,e.value),_),window.addEventListener(`pointerdown`,()=>{this.#k=!0},{capture:!0,signal:g}),window.addEventListener(`pointerup`,()=>{this.#k=!1},{capture:!0,signal:g}),window.addEventListener(`beforeunload`,this.endCurrentEditing.bind(this),{capture:!0,signal:g}),this.#te(),this.#ce(),this.#ie(),this.#s=s.annotationStorage,this.#x=s.filterFactory,this.#B=c,this.#w=l||null,this.#v=u,this.#y=d,this.#b=f,this.#F=p||null,this.viewParameters={realScale:xe.PDF_TO_CSS_UNITS,rotation:0},this.isShiftKeyDown=!1,this._editorUndoBar=m||null,this._supportsPinchToZoom=h!==!1,i?.setSidebarUiManager(this)}destroy(){this.#Y?.resolve(),this.#Y=null,this.#e?.abort(),this.#e=null,this._signal=null;for(let e of this.#i.values())e.destroy();this.#i.clear(),this.#r.clear(),this.#_.clear(),this.#P?.clear(),this.#t=null,this.#L.clear(),this.#l.destroy(),this.#o?.destroy(),this.#u?.destroy(),this.#z?.destroy(),this.#E?.hide(),this.#E=null,this.#N?.destroy(),this.#N=null,this.#n=null,this.#S&&=(clearTimeout(this.#S),null),this.#G&&=(clearTimeout(this.#G),null),this._editorUndoBar?.destroy(),this.#H=null}combinedSignal(e){return AbortSignal.any([this._signal,e.signal])}get mlManager(){return this.#F}get useNewAltTextFlow(){return this.#y}get useNewAltTextWhenAddingImage(){return this.#b}get hcmFilter(){return F(this,`hcmFilter`,this.#B?this.#x.addHCMFilter(this.#B.foreground,this.#B.background):`none`)}get direction(){return F(this,`direction`,getComputedStyle(this.#K).direction)}get _highlightColors(){return F(this,`_highlightColors`,this.#w?new Map(this.#w.split(`,`).map(e=>(e=e.split(`=`).map(e=>e.trim()),e[1]=e[1].toUpperCase(),e))):null)}get highlightColors(){let{_highlightColors:e}=this;if(!e)return F(this,`highlightColors`,null);let t=new Map,n=!!this.#B;for(let[r,i]of e){let e=r.endsWith(`_HCM`);if(n&&e){t.set(r.replace(`_HCM`,``),i);continue}!n&&!e&&t.set(r,i)}return F(this,`highlightColors`,t)}get highlightColorNames(){return F(this,`highlightColorNames`,this.highlightColors?new Map(Array.from(this.highlightColors,e=>e.reverse())):null)}getNonHCMColor(e){if(!this._highlightColors)return e;let t=this.highlightColorNames.get(e);return this._highlightColors.get(t)||e}getNonHCMColorName(e){return this.highlightColorNames.get(e)||e}setCurrentDrawingSession(e){e?(this.unselectAll(),this.disableUserSelect(!0)):this.disableUserSelect(!1),this.#f=e}setMainHighlightColorPicker(e){this.#N=e}editAltText(e,t=!1){this.#o?.editAltText(this,e,t)}hasCommentManager(){return!!this.#u}editComment(e,t,n,r){this.#u?.showDialog(this,e,t,n,r)}selectComment(e,t){(this.#i.get(e)?.getEditorByUID(t))?.toggleComment(!0,!0)}updateComment(e){this.#u?.updateComment(e.getData())}updatePopupColor(e){this.#u?.updatePopupColor(e)}removeComment(e){this.#u?.removeComments([e.uid])}deleteComment(e,t){let n=()=>{e.comment=t};this.addCommands({cmd:()=>{this._editorUndoBar?.show(n,`comment`),this.toggleComment(null),e.comment=null},undo:n,mustExec:!0})}toggleComment(e,t,n=void 0){this.#u?.toggleCommentPopup(e,t,n)}makeCommentColor(e,t){return e&&this.#u?.makeCommentColor(e,t)||null}getCommentDialogElement(){return this.#u?.dialogElement||null}async waitForEditorsRendered(e){if(this.#i.has(e-1))return;let{resolve:t,promise:n}=Promise.withResolvers(),r=n=>{n.pageNumber===e&&(this._eventBus.off(`editorsrendered`,r),t())};this._eventBus.on(`editorsrendered`,r,Ze),await n}getSignature(e){this.#z?.getSignature({uiManager:this,editor:e})}get signatureManager(){return this.#z}switchToMode(e,t){this._eventBus.on(`annotationeditormodechanged`,t,{once:!0,signal:this._signal,...Ze}),this._eventBus.dispatch(`showannotationeditorui`,{source:this,mode:e})}setPreference(e,t){this._eventBus.dispatch(`setpreference`,{source:this,name:e,value:t})}onSetPreference({name:e,value:t}){switch(e){case`enableNewAltTextWhenAddingImage`:this.#b=t;break}}onPageChanging({pageNumber:e}){this.#p=e-1}deletePage(e){for(let t of this.getEditors(e))t.remove();this.#i.delete(e),this.#p===e&&(this.#p=0)}focusMainContainer(){this.#K.focus()}findParent(e,t){for(let n of this.#i.values()){let{x:r,y:i,width:a,height:o}=n.div.getBoundingClientRect();if(e>=r&&e<=r+a&&t>=i&&t<=i+o)return n}return null}disableUserSelect(e=!1){this.#q.classList.toggle(`noUserSelect`,e)}addShouldRescale(e){this.#_.add(e)}removeShouldRescale(e){this.#_.delete(e)}onScaleChanging({scale:e}){this.commitOrRemove(),this.viewParameters.realScale=e*xe.PDF_TO_CSS_UNITS;for(let e of this.#_)e.onScaleChanging();this.#f?.onScaleChanging()}onRotationChanging({pagesRotation:e}){this.commitOrRemove(),this.viewParameters.rotation=e}#X({anchorNode:e}){return e.nodeType===Node.TEXT_NODE?e.parentElement:e}#Z(e){let{currentLayer:t}=this;if(t.hasTextLayer(e))return t;for(let t of this.#i.values())if(t.hasTextLayer(e))return t;return null}highlightSelection(e=``,t=!1){let n=document.getSelection();if(!n||n.isCollapsed)return;let{anchorNode:r,anchorOffset:i,focusNode:a,focusOffset:o}=n,s=n.toString(),c=this.#X(n).closest(`.textLayer`),l=this.getSelectionBoxes(c);if(!l)return;n.empty();let u=this.#Z(c),d=this.#I===p.NONE,f=()=>{let n=u?.createAndAddNewEditor({x:0,y:0},!1,{methodOfCreation:e,boxes:l,anchorNode:r,anchorOffset:i,focusNode:a,focusOffset:o,text:s});d&&this.showAllEditors(`highlight`,!0,!0),t&&n?.editComment()};if(d){this.switchToMode(p.HIGHLIGHT,f);return}f()}commentSelection(e=``){this.highlightSelection(e,!0)}endCurrentEditing(){this.commitOrRemove(),this.currentLayer?.endDrawingSession(!1)}#Q(){let e=document.getSelection();if(!e||e.isCollapsed)return;let t=this.#X(e).closest(`.textLayer`),n=this.getSelectionBoxes(t);n&&(this.#E||=new Xe(this),this.#E.show(t,n,this.direction===`ltr`))}getAndRemoveDataFromAnnotationStorage(e){if(!this.#s)return null;let t=`${f}${e}`,n=this.#s.getRawValue(t);return n&&this.#s.remove(t),n}addToAnnotationStorage(e){!e.isEmpty()&&this.#s&&!this.#s.has(e.id)&&this.#s.setValue(e.id,e)}a11yAlert(e,t=null){let n=this.#J;n&&(n.setAttribute(`data-l10n-id`,e),t?n.setAttribute(`data-l10n-args`,JSON.stringify(t)):n.removeAttribute(`data-l10n-args`))}#$(){let e=document.getSelection();if(!e||e.isCollapsed){this.#R&&(this.#E?.hide(),this.#R=null,this.#le({hasSelectedText:!1}));return}let{anchorNode:t}=e;if(t===this.#R)return;let n=this.#X(e).closest(`.textLayer`);if(!n){this.#R&&(this.#E?.hide(),this.#R=null,this.#le({hasSelectedText:!1}));return}if(this.#E?.hide(),this.#R=t,this.#le({hasSelectedText:!0}),!(this.#I!==p.HIGHLIGHT&&this.#I!==p.NONE)&&(this.#I===p.HIGHLIGHT&&this.showAllEditors(`highlight`,!0,!0),this.#T=this.isShiftKeyDown,!this.isShiftKeyDown)){let e=this.#I===p.HIGHLIGHT?this.#Z(n):null;if(e?.toggleDrawing(),this.#k){let t=new AbortController,n=this.combinedSignal(t),r=n=>{n.type===`pointerup`&&n.button!==0||(t.abort(),e?.toggleDrawing(!0),n.type===`pointerup`&&this.#ee(`main_toolbar`))};window.addEventListener(`pointerup`,r,{signal:n}),window.addEventListener(`blur`,r,{signal:n})}else e?.toggleDrawing(!0),this.#ee(`main_toolbar`)}}#ee(e=``){this.#I===p.HIGHLIGHT?this.highlightSelection(e):this.#v&&this.#Q()}#te(){document.addEventListener(`selectionchange`,this.#$.bind(this),{signal:this._signal})}#ne(){if(this.#C)return;this.#C=new AbortController;let e=this.combinedSignal(this.#C);window.addEventListener(`focus`,this.focus.bind(this),{signal:e}),window.addEventListener(`blur`,this.blur.bind(this),{signal:e})}#re(){this.#C?.abort(),this.#C=null}blur(){if(this.isShiftKeyDown=!1,this.#T&&(this.#T=!1,this.#ee(`main_toolbar`)),!this.hasSelection)return;let{activeElement:e}=document;for(let t of this.#L)if(t.div.contains(e)){this.#M=[t,e],t._focusEventsAllowed=!1;break}}focus(){if(!this.#M)return;let[e,t]=this.#M;this.#M=null,t.addEventListener(`focusin`,()=>{e._focusEventsAllowed=!0},{once:!0,signal:this._signal}),t.focus()}#ie(){if(this.#j)return;this.#j=new AbortController;let e=this.combinedSignal(this.#j);window.addEventListener(`keydown`,this.keydown.bind(this),{signal:e}),window.addEventListener(`keyup`,this.keyup.bind(this),{signal:e})}#ae(){this.#j?.abort(),this.#j=null}#oe(){if(this.#d)return;this.#d=new AbortController;let e=this.combinedSignal(this.#d);document.addEventListener(`copy`,this.copy.bind(this),{signal:e}),document.addEventListener(`cut`,this.cut.bind(this),{signal:e}),document.addEventListener(`paste`,this.paste.bind(this),{signal:e})}#se(){this.#d?.abort(),this.#d=null}#ce(){let e=this._signal;document.addEventListener(`dragover`,this.dragOver.bind(this),{signal:e}),document.addEventListener(`drop`,this.drop.bind(this),{signal:e})}addEditListeners(){this.#ie(),this.setEditingState(!0)}removeEditListeners(){this.#ae(),this.setEditingState(!1)}dragOver(e){for(let{type:t}of e.dataTransfer.items)for(let n of this.#g)if(n.isHandlingMimeForPasting(t)){e.dataTransfer.dropEffect=`copy`,e.preventDefault();return}}drop(e){for(let t of e.dataTransfer.items)for(let n of this.#g)if(n.isHandlingMimeForPasting(t.type)){n.paste(t,this.currentLayer),e.preventDefault();return}}copy(e){if(e.preventDefault(),this.#t?.commitOrRemove(),!this.hasSelection)return;let t=[];for(let e of this.#L){let n=e.serialize(!0);n&&t.push(n)}t.length!==0&&e.clipboardData.setData(`application/pdfjs`,JSON.stringify(t))}cut(e){this.copy(e),this.delete()}async paste(e){e.preventDefault();let{clipboardData:t}=e;for(let e of t.items)for(let t of this.#g)if(t.isHandlingMimeForPasting(e.type)){t.paste(e,this.currentLayer);return}let n=t.getData(`application/pdfjs`);if(!n)return;try{n=JSON.parse(n)}catch(e){O(`paste: "${e.message}".`);return}if(!Array.isArray(n))return;this.unselectAll();let r=this.currentLayer;try{let e=[];for(let t of n){let n=await r.deserialize(t);if(!n)return;e.push(n)}this.addCommands({cmd:()=>{for(let t of e)this.#pe(t);this.#ge(e)},undo:()=>{for(let t of e)t.remove()},mustExec:!0})}catch(e){O(`paste: "${e.message}".`)}}keydown(t){!this.isShiftKeyDown&&t.key===`Shift`&&(this.isShiftKeyDown=!0),this.#I!==p.NONE&&!this.isEditorHandlingKeyboard&&e._keyboardManager.exec(this,t)}keyup(e){this.isShiftKeyDown&&e.key===`Shift`&&(this.isShiftKeyDown=!1,this.#T&&(this.#T=!1,this.#ee(`main_toolbar`)))}onEditingAction({name:e}){switch(e){case`undo`:case`redo`:case`delete`:case`selectAll`:this[e]();break;case`highlightSelection`:this.highlightSelection(`context_menu`);break;case`commentSelection`:this.commentSelection(`context_menu`);break}}updatePageIndex(e,t){for(let n of this.getEditors(e))n.pageIndex=t;let n=this.#a.get(e);n&&(n.pageIndex=t,this.#i.set(t,n),this.#O?n.enable():n.disable())}startUpdatePages(){this.#a=new Map(this.#i),this.#i.clear()}endUpdatePages(){this.#a=null}clonePage(e,t){for(let n of this.getEditors(e)){let e=n.serialize(n.mode!==p.HIGHLIGHT);e&&(e.pageIndex=t,e.id=this.getId(),e.isClone=!0,delete e.popupRef,this.#s.setValue(e.id,e))}}findClonesForPage(e){let t=[],{pageIndex:n}=e;for(let[r,i]of this.#s)i.pageIndex===n&&i.isClone&&(this.#s.remove(r),t.push(e.deserialize(i).then(t=>{t&&(t.isClone=!0,e.addOrRebuild(t))})));return Promise.all(t)}#le(e){Object.entries(e).some(([e,t])=>this.#U[e]!==t)&&(this._eventBus.dispatch(`editingstateschanged`,{source:this,details:Object.assign(this.#U,e)}),this.#I===p.HIGHLIGHT&&e.hasSelectedEditor===!1&&this.#ue([[m.HIGHLIGHT_FREE,!0]]))}#ue(e){this._eventBus.dispatch(`annotationeditorparamschanged`,{source:this,details:e})}setEditingState(e){e?(this.#ne(),this.#oe(),this.#le({isEditing:this.#I!==p.NONE,isEmpty:this.#he(),hasSomethingToUndo:this.#l.hasSomethingToUndo(),hasSomethingToRedo:this.#l.hasSomethingToRedo(),hasSelectedEditor:!1})):(this.#re(),this.#se(),this.#le({isEditing:!1}),this.disableUserSelect(!1))}registerEditorTypes(e){if(!this.#g){this.#g=e;for(let e of this.#g)this.#ue(e.defaultPropertiesToUpdate)}}getId(){return this.#D.id}get currentLayer(){return this.#i.get(this.#p)}getLayer(e){return this.#i.get(e)}get currentPageIndex(){return this.#p}addLayer(e){this.#i.set(e.pageIndex,e),this.#O?e.enable():e.disable()}removeLayer(e){this.#i.delete(e.pageIndex)}async updateMode(e,t=null,n=!1,r=!1,i=!1,a=!1){if(this.#I!==e&&!(this.#Y&&(await this.#Y.promise,!this.#Y))){if(this.#Y=Promise.withResolvers(),this.#f?.commitOrRemove(),this.#I===p.POPUP&&this.#u?.hideSidebar(),this.#u?.destroyPopup(),this.#I=e,e===p.NONE){this.setEditingState(!1),this.#fe();for(let e of this.#r.values())e.hideStandaloneCommentButton();this._editorUndoBar?.hide(),this.toggleComment(null),this.#Y.resolve();return}for(let e of this.#r.values())e.addStandaloneCommentButton();e===p.SIGNATURE&&await this.#z?.loadSignatures(),n&&G.clearPointerType(),this.setEditingState(!0),await this.#de(),this.unselectAll();for(let t of this.#i.values())t.updateMode(e);if(e===p.POPUP){this.#n||=await this.#H.getAnnotationsByType(new Set(this.#g.map(e=>e._editorType)));let e=new Set,t=[];for(let n of this.#r.values()){let{annotationElementId:r,hasComment:i,deleted:a}=n;r&&e.add(r),i&&!a&&t.push(n.getData())}for(let n of this.#n){let{id:r,popupRef:i,contentsObj:a}=n;i&&a?.str&&!e.has(r)&&!this.#m.has(r)&&t.push(n)}this.#u?.showSidebar(t)}if(!t){r&&this.addNewEditorFromKeyboard(),this.#Y.resolve();return}for(let e of this.#r.values())e.uid===t?(this.setSelected(e),a?e.editComment():i?e.enterInEditMode():e.focus()):e.unselect();this.#Y.resolve()}}addNewEditorFromKeyboard(){this.currentLayer.canCreateNewEmptyEditor()&&this.currentLayer.addNewEditor()}updateToolbar(e){e.mode!==this.#I&&this._eventBus.dispatch(`switchannotationeditormode`,{source:this,...e})}updateParams(e,t){if(this.#g){switch(e){case m.CREATE:this.currentLayer.addNewEditor(t);return;case m.HIGHLIGHT_SHOW_ALL:this._eventBus.dispatch(`reporttelemetry`,{source:this,details:{type:`editing`,data:{type:`highlight`,action:`toggle_visibility`}}}),(this.#V||=new Map).set(e,t),this.showAllEditors(`highlight`,t);break}if(this.hasSelection)for(let n of this.#L)n.updateParams(e,t);else for(let n of this.#g)n.updateDefaultParams(e,t)}}showAllEditors(e,t,n=!1){for(let n of this.#r.values())n.editorType===e&&n.show(t);(this.#V?.get(m.HIGHLIGHT_SHOW_ALL)??!0)!==t&&this.#ue([[m.HIGHLIGHT_SHOW_ALL,t]])}enableWaiting(e=!1){if(this.#A!==e){this.#A=e;for(let t of this.#i.values())e?t.disableClick():t.enableClick(),t.div.classList.toggle(`waiting`,e)}}async#de(){if(!this.#O){this.#O=!0;let e=[];for(let t of this.#i.values())e.push(t.enable());await Promise.all(e);for(let e of this.#r.values())e.enable()}}#fe(){if(this.unselectAll(),this.#O){this.#O=!1;for(let e of this.#i.values())e.disable();for(let e of this.#r.values())e.disable()}}*getEditors(e){for(let t of this.#r.values())t.pageIndex===e&&(yield t)}getEditor(e){return this.#r.get(e)}addEditor(e){this.#r.set(e.id,e)}removeEditor(e){e.div.contains(document.activeElement)&&(this.#S&&clearTimeout(this.#S),this.#S=setTimeout(()=>{this.focusMainContainer(),this.#S=null},0)),this.#r.delete(e.id),e.annotationElementId&&this.#P?.delete(e.annotationElementId),this.unselect(e),(!e.annotationElementId||!this.#m.has(e.annotationElementId))&&this.#s?.remove(e.id)}addDeletedAnnotationElement(e){this.#m.add(e.annotationElementId),this.addChangedExistingAnnotation(e),e.deleted=!0}isDeletedAnnotationElement(e){return this.#m.has(e)}removeDeletedAnnotationElement(e){this.#m.delete(e.annotationElementId),this.removeChangedExistingAnnotation(e),e.deleted=!1}#pe(e){let t=this.#i.get(e.pageIndex);t?t.addOrRebuild(e):(this.addEditor(e),this.addToAnnotationStorage(e))}setActiveEditor(e){this.#t!==e&&(this.#t=e,e&&this.#ue(e.propertiesToUpdate))}get#me(){let e=null;for(e of this.#L);return e}updateUI(e){this.#me===e&&this.#ue(e.propertiesToUpdate)}updateUIForDefaultProperties(e){this.#ue(e.defaultPropertiesToUpdate)}toggleSelected(e){if(this.#L.has(e)){this.#L.delete(e),e.unselect(),this.#le({hasSelectedEditor:this.hasSelection});return}this.#L.add(e),e.select(),this.#ue(e.propertiesToUpdate),this.#le({hasSelectedEditor:!0})}setSelected(e){this.updateToolbar({mode:e.mode,editId:e.uid}),this.#f?.commitOrRemove();for(let t of this.#L)t!==e&&t.unselect();this.#u?.destroyPopup(),this.#L.clear(),this.#L.add(e),e.select(),this.#ue(e.propertiesToUpdate),this.#le({hasSelectedEditor:!0})}get firstSelectedEditor(){return this.#L.values().next().value}unselect(e){e.unselect(),this.#L.delete(e),this.#le({hasSelectedEditor:this.hasSelection})}get hasSelection(){return this.#L.size!==0}get isEnterHandled(){return this.#L.size===1&&this.firstSelectedEditor.isEnterHandled}undo(){this.#l.undo(),this.#le({hasSomethingToUndo:this.#l.hasSomethingToUndo(),hasSomethingToRedo:!0,isEmpty:this.#he()}),this._editorUndoBar?.hide()}redo(){this.#l.redo(),this.#le({hasSomethingToUndo:!0,hasSomethingToRedo:this.#l.hasSomethingToRedo(),isEmpty:this.#he()})}addCommands(e){this.#l.add(e),this.#le({hasSomethingToUndo:!0,hasSomethingToRedo:!1,isEmpty:this.#he()})}cleanUndoStack(e){this.#l.cleanType(e)}#he(){if(this.#r.size===0)return!0;if(this.#r.size===1)for(let e of this.#r.values())return e.isEmpty();return!1}delete(){this.commitOrRemove();let e=this.currentLayer?.endDrawingSession(!0);if(!this.hasSelection&&!e)return;let t=e?[e]:[...this.#L],n=()=>{this._editorUndoBar?.show(r,t.length===1?t[0].editorType:t.length);for(let e of t)e.remove()},r=()=>{for(let e of t)this.#pe(e)};this.addCommands({cmd:n,undo:r,mustExec:!0})}commitOrRemove(){this.#t?.commitOrRemove()}hasSomethingToControl(){return this.#t||this.hasSelection}#ge(e){for(let e of this.#L)e.unselect();this.#L.clear();for(let t of e)t.isEmpty()||(this.#L.add(t),t.select());this.#le({hasSelectedEditor:this.hasSelection})}selectAll(){for(let e of this.#L)e.commit();this.#ge(this.#r.values())}unselectAll(){if(!(this.#t&&(this.#t.commitOrRemove(),this.#I!==p.NONE))&&!this.#f?.commitOrRemove()&&(this.#u?.destroyPopup(),this.hasSelection)){for(let e of this.#L)e.unselect();this.#L.clear(),this.#le({hasSelectedEditor:!1})}}translateSelectedEditors(e,t,n=!1){if(n||this.commitOrRemove(),!this.hasSelection)return;this.#W[0]+=e,this.#W[1]+=t;let[r,i]=this.#W,a=[...this.#L];this.#G&&clearTimeout(this.#G),this.#G=setTimeout(()=>{this.#G=null,this.#W[0]=this.#W[1]=0,this.addCommands({cmd:()=>{for(let e of a)this.#r.has(e.id)&&(e.translateInPage(r,i),e.translationDone())},undo:()=>{for(let e of a)this.#r.has(e.id)&&(e.translateInPage(-r,-i),e.translationDone())},mustExec:!1})},1e3);for(let n of a)n.translateInPage(e,t),n.translationDone()}setUpDragSession(){if(this.hasSelection){this.disableUserSelect(!0),this.#h=new Map;for(let e of this.#L)this.#h.set(e,{savedX:e.x,savedY:e.y,savedPageIndex:e.pageIndex,newX:0,newY:0,newPageIndex:-1})}}endDragSession(){if(!this.#h)return!1;this.disableUserSelect(!1);let e=this.#h;this.#h=null;let t=!1;for(let[{x:n,y:r,pageIndex:i},a]of e)a.newX=n,a.newY=r,a.newPageIndex=i,t||=n!==a.savedX||r!==a.savedY||i!==a.savedPageIndex;if(!t)return!1;let n=(e,t,n,r)=>{if(this.#r.has(e.id)){let i=this.#i.get(r);i?e._setParentAndPosition(i,t,n):(e.pageIndex=r,e.x=t,e.y=n)}};return this.addCommands({cmd:()=>{for(let[t,{newX:r,newY:i,newPageIndex:a}]of e)n(t,r,i,a)},undo:()=>{for(let[t,{savedX:r,savedY:i,savedPageIndex:a}]of e)n(t,r,i,a)},mustExec:!0}),!0}dragSelectedEditors(e,t){if(this.#h)for(let n of this.#h.keys())n.drag(e,t)}rebuild(e){if(e.parent===null){let t=this.getLayer(e.pageIndex);t?(t.changeParent(e),t.addOrRebuild(e)):(this.addEditor(e),this.addToAnnotationStorage(e),e.rebuild())}else e.parent.addOrRebuild(e)}get isEditorHandlingKeyboard(){return this.getActive()?.shouldGetKeyboardEvents()||this.#L.size===1&&this.firstSelectedEditor.shouldGetKeyboardEvents()}isActive(e){return this.#t===e}getActive(){return this.#t}getMode(){return this.#I}isEditingMode(){return this.#I!==p.NONE}get imageManager(){return F(this,`imageManager`,new et)}getSelectionBoxes(e){if(!e)return null;let t=document.getSelection();for(let n=0,r=t.rangeCount;n({x:(t-r)/a,y:1-(e+o-n)/i,width:s/a,height:o/i});break;case`180`:o=(e,t,o,s)=>({x:1-(e+o-n)/i,y:1-(t+s-r)/a,width:o/i,height:s/a});break;case`270`:o=(e,t,o,s)=>({x:1-(t+s-r)/a,y:(e-n)/i,width:s/a,height:o/i});break;default:o=(e,t,o,s)=>({x:(e-n)/i,y:(t-r)/a,width:o/i,height:s/a});break}let s=[];for(let e=0,n=t.rangeCount;ee.stopPropagation(),{signal:r});let i=e=>{e.preventDefault(),this.#c._uiManager.editAltText(this.#c),this.#d&&this.#c._reportTelemetry({action:`pdfjs.image.alt_text.image_status_label_clicked`,data:{label:this.#p}})};return t.addEventListener(`click`,i,{capture:!0,signal:r}),t.addEventListener(`keydown`,e=>{e.target===t&&e.key===`Enter`&&(this.#o=!0,i(e))},{signal:r}),await this.#m(),t}get#p(){return this.#e&&`added`||this.#e===null&&this.guessedText&&`review`||`missing`}finish(){this.#n&&(this.#n.focus({focusVisible:this.#o}),this.#o=!1)}isEmpty(){return this.#d?this.#e===null:!this.#e&&!this.#t}hasData(){return this.#d?this.#e!==null||!!this.#l:this.isEmpty()}get guessedText(){return this.#l}async setGuessedText(t){this.#e===null&&(this.#l=t,this.#u=await e._l10n.get(`pdfjs-editor-new-alt-text-generated-alt-text-with-disclaimer`,{generatedAltText:t}),this.#m())}toggleAltTextBadge(e=!1){if(!this.#d||this.#e){this.#s?.remove(),this.#s=null;return}if(!this.#s){let e=this.#s=document.createElement(`div`);e.className=`noAltTextBadge`,this.#c.div.append(e)}this.#s.classList.toggle(`hidden`,!e)}serialize(e){let t=this.#e;return!e&&this.#l===t&&(t=this.#u),{altText:t,decorative:this.#t,guessedText:this.#l,textWithDisclaimer:this.#u}}get data(){return{altText:this.#e,decorative:this.#t}}set data({altText:e,decorative:t,guessedText:n,textWithDisclaimer:r,cancel:i=!1}){n&&(this.#l=n,this.#u=r),!(this.#e===e&&this.#t===t)&&(i||(this.#e=e,this.#t=t),this.#m())}toggle(e=!1){this.#n&&(!e&&this.#a&&(clearTimeout(this.#a),this.#a=null),this.#n.disabled=!e)}shown(){this.#c._reportTelemetry({action:`pdfjs.image.alt_text.image_status_label_displayed`,data:{label:this.#p}})}destroy(){this.#n?.remove(),this.#n=null,this.#r=null,this.#i=null,this.#s?.remove(),this.#s=null}async#m(){let t=this.#n;if(!t)return;if(this.#d){if(t.classList.toggle(`done`,!!this.#e),t.setAttribute(`data-l10n-id`,e.#f[this.#p]),this.#r?.setAttribute(`data-l10n-id`,e.#f[`${this.#p}-label`]),!this.#e){this.#i?.remove();return}}else{if(!this.#e&&!this.#t){t.classList.remove(`done`),this.#i?.remove();return}t.classList.add(`done`),t.setAttribute(`data-l10n-id`,`pdfjs-editor-alt-text-edit-button`)}let n=this.#i;if(!n){this.#i=n=document.createElement(`span`),n.className=`tooltip`,n.setAttribute(`role`,`tooltip`),n.id=`alt-text-tooltip-${this.#c.id}`;let e=this.#c._uiManager._signal;e.addEventListener(`abort`,()=>{clearTimeout(this.#a),this.#a=null},{once:!0}),t.addEventListener(`mouseenter`,()=>{this.#a=setTimeout(()=>{this.#a=null,this.#i.classList.add(`show`),this.#c._reportTelemetry({action:`alt_text_tooltip`})},100)},{signal:e}),t.addEventListener(`mouseleave`,()=>{this.#a&&=(clearTimeout(this.#a),null),this.#i?.classList.remove(`show`)},{signal:e})}this.#t?n.setAttribute(`data-l10n-id`,`pdfjs-editor-alt-text-decorative-tooltip`):(n.removeAttribute(`data-l10n-id`),n.textContent=this.#e),n.parentNode||t.append(n),this.#c.getElementForAltText()?.setAttribute(`aria-describedby`,n.id)}},ot=class{#e=null;#t=null;#n=!1;#r=null;#i=null;#a=null;#o=null;#s=null;#c=!1;#l=null;constructor(e){this.#r=e}renderForToolbar(){let e=this.#t=document.createElement(`button`);return e.className=`comment`,this.#u(e,!1)}renderForStandalone(){let e=this.#e=document.createElement(`button`);e.className=`annotationCommentButton`;let t=this.#r.commentButtonPosition;if(t){let{style:n}=e;n.insetInlineEnd=`calc(${100*(this.#r._uiManager.direction===`ltr`?1-t[0]:t[0])}% - var(--comment-button-dim))`,n.top=`calc(${100*t[1]}% - var(--comment-button-dim))`;let r=this.#r.commentButtonColor;r&&(n.backgroundColor=r)}return this.#u(e,!0)}focusButton(){setTimeout(()=>{(this.#e??this.#t)?.focus()},0)}onUpdatedColor(){if(!this.#e)return;let e=this.#r.commentButtonColor;e&&(this.#e.style.backgroundColor=e),this.#r._uiManager.updatePopupColor(this.#r)}get commentButtonWidth(){return(this.#e?.getBoundingClientRect().width??0)/this.#r.parent.boundingClientRect.width}get commentPopupPositionInLayer(){if(this.#l)return this.#l;if(!this.#e)return null;let{x:e,y:t,height:n}=this.#e.getBoundingClientRect(),{x:r,y:i,width:a,height:o}=this.#r.parent.boundingClientRect;return[(e-r)/a,(t+n-i)/o]}set commentPopupPositionInLayer(e){this.#l=e}hasDefaultPopupPosition(){return this.#l===null}removeStandaloneCommentButton(){this.#e?.remove(),this.#e=null}removeToolbarCommentButton(){this.#t?.remove(),this.#t=null}setCommentButtonStates({selected:e,hasPopup:t}){this.#e&&(this.#e.classList.toggle(`selected`,e),this.#e.ariaExpanded=t)}#u(e,t){if(!this.#r._uiManager.hasCommentManager())return null;e.tabIndex=`0`,e.ariaHasPopup=`dialog`,t?(e.ariaControls=`commentPopup`,e.setAttribute(`data-l10n-id`,`pdfjs-show-comment-button`)):(e.ariaControlsElements=[this.#r._uiManager.getCommentDialogElement()],e.setAttribute(`data-l10n-id`,`pdfjs-editor-add-comment-button`));let n=this.#r._uiManager._signal;if(!(n instanceof AbortSignal)||n.aborted)return e;e.addEventListener(`contextmenu`,H,{signal:n}),t&&(e.addEventListener(`focusin`,e=>{this.#r._focusEventsAllowed=!1,U(e)},{capture:!0,signal:n}),e.addEventListener(`focusout`,e=>{this.#r._focusEventsAllowed=!0,U(e)},{capture:!0,signal:n})),e.addEventListener(`pointerdown`,e=>e.stopPropagation(),{signal:n});let r=t=>{t.preventDefault(),e===this.#t?this.edit():this.#r.toggleComment(!0)};return e.addEventListener(`click`,r,{capture:!0,signal:n}),e.addEventListener(`keydown`,t=>{t.target===e&&t.key===`Enter`&&(this.#n=!0,r(t))},{signal:n}),e.addEventListener(`pointerenter`,()=>{this.#r.toggleComment(!1,!0)},{signal:n}),e.addEventListener(`pointerleave`,()=>{this.#r.toggleComment(!1,!1)},{signal:n}),e}edit(e){let t=this.commentPopupPositionInLayer,n,r;if(t)[n,r]=t;else{[n,r]=this.#r.commentButtonPosition;let{width:e,height:t,x:i,y:a}=this.#r;n=i+n*e,r=a+r*t}let i=this.#r.parent.boundingClientRect,{x:a,y:o,width:s,height:c}=i;this.#r._uiManager.editComment(this.#r,a+n*s,o+r*c,{...e,parentDimensions:i})}finish(){this.#t&&(this.#t.focus({focusVisible:this.#n}),this.#n=!1)}isDeleted(){return this.#c||this.#o===``}isEmpty(){return this.#o===null}hasBeenEdited(){return this.isDeleted()||this.#o!==this.#i}serialize(){return this.data}get data(){return{text:this.#o,richText:this.#a,date:this.#s,deleted:this.isDeleted()}}set data(e){if(e!==this.#o&&(this.#a=null),e===null){this.#o=``,this.#c=!0;return}this.#o=e,this.#s=new Date,this.#c=!1}restoreData({text:e,richText:t,date:n}){this.#o=e,this.#a=t,this.#s=n,this.#c=!1}setInitialText(e,t=null){this.#i=e,this.data=e,this.#s=null,this.#a=t}shown(){}destroy(){this.#t?.remove(),this.#t=null,this.#e?.remove(),this.#e=null,this.#o=``,this.#a=null,this.#s=null,this.#r=null,this.#n=!1,this.#c=!1}},st=class e{#e;#t=!1;#n=null;#r;#i;#a;#o;#s=null;#c;#l=null;#u;#d=null;constructor({container:e,isPinchingDisabled:t=null,isPinchingStopped:n=null,onPinchStart:r=null,onPinching:i=null,onPinchEnd:a=null,signal:o}){this.#e=e,this.#n=n,this.#r=t,this.#i=r,this.#a=i,this.#o=a,this.#u=new AbortController,this.#c=AbortSignal.any([o,this.#u.signal]),e.addEventListener(`touchstart`,this.#f.bind(this),{passive:!1,signal:this.#c})}get MIN_TOUCH_DISTANCE_TO_PINCH(){return 35/Ie.pixelRatio}#f(e){if(this.#r?.())return;if(e.touches.length===1){if(this.#s)return;let e=this.#s=new AbortController,t=AbortSignal.any([this.#c,e.signal]),n=this.#e,r={capture:!0,signal:t,passive:!1},i=e=>{e.pointerType===`touch`&&(this.#s?.abort(),this.#s=null)};n.addEventListener(`pointerdown`,e=>{e.pointerType===`touch`&&(U(e),i(e))},r),n.addEventListener(`pointerup`,i,r),n.addEventListener(`pointercancel`,i,r);return}if(!this.#d){this.#d=new AbortController;let e=AbortSignal.any([this.#c,this.#d.signal]),t=this.#e,n={signal:e,capture:!1,passive:!1};t.addEventListener(`touchmove`,this.#p.bind(this),n);let r=this.#m.bind(this);t.addEventListener(`touchend`,r,n),t.addEventListener(`touchcancel`,r,n),n.capture=!0,t.addEventListener(`pointerdown`,U,n),t.addEventListener(`pointermove`,U,n),t.addEventListener(`pointercancel`,U,n),t.addEventListener(`pointerup`,U,n),this.#i?.()}if(U(e),e.touches.length!==2||this.#n?.()){this.#l=null;return}let[t,n]=e.touches;t.identifier>n.identifier&&([t,n]=[n,t]),this.#l={touch0X:t.screenX,touch0Y:t.screenY,touch1X:n.screenX,touch1Y:n.screenY}}#p(t){if(!this.#l||t.touches.length!==2)return;U(t);let[n,r]=t.touches;n.identifier>r.identifier&&([n,r]=[r,n]);let{screenX:i,screenY:a}=n,{screenX:o,screenY:s}=r,c=this.#l,{touch0X:l,touch0Y:u,touch1X:d,touch1Y:f}=c,p=d-l,m=f-u,h=o-i,g=s-a,_=Math.hypot(h,g)||1,v=Math.hypot(p,m)||1;if(!this.#t&&Math.abs(v-_)<=e.MIN_TOUCH_DISTANCE_TO_PINCH)return;if(c.touch0X=i,c.touch0Y=a,c.touch1X=o,c.touch1Y=s,!this.#t){this.#t=!0;return}let y=[(i+o)/2,(a+s)/2];this.#a?.(y,v,_)}#m(e){e.touches.length>=2||(this.#d&&(this.#d.abort(),this.#d=null,this.#o?.()),this.#l&&(U(e),this.#l=null,this.#t=!1))}destroy(){this.#u?.abort(),this.#u=null,this.#s?.abort(),this.#s=null}},K=class e{#e=null;#t=null;#n=null;#r=null;#i=null;#a=!1;#o=null;#s=``;#c=null;#l=null;#u=null;#d=null;#f=null;#p=``;#m=!1;#h=null;#g=!1;#_=!1;#v=!1;#y=null;#b=0;#x=0;#S=null;#C=null;isSelected=!1;_isCopy=!1;_editToolbar=null;_initialOptions=Object.create(null);_initialData=null;_isVisible=!0;_uiManager=null;_focusEventsAllowed=!0;static _l10n=null;static _l10nAlert=null;static _l10nResizer=null;#w=!1;#T=e._zIndex++;static _borderLineWidth=-1;static _colorManager=new rt;static _zIndex=1;static _telemetryTimeout=1e3;static get _resizerKeyboardManager(){let t=e.prototype._resizeWithKeyboard,n=it.TRANSLATE_SMALL,r=it.TRANSLATE_BIG;return F(this,`_resizerKeyboardManager`,new nt([[[`ArrowLeft`],t,{args:[-n,0]}],[[`ctrl+ArrowLeft`,`mac+shift+ArrowLeft`],t,{args:[-r,0]}],[[`ArrowRight`],t,{args:[n,0]}],[[`ctrl+ArrowRight`,`mac+shift+ArrowRight`],t,{args:[r,0]}],[[`ArrowUp`],t,{args:[0,-n]}],[[`ctrl+ArrowUp`,`mac+shift+ArrowUp`],t,{args:[0,-r]}],[[`ArrowDown`],t,{args:[0,n]}],[[`ctrl+ArrowDown`,`mac+shift+ArrowDown`],t,{args:[0,r]}],[[`Escape`],e.prototype._stopResizingWithKeyboard]]))}constructor(e){this.parent=e.parent,this.id=e.id,this.width=this.height=null,this.pageIndex=e.parent.pageIndex,this.name=e.name,this.div=null,this._uiManager=e.uiManager,this.annotationElementId=null,this._willKeepAspectRatio=!1,this._initialOptions.isCentered=e.isCentered,this._structTreeParentId=null,this.annotationElementId=e.annotationElementId||null,this.creationDate=e.creationDate||new Date,this.modificationDate=e.modificationDate||null,this.canAddComment=!0;let{rotation:t,rawDims:{pageWidth:n,pageHeight:r,pageX:i,pageY:a}}=this.parent.viewport;this.rotation=t,this.pageRotation=(360+t-this._uiManager.viewParameters.rotation)%360,this.pageDimensions=[n,r],this.pageTranslation=[i,a];let[o,s]=this.parentDimensions;this.x=e.x/o,this.y=e.y/s,this.isAttachedToDOM=!1,this.deleted=!1}updatePageIndex(e){this.pageIndex=e}get editorType(){return Object.getPrototypeOf(this).constructor._type}get mode(){return Object.getPrototypeOf(this).constructor._editorType}static get isDrawer(){return!1}static get _defaultLineColor(){return F(this,`_defaultLineColor`,this._colorManager.getHexCode(`CanvasText`))}static deleteAnnotationElement(e){let t=new ct({id:e._uiManager.getId(),parent:e.parent,uiManager:e._uiManager});t.annotationElementId=e.annotationElementId,t.deleted=!0,t._uiManager.addToAnnotationStorage(t)}static initialize(t,n){if(e._l10n??=t,e._l10nAlert??=Object.freeze({highlight:`pdfjs-editor-highlight-added-alert`,freetext:`pdfjs-editor-freetext-added-alert`,ink:`pdfjs-editor-ink-added-alert`,stamp:`pdfjs-editor-stamp-added-alert`,signature:`pdfjs-editor-signature-added-alert`}),e._l10nResizer??=Object.freeze({topLeft:`pdfjs-editor-resizer-top-left`,topMiddle:`pdfjs-editor-resizer-top-middle`,topRight:`pdfjs-editor-resizer-top-right`,middleRight:`pdfjs-editor-resizer-middle-right`,bottomRight:`pdfjs-editor-resizer-bottom-right`,bottomMiddle:`pdfjs-editor-resizer-bottom-middle`,bottomLeft:`pdfjs-editor-resizer-bottom-left`,middleLeft:`pdfjs-editor-resizer-middle-left`}),e._borderLineWidth!==-1)return;let r=getComputedStyle(document.documentElement);e._borderLineWidth=parseFloat(r.getPropertyValue(`--outline-width`))||0}static updateDefaultParams(e,t){}static get defaultPropertiesToUpdate(){return[]}static isHandlingMimeForPasting(e){return!1}static paste(e,t){k(`Not implemented`)}get propertiesToUpdate(){return[]}get _isDraggable(){return this.#w}set _isDraggable(e){this.#w=e,this.div?.classList.toggle(`draggable`,e)}get uid(){return this.annotationElementId||this.id}get isEnterHandled(){return!0}center(){let[e,t]=this.pageDimensions;switch(this.parentRotation){case 90:this.x-=this.height*t/(e*2),this.y+=this.width*e/(t*2);break;case 180:this.x+=this.width/2,this.y+=this.height/2;break;case 270:this.x+=this.height*t/(e*2),this.y-=this.width*e/(t*2);break;default:this.x-=this.width/2,this.y-=this.height/2;break}this.fixAndSetPosition()}addCommands(e){this._uiManager.addCommands(e)}get currentLayer(){return this._uiManager.currentLayer}setInBackground(){this.div.style.zIndex=0}setInForeground(){this.div.style.zIndex=this.#T}setParent(e){e===null?(this.#W(),this.#d?.remove(),this.#d=null):(this.pageIndex=e.pageIndex,this.pageDimensions=e.pageDimensions),this.parent=e}focusin(e){this._focusEventsAllowed&&(this.#m?this.#m=!1:this.parent.setSelected(this))}focusout(e){this._focusEventsAllowed&&this.isAttachedToDOM&&(e.relatedTarget?.closest(`#${this.id}`)||(e.preventDefault(),this.parent?.isMultipleSelection||this.commitOrRemove()))}commitOrRemove(){this.isEmpty()?this.remove():this.commit()}commit(){this.isInEditMode()&&this.addToAnnotationStorage()}addToAnnotationStorage(){this._uiManager.addToAnnotationStorage(this)}setAt(e,t,n,r){let[i,a]=this.parentDimensions;[n,r]=this.screenToPageTranslation(n,r),this.x=(e+n)/i,this.y=(t+r)/a,this.fixAndSetPosition()}_moveAfterPaste(e,t){if(this.isClone){delete this.isClone;return}let[n,r]=this.parentDimensions;this.setAt(e*n,t*r,this.width*n,this.height*r),this._onTranslated()}#E([e,t],n,r){[n,r]=this.screenToPageTranslation(n,r),this.x+=n/e,this.y+=r/t,this._onTranslating(this.x,this.y),this.fixAndSetPosition()}translate(e,t){this.#E(this.parentDimensions,e,t)}translateInPage(e,t){this.#h||=[this.x,this.y,this.width,this.height],this.#E(this.pageDimensions,e,t),this.div.scrollIntoView({block:`nearest`})}translationDone(){this._onTranslated(this.x,this.y)}drag(e,t){this.#h||=[this.x,this.y,this.width,this.height];let{div:n,parentDimensions:[r,i]}=this;if(this.x+=e/r,this.y+=t/i,this.parent&&(this.x<0||this.x>1||this.y<0||this.y>1)){let{x:e,y:t}=this.div.getBoundingClientRect();this.parent.findNewParent(this,e,t)&&(this.x-=Math.floor(this.x),this.y-=Math.floor(this.y))}let{x:a,y:o}=this,[s,c]=this.getBaseTranslation();a+=s,o+=c;let{style:l}=n;l.left=`${(100*a).toFixed(2)}%`,l.top=`${(100*o).toFixed(2)}%`,this._onTranslating(a,o),n.scrollIntoView({block:`nearest`})}_onTranslating(e,t){}_onTranslated(e,t){}get _hasBeenMoved(){return!!this.#h&&(this.#h[0]!==this.x||this.#h[1]!==this.y)}get _hasBeenResized(){return!!this.#h&&(this.#h[2]!==this.width||this.#h[3]!==this.height)}getBaseTranslation(){let[t,n]=this.parentDimensions,{_borderLineWidth:r}=e,i=r/t,a=r/n;switch(this.rotation){case 90:return[-i,a];case 180:return[i,a];case 270:return[i,-a];default:return[-i,-a]}}get _mustFixPosition(){return!0}fixAndSetPosition(e=this.rotation){let{div:{style:t},pageDimensions:[n,r]}=this,{x:i,y:a,width:o,height:s}=this;if(o*=n,s*=r,i*=n,a*=r,this._mustFixPosition)switch(e){case 0:i=V(i,0,n-o),a=V(a,0,r-s);break;case 90:i=V(i,0,n-s),a=V(a,o,r);break;case 180:i=V(i,o,n),a=V(a,s,r);break;case 270:i=V(i,s,n),a=V(a,0,r-o);break}this.x=i/=n,this.y=a/=r;let[c,l]=this.getBaseTranslation();i+=c,a+=l,t.left=`${(100*i).toFixed(2)}%`,t.top=`${(100*a).toFixed(2)}%`,this.moveInDOM()}static#D(e,t,n){switch(n){case 90:return[t,-e];case 180:return[-e,-t];case 270:return[-t,e];default:return[e,t]}}screenToPageTranslation(t,n){return e.#D(t,n,this.parentRotation)}pageTranslationToScreen(t,n){return e.#D(t,n,360-this.parentRotation)}#O(e){switch(e){case 90:{let[e,t]=this.pageDimensions;return[0,-e/t,t/e,0]}case 180:return[-1,0,0,-1];case 270:{let[e,t]=this.pageDimensions;return[0,e/t,-t/e,0]}default:return[1,0,0,1]}}get parentScale(){return this._uiManager.viewParameters.realScale}get parentRotation(){return(this._uiManager.viewParameters.rotation+this.pageRotation)%360}get parentDimensions(){let{parentScale:e,pageDimensions:[t,n]}=this;return[t*e,n*e]}setDims(){let{div:{style:e},width:t,height:n}=this;e.width=`${(100*t).toFixed(2)}%`,e.height=`${(100*n).toFixed(2)}%`}getInitialTranslation(){return[0,0]}#k(){if(this.#c)return;this.#c=document.createElement(`div`),this.#c.classList.add(`resizers`);let e=this._willKeepAspectRatio?[`topLeft`,`topRight`,`bottomRight`,`bottomLeft`]:[`topLeft`,`topMiddle`,`topRight`,`middleRight`,`bottomRight`,`bottomMiddle`,`bottomLeft`,`middleLeft`],t=this._uiManager._signal;for(let n of e){let e=document.createElement(`div`);this.#c.append(e),e.classList.add(`resizer`,n),e.setAttribute(`data-resizer-name`,n),e.addEventListener(`pointerdown`,this.#A.bind(this,n),{signal:t}),e.addEventListener(`contextmenu`,H,{signal:t}),e.tabIndex=-1}this.div.prepend(this.#c)}#A(e,t){t.preventDefault();let{isMac:n}=z.platform;if(t.button!==0||t.ctrlKey&&n)return;this.#n?.toggle(!1);let r=this._isDraggable;this._isDraggable=!1,this.#l=[t.screenX,t.screenY];let i=new AbortController,a=this._uiManager.combinedSignal(i);this.parent.togglePointerEvents(!1),window.addEventListener(`pointermove`,this.#N.bind(this,e),{passive:!0,capture:!0,signal:a}),window.addEventListener(`touchmove`,U,{passive:!1,signal:a}),window.addEventListener(`contextmenu`,H,{signal:a}),this.#u={savedX:this.x,savedY:this.y,savedWidth:this.width,savedHeight:this.height};let o=this.parent.div.style.cursor,s=this.div.style.cursor;this.div.style.cursor=this.parent.div.style.cursor=window.getComputedStyle(t.target).cursor;let c=()=>{i.abort(),this.parent.togglePointerEvents(!0),this.#n?.toggle(!0),this._isDraggable=r,this.parent.div.style.cursor=o,this.div.style.cursor=s,this.#M()};window.addEventListener(`pointerup`,c,{signal:a}),window.addEventListener(`blur`,c,{signal:a})}#j(e,t,n,r){this.width=n,this.height=r,this.x=e,this.y=t,this.setDims(),this.fixAndSetPosition(),this._onResized()}_onResized(){}#M(){if(!this.#u)return;let{savedX:e,savedY:t,savedWidth:n,savedHeight:r}=this.#u;this.#u=null;let i=this.x,a=this.y,o=this.width,s=this.height;i===e&&a===t&&o===n&&s===r||this.addCommands({cmd:this.#j.bind(this,i,a,o,s),undo:this.#j.bind(this,e,t,n,r),mustExec:!0})}static _round(e){return Math.round(e*1e4)/1e4}#N(t,n){let[r,i]=this.parentDimensions,a=this.x,o=this.y,s=this.width,c=this.height,l=e.MIN_SIZE/r,u=e.MIN_SIZE/i,d=this.#O(this.rotation),f=(e,t)=>[d[0]*e+d[2]*t,d[1]*e+d[3]*t],p=this.#O(360-this.rotation),m=(e,t)=>[p[0]*e+p[2]*t,p[1]*e+p[3]*t],h,g,_=!1,v=!1;switch(t){case`topLeft`:_=!0,h=(e,t)=>[0,0],g=(e,t)=>[e,t];break;case`topMiddle`:h=(e,t)=>[e/2,0],g=(e,t)=>[e/2,t];break;case`topRight`:_=!0,h=(e,t)=>[e,0],g=(e,t)=>[0,t];break;case`middleRight`:v=!0,h=(e,t)=>[e,t/2],g=(e,t)=>[0,t/2];break;case`bottomRight`:_=!0,h=(e,t)=>[e,t],g=(e,t)=>[0,0];break;case`bottomMiddle`:h=(e,t)=>[e/2,t],g=(e,t)=>[e/2,0];break;case`bottomLeft`:_=!0,h=(e,t)=>[0,t],g=(e,t)=>[e,0];break;case`middleLeft`:v=!0,h=(e,t)=>[0,t/2],g=(e,t)=>[e,t/2];break}let y=h(s,c),b=g(s,c),x=f(...b),S=e._round(a+x[0]),C=e._round(o+x[1]),w=1,T=1,E,D;if(n.fromKeyboard)({deltaX:E,deltaY:D}=n);else{let{screenX:e,screenY:t}=n,[r,i]=this.#l;[E,D]=this.screenToPageTranslation(e-r,t-i),this.#l[0]=e,this.#l[1]=t}if([E,D]=m(E/r,D/i),_){let e=Math.hypot(s,c);w=T=Math.max(Math.min(Math.hypot(b[0]-y[0]-E,b[1]-y[1]-D)/e,1/s,1/c),l/s,u/c)}else v?w=V(Math.abs(b[0]-y[0]-E),l,1)/s:T=V(Math.abs(b[1]-y[1]-D),u,1)/c;let O=e._round(s*w),k=e._round(c*T);x=f(...g(O,k));let A=S-x[0],j=C-x[1];this.#h||=[this.x,this.y,this.width,this.height],this.width=O,this.height=k,this.x=A,this.y=j,this.setDims(),this.fixAndSetPosition(),this._onResizing()}_onResizing(){}altTextFinish(){this.#n?.finish()}get toolbarButtons(){return null}async addEditToolbar(){if(this._editToolbar||this.#_)return this._editToolbar;this._editToolbar=new Ye(this),this.div.append(this._editToolbar.render());let{toolbarButtons:e}=this;if(e)for(let[t,n]of e)await this._editToolbar.addButton(t,n);return this.hasComment||this._editToolbar.addButton(`comment`,this.addCommentButton()),this._editToolbar.addButton(`delete`),this._editToolbar}addCommentButtonInToolbar(){this._editToolbar?.addButtonBefore(`comment`,this.addCommentButton(),`.deleteButton`)}removeCommentButtonFromToolbar(){this._editToolbar?.removeButton(`comment`)}removeEditToolbar(){this._editToolbar?.remove(),this._editToolbar=null,this.#n?.destroy()}addContainer(e){let t=this._editToolbar?.div;t?t.before(e):this.div.append(e)}getClientDimensions(){return this.div.getBoundingClientRect()}createAltText(){return this.#n||(at.initialize(e._l10n),this.#n=new at(this),this.#e&&=(this.#n.data=this.#e,null)),this.#n}get altTextData(){return this.#n?.data}set altTextData(e){this.#n&&(this.#n.data=e)}get guessedAltText(){return this.#n?.guessedText}async setGuessedAltText(e){await this.#n?.setGuessedText(e)}serializeAltText(e){return this.#n?.serialize(e)}hasAltText(){return!!this.#n&&!this.#n.isEmpty()}hasAltTextData(){return this.#n?.hasData()??!1}focusCommentButton(){this.#r?.focusButton()}addCommentButton(){return this.canAddComment?this.#r||=new ot(this):null}addStandaloneCommentButton(){if(this._uiManager.hasCommentManager()){if(this.#i){this._uiManager.isEditingMode()&&this.#i.classList.remove(`hidden`);return}this.hasComment&&(this.#i=this.#r.renderForStandalone(),this.div.append(this.#i))}}removeStandaloneCommentButton(){this.#r.removeStandaloneCommentButton(),this.#i=null}hideStandaloneCommentButton(){this.#i?.classList.add(`hidden`)}get comment(){if(!this.#r)return null;let{data:{richText:e,text:t,date:n,deleted:r}}=this.#r;return{text:t,richText:e,date:n,deleted:r,color:this.getNonHCMColor(),opacity:this.opacity??1}}set comment(e){this.#r||=new ot(this),typeof e==`object`&&e?this.#r.restoreData(e):this.#r.data=e,this.hasComment?(this.removeCommentButtonFromToolbar(),this.addStandaloneCommentButton(),this._uiManager.updateComment(this)):(this.addCommentButtonInToolbar(),this.removeStandaloneCommentButton(),this._uiManager.removeComment(this))}setCommentData({comment:e,popupRef:t,richText:n}){if(!t||(this.#r||=new ot(this),this.#r.setInitialText(e,n),!this.annotationElementId))return;let r=this._uiManager.getAndRemoveDataFromAnnotationStorage(this.annotationElementId);r&&this.updateFromAnnotationLayer(r)}get hasEditedComment(){return this.#r?.hasBeenEdited()}get hasDeletedComment(){return this.#r?.isDeleted()}get hasComment(){return!!this.#r&&!this.#r.isEmpty()&&!this.#r.isDeleted()}async editComment(e){this.#r||=new ot(this),this.#r.edit(e)}toggleComment(e,t=void 0){this.hasComment&&this._uiManager.toggleComment(this,e,t)}setSelectedCommentButton(e){this.#r.setSelectedButton(e)}addComment(e){if(this.hasEditedComment){let[,,,t]=e.rect,[n]=this.pageDimensions,[r]=this.pageTranslation,i=r+n+1,a=t-100,o=i+180;e.popup={contents:this.comment.text,deleted:this.comment.deleted,rect:[i,a,o,t]}}}updateFromAnnotationLayer({popup:{contents:e,deleted:t}}){this.#r.data=t?null:e}get parentBoundingClientRect(){return this.parent.boundingClientRect}render(){let e=this.div=document.createElement(`div`);e.setAttribute(`data-editor-rotation`,(360-this.rotation)%360),e.className=this.name,e.setAttribute(`id`,this.id),e.tabIndex=this.#a?-1:0,e.setAttribute(`role`,`application`),this.defaultL10nId&&e.setAttribute(`data-l10n-id`,this.defaultL10nId),this._isVisible||e.classList.add(`hidden`),this.setInForeground(),this.#z();let[t,n]=this.parentDimensions;this.parentRotation%180!=0&&(e.style.maxWidth=`${(100*n/t).toFixed(2)}%`,e.style.maxHeight=`${(100*t/n).toFixed(2)}%`);let[r,i]=this.getInitialTranslation();return this.translate(r,i),Qe(this,e,[`keydown`,`pointerdown`,`dblclick`]),this.isResizable&&this._uiManager._supportsPinchToZoom&&(this.#C||=new st({container:e,isPinchingDisabled:()=>!this.isSelected,onPinchStart:this.#P.bind(this),onPinching:this.#F.bind(this),onPinchEnd:this.#I.bind(this),signal:this._uiManager._signal})),this.addStandaloneCommentButton(),this._uiManager._editorUndoBar?.hide(),e}#P(){this.#u={savedX:this.x,savedY:this.y,savedWidth:this.width,savedHeight:this.height},this.#n?.toggle(!1),this.parent.togglePointerEvents(!1)}#F(t,n,r){let i=.7,a=r/n*i+1-i;if(a===1)return;let o=this.#O(this.rotation),s=(e,t)=>[o[0]*e+o[2]*t,o[1]*e+o[3]*t],[c,l]=this.parentDimensions,u=this.x,d=this.y,f=this.width,p=this.height,m=e.MIN_SIZE/c,h=e.MIN_SIZE/l;a=Math.max(Math.min(a,1/f,1/p),m/f,h/p);let g=e._round(f*a),_=e._round(p*a);if(g===f&&_===p)return;this.#h||=[u,d,f,p];let v=s(f/2,p/2),y=e._round(u+v[0]),b=e._round(d+v[1]),x=s(g/2,_/2);this.x=y-x[0],this.y=b-x[1],this.width=g,this.height=_,this.setDims(),this.fixAndSetPosition(),this._onResizing()}#I(){this.#n?.toggle(!0),this.parent.togglePointerEvents(!0),this.#M()}pointerdown(e){let{isMac:t}=z.platform;if(e.button!==0||e.ctrlKey&&t){e.preventDefault();return}if(this.#m=!0,this._isDraggable){this.#R(e);return}this.#L(e)}#L(e){let{isMac:t}=z.platform;e.ctrlKey&&!t||e.shiftKey||e.metaKey&&t?this.parent.toggleSelected(this):this.parent.setSelected(this)}#R(e){let{isSelected:t}=this;this._uiManager.setUpDragSession();let n=!1,r=new AbortController,i=this._uiManager.combinedSignal(r),a={capture:!0,passive:!1,signal:i},o=e=>{r.abort(),this.#o=null,this.#m=!1,this._uiManager.endDragSession()||this.#L(e),n&&this._onStopDragging()};t&&(this.#b=e.clientX,this.#x=e.clientY,this.#o=e.pointerId,this.#s=e.pointerType,window.addEventListener(`pointermove`,e=>{n||(n=!0,this._uiManager.toggleComment(this,!0,!1),this._onStartDragging());let{clientX:t,clientY:r,pointerId:i}=e;if(i!==this.#o){U(e);return}let[a,o]=this.screenToPageTranslation(t-this.#b,r-this.#x);this.#b=t,this.#x=r,this._uiManager.dragSelectedEditors(a,o)},a),window.addEventListener(`touchmove`,U,a),window.addEventListener(`pointerdown`,e=>{e.pointerType===this.#s&&(this.#C||e.isPrimary)&&o(e),U(e)},a));let s=e=>{if(!this.#o||this.#o===e.pointerId){o(e);return}U(e)};window.addEventListener(`pointerup`,s,{signal:i}),window.addEventListener(`blur`,s,{signal:i})}_onStartDragging(){}_onStopDragging(){}moveInDOM(){this.#y&&clearTimeout(this.#y),this.#y=setTimeout(()=>{this.#y=null,this.parent?.moveEditorInDOM(this)},0)}_setParentAndPosition(e,t,n){e.changeParent(this),this.x=t,this.y=n,this.fixAndSetPosition(),this._onTranslated()}getRect(e,t,n=this.rotation){let r=this.parentScale,[i,a]=this.pageDimensions,[o,s]=this.pageTranslation,c=e/r,l=t/r,u=this.x*i,d=this.y*a,f=this.width*i,p=this.height*a;switch(n){case 0:return[u+c+o,a-d-l-p+s,u+c+f+o,a-d-l+s];case 90:return[u+l+o,a-d+c+s,u+l+p+o,a-d+c+f+s];case 180:return[u-c-f+o,a-d+l+s,u-c+o,a-d+l+p+s];case 270:return[u-l-p+o,a-d-c-f+s,u-l+o,a-d-c+s];default:throw Error(`Invalid rotation`)}}getRectInCurrentCoords(e,t){let[n,r,i,a]=e,o=i-n,s=a-r;switch(this.rotation){case 0:return[n,t-a,o,s];case 90:return[n,t-r,s,o];case 180:return[i,t-r,o,s];case 270:return[i,t-a,s,o];default:throw Error(`Invalid rotation`)}}getPDFRect(){return this.getRect(0,0)}getNonHCMColor(){return this.color&&e._colorManager.convert(this._uiManager.getNonHCMColor(this.color))}onUpdatedColor(){this.#r?.onUpdatedColor()}getData(){let{comment:{text:e,color:t,date:n,opacity:r,deleted:i,richText:a},uid:o,pageIndex:s,creationDate:c,modificationDate:l}=this;return{id:o,pageIndex:s,rect:this.getPDFRect(),richText:a,contentsObj:{str:e},creationDate:c,modificationDate:n||l,popupRef:!i,color:t,opacity:r}}onceAdded(e){}isEmpty(){return!1}enableEditMode(){return this.isInEditMode()?!1:(this.parent.setEditingState(!1),this.#_=!0,!0)}disableEditMode(){return this.isInEditMode()?(this.parent.setEditingState(!0),this.#_=!1,!0):!1}isInEditMode(){return this.#_}shouldGetKeyboardEvents(){return this.#v}needsToBeRebuilt(){return this.div&&!this.isAttachedToDOM}get isOnScreen(){let{top:e,left:t,bottom:n,right:r}=this.getClientDimensions(),{innerHeight:i,innerWidth:a}=window;return t0&&e0}#z(){if(this.#f||!this.div)return;this.#f=new AbortController;let e=this._uiManager.combinedSignal(this.#f);this.div.addEventListener(`focusin`,this.focusin.bind(this),{signal:e}),this.div.addEventListener(`focusout`,this.focusout.bind(this),{signal:e})}rebuild(){this.#z()}rotate(e){}resize(){}serializeDeleted(){return{id:this.annotationElementId,deleted:!0,pageIndex:this.pageIndex,popupRef:this._initialData?.popupRef||``}}serialize(e=!1,t=null){return{annotationType:this.mode,pageIndex:this.pageIndex,rect:this.getPDFRect(),rotation:this.rotation,structTreeParentId:this._structTreeParentId,popupRef:this._initialData?.popupRef||``}}static async deserialize(e,t,n){let r=new this.prototype.constructor({parent:t,id:n.getId(),uiManager:n,annotationElementId:e.annotationElementId,creationDate:e.creationDate,modificationDate:e.modificationDate});r.rotation=e.rotation,r.#e=e.accessibilityData,r._isCopy=e.isCopy||!1;let[i,a]=r.pageDimensions,[o,s,c,l]=r.getRectInCurrentCoords(e.rect,a);return r.x=o/i,r.y=s/a,r.width=c/i,r.height=l/a,r}get hasBeenModified(){return!!this.annotationElementId&&(this.deleted||this.serialize()!==null)}remove(){if(this.#f?.abort(),this.#f=null,this.isEmpty()||this.commit(),this.parent?this.parent.remove(this):this._uiManager.removeEditor(this),this.hideCommentPopup(),this.#y&&=(clearTimeout(this.#y),null),this.#W(),this.removeEditToolbar(),this.#S){for(let e of this.#S.values())clearTimeout(e);this.#S=null}this.parent=null,this.#C?.destroy(),this.#C=null,this.#d?.remove(),this.#d=null}get isResizable(){return!1}makeResizable(){this.isResizable&&(this.#k(),this.#c.classList.remove(`hidden`))}get toolbarPosition(){return null}get commentButtonPosition(){return this._uiManager.direction===`ltr`?[1,0]:[0,0]}get commentButtonPositionInPage(){let{commentButtonPosition:[t,n]}=this,[r,i,a,o]=this.getPDFRect();return[e._round(r+(a-r)*t),e._round(i+(o-i)*(1-n))]}get commentButtonColor(){return this._uiManager.makeCommentColor(this.getNonHCMColor(),this.opacity)}get commentPopupPosition(){return this.#r.commentPopupPositionInLayer}set commentPopupPosition(e){this.#r.commentPopupPositionInLayer=e}hasDefaultPopupPosition(){return this.#r.hasDefaultPopupPosition()}get commentButtonWidth(){return this.#r.commentButtonWidth}get elementBeforePopup(){return this.div}setCommentButtonStates(e){this.#r?.setCommentButtonStates(e)}keydown(t){if(!this.isResizable||t.target!==this.div||t.key!==`Enter`)return;this._uiManager.setSelected(this),this.#u={savedX:this.x,savedY:this.y,savedWidth:this.width,savedHeight:this.height};let n=this.#c.children;if(!this.#t){this.#t=Array.from(n);let t=this.#B.bind(this),r=this.#V.bind(this),i=this._uiManager._signal;for(let n of this.#t){let a=n.getAttribute(`data-resizer-name`);n.setAttribute(`role`,`spinbutton`),n.addEventListener(`keydown`,t,{signal:i}),n.addEventListener(`blur`,r,{signal:i}),n.addEventListener(`focus`,this.#H.bind(this,a),{signal:i}),n.setAttribute(`data-l10n-id`,e._l10nResizer[a])}}let r=this.#t[0],i=0;for(let e of n){if(e===r)break;i++}let a=(360-this.rotation+this.parentRotation)%360/90*(this.#t.length/4);if(a!==i){if(ai)for(let e=0;e{this.div?.classList.contains(`selectedEditor`)&&this._editToolbar?.show()});return}this._editToolbar?.show(),this.#n?.toggleAltTextBadge(!1)}focus(){this.div&&!this.div.contains(document.activeElement)&&setTimeout(()=>this.div?.focus({preventScroll:!0}),0)}unselect(){this.isSelected&&(this.isSelected=!1,this.#c?.classList.add(`hidden`),this.div?.classList.remove(`selectedEditor`),this.div?.contains(document.activeElement)&&this._uiManager.currentLayer.div.focus({preventScroll:!0}),this._editToolbar?.hide(),this.#n?.toggleAltTextBadge(!0),this.hideCommentPopup())}hideCommentPopup(){this.hasComment&&this._uiManager.toggleComment(null)}updateParams(e,t){}disableEditing(){}enableEditing(){}get canChangeContent(){return!1}enterInEditMode(){this.canChangeContent&&(this.enableEditMode(),this.div.focus())}dblclick(e){e.target.nodeName!==`BUTTON`&&(this.enterInEditMode(),this.parent.updateToolbar({mode:this.constructor._editorType,editId:this.uid}))}getElementForAltText(){return this.div}get contentDiv(){return this.div}get isEditing(){return this.#g}set isEditing(e){this.#g=e,this.parent&&(e?(this.parent.setSelected(this),this.parent.setActiveEditor(this)):this.parent.setActiveEditor(null))}static get MIN_SIZE(){return 16}static canCreateNewEmptyEditor(){return!0}get telemetryInitialData(){return{action:`added`}}get telemetryFinalData(){return null}_reportTelemetry(t,n=!1){if(n){this.#S||=new Map;let{action:n}=t,r=this.#S.get(n);r&&clearTimeout(r),r=setTimeout(()=>{this._reportTelemetry(t),this.#S.delete(n),this.#S.size===0&&(this.#S=null)},e._telemetryTimeout),this.#S.set(n,r);return}t.type||=this.editorType,this._uiManager._eventBus.dispatch(`reporttelemetry`,{source:this,details:{type:`editing`,data:t}})}show(e=this._isVisible){this.div.classList.toggle(`hidden`,!e),this._isVisible=e}enable(){this.div&&(this.div.tabIndex=0),this.#a=!1}disable(){this.div&&(this.div.tabIndex=-1),this.#a=!0}updateFakeAnnotationElement(e){if(!this.#d&&!this.deleted){this.#d=e.addFakeAnnotation(this);return}if(this.deleted){this.#d.remove(),this.#d=null;return}(this.hasEditedComment||this._hasBeenMoved||this._hasBeenResized)&&this.#d.updateEdited({rect:this.getPDFRect(),popup:this.comment})}renderAnnotationElement(e){if(this.deleted)return e.hide(),null;let t=e.container.querySelector(`.annotationContent`);if(!t)t=document.createElement(`div`),t.classList.add(`annotationContent`,this.editorType),e.container.prepend(t);else if(t.nodeName===`CANVAS`){let e=t;t=document.createElement(`div`),t.classList.add(`annotationContent`,this.editorType),e.before(t)}return t}resetAnnotationElement(e){let{firstElementChild:t}=e.container;t?.nodeName===`DIV`&&t.classList.contains(`annotationContent`)&&t.remove()}},ct=class extends K{constructor(e){super(e),this.annotationElementId=e.annotationElementId,this.deleted=!0}serialize(){return this.serializeDeleted()}},lt=3285377520,ut=4294901760,dt=65535,ft=class{constructor(e){this.h1=e?e&4294967295:lt,this.h2=e?e&4294967295:lt}update(e){let t,n;if(typeof e==`string`){t=new Uint8Array(e.length*2),n=0;for(let r=0,i=e.length;r>>8,t[n++]=i&255)}}else if(ArrayBuffer.isView(e))t=e.slice(),n=t.byteLength;else throw Error(`Invalid data format, must be a string or TypedArray.`);let r=n>>2,i=n-r*4,a=new Uint32Array(t.buffer,0,r),o=0,s=0,c=this.h1,l=this.h2,u=3432918353,d=461845907,f=11601,p=13715;for(let e=0;e>>17,o=o*d&ut|o*p&dt,c^=o,c=c<<13|c>>>19,c=c*5+3864292196):(s=a[e],s=s*u&ut|s*f&dt,s=s<<15|s>>>17,s=s*d&ut|s*p&dt,l^=s,l=l<<13|l>>>19,l=l*5+3864292196);switch(o=0,i){case 3:o^=t[r*4+2]<<16;case 2:o^=t[r*4+1]<<8;case 1:o^=t[r*4],o=o*u&ut|o*f&dt,o=o<<15|o>>>17,o=o*d&ut|o*p&dt,r&1?c^=o:l^=o}this.h1=c,this.h2=l}hexdigest(){let e=this.h1,t=this.h2;return e^=t>>>1,e=e*3981806797&ut|e*36045&dt,t=t*4283543511&ut|((t<<16|e>>>16)*2950163797&ut)>>>16,e^=t>>>1,e=e*444984403&ut|e*60499&dt,t=t*3301882366&ut|((t<<16|e>>>16)*3120437893&ut)>>>16,e^=t>>>1,(e>>>0).toString(16).padStart(8,`0`)+(t>>>0).toString(16).padStart(8,`0`)}},pt=Object.freeze({map:null,hash:``,transfer:void 0}),mt=class{#e=!1;#t=null;#n=null;#r=new Map;onSetModified=null;onResetModified=null;onAnnotationEditor=null;getValue(e,t){let n=this.#r.get(e);return n===void 0?t:Object.assign(t,n)}getRawValue(e){return this.#r.get(e)}remove(e){let t=this.#r.get(e);t!==void 0&&(t instanceof K&&this.#n.delete(t.annotationElementId),this.#r.delete(e),this.#r.size===0&&this.resetModified(),!this.#r.values().some(e=>e instanceof K)&&this.onAnnotationEditor?.(null))}setValue(e,t){let n=this.#r.get(e),r=!1;if(n!==void 0)for(let[e,i]of Object.entries(t))n[e]!==i&&(r=!0,n[e]=i);else r=!0,this.#r.set(e,t);r&&this.#i(),t instanceof K&&((this.#n||=new Map).set(t.annotationElementId,t),this.onAnnotationEditor?.(t.constructor._type))}has(e){return this.#r.has(e)}get size(){return this.#r.size}#i(){this.#e||(this.#e=!0,this.onSetModified?.())}resetModified(){this.#e&&(this.#e=!1,this.onResetModified?.())}get print(){return new ht(this)}get serializable(){if(this.#r.size===0)return pt;let e=new Map,t=new ft,n=[],r=Object.create(null),i=!1;for(let[n,a]of this.#r){let o=a instanceof K?a.serialize(!1,r):a;a.page&&(a.pageIndex=a.page._pageIndex,delete a.page),o&&(e.set(n,o),t.update(`${n}:${JSON.stringify(o)}`),i||=!!o.bitmap)}if(i)for(let t of e.values())t.bitmap&&n.push(t.bitmap);return e.size>0?{map:e,hash:t.hexdigest(),transfer:n}:pt}get editorStats(){let e=null,t=new Map,n=0,r=0;for(let i of this.#r.values()){if(!(i instanceof K)){i.popup&&(i.popup.deleted?r+=1:n+=1);continue}i.isCommentDeleted?r+=1:i.hasEditedComment&&(n+=1);let a=i.telemetryFinalData;if(!a)continue;let{type:o}=a;t.getOrInsertComputed(o,()=>Object.getPrototypeOf(i).constructor),e||=Object.create(null);let s=e[o]||=new Map;for(let[e,t]of Object.entries(a)){if(e===`type`)continue;let n=s.getOrInsertComputed(e,pe);n.set(t,(n.get(t)??0)+1)}}if((r>0||n>0)&&(e||=Object.create(null),e.comments={deleted:r,edited:n}),!e)return null;for(let[n,r]of t)e[n]=r.computeTelemetryFinalData(e[n]);return e}resetModifiedIds(){this.#t=null}updateEditor(e,t){let n=this.#n?.get(e);return n?(n.updateFromAnnotationLayer(t),!0):!1}getEditor(e){return this.#n?.get(e)||null}get modifiedIds(){if(this.#t)return this.#t;let e=[];if(this.#n)for(let t of this.#n.values())t.serialize()&&e.push(t.annotationElementId);let t=``;if(e.length){let n=new ft;n.update(e.join(`,`)),t=n.hexdigest()}return this.#t={ids:new Set(e),hash:t}}[Symbol.iterator](){return this.#r.entries()}},ht=class extends mt{#e=pt;constructor(e){super();let{serializable:t}=e;if(t===pt)return;let{map:n,hash:r,transfer:i}=t,a=structuredClone(n,i?{transfer:i}:null);this.#e={map:a,hash:r,transfer:[]}}get print(){k(`Should not call PrintAnnotationStorage.print`)}get serializable(){return this.#e}get modifiedIds(){return F(this,`modifiedIds`,{ids:new Set,hash:``})}};r(7588);var gt=`__forcedDependency`,{floor:_t,ceil:vt}=Math;function yt(e,t,n,r,i,a){e[t*4+0]=Math.min(e[t*4+0],n),e[t*4+1]=Math.min(e[t*4+1],r),e[t*4+2]=Math.max(e[t*4+2],i),e[t*4+3]=Math.max(e[t*4+3],a)}function bt(e,t,n,r,i){let a;e?(e<0&&(a=i[0],i[0]=i[2],i[2]=a),i[0]*=e,i[2]*=e,t<0&&(a=i[1],i[1]=i[3],i[3]=a),i[1]*=t,i[3]*=t):i.fill(0),i[0]+=n,i[1]+=r,i[2]+=n,i[3]+=r}var xt=new Uint32Array(new Uint8Array([255,255,0,0]).buffer)[0],St=class{#e;#t;constructor(e,t){this.#e=e,this.#t=t}get length(){return this.#e.length}isEmpty(e){return this.#e[e]===xt}minX(e){return this.#t[e*4+0]/256}minY(e){return this.#t[e*4+1]/256}maxX(e){return(this.#t[e*4+2]+1)/256}maxY(e){return(this.#t[e*4+3]+1)/256}},Ct=(e,t)=>e?.getOrInsertComputed(t,()=>({dependencies:new Set,isRenderingOperation:!1})),wt=class{#e=[[1,0,0,1,0,0]];#t=[-1/0,-1/0,1/0,1/0];#n=new Float64Array(a);_pendingBBoxIdx=-1;#r;#i;#a;#o;_savesStack=[];_markedContentStack=[];constructor(e,t){this.#r=e.width,this.#i=e.height,this.#s(t)}growOperationsCount(e){e>=this.#o.length&&this.#s(e,this.#o)}#s(e,t){let n=new ArrayBuffer(e*4);this.#a=new Uint8ClampedArray(n),this.#o=new Uint32Array(n),t&&t.length>0?(this.#o.set(t),this.#o.fill(xt,t.length)):this.#o.fill(xt)}get clipBox(){return this.#t}save(e){return this.#t={__proto__:this.#t},this._savesStack.push(e),this}restore(e,t){let n=Object.getPrototypeOf(this.#t);if(n===null)return this;this.#t=n;let r=this._savesStack.pop();return r!==void 0&&(t?.(r,e),this.#o[e]=this.#o[r]),this}recordOpenMarker(e){return this._savesStack.push(e),this}getOpenMarker(){return this._savesStack.length===0?null:this._savesStack.at(-1)}recordCloseMarker(e,t){let n=this._savesStack.pop();return n!==void 0&&(t?.(n,e),this.#o[e]=this.#o[n]),this}beginMarkedContent(e){return this._markedContentStack.push(e),this}endMarkedContent(e,t){let n=this._markedContentStack.pop();return n!==void 0&&(t?.(n,e),this.#o[e]=this.#o[n]),this}pushBaseTransform(e){return this.#e.push(B.multiplyByDOMMatrix(this.#e.at(-1),e.getTransform())),this}popBaseTransform(){return this.#e.length>1&&this.#e.pop(),this}resetBBox(e){return this._pendingBBoxIdx!==e&&(this._pendingBBoxIdx=e,this.#n.set(a,0)),this}recordClipBox(e,t,n,r,i,o){let s=B.multiplyByDOMMatrix(this.#e.at(-1),t.getTransform()),c=a.slice();B.axialAlignedBoundingBox([n,i,r,o],s,c);let l=B.intersect(this.#t,c);return l?(this.#t[0]=l[0],this.#t[1]=l[1],this.#t[2]=l[2],this.#t[3]=l[3]):(this.#t[0]=this.#t[1]=1/0,this.#t[2]=this.#t[3]=-1/0),this}recordBBox(e,t,n,r,i,o){let s=this.#t;if(s[0]===1/0)return this;let c=B.multiplyByDOMMatrix(this.#e.at(-1),t.getTransform());if(s[0]===-1/0)return B.axialAlignedBoundingBox([n,i,r,o],c,this.#n),this;let l=a.slice();return B.axialAlignedBoundingBox([n,i,r,o],c,l),this.#n[0]=V(l[0],s[0],this.#n[0]),this.#n[1]=V(l[1],s[1],this.#n[1]),this.#n[2]=V(l[2],this.#n[2],s[2]),this.#n[3]=V(l[3],this.#n[3],s[3]),this}recordFullPageBBox(e){return this.#n[0]=Math.max(0,this.#t[0]),this.#n[1]=Math.max(0,this.#t[1]),this.#n[2]=Math.min(this.#r,this.#t[2]),this.#n[3]=Math.min(this.#i,this.#t[3]),this}recordOperation(e,t=!1,n){if(this._pendingBBoxIdx!==e)return this;let r=_t(this.#n[0]*256/this.#r),i=_t(this.#n[1]*256/this.#i),a=vt(this.#n[2]*256/this.#r),o=vt(this.#n[3]*256/this.#i);if(yt(this.#a,e,r,i,a,o),n)for(let t of n)for(let n of t)n!==e&&yt(this.#a,n,r,i,a,o);return t||(this._pendingBBoxIdx=-1),this}bboxToClipBoxDropOperation(e){return this._pendingBBoxIdx===e&&(this._pendingBBoxIdx=-1,this.#t[0]=Math.max(this.#t[0],this.#n[0]),this.#t[1]=Math.max(this.#t[1],this.#n[1]),this.#t[2]=Math.min(this.#t[2],this.#n[2]),this.#t[3]=Math.min(this.#t[3],this.#n[3])),this}take(){return new St(this.#o,this.#a)}takeDebugMetadata(){throw Error(`Unreachable`)}recordSimpleData(e,t){return this}recordIncrementalData(e,t){return this}resetIncrementalData(e,t){return this}recordNamedData(e,t){return this}recordSimpleDataFromNamed(e,t,n){return this}recordFutureForcedDependency(e,t){return this}inheritSimpleDataAsFutureForcedDependencies(e){return this}inheritPendingDependenciesAsFutureForcedDependencies(){return this}recordCharacterBBox(e,t,n,r=1,i=0,a=0,o){return this}getSimpleIndex(e){}recordDependencies(e,t){return this}recordNamedDependency(e,t){return this}recordShowTextOperation(e,t=!1){return this}},Tt=class{#e={__proto__:null};#t={__proto__:null,transform:[],moveText:[],sameLineText:[],[gt]:[]};#n=new Map;#r=new Set;#i=new Map;#a;#o;#s;constructor(e,t=!1){this.#s=e,t&&(this.#a=new Map,this.#o=(e,t)=>{Ct(this.#a,t).dependencies.add(e)})}get clipBox(){return this.#s.clipBox}growOperationsCount(e){this.#s.growOperationsCount(e)}save(e){return this.#e={__proto__:this.#e},this.#t={__proto__:this.#t,transform:{__proto__:this.#t.transform},moveText:{__proto__:this.#t.moveText},sameLineText:{__proto__:this.#t.sameLineText},[gt]:{__proto__:this.#t[gt]}},this.#s.save(e),this}restore(e){this.#s.restore(e,this.#o);let t=Object.getPrototypeOf(this.#e);return t===null?this:(this.#e=t,this.#t=Object.getPrototypeOf(this.#t),this)}recordOpenMarker(e){return this.#s.recordOpenMarker(e,this.#o),this}getOpenMarker(){return this.#s.getOpenMarker()}recordCloseMarker(e){return this.#s.recordCloseMarker(e,this.#o),this}beginMarkedContent(e){return this.#s.beginMarkedContent(e),this}endMarkedContent(e){return this.#s.endMarkedContent(e,this.#o),this}pushBaseTransform(e){return this.#s.pushBaseTransform(e),this}popBaseTransform(){return this.#s.popBaseTransform(),this}recordSimpleData(e,t){return this.#e[e]=t,this}recordIncrementalData(e,t){return this.#t[e].push(t),this}resetIncrementalData(e,t){return this.#t[e].length=0,this}recordNamedData(e,t){return this.#n.set(e,t),this}recordSimpleDataFromNamed(e,t,n){this.#e[e]=this.#n.get(t)??n}recordFutureForcedDependency(e,t){return this.recordIncrementalData(gt,t),this}inheritSimpleDataAsFutureForcedDependencies(e){for(let t of e)t in this.#e&&this.recordFutureForcedDependency(t,this.#e[t]);return this}inheritPendingDependenciesAsFutureForcedDependencies(){for(let e of this.#r)this.recordFutureForcedDependency(gt,e);return this}resetBBox(e){return this.#s.resetBBox(e),this}recordClipBox(e,t,n,r,i,a){return this.#s.recordClipBox(e,t,n,r,i,a),this}recordBBox(e,t,n,r,i,a){return this.#s.recordBBox(e,t,n,r,i,a),this}recordCharacterBBox(e,t,n,r=1,i=0,a=0,o){let s=n.bbox,c,l;if(s&&(c=s[2]!==s[0]&&s[3]!==s[1]&&this.#i.get(n),c!==!1&&(l=[0,0,0,0],B.axialAlignedBoundingBox(s,n.fontMatrix,l),(r!==1||i!==0||a!==0)&&bt(r,-r,i,a,l),c)))return this.recordBBox(e,t,l[0],l[2],l[1],l[3]);if(!o)return this.recordFullPageBBox(e);let u=o();return s&&l&&c===void 0&&(c=l[0]<=i-u.actualBoundingBoxLeft&&l[2]>=i+u.actualBoundingBoxRight&&l[1]<=a-u.actualBoundingBoxAscent&&l[3]>=a+u.actualBoundingBoxDescent,this.#i.set(n,c),c)?this.recordBBox(e,t,l[0],l[2],l[1],l[3]):this.recordBBox(e,t,i-u.actualBoundingBoxLeft,i+u.actualBoundingBoxRight,a-u.actualBoundingBoxAscent,a+u.actualBoundingBoxDescent)}recordFullPageBBox(e){return this.#s.recordFullPageBBox(e),this}getSimpleIndex(e){return this.#e[e]}recordDependencies(e,t){let n=this.#r,r=this.#e,i=this.#t;for(let e of t)e in this.#e?n.add(r[e]):e in i&&i[e].forEach(n.add,n);return this}recordNamedDependency(e,t){return this.#n.has(t)&&this.#r.add(this.#n.get(t)),this}recordOperation(e,t=!1){if(this.recordDependencies(e,[gt]),this.#a){let t=Ct(this.#a,e),{dependencies:n}=t;this.#r.forEach(n.add,n),this.#s._savesStack.forEach(n.add,n),this.#s._markedContentStack.forEach(n.add,n),n.delete(e),t.isRenderingOperation=!0}let n=!t&&e===this.#s._pendingBBoxIdx;return this.#s.recordOperation(e,t,[this.#r,this.#s._savesStack,this.#s._markedContentStack]),n&&this.#r.clear(),this}recordShowTextOperation(e,t=!1){let n=Array.from(this.#r);this.recordOperation(e,t),this.recordIncrementalData(`sameLineText`,e);for(let e of n)this.recordIncrementalData(`sameLineText`,e);return this}bboxToClipBoxDropOperation(e,t=!1){let n=!t&&e===this.#s._pendingBBoxIdx;return this.#s.bboxToClipBoxDropOperation(e),n&&this.#r.clear(),this}take(){return this.#i.clear(),this.#s.take()}takeDebugMetadata(){return this.#a}},Et=class e{#e;#t;#n;#r=0;#i=0;constructor(t,n,r){if(t instanceof e&&t.#n===!!r)return t;this.#e=t,this.#t=n,this.#n=!!r}get clipBox(){return this.#e.clipBox}growOperationsCount(){throw Error(`Unreachable`)}save(e){return this.#i++,this.#e.save(this.#t),this}restore(e){return this.#i>0&&(this.#e.restore(this.#t),this.#i--),this}recordOpenMarker(e){return this.#r++,this}getOpenMarker(){return this.#r>0?this.#t:this.#e.getOpenMarker()}recordCloseMarker(e){return this.#r--,this}beginMarkedContent(e){return this}endMarkedContent(e){return this}pushBaseTransform(e){return this.#e.pushBaseTransform(e),this}popBaseTransform(){return this.#e.popBaseTransform(),this}recordSimpleData(e,t){return this.#e.recordSimpleData(e,this.#t),this}recordIncrementalData(e,t){return this.#e.recordIncrementalData(e,this.#t),this}resetIncrementalData(e,t){return this.#e.resetIncrementalData(e,this.#t),this}recordNamedData(e,t){return this}recordSimpleDataFromNamed(e,t,n){return this.#e.recordSimpleDataFromNamed(e,t,this.#t),this}recordFutureForcedDependency(e,t){return this.#e.recordFutureForcedDependency(e,this.#t),this}inheritSimpleDataAsFutureForcedDependencies(e){return this.#e.inheritSimpleDataAsFutureForcedDependencies(e),this}inheritPendingDependenciesAsFutureForcedDependencies(){return this.#e.inheritPendingDependenciesAsFutureForcedDependencies(),this}resetBBox(e){return this.#n||this.#e.resetBBox(this.#t),this}recordClipBox(e,t,n,r,i,a){return this.#n||this.#e.recordClipBox(this.#t,t,n,r,i,a),this}recordBBox(e,t,n,r,i,a){return this.#n||this.#e.recordBBox(this.#t,t,n,r,i,a),this}recordCharacterBBox(e,t,n,r,i,a,o){return this.#n||this.#e.recordCharacterBBox(this.#t,t,n,r,i,a,o),this}recordFullPageBBox(e){return this.#n||this.#e.recordFullPageBBox(this.#t),this}getSimpleIndex(e){return this.#e.getSimpleIndex(e)}recordDependencies(e,t){return this.#e.recordDependencies(this.#t,t),this}recordNamedDependency(e,t){return this.#e.recordNamedDependency(this.#t,t),this}recordOperation(e){return this.#e.recordOperation(this.#t,!0),this}recordShowTextOperation(e){return this.#e.recordShowTextOperation(this.#t,!0),this}bboxToClipBoxDropOperation(e){return this.#n||this.#e.bboxToClipBoxDropOperation(this.#t,!0),this}take(){throw Error(`Unreachable`)}takeDebugMetadata(){throw Error(`Unreachable`)}},Dt={stroke:[`path`,`transform`,`filter`,`strokeColor`,`strokeAlpha`,`lineWidth`,`lineCap`,`lineJoin`,`miterLimit`,`dash`],fill:[`path`,`transform`,`filter`,`fillColor`,`fillAlpha`,`globalCompositeOperation`,`SMask`],imageXObject:[`transform`,`SMask`,`filter`,`fillAlpha`,`strokeAlpha`,`globalCompositeOperation`],rawFillPath:[`filter`,`fillColor`,`fillAlpha`],showText:[`transform`,`leading`,`charSpacing`,`wordSpacing`,`hScale`,`textRise`,`moveText`,`textMatrix`,`font`,`fontObj`,`filter`,`fillColor`,`textRenderingMode`,`SMask`,`fillAlpha`,`strokeAlpha`,`globalCompositeOperation`,`sameLineText`],transform:[`transform`],transformAndFill:[`transform`,`fillColor`]},Ot=class e{#e;#t;#n=4;#r=0;#i=new e.#a(this.#n*6);static#a=z.isFloat16ArraySupported?Float16Array:Float32Array;constructor(e){this.#e=e.width,this.#t=e.height}record(t,n,r,i){if(this.#r===this.#n){this.#n*=2;let t=new e.#a(this.#n*6);t.set(this.#i),this.#i=t}let o=W(t),s;if(i[0]!==1/0){let e=a.slice();B.axialAlignedBoundingBox([0,-r,n,0],o,e);let t=B.intersect(i,e);if(!t)return;let[c,l,u,d]=t;if(c!==e[0]||l!==e[1]||u!==e[2]||d!==e[3]){let e=Math.atan2(o[1],o[0]),t=Math.abs(Math.sin(e)),n=Math.abs(Math.cos(e));if(t<1e-6||n<1e-6||Math.abs(t-n)<1e-6)s=[c,l,c,d,u,l];else{let e=u-c,r=d-l,i=t*t,a=n*n,o=n*t,f=a-i,p=(r*a-e*o)/f;s=[c+(r*o-e*i)/f,l,c,l+p,u,d-p]}}}s||(s=[0,-r,0,0,n,-r],B.applyTransform(s,o,0),B.applyTransform(s,o,2),B.applyTransform(s,o,4)),s[0]/=this.#e,s[1]/=this.#t,s[2]/=this.#e,s[3]/=this.#t,s[4]/=this.#e,s[5]/=this.#t,this.#i.set(s,this.#r*6),this.#r++}take(){return this.#i.subarray(0,this.#r*6)}},kt=class{#e=new Set;#t=null;constructor({ownerDocument:e=globalThis.document,styleElement:t=null}){this._document=e,this.nativeFontFaces=new Set,this.styleElement=null,this.loadingRequests=[],this.loadTestFontId=0}addNativeFontFace(e){this.nativeFontFaces.add(e),this._document.fonts.add(e)}removeNativeFontFace(e){this.nativeFontFaces.delete(e),this._document.fonts.delete(e)}insertRule(e){let t=this.#n();t.insertRule(e,t.cssRules.length)}#n(){if(this.#t)return this.#t;let e=this._document.defaultView?.CSSStyleSheet||globalThis.CSSStyleSheet;if(!this.styleElement&&e){let{adoptedStyleSheets:t}=this._document;if(t){let n=new e;return t.push(n),this.#t=n}}return this.styleElement||(this.styleElement=this._document.createElement(`style`),this._document.documentElement.getElementsByTagName(`head`)[0].append(this.styleElement)),this.#t=this.styleElement.sheet}clear(){for(let e of this.nativeFontFaces)this._document.fonts.delete(e);if(this.nativeFontFaces.clear(),this.#e.clear(),this.#t){let{adoptedStyleSheets:e}=this._document;e?.includes(this.#t)&&(this._document.adoptedStyleSheets=e.filter(e=>e!==this.#t)),this.#t=null}this.styleElement&&=(this.styleElement.remove(),null)}async loadSystemFont({systemFontInfo:e,disableFontFace:t,_inspectFont:n}){if(!(!e||this.#e.has(e.loadedName))){if(A(!t,"loadSystemFont shouldn't be called when `disableFontFace` is set."),this.isFontLoadingAPISupported){let{loadedName:t,src:r,style:i}=e,a=new FontFace(t,r,i);this.addNativeFontFace(a);try{await a.load(),this.#e.add(t),n?.(e)}catch{O(`Cannot load system font: ${e.baseFontName}, installing it could help to improve PDF rendering.`),this.removeNativeFontFace(a)}return}k(`Not implemented: loadSystemFont without the Font Loading API.`)}}async bind(e){if(e.attached||e.missingFile&&!e.systemFontInfo)return;if(e.attached=!0,e.systemFontInfo){await this.loadSystemFont(e);return}if(this.isFontLoadingAPISupported){let t=e.createNativeFontFace();if(t){this.addNativeFontFace(t);try{await t.loaded}catch(n){throw O(`Failed to load font '${t.family}': '${n}'.`),e.disableFontFace=!0,n}}return}let t=e.createFontFaceRule();if(t){if(this.insertRule(t),this.isSyncFontLoadingSupported)return;await new Promise(t=>{let n=this._queueLoadingCallback(t);this._prepareFontLoadEvent(e,n)})}}get isFontLoadingAPISupported(){let e=!!this._document?.fonts;return F(this,`isFontLoadingAPISupported`,e)}get isSyncFontLoadingSupported(){return F(this,`isSyncFontLoadingSupported`,i||z.platform.isFirefox)}_queueLoadingCallback(e){function t(){for(A(!r.done,`completeRequest() cannot be called twice.`),r.done=!0;n.length>0&&n[0].done;){let e=n.shift();setTimeout(e.callback,0)}}let{loadingRequests:n}=this,r={done:!1,complete:t,callback:e};return n.push(r),r}get _loadTestFont(){let e=atob(`T1RUTwALAIAAAwAwQ0ZGIDHtZg4AAAOYAAAAgUZGVE1lkzZwAAAEHAAAABxHREVGABQAFQAABDgAAAAeT1MvMlYNYwkAAAEgAAAAYGNtYXABDQLUAAACNAAAAUJoZWFk/xVFDQAAALwAAAA2aGhlYQdkA+oAAAD0AAAAJGhtdHgD6AAAAAAEWAAAAAZtYXhwAAJQAAAAARgAAAAGbmFtZVjmdH4AAAGAAAAAsXBvc3T/hgAzAAADeAAAACAAAQAAAAEAALZRFsRfDzz1AAsD6AAAAADOBOTLAAAAAM4KHDwAAAAAA+gDIQAAAAgAAgAAAAAAAAABAAADIQAAAFoD6AAAAAAD6AABAAAAAAAAAAAAAAAAAAAAAQAAUAAAAgAAAAQD6AH0AAUAAAKKArwAAACMAooCvAAAAeAAMQECAAACAAYJAAAAAAAAAAAAAQAAAAAAAAAAAAAAAFBmRWQAwAAuAC4DIP84AFoDIQAAAAAAAQAAAAAAAAAAACAAIAABAAAADgCuAAEAAAAAAAAAAQAAAAEAAAAAAAEAAQAAAAEAAAAAAAIAAQAAAAEAAAAAAAMAAQAAAAEAAAAAAAQAAQAAAAEAAAAAAAUAAQAAAAEAAAAAAAYAAQAAAAMAAQQJAAAAAgABAAMAAQQJAAEAAgABAAMAAQQJAAIAAgABAAMAAQQJAAMAAgABAAMAAQQJAAQAAgABAAMAAQQJAAUAAgABAAMAAQQJAAYAAgABWABYAAAAAAAAAwAAAAMAAAAcAAEAAAAAADwAAwABAAAAHAAEACAAAAAEAAQAAQAAAC7//wAAAC7////TAAEAAAAAAAABBgAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAAAAAD/gwAyAAAAAQAAAAAAAAAAAAAAAAAAAAABAAQEAAEBAQJYAAEBASH4DwD4GwHEAvgcA/gXBIwMAYuL+nz5tQXkD5j3CBLnEQACAQEBIVhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYAAABAQAADwACAQEEE/t3Dov6fAH6fAT+fPp8+nwHDosMCvm1Cvm1DAz6fBQAAAAAAAABAAAAAMmJbzEAAAAAzgTjFQAAAADOBOQpAAEAAAAAAAAADAAUAAQAAAABAAAAAgABAAAAAAAAAAAD6AAAAAAAAA==`);return F(this,`_loadTestFont`,e)}_prepareFontLoadEvent(e,t){function n(e,t){return e.charCodeAt(t)<<24|e.charCodeAt(t+1)<<16|e.charCodeAt(t+2)<<8|e.charCodeAt(t+3)&255}function r(e){return String.fromCharCode(e>>24&255,e>>16&255,e>>8&255,e&255)}function i(e,t,n,r){let i=e.substring(0,t),a=e.substring(t+n);return i+r+a}let a,o,s=this._document.createElement(`canvas`);s.width=1,s.height=1;let c=s.getContext(`2d`),l=0;function u(e,t){if(++l>30){O(`Load test font never loaded.`),t();return}if(c.font=`30px `+e,c.fillText(`.`,0,20),c.getImageData(0,0,1,1).data[3]>0){t();return}setTimeout(u.bind(null,e,t))}let d=`lt${Date.now()}${this.loadTestFontId++}`,f=this._loadTestFont;f=i(f,976,d.length,d);let p=1482184792,m=n(f,16);for(a=0,o=d.length-3;a{g.remove(),t.complete()})}},At=class{compiledGlyphs=Object.create(null);#e;constructor(e,t=null,n,r){this.#e=e,this._inspectFont=t,n&&(this.charProcOperatorList=n),r&&Object.assign(this,r)}createNativeFontFace(){if(!this.data||this.disableFontFace)return null;let e;if(!this.cssFontInfo)e=new FontFace(this.loadedName,this.data,{});else{let t={weight:this.cssFontInfo.fontWeight};this.cssFontInfo.italicAngle&&(t.style=`oblique ${this.cssFontInfo.italicAngle}deg`),e=new FontFace(this.cssFontInfo.fontFamily,this.data,t)}return this._inspectFont?.(this),e}createFontFaceRule(){if(!this.data||this.disableFontFace)return null;let e=`url(data:${this.mimetype};base64,${this.data.toBase64()});`,t;if(!this.cssFontInfo)t=`@font-face {font-family:"${this.loadedName}";src:${e}}`;else{let n=`font-weight: ${this.cssFontInfo.fontWeight};`;this.cssFontInfo.italicAngle&&(n+=`font-style: oblique ${this.cssFontInfo.italicAngle}deg;`),t=`@font-face {font-family:"${this.cssFontInfo.fontFamily}";${n}src:${e}}`}return this._inspectFont?.(this,e),t}getPathGenerator(e,t){if(this.compiledGlyphs[t]!==void 0)return this.compiledGlyphs[t];let n=this.loadedName+`_path_`+t,r;try{r=e.get(n)}catch(e){O(`getPathGenerator - ignoring character: "${e}".`)}let i=Je(r?.path);return this.fontExtraProperties||e.delete(n),this.compiledGlyphs[t]=i}get black(){return this.#e.black}get bold(){return this.#e.bold}get disableFontFace(){return this.#e.disableFontFace}set disableFontFace(e){F(this,`disableFontFace`,!!e)}get fontExtraProperties(){return this.#e.fontExtraProperties}get isInvalidPDFjsFont(){return this.#e.isInvalidPDFjsFont}get isType3Font(){return this.#e.isType3Font}get italic(){return this.#e.italic}get missingFile(){return this.#e.missingFile}get remeasure(){return this.#e.remeasure}get vertical(){return this.#e.vertical}get ascent(){return this.#e.ascent}get defaultWidth(){return this.#e.defaultWidth}get descent(){return this.#e.descent}get bbox(){return this.#e.bbox}get fontMatrix(){return this.#e.fontMatrix}get fallbackName(){return this.#e.fallbackName}get loadedName(){return this.#e.loadedName}get mimetype(){return this.#e.mimetype}get name(){return this.#e.name}get data(){return this.#e.data}clearData(){this.#e.clearData()}get cssFontInfo(){return this.#e.cssFontInfo}get systemFontInfo(){return this.#e.systemFontInfo}get defaultVMetrics(){return this.#e.defaultVMetrics}},jt=class{static strings=[`fontFamily`,`fontWeight`,`italicAngle`]},Mt=class{static strings=[`css`,`loadedName`,`baseFontName`,`src`]},Nt=class{static bools=[`black`,`bold`,`disableFontFace`,`fontExtraProperties`,`isInvalidPDFjsFont`,`isType3Font`,`italic`,`missingFile`,`remeasure`,`vertical`];static numbers=[`ascent`,`defaultWidth`,`descent`];static strings=[`fallbackName`,`loadedName`,`mimetype`,`name`];static OFFSET_NUMBERS=Math.ceil(this.bools.length*2/8);static OFFSET_BBOX=this.OFFSET_NUMBERS+this.numbers.length*8;static OFFSET_FONT_MATRIX=this.OFFSET_BBOX+1+8;static OFFSET_DEFAULT_VMETRICS=this.OFFSET_FONT_MATRIX+1+48;static OFFSET_STRINGS=this.OFFSET_DEFAULT_VMETRICS+1+6},Pt=class{static KIND=0;static HAS_BBOX=1;static HAS_BACKGROUND=2;static SHADING_TYPE=3;static N_COORD=4;static N_COLOR=8;static N_STOP=12;static N_FIGURES=16},Ft=class{#e;#t=new TextDecoder;#n;constructor(e){this.#e=e,this.#n=new DataView(e)}#r(e){A(e>n&3;return r===0?void 0:r===2}get black(){return this.#r(0)}get bold(){return this.#r(1)}get disableFontFace(){return this.#r(2)}get fontExtraProperties(){return this.#r(3)}get isInvalidPDFjsFont(){return this.#r(4)}get isType3Font(){return this.#r(5)}get italic(){return this.#r(6)}get missingFile(){return this.#r(7)}get remeasure(){return this.#r(8)}get vertical(){return this.#r(9)}#i(e){return A(e0){t=a.slice();for(let e=0,n=l.length;etypeof e==`object`&&Number.isInteger(e?.num)&&e.num>=0&&Number.isInteger(e?.gen)&&e.gen>=0,Wt=de.bind(null,Ut,e=>typeof e==`object`&&typeof e?.name==`string`),Gt=class{#e=new Map;#t=Promise.resolve();postMessage(e,t){let n={data:structuredClone(e,t?{transfer:t}:null)};this.#t.then(()=>{for(let[e]of this.#e)e.call(this,n)})}addEventListener(e,t,n=null){let r=null;if(n?.signal instanceof AbortSignal){let{signal:i}=n;if(i.aborted){O("LoopbackPort - cannot use an `aborted` signal.");return}let a=()=>this.removeEventListener(e,t);r=()=>i.removeEventListener(`abort`,a),i.addEventListener(`abort`,a)}this.#e.set(t,r)}removeEventListener(e,t){this.#e.get(t)?.(),this.#e.delete(t)}terminate(){for(let[,e]of this.#e)e?.();this.#e.clear()}};r(1689);var Kt={DATA:1,ERROR:2},q={CANCEL:1,CANCEL_COMPLETE:2,CLOSE:3,ENQUEUE:4,ERROR:5,PULL:6,PULL_COMPLETE:7,START_COMPLETE:8};function qt(){}function J(e){if(e instanceof re||e instanceof ee||e instanceof L||e instanceof te||e instanceof R)return e;switch(e instanceof Error||typeof e==`object`&&e||k(`wrapReason: Expected "reason" to be a (possibly cloned) Error.`),e.name){case`AbortException`:return new re(e.message);case`InvalidPDFException`:return new ee(e.message);case`PasswordException`:return new L(e.message,e.code);case`ResponseException`:return new te(e.message,e.status,e.missing);case`UnknownErrorException`:return new R(e.message,e.details)}return new R(e.message,e.toString())}var Jt=class{#e=new AbortController;constructor(e,t,n){this.sourceName=e,this.targetName=t,this.comObj=n,this.callbackId=1,this.streamId=1,this.streamSinks=Object.create(null),this.streamControllers=Object.create(null),this.callbackCapabilities=Object.create(null),this.actionHandler=Object.create(null),n.addEventListener(`message`,this.#t.bind(this),{signal:this.#e.signal})}#t({data:e}){if(e.targetName!==this.sourceName)return;if(e.stream){this.#r(e);return}if(e.callback){let t=e.callbackId,n=this.callbackCapabilities[t];if(!n)throw Error(`Cannot resolve callback ${t}`);if(delete this.callbackCapabilities[t],e.callback===Kt.DATA)n.resolve(e.data);else if(e.callback===Kt.ERROR)n.reject(J(e.reason));else throw Error(`Unexpected callback case`);return}let t=this.actionHandler[e.action];if(!t)throw Error(`Unknown action from worker: ${e.action}`);if(e.callbackId){let n=this.sourceName,r=e.sourceName,i=this.comObj;Promise.try(t,e.data).then(function(t){i.postMessage({sourceName:n,targetName:r,callback:Kt.DATA,callbackId:e.callbackId,data:t})},function(t){i.postMessage({sourceName:n,targetName:r,callback:Kt.ERROR,callbackId:e.callbackId,reason:J(t)})});return}if(e.streamId){this.#n(e);return}t(e.data)}on(e,t){let n=this.actionHandler;if(n[e])throw Error(`There is already an actionName called "${e}"`);n[e]=t}send(e,t,n){this.comObj.postMessage({sourceName:this.sourceName,targetName:this.targetName,action:e,data:t},n)}sendWithPromise(e,t,n){let r=this.callbackId++,i=Promise.withResolvers();this.callbackCapabilities[r]=i;try{this.comObj.postMessage({sourceName:this.sourceName,targetName:this.targetName,action:e,callbackId:r,data:t},n)}catch(e){i.reject(e)}return i.promise}sendWithStream(e,t,n,r){let i=this.streamId++,a=this.sourceName,o=this.targetName,s=this.comObj;return new ReadableStream({start:n=>{let c=Promise.withResolvers();return this.streamControllers[i]={controller:n,startCall:c,pullCall:null,cancelCall:null,isClosed:!1},s.postMessage({sourceName:a,targetName:o,action:e,streamId:i,data:t,desiredSize:n.desiredSize},r),c.promise},pull:e=>{let t=Promise.withResolvers();return this.streamControllers[i].pullCall=t,s.postMessage({sourceName:a,targetName:o,stream:q.PULL,streamId:i,desiredSize:e.desiredSize}),t.promise},cancel:e=>{A(e instanceof Error,`cancel must have a valid reason`);let t=Promise.withResolvers();return this.streamControllers[i].cancelCall=t,this.streamControllers[i].isClosed=!0,s.postMessage({sourceName:a,targetName:o,stream:q.CANCEL,streamId:i,reason:J(e)}),t.promise}},n)}#n(e){let t=e.streamId,n=this.sourceName,r=e.sourceName,i=this.comObj,a=this,o=this.actionHandler[e.action],s={enqueue(e,a=1,o){if(this.isCancelled)return;let s=this.desiredSize;this.desiredSize-=a,s>0&&this.desiredSize<=0&&(this.sinkCapability=Promise.withResolvers(),this.ready=this.sinkCapability.promise),i.postMessage({sourceName:n,targetName:r,stream:q.ENQUEUE,streamId:t,chunk:e},o)},close(){this.isCancelled||(this.isCancelled=!0,i.postMessage({sourceName:n,targetName:r,stream:q.CLOSE,streamId:t}),delete a.streamSinks[t])},error(e){A(e instanceof Error,`error must have a valid reason`),!this.isCancelled&&(this.isCancelled=!0,i.postMessage({sourceName:n,targetName:r,stream:q.ERROR,streamId:t,reason:J(e)}))},sinkCapability:Promise.withResolvers(),onPull:null,onCancel:null,isCancelled:!1,desiredSize:e.desiredSize,ready:null};s.sinkCapability.resolve(),s.ready=s.sinkCapability.promise,this.streamSinks[t]=s,Promise.try(o,e.data,s).then(function(){i.postMessage({sourceName:n,targetName:r,stream:q.START_COMPLETE,streamId:t,success:!0})},function(e){i.postMessage({sourceName:n,targetName:r,stream:q.START_COMPLETE,streamId:t,reason:J(e)})})}#r(e){let t=e.streamId,n=this.sourceName,r=e.sourceName,i=this.comObj,a=this.streamControllers[t],o=this.streamSinks[t];switch(e.stream){case q.START_COMPLETE:e.success?a.startCall.resolve():a.startCall.reject(J(e.reason));break;case q.PULL_COMPLETE:e.success?a.pullCall.resolve():a.pullCall.reject(J(e.reason));break;case q.PULL:if(!o){i.postMessage({sourceName:n,targetName:r,stream:q.PULL_COMPLETE,streamId:t,success:!0});break}o.desiredSize<=0&&e.desiredSize>0&&o.sinkCapability.resolve(),o.desiredSize=e.desiredSize,Promise.try(o.onPull||qt).then(function(){i.postMessage({sourceName:n,targetName:r,stream:q.PULL_COMPLETE,streamId:t,success:!0})},function(e){i.postMessage({sourceName:n,targetName:r,stream:q.PULL_COMPLETE,streamId:t,reason:J(e)})});break;case q.ENQUEUE:if(A(a,`enqueue should have stream controller`),a.isClosed)break;a.controller.enqueue(e.chunk);break;case q.CLOSE:if(A(a,`close should have stream controller`),a.isClosed)break;a.isClosed=!0,a.controller.close(),this.#i(a,t);break;case q.ERROR:A(a,`error should have stream controller`),a.controller.error(J(e.reason)),this.#i(a,t);break;case q.CANCEL_COMPLETE:e.success?a.cancelCall.resolve():a.cancelCall.reject(J(e.reason)),this.#i(a,t);break;case q.CANCEL:if(!o)break;let s=J(e.reason);Promise.try(o.onCancel||qt,s).then(function(){i.postMessage({sourceName:n,targetName:r,stream:q.CANCEL_COMPLETE,streamId:t,success:!0})},function(e){i.postMessage({sourceName:n,targetName:r,stream:q.CANCEL_COMPLETE,streamId:t,reason:J(e)})}),o.sinkCapability.reject(s),o.isCancelled=!0,delete this.streamSinks[t];break;default:throw Error(`Unexpected stream case`)}}async#i(e,t){await Promise.allSettled([e.startCall?.promise,e.pullCall?.promise,e.cancelCall?.promise]),delete this.streamControllers[t]}destroy(){this.#e?.abort(),this.#e=null}},Yt=class{#e=Object.freeze({cMapUrl:`CMap`,standardFontDataUrl:`font`,wasmUrl:`wasm`});constructor({cMapUrl:e=null,standardFontDataUrl:t=null,wasmUrl:n=null}){this.cMapUrl=e,this.standardFontDataUrl=t,this.wasmUrl=n}async fetch({kind:e,filename:t}){switch(e){case`cMapUrl`:case`standardFontDataUrl`:case`wasmUrl`:break;default:k(`Not implemented: ${e}`)}let n=this[e];if(!n)throw Error(`Ensure that the \`${e}\` API parameter is provided.`);let r=`${n}${t}`;return this._fetch(r,e).catch(t=>{throw Error(`Unable to load ${this.#e[e]} data at: ${r}`)})}async _fetch(e,t){k("Abstract method `_fetch` called.")}},Xt=class extends Yt{async _fetch(e,t){let n=await Se(e,t===`cMapUrl`&&!e.endsWith(`.bcmap`)?`text`:`bytes`);return n instanceof Uint8Array?n:ae(n)}},Zt=class{#e=!1;constructor({enableHWA:e=!1}){this.#e=e}create(e,t){if(e<=0||t<=0)throw Error(`Invalid canvas size`);let n=this._createCanvas(e,t);return{canvas:n,context:n.getContext(`2d`,{willReadFrequently:!this.#e})}}reset({canvas:e},t,n){if(!e)throw Error(`Canvas is not specified`);if(t<=0||n<=0)throw Error(`Invalid canvas size`);e.width=t,e.height=n}destroy(e){let{canvas:t}=e;if(!t)throw Error(`Canvas is not specified`);t.width=t.height=0,e.canvas=null,e.context=null}_createCanvas(e,t){k("Abstract method `_createCanvas` called.")}},Qt=class extends Zt{constructor({ownerDocument:e=globalThis.document,enableHWA:t=!1}){super({enableHWA:t}),this._document=e}_createCanvas(e,t){let n=this._document.createElement(`canvas`);return n.width=e,n.height=t,n}},$t=class{addFilter(e){return`none`}addHCMFilter(e,t){return`none`}addAlphaFilter(e){return`none`}addLuminosityFilter(e){return`none`}addKnockoutFilter(e=0){return`none`}addHighlightHCMFilter(e,t,n,r,i){return`none`}addSelectionHCMFilter(e,t){return`none`}addSelectionFilter(){return`none`}createSelectionStyle(e=null){return null}destroy(e=!1){}},en=class extends $t{#e;#t;#n;#r;#i;#a;#o=0;constructor({docId:e,ownerDocument:t=globalThis.document}){super(),this.#r=e,this.#i=t}get#s(){return this.#t||=new Map}get#c(){return this.#a||=new Map}get#l(){if(!this.#n){let e=this.#i.createElement(`div`),{style:t}=e;t.colorScheme=`only light`,t.visibility=`hidden`,t.contain=`strict`,t.width=t.height=0,t.position=`absolute`,t.top=t.left=0,t.zIndex=-1;let n=this.#i.createElementNS(c,`svg`);n.setAttribute(`width`,0),n.setAttribute(`height`,0),this.#n=this.#i.createElementNS(c,`defs`),e.append(n),n.append(this.#n),this.#i.body.append(e)}return this.#n}#u(e){if(e.length===1){let t=e[0],n=Array(256);for(let e=0;e<256;e++)n[e]=t[e]/255;let r=n.join(`,`);return[r,r,r]}let[t,n,r]=e,i=Array(256),a=Array(256),o=Array(256);for(let e=0;e<256;e++)i[e]=t[e]/255,a[e]=n[e]/255,o[e]=r[e]/255;return[i.join(`,`),a.join(`,`),o.join(`,`)]}#d(e){if(this.#e===void 0){this.#e=``;let e=this.#i.URL;e!==this.#i.baseURI&&(we(e)?O(`#createUrl: ignore "data:"-URL for performance reasons.`):this.#e=N(e,``))}return`url(${this.#e}#${e})`}addFilter(e){if(!e)return`none`;let t=this.#s.get(e);if(t)return t;let[n,r,i]=this.#u(e),a=e.length===1?n:`${n}${r}${i}`;if(t=this.#s.get(a),t)return this.#s.set(e,t),t;let o=`g_${this.#r}_transfer_map_${this.#o++}`,s=this.#d(o);this.#s.set(e,s),this.#s.set(a,s);let c=this.#m(o);return this.#g(n,r,i,c),s}addHCMFilter(e,t){let n=`${e}-${t}`,r=`base`,i=this.#c.get(r);if(i?.key===n||(i?(i.filter?.remove(),i.key=n,i.url=`none`,i.filter=null):(i={key:n,url:`none`,filter:null},this.#c.set(r,i)),!e||!t))return i.url;let a=this.#v(e);e=B.makeHexColor(...a);let o=this.#v(t);if(t=B.makeHexColor(...o),this.#b(),e===`#000000`&&t===`#ffffff`||e===t)return i.url;let s=Array(256);for(let e=0;e<=255;e++){let t=e/255;s[e]=t<=.03928?t/12.92:((t+.055)/1.055)**2.4}let c=s.join(`,`),l=`g_${this.#r}_hcm_filter`,u=i.filter=this.#m(l);this.#g(c,c,c,u),this.#p(u);let d=(e,t)=>{let n=a[e]/255,r=o[e]/255,i=Array(t+1);for(let e=0;e<=t;e++)i[e]=n+e/t*(r-n);return i.join(`,`)};return this.#g(d(0,5),d(1,5),d(2,5),u),i.url=this.#d(l),i.url}addSelectionHCMFilter(e,t){return this.addHighlightHCMFilter(`selection`,e,t,`HighlightText`,`Highlight`)}addSelectionFilter(){return this.addHighlightHCMFilter(`selection_default`,`black`,`white`,`HighlightText`,`Highlight`)}createSelectionStyle(e=null){let t=e?this.addSelectionHCMFilter(e.foreground,e.background):this.addSelectionFilter();return t===`none`||!z.platform.isFirefox?null:{"backdrop-filter":t,"background-color":`transparent`}}addAlphaFilter(e){let t=this.#s.get(e);if(t)return t;let[n]=this.#u([e]),r=`alpha_${n}`;if(t=this.#s.get(r),t)return this.#s.set(e,t),t;let i=`g_${this.#r}_alpha_map_${this.#o++}`,a=this.#d(i);this.#s.set(e,a),this.#s.set(r,a);let o=this.#m(i);return this.#_(n,o),a}addLuminosityFilter(e){let t=this.#s.get(e||`luminosity`);if(t)return t;let n,r;if(e?([n]=this.#u([e]),r=`luminosity_${n}`):r=`luminosity`,t=this.#s.get(r),t)return this.#s.set(e,t),t;let i=`g_${this.#r}_luminosity_map_${this.#o++}`,a=this.#d(i);this.#s.set(e,a),this.#s.set(r,a);let o=this.#m(i);return this.#f(o),e&&this.#_(n,o),a}addKnockoutFilter(e=0){let t=e>0?Math.min(1/e,1e6):1e6,n=`knockout_${t}`,r=this.#s.get(n);if(r)return r;let i=`g_${this.#r}_knockout_filter_${this.#o++}`,a=this.#d(i);this.#s.set(n,a);let o=this.#m(i),s=this.#i.createElementNS(c,`feComponentTransfer`);o.append(s);let l=this.#i.createElementNS(c,`feFuncA`);return l.setAttribute(`type`,`linear`),l.setAttribute(`slope`,`${t}`),l.setAttribute(`intercept`,`0`),s.append(l),a}addHighlightHCMFilter(e,t,n,r,i){let a=`${t}-${n}-${r}-${i}`,o=this.#c.get(e);if(o?.key===a||(o?(o.filter?.remove(),o.key=a,o.url=`none`,o.filter=null):(o={key:a,url:`none`,filter:null},this.#c.set(e,o)),!t||!n))return o.url;let[s,c]=[t,n].map(this.#v.bind(this)),l=Math.round(.2126*s[0]+.7152*s[1]+.0722*s[2]),u=Math.round(.2126*c[0]+.7152*c[1]+.0722*c[2]),[d,f]=[r,i].map(this.#x.bind(this));u{let r=Array(256),i=(u-l)/n,a=e/255,o=(t-e)/(255*n),s=0;for(let e=0;e<=n;e++){let t=Math.round(l+e*i),n=a+e*o;for(let e=s;e<=t;e++)r[e]=n;s=t+1}for(let e=s;e<256;e++)r[e]=r[s-1];return r.join(`,`)},m=`g_${this.#r}_hcm_${e}_filter`,h=o.filter=this.#m(m);return this.#p(h),this.#g(p(d[0],f[0],5),p(d[1],f[1],5),p(d[2],f[2],5),h),o.url=this.#d(m),o.url}destroy(e=!1){e&&this.#a?.size||(this.#n?.parentNode.parentNode.remove(),this.#n=null,this.#t?.clear(),this.#t=null,this.#a?.clear(),this.#a=null,this.#o=0)}#f(e){let t=this.#i.createElementNS(c,`feColorMatrix`);t.setAttribute(`type`,`matrix`),t.setAttribute(`values`,`0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.3 0.59 0.11 0 0`),e.append(t)}#p(e){let t=this.#i.createElementNS(c,`feColorMatrix`);t.setAttribute(`type`,`matrix`),t.setAttribute(`values`,`0.2126 0.7152 0.0722 0 0 0.2126 0.7152 0.0722 0 0 0.2126 0.7152 0.0722 0 0 0 0 0 1 0`),e.append(t)}#m(e){let t=this.#i.createElementNS(c,`filter`);return t.setAttribute(`color-interpolation-filters`,`sRGB`),t.setAttribute(`id`,e),this.#l.append(t),t}#h(e,t,n){let r=this.#i.createElementNS(c,t);r.setAttribute(`type`,`discrete`),r.setAttribute(`tableValues`,n),e.append(r)}#g(e,t,n,r){let i=this.#i.createElementNS(c,`feComponentTransfer`);r.append(i),this.#h(i,`feFuncR`,e),this.#h(i,`feFuncG`,t),this.#h(i,`feFuncB`,n)}#_(e,t){let n=this.#i.createElementNS(c,`feComponentTransfer`);t.append(n),this.#h(n,`feFuncA`,e)}#v(e){return this.#l.style.color=`CanvasText`,this.#l.style.backgroundColor=e,Me(getComputedStyle(this.#l).getPropertyValue(`background-color`))}#y(e){return this.#l.style.color=`CanvasText`,this.#l.style.backgroundColor=e,je(getComputedStyle(this.#l).getPropertyValue(`background-color`))}#b(){this.#l.style.color=``,this.#l.style.backgroundColor=``}#x(e){let[t,n,r,i]=this.#y(e);if(i===1)return[t,n,r];let[a,o,s]=this.#v(`Canvas`);return[tn(t,a,i),tn(n,o,i),tn(r,s,i)]}};function tn(e,t,n){return Math.round(n*e+(1-n)*t)}if(i){let e;try{let t=process.getBuiltinModule(`module`).createRequire(import.meta.url);try{e=t("@napi-rs/canvas")}catch(e){O(`Cannot load "@napi-rs/canvas" package: "${e}".`)}}catch(e){O(`Cannot access the \`require\` function: "${e}".`)}globalThis.DOMMatrix||(e?.DOMMatrix?globalThis.DOMMatrix=e.DOMMatrix:O("Cannot polyfill `DOMMatrix`, rendering may be broken.")),globalThis.Path2D||(e?.Path2D?globalThis.Path2D=e.Path2D:O("Cannot polyfill `Path2D`, rendering may be broken.")),globalThis.navigator?.language||(globalThis.navigator={language:`en-US`,platform:``,userAgent:``})}async function nn(e){let t=await process.getBuiltinModule(`fs/promises`).readFile(e);return new Uint8Array(t)}var rn=class extends $t{},an=class extends Zt{_createCanvas(e,t){return process.getBuiltinModule(`module`).createRequire(import.meta.url)(`@napi-rs/canvas`).createCanvas(e,t)}},on=class extends Yt{async _fetch(e,t){return nn(e)}};function sn({src:e,srcPos:t=0,dest:n,width:r,height:i,nonBlackColor:a=4294967295,inverseDecode:o=!1}){let s=z.isLittleEndian?4278190080:255,[c,l]=o?[a,s]:[s,a],u=r>>3,d=r&7,f=c^l,p=e.length;n=new Uint32Array(n.buffer);let m=0;for(let r=0;r>7&1)&f,n[m+1]=c^-(r>>6&1)&f,n[m+2]=c^-(r>>5&1)&f,n[m+3]=c^-(r>>4&1)&f,n[m+4]=c^-(r>>3&1)&f,n[m+5]=c^-(r>>2&1)&f,n[m+6]=c^-(r>>1&1)&f,n[m+7]=c^-(r&1)&f}if(d===0)continue;let r=t>7-e&1)&f}return{srcPos:t,destPos:m}}function cn({src:e,srcPos:t=0,dest:n,destPos:r=0,width:i,height:a}){let o=0,s=i*a*3,c=s>>2,l=new Uint32Array(e.buffer,t,c),u=z.isLittleEndian?4278190080:255;if(z.isLittleEndian){for(;o>>24|t<<8|u,n[r+2]=t>>>16|i<<16|u,n[r+3]=i>>>8|u}for(let i=o*4,a=t+s;i>>8|u,n[r+2]=t<<16|i>>>16|u,n[r+3]=i<<8|u}for(let i=o*4,a=t+s;inull));let s=[];for(let e of o)if(e)for(let t of e.profiles)s.push({cali_idx:t.slot_id,filament_id:t.filament_id,setting_id:t.setting_id||``,name:t.name,k_value:parseFloat(t.k_value)||0,n_coef:parseFloat(t.n_coef)||0,extruder_id:t.extruder_id,nozzle_diameter:t.nozzle_diameter,nozzle_id:t.nozzle_id});return s}var d=[{code:`GFL00`,name:`Bambu PLA Basic`,displayName:`Bambu PLA Basic`,isCustom:!1,allCodes:[`GFL00`],source:`builtin`},{code:`GFL01`,name:`Bambu PLA Matte`,displayName:`Bambu PLA Matte`,isCustom:!1,allCodes:[`GFL01`],source:`builtin`},{code:`GFL05`,name:`Generic PLA`,displayName:`Generic PLA`,isCustom:!1,allCodes:[`GFL05`],source:`builtin`},{code:`GFG00`,name:`Bambu PETG Basic`,displayName:`Bambu PETG Basic`,isCustom:!1,allCodes:[`GFG00`],source:`builtin`},{code:`GFG05`,name:`Generic PETG`,displayName:`Generic PETG`,isCustom:!1,allCodes:[`GFG05`],source:`builtin`},{code:`GFB00`,name:`Bambu ABS Basic`,displayName:`Bambu ABS Basic`,isCustom:!1,allCodes:[`GFB00`],source:`builtin`},{code:`GFB05`,name:`Generic ABS`,displayName:`Generic ABS`,isCustom:!1,allCodes:[`GFB05`],source:`builtin`},{code:`GFA00`,name:`Bambu ASA Basic`,displayName:`Bambu ASA Basic`,isCustom:!1,allCodes:[`GFA00`],source:`builtin`},{code:`GFU00`,name:`Bambu TPU 95A`,displayName:`Bambu TPU 95A`,isCustom:!1,allCodes:[`GFU00`],source:`builtin`},{code:`GFU05`,name:`Generic TPU`,displayName:`Generic TPU`,isCustom:!1,allCodes:[`GFU05`],source:`builtin`},{code:`GFC00`,name:`Bambu PC Basic`,displayName:`Bambu PC Basic`,isCustom:!1,allCodes:[`GFC00`],source:`builtin`},{code:`GFN00`,name:`Bambu PA Basic`,displayName:`Bambu PA Basic`,isCustom:!1,allCodes:[`GFN00`],source:`builtin`},{code:`GFN05`,name:`Generic PA`,displayName:`Generic PA`,isCustom:!1,allCodes:[`GFN05`],source:`builtin`},{code:`GFS00`,name:`Bambu PLA-CF`,displayName:`Bambu PLA-CF`,isCustom:!1,allCodes:[`GFS00`],source:`builtin`},{code:`GFT00`,name:`Bambu PETG-CF`,displayName:`Bambu PETG-CF`,isCustom:!1,allCodes:[`GFT00`],source:`builtin`},{code:`GFNC0`,name:`Bambu PA-CF`,displayName:`Bambu PA-CF`,isCustom:!1,allCodes:[`GFNC0`],source:`builtin`},{code:`GFV00`,name:`Bambu PVA`,displayName:`Bambu PVA`,isCustom:!1,allCodes:[`GFV00`],source:`builtin`}];function f(e){let t=e.replace(/@.*$/,``).trim();t=t.replace(/\(Custom\)/i,``).trim(),t=t.replace(/^[#*]+\s*/,``).trim();let n=`PLA-CF.PETG-CF.ABS-GF.ASA-CF.PA-CF.PAHT-CF.PA6-CF.PA6-GF.PPA-CF.PPA-GF.PET-CF.PPS-CF.PC-CF.PC-ABS.ABS-GF.PCTG.PETG.PLA.ABS.ASA.PC.PA.TPU.PVA.HIPS.BVOH.PPS.PEEK.PEI`.split(`.`),r=``,a=-1;for(let e of n){let n=t.toUpperCase().indexOf(e.toUpperCase());if(n!==-1){r=e,a=n;break}}let o=``;a>0&&(o=t.substring(0,a).trim(),o=o.replace(/[-_\s]+$/,``));let s=``;a!==-1&&r&&(s=t.substring(a+r.length).trim(),s=s.replace(/^[-_\s]+/,``));let c=``;for(let e of i)if(s.toLowerCase().includes(e.toLowerCase())){c=e;break}if(!c&&o)for(let e of i){let t=RegExp(`\\s+${e}$`,`i`);if(t.test(o)){c=e,o=o.replace(t,``).trim();break}}return{brand:o,material:r,variant:c}}function p(e,t){let n=new Set(r);for(let t of e){let{brand:e}=f(t.name);e&&e.length>1&&n.add(e)}if(t)for(let e of t)if(e.filament_vendor&&e.filament_vendor.length>1)n.add(e.filament_vendor);else{let{brand:t}=f(e.name);t&&t.length>1&&n.add(t)}return Array.from(n).sort((e,t)=>e.localeCompare(t))}function m(e){let t=e.filter(e=>e.preset_type===`filament`);return t.length===0?[]:t.map(e=>{let t=String(e.id),n=e.filament_type||t,r=Array.from(new Set([t,n]));return{code:t,name:e.name,displayName:e.name,isCustom:!1,allCodes:r,source:`local`}}).sort((e,t)=>e.displayName.localeCompare(t.displayName))}function h(e,t,n,r,i){let a=[],o=[],s=new Set;for(let n of e)if(n.is_custom){let e=n.name.toUpperCase();(t.size===0||Array.from(t).some(t=>e.includes(t))||!e.includes(`@`))&&(a.push({code:n.setting_id,name:n.name,displayName:`${n.name} (Custom)`,isCustom:!0,allCodes:[n.setting_id],source:i?.has(n.setting_id)?`orca_cloud`:`cloud`}),s.add(n.setting_id))}else o.push({code:n.setting_id,name:n.name,displayName:n.name,isCustom:!1,allCodes:[n.setting_id],source:i?.has(n.setting_id)?`orca_cloud`:`cloud`}),s.add(n.setting_id);let c=n&&n.length>0?m(n):[],l=[];if(r&&r.length>0)for(let e of r){let t=e.filament_id.startsWith(`GF`)?`GFS`+e.filament_id.slice(2):e.filament_id;s.has(e.filament_id)||s.has(t)||l.push({code:e.filament_id,name:e.name,displayName:e.name,isCustom:!1,allCodes:[e.filament_id,t],source:`builtin`})}let u=[...a,...o,...c,...l];return u.length===0?d:u.sort((e,t)=>e.displayName.localeCompare(t.displayName))}function g(e,t){if(!e)return;let n=t.find(t=>t.code===e);if(n||=t.find(t=>t.allCodes.includes(e)),!n){let r=e.toLowerCase();n=t.find(e=>e.code.toLowerCase()===r||e.allCodes.some(e=>e.toLowerCase()===r))}return n}function _(e,t){let n=t.trim();return!n||e.some(e=>e.toLowerCase()===n.toLowerCase())?e:[...e,n].sort((e,t)=>e.localeCompare(t))}function v(e,t,n){if(!t)return[];let r=n.get(t.toLowerCase());return!r||r.size===0?[]:e.filter(e=>r.has(e.toLowerCase()))}function y(){try{let e=localStorage.getItem(c);if(e)return JSON.parse(e)}catch{}return[]}function b(e,t){let n=[e,...t.filter(t=>t.hex.toUpperCase()!==e.hex.toUpperCase())].slice(0,8);try{localStorage.setItem(c,JSON.stringify(n))}catch{}return n}function x(e){if(!e)return``;let t=e.split(`_`)[0];return/^GFS/i.test(t)&&(t=t.slice(0,2)+t.slice(3)),t.toUpperCase()}function S(e){return!!e&&/^GF[A-Z]99$/i.test(e)}var C={GFB99:`ABS`,GFC99:`PC`,GFG99:`PETG`,GFL99:`PLA`,GFN99:`PA`,GFP99:`PE`,GFR99:`EVA`,GFS99:`PVA`,GFU99:`TPU`};function w(e){return e&&C[e.toUpperCase()]||``}function T(e){let t=e.trim().toUpperCase();return t===`NYLON`?`PA`:t}function E(e,t){let n=w(e);return!!n&&!!t&&T(n)===T(t)}function D(e,t,n){return`${e}:${t}:${n}`}function O(e,t){return`${e}\u0000${t}`}function k(e){let[t=``,n=``]=e.split(`\0`);return{model:t,diameter:n}}function A(e,t){if(!t.material)return!1;let n=x(t.slicer_filament),r=x(e.filament_id);if(n&&r&&n===r){if(!S(r))return!0;let e=t.brand.trim();if((!e||e.toUpperCase()===`GENERIC`)&&E(r,t.material))return!0}let i=(e.name||``).replace(/^High Flow[_\s]+/i,``).replace(/^Standard[_\s]+/i,``).replace(/^HF[_\s]+/i,``).replace(/^S[_\s]+/i,``).trim(),a=f(i);return!(a.material.toUpperCase()!==t.material.toUpperCase()||t.brand&&!(a.brand.toLowerCase().includes(t.brand.toLowerCase())||t.brand.toLowerCase().includes(a.brand.toLowerCase()))||t.subtype&&!(a.variant.toLowerCase().includes(t.subtype.toLowerCase())||t.subtype.toLowerCase().includes(a.variant.toLowerCase())||i.toLowerCase().includes(t.subtype.toLowerCase())))}export{i as _,D as a,l as b,v as c,O as d,b as f,r as g,s as h,g as i,k as l,_ as m,p as n,A as o,x as p,u as r,y as s,h as t,f as u,n as v,a as y}; \ No newline at end of file +import{a as e}from"./client-DnySrlFv.js";import{Y as t}from"./index-Cxa-KVmA.js";var n=[`PLA`,`PETG`,`ABS`,`TPU`,`ASA`,`PC`,`PA`,`PVA`,`HIPS`,`PA-CF`,`PETG-CF`,`PLA-CF`],r=[`Bambu`,`PolyLite`,`PolyTerra`,`eSUN`,`Overture`,`Fiberon`,`SUNLU`,`Inland`,`Hatchbox`,`Generic`],i=`Basic.Matte.Silk.Silk+.Tough.Tough+.HF.High Flow.Engineering.CF.GF.Galaxy.Glow.Marble.Metal.Rainbow.Sparkle.Wood.Translucent.Transparent.Clear.Lite.Pro.Plus.Max.Super.Ultra.Flex.Soft.Hard.Strong.Impact.Heat Resistant.UV Resistant.ESD.Conductive.Magnetic.Gradient.Dual Color.Tri Color.Multicolor`.split(`.`),a=[{name:`Black`,hex:`000000`},{name:`White`,hex:`FFFFFF`},{name:`Gray`,hex:`808080`},{name:`Red`,hex:`FF0000`},{name:`Orange`,hex:`FFA500`},{name:`Yellow`,hex:`FFFF00`},{name:`Green`,hex:`00AE42`},{name:`Blue`,hex:`0066FF`},{name:`Purple`,hex:`8B00FF`},{name:`Pink`,hex:`FF69B4`},{name:`Brown`,hex:`8B4513`},{name:`Silver`,hex:`C0C0C0`},{name:`Clear`,hex:`00000000`}],o=[{name:`Dark Red`,hex:`8B0000`},{name:`Crimson`,hex:`DC143C`},{name:`Coral`,hex:`FF7F50`},{name:`Salmon`,hex:`FA8072`},{name:`Dark Orange`,hex:`FF8C00`},{name:`Peach`,hex:`FFDAB9`},{name:`Gold`,hex:`FFD700`},{name:`Khaki`,hex:`F0E68C`},{name:`Lemon`,hex:`FFF44F`},{name:`Lime`,hex:`32CD32`},{name:`Forest Green`,hex:`228B22`},{name:`Olive`,hex:`808000`},{name:`Mint`,hex:`98FF98`},{name:`Teal`,hex:`008080`},{name:`Navy`,hex:`000080`},{name:`Sky Blue`,hex:`87CEEB`},{name:`Royal Blue`,hex:`4169E1`},{name:`Cyan`,hex:`00FFFF`},{name:`Turquoise`,hex:`40E0D0`},{name:`Violet`,hex:`EE82EE`},{name:`Magenta`,hex:`FF00FF`},{name:`Indigo`,hex:`4B0082`},{name:`Lavender`,hex:`E6E6FA`},{name:`Plum`,hex:`DDA0DD`},{name:`Hot Pink`,hex:`FF69B4`},{name:`Rose`,hex:`FF007F`},{name:`Blush`,hex:`FFB6C1`},{name:`Chocolate`,hex:`D2691E`},{name:`Tan`,hex:`D2B48C`},{name:`Beige`,hex:`F5F5DC`},{name:`Maroon`,hex:`800000`},{name:`Dark Gray`,hex:`404040`},{name:`Light Gray`,hex:`D3D3D3`},{name:`Charcoal`,hex:`36454F`},{name:`Ivory`,hex:`FFFFF0`},{name:`Bambu Green`,hex:`00AE42`},{name:`Jade White`,hex:`E8E8E8`},{name:`Titan Gray`,hex:`5A5A5A`}],s=[...a,...o],c=`bambuddy-recent-colors`,l=[`0.2`,`0.4`,`0.6`,`0.8`];async function u(n,r){let i=t(r),a=Array.from(new Set([...l,...i])),o=[];for(let t of a)o.push(await e.getKProfiles(n,t).catch(()=>null));let s=[];for(let e of o)if(e)for(let t of e.profiles)s.push({cali_idx:t.slot_id,filament_id:t.filament_id,setting_id:t.setting_id||``,name:t.name,k_value:parseFloat(t.k_value)||0,n_coef:parseFloat(t.n_coef)||0,extruder_id:t.extruder_id,nozzle_diameter:t.nozzle_diameter,nozzle_id:t.nozzle_id});return s}var d=[{code:`GFL00`,name:`Bambu PLA Basic`,displayName:`Bambu PLA Basic`,isCustom:!1,allCodes:[`GFL00`],source:`builtin`},{code:`GFL01`,name:`Bambu PLA Matte`,displayName:`Bambu PLA Matte`,isCustom:!1,allCodes:[`GFL01`],source:`builtin`},{code:`GFL05`,name:`Generic PLA`,displayName:`Generic PLA`,isCustom:!1,allCodes:[`GFL05`],source:`builtin`},{code:`GFG00`,name:`Bambu PETG Basic`,displayName:`Bambu PETG Basic`,isCustom:!1,allCodes:[`GFG00`],source:`builtin`},{code:`GFG05`,name:`Generic PETG`,displayName:`Generic PETG`,isCustom:!1,allCodes:[`GFG05`],source:`builtin`},{code:`GFB00`,name:`Bambu ABS Basic`,displayName:`Bambu ABS Basic`,isCustom:!1,allCodes:[`GFB00`],source:`builtin`},{code:`GFB05`,name:`Generic ABS`,displayName:`Generic ABS`,isCustom:!1,allCodes:[`GFB05`],source:`builtin`},{code:`GFA00`,name:`Bambu ASA Basic`,displayName:`Bambu ASA Basic`,isCustom:!1,allCodes:[`GFA00`],source:`builtin`},{code:`GFU00`,name:`Bambu TPU 95A`,displayName:`Bambu TPU 95A`,isCustom:!1,allCodes:[`GFU00`],source:`builtin`},{code:`GFU05`,name:`Generic TPU`,displayName:`Generic TPU`,isCustom:!1,allCodes:[`GFU05`],source:`builtin`},{code:`GFC00`,name:`Bambu PC Basic`,displayName:`Bambu PC Basic`,isCustom:!1,allCodes:[`GFC00`],source:`builtin`},{code:`GFN00`,name:`Bambu PA Basic`,displayName:`Bambu PA Basic`,isCustom:!1,allCodes:[`GFN00`],source:`builtin`},{code:`GFN05`,name:`Generic PA`,displayName:`Generic PA`,isCustom:!1,allCodes:[`GFN05`],source:`builtin`},{code:`GFS00`,name:`Bambu PLA-CF`,displayName:`Bambu PLA-CF`,isCustom:!1,allCodes:[`GFS00`],source:`builtin`},{code:`GFT00`,name:`Bambu PETG-CF`,displayName:`Bambu PETG-CF`,isCustom:!1,allCodes:[`GFT00`],source:`builtin`},{code:`GFNC0`,name:`Bambu PA-CF`,displayName:`Bambu PA-CF`,isCustom:!1,allCodes:[`GFNC0`],source:`builtin`},{code:`GFV00`,name:`Bambu PVA`,displayName:`Bambu PVA`,isCustom:!1,allCodes:[`GFV00`],source:`builtin`}];function f(e){let t=e.replace(/@.*$/,``).trim();t=t.replace(/\(Custom\)/i,``).trim(),t=t.replace(/^[#*]+\s*/,``).trim();let n=`PLA-CF.PETG-CF.ABS-GF.ASA-CF.PA-CF.PAHT-CF.PA6-CF.PA6-GF.PPA-CF.PPA-GF.PET-CF.PPS-CF.PC-CF.PC-ABS.ABS-GF.PCTG.PETG.PLA.ABS.ASA.PC.PA.TPU.PVA.HIPS.BVOH.PPS.PEEK.PEI`.split(`.`),r=``,a=-1;for(let e of n){let n=t.toUpperCase().indexOf(e.toUpperCase());if(n!==-1){r=e,a=n;break}}let o=``;a>0&&(o=t.substring(0,a).trim(),o=o.replace(/[-_\s]+$/,``));let s=``;a!==-1&&r&&(s=t.substring(a+r.length).trim(),s=s.replace(/^[-_\s]+/,``));let c=``;for(let e of i)if(s.toLowerCase().includes(e.toLowerCase())){c=e;break}if(!c&&o)for(let e of i){let t=RegExp(`\\s+${e}$`,`i`);if(t.test(o)){c=e,o=o.replace(t,``).trim();break}}return{brand:o,material:r,variant:c}}function p(e,t){let n=new Set(r);for(let t of e){let{brand:e}=f(t.name);e&&e.length>1&&n.add(e)}if(t)for(let e of t)if(e.filament_vendor&&e.filament_vendor.length>1)n.add(e.filament_vendor);else{let{brand:t}=f(e.name);t&&t.length>1&&n.add(t)}return Array.from(n).sort((e,t)=>e.localeCompare(t))}function m(e){let t=e.filter(e=>e.preset_type===`filament`);return t.length===0?[]:t.map(e=>{let t=String(e.id),n=e.filament_type||t,r=Array.from(new Set([t,n]));return{code:t,name:e.name,displayName:e.name,isCustom:!1,allCodes:r,source:`local`}}).sort((e,t)=>e.displayName.localeCompare(t.displayName))}function h(e,t,n,r,i){let a=[],o=[],s=new Set;for(let n of e)if(n.is_custom){let e=n.name.toUpperCase();(t.size===0||Array.from(t).some(t=>e.includes(t))||!e.includes(`@`))&&(a.push({code:n.setting_id,name:n.name,displayName:`${n.name} (Custom)`,isCustom:!0,allCodes:[n.setting_id],source:i?.has(n.setting_id)?`orca_cloud`:`cloud`}),s.add(n.setting_id))}else o.push({code:n.setting_id,name:n.name,displayName:n.name,isCustom:!1,allCodes:[n.setting_id],source:i?.has(n.setting_id)?`orca_cloud`:`cloud`}),s.add(n.setting_id);let c=n&&n.length>0?m(n):[],l=[];if(r&&r.length>0)for(let e of r){let t=e.filament_id.startsWith(`GF`)?`GFS`+e.filament_id.slice(2):e.filament_id;s.has(e.filament_id)||s.has(t)||l.push({code:e.filament_id,name:e.name,displayName:e.name,isCustom:!1,allCodes:[e.filament_id,t],source:`builtin`})}let u=[...a,...o,...c,...l];return u.length===0?d:u.sort((e,t)=>e.displayName.localeCompare(t.displayName))}function g(e,t){if(!e)return;let n=t.find(t=>t.code===e);if(n||=t.find(t=>t.allCodes.includes(e)),!n){let r=e.toLowerCase();n=t.find(e=>e.code.toLowerCase()===r||e.allCodes.some(e=>e.toLowerCase()===r))}return n}function _(e,t){let n=t.trim();return!n||e.some(e=>e.toLowerCase()===n.toLowerCase())?e:[...e,n].sort((e,t)=>e.localeCompare(t))}function v(e,t,n){if(!t)return[];let r=n.get(t.toLowerCase());return!r||r.size===0?[]:e.filter(e=>r.has(e.toLowerCase()))}function y(){try{let e=localStorage.getItem(c);if(e)return JSON.parse(e)}catch{}return[]}function b(e,t){let n=[e,...t.filter(t=>t.hex.toUpperCase()!==e.hex.toUpperCase())].slice(0,8);try{localStorage.setItem(c,JSON.stringify(n))}catch{}return n}function x(e){if(!e)return``;let t=e.split(`_`)[0];return/^GFS/i.test(t)&&(t=t.slice(0,2)+t.slice(3)),t.toUpperCase()}function S(e){return!!e&&/^GF[A-Z]99$/i.test(e)}var C={GFB99:`ABS`,GFC99:`PC`,GFG99:`PETG`,GFL99:`PLA`,GFN99:`PA`,GFP99:`PE`,GFR99:`EVA`,GFS99:`PVA`,GFU99:`TPU`};function w(e){return e&&C[e.toUpperCase()]||``}function T(e){let t=e.trim().toUpperCase();return t===`NYLON`?`PA`:t}function E(e,t){let n=w(e);return!!n&&!!t&&T(n)===T(t)}function D(e,t,n){return`${e}:${t}:${n}`}function O(e,t){return`${e}\u0000${t}`}function k(e){let[t=``,n=``]=e.split(`\0`);return{model:t,diameter:n}}function A(e,t){if(!t.material)return!1;let n=x(t.slicer_filament),r=x(e.filament_id);if(n&&r&&n===r){if(!S(r))return!0;let e=t.brand.trim();if((!e||e.toUpperCase()===`GENERIC`)&&E(r,t.material))return!0}let i=(e.name||``).replace(/^High Flow[_\s]+/i,``).replace(/^Standard[_\s]+/i,``).replace(/^HF[_\s]+/i,``).replace(/^S[_\s]+/i,``).trim(),a=f(i);return!(a.material.toUpperCase()!==t.material.toUpperCase()||t.brand&&!(a.brand.toLowerCase().includes(t.brand.toLowerCase())||t.brand.toLowerCase().includes(a.brand.toLowerCase()))||t.subtype&&!(a.variant.toLowerCase().includes(t.subtype.toLowerCase())||t.subtype.toLowerCase().includes(a.variant.toLowerCase())||i.toLowerCase().includes(t.subtype.toLowerCase())))}export{i as _,D as a,l as b,v as c,O as d,b as f,r as g,s as h,g as i,k as l,_ as m,p as n,A as o,x as p,u as r,y as s,h as t,f as u,n as v,a as y}; \ No newline at end of file diff --git a/static/index.html b/static/index.html index dc8abb847..ab2b53a11 100644 --- a/static/index.html +++ b/static/index.html @@ -26,7 +26,7 @@ - +