From 3bbe00784f896678e159dfb52018839d5e285b14 Mon Sep 17 00:00:00 2001 From: maziggy Date: Wed, 5 Aug 2026 14:40:05 +0200 Subject: [PATCH] Write printer status straight through while the tab is hidden (#2754) Removing the requestAnimationFrame wrapper fixed the total stall but left the 100ms coalescing timer in the path, and a hidden page's timers are clamped to once a second at best -- once a minute past five minutes hidden. The reporter still saw a tab title at 2% beside a page at 40%. The coalescing guards against a render cascade, which a hidden tab cannot have, so it is skipped there and kept while visible. The existing hidden-tab tests advanced fake timers, which simulates the timer the browser was throttling; the new one never advances the clock. --- CHANGELOG.md | 2 +- .../src/__tests__/hooks/useWebSocket.test.ts | 108 ++++++++++++++++-- frontend/src/hooks/useWebSocket.ts | 84 +++++++++----- .../{index-BAVjF7qG.js => index-Cy2mY2rf.js} | 2 +- static/index.html | 2 +- 5 files changed, 156 insertions(+), 42 deletions(-) rename static/assets/{index-BAVjF7qG.js => index-Cy2mY2rf.js} (99%) diff --git a/CHANGELOG.md b/CHANGELOG.md index b97e2c417..c1eee9340 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,7 +24,7 @@ All notable changes to Bambuddy will be documented in this file. - **A print that never starts now says AMS drying was running, instead of blaming the SD card (#2758)** — Sending a job to an X2D with two AMS units mid-drying failed silently: the file uploaded, the printer accepted it and then simply stayed idle. Bambuddy waited out the start watchdog, re-uploaded the whole 3MF, waited again, and after three attempts gave up with advice to check the printer's screen and the SD card — while Bambu Studio, asked directly, said it could not start the job because of the drying. Bambuddy now watches the AMS drying telemetry it already receives across the dispatch window and, when a job never starts while a unit was drying, names the units in the failure message and records the correlation in the log from the first attempt rather than only after the retries are spent. This is deliberately a diagnosis and not a rule: the printers concerned support drying *continuing* through a print, so drying and printing are not in conflict as such, and the report also involved one AMS drying without its external power supply — which would make the start-of-print calibration a power problem rather than a drying one. Stopping the cycle automatically would therefore be acting on a guess, and could tear down drying the hardware was happy to continue. Until it is known which of the two is the real obstacle, Bambuddy tells you what it saw and leaves the call to you. The message for a stalled dispatch with no drying involved is unchanged. Wiki updated. Covered by backend tests. - **A hand-written systemd service left the Virtual Printer unable to start, with nothing obvious to blame (#2549, reporter @Ru3ck3)** — The Virtual Printer binds ports 990 and 322, both below 1024, which a service running as a normal user may not do without the `CAP_NET_BIND_SERVICE` capability. Without it the rest of Bambuddy works perfectly and only the Virtual Printer is dead: its sockets never open, the slicer never finds the printer, and the sole trace is one line in the journal. The reporter lost days to this before someone on Discord spotted the missing line. The install script has carried it since March, but the three other places that define the same service did not — the manual-install template, the combined Bambuddy plus SpoolBuddy installer, and the unit the wiki tells you to paste. All three have it now, and the wiki no longer claims the capability is always included when its own instructions omitted it. Bambuddy also diagnoses this itself: **Diagnose** on the virtual printer card previously reported only that nothing was listening on port 990, which reads identically to an ordinary port conflict. It now checks whether the process actually holds the capability and, when that is what is wrong, says so and gives the line to add. The check stays quiet when the port is answering, since fronting it another way (an iptables redirect is the documented alternative) is a legitimate setup, and it stays quiet when the capability is held, so a port that failed for some other reason is not misattributed. Existing installs are unaffected until reinstalled; the diagnostic tells you whether yours needs the line. Translated in all locales; wiki updated. Covered by backend tests. - **A refused AMS filament setting now says so in the log (#2756, reporter @Jostxxl)** — Configuring a slot publishes an `ams_filament_setting` command, and the printer answers it with a verdict. That answer was received and then thrown away at debug level, so a printer that refused the write left no trace at the log level support bundles are collected at. The reporter hit exactly that: six manual **Configure Slot** attempts on one X1C, every one returning success, every one read back by the #2582 verification as still holding the previous profile, and nothing anywhere to say what the printer had made of the command. A refusal is now logged with the printer's own `result` and `reason` alongside the AMS and tray it concerned. Only refusals are promoted — unlike the K-profile and drying commands this one is not rare, since every spool assignment and every K-profile re-apply sends one, and logging each acknowledgement would bury the line worth reading. The developer-mode probe is excluded as well: it sends this same command to the external slot specifically to watch it be refused on P1 firmware, so its failure is a measurement rather than a fault. Diagnostics only — nothing about which commands are sent or how they are built has changed. Covered by backend tests. -- **Live updates stopped arriving while the Bambuddy tab was in the background (#2754, reporter @mic4rd)** — The progress percentage in the tab title froze whenever you switched to another tab and jumped straight to the current value the moment you switched back, which defeats the point of putting it in the title. The cause was not in the tab-title feature: every printer status arriving over the WebSocket was written into the browser's cache from inside an animation-frame callback, and a browser gives a hidden tab no frames at all. Those callbacks are not slowed down, they are held — so the connection stayed up, the messages kept arriving, and every one of them parked in a queue that only ran when the tab was shown again. The same applied to the archive, inventory and spool refreshes, and to the queue that carries every non-status message, which stalled completely and accumulated messages until the tab came back. The animation frames were added alongside the real fix for a browser freeze on print completion — that fix was the batching, which is untouched; the frames only ever deferred each write by about a sixteenth of a second and are gone. One limit is worth knowing about and is the browser's rather than ours: browsers deliberately slow down timers in tabs you are not looking at, to roughly once a second, and to about once a minute once a tab has been hidden for five minutes. So the title keeps moving in the background, but on a tab left alone for a long time it steps rather than ticks. Covered by frontend tests that reproduce a hidden tab. +- **Live updates stopped arriving while the Bambuddy tab was in the background (#2754, reporter @mic4rd)** — The progress percentage in the tab title froze whenever you switched away and jumped straight to the current value the moment you came back, which defeats the point of putting it in the title. There were two causes, and the first fix only got one of them. Every printer status arriving over the WebSocket was written into the browser's cache from inside an animation-frame callback, and a browser gives a hidden tab no frames at all — those callbacks are not slowed down, they are held, so the connection stayed up, the messages kept arriving, and every one of them parked in a queue that only ran when the tab was shown again. The same applied to the archive, inventory and spool refreshes, and to the queue carrying every non-status message, which stalled completely. Removing the frames fixed that stall but not the report, because the write still went through a 100 ms timer that batches rapid updates — and a timer is exactly what a browser throttles in a tab you are not looking at, to roughly once a second, and to about once a minute once the tab has been hidden for five minutes. The reporter's screenshot showed a tab title reading 2% beside a page at 40%. That batching exists to stop a burst of messages causing a rendering pile-up, and a hidden tab is not rendering, so there is nothing to protect there: while the tab is hidden the value is now written straight through, and the batching still applies while you are looking at it. Worth knowing if you use Windows: a browser window completely covered by another window counts as hidden, not merely unfocused, which is why this could bite without ever switching tabs. Covered by frontend tests that reproduce a hidden tab, including one that never advances the clock — the earlier tests passed by simulating the very timer the browser was throttling. - **The bug-report button no longer covers the controls in the bottom-right corner (#2750, reporter @goodjaltman)** — On a phone the floating red button sits on top of whatever else is in that corner, which turns out to be most things: the scroll-to-top button on Profiles was ~83% underneath it and, since both sit at the same stacking level, which one you could actually tap came down to the order they happened to render in. The floating camera window parks there, as do the Group Edit save bar, the bulk-selection toolbars, and — because the button is pinned to the viewport rather than the page — the per-card action buttons on File Manager and Archives simply scroll underneath it. The reporter asked for a switch to hide the button, but it is the only way into the report form, and that form is not just a text box: it runs the printer connection diagnostic, scans your logs against the known-issue catalog, optionally captures five minutes of debug logging and attaches a support bundle. Hiding it doesn't produce smaller reports, it produces reports with nothing attached. So the button moves instead of disappearing. Once the window is narrow enough that the sidebar collapses into a menu button, the bug icon moves into that top bar and the corner is left alone; above that width nothing changes. That threshold is the one the layout already switches on, so there is no new breakpoint and no third state to reason about, and it covers tablets and half-width desktop windows rather than only phones. The report form itself is now a proper bottom sheet on phones, which also fixes it hanging 16 pixels off the left edge of the screen — it was sized to the full viewport width and then inset from the right, so a strip of the form was simply unreachable on anything under about 460 pixels wide. The scroll-to-top button on Profiles has been nudged clear of the corner as well, for the wide layouts where the floating button stays. Wiki updated. Covered by frontend tests. - **The Print Log's cost and energy figures were never sent to the browser** — Bambuddy has been recording what each run cost and how much power it drew, but the two Print Log endpoints built their responses field by field and never mentioned `cost`, `energy_kwh` or `energy_cost`. A field nobody names comes back as its default, so the values arrived as nulls — indistinguishable from a column that genuinely holds nothing, with no error and no log line to say otherwise. The same trap had already swallowed the failure-cause classification once before. Both endpoints now validate straight off the database row, which removes the opportunity to forget a field rather than fixing the three that happened to be missing. Existing rows need no migration: the data was always there. Covered by backend tests. - **The Print Log is reachable again once you have no archives** — The Archives page decided it had nothing to show before it checked which view you were on, so with zero archives the "No archives yet" card replaced every view including the log. The Print Log is a separate table that deliberately outlives the archives it refers to — deleting an archive only clears the reference, and clearing the log is its own action — so purging archives hid a history that was still in the database, with no way back to it short of re-adding an archive. The log view now renders its own empty state instead of borrowing the archive one. Wiki updated. Covered by a frontend test. diff --git a/frontend/src/__tests__/hooks/useWebSocket.test.ts b/frontend/src/__tests__/hooks/useWebSocket.test.ts index c9a9dffb3..cd9df397a 100644 --- a/frontend/src/__tests__/hooks/useWebSocket.test.ts +++ b/frontend/src/__tests__/hooks/useWebSocket.test.ts @@ -623,16 +623,23 @@ describe('useWebSocket hook', () => { /** * #2754 (reporter @mic4rd): live updates froze whenever the tab wasn't in - * front, and caught up all at once on switching back. The cache writes ran - * inside requestAnimationFrame, and a hidden tab gets no rendering - * opportunities — so the browser holds queued frame callbacks indefinitely - * rather than merely throttling them. + * front, and caught up all at once on switching back. * - * The stub below is what makes these tests meaningful: it hands back a - * handle and never invokes the callback, which is what a real hidden tab - * does. `document.hidden` is set alongside it to name the scenario, but the - * production code doesn't branch on visibility — it simply no longer defers - * to a frame. Reintroduce a rAF wrapper on either path and these fail. + * Two causes, fixed in two rounds. First the cache writes ran inside a + * requestAnimationFrame, and a hidden tab gets no rendering opportunities — + * the browser holds queued frame callbacks indefinitely rather than merely + * throttling them. The rAF stub below is what makes those tests meaningful: + * it hands back a handle and never invokes the callback, which is what a + * real hidden tab does. + * + * Removing the frame callback did not close the report, because the 100ms + * coalescing timer was still in the path and a hidden page's timers are + * clamped to at best once a second — once a minute past five minutes hidden. + * So the writes must not depend on a timer either while hidden, which is + * what `writes without waiting on a timer` pins down. Note it deliberately + * never advances the clock: a test that advances fake timers cannot tell a + * throttled timer from a prompt one, which is exactly why the original tests + * kept passing while the reporter's tab stayed frozen. */ describe('hidden tab (#2754)', () => { let rafSpy: ReturnType; @@ -690,6 +697,49 @@ describe('useWebSocket hook', () => { expect(rafSpy).not.toHaveBeenCalled(); }); + it('writes without waiting on a timer', async () => { + const { useWebSocket } = await import('../../hooks/useWebSocket'); + + renderHook(() => useWebSocket(), { wrapper: createWrapper(queryClient) }); + const ws = await waitForWs(); + act(() => ws.open()); + + act(() => { + ws.simulateMessage({ + type: 'printer_status', + printer_id: 1, + data: { state: 'RUNNING', progress: 42 }, + }); + }); + + // No advanceTimersByTime: a hidden tab's timers are throttled to once a + // second at best, so anything the title depends on has to have landed + // already. Reintroduce the coalescing timer on this path and the cache + // is still empty here. + expect(queryClient.getQueryData(['printerStatus', 1])).toMatchObject({ + state: 'RUNNING', + progress: 42, + }); + }); + + it('applies the newest value when several arrive before a frame would have run', async () => { + const { useWebSocket } = await import('../../hooks/useWebSocket'); + + renderHook(() => useWebSocket(), { wrapper: createWrapper(queryClient) }); + const ws = await waitForWs(); + act(() => ws.open()); + + act(() => { + ws.simulateMessage({ type: 'printer_status', printer_id: 1, data: { progress: 40 } }); + ws.simulateMessage({ type: 'printer_status', printer_id: 1, data: { progress: 41 } }); + }); + + // Writing through per message must not resurrect an earlier one: the + // pending map is drained on each flush, so a stale entry cannot be + // re-applied over the newer value. + expect(queryClient.getQueryData(['printerStatus', 1])).toMatchObject({ progress: 41 }); + }); + it('drains queued messages instead of wedging the queue', async () => { const { useWebSocket } = await import('../../hooks/useWebSocket'); const invalidateSpy = vi.spyOn(queryClient, 'invalidateQueries'); @@ -715,6 +765,46 @@ describe('useWebSocket hook', () => { }); }); + describe('visible tab still coalesces (#2754)', () => { + /** + * The counterpart to the hidden-tab block: the write-through is scoped to + * a hidden tab on purpose. A visible one is painting, and the 100ms window + * is what stops a burst of status messages turning into a render cascade — + * so "just always write through" is not the simplification it looks like. + */ + it('defers the write while the tab is visible', async () => { + const { useWebSocket } = await import('../../hooks/useWebSocket'); + + const client = new QueryClient({ + defaultOptions: { queries: { retry: false, gcTime: Infinity } }, + }); + vi.useFakeTimers(); + try { + renderHook(() => useWebSocket(), { wrapper: createWrapper(client) }); + const ws = await waitForWs(); + act(() => ws.open()); + + act(() => { + ws.simulateMessage({ + type: 'printer_status', + printer_id: 1, + data: { state: 'RUNNING', progress: 42 }, + }); + }); + + expect(client.getQueryData(['printerStatus', 1])).toBeUndefined(); + + await act(async () => { + vi.advanceTimersByTime(200); + }); + + expect(client.getQueryData(['printerStatus', 1])).toMatchObject({ progress: 42 }); + } finally { + vi.useRealTimers(); + } + }); + }); + describe('sendMessage', () => { it('sends JSON message when connected', async () => { const { useWebSocket } = await import('../../hooks/useWebSocket'); diff --git a/frontend/src/hooks/useWebSocket.ts b/frontend/src/hooks/useWebSocket.ts index 002a14bd6..9b5ce77fc 100644 --- a/frontend/src/hooks/useWebSocket.ts +++ b/frontend/src/hooks/useWebSocket.ts @@ -194,45 +194,69 @@ export function useWebSocket() { wsRef.current = ws; }, [processMessageQueue]); - // Throttled printer status update - coalesces rapid updates per printer. + // Write every pending printer status into the query cache. // - // #2754: these cache writes used to happen inside a requestAnimationFrame. - // A hidden tab gets no rendering opportunities, so the browser *holds* - // queued frame callbacks rather than throttling them — every status update - // parked in a pending frame and nothing reached the query cache until the - // tab was shown again, at which point they all ran at once. That froze the - // tab-title progress (usePrintProgressTitle reads this key and nothing - // else) and stalled every other live view. The 100ms coalescing below is - // what prevented the original render cascade; the frame callback only ever - // deferred the write by a frame, so it is gone. + // Extracted so the hidden-tab path below can run it inline: both paths share + // this one body, so the merge semantics cannot drift apart. Cancels any + // scheduled coalescing timer, since everything it was going to write has + // just been written and re-running it would re-apply stale data over newer. + const flushPrinterStatus = useCallback(() => { + if (printerStatusTimeoutRef.current) { + clearTimeout(printerStatusTimeoutRef.current); + printerStatusTimeoutRef.current = null; + } + + const updates = new Map(pendingPrinterStatus.current); + pendingPrinterStatus.current.clear(); + + updates.forEach((statusData, id) => { + queryClient.setQueryData(['printerStatus', id], (old: Record | undefined) => { + const merged = { ...old, ...statusData }; + if (merged.wifi_signal == null && old?.wifi_signal != null) { + merged.wifi_signal = old.wifi_signal; + } + return merged; + }); + }); + }, [queryClient]); + + // Printer status update — coalesced while the tab is visible, written + // straight through while it is not. + // + // #2754 (reporter @mic4rd), in two stages. First, these writes ran inside a + // requestAnimationFrame: a hidden tab gets no rendering opportunities, so + // the browser *holds* queued frame callbacks rather than throttling them, + // and nothing reached the cache until the tab was shown again. Removing the + // frame callback fixed that total stall but not the report, because a second + // timer-shaped dependency was left behind — this 100ms coalescing window. + // + // Browsers clamp timers in a hidden page to at best once a second, and drop + // pages hidden for more than five minutes to roughly one wake-up a minute. + // The reporter saw a tab title stuck at 2% beside a page at 40%. + // + // The coalescing exists to stop rapid messages triggering a render cascade. + // A hidden tab is not painting, so there is no cascade to prevent there — + // the timer is pure cost, and it is exactly the thing being throttled. So + // when hidden, skip it and write immediately. + // + // Note "hidden", not "unfocused": on Windows a fully-occluded window reports + // visibilityState 'hidden' too, which is why the reporter saw this from + // merely clicking away rather than only from switching tabs. const throttledPrinterStatusUpdate = useCallback((printerId: number, data: Record) => { // Merge with any pending data for this printer const existing = pendingPrinterStatus.current.get(printerId) || {}; pendingPrinterStatus.current.set(printerId, { ...existing, ...data }); + if (document.hidden) { + flushPrinterStatus(); + return; + } + // Schedule update if not already scheduled if (!printerStatusTimeoutRef.current) { - printerStatusTimeoutRef.current = window.setTimeout(() => { - const updates = new Map(pendingPrinterStatus.current); - pendingPrinterStatus.current.clear(); - printerStatusTimeoutRef.current = null; - - // Apply all pending updates - updates.forEach((statusData, id) => { - queryClient.setQueryData( - ['printerStatus', id], - (old: Record | undefined) => { - const merged = { ...old, ...statusData }; - if (merged.wifi_signal == null && old?.wifi_signal != null) { - merged.wifi_signal = old.wifi_signal; - } - return merged; - } - ); - }); - }, 100); // Update at most every 100ms + printerStatusTimeoutRef.current = window.setTimeout(flushPrinterStatus, 100); } - }, [queryClient]); + }, [flushPrinterStatus]); // Debounced invalidation helper - coalesces multiple rapid invalidations const debouncedInvalidate = useCallback((queryKey: string) => { diff --git a/static/assets/index-BAVjF7qG.js b/static/assets/index-Cy2mY2rf.js similarity index 99% rename from static/assets/index-BAVjF7qG.js rename to static/assets/index-Cy2mY2rf.js index 2c6428394..96ed4365e 100644 --- a/static/assets/index-BAVjF7qG.js +++ b/static/assets/index-Cy2mY2rf.js @@ -8749,7 +8749,7 @@ ${t.slice(l+2)}`,d+=1;else break}t.push({indent:l,number:parseInt(s,10),content: `))}function c(e,t,n,r){let i=n.enter(`tableCell`),o=n.enter(`phrasing`),s=n.containerPhrasing(e,{...r,before:a,after:a});return o(),i(),s}function l(e,t){return SXe(e,{align:t,alignDelimiters:r,padding:n,stringLength:i})}function u(e,t,n){let r=e.children,i=-1,a=[],o=t.enter(`table`);for(;++i0&&!n&&(e[e.length-1][1]._gfmAutolinkLiteralWalkedInto=!0),n}var XZe={tokenize:iQe,partial:!0};function ZZe(){return{document:{91:{name:`gfmFootnoteDefinition`,tokenize:tQe,continuation:{tokenize:nQe},exit:rQe}},text:{91:{name:`gfmFootnoteCall`,tokenize:eQe},93:{name:`gfmPotentialFootnoteCall`,add:`after`,tokenize:QZe,resolveTo:$Ze}}}}function QZe(e,t,n){let r=this,i=r.events.length,a=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]),o;for(;i--;){let e=r.events[i][1];if(e.type===`labelImage`){o=e;break}if(e.type===`gfmFootnoteCall`||e.type===`labelLink`||e.type===`label`||e.type===`image`||e.type===`link`)break}return s;function s(i){if(!o||!o._balanced)return n(i);let s=b5(r.sliceSerialize({start:o.end,end:r.now()}));return s.codePointAt(0)!==94||!a.includes(s.slice(1))?n(i):(e.enter(`gfmFootnoteCallLabelMarker`),e.consume(i),e.exit(`gfmFootnoteCallLabelMarker`),t(i))}}function $Ze(e,t){let n=e.length;for(;n--;)if(e[n][1].type===`labelImage`&&e[n][0]===`enter`){e[n][1];break}e[n+1][1].type=`data`,e[n+3][1].type=`gfmFootnoteCallLabelMarker`;let r={type:`gfmFootnoteCall`,start:Object.assign({},e[n+3][1].start),end:Object.assign({},e[e.length-1][1].end)},i={type:`gfmFootnoteCallMarker`,start:Object.assign({},e[n+3][1].end),end:Object.assign({},e[n+3][1].end)};i.end.column++,i.end.offset++,i.end._bufferIndex++;let a={type:`gfmFootnoteCallString`,start:Object.assign({},i.end),end:Object.assign({},e[e.length-1][1].start)},o={type:`chunkString`,contentType:`string`,start:Object.assign({},a.start),end:Object.assign({},a.end)},s=[e[n+1],e[n+2],[`enter`,r,t],e[n+3],e[n+4],[`enter`,i,t],[`exit`,i,t],[`enter`,a,t],[`enter`,o,t],[`exit`,o,t],[`exit`,a,t],e[e.length-2],e[e.length-1],[`exit`,r,t]];return e.splice(n,e.length-n+1,...s),e}function eQe(e,t,n){let r=this,i=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]),a=0,o;return s;function s(t){return e.enter(`gfmFootnoteCall`),e.enter(`gfmFootnoteCallLabelMarker`),e.consume(t),e.exit(`gfmFootnoteCallLabelMarker`),c}function c(t){return t===94?(e.enter(`gfmFootnoteCallMarker`),e.consume(t),e.exit(`gfmFootnoteCallMarker`),e.enter(`gfmFootnoteCallString`),e.enter(`chunkString`).contentType=`string`,l):n(t)}function l(s){if(a>999||s===93&&!o||s===null||s===91||E5(s))return n(s);if(s===93){e.exit(`chunkString`);let a=e.exit(`gfmFootnoteCallString`);return i.includes(b5(r.sliceSerialize(a)))?(e.enter(`gfmFootnoteCallLabelMarker`),e.consume(s),e.exit(`gfmFootnoteCallLabelMarker`),e.exit(`gfmFootnoteCall`),t):n(s)}return E5(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 tQe(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||E5(t))return n(t);if(t===93){e.exit(`chunkString`);let n=e.exit(`gfmFootnoteDefinitionLabelString`);return a=b5(r.sliceSerialize(n)),e.enter(`gfmFootnoteDefinitionLabelMarker`),e.consume(t),e.exit(`gfmFootnoteDefinitionLabelMarker`),e.exit(`gfmFootnoteDefinitionLabel`),f}return E5(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),M5(e,p,`gfmFootnoteDefinitionWhitespace`)):n(t)}function p(e){return t(e)}}function nQe(e,t,n){return e.check(R5,t,e.attempt(XZe,t,n))}function rQe(e){e.exit(`gfmFootnoteDefinition`)}function iQe(e,t,n){let r=this;return M5(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 aQe(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=P5(a);return l._open=!u||u===2&&!!s,l._close=!s||s===2&&!!u,n(a)}}}var oQe=class{constructor(){this.map=[]}add(e,t,n){sQe(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 sQe(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):T5(t)?a>1?(a=0,r.interrupt=!0,e.exit(`tableRow`),e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),p):n(t):D5(t)?M5(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||E5(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,D5(t)?M5(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 D5(t)?M5(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||T5(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 D5(t)?M5(e,b,`whitespace`)(t):b(t)}function b(n){return n===124?m(n):n===null||T5(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||T5(n)?(e.exit(`tableRow`),t(n)):D5(n)?M5(e,C,`whitespace`)(n):(e.enter(`data`),w(n))}function w(t){return t===null||t===124||E5(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 dQe(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 oQe;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({},c9(t.events,i)),e.add(i,0,[[`exit`,a,t]]),a=void 0),a}function fQe(e,t,n,r,i){let a=[],o=c9(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 c9(e,t){let n=e[t],r=n[0]===`enter`?`start`:`end`;return n[1][r]}var pQe={name:`tasklistCheck`,tokenize:hQe};function mQe(){return{text:{91:pQe}}}function hQe(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 E5(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 T5(r)?t(r):D5(r)?e.check({tokenize:gQe},t,n)(r):n(r)}}function gQe(e,t,n){return M5(e,r,`whitespace`);function r(e){return e===null?n(e):t(e)}}function _Qe(e){return v5([RZe(),ZZe(),aQe(e),lQe(),mQe()])}var vQe={};function yQe(e){let t=this,n=e||vQe,r=t.data(),i=r.micromarkExtensions||=[],a=r.fromMarkdownExtensions||=[],o=r.toMarkdownExtensions||=[];i.push(_Qe(n)),a.push(kZe()),o.push(AZe(n))}var bQe=`fileManager.readmeCollapsed`;function xQe({folderId:e}){let{t}=$e(),[n,r]=(0,y.useState)(()=>localStorage.getItem(bQe)===`1`);(0,y.useEffect)(()=>{localStorage.setItem(bQe,n?`1`:`0`)},[n]);let{data:i,isLoading:a,error:o}=q({queryKey:[`folder-readme`,e],queryFn:()=>Q.getLibraryFolderReadme(e),retry:!1,staleTime:3e4});return a||o||!i?null:n?(0,K.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,K.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,K.jsx)(oc,{className:`w-4 h-4 text-bambu-green flex-shrink-0`}),(0,K.jsx)(`span`,{className:`text-sm font-medium text-white truncate`,children:i.filename}),(0,K.jsx)(xl,{className:`w-4 h-4 text-bambu-gray flex-shrink-0 ml-auto`})]}),(0,K.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,K.jsx)(xl,{className:`w-4 h-4 text-bambu-green flex-shrink-0`}),(0,K.jsx)(`span`,{className:`text-xs font-medium text-bambu-gray [writing-mode:vertical-rl] rotate-180 select-none`,children:t(`fileManager.readme.label`)})]})]}):(0,K.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,K.jsxs)(`div`,{className:`flex items-center justify-between gap-2 px-3 py-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,K.jsx)(oc,{className:`w-4 h-4 text-bambu-green flex-shrink-0`}),(0,K.jsx)(`span`,{className:`text-sm font-medium text-white truncate`,title:i.filename,children:i.filename}),i.truncated&&(0,K.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,K.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,K.jsx)(bl,{className:`w-4 h-4`})})]}),(0,K.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,K.jsx)(AYe,{remarkPlugins:[yQe],components:{h1:({children:e})=>(0,K.jsx)(`h1`,{className:`text-lg font-semibold text-white mt-2 mb-1`,children:e}),h2:({children:e})=>(0,K.jsx)(`h2`,{className:`text-base font-semibold text-white mt-2 mb-1`,children:e}),h3:({children:e})=>(0,K.jsx)(`h3`,{className:`text-sm font-semibold text-white mt-2 mb-1`,children:e}),p:({children:e})=>(0,K.jsx)(`p`,{className:`my-1`,children:e}),ul:({children:e})=>(0,K.jsx)(`ul`,{className:`list-disc list-inside space-y-0.5 ml-2`,children:e}),ol:({children:e})=>(0,K.jsx)(`ol`,{className:`list-decimal list-inside space-y-0.5 ml-2`,children:e}),li:({children:e})=>(0,K.jsx)(`li`,{children:e}),code:({children:e,...t})=>t.className?(0,K.jsx)(`code`,{className:`block p-2 bg-bambu-dark rounded text-xs font-mono text-bambu-gray-light overflow-x-auto`,children:e}):(0,K.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,K.jsx)(`pre`,{className:`my-2`,children:e}),blockquote:({children:e})=>(0,K.jsx)(`blockquote`,{className:`border-l-2 border-bambu-dark-tertiary pl-3 text-bambu-gray italic`,children:e}),a:({children:e,href:t})=>(0,K.jsx)(`a`,{href:t,target:`_blank`,rel:`noopener noreferrer`,className:`text-bambu-green hover:underline`,children:e}),table:({children:e})=>(0,K.jsx)(`div`,{className:`overflow-x-auto`,children:(0,K.jsx)(`table`,{className:`min-w-full text-xs border-collapse`,children:e})}),th:({children:e})=>(0,K.jsx)(`th`,{className:`border border-bambu-dark-tertiary px-2 py-1 text-left font-semibold text-white`,children:e}),td:({children:e})=>(0,K.jsx)(`td`,{className:`border border-bambu-dark-tertiary px-2 py-1`,children:e}),hr:()=>(0,K.jsx)(`hr`,{className:`border-bambu-dark-tertiary my-2`})},children:i.content})})]})}function SQe({open:e,onClose:t,onPickTag:n}){let{t:r}=$e(),i=ao(),{showToast:a}=Fd(),[o,s]=(0,y.useState)(!1),[c,l]=(0,y.useState)(null),[u,d]=(0,y.useState)(``),[f,p]=(0,y.useState)(null),{data:m=[],isLoading:h}=q({queryKey:b8,queryFn:Q.getLibraryTags,enabled:e}),g=()=>{i.invalidateQueries({queryKey:b8}),i.invalidateQueries({queryKey:[`library-files`]})},_=J({mutationFn:async()=>{let e=u.trim();if(!e)throw Error(r(`fileManager.tags.nameRequired`));return c?Q.updateLibraryTag(c.id,e):Q.createLibraryTag(e)},onSuccess:()=>{a(r(c?`fileManager.tags.updated`:`fileManager.tags.created`),`success`),s(!1),l(null),d(``),g()},onError:e=>{a(e.message||r(`fileManager.tags.saveFailed`),`error`)}}),v=J({mutationFn:e=>Q.deleteLibraryTag(e),onSuccess:()=>{a(r(`fileManager.tags.deleted`),`success`),p(null),g()},onError:e=>{a(e.message||r(`fileManager.tags.deleteFailed`),`error`)}}),b=()=>{l(null),d(``),s(!0)},x=e=>{l(e),d(e.name),s(!0)},S=(0,y.useCallback)(()=>{_.isPending||(s(!1),l(null),d(``))},[_.isPending]);(0,y.useEffect)(()=>{if(!e)return;let n=e=>{e.key===`Escape`&&(_.isPending||v.isPending||(o?S():f||t()))};return document.addEventListener(`keydown`,n),()=>document.removeEventListener(`keydown`,n)},[e,o,f,_.isPending,v.isPending,S,t]);let C=e=>{e.preventDefault(),_.mutate()};if(!e)return null;let w=`library-tags-modal-title`,T=`library-tag-editor-title`;return(0,K.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[(0,K.jsx)(`div`,{className:`absolute inset-0 bg-black/60`,onClick:()=>{_.isPending||v.isPending||t()}}),(0,K.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":w,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-4 px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,K.jsxs)(`h2`,{id:w,className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(yu,{className:`w-5 h-5 text-bambu-green`}),r(`fileManager.tags.title`)]}),(0,K.jsx)(`p`,{className:`text-bambu-gray text-sm mt-0.5`,children:r(`fileManager.tags.subtitle`)})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)($,{onClick:b,children:[(0,K.jsx)(kl,{className:`w-4 h-4`}),r(`fileManager.tags.add`)]}),(0,K.jsx)(`button`,{type:`button`,className:`p-1.5 text-bambu-gray hover:text-white rounded`,onClick:t,"aria-label":r(`common.close`),children:(0,K.jsx)(Ju,{className:`w-5 h-5`})})]})]}),(0,K.jsx)(`div`,{className:`overflow-y-auto`,children:h?(0,K.jsxs)(`div`,{className:`flex items-center justify-center py-16 text-bambu-gray`,children:[(0,K.jsx)(X,{className:`w-6 h-6 animate-spin mr-2`}),r(`common.loading`)]}):m.length===0?(0,K.jsx)(`div`,{className:`py-16 text-center text-bambu-gray`,children:r(`fileManager.tags.empty`)}):(0,K.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,K.jsx)(`thead`,{children:(0,K.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary text-left text-bambu-gray`,children:[(0,K.jsx)(`th`,{className:`px-4 py-3 font-medium`,children:r(`fileManager.tags.name`)}),(0,K.jsx)(`th`,{className:`px-4 py-3 font-medium text-right`,children:r(`fileManager.tags.fileCount`)}),(0,K.jsx)(`th`,{className:`px-4 py-3 font-medium text-right w-32`,children:r(`common.actions`)})]})}),(0,K.jsx)(`tbody`,{children:m.map(e=>(0,K.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,K.jsx)(`td`,{className:`px-4 py-3 text-white font-medium`,children:e.name}),(0,K.jsx)(`td`,{className:`px-4 py-3 text-right text-bambu-gray`,children:e.file_count}),(0,K.jsx)(`td`,{className:`px-4 py-3 text-right`,onClick:e=>e.stopPropagation(),children:(0,K.jsxs)(`div`,{className:`flex items-center justify-end gap-1`,children:[(0,K.jsx)(`button`,{type:`button`,className:`p-1.5 text-bambu-gray hover:text-bambu-green rounded`,onClick:()=>x(e),title:r(`common.edit`),"aria-label":r(`fileManager.tags.editAria`,{name:e.name}),children:(0,K.jsx)(Tl,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{type:`button`,className:`p-1.5 text-bambu-gray hover:text-red-600 dark:hover:text-red-400 rounded`,onClick:()=>p(e),title:r(`common.delete`),"aria-label":r(`fileManager.tags.deleteAria`,{name:e.name}),children:(0,K.jsx)(Du,{className:`w-4 h-4`})})]})})]},e.id))})]})})]}),o&&(0,K.jsxs)(`div`,{className:`fixed inset-0 z-[60] flex items-center justify-center`,children:[(0,K.jsx)(`div`,{className:`absolute inset-0 bg-black/60`,onClick:S}),(0,K.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":T,children:[(0,K.jsx)(`h3`,{id:T,className:`text-lg font-semibold text-white mb-4`,children:r(c?`fileManager.tags.edit`:`fileManager.tags.add`)}),(0,K.jsxs)(`form`,{onSubmit:C,children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,htmlFor:`library-tag-name`,children:r(`fileManager.tags.name`)}),(0,K.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:u,onChange:e=>d(e.target.value),autoFocus:!0}),(0,K.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,K.jsx)($,{type:`button`,variant:`secondary`,onClick:S,children:r(`common.cancel`)}),(0,K.jsxs)($,{type:`submit`,disabled:_.isPending||!u.trim(),children:[_.isPending&&(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),r(`common.save`)]})]})]})]})]}),f&&(0,K.jsx)(qd,{title:r(`fileManager.tags.confirmDelete`,{name:f.name}),message:f.file_count>0?r(`fileManager.tags.confirmDeleteInUseMessage`,{count:f.file_count}):r(`fileManager.tags.confirmDeleteMessage`),confirmText:r(`common.delete`),variant:`danger`,isLoading:v.isPending,onConfirm:()=>v.mutate(f.id),onCancel:()=>p(null)})]})}var CQe=90;function wQe({onClose:e}){let{t}=$e(),n=ao(),{showToast:r}=Fd(),[i,a]=(0,y.useState)(CQe),[o,s]=(0,y.useState)(!0),[c,l]=(0,y.useState)(i);(0,y.useEffect)(()=>{let e=window.setTimeout(()=>l(i),300);return()=>window.clearTimeout(e)},[i]);let u=q({queryKey:[`library-purge-preview`,c,o],queryFn:()=>Q.previewLibraryPurge(c,o),enabled:c>=1}),d=J({mutationFn:()=>Q.executeLibraryPurge(i,o),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,y.useEffect)(()=>{let t=t=>{t.key===`Escape`&&!d.isPending&&e()};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e,d.isPending]);let f=u.data,p=f?.count??0,m=f?.total_bytes??0,h=p>0&&!d.isPending;return(0,K.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4`,children:(0,K.jsxs)(`div`,{className:`bg-white dark:bg-gray-900 rounded-lg shadow-xl max-w-lg w-full`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-gray-200 dark:border-gray-700`,children:[(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-gray-900 dark:text-gray-100 flex items-center gap-2`,children:[(0,K.jsx)(Du,{className:`w-5 h-5`}),t(`libraryPurge.title`)]}),(0,K.jsx)(`button`,{onClick:e,className:`text-gray-400 hover:text-gray-600 dark:hover:text-gray-200`,"aria-label":t(`common.close`),disabled:d.isPending,children:(0,K.jsx)(Ju,{className:`w-5 h-5`})})]}),(0,K.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,K.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400`,children:t(`libraryPurge.description`)}),(0,K.jsxs)(`div`,{children:[(0,K.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,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`input`,{id:`purge-days`,type:`number`,min:1,max:3650,value:i,onChange:e=>a(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,K.jsx)(`span`,{className:`text-sm text-gray-600 dark:text-gray-400`,children:t(`libraryPurge.days`)})]})]}),(0,K.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-gray-700 dark:text-gray-300`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:o,onChange:e=>s(e.target.checked),className:`rounded border-gray-300`}),t(`libraryPurge.includeNeverPrinted`)]}),(0,K.jsxs)(`div`,{className:`rounded border border-gray-200 dark:border-gray-700 bg-gray-50 dark:bg-gray-800/30 p-3`,children:[(0,K.jsx)(`div`,{className:`text-xs font-semibold uppercase tracking-wide text-gray-600 dark:text-gray-300 mb-2`,children:t(`libraryPurge.effectsTitle`)}),(0,K.jsxs)(`ul`,{className:`text-xs text-gray-700 dark:text-gray-300 space-y-1 list-disc pl-4`,children:[(0,K.jsx)(`li`,{children:t(`libraryPurge.effect1`)}),(0,K.jsx)(`li`,{children:t(`libraryPurge.effect2`)}),(0,K.jsx)(`li`,{children:t(`libraryPurge.effect3`)}),(0,K.jsx)(`li`,{children:t(`libraryPurge.effect4`)})]})]}),(0,K.jsx)(`div`,{className:`rounded border border-gray-200 dark:border-gray-700 bg-gray-50 dark:bg-gray-800/50 p-3`,children:u.isLoading||u.isFetching?(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-gray-500 dark:text-gray-400`,children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),` `,t(`libraryPurge.previewLoading`)]}):u.isError?(0,K.jsx)(`div`,{className:`text-sm text-red-600 dark:text-red-400`,children:u.error?.message??t(`libraryPurge.previewFailed`)}):(0,K.jsxs)(`div`,{className:`text-sm text-gray-900 dark:text-gray-100`,children:[(0,K.jsx)(`div`,{className:`font-medium`,children:t(`libraryPurge.previewSummary`,{count:p,size:Nd(m)})}),f?.sample_filenames&&f.sample_filenames.length>0&&(0,K.jsxs)(`ul`,{className:`mt-2 text-xs text-gray-600 dark:text-gray-400 space-y-0.5 list-disc pl-4`,children:[f.sample_filenames.map(e=>(0,K.jsx)(`li`,{className:`truncate`,children:e},e)),p>f.sample_filenames.length&&(0,K.jsx)(`li`,{className:`list-none italic text-gray-500`,children:t(`libraryPurge.andMore`,{count:p-f.sample_filenames.length})})]})]})}),(0,K.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,K.jsx)(Au,{className:`w-4 h-4 mt-0.5 shrink-0`}),(0,K.jsx)(`span`,{children:t(`libraryPurge.warning`)})]})]}),(0,K.jsxs)(`div`,{className:`flex justify-end gap-2 p-4 border-t border-gray-200 dark:border-gray-700`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:e,disabled:d.isPending,children:t(`common.cancel`)}),(0,K.jsx)($,{variant:`danger`,disabled:!h,onClick:()=>d.mutate(),children:d.isPending?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin mr-1`}),t(`libraryPurge.purging`)]}):t(`libraryPurge.confirmCta`,{count:p})})]})]})})}function TQe({parentId:e,onClose:t,onSave:n,isLoading:r,t:i}){let[a,o]=(0,y.useState)(``);return(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-sm border border-bambu-dark-tertiary`,children:[(0,K.jsx)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary`,children:(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`fileManager.newFolder`)})}),(0,K.jsxs)(`form`,{onSubmit:t=>{t.preventDefault(),n({name:a.trim(),parent_id:e})},className:`p-4 space-y-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:i(`fileManager.folderName`)}),(0,K.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,K.jsxs)(`div`,{className:`flex justify-end gap-2 pt-2`,children:[(0,K.jsx)($,{type:`button`,variant:`secondary`,onClick:t,children:i(`common.cancel`)}),(0,K.jsx)($,{type:`submit`,disabled:!a.trim()||r,children:r?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):i(`common.create`)})]})]})]})})}function EQe({onClose:e,onSave:t,isLoading:n,t:r}){let[i,a]=(0,y.useState)(``),[o,s]=(0,y.useState)(``),[c,l]=(0,y.useState)(!0),[u,d]=(0,y.useState)(!1);return(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-md border border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(mc,{className:`w-5 h-5 text-bambu-green`}),r(`fileManager.linkExternalFolder`)]}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:r(`fileManager.linkExternalFolderDescription`)})]}),(0,K.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,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:r(`fileManager.folderName`)}),(0,K.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,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:r(`fileManager.externalPath`)}),(0,K.jsx)(`input`,{type:`text`,value:o,onChange:e=>s(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green font-mono text-sm`,placeholder:`/mnt/nas/3d-prints`,required:!0}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:r(`fileManager.externalPathHelp`)})]}),(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,K.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,K.jsx)(`span`,{className:`text-sm text-white`,children:r(`fileManager.readOnly`)}),(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[`(`,r(`fileManager.readOnlyHelp`),`)`]})]}),(0,K.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,K.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,K.jsx)(`span`,{className:`text-sm text-white`,children:r(`fileManager.showHiddenFiles`)})]})]}),(0,K.jsxs)(`div`,{className:`flex justify-end gap-2 pt-2`,children:[(0,K.jsx)($,{type:`button`,variant:`secondary`,onClick:e,children:r(`common.cancel`)}),(0,K.jsx)($,{type:`submit`,disabled:!i.trim()||!o.trim()||n,children:n?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):r(`fileManager.linkFolder`)})]})]})]})})}var DQe=`<>:"/\\|?*`;function OQe(e){for(let t of e)if(DQe.includes(t)||t.charCodeAt(0)<32)return t;return null}function kQe({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,y.useState)(s),u=e===`file`?OQe(c):null,d=u?a(`fileManager.invalidFilenameChar`,{char:u}):null;return(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-sm border border-bambu-dark-tertiary`,children:[(0,K.jsx)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary`,children:(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:a(e===`file`?`fileManager.renameFile`:`fileManager.renameFolder`)})}),(0,K.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,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`common.name`)}),(0,K.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,K.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,K.jsx)(`span`,{className:`pr-3 text-bambu-gray text-sm select-none whitespace-nowrap`,children:o})]}),d&&(0,K.jsx)(`p`,{className:`mt-1 text-xs text-red-700 dark:text-red-400`,children:d})]}),(0,K.jsxs)(`div`,{className:`flex justify-end gap-2 pt-2`,children:[(0,K.jsx)($,{type:`button`,variant:`secondary`,onClick:n,children:a(`common.cancel`)}),(0,K.jsx)($,{type:`submit`,disabled:!c.trim()||c.trim()===s||!!d||i,children:i?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):a(`common.rename`)})]})]})]})})}function AQe({folders:e,selectedFiles:t,currentFolderId:n,onClose:r,onMove:i,isLoading:a,t:o}){let[s,c]=(0,y.useState)(null),l=(e,t=0)=>{let n=[];for(let r of e)n.push({id:r.id,name:r.name,depth:t}),r.children.length>0&&n.push(...l(r.children,t+1));return n},u=[{id:null,name:o(`fileManager.rootNoFolder`),depth:0},...l(e)];return(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-sm border border-bambu-dark-tertiary`,children:[(0,K.jsx)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary`,children:(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:o(`fileManager.moveFiles`,{count:t.length})})}),(0,K.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,K.jsx)(`div`,{className:`max-h-64 overflow-y-auto space-y-1`,children:u.map(e=>(0,K.jsxs)(`button`,{onClick:()=>c(e.id),disabled:e.id===n,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?`opacity-50 cursor-not-allowed text-bambu-gray`:`hover:bg-bambu-dark text-white`}`,style:{paddingLeft:`${12+e.depth*16}px`},children:[(0,K.jsx)(fc,{className:`w-4 h-4`}),e.name,e.id===n&&(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray ml-auto`,children:[`(`,o(`fileManager.current`),`)`]})]},e.id??`root`))}),(0,K.jsxs)(`div`,{className:`flex justify-end gap-2 pt-2`,children:[(0,K.jsx)($,{type:`button`,variant:`secondary`,onClick:r,children:o(`common.cancel`)}),(0,K.jsx)($,{onClick:()=>i(s),disabled:a,children:a?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):o(`common.move`)})]})]})]})})}function jQe({folder:e,onClose:t,onLink:n,isLoading:r,t:i}){let[a,o]=(0,y.useState)(`project`),[s,c]=(0,y.useState)(e.project_id||e.archive_id||null);(0,y.useState)(()=>{e.archive_id&&o(`archive`)});let{data:l}=q({queryKey:[`projects`],queryFn:()=>Q.getProjects(),select:e=>[...e].sort((e,t)=>e.name.localeCompare(t.name))}),{data:u}=q({queryKey:[`archives-for-link`],queryFn:()=>Q.getArchives(void 0,void 0,100)}),d=()=>{n(a===`project`?{project_id:s,archive_id:0}:{project_id:0,archive_id:s})},f=()=>{n({project_id:0,archive_id:0})},p=e.project_id||e.archive_id;return(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-md border border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary flex items-center justify-between`,children:[(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(Gc,{className:`w-5 h-5 text-bambu-green`}),i(`fileManager.linkFolder`)]}),(0,K.jsx)(`button`,{onClick:t,className:`p-1 hover:bg-bambu-dark rounded`,children:(0,K.jsx)(Ju,{className:`w-5 h-5 text-bambu-gray`})})]}),(0,K.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`fileManager.linkFolderDescription`,{name:e.name})}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsxs)(`button`,{onClick:()=>{o(`project`),c(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg border transition-colors ${a===`project`?`border-bambu-green bg-bambu-green/10 text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:text-white`}`,children:[(0,K.jsx)(Jo,{className:`w-4 h-4`}),i(`fileManager.project`)]}),(0,K.jsxs)(`button`,{onClick:()=>{o(`archive`),c(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg border transition-colors ${a===`archive`?`border-bambu-green bg-bambu-green/10 text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:text-white`}`,children:[(0,K.jsx)(jo,{className:`w-4 h-4`}),i(`fileManager.archive`)]})]}),(0,K.jsx)(`div`,{className:`max-h-64 overflow-y-auto space-y-1 bg-bambu-dark rounded-lg p-2`,children:a===`project`?l&&l.length>0?l.map(e=>(0,K.jsxs)(`button`,{onClick:()=>c(e.id),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`:`hover:bg-bambu-dark-tertiary text-white`}`,children:[(0,K.jsx)(`div`,{className:`w-3 h-3 rounded-full flex-shrink-0`,style:{backgroundColor:e.color||`#00ae42`}}),(0,K.jsx)(`span`,{className:`truncate`,children:e.name})]},e.id)):(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray text-center py-4`,children:i(`fileManager.noProjectsFound`)}):u&&u.length>0?u.map(e=>(0,K.jsxs)(`button`,{onClick:()=>c(e.id),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`:`hover:bg-bambu-dark-tertiary text-white`}`,children:[(0,K.jsx)(nc,{className:`w-4 h-4 text-bambu-gray flex-shrink-0`}),(0,K.jsx)(`span`,{className:`truncate`,children:e.print_name||e.filename})]},e.id)):(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray text-center py-4`,children:i(`fileManager.noArchivesFound`)})})]}),(0,K.jsxs)(`div`,{className:`p-4 border-t border-bambu-dark-tertiary flex justify-between`,children:[p&&(0,K.jsxs)($,{variant:`danger`,onClick:f,disabled:r,children:[(0,K.jsx)(Nu,{className:`w-4 h-4 mr-2`}),i(`fileManager.unlink`)]}),(0,K.jsxs)(`div`,{className:`flex gap-2 ${p?``:`ml-auto`}`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:t,children:i(`common.cancel`)}),(0,K.jsx)($,{onClick:d,disabled:!s||r,children:r?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):i(`fileManager.link`)})]})]})]})})}function MQe({folder:e,selectedFolderId:t,onSelect:n,onDelete:r,onLink:i,onRename:a,depth:o=0,wrapNames:s=!1,defaultExpanded:c=!0,showModified:l=!1,hasPermission:u,t:d}){let[f,p]=(0,y.useState)(c),[m,h]=(0,y.useState)(!1),g=e.children.length>0,_=e.project_id||e.archive_id,v=e.is_external,b=u(`library:delete_all`)||u(`library:delete_own`)&&e.file_count===0&&!g&&!v&&!_,x=b?void 0:u(`library:delete_own`)&&!v&&!_?d(`fileManager.onlyEmptyFoldersDeletable`):d(`fileManager.noPermissionDeleteFolder`);return(0,K.jsxs)(`div`,{children:[(0,K.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+o*12}px`},onClick:()=>n(e.id),children:[g?(0,K.jsx)(`button`,{onClick:e=>{e.stopPropagation(),p(!f)},className:`p-0.5 hover:bg-bambu-dark-tertiary rounded`,children:(0,K.jsx)(ls,{className:`w-3.5 h-3.5 transition-transform ${f?`rotate-90`:``}`})}):(0,K.jsx)(`div`,{className:`w-4.5`}),v?(0,K.jsx)(mc,{className:`w-4 h-4 text-purple-600 dark:text-purple-400 flex-shrink-0`}):(0,K.jsx)(fc,{className:`w-4 h-4 text-bambu-green flex-shrink-0`}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`span`,{className:`block text-sm ${s?`break-all`:`truncate`}`,title:e.name,children:e.name}),l&&e.latest_activity_at&&(0,K.jsxs)(`span`,{className:`mt-0.5 flex items-center gap-1 text-xs text-bambu-gray`,title:d(`fileManager.lastActivity`),children:[(0,K.jsx)(Qo,{className:`w-3 h-3 flex-shrink-0`}),(0,K.jsx)(`span`,{className:`truncate`,children:Uf(e.latest_activity_at)})]})]}),_&&(0,K.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,K.jsx)(Gc,{className:`w-3 h-3`}),e.project_name?(0,K.jsx)(Jo,{className:`w-3 h-3`}):(0,K.jsx)(jo,{className:`w-3 h-3`})]}),v&&e.external_readonly&&(0,K.jsx)(`span`,{title:d(`fileManager.readOnly`),children:(0,K.jsx)(Zc,{className:`w-3 h-3 text-amber-600 dark:text-amber-400 flex-shrink-0`})}),e.file_count>0&&(0,K.jsx)(`span`,{className:`flex-shrink-0 text-xs text-bambu-gray`,children:e.file_count}),!_&&!v&&(0,K.jsx)(`button`,{onClick:t=>{t.stopPropagation(),i(e)},className:`flex-shrink-0 p-1 rounded hover:bg-bambu-dark-tertiary`,title:d(`fileManager.linkToProjectOrArchive`),children:(0,K.jsx)(Gc,{className:`w-3.5 h-3.5 text-bambu-gray hover:text-bambu-green`})}),(0,K.jsx)(`div`,{className:`flex-shrink-0 flex items-center gap-0.5 transition-opacity ${s?``:`opacity-0 group-hover:opacity-100`}`,onClick:e=>e.stopPropagation(),children:(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(`button`,{onClick:()=>h(!m),className:`p-1 rounded hover:bg-bambu-dark-tertiary`,children:(0,K.jsx)(Js,{className:`w-3.5 h-3.5 text-bambu-gray`})}),m&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>h(!1)}),(0,K.jsxs)(`div`,{className:`absolute right-0 top-full mt-1 z-20 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl py-1 min-w-[120px]`,children:[(0,K.jsxs)(`button`,{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${u(`library:update_all`)?`text-white hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{u(`library:update_all`)&&(a(e),h(!1))},disabled:!u(`library:update_all`),title:u(`library:update_all`)?void 0:d(`fileManager.noPermissionRenameFolder`),children:[(0,K.jsx)(Tl,{className:`w-3.5 h-3.5`}),d(`common.rename`)]}),(0,K.jsxs)(`button`,{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${u(`library:update_all`)?`text-white hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{u(`library:update_all`)&&(i(e),h(!1))},disabled:!u(`library:update_all`),title:u(`library:update_all`)?void 0:d(`fileManager.noPermissionLinkFolder`),children:[(0,K.jsx)(Gc,{className:`w-3.5 h-3.5`}),d(_?`fileManager.changeLink`:`fileManager.linkTo`)]}),(0,K.jsxs)(`button`,{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${b?`text-red-700 dark:text-red-400 hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{b&&(r(e.id),h(!1))},disabled:!b,title:x,children:[(0,K.jsx)(Du,{className:`w-3.5 h-3.5`}),d(`common.delete`)]})]})]})]})})]}),g&&f&&(0,K.jsx)(`div`,{children:e.children.map(e=>(0,K.jsx)(MQe,{folder:e,selectedFolderId:t,onSelect:n,onDelete:r,onLink:i,onRename:a,depth:o+1,wrapNames:s,defaultExpanded:c,showModified:l,hasPermission:u,t:d},e.id))})]})}function l9(e){let t=e.toLowerCase();return t.endsWith(`.gcode`)||t.endsWith(`.gcode.3mf`)}function NQe({file:e,isSelected:t,isMobile:n,onSelect:r,onDelete:i,onDownload:a,onPrint:o,onSlice:s,onOpenInSlicer:c,onRunPipeline:l,useSlicerApi:u,canSlice:d,onPreview3d:f,onRename:p,onGenerateThumbnail:m,onTagClick:h,thumbnailVersion:g,hasPermission:_,canModify:v,authEnabled:b,showModified:x,t:S}){let[C,w]=(0,y.useState)(!1);return(0,K.jsxs)(`div`,{className:`group relative bg-bambu-dark-secondary rounded-lg border transition-all cursor-pointer overflow-hidden ${t?`border-bambu-green ring-1 ring-bambu-green`:`border-bambu-dark-tertiary hover:border-bambu-green/50`}`,onClick:()=>r(e.id),children:[(0,K.jsxs)(`div`,{className:`aspect-square bg-bambu-dark flex items-center justify-center overflow-hidden`,children:[e.thumbnail_path?(0,K.jsx)(`img`,{src:`${Q.getLibraryFileThumbnailUrl(e.id)}${g?(Q.getLibraryFileThumbnailUrl(e.id).includes(`?`)?`&`:`?`)+`v=${g}`:``}`,alt:e.filename,className:`w-full h-full object-cover`}):(0,K.jsx)(nc,{className:`w-12 h-12 text-bambu-gray/30`}),(0,K.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`:`bg-bambu-gray/90 text-white`}`,children:e.file_type.toUpperCase()})]}),(0,K.jsxs)(`div`,{className:`p-3`,children:[(0,K.jsx)(`h3`,{className:`text-sm font-medium text-white truncate`,title:e.print_name||e.filename,children:e.print_name||e.filename}),(0,K.jsxs)(`div`,{className:`flex items-center gap-3 mt-1 text-xs text-bambu-gray`,children:[(0,K.jsx)(`span`,{children:Nd(e.file_size)}),e.print_time_seconds&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(Ts,{className:`w-3 h-3`}),Jf(e.print_time_seconds)]})]}),e.sliced_for_model&&(0,K.jsxs)(`div`,{className:`mt-1 text-xs text-bambu-gray flex items-center gap-1`,children:[(0,K.jsx)(Ml,{className:`w-3 h-3`}),e.sliced_for_model]}),(e.variant_count??0)>1&&(0,K.jsxs)(`div`,{className:`mt-1 text-xs text-bambu-green flex items-center gap-1`,children:[(0,K.jsx)(Hc,{className:`w-3 h-3`}),S(`fileManager.variants.badge`,{count:e.variant_count})]}),e.print_count>0&&(0,K.jsx)(`div`,{className:`mt-1 text-xs text-bambu-green`,children:S(`fileManager.printedCount`,{count:e.print_count})}),b&&e.created_by_username&&(0,K.jsxs)(`div`,{className:`mt-1 text-xs text-bambu-gray flex items-center gap-1`,children:[(0,K.jsx)(Fu,{className:`w-3 h-3`}),e.created_by_username]}),x&&(0,K.jsxs)(`div`,{className:`mt-1 text-xs text-bambu-gray flex items-center gap-1`,title:S(`fileManager.lastModified`),children:[(0,K.jsx)(Qo,{className:`w-3 h-3`}),Uf(e.fs_modified_at??e.created_at)]}),(e.tags?.length??0)>0&&(0,K.jsx)(`div`,{className:`mt-2 flex flex-wrap gap-1`,onClick:e=>e.stopPropagation(),children:e.tags.map(e=>(0,K.jsxs)(`button`,{type:`button`,onClick:()=>h?.(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,K.jsx)(yu,{className:`w-2.5 h-2.5 flex-shrink-0`}),(0,K.jsx)(`span`,{className:`truncate`,children:e.name})]},e.id))})]}),(0,K.jsxs)(`div`,{className:`absolute bottom-2 right-2 transition-opacity ${n?`opacity-100`:`opacity-0 group-hover:opacity-100`}`,onClick:e=>e.stopPropagation(),children:[(0,K.jsx)(`button`,{onClick:()=>w(!C),className:`p-1.5 rounded bg-bambu-dark-secondary/90 hover:bg-bambu-dark-tertiary`,children:(0,K.jsx)(Js,{className:`w-4 h-4 text-bambu-gray`})}),C&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>w(!1)}),(0,K.jsxs)(`div`,{className:`absolute right-0 bottom-8 z-20 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl py-1 min-w-[140px]`,children:[o&&l9(e.filename)&&(0,K.jsxs)(`button`,{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${_(`queue:create`)?`text-bambu-green hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{_(`queue:create`)&&(o(e),w(!1))},disabled:!_(`queue:create`),title:_(`queue:create`)?void 0:S(`fileManager.noPermissionAddToQueue`),children:[(0,K.jsx)(Ml,{className:`w-3.5 h-3.5`}),S(`common.print`)]}),nG(e.filename)&&(u?s:c)&&(0,K.jsxs)(`button`,{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${d?`text-white hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{d&&(u?s?.(e):c?.(e),w(!1))},disabled:!d,title:d?void 0:S(u?`fileManager.noPermissionSlice`:`fileManager.noPermissionDownload`),children:[u?(0,K.jsx)(Ns,{className:`w-3.5 h-3.5`}):(0,K.jsx)(Qs,{className:`w-3.5 h-3.5`}),S(`slice.action`)]}),l&&u&&nG(e.filename)&&(0,K.jsxs)(`button`,{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${_(`pipelines:run`)?`text-white hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{_(`pipelines:run`)&&(l(e),w(!1))},disabled:!_(`pipelines:run`),title:_(`pipelines:run`)?void 0:S(`library.runWithPipeline.noPermission`),children:[(0,K.jsx)(Dl,{className:`w-3.5 h-3.5`}),S(`library.runWithPipeline.actionLabel`)]}),f&&(e.file_type===`3mf`||e.file_type===`gcode`||e.file_type===`stl`||e.file_type===`gcode.3mf`)&&(0,K.jsxs)(`button`,{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${_(`library:read`)?`text-white hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{_(`library:read`)&&(f(e),w(!1))},disabled:!_(`library:read`),title:_(`library:read`)?void 0:`You do not have permission to preview files`,children:[(0,K.jsx)(qo,{className:`w-3.5 h-3.5`}),`3D Preview`]}),(0,K.jsxs)(`button`,{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${_(`library:read`)?`text-white hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{_(`library:read`)&&(a(e.id),w(!1))},disabled:!_(`library:read`),title:_(`library:read`)?void 0:S(`fileManager.noPermissionDownload`),children:[(0,K.jsx)(Gs,{className:`w-3.5 h-3.5`}),S(`common.download`)]}),p&&(0,K.jsxs)(`button`,{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${v(`library`,`update`,e.created_by_id)?`text-white hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{v(`library`,`update`,e.created_by_id)&&(p(e),w(!1))},disabled:!v(`library`,`update`,e.created_by_id),title:v(`library`,`update`,e.created_by_id)?void 0:S(`fileManager.noPermissionRenameFile`),children:[(0,K.jsx)(Tl,{className:`w-3.5 h-3.5`}),S(`common.rename`)]}),m&&e.file_type===`stl`&&(0,K.jsxs)(`button`,{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${v(`library`,`update`,e.created_by_id)?`text-white hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{v(`library`,`update`,e.created_by_id)&&(m(e),w(!1))},disabled:!v(`library`,`update`,e.created_by_id),title:v(`library`,`update`,e.created_by_id)?void 0:S(`fileManager.noPermissionGenerateThumbnail`),children:[(0,K.jsx)(Ic,{className:`w-3.5 h-3.5`}),S(`fileManager.generateThumbnail`)]}),(0,K.jsxs)(`button`,{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${v(`library`,`delete`,e.created_by_id)?`text-red-700 dark:text-red-400 hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{v(`library`,`delete`,e.created_by_id)&&(i(e.id),w(!1))},disabled:!v(`library`,`delete`,e.created_by_id),title:v(`library`,`delete`,e.created_by_id)?void 0:S(`fileManager.noPermissionDeleteFile`),children:[(0,K.jsx)(Du,{className:`w-3.5 h-3.5`}),S(`common.delete`)]})]})]})]}),(0,K.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 ${n?`opacity-100`:`opacity-0 group-hover:opacity-100`}`}`,children:t&&(0,K.jsx)(`div`,{className:`w-2 h-2 bg-white rounded-sm`})})]})}function PQe(){let{t:e}=$e(),t=ao(),{showToast:n}=Fd(),{hasPermission:r,hasAnyPermission:i,canModify:a,authEnabled:o}=xd(),[s]=Fi(),c=ir(),l=s.get(`folder`),[u,d]=(0,y.useState)(l?parseInt(l,10):null),[f,p]=(0,y.useState)(`internal`),[m,h]=(0,y.useState)([]),[g,_]=(0,y.useState)(!1),[v,b]=(0,y.useState)(!1),[x,S]=(0,y.useState)(!1),[C,w]=(0,y.useState)(!1),[T,E]=(0,y.useState)([]),[D,O]=(0,y.useState)(!1),[k,A]=(0,y.useState)(!1),[j,M]=(0,y.useState)(!1),[N,P]=(0,y.useState)([]),[F,I]=(0,y.useState)(null),[L,R]=(0,y.useState)(null),[z,B]=(0,y.useState)(null),[V,ee]=(0,y.useState)(null),[te,H]=(0,y.useState)(null),[ne,re]=(0,y.useState)(null),[U,ie]=(0,y.useState)({}),[ae,W]=(0,y.useState)(null),[oe,se]=(0,y.useState)(()=>localStorage.getItem(`library-view-mode`)||`grid`),[ce,le]=(0,y.useState)(()=>localStorage.getItem(`library-wrap-folders`)===`true`),[ue,de]=(0,y.useState)(()=>localStorage.getItem(`library-collapse-folders`)===`true`),[fe,pe]=(0,y.useState)(()=>localStorage.getItem(`library-folder-sort-field`)===`activity`?`activity`:`name`),[me,he]=(0,y.useState)(()=>localStorage.getItem(`library-folder-sort-direction`)===`desc`?`desc`:`asc`),[ge,_e]=(0,y.useState)(()=>{let e=localStorage.getItem(`library-sidebar-width`);return e?parseInt(e,10):256}),[ve,ye]=(0,y.useState)(!1),be=(0,y.useRef)(null);(0,y.useEffect)(()=>{if(!ve)return;document.body.style.userSelect=`none`,document.body.style.cursor=`col-resize`;let e=e=>{if(!be.current)return;let t=be.current.parentElement?.getBoundingClientRect();if(!t)return;let n=e.clientX-t.left;_e(Math.min(500,Math.max(200,n)))},t=()=>{ye(!1),document.body.style.userSelect=``,document.body.style.cursor=``,localStorage.setItem(`library-sidebar-width`,String(ge))};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=``}},[ve,ge]);let[xe,Se]=(0,y.useState)(``),[Ce,we]=(0,y.useState)(`all`),[Te,Ee]=(0,y.useState)(``),[De,Oe]=(0,y.useState)(()=>localStorage.getItem(`library-sort-field`)||`name`),[ke,Ae]=(0,y.useState)(()=>localStorage.getItem(`library-sort-direction`)||`asc`),[je,Me]=(0,y.useState)(()=>localStorage.getItem(`library-show-modified`)===`true`),Ne=zp();(0,y.useEffect)(()=>{let e=s.get(`folder`);e&&d(parseInt(e,10))},[s]);let{data:Pe}=q({queryKey:[`settings`],queryFn:()=>Q.getSettings()}),Fe=eG(Pe?.open_in_slicer,Pe?.preferred_slicer),Ie=(0,y.useCallback)(async t=>{try{let{token:e}=await Q.createLibrarySlicerToken(t.id),n=Q.getLibrarySlicerDownloadUrl(t.id,e,t.filename);rG(`${window.location.origin}${n}`,Fe)}catch{n(e(`fileManager.toast.openInSlicerFailed`),`error`);let r=Q.getLibraryFileDownloadUrl(t.id);rG(`${window.location.origin}${r}`,Fe)}},[Fe,n,e]),Le=(0,y.useCallback)(()=>Pe?.use_slicer_api?r(`library:upload`):i(`library:read_all`,`library:read_own`),[Pe?.use_slicer_api,r,i]),{data:Re,isLoading:ze}=q({queryKey:[`library-folders`],queryFn:()=>Q.getLibraryFolders()}),Be=(0,y.useMemo)(()=>{if(!Re)return Re;let e=t=>[...t].sort((e,t)=>{let n=0;if(fe===`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 me===`asc`?n:-n}).map(t=>({...t,children:e(t.children)}));return e(Re)},[Re,fe,me]),{data:Ve}=q({queryKey:[`library-trash-count`],queryFn:async()=>{try{return(await Q.listLibraryTrash(1,0)).total}catch{return 0}},staleTime:3e4}),He=u!==null&&xe.trim().length>0,Ue=(0,y.useMemo)(()=>[...N].sort((e,t)=>e-t),[N]),{data:We=[]}=q({queryKey:[`library-tags`],queryFn:Q.getLibraryTags}),Ge=(0,y.useMemo)(()=>{let e=new Map;for(let t of We)e.set(t.id,t.name);return e},[We]);(0,y.useEffect)(()=>{We.length!==0&&P(e=>{let t=e.filter(e=>Ge.has(e));return t.length===e.length?e:t})},[We.length,Ge]);let Ke=(0,y.useCallback)(e=>{P(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},[]),{data:qe,isLoading:Je}=q({queryKey:[`library-files`,u,f,He,Ue],queryFn:()=>Q.getLibraryFiles(u,!1,void 0,u===null?f:void 0,He,Ue)}),{data:Ye}=q({queryKey:[`library-stats`],queryFn:()=>Q.getLibraryStats()}),{data:Xe}=q({queryKey:[`users`],queryFn:()=>Q.getUsers()}),Ze=(0,y.useMemo)(()=>{if(!qe)return[];let e=new Set(qe.map(e=>e.file_type));return Array.from(e).sort()},[qe]),Qe=(0,y.useMemo)(()=>{if(!qe)return[];let e=[...qe];if(xe.trim()){let t=xe.toLowerCase();e=e.filter(e=>e.filename.toLowerCase().includes(t)||e.print_name&&e.print_name.toLowerCase().includes(t))}if(Ce!==`all`&&(e=e.filter(e=>e.file_type===Ce)),Te.trim()){let t=Te.toLowerCase();e=e.filter(e=>e.created_by_username&&e.created_by_username.toLowerCase().includes(t))}return e.sort((e,t)=>{let n=0;switch(De){case`name`:n=(e.print_name||e.filename).localeCompare(t.print_name||t.filename);break;case`date`:n=(Hf(e.fs_modified_at??e.created_at)?.getTime()??0)-(Hf(t.fs_modified_at??t.created_at)?.getTime()??0);break;case`size`:n=e.file_size-t.file_size;break;case`type`:n=e.file_type.localeCompare(t.file_type);break;case`prints`:n=e.print_count-t.print_count;break}return ke===`asc`?n:-n}),e},[qe,xe,Ce,Te,De,ke]),et=(0,y.useMemo)(()=>{if(!Ye||!Pe)return!1;let e=(Pe.library_disk_warning_gb||5)*1024*1024*1024;return Ye.disk_free_bytesQ.createLibraryFolder(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-folders`]}),_(!1),n(e(`fileManager.toast.folderCreated`),`success`)},onError:e=>n(e.message,`error`)}),nt=J({mutationFn:async e=>{let t=await Q.createExternalFolder(e);return await Q.scanExternalFolder(t.id),t},onSuccess:r=>{t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-stats`]}),b(!1),d(r.id),n(e(`fileManager.toast.externalFolderLinked`),`success`)},onError:e=>n(e.message,`error`)}),rt=J({mutationFn:e=>Q.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`)}),it=J({mutationFn:e=>Q.deleteLibraryFolder(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-stats`]}),u===L?.id&&d(null),R(null),n(e(`fileManager.toast.folderDeleted`),`success`)},onError:e=>{R(null),n(e.message,`error`)}}),at=J({mutationFn:e=>Q.deleteLibraryFile(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-stats`]}),t.invalidateQueries({queryKey:[`library-trash-count`]}),h(e=>e.filter(e=>e!==L?.id)),R(null),n(e(`fileManager.toast.fileDeleted`),`success`)},onError:e=>{R(null),n(e.message,`error`)}}),ot=J({mutationFn:e=>Q.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`),h([])},onError:e=>n(e.message,`error`)}),st=J({mutationFn:e=>Q.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`),h([]),R(null)},onError:e=>{R(null),n(e.message,`error`)}}),ct=J({mutationFn:({fileIds:e,folderId:t})=>Q.moveLibraryFiles(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-folders`]}),h([]),S(!1),n(e(`fileManager.toast.filesMoved`),`success`)},onError:e=>n(e.message,`error`)}),lt=J({mutationFn:({id:e,data:t})=>Q.updateLibraryFolder(e,t),onSuccess:(r,i)=>{t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`project-folders`]}),t.invalidateQueries({queryKey:[`archive-folders`]}),I(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`)}),ut=J({mutationFn:({id:e,filename:t})=>Q.updateLibraryFile(e,{filename:t}),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-files`]}),re(null),n(e(`fileManager.toast.fileRenamed`),`success`)},onError:e=>{re(null),n(e.message,`error`)}}),dt=J({mutationFn:({id:e,name:t})=>Q.updateLibraryFolder(e,{name:t}),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-files`]}),re(null),n(e(`fileManager.toast.folderRenamed`),`success`)},onError:e=>{re(null),n(e.message,`error`)}}),ft=J({mutationFn:()=>Q.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)}),ie(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`)}),pt=J({mutationFn:e=>Q.batchGenerateStlThumbnails({file_ids:[e]}),onSuccess:r=>{if(t.invalidateQueries({queryKey:[`library-files`]}),r.succeeded>0){let t=r.results[0]?.file_id;t&&ie(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`)}),mt=(0,y.useCallback)(e=>{let t=e.toLowerCase();return t.endsWith(`.gcode`)||t.includes(`.gcode.`)},[]),ht=(0,y.useMemo)(()=>qe?qe.filter(e=>m.includes(e.id)&&mt(e.filename)):[],[qe,m,mt]),{data:gt}=q({queryKey:[`variant-group`,z?.variant_group_id],queryFn:()=>Q.getVariantGroup(z.variant_group_id),enabled:!!z?.variant_group_id}),_t=(0,y.useMemo)(()=>{if(z){if(ht.length>1)return ht.map(e=>({id:e.id,filename:e.filename,sliced_for_model:e.sliced_for_model}));if(gt&>.members.length>1)return gt.members.map(e=>({id:e.library_file_id,filename:e.filename,sliced_for_model:e.target_model}))}},[z,ht,gt]),vt=(0,y.useCallback)(e=>{h(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},[]),yt=(0,y.useCallback)(()=>{Qe.length>0&&h(Qe.map(e=>e.id))},[Qe]),bt=(0,y.useCallback)(()=>{h([])},[]),xt=()=>{t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-stats`]})},{isDraggingOver:St,dragHandlers:Ct}=aG({disabled:!r(`library:upload`)||C,onFiles:e=>{E(e),w(!0)}}),wt=e=>{Q.downloadLibraryFile(e).catch(e=>{console.error(`Library file download failed:`,e)})},Tt=()=>{L&&(L.type===`file`?at.mutate(L.id):L.type===`folder`?it.mutate(L.id):L.type===`bulk`&&st.mutate(m))},Et=it.isPending||at.isPending||st.isPending,Dt=e=>{se(e),localStorage.setItem(`library-view-mode`,e)},Ot=ze||Je,kt=(0,y.useMemo)(()=>{if(!u||!Re)return null;let e=t=>{for(let n of t){if(n.id===u)return n;let t=e(n.children);if(t)return t}return null};return e(Re)},[u,Re]);return(0,K.jsxs)(`div`,{className:`p-4 md:p-8 min-h-[calc(100vh-64px)] lg:h-[calc(100vh-64px)] flex flex-col relative`,...Ct,children:[St&&(0,K.jsx)(`div`,{className:`fixed inset-0 z-50 bg-bambu-dark/90 flex items-center justify-center pointer-events-none`,children:(0,K.jsxs)(`div`,{className:`border-4 border-dashed border-bambu-green rounded-xl p-12 text-center`,children:[(0,K.jsx)(Pu,{className:`w-16 h-16 mx-auto mb-4 text-bambu-green`}),(0,K.jsx)(`p`,{className:`text-2xl font-semibold text-white mb-2`,children:e(`fileManager.dropFilesHere`)}),(0,K.jsx)(`p`,{className:`text-bambu-gray`,children:e(`fileManager.releaseToUpload`)})]})}),(0,K.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-4 mb-6`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,K.jsx)(fc,{className:`w-7 h-7 text-bambu-green`}),e(`fileManager.title`)]}),(0,K.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:e(`fileManager.subtitle`)})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center bg-bambu-dark rounded-lg p-1`,children:[(0,K.jsx)(`button`,{onClick:()=>Dt(`grid`),className:`p-1.5 rounded transition-colors ${oe===`grid`?`bg-bambu-dark-secondary text-white`:`text-bambu-gray hover:text-white`}`,title:e(`fileManager.gridView`),children:(0,K.jsx)(Uc,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>Dt(`list`),className:`p-1.5 rounded transition-colors ${oe===`list`?`bg-bambu-dark-secondary text-white`:`text-bambu-gray hover:text-white`}`,title:e(`fileManager.listView`),children:(0,K.jsx)(Yc,{className:`w-4 h-4`})})]}),(0,K.jsxs)($,{variant:`secondary`,onClick:()=>ft.mutate(),disabled:ft.isPending||!i(`library:update_own`,`library:update_all`),title:i(`library:update_own`,`library:update_all`)?e(`fileManager.generateThumbnailsForMissing`):e(`fileManager.noPermissionGenerateThumbnail`),children:[ft.isPending?(0,K.jsx)(X,{className:`w-4 h-4 mr-2 animate-spin`}):(0,K.jsx)(Ic,{className:`w-4 h-4 mr-2`}),e(`fileManager.generateThumbnails`)]}),(0,K.jsxs)($,{variant:`secondary`,onClick:()=>b(!0),disabled:!r(`library:upload`),title:r(`library:upload`)?e(`fileManager.linkExternalFolder`):e(`fileManager.noPermissionCreateFolder`),children:[(0,K.jsx)(mc,{className:`w-4 h-4 mr-2`}),e(`fileManager.linkExternal`)]}),(0,K.jsxs)($,{variant:`secondary`,onClick:()=>_(!0),disabled:!r(`library:upload`),title:r(`library:upload`)?void 0:e(`fileManager.noPermissionCreateFolder`),children:[(0,K.jsx)(pc,{className:`w-4 h-4 mr-2`}),e(`fileManager.newFolder`)]}),(0,K.jsxs)($,{variant:`secondary`,onClick:()=>A(!0),title:e(`fileManager.tags.manageTitle`),children:[(0,K.jsx)(yu,{className:`w-4 h-4 mr-2`}),e(`fileManager.tags.manage`)]}),r(`library:purge`)&&(0,K.jsxs)($,{variant:`secondary`,onClick:()=>O(!0),title:e(`libraryPurge.headerTooltip`),children:[(0,K.jsx)(Du,{className:`w-4 h-4 mr-2`}),e(`libraryPurge.headerButton`)]}),i(`library:delete_own`,`library:delete_all`)&&(0,K.jsxs)(Di,{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,K.jsx)(Du,{className:`w-4 h-4 mr-2`}),e(`libraryTrash.headerButton`),typeof Ve==`number`&&Ve>0&&(0,K.jsx)(`span`,{className:`ml-1.5 px-1.5 py-0.5 text-xs rounded-full bg-bambu-green/20 text-bambu-green`,children:Ve})]}),(0,K.jsxs)($,{onClick:()=>w(!0),disabled:!r(`library:upload`),title:r(`library:upload`)?void 0:e(`fileManager.noPermissionUpload`),children:[(0,K.jsx)(Pu,{className:`w-4 h-4 mr-2`}),e(`common.upload`)]})]})]}),et&&Ye&&Pe&&(0,K.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,K.jsx)(Au,{className:`w-5 h-5 text-amber-500 flex-shrink-0`}),(0,K.jsxs)(`div`,{className:`flex-1`,children:[(0,K.jsx)(`p`,{className:`text-sm text-amber-500 font-medium`,children:e(`fileManager.lowDiskSpaceWarning`)}),(0,K.jsx)(`p`,{className:`text-xs text-amber-500/80`,children:e(`fileManager.lowDiskSpaceDetails`,{free:Nd(Ye.disk_free_bytes),total:Nd(Ye.disk_total_bytes),threshold:Pe.library_disk_warning_gb})})]})]}),Ye&&(0,K.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,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,K.jsx)(sc,{className:`w-4 h-4 text-bambu-green`}),(0,K.jsxs)(`span`,{className:`text-bambu-gray`,children:[e(`fileManager.files`),`:`]}),(0,K.jsx)(`span`,{className:`text-white font-medium`,children:Ye.total_files})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,K.jsx)(fc,{className:`w-4 h-4 text-blue-600 dark:text-blue-400`}),(0,K.jsxs)(`span`,{className:`text-bambu-gray`,children:[e(`fileManager.folders`),`:`]}),(0,K.jsx)(`span`,{className:`text-white font-medium`,children:Ye.total_folders})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,K.jsx)(Oc,{className:`w-4 h-4 text-amber-600 dark:text-amber-400`}),(0,K.jsxs)(`span`,{className:`text-bambu-gray`,children:[e(`fileManager.size`),`:`]}),(0,K.jsx)(`span`,{className:`text-white font-medium`,children:Nd(Ye.total_size_bytes)})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm sm:ml-auto`,children:[(0,K.jsxs)(`span`,{className:`text-bambu-gray`,children:[e(`fileManager.free`),`:`]}),(0,K.jsx)(`span`,{className:`font-medium ${et?`text-amber-500`:`text-white`}`,children:Nd(Ye.disk_free_bytes)})]})]}),(0,K.jsxs)(`div`,{className:`flex-1 flex flex-col lg:flex-row gap-4 lg:gap-6 min-h-0`,children:[(0,K.jsx)(`div`,{className:`lg:hidden`,children:(0,K.jsxs)(`select`,{value:u===null?`__top:${f}`:String(u),onChange:e=>{let t=e.target.value;t.startsWith(`__top:`)?(d(null),p(t.slice(6))):d(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,K.jsxs)(`option`,{value:`__top:internal`,children:[`📁 `,e(`fileManager.allFiles`)]}),Re?.some(e=>e.is_external)&&(0,K.jsxs)(`option`,{value:`__top:external`,children:[`🔗 `,e(`fileManager.allExternal`)]}),Be&&(()=>{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(Be).map(e=>(0,K.jsxs)(`option`,{value:e.id,children:[`│ `.repeat(e.depth),`📂 `,e.name,` `,e.fileCount>0?`(${e.fileCount})`:``]},e.id))})()]})}),(0,K.jsxs)(`div`,{ref:be,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:`${ge}px`},children:[(0,K.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 ${ve?`bg-bambu-green`:`hover:bg-bambu-green/50`}`,onMouseDown:e=>{e.preventDefault(),ye(!0)},onDoubleClick:()=>{_e(256),localStorage.setItem(`library-sidebar-width`,`256`)},title:e(`fileManager.dragToResizeTooltip`),children:(0,K.jsxs)(`div`,{className:`flex flex-col gap-1 opacity-0 group-hover/resize:opacity-100 transition-opacity ${ve?`opacity-100`:``}`,children:[(0,K.jsx)(`div`,{className:`w-0.5 h-0.5 rounded-full bg-white/70`}),(0,K.jsx)(`div`,{className:`w-0.5 h-0.5 rounded-full bg-white/70`}),(0,K.jsx)(`div`,{className:`w-0.5 h-0.5 rounded-full bg-white/70`})]})}),(0,K.jsxs)(`div`,{className:`p-3 border-b border-bambu-dark-tertiary flex items-center justify-between`,children:[(0,K.jsx)(`h2`,{className:`text-sm font-medium text-white`,children:e(`fileManager.folders`)}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,K.jsxs)(`select`,{value:fe,onChange:e=>{let t=e.target.value===`activity`?`activity`:`name`;pe(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,K.jsx)(`option`,{value:`name`,children:e(`fileManager.folderSortByName`)}),(0,K.jsx)(`option`,{value:`activity`,children:e(`fileManager.folderSortByActivity`)})]}),(0,K.jsx)(`button`,{onClick:()=>{let e=me===`asc`?`desc`:`asc`;he(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(me===`asc`?`fileManager.ascending`:`fileManager.descending`),"aria-label":e(me===`asc`?`fileManager.ascending`:`fileManager.descending`),children:me===`asc`?(0,K.jsx)(Ro,{className:`w-3.5 h-3.5`}):(0,K.jsx)(Mo,{className:`w-3.5 h-3.5`})}),(0,K.jsx)(`button`,{onClick:()=>{let e=!ue;de(e),localStorage.setItem(`library-collapse-folders`,String(e))},className:`text-xs px-1.5 py-0.5 rounded transition-colors ${ue?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:text-white hover:bg-bambu-dark`}`,title:e(ue?`fileManager.expandFoldersByDefault`:`fileManager.collapseFoldersByDefault`),children:e(`fileManager.collapse`)}),(0,K.jsx)(`button`,{onClick:()=>{let e=!ce;le(e),localStorage.setItem(`library-wrap-folders`,String(e))},className:`text-xs px-1.5 py-0.5 rounded transition-colors ${ce?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:text-white hover:bg-bambu-dark`}`,title:e(ce?`fileManager.disableTextWrapping`:`fileManager.enableTextWrapping`),children:e(`fileManager.wrap`)})]})]}),(0,K.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-1.5 rounded cursor-pointer transition-colors ${u===null&&f===`internal`?`bg-bambu-green/20 text-bambu-green`:`hover:bg-bambu-dark text-white`}`,onClick:()=>{d(null),p(`internal`)},children:[(0,K.jsx)(nc,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{className:`text-sm`,children:e(`fileManager.allFiles`)})]}),Re?.some(e=>e.is_external)&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-1.5 rounded cursor-pointer transition-colors ${u===null&&f===`external`?`bg-bambu-green/20 text-bambu-green`:`hover:bg-bambu-dark text-white`}`,onClick:()=>{d(null),p(`external`)},children:[(0,K.jsx)(mc,{className:`w-4 h-4 text-purple-600 dark:text-purple-400`}),(0,K.jsx)(`span`,{className:`text-sm`,children:e(`fileManager.allExternal`)})]}),Be?.map(t=>(0,K.jsx)(MQe,{folder:t,selectedFolderId:u,onSelect:d,onDelete:e=>R({type:`folder`,id:e}),onLink:I,onRename:e=>re({type:`folder`,id:e.id,name:e.name}),wrapNames:ce,defaultExpanded:!ue,showModified:je,hasPermission:r,t:e},`${t.id}-${ue?`c`:`e`}`))]})]}),(0,K.jsxs)(`div`,{className:`flex-1 flex flex-col lg:flex-row min-w-0 min-h-0 gap-4 lg:gap-6`,children:[(0,K.jsxs)(`div`,{className:`flex-1 flex flex-col min-w-0 min-h-0`,children:[We.length>0&&(0,K.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,K.jsx)(`span`,{className:`text-xs text-bambu-gray font-medium shrink-0`,children:e(`fileManager.tags.filterLabel`)}),We.map(e=>{let t=N.includes(e.id);return(0,K.jsxs)(`button`,{type:`button`,onClick:()=>Ke(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,K.jsx)(yu,{className:`w-3 h-3`}),(0,K.jsx)(`span`,{children:e.name}),t&&(0,K.jsx)(Ju,{className:`w-3 h-3`})]},e.id)}),N.length>0&&(0,K.jsx)(`button`,{type:`button`,onClick:()=>P([]),className:`ml-auto text-xs text-bambu-gray hover:text-white shrink-0`,children:e(`fileManager.tags.clearAll`)})]}),kt?.is_external&&(0,K.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,K.jsx)(mc,{className:`w-5 h-5 text-purple-600 dark:text-purple-400 flex-shrink-0`}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-sm font-medium text-purple-700 dark:text-purple-300`,children:e(`fileManager.externalFolder`)}),kt.external_readonly&&(0,K.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,K.jsx)(Zc,{className:`w-3 h-3`}),e(`fileManager.readOnly`)]})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray truncate font-mono`,title:kt.external_path||``,children:kt.external_path})]}),(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:()=>u&&rt.mutate(u),disabled:rt.isPending,title:e(`fileManager.scanFolder`),children:[rt.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(Fl,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{className:`ml-1.5`,children:e(`fileManager.scanFolder`)})]})]}),qe&&qe.length>0&&(0,K.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,K.jsxs)(`div`,{className:`relative w-full sm:w-auto sm:flex-1 sm:max-w-xs`,children:[(0,K.jsx)(Gl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`input`,{type:`text`,placeholder:e(`fileManager.searchFiles`),value:xe,onChange:e=>Se(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`}),He&&(0,K.jsx)(`span`,{className:`absolute -bottom-4 left-0 text-[10px] text-bambu-gray whitespace-nowrap`,title:e(`fileManager.searchSubfoldersHint`),children:e(`fileManager.searchSubfoldersHint`)})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(vc,{className:`w-4 h-4 text-bambu-gray hidden sm:block`}),(0,K.jsxs)(`select`,{value:Ce,onChange:e=>we(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,K.jsx)(`option`,{value:`all`,children:e(`fileManager.allTypes`)}),Ze.map(e=>(0,K.jsx)(`option`,{value:e,children:e.toUpperCase()},e))]})]}),o&&(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(`input`,{type:`text`,placeholder:e(`fileManager.filterByUser`,{defaultValue:`Filter by user`}),value:Te,onChange:e=>Ee(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 ${Te?`pr-7`:``}`,style:Te?{WebkitAppearance:`none`,MozAppearance:`textfield`}:void 0}),Te&&(0,K.jsx)(`button`,{onClick:()=>Ee(``),className:`absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white z-10`,children:(0,K.jsx)(Ju,{className:`w-3 h-3`})}),(0,K.jsx)(`datalist`,{id:`usernames-list`,children:Xe?.map(e=>(0,K.jsx)(`option`,{value:e.username},e.id))})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)(`select`,{value:De,onChange:e=>{let t=e.target.value;Oe(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,K.jsx)(`option`,{value:`name`,children:e(`common.name`)}),(0,K.jsx)(`option`,{value:`date`,children:e(`common.date`)}),(0,K.jsx)(`option`,{value:`size`,children:e(`fileManager.size`)}),(0,K.jsx)(`option`,{value:`type`,children:e(`common.type`)}),(0,K.jsx)(`option`,{value:`prints`,children:e(`fileManager.prints`)})]}),(0,K.jsx)(`button`,{onClick:()=>Ae(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(ke===`asc`?`fileManager.ascending`:`fileManager.descending`),children:ke===`asc`?(0,K.jsx)(Ro,{className:`w-4 h-4 text-white`}):(0,K.jsx)(Mo,{className:`w-4 h-4 text-white`})}),(0,K.jsx)(`button`,{onClick:()=>Me(e=>{let t=!e;return localStorage.setItem(`library-show-modified`,String(t)),t}),className:`p-1.5 rounded bg-bambu-dark border transition-colors ${je?`border-bambu-green text-bambu-green`:`border-bambu-dark-tertiary text-white hover:border-bambu-green`}`,title:e(je?`fileManager.hideModified`:`fileManager.showModified`),"aria-pressed":je,children:(0,K.jsx)(Qo,{className:`w-4 h-4`})})]}),(xe||Ce!==`all`||Te)&&(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray hidden sm:inline`,children:e(`fileManager.resultsCount`,{showing:Qe.length,total:qe.length})})]}),Qe.length>0&&(0,K.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:[m.length===Qe.length&&m.length>0?(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:bt,children:[(0,K.jsx)(pu,{className:`w-4 h-4 sm:mr-1`}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:e(`fileManager.deselectAll`)})]}):(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:yt,children:[(0,K.jsx)(du,{className:`w-4 h-4 sm:mr-1`}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:e(`fileManager.selectAll`)})]}),m.length>0&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray ml-2`,children:e(`fileManager.selected`,{count:m.length})}),(0,K.jsx)(`div`,{className:`hidden sm:block flex-1`}),(0,K.jsxs)(`div`,{className:`w-full sm:w-auto flex flex-wrap items-center gap-2 mt-2 sm:mt-0`,children:[ht.length>=1&&(0,K.jsxs)($,{variant:`primary`,size:`sm`,onClick:()=>B(ht[0]),disabled:!r(`queue:create`),title:r(`queue:create`)?void 0:e(`fileManager.noPermissionAddToQueue`),children:[(0,K.jsx)(Ml,{className:`w-4 h-4 sm:mr-1`}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:ht.length>1?e(`fileManager.variants.printAlternatives`,{count:ht.length}):e(`common.print`)})]}),ht.length>=2&&!ht.some(e=>e.variant_group_id)&&(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:()=>ot.mutate(ht.map(e=>e.id)),disabled:ot.isPending||!i(`library:update_own`,`library:update_all`),title:e(`fileManager.variants.groupTooltip`),children:[(0,K.jsx)(Hc,{className:`w-4 h-4 sm:mr-1`}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:e(`fileManager.variants.groupAction`)})]}),(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:()=>S(!0),disabled:!i(`library:update_own`,`library:update_all`),title:i(`library:update_own`,`library:update_all`)?void 0:e(`fileManager.noPermissionMoveFiles`),children:[(0,K.jsx)(pl,{className:`w-4 h-4 sm:mr-1`}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.move`)})]}),(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:()=>M(!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,K.jsx)(yu,{className:`w-4 h-4 sm:mr-1`}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:e(`fileManager.tags.tagAction`)})]}),(0,K.jsxs)($,{variant:`danger`,size:`sm`,onClick:()=>{m.length===1?R({type:`file`,id:m[0]}):R({type:`bulk`,id:0,count:m.length})},disabled:!i(`library:delete_own`,`library:delete_all`),title:i(`library:delete_own`,`library:delete_all`)?void 0:e(`fileManager.noPermissionDeleteFiles`),children:[(0,K.jsx)(Du,{className:`w-4 h-4 sm:mr-1`}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.delete`)})]}),(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:bt,children:[(0,K.jsx)(Ju,{className:`w-4 h-4 sm:mr-1`}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.clear`)})]})]})]})]}),Ot?(0,K.jsx)(`div`,{className:`flex-1 flex items-center justify-center`,children:(0,K.jsxs)(`div`,{className:`flex flex-col items-center gap-3`,children:[(0,K.jsx)(X,{className:`w-8 h-8 animate-spin text-bambu-green`}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`fileManager.loadingFiles`)})]})}):qe?.length===0?(0,K.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center`,children:[(0,K.jsx)(`div`,{className:`p-4 bg-bambu-dark rounded-2xl mb-4`,children:(0,K.jsx)(nc,{className:`w-12 h-12 text-bambu-gray/50`})}),(0,K.jsx)(`h3`,{className:`text-lg font-medium text-white mb-2`,children:e(u===null?f===`external`?`fileManager.externalIsEmpty`:`fileManager.noFilesYet`:`fileManager.folderIsEmpty`)}),(0,K.jsx)(`p`,{className:`text-bambu-gray text-center max-w-md mb-6`,children:e(u===null?f===`external`?`fileManager.externalEmptyDescription`:`fileManager.noFilesDescription`:`fileManager.folderEmptyDescription`)}),(0,K.jsxs)($,{onClick:()=>w(!0),disabled:!r(`library:upload`),title:r(`library:upload`)?void 0:e(`fileManager.noPermissionUpload`),children:[(0,K.jsx)(kl,{className:`w-4 h-4 mr-2`}),e(`fileManager.uploadFiles`)]})]}):Qe.length===0?(0,K.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center`,children:[(0,K.jsx)(`div`,{className:`p-4 bg-bambu-dark rounded-2xl mb-4`,children:(0,K.jsx)(Gl,{className:`w-12 h-12 text-bambu-gray/50`})}),(0,K.jsx)(`h3`,{className:`text-lg font-medium text-white mb-2`,children:e(`fileManager.noMatchingFiles`)}),(0,K.jsx)(`p`,{className:`text-bambu-gray text-center max-w-md mb-6`,children:e(`fileManager.noMatchingFilesDescription`)}),(0,K.jsx)($,{variant:`secondary`,onClick:()=>{Se(``),we(`all`)},children:e(`fileManager.clearFilters`)})]}):oe===`grid`?(0,K.jsx)(`div`,{className:`flex-1 lg:overflow-y-auto`,children:(0,K.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:Qe.map(t=>(0,K.jsx)(NQe,{file:t,isSelected:m.includes(t.id),isMobile:Ne,t:e,onSelect:vt,onDelete:e=>R({type:`file`,id:e}),onDownload:wt,onPrint:B,onSlice:ee,onOpenInSlicer:Ie,onRunPipeline:H,useSlicerApi:Pe?.use_slicer_api??!1,canSlice:Le(),onPreview3d:e=>{l9(e.filename)?c(`/gcode-viewer?library_file=${e.id}`):W(e)},onRename:e=>re({type:`file`,id:e.id,name:e.filename}),onGenerateThumbnail:e=>pt.mutate(e.id),onTagClick:Ke,thumbnailVersion:U[t.id],hasPermission:r,canModify:a,authEnabled:o,showModified:je},t.id))})}):(0,K.jsx)(`div`,{className:`flex-1 lg:overflow-y-auto`,children:(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary overflow-x-auto`,children:[(0,K.jsxs)(`div`,{className:`hidden sm:grid ${o?`grid-cols-[auto_1fr_120px_100px_100px_100px_minmax(0,200px)_220px]`:`grid-cols-[auto_1fr_100px_100px_100px_minmax(0,200px)_220px]`} 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,K.jsx)(`div`,{className:`w-6`}),(0,K.jsx)(`div`,{children:e(`common.name`)}),o&&(0,K.jsx)(`div`,{children:e(`fileManager.uploadedBy`,{defaultValue:`Uploaded By`})}),(0,K.jsx)(`div`,{children:e(`common.type`)}),(0,K.jsx)(`div`,{children:e(`fileManager.size`)}),(0,K.jsx)(`div`,{children:e(`fileManager.prints`)}),(0,K.jsx)(`div`,{children:e(`fileManager.tags.title`)}),(0,K.jsx)(`div`,{})]}),Qe.map(t=>(0,K.jsxs)(`div`,{className:`grid ${o?`grid-cols-[auto_1fr_120px_100px_100px_100px_minmax(0,200px)_220px]`:`grid-cols-[auto_1fr_100px_100px_100px_minmax(0,200px)_220px]`} 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 ${m.includes(t.id)?`bg-bambu-green/10`:``}`,onClick:()=>vt(t.id),children:[(0,K.jsx)(`div`,{className:`w-5 h-5 rounded border-2 flex items-center justify-center ${m.includes(t.id)?`bg-bambu-green border-bambu-green`:`border-bambu-gray/50`}`,children:m.includes(t.id)&&(0,K.jsx)(`div`,{className:`w-2 h-2 bg-white rounded-sm`})}),(0,K.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0`,children:[(0,K.jsxs)(`div`,{className:`relative group/thumb`,children:[(0,K.jsx)(`div`,{className:`w-10 h-10 rounded bg-bambu-dark flex-shrink-0 overflow-hidden`,children:t.thumbnail_path?(0,K.jsx)(`img`,{src:`${Q.getLibraryFileThumbnailUrl(t.id)}${U[t.id]?(Q.getLibraryFileThumbnailUrl(t.id).includes(`?`)?`&`:`?`)+`v=${U[t.id]}`:``}`,alt:``,className:`w-full h-full object-cover`}):(0,K.jsx)(`div`,{className:`w-full h-full flex items-center justify-center`,children:(0,K.jsx)(nc,{className:`w-5 h-5 text-bambu-gray/50`})})}),t.thumbnail_path&&(0,K.jsx)(`div`,{className:`absolute left-0 top-full mt-2 z-50 hidden group-hover/thumb:block`,children:(0,K.jsx)(`div`,{className:`w-48 h-48 rounded-lg bg-bambu-dark-secondary border border-bambu-dark-tertiary shadow-xl overflow-hidden`,children:(0,K.jsx)(`img`,{src:`${Q.getLibraryFileThumbnailUrl(t.id)}${U[t.id]?(Q.getLibraryFileThumbnailUrl(t.id).includes(`?`)?`&`:`?`)+`v=${U[t.id]}`:``}`,alt:t.filename,className:`w-full h-full object-contain`})})})]}),(0,K.jsxs)(`div`,{className:`min-w-0`,children:[(0,K.jsx)(`div`,{className:`text-sm text-white truncate`,children:t.print_name||t.filename}),je&&(0,K.jsxs)(`div`,{className:`text-xs text-bambu-gray flex items-center gap-1 mt-0.5`,title:e(`fileManager.lastModified`),children:[(0,K.jsx)(Qo,{className:`w-3 h-3 flex-shrink-0`}),(0,K.jsx)(`span`,{className:`truncate`,children:Uf(t.fs_modified_at??t.created_at)})]})]})]}),o&&(0,K.jsx)(`div`,{className:`text-sm text-bambu-gray flex items-center gap-1`,children:t.created_by_username?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Fu,{className:`w-3 h-3`}),(0,K.jsx)(`span`,{className:`truncate`,children:t.created_by_username})]}):`-`}),(0,K.jsx)(`div`,{children:(0,K.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded font-medium ${t.file_type===`3mf`?`bg-bambu-green/20 text-bambu-green`:t.file_type===`gcode`||t.file_type===`gcode.3mf`?`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`:t.file_type===`stl`?`bg-purple-100 dark:bg-purple-500/20 text-purple-700 dark:text-purple-400`:`bg-bambu-gray/20 text-bambu-gray`}`,children:t.file_type.toUpperCase()})}),(0,K.jsx)(`div`,{className:`text-sm text-bambu-gray`,children:Nd(t.file_size)}),(0,K.jsx)(`div`,{className:`text-sm text-bambu-gray`,children:t.print_count>0?`${t.print_count}x`:`-`}),(0,K.jsx)(`div`,{className:`min-w-0`,onClick:e=>e.stopPropagation(),children:!t.tags||t.tags.length===0?(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray/50`,children:`-`}):(0,K.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:t.tags.map(e=>(0,K.jsxs)(`button`,{type:`button`,onClick:()=>Ke(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,K.jsx)(yu,{className:`w-2.5 h-2.5 flex-shrink-0`}),(0,K.jsx)(`span`,{className:`truncate`,children:e.name})]},e.id))})}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1`,onClick:e=>e.stopPropagation(),children:[l9(t.filename)&&(0,K.jsx)(K.Fragment,{children:(0,K.jsx)(`button`,{onClick:()=>r(`queue:create`)&&B(t),className:`p-1.5 rounded transition-colors ${r(`queue:create`)?`hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green`:`text-bambu-gray/50 cursor-not-allowed`}`,title:r(`queue:create`)?e(`common.print`):e(`fileManager.noPermissionAddToQueue`),disabled:!r(`queue:create`),children:(0,K.jsx)(Ml,{className:`w-4 h-4`})})}),nG(t.filename)&&(0,K.jsx)(`button`,{onClick:()=>{Le()&&(Pe?.use_slicer_api?ee:Ie)(t)},className:`p-1.5 rounded transition-colors ${Le()?`hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green`:`text-bambu-gray/50 cursor-not-allowed`}`,title:Le()?e(`slice.action`):Pe?.use_slicer_api?e(`fileManager.noPermissionSlice`):e(`fileManager.noPermissionDownload`),disabled:!Le(),children:Pe?.use_slicer_api?(0,K.jsx)(Ns,{className:`w-4 h-4`}):(0,K.jsx)(Qs,{className:`w-4 h-4`})}),(Pe?.use_slicer_api??!1)&&nG(t.filename)&&(0,K.jsx)(`button`,{onClick:()=>r(`pipelines:run`)&&H(t),className:`p-1.5 rounded transition-colors ${r(`pipelines:run`)?`hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green`:`text-bambu-gray/50 cursor-not-allowed`}`,title:r(`pipelines:run`)?e(`library.runWithPipeline.actionLabel`,`Run with pipeline`):e(`library.runWithPipeline.noPermission`,`You do not have permission to run pipelines`),disabled:!r(`pipelines:run`),children:(0,K.jsx)(Dl,{className:`w-4 h-4`})}),(t.file_type===`3mf`||t.file_type===`gcode`||t.file_type===`gcode.3mf`||t.file_type===`stl`)&&(0,K.jsx)(`button`,{onClick:()=>{r(`library:read`)&&(l9(t.filename)?c(`/gcode-viewer?library_file=${t.id}`):W(t))},className:`p-1.5 rounded transition-colors ${r(`library:read`)?`hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green`:`text-bambu-gray/50 cursor-not-allowed`}`,title:r(`library:read`)?`3D Preview`:`You do not have permission to preview files`,disabled:!r(`library:read`),children:(0,K.jsx)(qo,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>r(`library:read`)&&wt(t.id),className:`p-1.5 rounded transition-colors ${r(`library:read`)?`hover:bg-bambu-dark text-bambu-gray hover:text-white`:`text-bambu-gray/50 cursor-not-allowed`}`,title:r(`library:read`)?e(`common.download`):e(`fileManager.noPermissionDownload`),disabled:!r(`library:read`),children:(0,K.jsx)(Gs,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>a(`library`,`update`,t.created_by_id)&&re({type:`file`,id:t.id,name:t.filename}),className:`p-1.5 rounded transition-colors ${a(`library`,`update`,t.created_by_id)?`hover:bg-bambu-dark text-bambu-gray hover:text-white`:`text-bambu-gray/50 cursor-not-allowed`}`,title:a(`library`,`update`,t.created_by_id)?e(`common.rename`):e(`fileManager.noPermissionRenameFile`),disabled:!a(`library`,`update`,t.created_by_id),children:(0,K.jsx)(Tl,{className:`w-4 h-4`})}),t.file_type===`stl`&&(0,K.jsx)(`button`,{onClick:()=>a(`library`,`update`,t.created_by_id)&&pt.mutate(t.id),className:`p-1.5 rounded transition-colors ${a(`library`,`update`,t.created_by_id)?`hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green`:`text-bambu-gray/50 cursor-not-allowed`}`,title:a(`library`,`update`,t.created_by_id)?e(`fileManager.generateThumbnail`):e(`fileManager.noPermissionGenerateThumbnail`),disabled:pt.isPending||!a(`library`,`update`,t.created_by_id),children:(0,K.jsx)(Ic,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>a(`library`,`delete`,t.created_by_id)&&R({type:`file`,id:t.id}),className:`p-1.5 rounded transition-colors ${a(`library`,`delete`,t.created_by_id)?`hover:bg-bambu-dark text-bambu-gray hover:text-red-700 dark:hover:text-red-400`:`text-bambu-gray/50 cursor-not-allowed`}`,title:a(`library`,`delete`,t.created_by_id)?e(`common.delete`):e(`fileManager.noPermissionDeleteFile`),disabled:!a(`library`,`delete`,t.created_by_id),children:(0,K.jsx)(Du,{className:`w-4 h-4`})})]})]},t.id))]})})]}),u!==null&&(0,K.jsx)(xQe,{folderId:u})]})]}),g&&(0,K.jsx)(TQe,{parentId:u,onClose:()=>_(!1),onSave:e=>tt.mutate(e),isLoading:tt.isPending,t:e}),v&&(0,K.jsx)(EQe,{onClose:()=>b(!1),onSave:e=>nt.mutate(e),isLoading:nt.isPending,t:e}),x&&Re&&(0,K.jsx)(AQe,{folders:Re,selectedFiles:m,currentFolderId:u,onClose:()=>S(!1),onMove:e=>ct.mutate({fileIds:m,folderId:e}),isLoading:ct.isPending,t:e}),C&&(0,K.jsx)(QU,{folderId:u,onClose:()=>{w(!1),E([])},onUploadComplete:xt,initialFiles:T.length>0?T:void 0}),D&&(0,K.jsx)(wQe,{onClose:()=>O(!1)}),(0,K.jsx)(SQe,{open:k,onClose:()=>A(!1),onPickTag:e=>{N.includes(e)||P(t=>[...t,e])}}),(0,K.jsx)(bGe,{open:j,fileIds:m,onClose:()=>M(!1)}),F&&(0,K.jsx)(jQe,{folder:F,onClose:()=>I(null),onLink:e=>lt.mutate({id:F.id,data:e}),isLoading:lt.isPending,t:e}),L&&(0,K.jsx)(qd,{title:L.type===`folder`?e(`fileManager.deleteFolder`):L.type===`bulk`?e(`fileManager.deleteFilesCount`,{count:L.count}):e(`fileManager.deleteFile`),message:L.type===`folder`?e(`fileManager.deleteFolderConfirm`):L.type===`bulk`?e(`fileManager.deleteFilesConfirm`,{count:L.count}):e(`fileManager.deleteFileConfirm`),confirmText:e(`common.delete`),variant:`danger`,isLoading:Et,loadingText:e(`fileManager.deleting`),onConfirm:Tt,onCancel:()=>R(null)}),z&&(!z.variant_group_id||gt!==void 0)&&(0,K.jsx)(gW,{mode:`create`,libraryFileId:_t?.[0]?.id??z.id,variantFiles:_t,archiveName:_t&&_t.length>1?`${_t[0].filename} ${e(`common.plusNMore`,{count:_t.length-1})}`:z.print_name||z.filename,onClose:()=>B(null),onSuccess:()=>{B(null),h([]),t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`queue`]}),t.invalidateQueries({queryKey:[`archives`]})}}),V&&(0,K.jsx)(XW,{source:{kind:`libraryFile`,id:V.id,filename:V.filename},onClose:()=>ee(null)}),te&&(0,K.jsx)($W,{source:{kind:`libraryFile`,id:te.id,filename:te.filename},onClose:()=>H(null)}),ae&&(0,K.jsx)(yGe,{libraryFileId:ae.id,title:ae.print_name||ae.filename,fileType:ae.file_type,onClose:()=>W(null),onSliceWithBambuddy:nG(ae.filename)&&r(`library:upload`)?()=>{let e=ae;W(null),ee(e)}:void 0}),ne&&(0,K.jsx)(kQe,{type:ne.type,currentName:ne.name,onClose:()=>re(null),onSave:e=>{ne.type===`file`?ut.mutate({id:ne.id,filename:e}):dt.mutate({id:ne.id,name:e})},isLoading:ut.isPending||dt.isPending,t:e})]})}function FQe(e){let t=Hf(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 IQe(e){let t=Hf(e);return t?t.toLocaleString():e}function LQe(){let{t:e}=$e(),t=ir(),n=ao(),{showToast:r}=Fd(),{hasPermission:i,authEnabled:a}=xd(),[o,s]=(0,y.useState)(null),[c,l]=(0,y.useState)(new Set),u=!a||i(`library:purge`),d=q({queryKey:[`library-trash`],queryFn:()=>Q.listLibraryTrash(200,0)}),f=q({queryKey:[`library-trash-settings`],queryFn:()=>Q.getLibraryTrashSettings(),enabled:u}),[p,m]=(0,y.useState)(null);(0,y.useEffect)(()=>{f.data&&p===null&&m(f.data.retention_days)},[f.data,p]);let h=J({mutationFn:e=>{let t=f.data;return Q.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=>{r(e(`libraryTrash.toast.retentionSaved`,{days:t.retention_days}),`success`),n.invalidateQueries({queryKey:[`library-trash-settings`]}),n.invalidateQueries({queryKey:[`library-trash`]})},onError:t=>r(t.message||e(`libraryTrash.toast.retentionFailed`),`error`)}),g=J({mutationFn:e=>Q.restoreLibraryTrash(e),onSuccess:()=>{r(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=>r(t.message||e(`libraryTrash.toast.restoreFailed`),`error`)}),_=J({mutationFn:e=>Q.hardDeleteLibraryTrash(e),onSuccess:()=>{r(e(`libraryTrash.toast.purged`),`success`),n.invalidateQueries({queryKey:[`library-trash`]}),n.invalidateQueries({queryKey:[`library-trash-count`]})},onError:t=>r(t.message||e(`libraryTrash.toast.purgeFailed`),`error`)}),v=J({mutationFn:()=>Q.emptyLibraryTrash(),onSuccess:t=>{r(e(`libraryTrash.toast.emptied`,{count:t.deleted}),`success`),n.invalidateQueries({queryKey:[`library-trash`]}),n.invalidateQueries({queryKey:[`library-trash-count`]})},onError:t=>r(t.message||e(`libraryTrash.toast.emptyFailed`),`error`)}),b=J({mutationFn:e=>Promise.all(e.map(e=>Q.restoreLibraryTrash(e))),onSuccess:(t,i)=>{r(e(`libraryTrash.toast.bulkRestored`,{count:i.length}),`success`),l(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=>r(t.message||e(`libraryTrash.toast.restoreFailed`),`error`)}),x=J({mutationFn:e=>Promise.all(e.map(e=>Q.hardDeleteLibraryTrash(e))),onSuccess:(t,i)=>{r(e(`libraryTrash.toast.bulkPurged`,{count:i.length}),`success`),l(new Set),n.invalidateQueries({queryKey:[`library-trash`]}),n.invalidateQueries({queryKey:[`library-trash-count`]})},onError:t=>r(t.message||e(`libraryTrash.toast.purgeFailed`),`error`)}),S=(0,y.useMemo)(()=>d.data?.items??[],[d.data?.items]),C=d.data?.retention_days??30,w=(0,y.useMemo)(()=>S.reduce((e,t)=>e+t.file_size,0),[S]),T=S.length>0&&S.every(e=>c.has(e.id)),E=c.size>0&&!T,D=e=>{l(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};return(0,K.jsxs)(`div`,{className:`p-6 max-w-screen-2xl mx-auto`,children:[(0,K.jsx)(`div`,{className:`flex items-center gap-3 mb-4`,children:(0,K.jsxs)(Di,{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,K.jsx)(Po,{className:`w-4 h-4`}),` `,e(`libraryTrash.backToFiles`)]})}),(0,K.jsxs)(`div`,{className:`flex items-start justify-between mb-6 gap-4 flex-wrap`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h1`,{className:`text-2xl font-bold text-gray-900 dark:text-gray-100`,children:e(`libraryTrash.title`)}),(0,K.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400 mt-1`,children:e(u?`libraryTrash.subtitleAdmin`:`libraryTrash.subtitleUser`,{days:C})})]}),S.length>0&&(0,K.jsxs)($,{variant:`secondary`,onClick:()=>s({type:`empty`}),className:`text-red-600 dark:text-red-400`,children:[(0,K.jsx)(Du,{className:`w-4 h-4 mr-1`}),e(`libraryTrash.emptyTrash`)]})]}),u&&f.data&&(0,K.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,K.jsx)(`label`,{htmlFor:`retention-days`,className:`text-sm font-medium text-gray-700 dark:text-gray-300`,children:e(`libraryTrash.retentionLabel`)}),(0,K.jsx)(`input`,{id:`retention-days`,type:`number`,min:1,max:365,value:p??f.data.retention_days,onChange:e=>m(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,K.jsx)(`span`,{className:`text-sm text-gray-600 dark:text-gray-400`,children:e(`libraryTrash.days`)}),(0,K.jsxs)($,{variant:`secondary`,onClick:()=>p!=null&&h.mutate(p),disabled:h.isPending||p==null||p===f.data.retention_days,className:`ml-auto`,children:[(0,K.jsx)(Bl,{className:`w-4 h-4 mr-1`}),e(`common.save`)]})]}),d.isLoading?(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-gray-500 dark:text-gray-400`,children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),` `,e(`libraryTrash.loading`)]}):S.length===0?(0,K.jsx)(`div`,{className:`border border-dashed border-gray-300 dark:border-gray-700 rounded-lg p-12 text-center`,children:(0,K.jsx)(`p`,{className:`text-gray-500 dark:text-gray-400`,children:e(`libraryTrash.empty`)})}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,K.jsx)(`div`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:e(`libraryTrash.summary`,{count:S.length,size:Nd(w)})}),c.size>0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,K.jsx)(`span`,{className:`text-gray-600 dark:text-gray-400`,children:e(`libraryTrash.selectionCount`,{count:c.size})}),(0,K.jsxs)($,{variant:`secondary`,onClick:()=>b.mutate(Array.from(c)),disabled:b.isPending,children:[(0,K.jsx)(Ll,{className:`w-4 h-4 mr-1`}),e(`libraryTrash.bulkRestore`)]}),(0,K.jsxs)($,{variant:`secondary`,onClick:()=>s({type:`bulkDelete`,count:c.size}),disabled:x.isPending,className:`text-red-600 dark:text-red-400`,children:[(0,K.jsx)(Du,{className:`w-4 h-4 mr-1`}),e(`libraryTrash.bulkPurge`)]})]})]}),(0,K.jsx)(`div`,{className:`border border-gray-200 dark:border-gray-700 rounded-lg overflow-x-auto`,children:(0,K.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,K.jsx)(`thead`,{className:`bg-gray-50 dark:bg-gray-800 text-left text-gray-600 dark:text-gray-300`,children:(0,K.jsxs)(`tr`,{children:[(0,K.jsx)(`th`,{className:`px-3 py-2 w-10`,children:(0,K.jsx)(`input`,{type:`checkbox`,checked:T,ref:e=>{e&&(e.indeterminate=E)},onChange:()=>{l(e=>e.size===S.length?new Set:new Set(S.map(e=>e.id)))},"aria-label":e(`libraryTrash.selectAll`),className:`rounded border-gray-300 cursor-pointer`})}),(0,K.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:e(`libraryTrash.col.filename`)}),(0,K.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:e(`libraryTrash.col.folder`)}),(0,K.jsx)(`th`,{className:`px-3 py-2 font-medium text-right`,children:e(`libraryTrash.col.size`)}),(0,K.jsx)(`th`,{className:`px-3 py-2 font-medium whitespace-nowrap`,children:e(`libraryTrash.col.deleted`)}),(0,K.jsx)(`th`,{className:`px-3 py-2 font-medium whitespace-nowrap`,children:e(`libraryTrash.col.autoPurge`)}),u&&(0,K.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:e(`libraryTrash.col.owner`)}),(0,K.jsx)(`th`,{className:`px-3 py-2 font-medium text-right`,children:e(`libraryTrash.col.actions`)})]})}),(0,K.jsx)(`tbody`,{className:`divide-y divide-gray-100 dark:divide-gray-800`,children:S.map(t=>(0,K.jsxs)(`tr`,{className:`hover:bg-gray-50 dark:hover:bg-gray-800/50`,children:[(0,K.jsx)(`td`,{className:`px-3 py-2`,children:(0,K.jsx)(`input`,{type:`checkbox`,checked:c.has(t.id),onChange:()=>D(t.id),"aria-label":e(`libraryTrash.selectOne`,{filename:t.filename}),className:`rounded border-gray-300 cursor-pointer`})}),(0,K.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,K.jsx)(`td`,{className:`px-3 py-2 text-gray-600 dark:text-gray-400`,children:t.folder_name??`—`}),(0,K.jsx)(`td`,{className:`px-3 py-2 text-right text-gray-600 dark:text-gray-400 tabular-nums whitespace-nowrap`,children:Nd(t.file_size)}),(0,K.jsx)(`td`,{className:`px-3 py-2 text-gray-600 dark:text-gray-400 whitespace-nowrap`,children:IQe(t.deleted_at)}),(0,K.jsx)(`td`,{className:`px-3 py-2 text-gray-600 dark:text-gray-400 whitespace-nowrap`,children:(0,K.jsx)(`span`,{title:IQe(t.auto_purge_at),children:e(`libraryTrash.autoPurgeIn`,{when:FQe(t.auto_purge_at)})})}),u&&(0,K.jsx)(`td`,{className:`px-3 py-2 text-gray-600 dark:text-gray-400`,children:t.created_by_username??`—`}),(0,K.jsxs)(`td`,{className:`px-3 py-2 text-right whitespace-nowrap`,children:[(0,K.jsxs)(`button`,{onClick:()=>g.mutate(t.id),disabled:g.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,K.jsx)(Ll,{className:`w-3.5 h-3.5`}),e(`libraryTrash.restore`)]}),(0,K.jsxs)(`button`,{onClick:()=>s({type:`delete`,id:t.id,filename:t.filename}),disabled:_.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,K.jsx)(Du,{className:`w-3.5 h-3.5`}),e(`libraryTrash.purgeNow`)]})]})]},t.id))})]})})]}),o&&(0,K.jsx)(qd,{onCancel:()=>s(null),onConfirm:()=>{o&&(o.type===`delete`?_.mutate(o.id):o.type===`bulkDelete`?x.mutate(Array.from(c)):v.mutate(),s(null))},title:o.type===`delete`?e(`libraryTrash.confirm.purgeTitle`):o.type===`bulkDelete`?e(`libraryTrash.confirm.bulkPurgeTitle`):e(`libraryTrash.confirm.emptyTitle`),message:o.type===`delete`?e(`libraryTrash.confirm.purgeBody`,{filename:o.filename}):o.type===`bulkDelete`?e(`libraryTrash.confirm.bulkPurgeBody`,{count:o.count}):e(`libraryTrash.confirm.emptyBody`,{count:S.length}),confirmText:e(`libraryTrash.confirm.cta`),variant:`danger`}),d.isError&&(0,K.jsxs)(`div`,{className:`mt-4 text-sm text-red-600 dark:text-red-400`,children:[d.error?.message??e(`libraryTrash.loadError`),(0,K.jsx)($,{variant:`secondary`,onClick:()=>t(`/files`),className:`ml-3`,children:e(`libraryTrash.backToFiles`)})]})]})}function RQe(e,t){let n=`token=${encodeURIComponent(t)}`,r=0;return e.querySelectorAll(`img[src*="/api/v1/"], video[src*="/api/v1/"]`).forEach(e=>{let t=e.getAttribute(`src`)||``;if(t.includes(n))return;let i=t.replace(/([?&])token=[^&]*(&|$)/,(e,t,n)=>n===`&`?t:``);e.src=`${i}${i.includes(`?`)?`&`:`?`}${n}`,r+=1}),r}function zQe(){let{authEnabled:e,user:t,loading:n}=xd(),r=ao(),i=(0,y.useRef)(!1),{data:a}=q({queryKey:[`camera-stream-token`,t?.id??null],queryFn:()=>Q.getCameraStreamToken(),enabled:!n&&(!e||t!==null),staleTime:3e3*1e3,refetchInterval:3e3*1e3});(0,y.useEffect)(()=>{let e=a?.token??null;return id(e),e&&RQe(document,e),()=>id(null)},[a?.token]),(0,y.useEffect)(()=>{if(!e)return;let t=e=>{let t=e.target;if(!(t instanceof HTMLImageElement||t instanceof HTMLVideoElement))return;let n=t.src||``,a=ad();!a||!n.includes(`token=${encodeURIComponent(a)}`)||i.current||(i.current=!0,r.invalidateQueries({queryKey:[`camera-stream-token`]}),setTimeout(()=>{i.current=!1},5e3))};return document.addEventListener(`error`,t,!0),()=>document.removeEventListener(`error`,t,!0)},[e,r])}var u9=5,BQe=2e3,VQe=3e4,HQe=5e3;function UQe(){let{t:e}=$e(),t=ao(),{showToast:n}=Fd(),{hasPermission:r,authEnabled:i,user:a}=xd(),{printerId:o}=lr(),s=parseInt(o||`0`,10),[c]=Fi(),l=parseInt(c.get(`fps`)||`15`,10),u=Math.min(Math.max(isNaN(l)?15:l,1),30);zQe();let{data:d,isPending:f}=q({queryKey:[`camera-stream-token`,a?.id??null],queryFn:()=>Q.getCameraStreamToken(),enabled:i?!!a:!0,staleTime:3e3*1e3}),p=d?.token??ad(),[m,h]=(0,y.useState)(`stream`),[g,_]=(0,y.useState)(!1),[v,b]=(0,y.useState)(!1),[x,S]=(0,y.useState)(!1),[C,w]=(0,y.useState)(!0),[T,E]=(0,y.useState)(Date.now()),[D,O]=(0,y.useState)(!1),[k,A]=(0,y.useState)(!1),[j,M]=(0,y.useState)(0),[N,P]=(0,y.useState)(!1),[F,I]=(0,y.useState)(0),[L,R]=(0,y.useState)(1),[z,B]=(0,y.useState)({x:0,y:0}),[V,ee]=(0,y.useState)(!1),[te,H]=(0,y.useState)({x:0,y:0}),[ne,re]=(0,y.useState)(null),[U,ie]=(0,y.useState)(null),ae=(0,y.useRef)(null),W=(0,y.useRef)(null),oe=(0,y.useRef)(null),se=(0,y.useRef)(null),ce=(0,y.useRef)(null),le=(0,y.useRef)(0),{data:ue}=q({queryKey:[`printer`,s],queryFn:()=>Q.getPrinter(s),enabled:s>0}),{data:de}=q({queryKey:[`printerStatus`,s],queryFn:()=>Q.getPrinterStatus(s),refetchInterval:3e4,enabled:s>0}),fe=J({mutationFn:e=>Q.setChamberLight(s,e),onMutate:async e=>{await t.cancelQueries({queryKey:[`printerStatus`,s]});let n=t.getQueryData([`printerStatus`,s]);return t.setQueryData([`printerStatus`,s],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`,s],a.previousStatus),n(r.message||e(`printers.toast.failedToControlChamberLight`),`error`)}}),pe=(de?.state===`RUNNING`||de?.state===`PAUSE`)&&(de?.printable_objects_count??0)>=2;(0,y.useEffect)(()=>(ue&&(document.title=`${ue.name} - Camera`),()=>{document.title=`Bambuddy`}),[ue]);let me=(0,y.useRef)(!1);(0,y.useEffect)(()=>{let e=`/api/v1/printers/${s}/camera/stop`;me.current=!1;let t=()=>{if(s>0&&!me.current){me.current=!0;let t={},n=nd();n&&(t.Authorization=`Bearer ${n}`),fetch(e,{method:`POST`,keepalive:!0,headers:t}).catch(()=>{})}},n=()=>{t()};window.addEventListener(`beforeunload`,n);let r=ae.current;return()=>{window.removeEventListener(`beforeunload`,n),r&&(r.src=``),t()}},[s]),(0,y.useEffect)(()=>{if(C&&!D){let e=setTimeout(()=>{w(!1)},m===`stream`?3e3:2e4);return()=>clearTimeout(e)}},[m,C,T,D]),(0,y.useEffect)(()=>{let e=()=>{A(!!document.fullscreenElement),R(1),B({x:0,y:0}),m===`stream`&&!D&&(ae.current&&(ae.current.src=``),setTimeout(()=>{w(!0),E(Date.now())},200))};return document.addEventListener(`fullscreenchange`,e),()=>document.removeEventListener(`fullscreenchange`,e)},[m,D]),(0,y.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,y.useEffect)(()=>()=>{oe.current&&clearTimeout(oe.current),se.current&&clearInterval(se.current),ce.current&&clearInterval(ce.current)},[]);let he=(0,y.useCallback)(()=>{if(j>=u9){P(!1),S(!0);return}let e=Math.min(BQe*2**j,VQe);P(!0),I(Math.ceil(e/1e3)),se.current=setInterval(()=>{I(e=>e<=1?(se.current&&clearInterval(se.current),0):e-1)},1e3),oe.current=setTimeout(()=>{M(e=>e+1),P(!1),w(!0),S(!1),ae.current&&(ae.current.src=``),E(Date.now())},e)},[j]);(0,y.useEffect)(()=>{if(m!==`stream`||C||N||D){ce.current&&=(clearInterval(ce.current),null);return}return le.current=0,ce.current=setInterval(async()=>{try{let e=await Q.getCameraStatus(s);if(!(e.stalled||!e.active&&!x)){le.current=0;return}if(le.current+=1,le.current<2)return;le.current=0,console.log(`Stream issue detected: stalled=${e.stalled}, active=${e.active}, reconnecting...`),ce.current&&=(clearInterval(ce.current),null),w(!1),he()}catch{}},HQe),()=>{ce.current&&=(clearInterval(ce.current),null)}},[m,C,x,N,D,s,he]);let ge=()=>{w(!1),m===`stream`&&j{if(w(!1),S(!1),M(0),le.current=0,P(!1),oe.current&&clearTimeout(oe.current),se.current&&clearInterval(se.current),ae.current&&!localStorage.getItem(`cameraWindowState`)){let e=ae.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{}}}},ve=()=>{if(s>0){let e={},t=nd();t&&(e.Authorization=`Bearer ${t}`),fetch(`/api/v1/printers/${s}/camera/stop`,{method:`POST`,headers:e}).catch(()=>{})}},ye=e=>{m===e||D||(O(!0),w(!0),S(!1),M(0),P(!1),R(1),B({x:0,y:0}),oe.current&&clearTimeout(oe.current),se.current&&clearInterval(se.current),ae.current&&(ae.current.src=``),m===`stream`&&ve(),setTimeout(()=>{h(e),E(Date.now()),O(!1)},100))},be=()=>{D||(O(!0),w(!0),S(!1),M(0),P(!1),oe.current&&clearTimeout(oe.current),se.current&&clearInterval(se.current),ae.current&&(ae.current.src=``),m===`stream`&&ve(),setTimeout(()=>{E(Date.now()),O(!1)},100))},xe=()=>{W.current&&(document.fullscreenElement?document.exitFullscreen():W.current.requestFullscreen())},Se=()=>{R(e=>Math.min(e+.5,4))},Ce=()=>{R(e=>{let t=Math.max(e-.5,1);return t===1&&B({x:0,y:0}),t})},we=e=>{e.preventDefault(),e.deltaY<0?Se():Ce()},Te=e=>{L>1&&(e.preventDefault(),ee(!0),H({x:e.clientX-z.x,y:e.clientY-z.y}))},Ee=(0,y.useCallback)(()=>{if(!W.current)return{x:300,y:200};let e=W.current.getBoundingClientRect(),t=e.width*(L-1)/2,n=e.height*(L-1)/2;return{x:Math.max(50,t),y:Math.max(50,n)}},[L]),De=e=>{if(V&&L>1){let t=e.clientX-te.x,n=e.clientY-te.y,r=Ee();B({x:Math.max(-r.x,Math.min(r.x,t)),y:Math.max(-r.y,Math.min(r.y,n))})}},Oe=()=>{ee(!1)},ke=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)},Ae=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},je=e=>{e.touches.length===2?(e.preventDefault(),re(ke(e.touches)),ie(Ae(e.touches))):e.touches.length===1&&L>1&&(e.preventDefault(),ee(!0),H({x:e.touches[0].clientX-z.x,y:e.touches[0].clientY-z.y}))},Me=e=>{if(e.touches.length===2&&ne!==null){e.preventDefault();let t=ke(e.touches),n=t/ne;R(e=>{let t=Math.max(1,Math.min(4,e*n));return t===1&&B({x:0,y:0}),t}),re(t);let r=Ae(e.touches);if(U){let e=Ee();B(t=>({x:Math.max(-e.x,Math.min(e.x,t.x+(r.x-U.x))),y:Math.max(-e.y,Math.min(e.y,t.y+(r.y-U.y)))}))}ie(r)}else if(e.touches.length===1&&V&&L>1){e.preventDefault();let t=e.touches[0].clientX-te.x,n=e.touches[0].clientY-te.y,r=Ee();B({x:Math.max(-r.x,Math.min(r.x,t)),y:Math.max(-r.y,Math.min(r.y,n))})}},Ne=e=>{e.touches.length<2&&(re(null),ie(null)),e.touches.length===0&&ee(!1)},Pe=()=>{R(1),B({x:0,y:0})},Fe=D||!p&&(i||f)?``:(e=>p?`${e}&token=${encodeURIComponent(p)}`:od(e))(m===`stream`?`/api/v1/printers/${s}/camera/stream?fps=${u}&t=${T}`:`/api/v1/printers/${s}/camera/snapshot?t=${T}`),Ie=C||D||N;return s?(0,K.jsxs)(`div`,{ref:W,className:`min-h-screen bg-black flex flex-col`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2 bg-bambu-dark-secondary border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`h1`,{className:`text-sm font-medium text-white flex items-center gap-2`,children:[(0,K.jsx)(ts,{className:`w-4 h-4`}),ue?.name||`Printer ${s}`]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)(`div`,{className:`flex bg-bambu-dark rounded p-0.5`,children:[(0,K.jsx)(`button`,{onClick:()=>ye(`stream`),disabled:Ie,className:`px-3 py-1 text-xs rounded transition-colors ${m===`stream`?`bg-bambu-green text-white`:`text-bambu-gray hover:text-white disabled:opacity-50`}`,children:e(`camera.live`)}),(0,K.jsx)(`button`,{onClick:()=>ye(`snapshot`),disabled:Ie,className:`px-3 py-1 text-xs rounded transition-colors ${m===`snapshot`?`bg-bambu-green text-white`:`text-bambu-gray hover:text-white disabled:opacity-50`}`,children:e(`camera.snapshot`)})]}),(0,K.jsx)(`button`,{onClick:()=>fe.mutate(!de?.chamber_light),disabled:!de?.connected||fe.isPending||!r(`printers:control`),className:`p-1.5 rounded disabled:opacity-50 ${de?.chamber_light?`bg-yellow-500/20 hover:bg-yellow-500/30`:`hover:bg-bambu-dark-tertiary`}`,title:r(`printers:control`)?e(`camera.chamberLight`):e(`printers.permission.noControl`),children:(0,K.jsx)(hT,{on:de?.chamber_light??!1,className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>_(!0),disabled:!pe||!r(`printers:control`),className:`p-1.5 rounded disabled:opacity-50 ${pe&&r(`printers:control`)?`hover:bg-bambu-dark-tertiary`:``}`,title:r(`printers:control`)?e(pe?`printers.skipObjects.tooltip`:`printers.skipObjects.onlyWhilePrinting`):e(`printers.permission.noControl`),children:(0,K.jsx)(gT,{className:`w-4 h-4 text-bambu-gray`})}),(0,K.jsx)(`button`,{onClick:be,disabled:Ie,className:`p-1.5 hover:bg-bambu-dark-tertiary rounded disabled:opacity-50`,title:e(m===`stream`?`camera.restartStream`:`camera.refreshSnapshot`),children:(0,K.jsx)(Fl,{className:`w-4 h-4 text-bambu-gray ${Ie?`animate-spin`:``}`})}),(0,K.jsx)(`button`,{onClick:()=>b(!0),className:`p-1.5 hover:bg-bambu-dark-tertiary rounded`,title:e(`camera.diagnose.button`),children:(0,K.jsx)(hu,{className:`w-4 h-4 text-bambu-gray`})}),(0,K.jsx)(`button`,{onClick:xe,className:`p-1.5 hover:bg-bambu-dark-tertiary rounded`,title:e(k?`camera.exitFullscreen`:`camera.fullscreen`),children:k?(0,K.jsx)(cl,{className:`w-4 h-4 text-bambu-gray`}):(0,K.jsx)(il,{className:`w-4 h-4 text-bambu-gray`})})]})]}),(0,K.jsx)(`div`,{className:`flex-1 flex items-center justify-center p-2 overflow-hidden`,onWheel:we,onMouseMove:De,onMouseUp:Oe,onMouseLeave:Oe,onTouchStart:je,onTouchMove:Me,onTouchEnd:Ne,style:{touchAction:`none`},children:(0,K.jsxs)(`div`,{className:`relative w-full h-full flex items-center justify-center`,children:[(C||D)&&!N&&(0,K.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-black/50 z-10`,children:(0,K.jsxs)(`div`,{className:`text-center`,children:[(0,K.jsx)(Fl,{className:`w-8 h-8 text-bambu-gray animate-spin mx-auto mb-2`}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(m===`stream`?`camera.connectingToCamera`:`camera.capturingSnapshot`)})]})}),N&&(0,K.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-black/80 z-10`,children:(0,K.jsxs)(`div`,{className:`text-center p-4`,children:[(0,K.jsx)(Uu,{className:`w-10 h-10 text-orange-400 mx-auto mb-3`}),(0,K.jsx)(`p`,{className:`text-white mb-2`,children:e(`camera.connectionLost`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mb-3`,children:e(`camera.reconnecting`,{countdown:F,attempt:Math.min(j+1,u9),max:u9})}),(0,K.jsx)(`button`,{onClick:be,className:`px-4 py-2 bg-bambu-green text-white text-sm rounded hover:bg-bambu-green/80 transition-colors`,children:e(`camera.reconnectNow`)})]})}),x&&!N&&(0,K.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-black z-10`,children:(0,K.jsxs)(`div`,{className:`text-center p-4`,children:[(0,K.jsx)(Au,{className:`w-12 h-12 text-orange-400 mx-auto mb-3`}),(0,K.jsx)(`p`,{className:`text-white mb-2`,children:e(`camera.cameraUnavailable`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mb-4 max-w-md`,children:e(`camera.cameraUnavailableDesc`)}),(0,K.jsxs)(`div`,{className:`flex gap-2 justify-center`,children:[(0,K.jsx)(`button`,{onClick:be,className:`px-4 py-2 bg-bambu-green text-white rounded hover:bg-bambu-green/80 transition-colors`,children:e(`camera.retry`)}),(0,K.jsx)(`button`,{onClick:()=>b(!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,K.jsx)(`img`,{ref:ae,src:Fe,alt:e(`camera.cameraStream`),className:`max-w-full max-h-full object-contain select-none`,style:{transform:`scale(${L}) translate(${z.x/L}px, ${z.y/L}px) rotate(${ue?.camera_rotation||0}deg)`,...ue?.camera_rotation===90||ue?.camera_rotation===270?{maxWidth:`100vh`,maxHeight:`100vw`}:{},cursor:L>1?V?`grabbing`:`grab`:`default`},onError:Fe?ge:void 0,onLoad:Fe?_e:void 0,onMouseDown:Te,draggable:!1},T),(0,K.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,K.jsx)(`button`,{onClick:Ce,disabled:L<=1,className:`p-1.5 hover:bg-white/10 rounded disabled:opacity-30`,title:e(`camera.zoomOut`),children:(0,K.jsx)(Zu,{className:`w-4 h-4 text-white`})}),(0,K.jsxs)(`button`,{onClick:Pe,className:`px-2 py-1 text-sm text-white hover:bg-white/10 rounded min-w-[48px]`,title:e(`camera.resetZoom`),children:[Math.round(L*100),`%`]}),(0,K.jsx)(`button`,{onClick:Se,disabled:L>=4,className:`p-1.5 hover:bg-white/10 rounded disabled:opacity-30`,title:e(`camera.zoomIn`),children:(0,K.jsx)(Yu,{className:`w-4 h-4 text-white`})})]})]})}),(0,K.jsx)(_T,{printerId:s,isOpen:g,onClose:()=>_(!1)}),v&&(0,K.jsx)(vT,{printerId:s,printerName:ue?.name||null,onClose:()=>b(!1)})]}):(0,K.jsx)(`div`,{className:`min-h-screen bg-black flex items-center justify-center`,children:(0,K.jsx)(`p`,{className:`text-white`,children:e(`camera.invalidPrinterId`)})})}var WQe=5e3,GQe=4,KQe=8,qQe=1,JQe=16,YQe=2,XQe=60;function ZQe(e,t,n,r){let i=parseInt(e??``,10);return Number.isFinite(i)?Math.min(r,Math.max(n,i)):t}function QQe(e,t,n,r,i,a){return e.has(t)?ZQe(e.get(t),r,i,a):ZQe(localStorage.getItem(n),r,i,a)}function $Qe(){let{t:e}=$e(),t=tr(),{authEnabled:n,loading:r,user:i}=xd(),[a]=Fi(),o=a.get(`token`),s=o!=null&&o!==``,[c,l]=(0,y.useState)(()=>QQe(a,`maxLive`,`camWallMaxLive`,GQe,qQe,JQe)),[u,d]=(0,y.useState)(()=>QQe(a,`interval`,`camWallSnapshotSec`,KQe,YQe,XQe)),[f,p]=(0,y.useState)(()=>{let e=a.get(`status`)??localStorage.getItem(`camWallStatusMode`);return(s?[`off`,`compact`]:[`off`,`compact`,`full`]).includes(e)?e:`compact`});(0,y.useEffect)(()=>{if(s)return id(o),()=>id(null)},[s,o]);let m=q({queryKey:[`camwall-printers`,o],queryFn:()=>Q.getCamWallPrinters(o??void 0),enabled:s,refetchInterval:WQe}),h=q({queryKey:[`printers`],queryFn:()=>Q.getPrinters(),enabled:!s&&!r&&(!n||i!==null),refetchInterval:WQe}),g=(0,y.useMemo)(()=>{let e=new Map;for(let t of m.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},[m.data]);if(!s&&r)return(0,K.jsx)(`div`,{className:`flex min-h-screen items-center justify-center bg-bambu-dark text-bambu-gray`,children:e(`common.loading`)});if(!s&&n&&!i)return(0,K.jsx)(Nr,{to:`/login`,replace:!0,state:{from:t}});let _=s?m:h,v=s?m.data??[]:h.data??[];return _.isError?(0,K.jsx)(`div`,{className:`flex min-h-screen items-center justify-center bg-bambu-dark p-6 text-center`,children:(0,K.jsx)(`p`,{className:`max-w-md text-sm text-red-400`,children:e(s?`printers.camWall.page.tokenRejected`:`printers.camWall.page.loadFailed`)})}):(0,K.jsx)(`div`,{className:`min-h-screen bg-bambu-dark p-4`,children:(0,K.jsx)(TT,{printers:v,maxLive:c,snapshotIntervalSec:u,statusMode:f,statuses:s?g:void 0,showSettings:!s,onTileClick:s?void 0:e=>window.open(`/camera/${e}`,`camera-${e}`),onChangeMaxLive:e=>{l(e),localStorage.setItem(`camWallMaxLive`,String(e))},onChangeSnapshotIntervalSec:e=>{d(e),localStorage.setItem(`camWallSnapshotSec`,String(e))},onChangeStatusMode:e=>{p(e),localStorage.setItem(`camWallStatusMode`,e)}})})}function e$e(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 t$e(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`;return{size:e.get(`size`)||`medium`,fps:r,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`),showNozzle:t.includes(`nozzle`),showBed:t.includes(`bed`),showChamber:t.includes(`chamber`)}}function n$e(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 d9(e,t){let n=e[t];return typeof n==`number`?n:null}function r$e({icon:e,label:t,current:n,target:r,sizes:i}){let a=r!=null&&r>0&&Math.round(r)!==Math.round(n);return(0,K.jsxs)(`div`,{className:`flex items-center ${i.gap} text-white/70`,children:[e,(0,K.jsxs)(`span`,{className:i.text,children:[(0,K.jsx)(`span`,{className:`mr-1`,children:t}),(0,K.jsxs)(`span`,{className:`text-white`,children:[Math.round(n),`°C`]}),a&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`span`,{className:`mx-1`,children:`/`}),(0,K.jsxs)(`span`,{children:[Math.round(r),`°C`]})]})]})]})}function i$e(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 a$e(){let{printerId:e}=lr(),[t]=Fi(),{t:n}=$e(),r=ao(),i=parseInt(e||`0`,10),[a,o]=(0,y.useState)(Date.now()),s=(0,y.useMemo)(()=>t$e(t),[t]),c=i$e(s.size),l=t.get(`token`),u=l!=null&&l!==``,{data:d}=q({queryKey:[`overlayStatus`,i,l],queryFn:()=>Q.getOverlayStatus(i,l??void 0),enabled:i>0&&u,refetchInterval:2e3}),{data:f}=q({queryKey:[`printer`,i],queryFn:()=>Q.getPrinter(i),enabled:i>0&&!u}),{data:p}=q({queryKey:[`printerStatus`,i],queryFn:()=>Q.getPrinterStatus(i),enabled:i>0&&!u,refetchInterval:2e3}),{data:m}=q({queryKey:[`settings`],queryFn:Q.getSettings,enabled:!u}),h=(0,y.useMemo)(()=>u?d&&{name:d.name,camera_rotation:d.camera_rotation}:f,[u,d,f]),g=u?d:p,_=(u?d?.time_format:m?.time_format)||`system`;(0,y.useEffect)(()=>{if(!i||u)return;let e=null,t=!1;return(async()=>{let n;try{n=(await Q.getWebSocketToken()).token}catch(e){let t=e instanceof $u?e.status:0;if(t===401||t===403)return}if(t)return;let a=window.location.protocol===`https:`?`wss:`:`ws:`,o=n?`?token=${encodeURIComponent(n)}`:``,s=`${a}//${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===i&&r.setQueryData([`printerStatus`,i],t.status)}catch{}},e.onerror=()=>{}})(),()=>{t=!0,e&&e.close()}},[i,u,r]),(0,y.useEffect)(()=>(document.title=h?`${h.name} - ${n(`streamOverlay.title`)}`:n(`streamOverlay.title`),()=>{document.title=`Bambuddy`}),[h,n]);let v=()=>{setTimeout(()=>{o(Date.now())},3e3)};if(!i)return(0,K.jsx)(`div`,{className:`min-h-screen bg-black flex items-center justify-center`,children:(0,K.jsx)(`p`,{className:`text-white`,children:n(`streamOverlay.invalidPrinterId`)})});if(!g)return(0,K.jsx)(`div`,{className:`min-h-screen bg-black flex items-center justify-center`,children:(0,K.jsx)(`p`,{className:`text-gray-400`,children:n(`common.loading`)})});let b=g.state===`RUNNING`||g.state===`PAUSE`,x=g.progress||0,S=g.temperatures??{},C=[];if(s.showNozzle){let e=d9(S,`nozzle`),t=d9(S,`nozzle_2`);e!=null&&C.push({key:`nozzle`,icon:(0,K.jsx)(lc,{className:c.icon}),label:n(`printers.heaterHistory.nozzle`,`Nozzle`),current:e,target:d9(S,`nozzle_target`)}),t!=null&&C.push({key:`nozzle_2`,icon:(0,K.jsx)(lc,{className:c.icon}),label:n(`printers.heaterHistory.nozzle2`,`Nozzle 2`),current:t,target:d9(S,`nozzle_2_target`)})}if(s.showBed){let e=d9(S,`bed`);e!=null&&C.push({key:`bed`,icon:(0,K.jsx)(pu,{className:c.icon}),label:n(`printers.heaterHistory.bed`,`Bed`),current:e,target:d9(S,`bed_target`)})}if(s.showChamber){let e=d9(S,`chamber`);e!=null&&C.push({key:`chamber`,icon:(0,K.jsx)(qo,{className:c.icon}),label:n(`printers.heaterHistory.chamber`,`Chamber`),current:e,target:d9(S,`chamber_target`)})}let w=`/api/v1/printers/${i}/camera/stream?fps=${s.fps}&t=${a}`,T=u&&l?`${w}&token=${encodeURIComponent(l)}`:od(w);return(0,K.jsxs)(`div`,{className:`min-h-screen bg-black relative overflow-hidden`,children:[s.showCamera&&(0,K.jsx)(`img`,{src:T,alt:n(`streamOverlay.cameraStream`),className:`absolute inset-0 w-full h-full object-contain`,style:h?.camera_rotation?{transform:`rotate(${h.camera_rotation}deg)`}:void 0,onError:v},a),(0,K.jsx)(`a`,{href:`https://github.com/maziggy/bambuddy`,target:`_blank`,rel:`noopener noreferrer`,className:`absolute top-4 right-4 z-10`,children:(0,K.jsx)(`img`,{src:`/img/bambuddy_logo_dark_transparent.png`,alt:`Bambuddy`,className:`${c.logoHeight} object-contain drop-shadow-lg hover:scale-105 transition-transform`})}),(0,K.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,K.jsxs)(`div`,{className:`${c.container}`,children:[s.showPrinter&&h&&(0,K.jsxs)(`div`,{className:`flex items-center ${c.gap} mb-2`,children:[(0,K.jsx)(Ml,{className:`${c.icon} text-white/70`}),(0,K.jsx)(`span`,{className:`${c.text} text-white font-medium`,children:h.name})]}),s.showFilename&&g.current_print&&(0,K.jsx)(`div`,{className:`${c.textLarge} text-white font-semibold mb-2 truncate drop-shadow-md`,children:e$e(g.current_print.replace(/\.gcode\.3mf$|\.3mf$|\.gcode$/i,``),g.gcode_file,n)}),s.showStatus&&(0,K.jsx)(`div`,{className:`${c.text} text-white/70 mb-2`,children:n$e(g,n)}),s.showProgress&&b&&(0,K.jsxs)(`div`,{className:`mb-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-1 ${c.text}`,children:[(0,K.jsx)(`span`,{className:`text-white/70`,children:n(`streamOverlay.progress`)}),(0,K.jsxs)(`span`,{className:`text-white font-bold`,children:[Math.round(x),`%`]})]}),(0,K.jsx)(`div`,{className:`w-full bg-white/20 rounded-full ${c.progressHeight}`,children:(0,K.jsx)(`div`,{className:`bg-bambu-green ${c.progressHeight} rounded-full transition-all duration-500`,style:{width:`${x}%`}})})]}),b&&(s.showLayers||s.showEta)&&(0,K.jsxs)(`div`,{className:`flex items-center ${c.gap} flex-wrap`,children:[s.showLayers&&g.layer_num!=null&&g.total_layers!=null&&g.total_layers>0&&(0,K.jsxs)(`div`,{className:`flex items-center ${c.gap} text-white/70`,children:[(0,K.jsx)(Hc,{className:c.icon}),(0,K.jsxs)(`span`,{className:c.text,children:[(0,K.jsx)(`span`,{className:`text-white`,children:g.layer_num}),(0,K.jsx)(`span`,{className:`mx-1`,children:`/`}),(0,K.jsx)(`span`,{children:g.total_layers})]})]}),s.showEta&&g.remaining_time!=null&&g.remaining_time>0&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`flex items-center ${c.gap} text-white/70`,children:[(0,K.jsx)(Eu,{className:c.icon}),(0,K.jsx)(`span`,{className:`${c.text} text-white`,children:Jf(g.remaining_time*60)})]}),(0,K.jsxs)(`div`,{className:`flex items-center ${c.gap} text-white/70`,children:[(0,K.jsx)(Ts,{className:c.icon}),(0,K.jsxs)(`span`,{className:`${c.text} text-white`,children:[n(`streamOverlay.eta`),` `,qf(g.remaining_time,_,n)]})]})]})]}),!b&&(0,K.jsx)(`div`,{className:`${c.text} text-white/70 py-2`,children:g.connected?n(`streamOverlay.printerIdle`):n(`streamOverlay.printerOffline`)}),C.length>0&&(0,K.jsx)(`div`,{className:`flex items-center ${c.gap} flex-wrap mt-2`,children:C.map(e=>(0,K.jsx)(r$e,{icon:e.icon,label:e.label,current:e.current,target:e.target,sizes:c},e.key))})]})})]})}function o$e(){let{t:e}=$e(),{id:t}=lr(),{mode:n}=wd(),{data:r,isLoading:i,error:a}=q({queryKey:[`external-link`,t],queryFn:()=>Q.getExternalLink(Number(t)),enabled:!!t});return i?(0,K.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,K.jsx)(X,{className:`w-8 h-8 text-bambu-green animate-spin`})}):a||!r?(0,K.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-4 text-bambu-gray`,children:[(0,K.jsx)(Au,{className:`w-12 h-12`}),(0,K.jsx)(`p`,{children:e(`common.linkNotFound`)})]}):(0,K.jsx)(`iframe`,{src:r.url,className:`h-full w-full border-0`,style:{colorScheme:n},title:r.name,sandbox:`allow-scripts allow-same-origin allow-forms allow-popups allow-popups-to-escape-sandbox`})}function s$e(){let{id:e}=lr(),t=ir(),n=ao(),{t:r}=$e(),{showToast:i}=Fd(),a=!!e,[o,s]=(0,y.useState)(``),[c,l]=(0,y.useState)(``),[u,d]=(0,y.useState)([]),[f,p]=(0,y.useState)(``),[m,h]=(0,y.useState)(!1),{data:g,isLoading:_}=q({queryKey:[`group`,e],queryFn:()=>Q.getGroup(Number(e)),enabled:a}),{data:v,isLoading:b}=q({queryKey:[`permissions`],queryFn:()=>Q.getPermissions()});a&&g&&!m&&(s(g.name),l(g.description||``),d(g.permissions),h(!0));let x=J({mutationFn:e=>Q.createGroup(e),onSuccess:()=>{n.invalidateQueries({queryKey:[`groups`]}),n.invalidateQueries({queryKey:[`group`]}),i(r(`groups.toast.created`)),t(`/settings?tab=users`)},onError:e=>{i(e.message,`error`)}}),S=J({mutationFn:t=>Q.updateGroup(Number(e),t),onSuccess:a=>{n.invalidateQueries({queryKey:[`groups`]}),a&&n.setQueryData([`group`,e],a),i(r(`groups.toast.updated`)),t(`/settings?tab=users`)},onError:e=>{i(e.message,`error`)}}),C=x.isPending||S.isPending,w=()=>{if(!o.trim()){i(r(`groups.toast.enterGroupName`),`error`);return}a?S.mutate({name:o===g?.name?void 0:o,description:c,permissions:u}):x.mutate({name:o,description:c||void 0,permissions:u})},T=e=>{d(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},E=(e,t)=>{let n=e.permissions.map(e=>e.value);d(e=>{let r=e.filter(e=>!n.includes(e));return t?[...r,...n]:r})},D=e=>e.permissions.every(e=>u.includes(e.value)),O=e=>{let t=e.permissions.filter(e=>u.includes(e.value)).length;return t>0&&t{v&&d(v.all_permissions)},A=()=>{d([])},j=f.toLowerCase(),M=(0,y.useMemo)(()=>v?j?v.categories.map(e=>({...e,permissions:e.permissions.filter(e=>e.label.toLowerCase().includes(j))})).filter(e=>e.permissions.length>0):v.categories:[],[v,j]),N=v?.all_permissions.length??0;return _||b?(0,K.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,K.jsx)(X,{className:`w-8 h-8 text-bambu-green animate-spin`})}):(0,K.jsxs)(`div`,{className:`space-y-6 max-w-5xl mx-auto`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.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,K.jsx)(Po,{className:`w-5 h-5`})}),(0,K.jsx)(`h1`,{className:`text-xl font-bold text-white`,children:r(a?`groups.editor.title`:`groups.editor.createTitle`)})]}),a&&g?.is_system&&(0,K.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,K.jsx)(Au,{className:`w-4 h-4 shrink-0`}),r(`groups.form.systemGroupWarning`)]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:r(`groups.form.groupName`)}),(0,K.jsx)(`input`,{type:`text`,value:o,onChange:e=>s(e.target.value),disabled:a&&g?.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:r(`groups.form.groupNamePlaceholder`)})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:r(`groups.form.description`)}),(0,K.jsx)(`input`,{type:`text`,value:c,onChange:e=>l(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:r(`groups.form.descriptionPlaceholder`)})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between flex-wrap gap-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[r(`groups.editor.permissionsSelected`,{count:u.length}),` / `,N]}),(0,K.jsx)($,{size:`sm`,variant:`ghost`,onClick:k,children:r(`groups.editor.selectAll`)}),(0,K.jsx)($,{size:`sm`,variant:`ghost`,onClick:A,children:r(`groups.editor.clearAll`)})]}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(Gl,{className:`w-4 h-4 absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray`}),(0,K.jsx)(`input`,{type:`text`,value:f,onChange:e=>p(e.target.value),placeholder:r(`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`})]})]}),M.length===0?(0,K.jsx)(`div`,{className:`text-center py-12 text-bambu-gray`,children:r(`groups.editor.noResults`)}):(0,K.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:M.map(e=>{let t=v.categories.find(t=>t.name===e.name),n=t.permissions.filter(e=>u.includes(e.value)).length,i=t.permissions.length,a=D(t),o=O(t);return(0,K.jsxs)(Dd,{children:[(0,K.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,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsxs)(`button`,{type:`button`,onClick:()=>E(t,!a),className:`w-5 h-5 rounded border flex items-center justify-center transition-colors shrink-0 ${a?`bg-bambu-green border-bambu-green`:o?`bg-bambu-green/50 border-bambu-green`:`border-bambu-gray hover:border-white`}`,children:[a&&(0,K.jsx)(ss,{className:`w-3 h-3 text-white`}),o&&!a&&(0,K.jsx)(ll,{className:`w-3 h-3 text-white`})]}),(0,K.jsx)(eu,{className:`w-4 h-4 text-bambu-gray shrink-0`}),(0,K.jsx)(`span`,{className:`text-white font-medium text-sm`,children:e.name})]}),(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray tabular-nums`,children:[n,`/`,i]})]}),(0,K.jsx)(`div`,{className:`p-3 space-y-1`,children:e.permissions.map(e=>(0,K.jsxs)(`label`,{className:`flex items-center gap-3 px-2 py-1.5 rounded hover:bg-bambu-dark-secondary cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:u.includes(e.value),onChange:()=>T(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,K.jsxs)(`span`,{className:`flex flex-col`,children:[(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.label}),e.value===`websocket:connect`&&(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray/60`,children:r(`groups.editor.websocketHint`)})]})]},e.value))})]},e.name)})}),(0,K.jsx)(`div`,{className:`h-16`}),(0,K.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,K.jsx)($,{variant:`secondary`,onClick:()=>t(`/settings?tab=users`),children:r(`common.cancel`)}),(0,K.jsx)($,{onClick:w,disabled:C||!o.trim(),children:C?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),r(`common.saving`)]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Bl,{className:`w-4 h-4`}),r(`common.save`)]})})]})]})}var c$e=1.65,l$e=[`#1DB954`,`#3B82F6`,`#F59E0B`,`#EF4444`,`#8B5CF6`];function f9(e,t,n,r){return`${e}||${t??``}||${n??``}||${r??``}`}function p9(e,t){let n=new Date(e);return n.setDate(n.getDate()+Math.round(t)),n}function m9(e){return e.toLocaleDateString(void 0,{month:`short`,day:`numeric`,year:`numeric`})}function h9(e){return e.toLocaleDateString(void 0,{month:`short`,day:`numeric`})}function u$e(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 d$e(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 nQ.getAllUsageHistory(5e3),staleTime:6e4,enabled:o}),{data:O=[]}=q({queryKey:[`shopping-list`],queryFn:Q.getShoppingList,staleTime:3e4,enabled:o}),k=T?.forecast_global_lead_time_days??0,A=(0,y.useMemo)(()=>{let e=new Map;for(let t of E)e.set(f9(t.material,t.subtype,t.brand,t.color_name),t);return e},[E]),j=(0,y.useMemo)(()=>{let e=new Map;for(let t of D){let n=e.get(t.spool_id)??[];n.push(t),e.set(t.spool_id,n)}return e},[D]),M=(0,y.useMemo)(()=>{let t=new Map;for(let n of e){if(n.archived_at)continue;let e=f9(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]),N=(0,y.useMemo)(()=>{let e=new Date;return e.setHours(0,0,0,0),M.map(t=>{let n=A.get(t.key)??(t.colorName===null?null:A.get(f9(t.material,t.subtype,t.brand,null))??null),r=n?.lead_time_days??0,i=Math.max(k,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(...j.get(e.id)??[]);let d=null,f=null,p=`none`,m=u$e(u);if(m!==null)d=m.rate,f=m.stdDev,p=`history`;else{let e=d$e(t.spools);e!==null&&(d=e,p=`delta`)}let h=c$e*(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:p9(e,_),y=d&&d>0?Math.floor((s-g)/d):null,b=y===null?null:p9(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}})},[M,A,j,k]),P=(0,y.useMemo)(()=>[...new Set(M.map(e=>e.material))].sort(),[M]),F=(0,y.useMemo)(()=>[...new Set(M.map(e=>e.brand).filter(Boolean))].sort(),[M]),I=(0,y.useMemo)(()=>{let e=[...N];return m&&(e=e.filter(e=>e.group.material===m)),g&&(e=e.filter(e=>e.group.brand===g)),e.sort((e,t)=>{let n=0,r=0;switch(u){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 f===`asc`?i:-i}),e},[N,u,f,m,g]),L=(0,y.useMemo)(()=>N.filter(e=>!e.settings?.alerts_snoozed&&(e.stockBreakAlert||e.reorderAlert)),[N]),R=(0,y.useMemo)(()=>[...N].filter(e=>e.dailyRateG!==null).sort((e,t)=>t.totalUsedG-e.totalUsedG).slice(0,5),[N]);if(!o)return(0,K.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-16 text-bambu-gray gap-3`,children:[(0,K.jsx)(Zc,{className:`w-8 h-8 opacity-40`}),(0,K.jsx)(`p`,{className:`text-sm`,children:r(`forecast.noReadAccess`)})]});function z(e){u===e?p(e=>e===`asc`?`desc`:`asc`):(d(e),p(e===`days_left`?`asc`:`desc`))}let B=O.length>0?O.length:null;return(0,K.jsxs)(`div`,{className:`space-y-5`,children:[(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[L.length>0&&(0,K.jsxs)(`button`,{onClick:()=>l(e=>!e),className:`flex items-center gap-2 px-3 py-1.5 rounded-lg border text-sm font-medium transition-colors ${L.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,K.jsx)(Au,{className:`w-4 h-4`}),r(`forecast.alertCount`,{count:L.length}),c?(0,K.jsx)(ds,{className:`w-3.5 h-3.5`}):(0,K.jsx)(cs,{className:`w-3.5 h-3.5`})]}),s&&(0,K.jsx)(_$e,{value:k,onSave:e=>{Q.updateSettings({forecast_global_lead_time_days:e}).then(()=>{t.invalidateQueries({queryKey:[`settings`]}),n(r(`forecast.globalLeadTimeSaved`),`success`)})}}),(0,K.jsxs)(`select`,{value:m,onChange:e=>h(e.target.value),className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${m?`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,K.jsx)(`option`,{value:``,children:r(`inventory.material`)}),P.map(e=>(0,K.jsx)(`option`,{value:e,children:e},e))]}),(0,K.jsxs)(`select`,{value:g,onChange:e=>_(e.target.value),className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${g?`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,K.jsx)(`option`,{value:``,children:r(`inventory.brand`)}),F.map(e=>(0,K.jsx)(`option`,{value:e,children:e},e))]}),(0,K.jsxs)(`button`,{onClick:()=>S(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,K.jsx)(tu,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:r(`forecast.shoppingList`)}),B&&(0,K.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:B})]})]}),c&&L.length>0&&(0,K.jsx)(`div`,{className:`space-y-2`,children:L.map(e=>(0,K.jsx)(m$e,{forecast:e,onCart:()=>b(e)},e.group.key))}),x&&(0,K.jsx)(S$e,{items:O,forecasts:N,globalLeadTime:k,canWrite:s,onClose:()=>S(!1),onRemove:e=>{Q.removeFromShoppingList(e).then(()=>t.invalidateQueries({queryKey:[`shopping-list`]})).catch(()=>n(r(`forecast.failedSaveSettings`),`error`))},onClear:()=>{Q.clearShoppingList().then(()=>t.invalidateQueries({queryKey:[`shopping-list`]})).catch(()=>n(r(`forecast.failedSaveSettings`),`error`))}}),R.length>0&&(0,K.jsx)(g$e,{forecasts:R,days:C,onDaysChange:w}),N.length===0?(0,K.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-16 text-bambu-gray`,children:[(0,K.jsx)(Ou,{className:`w-10 h-10 mb-3 opacity-40`}),(0,K.jsx)(`p`,{className:`text-sm`,children:r(`forecast.noSpools`)})]}):(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-dark-tertiary`,children:[(0,K.jsx)(`div`,{className:`overflow-x-auto`,children:(0,K.jsxs)(`table`,{className:`w-full`,children:[(0,K.jsx)(`thead`,{children:(0,K.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary bg-bambu-dark-tertiary/30`,children:[(0,K.jsx)(`th`,{className:`w-8 px-4 py-3`}),(0,K.jsx)(g9,{col:`material`,active:u,dir:f,onSort:z,children:r(`forecast.sku`)}),(0,K.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:r(`locations.spools`)}),(0,K.jsx)(g9,{col:`stock`,active:u,dir:f,onSort:z,children:r(`forecast.stock`)}),(0,K.jsx)(g9,{col:`used`,active:u,dir:f,onSort:z,children:r(`forecast.dailyRate`)}),(0,K.jsx)(g9,{col:`days_left`,active:u,dir:f,onSort:z,children:r(`forecast.daysLeft`)}),(0,K.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:r(`forecast.emptyBy`)}),(0,K.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:r(`forecast.reorderBy`)}),(0,K.jsx)(`th`,{className:`w-24 px-4 py-3`})]})}),(0,K.jsx)(`tbody`,{className:`divide-y divide-bambu-dark-tertiary`,children:I.map(e=>(0,K.jsx)(v$e,{forecast:e,globalLeadTime:k,canWrite:s,onSaved:()=>t.invalidateQueries({queryKey:[`sku-settings`]}),onCart:()=>b(e),showToast:n},e.group.key))})]})}),(0,K.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,K.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,K.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-bambu-green inline-block`}),r(`forecast.trendLegend`)]}),(0,K.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,K.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-blue-400 inline-block`}),r(`forecast.estimatedLegend`)]}),(0,K.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,K.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-bambu-gray/40 inline-block`}),r(`forecast.noDataLegend`)]})]})]}),v&&(0,K.jsx)(w$e,{forecast:v,onClose:()=>b(null),onAdd:e=>{Q.addToShoppingList(e).then(()=>{t.invalidateQueries({queryKey:[`shopping-list`]}),n(r(`forecast.addedToCart`),`success`),b(null),S(!0)}).catch(()=>n(r(`forecast.failedAddItem`),`error`))}})]})}function g9({col:e,active:t,dir:n,onSort:r,children:i}){return(0,K.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,K.jsxs)(`span`,{className:`inline-flex items-center`,children:[i,t===e?n===`asc`?(0,K.jsx)(zo,{className:`w-3 h-3 ml-1 text-bambu-green`}):(0,K.jsx)(No,{className:`w-3 h-3 ml-1 text-bambu-green`}):(0,K.jsx)(Lo,{className:`w-3 h-3 ml-1 opacity-40`})]})})}function m$e({forecast:e,onCart:t}){let{t:n}=$e(),r=[e.group.brand,e.group.material,e.group.subtype,e.group.colorName].filter(Boolean).join(` `),i=e.stockBreakAlert;return(0,K.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,K.jsx)(Au,{className:`w-4 h-4 flex-shrink-0`}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`span`,{className:`font-medium`,children:r}),i?(0,K.jsxs)(`span`,{className:`ml-2 text-xs opacity-80`,children:[n(`forecast.stockBreakRisk`),` — `,n(`forecast.stockBreakDetail`,{days:e.daysRemaining,lt:e.effectiveLeadTimeDays})]}):(0,K.jsxs)(`span`,{className:`ml-2 text-xs opacity-80`,children:[n(`forecast.reorderNow`),` — `,n(`forecast.reorderTriggerPassed`,{date:e.reorderTriggerDate?m9(e.reorderTriggerDate):`—`})]})]}),(0,K.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,K.jsx)(tu,{className:`w-3 h-3`}),` `,n(`forecast.order`)]})]})}var h$e=[{label:`1W`,value:7},{label:`1M`,value:30},{label:`6M`,value:180}];function g$e({forecasts:e,days:t,onDaysChange:n}){let{t:r}=$e(),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:l$e[n%l$e.length],rop:e.reorderPointG,points:f$e(e,t)})),o=i.map(e=>{let t={day:e,label:h9(p9(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})(),c=o.slice(0,s+1),l=a.filter(e=>e.rop>0);return(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-dark-tertiary p-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-4`,children:[(0,K.jsx)(Ou,{className:`w-4 h-4 text-bambu-green`}),(0,K.jsx)(`h3`,{className:`text-sm font-semibold text-white`,children:r(`forecast.chartTitle`)}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1 hidden sm:inline`,children:r(`forecast.dashedLinesROP`)}),(0,K.jsx)(`div`,{className:`ml-auto flex items-center bg-bambu-dark-tertiary rounded-lg p-0.5`,children:h$e.map(e=>(0,K.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,K.jsx)(xA,{width:`100%`,height:220,children:(0,K.jsxs)(aU,{data:c,margin:{top:4,right:8,bottom:0,left:0},children:[(0,K.jsx)(`defs`,{children:a.map(e=>(0,K.jsxs)(`linearGradient`,{id:`grad-${e.key}`,x1:`0`,y1:`0`,x2:`0`,y2:`1`,children:[(0,K.jsx)(`stop`,{offset:`5%`,stopColor:e.color,stopOpacity:.25}),(0,K.jsx)(`stop`,{offset:`95%`,stopColor:e.color,stopOpacity:.02})]},e.key))}),(0,K.jsx)(LV,{strokeDasharray:`3 3`,stroke:`#374151`,strokeOpacity:.5}),(0,K.jsx)(hH,{dataKey:`label`,tick:{fill:`#6B7280`,fontSize:10},interval:Math.max(0,Math.ceil(s/8)-1),axisLine:!1,tickLine:!1}),(0,K.jsx)(bH,{tick:{fill:`#6B7280`,fontSize:10},axisLine:!1,tickLine:!1,tickFormatter:e=>e>=1e3?`${(e/1e3).toFixed(1)}kg`:`${e}g`,width:48}),(0,K.jsx)(yz,{content:({label:e,payload:t})=>t?.length?(0,K.jsxs)(`div`,{style:{background:`#1a1a2e`,border:`1px solid #374151`,borderRadius:8,fontSize:12,padding:`8px 12px`},children:[(0,K.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,K.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:6,color:`#E5E7EB`,marginBottom:2},children:[(0,K.jsx)(`span`,{style:{color:t?.color??`#9CA3AF`,fontSize:10},children:`●`}),(0,K.jsx)(`span`,{children:t?.label??String(e.dataKey)}),(0,K.jsxs)(`span`,{style:{color:`#9CA3AF`,marginLeft:4},children:[e.value,`g`]})]},String(e.dataKey)):null})]}):null}),(0,K.jsx)(Ej,{formatter:e=>(0,K.jsx)(`span`,{style:{color:`#9CA3AF`,fontSize:11},children:a.find(t=>t.key===e)?.label??e})}),a.map(e=>(0,K.jsx)(ZV,{type:`monotone`,dataKey:e.key,stroke:e.color,strokeWidth:2,fill:`url(#grad-${e.key})`,dot:!1,activeDot:{r:3}},e.key)),l.map(e=>(0,K.jsx)(xV,{y:e.rop,stroke:e.color,strokeDasharray:`4 3`,strokeOpacity:.6},`rop-${e.key}`))]})})]})}function _$e({value:e,onSave:t}){let{t:n}=$e(),[r,i]=(0,y.useState)(!1),[a,o]=(0,y.useState)(String(e));function s(){let e=parseInt(a,10);isNaN(e)||e<0||(t(e),i(!1))}return(0,K.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,K.jsx)(Rc,{className:`w-3.5 h-3.5 flex-shrink-0`,"aria-label":n(`forecast.globalLeadTimeHint`)}),(0,K.jsxs)(`span`,{className:`hidden sm:inline`,children:[n(`forecast.globalLeadTime`),`:`]}),r?(0,K.jsxs)(`form`,{className:`flex items-center gap-1.5`,onSubmit:e=>{e.preventDefault(),s()},children:[(0,K.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,K.jsx)(`span`,{className:`text-bambu-gray`,children:`d`}),(0,K.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,K.jsx)(`button`,{type:`button`,onClick:()=>i(!1),className:`text-xs text-bambu-gray hover:text-white`,children:`✕`})]}):(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,K.jsxs)(`span`,{className:`font-semibold text-white`,children:[e,`d`]}),(0,K.jsx)(`button`,{onClick:()=>{o(String(e)),i(!0)},className:`p-0.5 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,K.jsx)(wl,{className:`w-3 h-3`})})]})]})}function v$e({forecast:e,globalLeadTime:t,canWrite:n,onSaved:r,onCart:i,showToast:a}){let{t:o}=$e(),[s,c]=(0,y.useState)(!1),[l,u]=(0,y.useState)(!1),[d,f]=(0,y.useState)(!1),[p,m]=(0,y.useState)(String(e.settings?.lead_time_days??0)),[h,g]=(0,y.useState)(String(e.settings?.safety_margin_value??14)),[_,v]=(0,y.useState)(e.settings?.safety_margin_unit??`days`);(0,y.useEffect)(()=>{l||m(String(e.settings?.lead_time_days??0))},[e.settings?.lead_time_days,l]),(0,y.useEffect)(()=>{d||(g(String(e.settings?.safety_margin_value??14)),v(e.settings?.safety_margin_unit??`days`))},[e.settings?.safety_margin_value,e.settings?.safety_margin_unit,d]);let b=J({mutationFn:Q.upsertSkuSettings,onSuccess:()=>{r(),a(o(`forecast.settingsSaved`),`success`)},onError:()=>a(o(`forecast.failedSaveSettings`),`error`)}),x=e.settings?.alerts_snoozed??!1,S=[e.group.brand,e.group.material,e.group.subtype,e.group.colorName].filter(Boolean).join(` `),C=e.group.spools[0]?.rgba?_f(e.group.spools[0].rgba):{backgroundColor:`#4B5563`},w=e.totalLabelG>0?Math.round(e.totalRemainingG/e.totalLabelG*100):0,T=x||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 E(t,n,r,i=x){b.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 D(t){t.stopPropagation(),E(e.settings?.lead_time_days??0,e.settings?.safety_margin_value??14,e.settings?.safety_margin_unit??`days`,!x)}let O=e.rateTier===`history`?(0,K.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,K.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-bambu-green`}),o(`forecast.trend`)]}):e.rateTier===`delta`?(0,K.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,K.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-blue-400`}),o(`forecast.estimated`)]}):(0,K.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,K.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-bambu-gray/40`}),o(`forecast.noData`)]});return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/50 cursor-pointer hover:bg-bambu-dark-tertiary/30 transition-colors ${x?``:e.stockBreakAlert?`bg-red-500/5`:e.reorderAlert?`bg-yellow-500/5`:``} ${x?`opacity-50`:``}`,onClick:()=>c(e=>!e),children:[(0,K.jsx)(`td`,{className:`px-4 py-3`,children:(0,K.jsx)(`span`,{className:`block w-5 h-5 rounded-full border border-black/20`,style:C})}),(0,K.jsx)(`td`,{className:`px-4 py-3`,children:(0,K.jsx)(`span`,{className:`text-sm text-white`,children:S})}),(0,K.jsx)(`td`,{className:`px-4 py-3`,children:(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.totalSpools})}),(0,K.jsx)(`td`,{className:`px-4 py-3 min-w-[140px]`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`div`,{className:`flex-1 h-2 bg-bambu-dark-tertiary rounded-full overflow-hidden`,children:(0,K.jsx)(`div`,{className:`h-full rounded-full ${w>50?`bg-bambu-green`:w>20?`bg-yellow-500`:`bg-red-500`}`,style:{width:`${Math.min(w,100)}%`}})}),(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray min-w-[40px] text-right`,children:[Math.round(e.totalRemainingG),`g`]})]})}),(0,K.jsx)(`td`,{className:`px-4 py-3`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 flex-wrap`,children:[(0,K.jsx)(`span`,{className:`text-sm text-white`,children:e.dailyRateG===null?`—`:`${e.dailyRateG.toFixed(1)}g/d`}),O]})}),(0,K.jsx)(`td`,{className:`px-4 py-3`,children:(0,K.jsx)(`span`,{className:`text-sm font-semibold ${T}`,children:e.daysRemaining===null?(0,K.jsx)(`span`,{className:`text-bambu-gray font-normal`,children:`—`}):`${e.daysRemaining}d`})}),(0,K.jsx)(`td`,{className:`px-4 py-3`,children:(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.projectedEmptyDate?m9(e.projectedEmptyDate):`—`})}),(0,K.jsx)(`td`,{className:`px-4 py-3`,children:(0,K.jsx)(`span`,{className:`text-sm ${!x&&e.reorderAlert?`text-yellow-700 dark:text-yellow-400`:`text-bambu-gray`}`,children:e.reorderTriggerDate?m9(e.reorderTriggerDate):`—`})}),(0,K.jsx)(`td`,{className:`px-4 py-3`,onClick:e=>e.stopPropagation(),children:(0,K.jsxs)(`div`,{className:`flex items-center justify-end gap-1`,children:[n&&(0,K.jsx)(`button`,{onClick:i,className:`p-1.5 text-bambu-gray hover:text-bambu-green rounded transition-colors`,title:o(`forecast.addToCart`),children:(0,K.jsx)(tu,{className:`w-4 h-4`})}),!x&&(e.stockBreakAlert?(0,K.jsx)(Au,{className:`w-4 h-4 text-red-600 dark:text-red-400`,"aria-label":o(`forecast.stockBreakRisk`)}):e.reorderAlert?(0,K.jsx)(Au,{className:`w-4 h-4 text-yellow-600 dark:text-yellow-400`,"aria-label":o(`forecast.reorderNow`)}):e.daysRemaining===null?null:(0,K.jsx)(ss,{className:`w-4 h-4 text-bambu-green/50`})),n&&(0,K.jsx)(`button`,{onClick:D,className:`p-1 rounded transition-colors ${x?`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:o(x?`forecast.alertsEnabled`:`forecast.alertsSnoozed`),children:(0,K.jsx)(Ho,{className:`w-3.5 h-3.5`})}),(0,K.jsx)(`button`,{onClick:e=>{e.stopPropagation(),c(e=>!e)},className:`p-1.5 text-bambu-gray hover:text-white rounded transition-colors`,children:s?(0,K.jsx)(ds,{className:`w-4 h-4`}):(0,K.jsx)(cs,{className:`w-4 h-4`})})]})})]}),s&&(0,K.jsx)(`tr`,{className:`bg-bambu-dark-tertiary/10`,children:(0,K.jsx)(`td`,{colSpan:9,className:`px-6 py-4`,children:(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsxs)(`div`,{className:`grid gap-2 ${n?`grid-cols-2 sm:grid-cols-4`:`grid-cols-2`}`,children:[(0,K.jsx)(y$e,{label:o(`forecast.effectiveLeadTime`),value:`${e.effectiveLeadTimeDays}d`,hint:o(`forecast.effectiveLeadTimeHint`,{global:t,sku:e.settings?.lead_time_days??0})}),(0,K.jsx)(y$e,{label:o(`forecast.reorderPoint`),value:`${Math.round(e.reorderPointG)}g`,hint:o(`forecast.reorderPointHint`)}),n&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(b$e,{label:o(`forecast.skuLeadTimeOverride`),hint:o(`forecast.skuLeadTimeHint`),unit:o(`forecast.leadTime`),editing:l,value:e.settings?.lead_time_days??0,inputValue:p,onInputChange:m,onEdit:()=>{m(String(e.settings?.lead_time_days??0)),u(!0)},onSave:()=>{let t=parseInt(p,10);!isNaN(t)&&t>=0&&(E(t,e.settings?.safety_margin_value??14,_),u(!1))},onCancel:()=>u(!1),isPending:b.isPending,saveLabel:o(`forecast.save`),cancelLabel:o(`forecast.cancel`)}),(0,K.jsx)(x$e,{value:e.settings?.safety_margin_value??14,unit:_,editing:d,inputValue:h,dailyRateG:e.dailyRateG,onInputChange:g,onUnitChange:e=>v(e),onEdit:()=>{g(String(e.settings?.safety_margin_value??14)),v(e.settings?.safety_margin_unit??`days`),f(!0)},onSave:()=>{let t=parseInt(h,10);!isNaN(t)&&t>=0&&(E(e.settings?.lead_time_days??0,t,_),f(!1))},onCancel:()=>f(!1),isPending:b.isPending,saveLabel:o(`forecast.save`),cancelLabel:o(`forecast.cancel`),safetyMarginLabel:o(`forecast.safetyMarginLabel`)})]})]}),e.group.spools.length>1&&(0,K.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary pt-3`,children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:o(`forecast.individualSpools`)}),(0,K.jsx)(`div`,{className:`bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-dark-tertiary`,children:(0,K.jsxs)(`table`,{className:`w-full`,children:[(0,K.jsx)(`thead`,{children:(0,K.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary bg-bambu-dark-tertiary/30`,children:[(0,K.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:`#`}),(0,K.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:o(`inventory.remaining`)}),(0,K.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:o(`inventory.used`)}),(0,K.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:o(`forecast.labelWeight`)})]})}),(0,K.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,K.jsxs)(`tr`,{className:`hover:bg-bambu-dark-tertiary/30 transition-colors`,children:[(0,K.jsx)(`td`,{className:`px-4 py-2`,children:(0,K.jsxs)(`span`,{className:`text-xs font-mono text-bambu-gray/70`,children:[`#`,e.id]})}),(0,K.jsx)(`td`,{className:`px-4 py-2`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`w-24 h-1.5 bg-bambu-dark-tertiary rounded-full overflow-hidden flex-shrink-0`,children:(0,K.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,K.jsxs)(`span`,{className:`text-sm text-white`,children:[Math.round(t),`g`]})]})}),(0,K.jsx)(`td`,{className:`px-4 py-2`,children:(0,K.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[Math.round(Math.max(0,e.weight_used-(e.weight_used_baseline??0))),`g`]})}),(0,K.jsx)(`td`,{className:`px-4 py-2`,children:(0,K.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[e.label_weight,`g`]})})]},e.id)})})]})})]})]})})})]})}function y$e({label:e,value:t,hint:n}){return(0,K.jsxs)(`div`,{className:`bg-bambu-dark-tertiary/40 rounded-lg p-3`,title:n,children:[(0,K.jsx)(`div`,{className:`text-xs font-medium text-white mb-1`,children:e}),(0,K.jsx)(`div`,{className:`text-lg font-semibold text-white`,children:t})]})}function b$e({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,K.jsxs)(`div`,{className:`bg-bambu-dark-tertiary/40 rounded-lg p-3 space-y-1`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,K.jsx)(`span`,{className:`text-xs font-medium text-white`,children:e}),(0,K.jsx)(`span`,{title:t,children:(0,K.jsx)(Rc,{className:`w-3 h-3 text-bambu-gray/50`})})]}),r?(0,K.jsxs)(`form`,{className:`flex items-center gap-2`,onSubmit:e=>{e.preventDefault(),c()},children:[(0,K.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,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:n}),(0,K.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,K.jsx)(`button`,{type:`button`,onClick:l,disabled:u,className:`px-2 py-1 text-xs text-bambu-gray hover:text-white`,children:f})]}):(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-lg font-semibold text-white`,children:i}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:n}),(0,K.jsx)(`button`,{onClick:s,className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,K.jsx)(wl,{className:`w-3 h-3`})})]})]})}function x$e({value:e,unit:t,editing:n,inputValue:r,dailyRateG:i,onInputChange:a,onUnitChange:o,onEdit:s,onSave:c,onCancel:l,isPending:u,saveLabel:d=`Save`,cancelLabel:f=`Cancel`,safetyMarginLabel:p=`Safety Margin`}){let{t:m}=$e(),h=t===`g`?e:i===null?null:Math.round(i*e),g=t===`days`?m(`forecast.safetyMarginHintDays`,{approx:h===null?``:m(`forecast.safetyMarginHintDaysApprox`,{g:h})}):m(`forecast.safetyMarginHintG`,{approx:i===null?``:m(`forecast.safetyMarginHintGApprox`,{days:Math.round(e/i)})});return(0,K.jsxs)(`div`,{className:`bg-bambu-dark-tertiary/40 rounded-lg p-3 space-y-1`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,K.jsx)(`span`,{className:`text-xs font-medium text-white`,children:p}),(0,K.jsx)(`span`,{title:g,children:(0,K.jsx)(Rc,{className:`w-3 h-3 text-bambu-gray/50`})})]}),n?(0,K.jsxs)(`form`,{className:`flex items-center gap-2 flex-wrap`,onSubmit:e=>{e.preventDefault(),c()},children:[(0,K.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:u}),(0,K.jsxs)(`div`,{className:`flex bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded overflow-hidden text-xs`,children:[(0,K.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,K.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,K.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,K.jsx)(`button`,{type:`button`,onClick:l,disabled:u,className:`px-2 py-1 text-xs text-bambu-gray hover:text-white`,children:f})]}):(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-lg font-semibold text-white`,children:e}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:t}),h!==null&&t===`days`&&(0,K.jsxs)(`span`,{className:`text-lg font-semibold text-white`,children:[`≈ `,h,`g`]}),t===`g`&&i!==null&&(0,K.jsxs)(`span`,{className:`text-lg font-semibold text-white`,children:[`≈ `,Math.round(e/i),`d`]}),(0,K.jsx)(`button`,{onClick:s,className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,K.jsx)(wl,{className:`w-3 h-3`})})]})]})}function S$e({items:e,forecasts:t,globalLeadTime:n,canWrite:r,onClose:i,onRemove:a,onClear:o}){let{t:s}=$e(),c=ao(),[l,u]=(0,y.useState)(`list`),d=J({mutationFn:async({id:e,status:t,item:n,avgSpoolG:r})=>{if(await Q.updateShoppingListStatus(e,t),t===`received`&&n){let t=r??1e3,i={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};await Q.bulkCreateSpools(i,n.quantity_spools),await Q.removeFromShoppingList(e)}},onSuccess:()=>{c.invalidateQueries({queryKey:[`shopping-list`]}),c.invalidateQueries({queryKey:[`spools`]})}}),f=(0,y.useMemo)(()=>{let e=new Map;for(let n of t)e.set(n.group.key,n);return e},[t]),p=(0,y.useMemo)(()=>e.map(e=>({item:e,forecast:f.get(f9(e.material,e.subtype,e.brand,e.color_name))??null})),[e,f]),m=(0,y.useMemo)(()=>p.filter(({forecast:e})=>!e||e.dailyRateG===null?!1:e.stockBreakAlert||e.daysRemaining!==null&&e.daysRemaining<=e.effectiveLeadTimeDays),[p]);function h(){let t=[s(`forecast.qty`),s(`forecast.material`),s(`inventory.brand`),s(`inventory.subtype`),s(`inventory.color`),`${s(`forecast.weight`)} (g)`,`${s(`forecast.leadTime`)} (d)`,s(`forecast.expectedRestock`),s(`forecast.status`),s(`forecast.note`)],r=e.map(e=>{let t=f.get(f9(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?m9(p9(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),c=document.createElement(`a`);c.href=o,c.download=`shopping-list-${new Date().toISOString().slice(0,10)}.csv`,c.click(),setTimeout(()=>URL.revokeObjectURL(o),100)}return(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-dark-tertiary`,children:[(0,K.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,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(tu,{className:`w-4 h-4 text-bambu-green`}),(0,K.jsx)(`h3`,{className:`text-sm font-semibold text-white`,children:s(`forecast.shoppingList`)}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:s(`forecast.shoppingListItems`,{count:e.length})}),e.length>0&&(0,K.jsxs)(`div`,{className:`flex bg-bambu-dark-tertiary rounded-md p-0.5 ml-1`,children:[(0,K.jsxs)(`button`,{onClick:()=>u(`list`),className:`flex items-center gap-1.5 px-2 py-0.5 text-xs font-medium rounded transition-colors ${l===`list`?`bg-bambu-dark-secondary text-white shadow`:`text-bambu-gray hover:text-white`}`,children:[(0,K.jsx)(vl,{className:`w-3 h-3`}),s(`forecast.listView`)]}),(0,K.jsxs)(`button`,{onClick:()=>u(`logistics`),className:`flex items-center gap-1.5 px-2 py-0.5 text-xs font-medium rounded transition-colors ${l===`logistics`?`bg-bambu-dark-secondary text-white shadow`:`text-bambu-gray hover:text-white`}`,children:[(0,K.jsx)(is,{className:`w-3 h-3`}),s(`forecast.logisticsView`),m.length>0&&(0,K.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:m.length})]})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.length>0&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`button`,{onClick:h,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,K.jsx)(Gs,{className:`w-3 h-3`}),s(`forecast.downloadCsv`)]}),r&&(0,K.jsx)(`button`,{onClick:o,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:s(`forecast.clearAll`)})]}),(0,K.jsx)(`button`,{onClick:i,className:`p-1 text-bambu-gray hover:text-white transition-colors`,children:(0,K.jsx)(Ju,{className:`w-4 h-4`})})]})]}),e.length===0?(0,K.jsxs)(`div`,{className:`flex flex-col items-center py-8 text-bambu-gray`,children:[(0,K.jsx)(vl,{className:`w-8 h-8 mb-2 opacity-30`}),(0,K.jsx)(`p`,{className:`text-sm`,children:s(`forecast.shoppingListEmpty`)})]}):l===`list`?(0,K.jsx)(`div`,{className:`overflow-x-auto`,children:(0,K.jsxs)(`table`,{className:`w-full`,children:[(0,K.jsx)(`thead`,{children:(0,K.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary bg-bambu-dark-tertiary/20`,children:[(0,K.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:s(`forecast.qty`)}),(0,K.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:s(`forecast.material`)}),(0,K.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:s(`forecast.weight`)}),(0,K.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:s(`forecast.leadTime`)}),(0,K.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:s(`forecast.expectedRestock`)}),(0,K.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:s(`forecast.status`)}),(0,K.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:s(`forecast.note`)}),(0,K.jsx)(`th`,{className:`px-4 py-2 text-right text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:s(`forecast.actions`)})]})}),(0,K.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(` `),i=m.some(t=>t.item.id===e.id),o=f.get(f9(e.material,e.subtype,e.brand,e.color_name))??null,c=o&&o.totalSpools>0?o.totalLabelG/o.totalSpools:1e3,l=Math.round(e.quantity_spools*c),u=o?.effectiveLeadTimeDays??n??0,p=u>0?p9(new Date,u):null,h=e.status===`purchased`||e.status===`received`,g=e.status===`received`,_=d.isPending;return(0,K.jsxs)(`tr`,{className:`hover:bg-bambu-dark-tertiary/30 transition-colors ${i&&!h?`bg-red-500/5`:``}`,children:[(0,K.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,K.jsxs)(`span`,{className:`text-sm font-semibold text-bambu-green`,children:[e.quantity_spools,`×`]})}),(0,K.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-sm text-white`,children:t}),i&&!h&&(0,K.jsx)(Au,{className:`w-3.5 h-3.5 text-red-600 dark:text-red-400 flex-shrink-0`,"aria-label":s(`forecast.stockBreakBefore`)})]})}),(0,K.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,K.jsx)(`span`,{className:`text-sm text-white`,children:l>=1e3?`${(l/1e3).toFixed(1)}kg`:`${l}g`})}),(0,K.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:u>0?`${u}d`:`—`})}),(0,K.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:p?m9(p):`—`})}),(0,K.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,K.jsx)(`span`,{className:`inline-flex items-center px-2 py-0.5 rounded text-xs font-medium ${g?`bg-bambu-green/20 text-bambu-green`:h?`bg-blue-100 dark:bg-blue-400/20 text-blue-700 dark:text-blue-400`:`bg-bambu-dark-tertiary text-bambu-gray`}`,children:s(g?`forecast.received`:h?`forecast.purchased`:`forecast.pending`)})}),(0,K.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:e.note||`—`})}),(0,K.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,K.jsx)(`div`,{className:`flex items-center justify-end gap-1`,children:r&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`button`,{onClick:()=>d.mutate({id:e.id,status:h?`pending`:`purchased`}),disabled:_||g,title:s(h?`forecast.resetToPending`:`forecast.markPurchased`),className:`p-1.5 rounded transition-colors disabled:opacity-30 ${h?`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:h?(0,K.jsx)(Ll,{className:`w-4 h-4`}):(0,K.jsx)(Rs,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>d.mutate({id:e.id,status:`received`,item:e,avgSpoolG:c}),disabled:_||!h||g,title:s(`forecast.markReceived`),className:`p-1.5 rounded transition-colors text-bambu-green/50 hover:text-bambu-green disabled:opacity-30`,children:(0,K.jsx)(gl,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>a(e.id),className:`p-1 text-bambu-gray hover:text-red-600 dark:hover:text-red-400 transition-colors`,title:s(`forecast.remove`),children:(0,K.jsx)(Du,{className:`w-3.5 h-3.5`})})]})})})]},e.id)})})]})}):(0,K.jsx)(`div`,{className:`divide-y divide-bambu-dark-tertiary`,children:p.filter(({item:e})=>e.status!==`received`).map(({item:e,forecast:t})=>(0,K.jsx)(C$e,{item:e,forecast:t,globalLeadTime:n,canWrite:r,onRemove:()=>a(e.id)},e.id))})]})}function C$e({item:e,forecast:t,globalLeadTime:n,canWrite:r,onRemove:i}){let{t:a}=$e(),o=[e.brand,e.material,e.subtype,e.color_name].filter(Boolean).join(` `),s=(0,y.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=h9(p9(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,K.jsx)(yz,{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,K.jsx)(ZV,{type:`linear`,dataKey:`stock`,stroke:`#1DB954`,strokeWidth:2,fill:`url(#cart-post-${e.id})`,dot:!1,activeDot:{r:3}}),t.reorderPointG>0&&(0,K.jsx)(xV,{y:t.reorderPointG,stroke:`#F59E0B`,strokeDasharray:`5 3`,strokeOpacity:.8,label:{value:`ROP`,position:`insideTopRight`,fill:`#F59E0B`,fontSize:9}}),t.safetyStockG>0&&(0,K.jsx)(xV,{y:t.safetyStockG,stroke:`#6B7280`,strokeDasharray:`3 3`,strokeOpacity:.6,label:{value:`SS`,position:`insideTopRight`,fill:`#6B7280`,fontSize:9}}),(0,K.jsx)(xV,{x:h9(p9(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}}),c!==null&&(0,K.jsx)(xV,{x:h9(p9(new Date,c)),stroke:`#EF4444`,strokeWidth:1.5,strokeOpacity:.9,label:{value:`OUT`,position:`insideTopLeft`,fill:`#EF4444`,fontSize:9}})]})}),(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 mt-2 text-[10px] text-bambu-gray`,children:[(0,K.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(`span`,{className:`inline-block w-4 border-t-2 border-yellow-400 border-dashed`}),` `,a(`forecast.ropLabel`)]}),(0,K.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(`span`,{className:`inline-block w-4 border-t border-bambu-gray border-dashed`}),` `,a(`forecast.safetyStockLegend`)]}),(0,K.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(`span`,{className:`inline-block w-4 border-t-2 border-blue-400 border-dashed`}),` `,a(`forecast.stockArrivalLegend`)]}),l&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-red-700 dark:text-red-400`,children:[(0,K.jsx)(`span`,{className:`inline-block w-4 border-t-2 border-red-400`}),` `,a(`forecast.stockoutLegend`)]})]})]}):null]})}function w$e({forecast:e,onClose:t,onAdd:n}){let{t:r}=$e(),i=[e.group.brand,e.group.material,e.group.subtype,e.group.colorName].filter(Boolean).join(` `),[a,o]=(0,y.useState)(`qty`),[s,c]=(0,y.useState)(`1`),[l,u]=(0,y.useState)(`30`),[d,f]=(0,y.useState)(``),p=(0,y.useMemo)(()=>{if(!e.dailyRateG||e.dailyRateG<=0)return null;let t=e.dailyRateG*Number(l),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,l]),m=a===`qty`?parseInt(s,10)||1:p??1;function h(t){t.preventDefault(),n({material:e.group.material,subtype:e.group.subtype,brand:e.group.brand,color_name:e.group.colorName,quantity_spools:m,note:d||null})}return(0,K.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm p-4`,children:(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-2xl border border-bambu-dark-tertiary w-full max-w-sm shadow-2xl`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between px-5 pt-5 pb-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(tu,{className:`w-5 h-5 text-bambu-green`}),(0,K.jsx)(`h2`,{className:`text-base font-semibold text-white`,children:r(`forecast.addToCartTitle`)})]}),(0,K.jsx)(`button`,{onClick:t,className:`p-1 text-bambu-gray hover:text-white transition-colors`,children:(0,K.jsx)(Ju,{className:`w-5 h-5`})})]}),(0,K.jsxs)(`form`,{onSubmit:h,className:`p-5 space-y-4`,children:[(0,K.jsx)(`div`,{className:`text-sm text-bambu-gray`,children:i}),(0,K.jsxs)(`div`,{className:`flex bg-bambu-dark-tertiary rounded-lg p-0.5`,children:[(0,K.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,K.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,K.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,K.jsx)(`label`,{className:`text-xs text-bambu-gray`,children:r(`forecast.numberOfSpools`)}),(0,K.jsx)(`input`,{type:`number`,min:1,max:99,value:s,onChange:e=>c(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,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,K.jsx)(`label`,{className:`text-xs text-bambu-gray`,children:r(`forecast.lastHowManyDays`)}),(0,K.jsx)(`input`,{type:`number`,min:1,max:365,value:l,onChange:e=>u(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,K.jsx)(`div`,{className:`text-xs text-yellow-700 dark:text-yellow-400 px-1`,children:r(`forecast.noUsageQty`)}):(0,K.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2 bg-bambu-dark-tertiary/50 rounded-lg`,children:[(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:`≈`}),(0,K.jsx)(`span`,{className:`text-sm font-semibold text-bambu-green`,children:r(`forecast.spoolCount`,{count:p??0})}),(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[`at `,e.dailyRateG.toFixed(1),`g/day`]})]})]}),(0,K.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,K.jsx)(`label`,{className:`text-xs text-bambu-gray`,children:r(`forecast.noteOptional`)}),(0,K.jsx)(`input`,{type:`text`,maxLength:200,value:d,onChange:e=>f(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,K.jsxs)(`div`,{className:`flex items-center gap-3 pt-1`,children:[(0,K.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:m})}),(0,K.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`)})]})]})]})})}var _9={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,location_id:null,spoolman_filament_id:null},T$e=new Set([`material`,`subtype`,`brand`,`rgba`,`color_name`,`label_weight`]);function E$e(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})}function D$e(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 v9({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 O$e({formData:e,updateField:t,cloudAuthenticated:n,loadingCloudPresets:r,presetInputValue:i,setPresetInputValue:a,selectedPresetOption:o,filamentOptions:s,availableBrands:c,availableMaterials:l,suggestedBrands:u,suggestedMaterials:d,quickAdd:f,detailsRequired:p,quantity:m,onQuantityChange:h,errors:g}){let{t:_}=$e(),[v,b]=(0,y.useState)(!1),[x,S]=(0,y.useState)(!1),[C,w]=(0,y.useState)(!1),[T,E]=(0,y.useState)(!1),[D,O]=(0,y.useState)(``),[k,A]=(0,y.useState)(``),[j,M]=(0,y.useState)(``),[N,P]=(0,y.useState)(String(e.label_weight)),[F,I]=(0,y.useState)(!1),[L,R]=(0,y.useState)(new Set),z=(0,y.useRef)(null),B=(0,y.useRef)(null),V=(0,y.useRef)(null),ee=(0,y.useRef)(null);(0,y.useEffect)(()=>{let e=e=>{z.current&&!z.current.contains(e.target)&&b(!1),ee.current&&!ee.current.contains(e.target)&&E(!1),B.current&&!B.current.contains(e.target)&&S(!1),V.current&&!V.current.contains(e.target)&&w(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[]);let te=(0,y.useMemo)(()=>{if(!i)return s;let e=i.toLowerCase();return s.filter(t=>t.displayName.toLowerCase().includes(e)||t.code.toLowerCase().includes(e))},[s,i]),H=(0,y.useMemo)(()=>{if(!D)return c;let e=D.toLowerCase();return c.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)})},[c,D]),ne=(0,y.useMemo)(()=>{if(!k)return TU;let e=k.toLowerCase();return TU.filter(t=>t.toLowerCase().includes(e))},[k]),re=(0,y.useMemo)(()=>{if(!j)return l;let e=j.toLowerCase();return l.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)})},[j,l]),U=(0,y.useMemo)(()=>D$e(H,u),[H,u]),ie=(0,y.useMemo)(()=>D$e(re,d),[re,d]);(0,y.useEffect)(()=>{F||P(String(e.label_weight))},[e.label_weight,F]);let ae=n=>{t(`slicer_filament`,n.code),a(n.displayName),b(!1);let r=AU(n.name),i=new Set,o=[[`material`,r.material],[`brand`,r.brand],[`subtype`,r.variant]];for(let[n,r]of o)r&&(e[n]&&!L.has(n)||(t(n,r),i.add(n)));R(i)},W=(e,n)=>{L.has(e)&&R(t=>{let n=new Set(t);return n.delete(e),n}),t(e,n)},oe=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:()=>{W(`brand`,t),S(!1),O(``)},children:t},t),se=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:()=>{W(`material`,t),E(!1),M(``)},children:t},t);return(0,K.jsxs)(`div`,{className:`space-y-4`,children:[!f&&(0,K.jsx)(`div`,{className:`flex items-center gap-2 text-xs text-bambu-gray`,children:r?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(X,{className:`w-3 h-3 animate-spin`}),` `,_(`inventory.loadingPresets`)]}):n?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Os,{className:`w-3 h-3 text-bambu-green`}),` `,_(`inventory.cloudConnected`)]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Es,{className:`w-3 h-3`}),` `,_(`inventory.cloudNotConnected`)]})}),!f&&(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:[_(`inventory.slicerPreset`),p&&` *`]}),(0,K.jsxs)(`div`,{className:`relative`,ref:z,children:[(0,K.jsx)(Gl,{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:_(`inventory.searchPresets`),value:i,onChange:e=>{a(e.target.value),b(!0)},onFocus:()=>{b(!0),a(``)}}),v&&(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:te.length===0?(0,K.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:_(`inventory.noPresetsFound`)}):te.map(e=>(0,K.jsx)(`button`,{type:`button`,className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary truncate ${o?.code===e.code?`bg-bambu-green/10 text-bambu-green`:`text-white`}`,onClick:()=>ae(e),children:e.displayName},`${e.code}::${e.name}`))})]}),o&&(0,K.jsxs)(`div`,{className:`mt-1 text-xs text-bambu-gray`,children:[_(`inventory.selectedPreset`),`: `,(0,K.jsx)(`span`,{className:`font-mono text-bambu-green`,children:o.code})]}),g?.slicer_filament&&(0,K.jsx)(`p`,{className:`mt-1 text-xs text-red-700 dark:text-red-400`,children:g.slicer_filament})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:[_(`inventory.material`),` *`]}),(0,K.jsxs)(`div`,{className:`relative`,ref:ee,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:_(`inventory.selectMaterial`),value:T?j:e.material,onChange:e=>{M(e.target.value),E(!0)},onFocus:()=>{E(!0),M(``)}}),(0,K.jsx)(cs,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50 pointer-events-none`}),T&&(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:[re.length===0?(0,K.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:_(`inventory.noResults`)}):(0,K.jsxs)(K.Fragment,{children:[ie.top.length>0&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(v9,{label:_(`inventory.suggestedOptions`)}),ie.top.map(se)]}),ie.rest.length>0&&(0,K.jsxs)(K.Fragment,{children:[ie.top.length>0&&(0,K.jsx)(v9,{label:_(`inventory.allOptions`)}),ie.rest.map(se)]})]}),j&&!re.includes(j)&&(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:()=>{W(`material`,j),E(!1),M(``)},children:_(`inventory.useCustomMaterial`,{material:j})})]})]}),g?.material&&(0,K.jsx)(`p`,{className:`mt-1 text-xs text-red-700 dark:text-red-400`,children:g.material})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:[_(`inventory.brand`),p&&` *`]}),(0,K.jsxs)(`div`,{className:`relative`,ref:B,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:_(`inventory.searchBrand`),value:x?D:e.brand,onChange:e=>{O(e.target.value),S(!0)},onFocus:()=>{S(!0),O(``)}}),(0,K.jsx)(cs,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50 pointer-events-none`}),x&&(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:[H.length===0?(0,K.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:_(`inventory.noResults`)}):(0,K.jsxs)(K.Fragment,{children:[U.top.length>0&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(v9,{label:_(`inventory.suggestedOptions`)}),U.top.map(oe)]}),U.rest.length>0&&(0,K.jsxs)(K.Fragment,{children:[U.top.length>0&&(0,K.jsx)(v9,{label:_(`inventory.allOptions`)}),U.rest.map(oe)]})]}),D&&!H.includes(D)&&(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:()=>{W(`brand`,D),S(!1),O(``)},children:_(`inventory.useCustomBrand`,{brand:D})})]})]}),g?.brand&&(0,K.jsx)(`p`,{className:`mt-1 text-xs text-red-700 dark:text-red-400`,children:g.brand})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:[_(`inventory.subtype`),p&&` *`]}),(0,K.jsxs)(`div`,{className:`relative`,ref:V,children:[(0,K.jsx)(`input`,{type:`text`,value:C?k:e.subtype,onChange:e=>{A(e.target.value),w(!0)},onFocus:()=>{w(!0),A(``)},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)(cs,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50 pointer-events-none`}),C&&(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:[ne.length===0?(0,K.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:_(`inventory.noResults`)}):ne.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:()=>{W(`subtype`,t),w(!1),A(``)},children:t},t)),k&&!TU.some(e=>e.toLowerCase()===k.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:()=>{W(`subtype`,k),w(!1),A(``)},children:_(`inventory.useCustomBrand`,{brand:k})})]})]}),g?.subtype&&(0,K.jsx)(`p`,{className:`mt-1 text-xs text-red-700 dark:text-red-400`,children:g.subtype})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:_(`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:N,min:0,onFocus:()=>I(!0),onChange:e=>P(e.target.value),onBlur:()=>{I(!1);let n=N.trim(),r=Number(n);if(!n||!Number.isFinite(r)||r<0){P(String(e.label_weight));return}let i=Math.round(r);t(`label_weight`,i),P(String(i))}}),(0,K.jsx)(`span`,{className:`absolute right-2 top-1/2 -translate-y-1/2 text-xs text-bambu-gray`,children:`g`})]})]}),f&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:_(`inventory.quantity`)}),(0,K.jsx)(`input`,{type:`number`,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:m,min:1,max:100,onChange:e=>{h(Math.max(1,Math.min(100,parseInt(e.target.value)||1)))}})]})]})}function k$e(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 A$e({formData:e,updateField:t,recentColors:n,onColorUsed:r,catalogColors:i}){let{t:a}=$e(),[o,s]=(0,y.useState)(!1),[c,l]=(0,y.useState)(``),u=(e.rgba.replace(`#`,``)+`FF`).substring(0,8).toUpperCase(),d=u.substring(0,6),f=u.substring(6,8)===`00`,[p,m]=(0,y.useState)(f?u:d);(0,y.useEffect)(()=>{m(f?u:d)},[d,u,f]);let h=e=>u===(e.replace(`#`,``)+`FF`).substring(0,8).toUpperCase(),g=e=>_f(e),_=(e,n,i,a)=>{let o=e.replace(`#`,``).toUpperCase();if(t(`rgba`,o.length===8?o:o+`FF`),t(`color_name`,n),i!==void 0){let e=i??``;w(e),E([]),D.current=e,t(`extra_colors`,e)}a!==void 0&&t(`effect_type`,a??``),r({name:n,hex:e})},v=(0,y.useMemo)(()=>{if(i.length===0)return[];let t=e.brand?.trim(),n=e.material?.toLowerCase().trim(),r=e.subtype?.toLowerCase().trim();if(!t&&!n)return[];let a=t?t.toLowerCase().split(/[\s\-_]+/).filter(e=>e.length>=2):[],o=e=>{if(a.length===0)return!0;let t=e.toLowerCase();return a.some(e=>t.includes(e))};if(t&&!n){let e=i.filter(e=>o(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 s=n&&r?`${n} ${r}`:``;if(s){let e=i.filter(e=>o(e.manufacturer)&&e.material?.toLowerCase()===s);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=s.replace(/\+$/,``);if(t!==s){let e=i.filter(e=>o(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=i.filter(e=>o(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[]},[i,e.brand,e.material,e.subtype]),b=(0,y.useMemo)(()=>{if(!c)return v;if(v.length===0)return[];let e=c.toLowerCase();return v.filter(t=>t.name.toLowerCase().includes(e)||(t.manufacturer?.toLowerCase().includes(e)??!1)||(t.material?.toLowerCase().includes(e)??!1))},[c,v]),x=v.length>0,S=(0,y.useMemo)(()=>c?DU.filter(e=>e.name.toLowerCase().includes(c.toLowerCase())):o?DU:EU,[c,o]),[C,w]=(0,y.useState)(e.extra_colors),[T,E]=(0,y.useState)([]),D=(0,y.useRef)(e.extra_colors);(0,y.useEffect)(()=>{e.extra_colors!==D.current&&(w(e.extra_colors),E([]),D.current=e.extra_colors)},[e.extra_colors]);let O=(0,y.useMemo)(()=>S6({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]),k=e=>{if(w(e),!e.trim()){E([]),D.current=``,t(`extra_colors`,``);return}let{value:n,invalid:r}=k$e(e);E(r),D.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:O,"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)(Ts,{className:`w-3 h-3`}),(0,K.jsx)(`span`,{children:a(`inventory.recentColors`)})]}),(0,K.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:n.map(e=>(0,K.jsx)(`button`,{type:`button`,onClick:()=>_(e.hex,e.name),className:`w-6 h-6 rounded border-2 transition-all hover:scale-110 ${h(e.hex)?`border-bambu-green ring-1 ring-bambu-green/30 scale-110`:`border-bambu-dark-tertiary`}`,style:g(e.hex),title:e.name},e.hex))})]}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(Gl,{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:a(`inventory.searchColors`),value:c,onChange:e=>l(e.target.value)})]}),x?(0,K.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:c?a(`inventory.searchResults`):`${e.brand}${e.material?` ${e.material}`:``}`}),(0,K.jsxs)(`div`,{className:`flex flex-wrap gap-1.5`,children:[b.map(e=>(0,K.jsx)(`button`,{type:`button`,onClick:()=>_(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 ${h(e.hex)?`border-bambu-green ring-1 ring-bambu-green/30 scale-110`:`border-bambu-dark-tertiary`}`,style:g(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??``}`)),b.length===0&&(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray py-1`,children:a(`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:a(c?`inventory.searchResults`:o?`inventory.allColors`:`inventory.commonColors`)}),!c&&(0,K.jsx)(`button`,{type:`button`,onClick:()=>s(!o),className:`flex items-center gap-1 hover:text-white transition-colors`,children:o?(0,K.jsxs)(K.Fragment,{children:[a(`inventory.showLess`),` `,(0,K.jsx)(ds,{className:`w-3 h-3`})]}):(0,K.jsxs)(K.Fragment,{children:[a(`inventory.showAll`),` `,(0,K.jsx)(cs,{className:`w-3 h-3`})]})})]}),(0,K.jsxs)(`div`,{className:`flex flex-wrap gap-1.5`,children:[S.map(e=>(0,K.jsx)(`button`,{type:`button`,onClick:()=>_(e.hex,e.name),className:`w-6 h-6 rounded border-2 transition-all hover:scale-110 hover:z-20 relative group ${h(e.hex)?`border-bambu-green ring-1 ring-bambu-green/30 scale-110`:`border-bambu-dark-tertiary`}`,style:g(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)),S.length===0&&(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray py-1`,children:a(`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:a(`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:a(`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:a(`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:p.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;m(r),r.length===6?t(`rgba`,r+`FF`):r.length===8&&t(`rgba`,r)},onBlur:()=>{if(p.length===7){let e=p+`0`;m(e),t(`rgba`,e)}else if(p.length>0&&p.length<6){let e=p.padEnd(6,`0`);m(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:`#${d}`,onChange:e=>{t(`rgba`,e.target.value.replace(`#`,``).toUpperCase()+`FF`)},title:a(`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:a(`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:a(`inventory.extraColorsPlaceholder`),value:C,onChange:e=>k(e.target.value),"data-testid":`extra-colors-input`}),T.length>0&&(0,K.jsx)(`p`,{className:`text-xs text-red-700 dark:text-red-400 mt-1`,children:a(`inventory.extraColorsInvalid`,{tokens:T.join(`, `)})}),!T.length&&(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray/70 mt-1`,children:a(`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)(uu,{className:`w-3.5 h-3.5`}),a(`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:y6.map(e=>(0,K.jsx)(`option`,{value:e.value,children:a(e.labelKey)},e.value||`none`))}),(0,K.jsx)(C6,{rgba:e.rgba,extraColors:e.extra_colors,effectType:e.effect_type,subtype:e.subtype,effectSize:`preview`,className:`w-10 h-10`,shape:`square`})]})]})]})]})}function j$e({catalog:e,value:t,onChange:n,catalogId:r,onCatalogIdChange:i}){let{t:a}=$e(),[o,s]=(0,y.useState)(!1),[c,l]=(0,y.useState)(``),u=(0,y.useRef)(null),d=(0,y.useRef)(null);(0,y.useEffect)(()=>{let e=e=>{u.current&&!u.current.contains(e.target)&&s(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[]),(0,y.useEffect)(()=>{if(e.length===0)return;let n=e.filter(e=>e.weight===t);if(r){let n=e.find(e=>e.id===r);if(n&&n.weight===t)return}n.length===1?i(n[0].id):n.length===0&&r!==null&&i(null)},[t,e,r,i]);let f=(0,y.useMemo)(()=>{if(!c)return e;let t=c.toLowerCase();return e.filter(e=>e.name.toLowerCase().includes(t)||e.weight.toString().includes(t))},[e,c]),p=(0,y.useMemo)(()=>e.filter(e=>e.weight===t),[e,t]),m=(0,y.useMemo)(()=>{if(o)return c;if(r){let t=e.find(e=>e.id===r);if(t)return t.name}return p.length>0?p[0].name:``},[o,c,r,e,p]);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)(Vl,{className:`w-3.5 h-3.5 text-bambu-gray`}),a(`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:u,children:[(0,K.jsx)(`input`,{ref:d,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:a(`inventory.searchSpoolWeight`),value:m,onFocus:()=>{s(!0),l(``)},onChange:e=>{l(e.target.value),s(!0)}}),o&&(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:f.length===0?(0,K.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:a(`inventory.noResults`)}):f.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 ${(r?e.id===r:e.weight===t)?`bg-bambu-green/10 text-bambu-green`:`text-white`}`,onClick:()=>{i(e.id),n(e.weight),s(!1),l(``)},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 M$e({formData:e,updateField:t,spoolCatalog:n,currencySymbol:r,availableCategories:i,availableLocations:a=[],onCreateLocation:o,globalLowStockThreshold:s,spoolmanMode:c=!1}){let{t:l}=$e(),{showToast:u}=Fd(),[d,f]=(0,y.useState)(``),[p,m]=(0,y.useState)(!1),[h,g]=(0,y.useState)(``),[_,v]=(0,y.useState)(!1),[b,x]=(0,y.useState)(``),[S,C]=(0,y.useState)(!1),w=Math.max(0,e.label_weight-e.weight_used),T=e.core_weight+w;return(0,y.useEffect)(()=>{p||f(String(T))},[p,T]),(0,y.useEffect)(()=>{_||g(String(w))},[_,w]),(0,K.jsxs)(`div`,{className:`space-y-4`,children:[c?(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray px-1`,children:l(`inventory.spoolWeightManagedBySpoolman`)}):(0,K.jsx)(j$e,{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:l(`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:h,min:0,max:e.label_weight,onFocus:()=>v(!0),onChange:e=>{g(e.target.value)},onBlur:()=>{v(!1);let n=h.trim(),r=Number(n);if(!n||!Number.isFinite(r)||r<0||r>e.label_weight){g(String(w));return}let i=Math.round(r);t(`weight_used`,Math.max(0,e.label_weight-i)),g(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:l(`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:d,min:0,onFocus:()=>m(!0),onChange:e=>{f(e.target.value)},onBlur:()=>{m(!1);let n=d.trim(),r=Number(n),i=e.core_weight,a=e.core_weight+e.label_weight;if(!n||!Number.isFinite(r)||ra){u(l(`inventory.measuredWeightError`,{min:i,max:a}),`error`),f(String(T));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)),f(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:l(`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:r}),(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,r.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`})]})})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,htmlFor:`spool-category`,children:l(`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:l(`inventory.categoryPlaceholder`),value:e.category,maxLength:50,onChange:e=>t(`category`,e.target.value)}),i.length>0&&(0,K.jsx)(`datalist`,{id:`spool-category-options`,children:i.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:l(`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(s),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:l(`inventory.lowStockThresholdOverrideHelp`,{global:s})})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:l(`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:l(`inventory.notePlaceholder`),value:e.note,onChange:e=>t(`note`,e.target.value)})]}),(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:l(`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:l(`inventory.storageLocationNone`)}),a.map(e=>(0,K.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),o&&(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:l(`locations.createPlaceholder`),value:b,onChange:e=>x(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:!b.trim()||S,onClick:async()=>{let e=b.trim();if(!(!e||!o)){C(!0);try{let n=await o(e);n&&(t(`location_id`,n.id),x(``))}finally{C(!1)}}},children:l(`locations.addShort`)})]})]})]})}function N$e({filaments:e,isLoading:t,selectedId:n,onSelect:r}){let{t:i}=$e(),[a,o]=(0,y.useState)(!1),[s,c]=(0,y.useState)(``),l=(0,y.useRef)(null),u=(0,y.useRef)(null),d=(0,y.useMemo)(()=>e.find(e=>e.id===n)??null,[e,n]);(0,y.useEffect)(()=>{let e=e=>{l.current&&!l.current.contains(e.target)&&(o(!1),c(``))};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[]);let f=(0,y.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,y.useEffect)(()=>{a&&u.current?.focus()},[a]);let p=()=>{o(!0),c(``)},m=e=>{r(e),o(!1),c(``)},h=e=>e?`#${e.replace(`#`,``)}`:`#808080`;return(0,K.jsxs)(`div`,{ref:l,className:`relative`,children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:i(`inventory.pickFromSpoolmanCatalog`)}),(0,K.jsxs)(`button`,{type:`button`,onClick:p,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,K.jsx)(X,{className:`w-4 h-4 text-bambu-gray animate-spin shrink-0`}):d?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`span`,{className:`w-4 h-4 rounded-full shrink-0 border border-white/20`,style:{backgroundColor:h(d.color_hex)},"aria-label":i(`inventory.spoolmanFilamentColorSwatch`)}),(0,K.jsxs)(`span`,{className:`text-white text-sm truncate flex-1`,children:[d.vendor?.name?`${d.vendor.name} — `:``,d.name]})]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(vl,{className:`w-4 h-4 text-bambu-gray shrink-0`}),(0,K.jsx)(`span`,{className:`text-bambu-gray text-sm flex-1`,children:i(`inventory.spoolmanFilamentCatalog`)})]}),(0,K.jsx)(cs,{className:`w-4 h-4 text-bambu-gray shrink-0 ml-auto`})]}),a&&(0,K.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,K.jsx)(`div`,{className:`p-2 border-b border-bambu-dark-tertiary`,children:(0,K.jsx)(`input`,{ref:u,type:`text`,value:s,onChange:e=>c(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,K.jsx)(`ul`,{className:`max-h-56 overflow-y-auto py-1`,children:t?(0,K.jsxs)(`li`,{className:`flex items-center justify-center gap-2 py-4 text-bambu-gray text-sm`,children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),(0,K.jsx)(`span`,{children:i(`common.loading`,`Loading…`)})]}):f.length===0?(0,K.jsx)(`li`,{className:`py-4 text-center text-bambu-gray text-sm`,children:i(`inventory.noSpoolmanFilaments`)}):f.map(e=>(0,K.jsx)(`li`,{children:(0,K.jsxs)(`button`,{type:`button`,onClick:()=>m(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,K.jsx)(`span`,{className:`w-4 h-4 rounded-full shrink-0 border border-white/20`,style:{backgroundColor:h(e.color_hex)},"aria-label":i(`inventory.spoolmanFilamentColorSwatch`)}),(0,K.jsxs)(`span`,{className:`flex-1 min-w-0`,children:[(0,K.jsxs)(`span`,{className:`block text-white text-sm truncate`,children:[e.vendor?.name?`${e.vendor.name} — `:``,e.name]}),(0,K.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 P$e({formData:e,printersWithCalibrations:t,selectedProfiles:n,setSelectedProfiles:r,expandedPrinters:i,setExpandedPrinters:a}){let{t:o}=$e(),s=e=>{a(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},c=(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})},l=()=>{let n=new Set;for(let{printer:r,calibrations:i}of t){if(!r.connected)continue;let t=i.filter(t=>BU(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,K.jsx)(`div`,{className:`p-6 bg-bambu-dark rounded-lg text-center`,children:(0,K.jsx)(`p`,{className:`text-bambu-gray`,children:o(`inventory.selectMaterialFirst`)})});if(t.length===0)return(0,K.jsx)(`div`,{className:`p-6 bg-bambu-dark rounded-lg text-center`,children:(0,K.jsx)(`p`,{className:`text-bambu-gray`,children:o(`inventory.noPrintersConfigured`)})});let u=t.reduce((t,{printer:n,calibrations:r})=>n.connected?t+r.filter(t=>BU(t,e)).length:t,0),d=(e,t)=>{let r=`${e.id}:${t.cali_idx}:${t.extruder_id??`null`}`,i=n.has(r);return(0,K.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,K.jsx)(`input`,{type:`checkbox`,checked:i,onChange:()=>c(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,K.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,K.jsx)(`span`,{className:`text-sm font-medium ${i?`text-bambu-green`:`text-white`}`,children:t.name||t.filament_id})}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[t.nozzle_diameter&&(0,K.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,K.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,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[o(`inventory.matchingFilter`),`: `,e.brand||o(`inventory.anyBrand`),` / `,e.material,` / `,e.subtype||o(`inventory.anyVariant`)]}),u>0&&(0,K.jsxs)(`button`,{type:`button`,onClick:l,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,K.jsx)(uu,{className:`w-3.5 h-3.5`}),o(`inventory.autoSelect`),` (`,u,`)`]})]}),(0,K.jsx)(`div`,{className:`space-y-3`,children:t.map(({printer:t,calibrations:n})=>{let r=i.has(String(t.id)),a=n.filter(t=>BU(t,e)),c=a.length,l=a.some(e=>e.extruder_id!==void 0&&e.extruder_id!==null&&e.extruder_id>0),u=a.filter(e=>e.extruder_id===1),f=a.filter(e=>e.extruder_id===0||e.extruder_id===void 0||e.extruder_id===null);return(0,K.jsxs)(`div`,{className:`border border-bambu-dark-tertiary rounded-lg overflow-hidden`,children:[(0,K.jsxs)(`button`,{type:`button`,onClick:()=>s(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,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[r?(0,K.jsx)(cs,{className:`w-4 h-4 text-bambu-gray`}):(0,K.jsx)(ls,{className:`w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`span`,{className:`font-medium text-white`,children:t.name}),c>0?(0,K.jsxs)(`span`,{className:`text-xs px-2 py-0.5 rounded-full bg-bambu-green/20 text-bambu-green`,children:[c,` `,o(c===1?`inventory.match`:`inventory.matches`)]}):(0,K.jsx)(`span`,{className:`text-xs px-2 py-0.5 rounded-full bg-bambu-dark-tertiary text-bambu-gray`,children:o(`inventory.noMatches`)})]}),(0,K.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?o(`inventory.connected`):o(`inventory.offline`)})]}),r&&(0,K.jsx)(`div`,{className:`px-4 py-3 space-y-3 bg-bambu-dark border-t border-bambu-dark-tertiary`,children:t.connected?c===0?(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray italic py-2`,children:o(`inventory.noKProfilesMatch`)}):l?(0,K.jsxs)(K.Fragment,{children:[u.length>0&&(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(`p`,{className:`text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:o(`inventory.leftNozzle`)}),(0,K.jsx)(`div`,{className:`space-y-2`,children:u.map(e=>d(t,e))})]}),f.length>0&&(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(`p`,{className:`text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:o(`inventory.rightNozzle`)}),(0,K.jsx)(`div`,{className:`space-y-2`,children:f.map(e=>d(t,e))})]})]}):(0,K.jsx)(`div`,{className:`space-y-2`,children:a.map(e=>d(t,e))}):(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray italic py-2`,children:o(`inventory.printerOffline`)})})]},t.id)})}),n.size>0&&(0,K.jsx)(`div`,{className:`p-3 bg-bambu-green/10 border border-bambu-green/30 rounded-lg`,children:(0,K.jsxs)(`p`,{className:`text-sm text-white`,children:[(0,K.jsx)(`span`,{className:`font-semibold`,children:n.size}),` `,o(`inventory.profilesSelected`)]})})]})}function F$e(e){let t=Hf(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 I$e={completed:`text-bambu-green`,failed:`text-red-700 dark:text-red-400`,aborted:`text-yellow-700 dark:text-yellow-400`};function L$e({spoolId:e}){let{t}=$e(),n=ao(),{showToast:r}=Fd(),{data:i,isLoading:a}=q({queryKey:[`spool-usage`,e],queryFn:()=>Q.getSpoolUsageHistory(e)}),o=J({mutationFn:()=>Q.clearSpoolUsageHistory(e),onSuccess:()=>{n.invalidateQueries({queryKey:[`spool-usage`,e]}),r(t(`inventory.historyCleared`),`success`)}});return a?(0,K.jsx)(`div`,{className:`flex justify-center py-4`,children:(0,K.jsx)(X,{className:`w-5 h-5 animate-spin text-bambu-green`})}):!i||i.length===0?(0,K.jsxs)(`div`,{className:`text-center py-4 text-bambu-gray text-sm`,children:[(0,K.jsx)(Ts,{className:`w-5 h-5 mx-auto mb-2 opacity-50`}),t(`inventory.noUsageHistory`)]}):(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsx)(`h4`,{className:`text-sm font-medium text-white`,children:t(`inventory.usageHistory`)}),(0,K.jsxs)($,{variant:`ghost`,size:`sm`,onClick:()=>o.mutate(),disabled:o.isPending,className:`text-xs text-bambu-gray hover:text-red-700 dark:hover:text-red-400`,children:[(0,K.jsx)(Du,{className:`w-3 h-3 mr-1`}),t(`inventory.clearHistory`)]})]}),(0,K.jsx)(`div`,{className:`max-h-48 overflow-y-auto space-y-1`,children:i.map(e=>(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-2 rounded bg-bambu-dark/50 text-xs`,children:[(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:F$e(e.created_at)}),e.print_name&&(0,K.jsx)(`span`,{className:`text-white ml-2 truncate`,title:e.print_name,children:e.print_name})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0 ml-2`,children:[(0,K.jsxs)(`span`,{className:`text-white font-medium`,children:[e.weight_used.toFixed(1),`g`]}),(0,K.jsxs)(`span`,{className:`text-bambu-gray`,children:[`(`,e.percent_used,`%)`]}),(0,K.jsx)(`span`,{className:I$e[e.status]||`text-bambu-gray`,children:e.status})]})]},e.id))})]})}var y9=[`inventory-locations`];function b9(e){return e.invalidateQueries({queryKey:y9})}function R$e(e,t){return Promise.all([e.invalidateQueries({queryKey:[...t]}),b9(e)])}var z$e={tag_uid:null,tray_uuid:null,tag_type:null,data_origin:null};function B$e({isOpen:e,onClose:t,spool:n,mode:r,printersWithCalibrations:i=[],currencySymbol:a,onSpoolsCreated:o,spoolmanMode:s=!1,spoolsQueryKey:c=[`inventory-spools`]}){let{t:l}=$e(),u=ao(),{showToast:d}=Fd(),f=()=>R$e(u,c),p=r===`edit`,m=r===`copy`,[h,g]=(0,y.useState)(_9),[_,v]=(0,y.useState)({}),[b,x]=(0,y.useState)(`filament`),[S,C]=(0,y.useState)(!1),[w,T]=(0,y.useState)(!1),[E,D]=(0,y.useState)(!1),[O,k]=(0,y.useState)(1),[A,j]=(0,y.useState)(!1),[M,N]=(0,y.useState)(!1),[P,F]=(0,y.useState)([]),[I,L]=(0,y.useState)(``),[R,z]=(0,y.useState)([]),[B,V]=(0,y.useState)([]),[ee,te]=(0,y.useState)([]),[H,ne]=(0,y.useState)([]),[re,U]=(0,y.useState)([]),[ie,ae]=(0,y.useState)([]),[W,oe]=(0,y.useState)([]),[se,ce]=(0,y.useState)(new Set),[le,ue]=(0,y.useState)(new Set),de=i.length>0?i:W,fe=se.size,{data:pe=[],isLoading:me,error:he}=q({queryKey:[`spoolman-inventory-filaments`],queryFn:()=>Q.getSpoolmanInventoryFilaments(),enabled:s&&e,staleTime:6e4,retry:!1});(0,y.useEffect)(()=>{ae(IU())},[]),(0,y.useEffect)(()=>{let t=!1;return e&&((async()=>{N(!0);try{let[e,n]=await Promise.allSettled([(async()=>(await Q.getCloudStatus()).is_authenticated?{connected:!0,presets:await Q.getFilamentPresets()}:{connected:!1,presets:[]})(),(async()=>(await Q.orcaCloudStatus()).connected?{connected:!0,presets:(await Q.orcaCloudListProfiles()).filament}:{connected:!1,presets:[]})()]);if(t)return;let r=e.status===`fulfilled`&&e.value.connected,i=n.status===`fulfilled`&&n.value.connected,a=e.status===`fulfilled`?e.value.presets:[],o=n.status===`fulfilled`?n.value.presets:[];j(r||i),F([...a,...o])}catch(e){if(t)return;console.error(`Failed to fetch cloud presets:`,e),j(!1)}finally{t||N(!1)}})(),s||Q.getSpoolCatalog().then(z).catch(console.error),Q.getColorCatalog().then(U).catch(console.error),Q.getLocalPresets().then(e=>te(e.filament)).catch(console.error),Q.getBuiltinFilaments().then(ne).catch(console.error),Q.getLocations().then(e=>V(e.map(e=>({id:e.id,name:e.name})))).catch(console.error),i.length===0&&(async()=>{try{let e=await Q.getPrinters(),t=await Promise.all(e.map(e=>Q.getPrinterStatus(e.id).catch(()=>null))),n=[];for(let r=0;r{t=!0}},[e,i.length]);let ge=(0,y.useMemo)(()=>MU(P,new Set,ee,H),[P,ee,H]),_e=(0,y.useMemo)(()=>{let e=jU(P,ee),t=re.map(e=>e.manufacturer?.trim()).filter(e=>!!e),n=new Set([...e,...t]);return Array.from(n).sort((e,t)=>e.localeCompare(t))},[P,ee,re]),ve=(0,y.useMemo)(()=>{let e=re.map(e=>e.material?.trim()).filter(e=>!!e),t=new Set([...CU,...e]);return Array.from(t).sort((e,t)=>e.localeCompare(t))},[re]),ye=(0,y.useMemo)(()=>{let e=[];for(let t of re){let n=t.manufacturer?.trim(),r=t.material?.trim();n&&r&&e.push({brand:n,material:r})}for(let t of P){let n=AU(t.name);n.brand&&n.material&&e.push({brand:n.brand,material:n.material})}for(let t of ee){let n=AU(t.name),r=t.filament_vendor?.trim()||n.brand,i=n.material;r&&i&&e.push({brand:r,material:i})}return e},[P,re,ee]),be=(0,y.useMemo)(()=>{let e=new Map;for(let t of ye){let n=t.brand.toLowerCase(),r=t.material.toLowerCase();e.has(n)||e.set(n,new Set),e.get(n).add(r)}return e},[ye]),xe=(0,y.useMemo)(()=>{let e=new Map;for(let t of ye){let n=t.brand.toLowerCase(),r=t.material.toLowerCase();e.has(r)||e.set(r,new Set),e.get(r).add(n)}return e},[ye]),Se=(0,y.useMemo)(()=>PU(_e,h.brand),[_e,h.brand]),Ce=(0,y.useMemo)(()=>PU(ve,h.material),[ve,h.material]),we=(0,y.useMemo)(()=>FU(Se,h.material,xe),[Se,h.material,xe]),Te=(0,y.useMemo)(()=>FU(Ce,h.brand,be),[Ce,h.brand,be]),Ee=(0,y.useMemo)(()=>NU(h.slicer_filament,ge),[h.slicer_filament,ge]);(0,y.useEffect)(()=>{if(e){if(n){let e=n.rgba&&/^[0-9A-Fa-f]{8}$/.test(n.rgba)?n.rgba:`808080FF`;if(g({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:m?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,location_id:n.location_id??null,spoolman_filament_id:null}),L(n.slicer_filament_name||n.slicer_filament||``),n.k_profiles&&n.k_profiles.length>0){let e=new Set;for(let t of n.k_profiles)t.cali_idx!==null&&t.cali_idx!==void 0&&e.add(`${t.printer_id}:${t.cali_idx}:${t.extruder??`null`}`);ce(e)}else ce(new Set)}else g(_9),L(``),ce(new Set);D(!1),k(1),v({}),x(`filament`),C(!1),T(!1)}},[e,n,r,m]),(0,y.useEffect)(()=>{if(!e||!n||w||h.location_id!=null)return;let t=n.storage_location?.trim();if(!t||B.length===0)return;let r=B.find(e=>e.name.toLowerCase()===t.toLowerCase());r&&g(e=>e.location_id===r.id?e:{...e,location_id:r.id})},[e,n,B,h.location_id,w]),(0,y.useEffect)(()=>{e&&de.length>0&&ue(new Set(de.map(e=>String(e.printer.id))))},[e,de]);let De=(e,t)=>{let n=T$e.has(e);s&&n&&h.spoolman_filament_id!==null&&d(l(`inventory.spoolmanFilamentUnlinked`),`info`),g(r=>({...r,[e]:t,...s&&n&&r.spoolman_filament_id!==null?{spoolman_filament_id:null}:{}})),e===`weight_used`&&C(!0),e===`location_id`&&T(!0),_[e]&&v(t=>({...t,[e]:void 0}))},Oe=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}$/.test(i)?i:`808080`;g(n=>({...n,spoolman_filament_id:e.id,material:t,subtype:r,brand:e.vendor?.name||``,rgba:`${a}FF`,color_name:e.color_name||``,label_weight:e.weight??n.label_weight})),d(l(`inventory.spoolmanFilamentSelected`),`success`)},ke=e=>{ae(t=>LU(e,t))},Ae=J({mutationFn:e=>s?Q.createSpoolmanInventorySpool(e):Q.createSpool(e),onSuccess:async e=>{e?.id&&!await He(e.id)||(await f(),o&&o([e]),d(l(`inventory.spoolCreated`),`success`),t())},onError:e=>{e instanceof $u&&e.status===503?d(l(`inventory.spoolmanUnreachable`),`error`):d(l(`inventory.saveFailed`),`error`)}}),je=J({mutationFn:({data:e,qty:t})=>s?Q.bulkCreateSpoolmanInventorySpools(e,t):Q.bulkCreateSpools(e,t),onSuccess:async e=>{let n=s&&`created`in e?e:null,r=n?n.created:e;if(se.size>0)for(let e of r)await He(e.id);await f(),o&&o(r),n&&n.failed_count>0?d(l(`inventory.spoolsPartiallyCreated`,{created:r.length,total:n.requested_count}),`warning`):d(l(`inventory.spoolsCreated`,{count:r.length}),`success`),t()},onError:e=>{e instanceof $u&&e.status===503?d(l(`inventory.spoolmanUnreachable`),`error`):d(l(`inventory.saveFailed`),`error`)}}),Me=J({mutationFn:e=>s?Q.updateSpoolmanInventorySpool(n.id,e):Q.updateSpool(n.id,e),onSuccess:async()=>{n?.id&&!await He(n.id)||(await f(),d(l(`inventory.spoolUpdated`),`success`),t())},onError:e=>{e instanceof $u&&e.status===503?d(l(`inventory.spoolmanUnreachable`),`error`):d(l(`inventory.saveFailed`),`error`)}}),Ne=J({mutationFn:()=>s?Q.updateSpoolmanInventorySpool(n.id,z$e):Q.updateSpool(n.id,z$e),onSuccess:async()=>{await f(),d(l(`inventory.rfidCleared`,`RFID tag cleared`),`success`),t()},onError:e=>{e instanceof $u&&e.status===503?d(l(`inventory.spoolmanUnreachable`),`error`):d(l(`inventory.tagClearFailed`),`error`)}}),{data:Pe}=q({queryKey:[`spool-assignments`],queryFn:()=>Q.getAssignments(),enabled:e&&p&&!s}),{data:Fe}=q({queryKey:[`spoolman-slot-assignments-all`],queryFn:()=>Q.getSpoolmanSlotAssignments(),enabled:e&&p&&s}),Ie=(()=>{if(n)return s?Fe?.find(e=>e.spoolman_spool_id===n.id):Pe?.find(e=>e.spool_id===n.id)})(),{data:Le}=q({queryKey:[`inventory-spools`],queryFn:()=>Q.getSpools(!0),enabled:e}),{data:Re}=q({queryKey:[`settings`],queryFn:Q.getSettings,enabled:e}),ze=(()=>{let e=new Set;for(let t of Le??[]){let n=t.category?.trim();n&&e.add(n)}return Array.from(e).sort((e,t)=>e.localeCompare(t))})(),Be=Re?.low_stock_threshold??20,Ve=J({mutationFn:async()=>{if(!Ie)throw Error(`No assignment`);if(s){if(!n)throw Error(`No spool`);await Q.unassignSpoolmanSlot(n.id);return}await Q.unassignSpool(Ie.printer_id,Ie.ams_id,Ie.tray_id)},onSuccess:async()=>{s?(await u.invalidateQueries({queryKey:[`spoolman-slot-assignments-all`]}),await u.invalidateQueries({queryKey:[`spoolman-slot-assignments`]})):await u.invalidateQueries({queryKey:[`spool-assignments`]}),d(l(`inventory.unassignSuccess`,`Spool unassigned`),`success`),t()},onError:e=>{d(e.message,`error`)}}),He=async e=>{let t=s?Q.saveSpoolmanKProfiles:Q.saveSpoolKProfiles;if(se.size===0)try{return await t(e,[]),!0}catch(e){return console.error(`Failed to save K-profiles:`,e),d(l(`inventory.kProfileSaveFailed`),`warning`),!1}let n=[],r=0;for(let e of se){let[t,i,a]=e.split(`:`),o=parseInt(t),s=parseInt(i),c=a===`null`?0:parseInt(a),l=de.find(e=>e.printer.id===o);if(l){let e=l.calibrations.find(e=>e.cali_idx===s);e?n.push({printer_id:o,extruder:c,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}):r++}else r++}if(r>0)return console.error(`saveKProfiles: ${r} profile key(s) could not be resolved`,Array.from(se)),d(l(`inventory.kProfileSaveFailed`),`warning`),!1;if(n.length>0)try{return await t(e,n),!0}catch(e){return console.error(`Failed to save K-profiles:`,e),d(l(`inventory.kProfileSaveFailed`),`warning`),!1}return!0};if((0,y.useEffect)(()=>{if(!e)return;let n=e=>{e.key===`Escape`&&t()};return document.addEventListener(`keydown`,n),()=>document.removeEventListener(`keydown`,n)},[e,t]),!e)return null;let Ue=()=>{let e=E$e(h,E,s,r);if(!e.isValid){v(e.errors),(e.errors.slicer_filament||e.errors.material||e.errors.brand||e.errors.subtype)&&x(`filament`);return}let t=Ee?.displayName||I||null,n={material:h.material||null,subtype:h.subtype||null,brand:h.brand||null,color_name:h.color_name||null,rgba:h.rgba||null,extra_colors:h.extra_colors||null,effect_type:h.effect_type||null,label_weight:h.label_weight,...s?{}:{core_weight:h.core_weight,core_weight_catalog_id:h.core_weight_catalog_id},slicer_filament:h.slicer_filament||null,slicer_filament_name:t,nozzle_temp_min:null,nozzle_temp_max:null,note:h.note||null,cost_per_kg:h.cost_per_kg,category:h.category.trim()||null,low_stock_threshold_pct:h.low_stock_threshold_pct,...s?{spoolman_filament_id:h.spoolman_filament_id}:{}};(!p||S)&&(n.weight_used=h.weight_used),(!p||w)&&(n.location_id=h.location_id),p?Me.mutate(n):O>1?je.mutate({data:n,qty:O}):Ae.mutate(n)},We=Ae.isPending||je.isPending||Me.isPending||Ne.isPending||Ve.isPending;return(0,K.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[(0,K.jsx)(`div`,{className:`absolute inset-0 bg-black/60 backdrop-blur-sm`,onClick:t}),(0,K.jsxs)(`div`,{className:`relative w-full max-w-xl mx-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl max-h-[90vh] flex flex-col`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary flex-shrink-0`,children:[(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-baseline gap-2`,children:[l(p?`inventory.editSpool`:m?`inventory.copySpool`:`inventory.addSpool`),p&&n&&(0,K.jsxs)(`span`,{className:`text-sm font-mono text-bambu-gray`,children:[`#`,n.id]})]}),(0,K.jsx)(`button`,{onClick:t,className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,K.jsx)(Ju,{className:`w-5 h-5`})})]}),r===`create`&&(0,K.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2 border-b border-bambu-dark-tertiary flex-shrink-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(Xu,{className:`w-4 h-4 text-amber-600 dark:text-amber-400`}),(0,K.jsx)(`span`,{className:`text-sm text-white`,children:l(`inventory.quickAdd`)})]}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>{D(!E),E||x(`filament`)},className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors ${E?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,children:(0,K.jsx)(`span`,{className:`inline-block h-3.5 w-3.5 rounded-full bg-white transition-transform ${E?`translate-x-4`:`translate-x-0.5`}`})})]}),(0,K.jsxs)(`div`,{className:`flex border-b border-bambu-dark-tertiary flex-shrink-0`,children:[(0,K.jsxs)(`button`,{onClick:()=>x(`filament`),className:`flex-1 px-4 py-2.5 text-sm font-medium flex items-center justify-center gap-2 transition-colors ${b===`filament`?`text-bambu-green border-b-2 border-bambu-green`:`text-bambu-gray hover:text-white`}`,children:[(0,K.jsx)(yl,{className:`w-4 h-4`}),l(`inventory.filamentInfoTab`)]}),!E&&(0,K.jsxs)(`button`,{onClick:()=>x(`pa-profile`),className:`flex-1 px-4 py-2.5 text-sm font-medium flex items-center justify-center gap-2 transition-colors ${b===`pa-profile`?`text-bambu-green border-b-2 border-bambu-green`:`text-bambu-gray hover:text-white`}`,children:[(0,K.jsx)(Vo,{className:`w-4 h-4`}),l(`inventory.paProfileTab`),fe>0&&(0,K.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded-full bg-bambu-green/20 text-bambu-green`,children:fe})]})]}),(0,K.jsx)(`div`,{className:`p-4 overflow-y-auto flex-1`,style:{scrollbarGutter:`stable`},children:b===`filament`?(0,K.jsxs)(`div`,{className:`space-y-6`,children:[s&&!p&&(0,K.jsx)(`div`,{children:he?(0,K.jsx)(`p`,{className:`text-sm text-red-700 dark:text-red-400 px-1`,children:l(`inventory.spoolmanCatalogLoadFailed`)}):(0,K.jsx)(N$e,{filaments:pe,isLoading:me,selectedId:h.spoolman_filament_id,onSelect:Oe})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h3`,{className:`text-sm font-semibold text-bambu-gray uppercase tracking-wide mb-3`,children:l(`inventory.filamentInfo`)}),(0,K.jsx)(O$e,{formData:h,updateField:De,cloudAuthenticated:A,loadingCloudPresets:M,presetInputValue:I,setPresetInputValue:L,selectedPresetOption:Ee,filamentOptions:ge,availableBrands:Se,availableMaterials:Ce,suggestedBrands:we,suggestedMaterials:Te,quickAdd:E,detailsRequired:!E&&!s&&r===`create`,quantity:O,onQuantityChange:k,errors:_})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h3`,{className:`text-sm font-semibold text-bambu-gray uppercase tracking-wide mb-3`,children:l(`inventory.color`)}),(0,K.jsx)(A$e,{formData:h,updateField:De,recentColors:ie,onColorUsed:ke,catalogColors:re})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h3`,{className:`text-sm font-semibold text-bambu-gray uppercase tracking-wide mb-3`,children:l(`inventory.additional`)}),(0,K.jsx)(M$e,{formData:h,updateField:De,spoolCatalog:R,currencySymbol:a,availableCategories:ze,availableLocations:B,onCreateLocation:async e=>{try{let t=await Q.createLocation({name:e});return V(e=>[...e,{id:t.id,name:t.name}].sort((e,t)=>e.name.localeCompare(t.name))),await b9(u),{id:t.id,name:t.name}}catch(e){return console.error(e),d((e instanceof Error?e.message:l(`locations.saveFailed`))||l(`locations.saveFailed`),`error`),null}},globalLowStockThreshold:Be,spoolmanMode:s})]}),p&&n&&!s&&(0,K.jsx)(`div`,{children:(0,K.jsx)(L$e,{spoolId:n.id})})]}):(0,K.jsx)(P$e,{formData:h,updateField:De,printersWithCalibrations:de,selectedProfiles:se,setSelectedProfiles:ce,expandedPrinters:le,setExpandedPrinters:ue})}),(0,K.jsxs)(`div`,{className:`flex gap-2 p-4 border-t border-bambu-dark-tertiary flex-shrink-0`,children:[p&&(0,K.jsxs)(`div`,{className:`flex gap-2 mr-auto`,children:[(0,K.jsxs)($,{variant:`secondary`,onClick:()=>Ne.mutate(),disabled:We||!n?.tag_uid,children:[(0,K.jsx)(yu,{className:`w-4 h-4`}),l(`inventory.clearRfid`,`Clear RFID Tag`)]}),(0,K.jsxs)($,{variant:`secondary`,onClick:()=>Ve.mutate(),disabled:We||!Ie,children:[(0,K.jsx)(Nu,{className:`w-4 h-4`}),l(`inventory.unassignSpool`,`Unassign`)]})]}),(0,K.jsxs)(`div`,{className:`flex gap-2 ml-auto`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:t,children:l(`common.cancel`)}),(0,K.jsx)($,{onClick:Ue,disabled:We,children:We?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),l(`common.saving`)]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Bl,{className:`w-4 h-4`}),l(p?`common.save`:m?`inventory.copySpool`:`inventory.addSpool`)]})})]})]})]})]})}var V$e=[{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.`}];function H$e(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 U$e(e){return _f(e)}function W$e(e){return`${e.color_name??`${e.material}${e.subtype?` ${e.subtype}`:``}`}${e.brand?` · ${e.brand}`:``}`}function G$e(e){return[e.color_name,e.material,e.subtype,e.brand,`#${e.id}`].filter(Boolean).join(` `).toLowerCase()}function K$e(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 q$e({isOpen:e,onClose:t,availableSpools:n,initialSelectedIds:r,spoolmanMode:i}){let{t:a}=$e(),{showToast:o}=Fd(),[s,c]=(0,y.useState)(null),[l,u]=(0,y.useState)(new Set),[d,f]=(0,y.useState)(``),[p,m]=(0,y.useState)(``),[h,g]=(0,y.useState)(`id`),[_,v]=(0,y.useState)(!1);(0,y.useEffect)(()=>{if(e){let e=new Set(n.map(e=>e.id));u(new Set(r.filter(t=>e.has(t)))),f(``),m(``),g(`id`),v(!1),c(null)}},[e]);let b=(0,y.useMemo)(()=>{let e=[...n];return h===`color`?(e.sort((e,t)=>{let n=K$e(e.rgba),r=K$e(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,h]),x=(0,y.useMemo)(()=>{let e=new Set;for(let t of b)t.material&&e.add(t.material.toUpperCase());return[...e].sort()},[b]),S=(0,y.useMemo)(()=>{let e=d.trim().toLowerCase();return b.filter(t=>!(p&&(t.material||``).toUpperCase()!==p||e&&!G$e(t).includes(e)))},[b,d,p]),C=S.length>0&&S.every(e=>l.has(e.id));if(!e)return null;let w=l.size,T=w===0;function E(e){u(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function D(){u(e=>{let t=new Set(e);for(let e of S)t.add(e.id);return t})}function O(){u(e=>{let t=new Set(e);for(let e of S)t.delete(e.id);return t})}function k(){u(new Set)}async function A(e){if(T||s)return;let n=b.filter(e=>l.has(e.id)).map(e=>e.id);c(e);try{H$e(i?await Q.printSpoolmanSpoolLabels({spool_ids:n,template:e,monochrome:_}):await Q.printSpoolLabels({spool_ids:n,template:e,monochrome:_})),t()}catch(e){o(a(`inventory.labels.error`,`Could not generate labels: {{msg}}`,{msg:e instanceof Error?e.message:String(e)}),`error`)}finally{c(null)}}return(0,K.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-start sm:items-center justify-center p-4 overflow-y-auto`,children:[(0,K.jsx)(`div`,{className:`absolute inset-0 bg-black/60 backdrop-blur-sm`,onClick:t}),(0,K.jsxs)(`div`,{className:`relative w-full max-w-3xl 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,K.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(Ml,{className:`w-5 h-5 text-bambu-green`}),(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:a(`inventory.labels.title`,`Print spool labels`)}),w>0&&(0,K.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[`(`,a(`inventory.labels.selectedCount`,`{{count}} selected`,{count:w}),`)`]})]}),(0,K.jsx)(`button`,{onClick:t,className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,"aria-label":a(`common.close`,`Close`),children:(0,K.jsx)(Ju,{className:`w-5 h-5`})})]}),(0,K.jsxs)(`div`,{className:`p-4 space-y-2 border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(Gl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`}),(0,K.jsx)(`input`,{type:`search`,value:d,onChange:e=>f(e.target.value),placeholder:a(`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`})]}),x.length>1&&(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray mr-1`,children:a(`inventory.labels.filterByMaterial`,`Material:`)}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>m(``),className:`px-2 py-0.5 text-xs rounded-full border transition ${p===``?`bg-bambu-green text-bambu-dark border-bambu-green`:`bg-bambu-dark text-bambu-gray border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:a(`inventory.labels.allMaterials`,`All`)}),x.map(e=>(0,K.jsx)(`button`,{type:`button`,onClick:()=>m(e),className:`px-2 py-0.5 text-xs rounded-full border transition ${p===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,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray mr-1`,children:a(`inventory.labels.sortBy.label`)}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>g(`id`),className:`px-2 py-0.5 text-xs rounded-full border transition ${h===`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:a(`inventory.labels.sortBy.id`)}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>g(`color`),className:`px-2 py-0.5 text-xs rounded-full border transition ${h===`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:a(`inventory.labels.sortBy.color`)})]})]}),(0,K.jsxs)(`div`,{className:`px-4 pt-3 pb-2 flex items-center justify-between gap-3 flex-wrap`,children:[(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:a(`inventory.labels.pickSpools`,`Pick which spools to print labels for:`)}),(0,K.jsxs)(`div`,{className:`flex items-center gap-3 text-xs`,children:[(0,K.jsx)(`button`,{type:`button`,onClick:C?O:D,disabled:S.length===0,className:`text-bambu-green hover:underline disabled:opacity-50 disabled:no-underline disabled:cursor-not-allowed`,children:C?a(`inventory.labels.deselectVisible`,`Deselect visible`):a(`inventory.labels.selectVisible`,`Select all visible ({{count}})`,{count:S.length})}),(0,K.jsx)(`button`,{type:`button`,onClick:k,disabled:w===0,className:`text-bambu-gray hover:text-white hover:underline disabled:opacity-50 disabled:no-underline disabled:cursor-not-allowed`,children:a(`inventory.labels.clearAll`,`Clear all`)})]})]}),(0,K.jsx)(`div`,{className:`flex-1 overflow-y-auto px-2 pb-2 min-h-0`,children:S.length===0?(0,K.jsx)(`div`,{className:`text-center text-sm text-bambu-gray py-6`,children:b.length===0?a(`inventory.labels.noSpoolsToShow`,`No spools to show. Adjust your filter and try again.`):a(`inventory.labels.noMatches`,`No spools match the current search or filter.`)}):(0,K.jsx)(`ul`,{className:`space-y-0.5`,children:S.map(e=>{let t=l.has(e.id);return(0,K.jsx)(`li`,{children:(0,K.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,K.jsx)(du,{className:`w-4 h-4 text-bambu-green shrink-0`}):(0,K.jsx)(pu,{className:`w-4 h-4 text-bambu-gray shrink-0`}),(0,K.jsx)(`input`,{type:`checkbox`,checked:t,onChange:()=>E(e.id),className:`sr-only`}),(0,K.jsx)(`span`,{className:`w-4 h-4 rounded border border-black/20 shrink-0`,style:U$e(e.rgba)}),(0,K.jsx)(`span`,{className:`flex-1 min-w-0 truncate text-sm text-white`,children:W$e(e)}),(0,K.jsxs)(`span`,{className:`text-xs font-mono text-bambu-gray shrink-0`,children:[`#`,e.id]})]})},e.id)})})}),(0,K.jsx)(`div`,{className:`px-4 pt-2 pb-1 border-t border-bambu-dark-tertiary`,children:(0,K.jsxs)(`label`,{className:`inline-flex items-center gap-2 cursor-pointer select-none`,children:[_?(0,K.jsx)(du,{className:`w-4 h-4 text-bambu-green shrink-0`}):(0,K.jsx)(pu,{className:`w-4 h-4 text-bambu-gray shrink-0`}),(0,K.jsx)(`input`,{type:`checkbox`,checked:_,onChange:e=>v(e.target.checked),className:`sr-only`}),(0,K.jsx)(`span`,{className:`text-sm text-white`,children:a(`inventory.labels.monochrome`,`Monochrome (black & white printer)`)}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:a(`inventory.labels.monochromeHint`,`Drops the colour swatch and widens the text`)})]})}),(0,K.jsx)(`div`,{className:`px-3 pt-1 pb-2 grid grid-cols-1 sm:grid-cols-2 gap-2`,children:V$e.map(e=>{let t=s===e.value,n=a(`inventory.labels.templates.${e.i18nKey}.label`,e.fallbackLabel),r=a(`inventory.labels.templates.${e.i18nKey}.hint`,e.fallbackHint);return(0,K.jsxs)(`button`,{disabled:T||s!==null,onClick:()=>A(e.value),title:`${n} — ${r}`,className:`w-full text-left p-2.5 rounded-lg border border-bambu-dark-tertiary bg-bambu-dark hover:border-bambu-green hover:bg-bambu-green/10 disabled:opacity-50 disabled:cursor-not-allowed disabled:hover:border-bambu-dark-tertiary disabled:hover:bg-bambu-dark transition flex items-center gap-3`,children:[(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`div`,{className:`font-medium text-white text-sm truncate`,children:n}),(0,K.jsx)(`div`,{className:`text-xs text-bambu-gray mt-0.5 truncate`,children:r})]}),t&&(0,K.jsx)(X,{className:`w-4 h-4 animate-spin text-bambu-green shrink-0`})]},e.value)})}),(0,K.jsx)(`div`,{className:`flex justify-end gap-2 px-5 py-2 border-t border-bambu-dark-tertiary`,children:(0,K.jsx)($,{variant:`secondary`,onClick:t,disabled:s!==null,children:a(`common.cancel`,`Cancel`)})})]})]})}function J$e({onClose:e,onImported:t}){let{t:n}=$e(),[r,i]=(0,y.useState)(null),[a,o]=(0,y.useState)(!1),[s,c]=(0,y.useState)(null),[l,u]=(0,y.useState)(!1),[d,f]=(0,y.useState)(!1),[p,m]=(0,y.useState)(null),h=(0,y.useRef)(null),g=async e=>{i(e),c(null),m(null),u(!0);try{c(await Q.importSpoolsCsvPreview(e))}catch(e){m(e instanceof Error?e.message:n(`inventory.csv.previewError`,`Could not read the CSV file`))}finally{u(!1)}},_=e=>{let t=e.target.files?.[0];t&&g(t)},v=e=>{e.preventDefault(),o(!1);let t=e.dataTransfer.files?.[0];t&&g(t)},b=async()=>{if(r){f(!0),m(null);try{t((await Q.importSpoolsCsv(r)).created)}catch(e){m(e instanceof Error?e.message:n(`inventory.csv.importError`,`Import failed`)),f(!1)}}},x=e=>e===`valid`?(0,K.jsx)(gs,{className:`w-4 h-4 text-green-500 flex-shrink-0`}):e===`error`?(0,K.jsx)(Ss,{className:`w-4 h-4 text-red-500 flex-shrink-0`}):(0,K.jsx)(ys,{className:`w-4 h-4 text-bambu-gray flex-shrink-0`}),S=s?.valid_count??0;return(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-3xl border border-bambu-dark-tertiary flex flex-col max-h-[90vh]`,children:[(0,K.jsxs)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary flex items-center justify-between`,children:[(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:n(`inventory.csv.modalTitle`,`Import spools from CSV`)}),(0,K.jsx)(`button`,{onClick:e,className:`p-1 hover:bg-bambu-dark rounded`,children:(0,K.jsx)(Ju,{className:`w-5 h-5 text-bambu-gray`})})]}),(0,K.jsxs)(`div`,{className:`p-4 space-y-4 overflow-y-auto flex-1`,children:[(0,K.jsxs)(`div`,{onDragOver:e=>{e.preventDefault(),o(!0)},onDragLeave:e=>{e.preventDefault(),o(!1)},onDrop:v,onClick:()=>h.current?.click(),className:`border-2 border-dashed rounded-lg p-6 text-center cursor-pointer transition-colors ${a?`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary hover:border-bambu-green/50`}`,children:[(0,K.jsx)(Pu,{className:`w-9 h-9 mx-auto mb-2 ${a?`text-bambu-green`:`text-bambu-gray`}`}),r?(0,K.jsxs)(`p`,{className:`text-white font-medium flex items-center justify-center gap-2`,children:[(0,K.jsx)(oc,{className:`w-4 h-4`}),` `,r.name]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`p`,{className:`text-white font-medium`,children:n(`inventory.csv.selectFile`,`Choose a CSV file or drag it here`)}),(0,K.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,K.jsx)(`input`,{ref:h,type:`file`,accept:`.csv,text/csv`,className:`hidden`,onChange:_}),l&&(0,K.jsxs)(`div`,{className:`flex items-center justify-center gap-2 text-bambu-gray py-4`,children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),n(`inventory.csv.parsing`,`Reading file…`)]}),p&&(0,K.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,K.jsx)(Ss,{className:`w-5 h-5 text-red-600 dark:text-red-400 mt-0.5 flex-shrink-0`}),(0,K.jsx)(`p`,{className:`text-sm text-red-700 dark:text-red-300 break-words`,children:p})]}),s&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`flex flex-wrap gap-3 text-sm`,children:[(0,K.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:s.valid_count})}),(0,K.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:s.error_count})}),(0,K.jsx)(`span`,{className:`px-2 py-1 rounded bg-bambu-dark text-bambu-gray`,children:n(`inventory.csv.skippedCount`,`{{count}} skipped`,{count:s.skipped_count})})]}),s.warnings.length>0&&(0,K.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:s.warnings.map((e,t)=>(0,K.jsx)(`p`,{className:`text-xs text-yellow-700 dark:text-yellow-300`,children:e},t))}),s.rows.length>0&&(0,K.jsx)(`div`,{className:`border border-bambu-dark-tertiary rounded-lg overflow-hidden`,children:(0,K.jsx)(`div`,{className:`max-h-72 overflow-y-auto`,children:(0,K.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,K.jsx)(`thead`,{className:`bg-bambu-dark sticky top-0`,children:(0,K.jsxs)(`tr`,{className:`text-left text-bambu-gray`,children:[(0,K.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:n(`inventory.csv.colRow`,`Row`)}),(0,K.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:n(`inventory.csv.colStatus`,`Status`)}),(0,K.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:n(`inventory.material`,`Material`)}),(0,K.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:n(`inventory.brand`,`Brand`)}),(0,K.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:n(`inventory.csv.colColor`,`Color`)})]})}),(0,K.jsx)(`tbody`,{children:s.rows.map(e=>(0,K.jsxs)(`tr`,{className:`border-t border-bambu-dark-tertiary`,children:[(0,K.jsx)(`td`,{className:`px-3 py-2 text-bambu-gray`,children:e.row_number}),(0,K.jsx)(`td`,{className:`px-3 py-2`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[x(e.status),e.status===`error`&&e.reason&&(0,K.jsx)(`span`,{className:`text-xs text-red-700 dark:text-red-400 break-words`,children:e.reason})]})}),(0,K.jsx)(`td`,{className:`px-3 py-2 text-white`,children:e.material||`—`}),(0,K.jsx)(`td`,{className:`px-3 py-2 text-white`,children:e.brand||`—`}),(0,K.jsx)(`td`,{className:`px-3 py-2`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.rgba&&(0,K.jsx)(`span`,{className:`inline-block w-4 h-4 rounded-full border border-bambu-dark-tertiary flex-shrink-0`,style:_f(e.rgba)}),(0,K.jsx)(`span`,{className:`text-white`,children:e.color_name||`—`}),e.resolved_color&&!e.cross_material_color&&(0,K.jsx)(`span`,{title:n(`inventory.csv.colorResolved`,`Color filled from catalog`),children:(0,K.jsx)(Vu,{className:`w-3.5 h-3.5 text-bambu-green flex-shrink-0`})}),e.cross_material_color&&(0,K.jsx)(`span`,{title:n(`inventory.csv.colorCrossMaterial`,`Color taken from a different material — no exact match in catalog`),children:(0,K.jsx)(Au,{className:`w-3.5 h-3.5 text-yellow-500 flex-shrink-0`})}),e.duplicate_of_existing&&(0,K.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,K.jsx)(Is,{className:`w-3.5 h-3.5 text-amber-600 dark:text-amber-400 flex-shrink-0`})})]})})]},e.row_number))})]})})})]})]}),(0,K.jsxs)(`div`,{className:`p-4 border-t border-bambu-dark-tertiary flex justify-end gap-2`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:e,disabled:d,children:n(`common.cancel`)}),(0,K.jsx)($,{onClick:b,disabled:!s||S===0||d,children:d?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(X,{className:`w-4 h-4 mr-2 animate-spin`}),n(`inventory.csv.importing`,`Importing…`)]}):S>0?n(`inventory.csv.importValidRows`,`Import {{count}} valid rows`,{count:S}):n(`inventory.csv.noValidRows`,`No valid rows`)})]})]})})}function Y$e({open:e,onClose:t,onPickLocation:n}){let{t:r}=$e(),i=ao(),{showToast:a}=Fd(),[o,s]=(0,y.useState)(!1),[c,l]=(0,y.useState)(null),[u,d]=(0,y.useState)(``),[f,p]=(0,y.useState)(null),{data:m=[],isLoading:h}=q({queryKey:y9,queryFn:Q.getLocations,enabled:e}),g=()=>{b9(i),i.invalidateQueries({queryKey:[`inventory-spools`]}),i.invalidateQueries({queryKey:[`spoolman-inventory-spools`]})},_=J({mutationFn:async()=>{let e=u.trim();if(!e)throw Error(r(`locations.nameRequired`));return c?Q.updateLocation(c.id,{name:e}):Q.createLocation({name:e})},onSuccess:()=>{a(r(c?`locations.updated`:`locations.created`),`success`),s(!1),l(null),d(``),g()},onError:e=>{a(e.message||r(`locations.saveFailed`),`error`)}}),v=J({mutationFn:e=>Q.deleteLocation(e),onSuccess:()=>{a(r(`locations.deleted`),`success`),p(null),g()},onError:e=>{a(e.message||r(`locations.deleteFailed`),`error`)}}),b=()=>{l(null),d(``),s(!0)},x=e=>{l(e),d(e.name),s(!0)},S=(0,y.useCallback)(()=>{_.isPending||(s(!1),l(null),d(``))},[_.isPending]);(0,y.useEffect)(()=>{if(!e)return;let n=e=>{e.key===`Escape`&&(_.isPending||v.isPending||(o?S():f||t()))};return document.addEventListener(`keydown`,n),()=>document.removeEventListener(`keydown`,n)},[e,o,f,_.isPending,v.isPending,S,t]);let C=e=>{e.preventDefault(),_.mutate()};if(!e)return null;let w=`locations-modal-title`,T=`location-editor-title`;return(0,K.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[(0,K.jsx)(`div`,{className:`absolute inset-0 bg-black/60`,onClick:()=>{_.isPending||v.isPending||t()}}),(0,K.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,K.jsxs)(`div`,{className:`flex items-center justify-between gap-4 px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`h2`,{id:w,className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(tl,{className:`w-5 h-5 text-bambu-green`}),r(`locations.title`)]}),(0,K.jsx)(`p`,{className:`text-bambu-gray text-sm mt-0.5`,children:r(`locations.subtitle`)})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)($,{onClick:b,children:[(0,K.jsx)(kl,{className:`w-4 h-4`}),r(`locations.add`)]}),(0,K.jsx)(`button`,{type:`button`,className:`p-1.5 text-bambu-gray hover:text-white rounded`,onClick:t,"aria-label":r(`common.close`),children:(0,K.jsx)(Ju,{className:`w-5 h-5`})})]})]}),(0,K.jsx)(`div`,{className:`overflow-y-auto`,children:h?(0,K.jsxs)(`div`,{className:`flex items-center justify-center py-16 text-bambu-gray`,children:[(0,K.jsx)(X,{className:`w-6 h-6 animate-spin mr-2`}),r(`common.loading`)]}):m.length===0?(0,K.jsx)(`div`,{className:`py-16 text-center text-bambu-gray`,children:r(`locations.empty`)}):(0,K.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,K.jsx)(`thead`,{children:(0,K.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary text-left text-bambu-gray`,children:[(0,K.jsx)(`th`,{className:`px-4 py-3 font-medium`,children:r(`locations.name`)}),(0,K.jsx)(`th`,{className:`px-4 py-3 font-medium text-right`,children:r(`locations.spools`)}),(0,K.jsx)(`th`,{className:`px-4 py-3 font-medium text-right w-32`,children:r(`common.actions`)})]})}),(0,K.jsx)(`tbody`,{children:m.map(e=>(0,K.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,K.jsx)(`td`,{className:`px-4 py-3 text-white font-medium`,children:e.name}),(0,K.jsx)(`td`,{className:`px-4 py-3 text-right text-bambu-gray`,children:e.spool_count}),(0,K.jsx)(`td`,{className:`px-4 py-3 text-right`,onClick:e=>e.stopPropagation(),children:(0,K.jsxs)(`div`,{className:`flex items-center justify-end gap-1`,children:[(0,K.jsx)(`button`,{type:`button`,className:`p-1.5 text-bambu-gray hover:text-bambu-green rounded`,onClick:()=>x(e),title:r(`common.edit`),"aria-label":r(`locations.editAria`,{name:e.name,defaultValue:`Edit ${e.name}`}),children:(0,K.jsx)(Tl,{className:`w-4 h-4`})}),(0,K.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:()=>p(e),title:e.spool_count>0?r(`locations.deleteBlocked`):r(`common.delete`),"aria-label":r(`locations.deleteAria`,{name:e.name,defaultValue:`Delete ${e.name}`}),children:(0,K.jsx)(Du,{className:`w-4 h-4`})})]})})]},e.id))})]})})]}),o&&(0,K.jsxs)(`div`,{className:`fixed inset-0 z-[60] flex items-center justify-center`,children:[(0,K.jsx)(`div`,{className:`absolute inset-0 bg-black/60`,onClick:S}),(0,K.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":T,children:[(0,K.jsx)(`h3`,{id:T,className:`text-lg font-semibold text-white mb-4`,children:r(c?`locations.edit`:`locations.add`)}),(0,K.jsxs)(`form`,{onSubmit:C,children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,htmlFor:`location-name`,children:r(`locations.name`)}),(0,K.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:r(`locations.createPlaceholder`),value:u,onChange:e=>d(e.target.value),autoFocus:!0}),(0,K.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,K.jsx)($,{type:`button`,variant:`secondary`,onClick:S,children:r(`common.cancel`)}),(0,K.jsxs)($,{type:`submit`,disabled:_.isPending||!u.trim(),children:[_.isPending&&(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),r(`common.save`)]})]})]})]})]}),f&&(0,K.jsx)(qd,{title:r(`locations.confirmDelete`,{name:f.name}),message:r(`locations.confirmDeleteMessage`),confirmText:r(`common.delete`),variant:`danger`,isLoading:v.isPending,onConfirm:()=>v.mutate(f.id),onCancel:()=>p(null)})]})}var x9=[{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`},{id:`low_stock_threshold_pct`,type:`number`,labelKey:`inventory.lowStockThresholdOverride`,min:1,max:99,step:1}];function X$e({value:e,onChange:t,options:n,allowCustom:r,placeholderKey:i,disabled:a}){let{t:o}=$e(),s=(0,y.useRef)(null),[c,l]=(0,y.useState)(!1),[u,d]=(0,y.useState)(``);(0,y.useEffect)(()=>{if(!c)return;let e=e=>{s.current&&!s.current.contains(e.target)&&(l(!1),d(``))},t=e=>{e.key===`Escape`&&(l(!1),d(``))};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[c]);let f=c?u:n.find(t=>t.value===e)?.label??e,p=(0,y.useMemo)(()=>{if(!c)return n;let e=u.trim().toLowerCase();return e?n.filter(t=>t.label.toLowerCase().includes(e)||t.value.toLowerCase().includes(e)):n},[c,u,n]),m=c&&u.trim()&&!n.some(e=>e.value.toLowerCase()===u.trim().toLowerCase());return(0,K.jsxs)(`div`,{className:`relative`,ref:s,children:[(0,K.jsx)(`input`,{type:`text`,disabled:a,value:f,onChange:e=>{d(e.target.value),l(!0),r&&t(e.target.value)},onFocus:()=>{l(!0),d(``)},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,K.jsx)(cs,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50 pointer-events-none`}),c&&(0,K.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:[p.length===0&&!r&&(0,K.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:o(`inventory.noResults`)}),p.map(n=>(0,K.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),l(!1),d(``)},children:n.label},n.value)),r&&m&&(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:()=>{t(u.trim()),l(!1),d(``)},children:o(`inventory.bulk.useCustom`,{value:u.trim()})})]})]})}function S9(...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 Z$e({isOpen:e,selectedCount:t,isPending:n,availableLocations:r,availableMaterials:i,availableSubtypes:a,availableBrands:o,availableCategories:s,availableSlicerFilaments:c,availableSlicerFilamentNames:l,onClose:u,onApply:d}){let{t:f}=$e(),{data:p=[]}=q({queryKey:[`bulk-edit-cloud-presets`],enabled:e,staleTime:300*1e3,queryFn:async()=>{let e=[];try{if((await Q.getCloudStatus()).is_authenticated){let t=await Q.getFilamentPresets();e.push(...t)}}catch{}try{if((await Q.orcaCloudStatus()).connected){let t=await Q.orcaCloudListProfiles();e.push(...t.filament)}}catch{}return e}}),{data:m}=q({queryKey:[`bulk-edit-local-presets`],enabled:e,staleTime:300*1e3,queryFn:Q.getLocalPresets}),{data:h=[]}=q({queryKey:[`builtin-filaments`],enabled:e,staleTime:300*1e3,queryFn:Q.getBuiltinFilaments}),g=(0,y.useMemo)(()=>MU(p,new Set,m?.filament??[],h),[p,m,h]),[_,v]=(0,y.useState)({}),b=(0,y.useMemo)(()=>S9(CU,i).map(e=>({value:e,label:e})),[i]),x=(0,y.useMemo)(()=>S9(TU,a).map(e=>({value:e,label:e})),[a]),S=(0,y.useMemo)(()=>S9(wU,o).map(e=>({value:e,label:e})),[o]),C=(0,y.useMemo)(()=>S9(s).map(e=>({value:e,label:e})),[s]),w=(0,y.useMemo)(()=>{let e=g.map(e=>({value:e.code,label:e.displayName})),t=c.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))},[g,c]),T=(0,y.useMemo)(()=>{let e=g.map(e=>({value:e.displayName,label:e.displayName})),t=l.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))},[g,l]),E=(0,y.useMemo)(()=>r.map(e=>({value:String(e.id),label:e.name})),[r]);if(!e)return null;let D=(e,t)=>{v(n=>({...n,[e]:t}))},O=e=>{v(t=>{let n={...t};return delete n[e],n})},k=(()=>{let e={};for(let t of x9){let n=_[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})(),A=Object.keys(k).length>0,j=x9.some(e=>{let t=_[e.id];return t===void 0||t.trim()===``?!1:k[e.id]===void 0}),M=e=>e===`material`?b:e===`subtype`?x:e===`brand`?S:e===`category`?C:e===`slicer_filament`?w:e===`slicer_filament_name`?T:e===`location_id`?E:[],N=e=>{let t=_[e.id]??``;if(e.type===`searchable`||e.type===`searchableClosed`)return(0,K.jsx)(X$e,{value:t,onChange:t=>{t===``?O(e.id):D(e.id,t)},options:M(e.id),allowCustom:e.type===`searchable`,disabled:n});if(e.type===`textarea`)return(0,K.jsx)(`textarea`,{disabled:n,value:t,onChange:t=>D(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,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`input`,{type:`color`,disabled:n,value:`#${(t||`808080`).replace(/^#/,``).slice(0,6)}`,onChange:t=>D(e.id,t.target.value.replace(/^#/,``).toUpperCase()),className:`h-9 w-12 rounded cursor-pointer`}),(0,K.jsx)(`input`,{type:`text`,disabled:n,value:t,onChange:t=>D(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,K.jsx)(`p`,{className:`mt-1 text-xs text-red-600 dark:text-red-400`,children:f(`inventory.bulk.invalidHex`)})]})}return(0,K.jsx)(`input`,{type:e.type===`number`?`number`:`text`,disabled:n,value:t,onChange:t=>D(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,K.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center p-4 z-50`,onClick:n?void 0:u,children:(0,K.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,K.jsxs)(`div`,{className:`flex items-center justify-between p-5 border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:f(`inventory.bulk.editTitle`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mt-0.5`,children:f(`inventory.bulk.editSubtitle`,{count:t})})]}),(0,K.jsx)(`button`,{onClick:u,disabled:n,className:`p-1 text-bambu-gray hover:text-white transition-colors`,"aria-label":f(`common.close`),children:(0,K.jsx)(Ju,{className:`w-5 h-5`})})]}),(0,K.jsx)(`p`,{className:`px-5 pt-4 text-xs text-bambu-gray`,children:f(`inventory.bulk.editHint`)}),(0,K.jsx)(`div`,{className:`flex-1 overflow-y-auto p-5 space-y-3`,children:x9.map(e=>{let t=_[e.id]!==void 0;return(0,K.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,K.jsx)(`div`,{className:`pt-2`,children:(0,K.jsx)(`input`,{type:`checkbox`,className:`h-4 w-4 cursor-pointer`,checked:t,onChange:t=>{t.target.checked?D(e.id,``):O(e.id)},"aria-label":f(`inventory.bulk.toggleField`)})}),(0,K.jsxs)(`div`,{className:`flex-1`,children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:f(e.labelKey)}),N(e)]})]},e.id)})}),(0,K.jsxs)(`div`,{className:`flex items-center gap-3 p-5 border-t border-bambu-dark-tertiary`,children:[(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:f(`inventory.bulk.changeCount`,{count:Object.keys(k).length})}),(0,K.jsxs)(`div`,{className:`ml-auto flex gap-2`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:u,disabled:n,children:f(`common.cancel`)}),(0,K.jsx)($,{onClick:()=>d(k),disabled:!A||n||j,children:n?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(X,{className:`w-4 h-4 mr-2 animate-spin`}),f(`inventory.bulk.applyPending`)]}):f(`inventory.bulk.applyButton`,{count:t})})]})]})]})})}function Q$e(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 C9(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 $$e(e){return`${e.material}|${e.subtype||``}|${e.brand||``}|${e.color_name||``}|${e.rgba||``}|${e.extra_colors||``}|${e.effect_type||``}|${e.label_weight}`}var e1e=`bambuddy-inventory-columns`,w9=[{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:`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:`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 t1e(){try{let e=localStorage.getItem(e1e);if(e){let t=JSON.parse(e),n=new Set(w9.map(e=>e.id)),r=new Set(t.map(e=>e.id)),i=t.filter(e=>n.has(e.id)),a=w9.filter(e=>!r.has(e.id));return[...i,...a]}}catch{}return w9.map(e=>({...e}))}function n1e(e){try{localStorage.setItem(e1e,JSON.stringify(e))}catch{}}function T9(e,t=!1){return t&&e>=1e3?`${(e/1e3).toFixed(1)}kg`:`${Math.round(e)}g`}var r1e={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 E9(e,t=`system`){if(!e)return`-`;let n=Hf(e);return n?Pf(n,t):`-`}var i1e={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`),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`),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`)},D9={id:({spool:e})=>(0,K.jsx)(`span`,{className:`text-sm font-medium text-white`,children:e.id}),added_time:({spool:e,dateFormat:t})=>(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:E9(e.created_at,t)}),encode_time:({spool:e,dateFormat:t})=>(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:E9(e.encode_time,t)}),last_used_time:({spool:e,dateFormat:t})=>(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.last_used?E9(e.last_used,t):`Never`}),rgba:({spool:e})=>(0,K.jsx)(`div`,{className:`flex items-center justify-center`,children:(0,K.jsx)(C6,{rgba:e.rgba,extraColors:e.extra_colors,effectType:e.effect_type,effectSize:`table`,subtype:e.subtype})}),material:({spool:e})=>(0,K.jsx)(`span`,{className:`text-sm text-white`,children:e.material}),subtype:({spool:e})=>(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.subtype||`-`}),color_name:({spool:e})=>(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:hf(e.color_name,e.rgba)||`-`}),brand:({spool:e})=>(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.brand||`-`}),slicer_filament:({spool:e})=>(0,K.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,K.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,K.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,` `,sp(n.ams_id,n.tray_id,a,i),n.ams_label?` (${n.ams_label})`:``]})},storage_location:({spool:e})=>e.storage_location?(0,K.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,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:`-`}),label_weight:({spool:e})=>(0,K.jsx)(`span`,{className:`text-sm text-white`,children:T9(e.label_weight)}),net:({remaining:e})=>(0,K.jsx)(`span`,{className:`text-sm text-white`,children:T9(e)}),gross:({spool:e,remaining:t})=>(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:T9(t+e.core_weight)}),added_full:({spool:e})=>(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.added_full==null?`-`:e.added_full?`Yes`:`No`}),used:({spool:e})=>(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.weight_used>0?T9(e.weight_used):`-`}),printed_total:()=>(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray/50`,children:`-`}),printed_since_weight:()=>(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray/50`,children:`-`}),note:({spool:e})=>(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray max-w-[150px] truncate block`,title:e.note||void 0,children:e.note||`-`}),pa_k:({spool:e})=>(e.k_profiles?.length??0)===0?(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:`-`}):(0,K.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,K.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,K.jsx)(`span`,{className:`text-sm text-bambu-gray/50`,children:`-`})},data_origin:({spool:e})=>(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.data_origin||`-`}),tag_type:({spool:e})=>(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.tag_type||`-`}),stock:({spool:e,t})=>e.slicer_filament?(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:`-`}):(0,K.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,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`div`,{className:`flex-1 h-2 bg-bambu-dark-tertiary rounded-full overflow-hidden`,children:(0,K.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,K.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,K.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,K.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,K.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,K.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,K.jsxs)(`span`,{children:[Math.round(n),`g`]}),o?(0,K.jsx)(ss,{className:`w-3 h-3`}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Au,{className:`w-3 h-3`}),t&&(0,K.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,K.jsx)(Fl,{className:`w-3.5 h-3.5`})})]})]})}},O9={id:e=>e.id,added_time:e=>e.created_at||``,encode_time:e=>e.encode_time||``,last_used_time:e=>e.last_used||``,material:e=>(e.material||``).toLowerCase(),subtype:e=>(e.subtype||``).toLowerCase(),color_name:e=>(e.color_name||``).toLowerCase(),rgba:e=>pf(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||``} ${sp(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(),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)}},k9=`bambuddy-inventory-sort`;function a1e(){try{let e=localStorage.getItem(k9);if(e)return JSON.parse(e)}catch{}return null}function o1e(e){try{e?localStorage.setItem(k9,JSON.stringify(e)):localStorage.removeItem(k9)}catch{}}function s1e(){let{data:e}=q({queryKey:[`spoolman-settings`],queryFn:Q.getSpoolmanSettings,staleTime:300*1e3}),t=e!==void 0;return(0,K.jsx)(c1e,{spoolmanMode:e?.spoolman_enabled===`true`&&!!e?.spoolman_url,spoolmanModeReady:t})}function c1e({spoolmanMode:e=!1,spoolmanModeReady:t=!0}){let{t:n}=$e(),r=ao(),{showToast:i}=Fd(),{hasPermission:a,loading:o}=xd(),s=!o&&a(`inventory:forecast_read`),[c,l]=Fi(),[u,d]=(0,y.useState)(null),f=(0,y.useRef)(!1),[p,m]=(0,y.useState)(null),[h,g]=(0,y.useState)(null),[_,v]=(0,y.useState)(!1),[b,x]=(0,y.useState)(!1),[S,C]=(0,y.useState)(!1),[w,T]=(0,y.useState)(`active`),[E,D]=(0,y.useState)(`all`),[O,k]=(0,y.useState)(``),[A,j]=(0,y.useState)(``),[M,N]=(0,y.useState)(``),[P,F]=(0,y.useState)(``),[I,L]=(0,y.useState)(`all`),[R,z]=(0,y.useState)(``),[B,V]=(0,y.useState)(`table`),[ee,te]=(0,y.useState)(a1e),[H,ne]=(0,y.useState)(t1e),[re,U]=(0,y.useState)(!1),[ie,ae]=(0,y.useState)(()=>{try{return localStorage.getItem(`bambuddy-inventory-group`)===`true`}catch{return!1}}),[W,oe]=(0,y.useState)(new Set),[se,ce]=(0,y.useState)(new Set),[le,ue]=(0,y.useState)(!1),[de,fe]=(0,y.useState)(null),pe=(0,y.useCallback)(e=>{ce(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),me=(0,y.useCallback)(()=>ce(new Set),[]);(0,y.useEffect)(()=>{ce(new Set)},[w,E,O,A,M,P,I,R]);let[he,ge]=(0,y.useState)(0),[_e,ve]=(0,y.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:ye}=q({queryKey:[`settings`],queryFn:Q.getSettings}),be=ye?.date_format||`system`,xe=e?[`spoolman-inventory-spools`]:[`inventory-spools`],Se=()=>R$e(r,xe),{data:Ce,isLoading:we}=q({queryKey:xe,queryFn:()=>e?Q.getSpoolmanInventorySpools(!0):Q.getSpools(!0),refetchInterval:3e4}),Te=(0,y.useCallback)(async()=>{x(!0);try{await Q.exportSpoolsCsv()}catch(e){i(e instanceof Error?e.message:n(`inventory.csv.exportError`,`Export failed`),`error`)}finally{x(!1)}},[i,n]),Ee=e?n(`inventory.csv.spoolmanHint`,`In Spoolman mode, use Spoolman's built-in CSV import/export.`):void 0,{data:De=[]}=q({queryKey:y9,queryFn:Q.getLocations}),Oe=c.get(`location_id`),ke=Oe===`__none__`?`__none__`:Oe&&/^\d+$/.test(Oe)&&Number(Oe)>0?Oe:``,Ae=c.get(`spool`),je=Ae&&/^\d+$/.test(Ae)&&Number(Ae)>0?Number(Ae):null,Me=Ce?.find(e=>e.id===je)??null,Ne=(0,y.useCallback)(()=>{f.current=!0,l(e=>(e.delete(`spool`),e),{replace:!0})},[l]),{data:Pe,isError:Fe,error:Ie}=q({queryKey:e?[`spoolman-inventory-spool`,je]:[`inventory-spool`,je],queryFn:()=>e?Q.getSpoolmanInventorySpool(je):Q.getSpool(je),enabled:t&&je!==null&&Me===null,staleTime:1/0,retry:(e,t)=>e<2&&!(t instanceof $u&&t.status===404)});(0,y.useEffect)(()=>{if(!f.current){if(t&&je&&Me){Ne(),d({spool:Me,mode:`edit`});return}if(Pe){Ne(),d({spool:Pe,mode:`edit`});return}Fe&&(Ne(),i(n(Ie instanceof $u&&Ie.status===404?`inventory.deepLinkSpoolNotFound`:`inventory.deepLinkFetchFailed`),`error`))}},[t,je,Me,Pe,Fe,Ie,Ne,i,n]);let{data:Le}=q({queryKey:[`spool-assignments`],queryFn:()=>Q.getAssignments(),refetchInterval:3e4}),{data:Re=[],isError:ze}=q({queryKey:[`spoolman-slot-assignments-all`],queryFn:()=>Q.getSpoolmanSlotAssignments(),enabled:e,refetchInterval:3e4,staleTime:1e4,retry:1}),Be=(0,y.useRef)(!1);(0,y.useEffect)(()=>{ze&&!Be.current?(Be.current=!0,i(n(`inventory.spoolmanUnreachable`),`error`)):ze||(Be.current=!1)},[ze,i,n]);let{data:Ve}=q({queryKey:[`spool-catalog`],queryFn:()=>Q.getSpoolCatalog()}),He=J({mutationFn:t=>e?Q.deleteSpoolmanInventorySpool(t):Q.deleteSpool(t),onSuccess:()=>{Se(),i(n(`inventory.spoolDeleted`),`success`)},onError:e=>{e instanceof $u&&e.status===404?i(n(`inventory.deleteSpoolNotFound`),`error`):e instanceof $u&&e.status===503?i(n(`inventory.spoolmanUnreachable`),`error`):i(n(`inventory.deleteFailed`),`error`)}}),Ue=J({mutationFn:t=>e?Q.archiveSpoolmanInventorySpool(t):Q.archiveSpool(t),onSuccess:()=>{Se(),i(n(`inventory.spoolArchived`),`success`)},onError:e=>{e instanceof $u&&e.status===404?i(n(`inventory.archiveSpoolNotFound`),`error`):e instanceof $u&&e.status===503?i(n(`inventory.spoolmanUnreachable`),`error`):i(n(`inventory.archiveFailed`),`error`)}}),We=J({mutationFn:t=>e?Q.restoreSpoolmanInventorySpool(t):Q.restoreSpool(t),onSuccess:()=>{Se(),i(n(`inventory.spoolRestored`),`success`)},onError:e=>{e instanceof $u&&e.status===404?i(n(`inventory.restoreSpoolNotFound`),`error`):e instanceof $u&&e.status===503?i(n(`inventory.spoolmanUnreachable`),`error`):i(n(`inventory.restoreFailed`),`error`)}}),Ge=J({mutationFn:t=>e?Q.resetSpoolmanInventorySpoolConsumedCounter(t):Q.resetSpoolConsumedCounter(t),onSuccess:()=>{r.invalidateQueries({queryKey:xe}),i(n(`inventory.consumedCounterReset`),`success`)},onError:()=>{i(n(`inventory.resetConsumedCounterFailed`),`error`)}}),Ke=J({mutationFn:t=>e?Q.bulkResetSpoolmanInventorySpoolConsumedCounter(t):Q.bulkResetSpoolConsumedCounter(t),onSuccess:e=>{r.invalidateQueries({queryKey:xe}),i(n(`inventory.allConsumedCountersReset`,{count:e.reset}),`success`),fe(null),me()},onError:()=>{i(n(`inventory.resetConsumedCounterFailed`),`error`)}}),qe=e=>(e.not_found?.length??0)+(e.errors?.length??0),Je=J({mutationFn:async({ids:t,update:n})=>e?Q.bulkUpdateSpoolmanInventorySpools(t,n):Q.bulkUpdateSpools(t,n),onSuccess:e=>{Se();let t=qe(e);if(e.updated===0){i(n(`inventory.bulk.updateAllFailed`,{count:t}),`error`);return}t>0?i(n(`inventory.bulk.updatePartial`,{ok:e.updated,failed:t}),`warning`):i(n(`inventory.bulk.updateSuccess`,{count:e.updated}),`success`),ue(!1),me()},onError:e=>{i(e.message||n(`inventory.bulk.updateFailed`),`error`)}}),Ye=J({mutationFn:async t=>e?Q.bulkDeleteSpoolmanInventorySpools(t):Q.bulkDeleteSpools(t),onSuccess:e=>{Se();let t=qe(e);if(e.deleted===0){i(n(`inventory.bulk.deleteAllFailed`,{count:t}),`error`);return}t>0?i(n(`inventory.bulk.deletePartial`,{ok:e.deleted,failed:t}),`warning`):i(n(`inventory.bulk.deleteSuccess`,{count:e.deleted}),`success`),fe(null),me()},onError:e=>{i(e.message||n(`inventory.bulk.deleteFailed`),`error`)}}),Xe=J({mutationFn:async t=>e?Q.bulkArchiveSpoolmanInventorySpools(t):Q.bulkArchiveSpools(t),onSuccess:e=>{Se();let t=qe(e);if(e.archived===0&&t>0){i(n(`inventory.bulk.archiveAllFailed`,{count:t}),`error`);return}t>0?i(n(`inventory.bulk.archivePartial`,{ok:e.archived,failed:t}),`warning`):i(n(`inventory.bulk.archiveSuccess`,{count:e.archived}),`success`),fe(null),me()},onError:e=>{i(e.message||n(`inventory.bulk.archiveFailed`),`error`)}}),Ze=J({mutationFn:async t=>e?Q.bulkRestoreSpoolmanInventorySpools(t):Q.bulkRestoreSpools(t),onSuccess:e=>{Se();let t=qe(e);if(e.restored===0&&t>0){i(n(`inventory.bulk.restoreAllFailed`,{count:t}),`error`);return}t>0?i(n(`inventory.bulk.restorePartial`,{ok:e.restored,failed:t}),`warning`):i(n(`inventory.bulk.restoreSuccess`,{count:e.restored}),`success`),fe(null),me()},onError:e=>{i(e.message||n(`inventory.bulk.restoreFailed`),`error`)}}),Qe=(0,y.useMemo)(()=>(Ce??[]).map(e=>e.id),[Ce]),et=async t=>{if(t.last_scale_weight!=null)try{e?await Q.syncSpoolmanSpoolWeight(t.id,t.last_scale_weight):await gd.updateSpoolWeight(t.id,t.last_scale_weight),r.invalidateQueries({queryKey:xe}),i(`Synced "${[t.brand,t.material,t.color_name].filter(Boolean).join(` `)}" to scale weight`,`success`)}catch(e){let t=e instanceof $u&&e.status===404,r=e instanceof $u&&e.status===503;i(n(t?`inventory.syncWeightSpoolNotFound`:r?`inventory.syncWeightSpoolmanUnreachable`:`inventory.syncWeightFailed`),`error`)}},tt=ye?.low_stock_threshold??20,[nt,rt]=(0,y.useState)(!1),[it,at]=(0,y.useState)(tt.toString());(0,y.useEffect)(()=>{nt||at(tt.toString())},[tt,nt]);let ot=J({mutationFn:e=>Q.updateSettings({low_stock_threshold:e}),onSuccess:()=>{r.invalidateQueries({queryKey:[`settings`]}),i(n(`common.saved`),`success`),rt(!1)},onError:()=>{i(n(`inventory.lowStockThresholdError`),`error`)}}),st=(0,y.useMemo)(()=>{if(!Ce)return null;let e=0,t=0,n=0,r=0,i={};for(let a of Ce){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??tt)&&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}},[Ce,tt]),ct=(Le?.length??0)+(e?Re.length:0),lt=Sf(ye?.currency||`USD`),ut=(0,y.useMemo)(()=>{let e={};for(let t of Le||[])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 Re)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},[Le,Re]),dt=(0,y.useMemo)(()=>{let e={};for(let t of Ve||[])e[t.id]=t;return e},[Ve]),ft=(0,y.useMemo)(()=>st?Object.entries(st.byMaterial).sort((e,t)=>t[1].weight-e[1].weight).slice(0,4):[],[st]),pt=(0,y.useMemo)(()=>{let e=Ce||[];if(e=w===`active`?e.filter(e=>!e.archived_at):e.filter(e=>!!e.archived_at),E===`used`?e=e.filter(e=>e.weight_used>0):E===`new`?e=e.filter(e=>e.weight_used===0):E===`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??tt)})),O&&(e=e.filter(e=>e.material===O)),A&&(e=e.filter(e=>e.brand===A)),M&&(e=M===`__none__`?e.filter(e=>!e.category):e.filter(e=>e.category===M)),P){let t=Number(P);e=e.filter(e=>e.core_weight_catalog_id===t)}if(ke)if(ke===`__none__`)e=e.filter(e=>!e.location_id&&!e.storage_location?.trim());else{let t=Number(ke),n=De.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 I===`stock`?e=e.filter(e=>!e.slicer_filament):I===`configured`&&(e=e.filter(e=>!!e.slicer_filament)),R&&(e=pU(e,R)),e},[Ce,w,E,O,A,M,P,I,ke,R,tt,De]),mt=()=>ge(0),ht=(0,y.useCallback)(e=>{l(t=>(t.delete(`location_id`),e&&t.set(`location_id`,e),t),{replace:!0}),mt()},[l]),gt=[...new Set(Ce?.map(e=>e.material)||[])].sort(),_t=[...new Set(Ce?.map(e=>e.brand).filter(Boolean)||[])].sort(),vt=[...new Set(Ce?.map(e=>e.category?.trim()).filter(Boolean)||[])].sort(),yt=(Ce??[]).some(e=>!e.category),bt=[...new Set(Ce?.map(e=>e.core_weight_catalog_id).filter(e=>e!=null)||[])].sort((e,t)=>{let n=(dt[e]?.name||``).toLowerCase(),r=(dt[t]?.name||``).toLowerCase();return n.localeCompare(r)}),xt=(Ce??[]).some(e=>!e.location_id&&!e.storage_location?.trim()),St=w!==`active`||E!==`all`||!!O||!!A||!!M||!!P||!!ke||I!==`all`||!!R,Ct=e=>{ne(e),n1e(e)},wt=(0,y.useMemo)(()=>H.filter(e=>e.visible).map(e=>e.id),[H]),Tt=e=>{O9[e]&&(te(t=>{let n;return n=t?.column===e?t.direction===`asc`?{column:e,direction:`desc`}:null:{column:e,direction:`asc`},o1e(n),n}),mt())},Et=(0,y.useMemo)(()=>{if(!ee)return pt;let e=O9[ee.column];return e?[...pt].sort((t,n)=>{let r=e(t,ut),i=e(n,ut);return ri?ee.direction===`asc`?1:-1:0}):pt},[pt,ee,ut]),Dt=(0,y.useMemo)(()=>{if(!ie)return Et.map(e=>({type:`single`,spool:e}));let e=new Map;for(let t of Et)if(!(t.weight_used>0||ut[t.id])){let n=$$e(t),r=e.get(n);r?r.push(t):e.set(n,[t])}let t=[],n=new Set;for(let r of Et){if(r.weight_used>0||ut[r.id]){t.push({type:`single`,spool:r});continue}let i=$$e(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},[Et,ie,ut]),Ot=_e===-1,kt=Dt.length,At=Ot?kt||1:_e,jt=Math.max(1,Math.ceil(kt/At)),Mt=Ot?0:Math.min(he,jt-1),Nt=Ot?Dt:Dt.slice(Mt*At,(Mt+1)*At),Pt=()=>{let e=!ie;ae(e),oe(new Set),mt();try{localStorage.setItem(`bambuddy-inventory-group`,String(e))}catch{}},Ft=e=>{oe(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},It=e=>{ve(e),ge(0);try{localStorage.setItem(`bambuddy-inventory-pageSize`,String(e))}catch{}};return(0,K.jsxs)(`div`,{className:`p-4 md:p-8 space-y-6`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,K.jsx)(vl,{className:`w-7 h-7 text-bambu-green`}),n(`inventory.title`)]}),(0,K.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:n(`inventory.subtitle`)})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)($,{variant:`secondary`,disabled:e,onClick:()=>v(!0),title:Ee,children:[(0,K.jsx)(Pu,{className:`w-4 h-4`}),n(`inventory.csv.importButton`,`Import CSV`)]}),(0,K.jsxs)($,{variant:`secondary`,disabled:e||b,onClick:Te,title:Ee,children:[b?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(Gs,{className:`w-4 h-4`}),n(`inventory.csv.exportButton`,`Export CSV`)]}),(0,K.jsxs)($,{variant:`secondary`,onClick:()=>C(!0),children:[(0,K.jsx)(tl,{className:`w-4 h-4`}),n(`locations.manage`)]}),(0,K.jsxs)($,{variant:`secondary`,disabled:pt.length===0,onClick:()=>g(pt.map(e=>e.id)),title:pt.length===0?n(`inventory.labels.noSpoolsTitle`,`No spools to label`):n(`inventory.labels.bulkTitle`,`Pick spools to print labels for from the {{count}} currently shown`,{count:pt.length}),children:[(0,K.jsx)(Ml,{className:`w-4 h-4`}),n(`inventory.labels.printLabels`,`Print labels…`)]}),(0,K.jsxs)($,{onClick:()=>d({spool:null,mode:`create`}),children:[(0,K.jsx)(kl,{className:`w-4 h-4`}),n(`inventory.addSpool`)]})]})]}),st&&!we&&(0,K.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-3 lg:grid-cols-5 gap-3`,children:[(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,K.jsx)(vl,{className:`w-4 h-4 text-bambu-green`}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray font-medium uppercase tracking-wide`,children:n(`inventory.totalInventory`)})]}),(0,K.jsx)(`div`,{className:`text-xl font-bold text-white`,children:T9(st.totalWeight,!0)}),(0,K.jsxs)(`div`,{className:`text-xs text-bambu-gray mt-1`,children:[st.totalSpools,` `,st.totalSpools===1?n(`inventory.spool`):n(`inventory.spools`)]})]}),(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-2 mb-1`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(Ou,{className:`w-4 h-4 text-blue-600 dark:text-blue-400`}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray font-medium uppercase tracking-wide`,children:n(`inventory.totalConsumed`)})]}),st.totalConsumed>0&&Qe.length>0&&(0,K.jsx)(`button`,{onClick:()=>m({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,K.jsx)(Zs,{className:`w-3.5 h-3.5`})})]}),(0,K.jsx)(`div`,{className:`text-xl font-bold text-white`,children:T9(st.totalConsumed,!0)}),(0,K.jsx)(`div`,{className:`text-xs text-bambu-gray mt-1`,children:n(`inventory.sinceTracking`)})]}),(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,K.jsx)(Hc,{className:`w-4 h-4 text-green-600 dark:text-green-400`}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray font-medium uppercase tracking-wide`,children:n(`inventory.byMaterial`)})]}),(0,K.jsx)(`div`,{className:`flex flex-wrap gap-1.5 mt-1`,children:ft.map(([e,t])=>(0,K.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium ${r1e[e]||`bg-bambu-dark-tertiary text-bambu-gray`}`,children:[e,` `,(0,K.jsx)(`span`,{className:`opacity-70`,children:T9(t.weight,!0)})]},e))})]}),(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,K.jsx)(Ml,{className:`w-4 h-4 text-purple-600 dark:text-purple-400`}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray font-medium uppercase tracking-wide`,children:n(`inventory.inPrinter`)})]}),(0,K.jsx)(`div`,{className:`text-xl font-bold text-white`,children:ct}),(0,K.jsx)(`div`,{className:`text-xs text-bambu-gray mt-1`,children:n(`inventory.loadedInAms`)})]}),(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,K.jsx)(Au,{className:`w-4 h-4 text-yellow-600 dark:text-yellow-400`}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray font-medium uppercase tracking-wide`,children:n(`inventory.lowStock`)})]}),(0,K.jsx)(`div`,{className:`text-xl font-bold ${st.lowStock>0?`text-yellow-700 dark:text-yellow-400`:`text-white`}`,children:st.lowStock}),(0,K.jsx)(`div`,{className:`text-xs text-bambu-gray mt-1 flex items-center gap-2`,children:nt?(0,K.jsxs)(`form`,{onSubmit:e=>{e.preventDefault();let t=parseFloat(it);!isNaN(t)&&t>=.1&&t<=99.9?ot.mutate(t):i(n(`inventory.lowStockThresholdError`),`error`)},className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:`<`}),(0,K.jsx)(`input`,{type:`text`,inputMode:`decimal`,pattern:`^\\d{0,2}(\\.\\d?)?$`,maxLength:4,value:it,onChange:e=>{let t=e.target.value.replace(/[^\d.]/g,``);/^\d{0,2}(\.\d?)?$/.test(t)&&at(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:ot.isPending}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:`%`}),(0,K.jsx)($,{type:`submit`,size:`sm`,disabled:ot.isPending,children:n(`common.save`)}),(0,K.jsx)($,{type:`button`,size:`sm`,variant:`ghost`,onClick:()=>rt(!1),disabled:ot.isPending,children:n(`common.cancel`)})]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`span`,{className:`text-bambu-gray`,children:[`< `,tt,`%`]}),(0,K.jsx)(`button`,{className:`p-1.5 text-bambu-gray hover:text-white rounded transition-colors`,title:n(`common.edit`),onClick:()=>{at(tt.toString()),rt(!0)},children:(0,K.jsx)(wl,{className:`w-4 h-4`})})]})})]})]}),(0,K.jsxs)(`div`,{className:`flex flex-col sm:flex-row gap-3 items-start sm:items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`relative flex-1 max-w-md ${B===`forecast`?`invisible pointer-events-none`:``}`,children:[(0,K.jsx)(Gl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50`}),(0,K.jsx)(`input`,{type:`text`,value:R,onChange:e=>{z(e.target.value),mt()},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`}),R&&(0,K.jsx)(`button`,{onClick:()=>{z(``),mt()},className:`absolute right-3 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white`,children:(0,K.jsx)(Ju,{className:`w-4 h-4`})})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[B===`table`&&(0,K.jsxs)(`button`,{onClick:()=>U(!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,K.jsx)(Ps,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:n(`inventory.columns`)})]}),B!==`forecast`&&(0,K.jsxs)(`button`,{onClick:Pt,className:`flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium border rounded-lg transition-colors ${ie?`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,K.jsx)(Ec,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:n(`inventory.groupSimilar`)})]}),(0,K.jsxs)(`div`,{className:`flex bg-bambu-dark-primary border border-bambu-dark-tertiary rounded-lg overflow-hidden`,children:[(0,K.jsxs)(`button`,{onClick:()=>V(`table`),className:`flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium transition-colors ${B===`table`?`bg-bambu-green text-white`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:[(0,K.jsx)(vu,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:n(`inventory.table`)})]}),(0,K.jsxs)(`button`,{onClick:()=>V(`cards`),className:`flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium transition-colors ${B===`cards`?`bg-bambu-green text-white`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:[(0,K.jsx)(Uc,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:n(`inventory.cards`)})]}),(0,K.jsxs)(`button`,{onClick:()=>s&&V(`forecast`),disabled:!s,title:s?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 ${B===`forecast`?`bg-bambu-green text-white`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:[s?(0,K.jsx)(ku,{className:`w-4 h-4`}):(0,K.jsx)(Zc,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:n(`forecast.title`)})]})]})]})]}),(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 ${B===`forecast`?`hidden`:``}`,children:[(0,K.jsxs)(`div`,{className:`flex items-center rounded-lg border border-bambu-dark-tertiary overflow-hidden`,children:[(0,K.jsxs)(`button`,{onClick:()=>{T(`active`),mt()},className:`flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium transition-colors ${w===`active`?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:[(0,K.jsx)(vl,{className:`w-3.5 h-3.5`}),n(`inventory.active`)]}),(0,K.jsxs)(`button`,{onClick:()=>{T(`archived`),mt()},className:`flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium transition-colors ${w===`archived`?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:[(0,K.jsx)(jo,{className:`w-3.5 h-3.5`}),n(`inventory.archived`)]})]}),(0,K.jsx)(`div`,{className:`w-px h-5 bg-bambu-dark-tertiary`}),(0,K.jsxs)(`div`,{className:`flex items-center rounded-lg border border-bambu-dark-tertiary overflow-hidden`,children:[(0,K.jsx)(`button`,{onClick:()=>{D(`all`),mt()},className:`px-3 py-1.5 text-xs font-medium transition-colors ${E===`all`?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:n(`inventory.all`)}),(0,K.jsxs)(`button`,{onClick:()=>{D(`used`),mt()},className:`flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium transition-colors ${E===`used`?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:[(0,K.jsx)(Ts,{className:`w-3.5 h-3.5`}),n(`inventory.used`)]}),(0,K.jsx)(`button`,{onClick:()=>{D(`new`),mt()},className:`px-3 py-1.5 text-xs font-medium transition-colors ${E===`new`?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:n(`inventory.new`)}),(0,K.jsxs)(`button`,{onClick:()=>{D(`lowstock`),mt()},className:`flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium transition-colors ${E===`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,K.jsx)(Au,{className:`w-3.5 h-3.5`}),n(`inventory.lowStock`)]})]}),(0,K.jsxs)(`div`,{className:`flex items-center rounded-lg border border-bambu-dark-tertiary overflow-hidden`,children:[(0,K.jsx)(`button`,{onClick:()=>{L(`all`),mt()},className:`px-3 py-1.5 text-xs font-medium transition-colors ${I===`all`?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:n(`inventory.all`)}),(0,K.jsx)(`button`,{onClick:()=>{L(`stock`),mt()},className:`px-3 py-1.5 text-xs font-medium transition-colors ${I===`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,K.jsx)(`button`,{onClick:()=>{L(`configured`),mt()},className:`px-3 py-1.5 text-xs font-medium transition-colors ${I===`configured`?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:n(`inventory.configured`)})]}),(0,K.jsx)(`div`,{className:`w-px h-5 bg-bambu-dark-tertiary`}),(0,K.jsxs)(`select`,{value:O,onChange:e=>{k(e.target.value),mt()},className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${O?`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,K.jsx)(`option`,{value:``,children:n(`inventory.material`)}),gt.map(e=>(0,K.jsx)(`option`,{value:e,children:e},e))]}),(0,K.jsxs)(`select`,{value:A,onChange:e=>{j(e.target.value),mt()},className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${A?`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,K.jsx)(`option`,{value:``,children:n(`inventory.brand`)}),_t.map(e=>(0,K.jsx)(`option`,{value:e,children:e},e))]}),(vt.length>0||M)&&(0,K.jsxs)(`select`,{value:M,onChange:e=>{N(e.target.value),mt()},className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${M?`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,K.jsx)(`option`,{value:``,children:n(`inventory.category`)}),vt.map(e=>(0,K.jsx)(`option`,{value:e,children:e},e)),yt&&(0,K.jsx)(`option`,{value:`__none__`,children:n(`inventory.categoryNone`)})]}),bt.length>0&&(0,K.jsxs)(`select`,{value:P,onChange:e=>{F(e.target.value),mt()},className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${P?`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,K.jsx)(`option`,{value:``,children:n(`inventory.spoolName`)}),bt.map(e=>(0,K.jsx)(`option`,{value:e,children:dt[e]?.name||`#${e}`},e))]}),(De.length>0||ke)&&(0,K.jsxs)(`select`,{value:ke,onChange:e=>{ht(e.target.value)},className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${ke?`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,K.jsx)(`option`,{value:``,children:n(`inventory.storageLocation`)}),De.map(e=>(0,K.jsx)(`option`,{value:String(e.id),children:e.name},e.id)),xt&&(0,K.jsx)(`option`,{value:`__none__`,children:n(`inventory.storageLocationNone`)})]}),St&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`w-px h-5 bg-bambu-dark-tertiary`}),(0,K.jsxs)(`button`,{onClick:()=>{T(`active`),D(`all`),k(``),j(``),N(``),F(``),L(`all`),z(``),l(e=>(e.delete(`location_id`),e),{replace:!0}),mt()},className:`flex items-center gap-1 text-xs text-bambu-gray hover:text-bambu-green transition-colors`,children:[(0,K.jsx)(Ju,{className:`w-3.5 h-3.5`}),n(`inventory.clearFilters`)]})]}),B!==`forecast`&&(0,K.jsxs)(`span`,{className:`ml-auto text-xs text-bambu-gray`,children:[Et.length,` `,Et.length===1?n(`inventory.spool`):n(`inventory.spools`),ie&&kt0&&B!==`forecast`&&(0,K.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,K.jsx)(`span`,{className:`text-sm text-bambu-green font-medium`,children:n(`inventory.bulk.selectionCount`,{count:se.size})}),(0,K.jsxs)(`div`,{className:`ml-auto flex flex-wrap items-center gap-2`,children:[(0,K.jsxs)($,{size:`sm`,variant:`secondary`,onClick:()=>ue(!0),children:[(0,K.jsx)(wl,{className:`w-3.5 h-3.5 mr-1.5`}),n(`inventory.bulk.edit`)]}),(0,K.jsxs)($,{size:`sm`,variant:`secondary`,onClick:()=>g([...se]),children:[(0,K.jsx)(Ml,{className:`w-3.5 h-3.5 mr-1.5`}),n(`inventory.bulk.printLabels`)]}),(0,K.jsxs)($,{size:`sm`,variant:`secondary`,onClick:()=>fe(`reset-consumed-counter`),children:[(0,K.jsx)(Zs,{className:`w-3.5 h-3.5 mr-1.5`}),n(`inventory.bulk.resetUsage`)]}),w===`archived`?(0,K.jsxs)($,{size:`sm`,variant:`secondary`,onClick:()=>fe(`restore`),children:[(0,K.jsx)(Ll,{className:`w-3.5 h-3.5 mr-1.5`}),n(`inventory.bulk.restore`)]}):(0,K.jsxs)($,{size:`sm`,variant:`secondary`,onClick:()=>fe(`archive`),children:[(0,K.jsx)(jo,{className:`w-3.5 h-3.5 mr-1.5`}),n(`inventory.bulk.archive`)]}),(0,K.jsxs)($,{size:`sm`,variant:`danger`,onClick:()=>fe(`delete`),children:[(0,K.jsx)(Du,{className:`w-3.5 h-3.5 mr-1.5`}),n(`inventory.bulk.delete`)]}),(0,K.jsx)(`button`,{className:`p-1.5 text-bambu-gray hover:text-white rounded transition-colors`,onClick:me,title:n(`inventory.bulk.clearSelection`),"aria-label":n(`inventory.bulk.clearSelection`),children:(0,K.jsx)(Ju,{className:`w-4 h-4`})})]})]}),we?(0,K.jsx)(`div`,{className:`flex justify-center py-16`,children:(0,K.jsx)(X,{className:`w-8 h-8 text-bambu-green animate-spin`})}):B===`forecast`?(0,K.jsx)(p$e,{spools:Ce||[]}):B===`cards`?Nt.length>0?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4`,children:Nt.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=S6({rgba:i.rgba,extraColors:i.extra_colors,effectType:i.effect_type,subtype:i.subtype,effectSize:`groupheader`}),s=W.has(t);return(0,K.jsxs)(`div`,{className:`col-span-full`,children:[(0,K.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:()=>Ft(t),children:[(0,K.jsx)(`div`,{className:`h-10 flex items-center px-4 gap-3`,style:o,children:(0,K.jsx)(`span`,{className:`bg-white/90 text-gray-800 px-3 py-0.5 rounded-full text-sm font-medium`,children:hf(i.color_name,i.rgba)||`-`})}),(0,K.jsxs)(`div`,{className:`px-4 py-3 flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(cs,{className:`w-4 h-4 text-bambu-gray transition-transform ${s?``:`-rotate-90`}`}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`h3`,{className:`font-semibold text-white`,children:[i.material,i.subtype?` ${i.subtype}`:``]}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i.brand||`-`})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,title:n(`inventory.remaining`),children:T9(a)}),(0,K.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,K.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,K.jsx)(u1e,{spool:e,remaining:t,pct:e.label_weight>0?t/e.label_weight*100:0,onClick:()=>d({spool:e,mode:`edit`}),onPrintLabel:()=>g([e.id]),onCopy:()=>d({spool:e,mode:`copy`}),t:n},e.id)})})]},`group-${t}`)}let t=e.spool,r=Math.max(0,t.label_weight-t.weight_used);return(0,K.jsx)(u1e,{spool:t,remaining:r,pct:t.label_weight>0?r/t.label_weight*100:0,onClick:()=>d({spool:t,mode:`edit`}),onPrintLabel:()=>g([t.id]),onCopy:()=>d({spool:t,mode:`copy`}),t:n},t.id)})}),(0,K.jsx)(l1e,{pageIndex:Mt,pageSize:_e,totalRows:kt,totalPages:jt,onPageChange:ge,onPageSizeChange:It,t:n})]}):(0,K.jsx)(p1e,{hasFilters:St,onAddSpool:()=>d({spool:null,mode:`create`}),t:n}):Nt.length>0?(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-dark-tertiary`,children:[(0,K.jsx)(`div`,{className:`overflow-x-auto`,children:(0,K.jsxs)(`table`,{className:`w-full`,children:[(0,K.jsx)(`thead`,{children:(0,K.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary bg-bambu-dark-tertiary/30`,children:[(0,K.jsx)(`th`,{className:`w-10 px-3 py-3`,children:(0,K.jsx)(`input`,{type:`checkbox`,className:`h-4 w-4 cursor-pointer`,"aria-label":n(`inventory.bulk.selectAllVisible`),checked:Nt.length>0&&Nt.every(e=>(e.type===`group`?e.spools.map(e=>e.id):[e.spool.id]).every(e=>se.has(e))),onChange:e=>{if(e.target.checked){let e=new Set(se);for(let t of Nt){let n=t.type===`group`?t.spools.map(e=>e.id):[t.spool.id];for(let t of n)e.add(t)}ce(e)}else{let e=new Set(se);for(let t of Nt){let n=t.type===`group`?t.spools.map(e=>e.id):[t.spool.id];for(let t of n)e.delete(t)}ce(e)}}})}),wt.map(e=>{let t=!!O9[e],r=ee?.column===e;return(0,K.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?()=>Tt(e):void 0,children:(0,K.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[i1e[e]?.(n)??e,t&&(r?ee.direction===`asc`?(0,K.jsx)(zo,{className:`w-3 h-3`}):(0,K.jsx)(No,{className:`w-3 h-3`}):(0,K.jsx)(Lo,{className:`w-3 h-3 opacity-30`}))]})},e)}),(0,K.jsx)(`th`,{className:`text-right py-3 px-4 text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:n(`common.actions`)})]})}),(0,K.jsx)(`tbody`,{children:Nt.map(e=>{if(e.type===`group`){let{key:t,spools:r}=e,i=W.has(t),a=Q$e(r),o=Math.max(0,a.label_weight-a.weight_used);return(0,K.jsx)(f1e,{spools:r,headerSpool:a,remaining:o,pct:a.label_weight>0?o/a.label_weight*100:0,isExpanded:i,onToggle:()=>Ft(t),selectedIds:se,onToggleSelected:pe,onToggleGroupSelected:(e,t)=>{ce(n=>{let r=new Set(n);for(let n of e)t?r.add(n):r.delete(n);return r})},onEdit:e=>d({spool:e,mode:`edit`}),onCopy:e=>d({spool:e,mode:`copy`}),onArchive:e=>m({type:`archive`,spoolId:e}),onDelete:e=>m({type:`delete`,spoolId:e}),onPrintLabel:e=>g([e]),onResetConsumedCounter:e=>m({type:`reset-consumed-counter`,spoolId:e}),visibleColumns:wt,assignmentMap:ut,catalogMap:dt,currencySymbol:lt,dateFormat:be,t:n,onSyncWeight:et},`group-${t}`)}let t=e.spool,r=Math.max(0,t.label_weight-t.weight_used);return(0,K.jsx)(d1e,{spool:t,remaining:r,pct:t.label_weight>0?r/t.label_weight*100:0,isSelected:se.has(t.id),onToggleSelected:()=>pe(t.id),onEdit:()=>d({spool:t,mode:`edit`}),onCopy:()=>d({spool:t,mode:`copy`}),onRestore:()=>We.mutate(t.id),onArchive:()=>m({type:`archive`,spoolId:t.id}),onDelete:()=>m({type:`delete`,spoolId:t.id}),onPrintLabel:()=>g([t.id]),onResetConsumedCounter:()=>m({type:`reset-consumed-counter`,spoolId:t.id}),visibleColumns:wt,assignmentMap:ut,catalogMap:dt,currencySymbol:lt,dateFormat:be,t:n,onSyncWeight:et},t.id)})})]})}),(0,K.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,K.jsx)(`span`,{className:`text-bambu-gray`,children:Ot?`${kt} ${n(kt===1?`inventory.spool`:`inventory.spools`)}`:(0,K.jsxs)(K.Fragment,{children:[n(`inventory.showing`),` `,Mt*At+1,` `,n(`inventory.to`),` `,Math.min((Mt+1)*At,kt),` `,n(`inventory.of`),` `,kt,` `,n(`inventory.spools`)]})}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:n(`inventory.show`)}),(0,K.jsxs)(`select`,{value:_e,onChange:e=>It(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,K.jsx)(`option`,{value:e,children:e},e)),(0,K.jsx)(`option`,{value:-1,children:n(`inventory.all`)})]}),!Ot&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`button`,{onClick:()=>ge(0),disabled:Mt===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,K.jsx)(fs,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>ge(e=>Math.max(0,e-1)),disabled:Mt===0,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,children:(0,K.jsx)(us,{className:`w-4 h-4`})}),(0,K.jsxs)(`span`,{className:`text-bambu-gray px-2 whitespace-nowrap`,children:[n(`inventory.page`),` `,Mt+1,` `,n(`inventory.of`),` `,jt]}),(0,K.jsx)(`button`,{onClick:()=>ge(e=>Math.min(jt-1,e+1)),disabled:Mt>=jt-1,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,children:(0,K.jsx)(ls,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>ge(jt-1),disabled:Mt>=jt-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,K.jsx)(ps,{className:`w-4 h-4`})})]})]})]})]}):(0,K.jsx)(p1e,{hasFilters:St,onAddSpool:()=>d({spool:null,mode:`create`}),t:n}),u!==null&&(0,K.jsx)(B$e,{isOpen:!0,onClose:()=>d(null),spool:u.spool,mode:u.mode,currencySymbol:lt,spoolmanMode:e,spoolsQueryKey:xe}),p&&(0,K.jsx)(qd,{title:p.type===`delete`?n(`common.delete`):p.type===`archive`?n(`inventory.archive`):p.type===`reset-consumed-counter`?n(`inventory.resetConsumedCounter`):n(`inventory.resetAllConsumedCounters`),message:p.type===`delete`?n(`inventory.deleteConfirm`):p.type===`archive`?n(`inventory.archiveConfirm`):p.type===`reset-consumed-counter`?n(`inventory.resetConsumedCounterConfirm`):n(`inventory.resetAllConsumedCountersConfirm`,{count:Qe.length}),confirmText:p.type===`delete`?n(`common.delete`):p.type===`archive`?n(`inventory.archive`):n(`inventory.resetConsumedCounter`),variant:p.type===`archive`?`warning`:`danger`,onConfirm:()=>{p.type===`delete`?He.mutate(p.spoolId):p.type===`archive`?Ue.mutate(p.spoolId):p.type===`reset-consumed-counter`?Ge.mutate(p.spoolId):Ke.mutate(Qe),m(null)},onCancel:()=>m(null)}),(0,K.jsx)(uG,{isOpen:re,onClose:()=>U(!1),columns:H,defaultColumns:w9,onSave:Ct}),(0,K.jsx)(q$e,{isOpen:h!==null,onClose:()=>g(null),availableSpools:pt,initialSelectedIds:h??[],spoolmanMode:e}),(0,K.jsx)(Z$e,{isOpen:le,selectedCount:se.size,isPending:Je.isPending,availableLocations:De.map(e=>({id:e.id,name:e.name})),availableMaterials:C9((Ce??[]).map(e=>e.material)),availableSubtypes:C9((Ce??[]).map(e=>e.subtype)),availableBrands:C9((Ce??[]).map(e=>e.brand)),availableCategories:C9((Ce??[]).map(e=>e.category)),availableSlicerFilaments:C9((Ce??[]).map(e=>e.slicer_filament)),availableSlicerFilamentNames:C9((Ce??[]).map(e=>e.slicer_filament_name)),onClose:()=>ue(!1),onApply:e=>Je.mutate({ids:[...se],update:e})}),de&&(0,K.jsx)(qd,{title:n(de===`delete`?`inventory.bulk.deleteTitle`:de===`archive`?`inventory.bulk.archiveTitle`:de===`restore`?`inventory.bulk.restoreTitle`:`inventory.bulk.resetUsageTitle`),message:n(de===`delete`?`inventory.bulk.deleteMessage`:de===`archive`?`inventory.bulk.archiveMessage`:de===`restore`?`inventory.bulk.restoreMessage`:`inventory.bulk.resetUsageMessage`,{count:se.size}),confirmText:n(de===`delete`?`common.delete`:de===`archive`?`inventory.archive`:de===`restore`?`inventory.restore`:`inventory.resetConsumedCounter`),variant:de===`delete`?`danger`:`warning`,isLoading:Ye.isPending||Xe.isPending||Ze.isPending||Ke.isPending,onConfirm:()=>{let e=[...se];de===`delete`?Ye.mutate(e):de===`archive`?Xe.mutate(e):de===`restore`?Ze.mutate(e):Ke.mutate(e)},onCancel:()=>fe(null)}),_&&(0,K.jsx)(J$e,{onClose:()=>v(!1),onImported:e=>{v(!1),r.invalidateQueries({queryKey:xe}),i(n(`inventory.csv.importSuccess`,`{{count}} spools imported`,{count:e}),`success`)}}),(0,K.jsx)(Y$e,{open:S,onClose:()=>C(!1),onPickLocation:e=>ht(String(e))})]})}function l1e({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,K.jsxs)(`div`,{className:`flex items-center justify-between pt-2 text-sm`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:s?`${n} ${o(n===1?`inventory.spool`:`inventory.spools`)}`:(0,K.jsxs)(K.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,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:o(`inventory.show`)}),(0,K.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,K.jsx)(`option`,{value:e,children:e},e)),(0,K.jsx)(`option`,{value:-1,children:o(`inventory.all`)})]}),!s&&(0,K.jsxs)(K.Fragment,{children:[(0,K.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,K.jsx)(fs,{className:`w-4 h-4`})}),(0,K.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,K.jsx)(us,{className:`w-4 h-4`})}),(0,K.jsxs)(`span`,{className:`text-bambu-gray px-2 whitespace-nowrap`,children:[o(`inventory.page`),` `,e+1,` `,o(`inventory.of`),` `,r]}),(0,K.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,K.jsx)(ls,{className:`w-4 h-4`})}),(0,K.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,K.jsx)(ps,{className:`w-4 h-4`})})]})]})]})}function u1e({spool:e,remaining:t,pct:n,onClick:r,onPrintLabel:i,onCopy:a,t:o}){let s=S6({rgba:e.rgba,extraColors:e.extra_colors,effectType:e.effect_type,subtype:e.subtype,effectSize:`card`});return(0,K.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,K.jsxs)(`div`,{className:`h-14 flex items-center justify-center`,style:s,children:[(0,K.jsx)(`span`,{className:`bg-white/90 text-gray-800 px-3 py-0.5 rounded-full text-sm font-medium`,children:hf(e.color_name,e.rgba)||`-`}),a&&(0,K.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,K.jsx)(Is,{className:`w-3.5 h-3.5`})})]}),(0,K.jsxs)(`div`,{className:`p-4 space-y-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`h3`,{className:`font-semibold text-white`,children:[e.material,e.subtype?` ${e.subtype}`:``]}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e.brand||`-`})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1`,children:[i&&(0,K.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,K.jsx)(Ml,{className:`w-4 h-4`})}),(0,K.jsxs)(`span`,{className:`text-xs font-mono text-bambu-gray bg-bambu-dark-tertiary px-2 py-1 rounded`,children:[`#`,e.id]})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex justify-between text-xs text-bambu-gray mb-1`,children:[(0,K.jsx)(`span`,{children:o(`inventory.remaining`)}),(0,K.jsxs)(`span`,{children:[Math.round(n),`%`]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`div`,{className:`flex-1 h-2 bg-bambu-dark-tertiary rounded-full overflow-hidden`,children:(0,K.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,K.jsxs)(`span`,{className:`text-xs text-bambu-gray min-w-[40px] text-right`,children:[Math.round(t),`g`]})]})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 text-xs`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`span`,{className:`text-bambu-gray/60`,children:[o(`inventory.labelWeight`),`: `]}),(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:T9(e.label_weight)})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`span`,{className:`text-bambu-gray/60`,children:[o(`inventory.weightUsed`),`: `]}),(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:e.weight_used>0?T9(e.weight_used):`-`})]})]}),e.note&&(0,K.jsx)(`div`,{className:`text-xs text-bambu-gray/60 pt-2 border-t border-bambu-dark-tertiary truncate`,title:e.note,children:e.note})]})]})}function d1e({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,currencySymbol:h,dateFormat:g,t:_,onSyncWeight:v}){return(0,K.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,K.jsx)(`td`,{className:`w-10 px-3 py-3`,onClick:e=>e.stopPropagation(),children:i&&(0,K.jsx)(`input`,{type:`checkbox`,className:`h-4 w-4 cursor-pointer`,"aria-label":_(`inventory.bulk.selectRow`),checked:!!r,onChange:i})}),f.map(r=>(0,K.jsx)(`td`,{className:`py-3 px-4`,children:D9[r]?.({spool:e,remaining:t,pct:n,assignmentMap:p,catalogMap:m,currencySymbol:h,dateFormat:g,t:_,onSyncWeight:v})},r)),(0,K.jsx)(`td`,{className:`py-3 px-4`,children:(0,K.jsxs)(`div`,{className:`flex items-center justify-end gap-1`,onClick:e=>e.stopPropagation(),children:[(0,K.jsx)(`button`,{onClick:a,className:`p-1.5 text-bambu-gray hover:text-white rounded transition-colors`,title:_(`common.edit`),children:(0,K.jsx)(wl,{className:`w-4 h-4`})}),o&&(0,K.jsx)(`button`,{onClick:o,className:`p-1.5 text-bambu-gray hover:text-bambu-green rounded transition-colors`,title:_(`inventory.copySpool`),children:(0,K.jsx)(Is,{className:`w-4 h-4`})}),u&&(0,K.jsx)(`button`,{onClick:u,className:`p-1.5 text-bambu-gray hover:text-white rounded transition-colors`,title:_(`inventory.labels.printOne`),children:(0,K.jsx)(Ml,{className:`w-4 h-4`})}),d&&e.weight_used>0&&(0,K.jsx)(`button`,{onClick:d,className:`p-1.5 text-bambu-gray hover:text-orange-600 dark:hover:text-orange-400 rounded transition-colors`,title:_(`inventory.resetConsumedCounterTooltip`),children:(0,K.jsx)(Zs,{className:`w-4 h-4`})}),e.archived_at?(0,K.jsx)(`button`,{onClick:s,className:`p-1.5 text-bambu-gray hover:text-bambu-green rounded transition-colors`,title:_(`inventory.restore`),children:(0,K.jsx)(Ll,{className:`w-4 h-4`})}):(0,K.jsx)(`button`,{onClick:c,className:`p-1.5 text-bambu-gray hover:text-yellow-600 dark:hover:text-yellow-400 rounded transition-colors`,title:_(`inventory.archive`),children:(0,K.jsx)(jo,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:l,className:`p-1.5 text-bambu-gray hover:text-red-600 dark:hover:text-red-400 rounded transition-colors`,title:_(`common.delete`),children:(0,K.jsx)(Du,{className:`w-4 h-4`})})]})})]})}function f1e({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,currencySymbol:h,dateFormat:g,t:_,onSyncWeight:v,selectedIds:y,onToggleSelected:b,onToggleGroupSelected:x}){let S=!!y&&e.every(e=>y.has(e.id));return(0,K.jsxs)(K.Fragment,{children:[(0,K.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,K.jsx)(`td`,{className:`w-10 px-3 py-3`,onClick:e=>e.stopPropagation(),children:x&&(0,K.jsx)(`input`,{type:`checkbox`,className:`h-4 w-4 cursor-pointer`,"aria-label":_(`inventory.bulk.selectGroup`),checked:S,onChange:t=>x(e.map(e=>e.id),t.target.checked)})}),f.map((a,o)=>(0,K.jsx)(`td`,{className:`py-3 px-4`,children:o===0?(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(cs,{className:`w-4 h-4 text-bambu-gray transition-transform ${i?``:`-rotate-90`}`}),D9[a]?.({spool:t,remaining:n,pct:r,assignmentMap:p,catalogMap:m,currencySymbol:h,dateFormat:g,t:_,onSyncWeight:v})]}):a===`id`?(0,K.jsx)(`span`,{className:`text-xs font-medium bg-bambu-green/20 text-bambu-green px-2 py-0.5 rounded-full`,children:_(`inventory.groupedSpools`,{count:e.length})}):D9[a]?.({spool:t,remaining:n,pct:r,assignmentMap:p,catalogMap:m,currencySymbol:h,dateFormat:g,t:_,onSyncWeight:v})},a)),(0,K.jsx)(`td`,{className:`py-3 px-4`,children:(0,K.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,K.jsx)(d1e,{spool:e,remaining:t,pct:e.label_weight>0?t/e.label_weight*100:0,isSelected:y?.has(e.id),onToggleSelected:b?()=>b(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,currencySymbol:h,dateFormat:g,t:_,onSyncWeight:v},e.id)})]})}function p1e({hasFilters:e,onAddSpool:t,t:n}){return(0,K.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-16 px-4`,children:[(0,K.jsxs)(`div`,{className:`relative mb-6`,children:[(0,K.jsx)(`div`,{className:`absolute inset-0 -m-4 bg-bambu-green/5 rounded-full blur-2xl`}),(0,K.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,K.jsx)(`div`,{className:`absolute -top-1 -right-1 w-3 h-3 rounded-full bg-bambu-green/30`}),(0,K.jsx)(`div`,{className:`absolute -bottom-2 -left-2 w-2 h-2 rounded-full bg-bambu-green/20`}),e?(0,K.jsx)(Gl,{className:`w-10 h-10 text-bambu-gray/40`,strokeWidth:1.5}):(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(`div`,{className:`w-14 h-14 rounded-full border-4 border-bambu-gray/20 flex items-center justify-center`,children:(0,K.jsx)(`div`,{className:`w-6 h-6 rounded-full bg-bambu-gray/10 border-2 border-bambu-gray/20`})}),(0,K.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,K.jsx)(`span`,{className:`text-white text-lg font-bold leading-none`,children:`+`})})]})]})]}),(0,K.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-2 text-center`,children:e?n(`inventory.noSpoolsMatch`):n(`inventory.noSpools`).split(`.`)[0]}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray text-center max-w-sm mb-6`,children:n(e?`inventory.noSpoolsMatchDesc`:`inventory.noSpools`)}),!e&&(0,K.jsxs)($,{onClick:t,children:[(0,K.jsx)(vl,{className:`w-4 h-4`}),n(`inventory.addSpool`)]})]})}function A9(e,t){let n=e?.[t];return typeof n==`string`?n:``}function m1e(e){return e.replace(/(https?:\/\/(?:makerworld|public-cdn)\.bblmw\.com\/[^\s"']+)/gi,e=>`/api/v1/makerworld/thumbnail?url=${encodeURIComponent(e)}`)}function j9(e){return e?/^https?:\/\/(makerworld|public-cdn)\.bblmw\.com\//i.test(e)?`/api/v1/makerworld/thumbnail?url=${encodeURIComponent(e)}`:e:``}function M9(e,t){let n=e?.[t];return typeof n==`number`?n:null}function h1e(e,t){let n=e?.[t];return n&&typeof n==`object`&&!Array.isArray(n)?n:void 0}function g1e(e,t=0,n=[]){n.push({folder:e,depth:t});for(let r of e.children??[])g1e(r,t+1,n);return n}function _1e(e,t){return t(e<1?`makerworld.phaseResolving`:`makerworld.phaseDownloading`)}function v1e(e){let[t,n]=(0,y.useState)(0);return(0,y.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 y1e(){let{t:e}=$e(),{hasPermission:t}=xd(),{showToast:n}=Fd(),r=ao(),i=t(`makerworld:import`),[a,o]=(0,y.useState)(``),[s,c]=(0,y.useState)(null),[l,u]=(0,y.useState)(null),[d,f]=(0,y.useState)(null),[p,m]=(0,y.useState)(null),[h,g]=(0,y.useState)(null),[_,v]=(0,y.useState)(``),[b,x]=(0,y.useState)({}),S=q({queryKey:[`makerworld-status`],queryFn:()=>Q.getMakerworldStatus()}),C=q({queryKey:[`library-folders`],queryFn:()=>Q.getLibraryFolders()}),w=q({queryKey:[`makerworld-recent-imports`],queryFn:()=>Q.getMakerworldRecentImports(10)}),T=q({queryKey:[`settings`],queryFn:()=>Q.getSettings()}),E=T.data?.use_slicer_api??!1,D=T.data?.preferred_slicer||`bambu_studio`,O=eG(T.data?.open_in_slicer,T.data?.preferred_slicer),k=E?D:O,A=k===`orcaslicer`?`OrcaSlicer`:`Bambu Studio`,[j,M]=(0,y.useState)(null),N=(e,t)=>{M({kind:`libraryFile`,id:e,filename:t})},P=J({mutationFn:e=>Q.resolveMakerworldUrl(e),onSuccess:(e,t)=>{c(e),v(t),x({})},onError:t=>n(t.message||e(`makerworld.errors.resolveFailed`),`error`)});(0,y.useEffect)(()=>{s!==null&&a.trim()!==_.trim()&&(c(null),v(``),x({}))},[a,s,_]);let F=J({mutationFn:({instanceId:e,profileId:t})=>Q.importMakerworldInstance(s?.model_id??0,e,t,l),onSuccess:t=>{r.invalidateQueries({queryKey:[`library-files`]}),r.invalidateQueries({queryKey:[`library-folders`]}),t.profile_id&&x(e=>({...e,[t.profile_id]:t})),n(t.was_existing?e(`makerworld.alreadyInLibrary`):e(`makerworld.importSuccess`,{filename:t.filename}),`success`)},onError:t=>n(t.message||e(`makerworld.errors.downloadFailed`),`error`)}),I=J({mutationFn:({libraryFileId:e})=>Q.deleteLibraryFile(e),onSuccess:(t,{profileId:i})=>{r.invalidateQueries({queryKey:[`library-files`]}),r.invalidateQueries({queryKey:[`library-folders`]}),r.invalidateQueries({queryKey:[`makerworld-recent-imports`]}),x(e=>{let t={...e};return delete t[i],t}),m(null),n(e(`makerworld.importDeleted`),`success`)},onError:t=>{m(null),n(t.message||e(`makerworld.errors.deleteFailed`),`error`)}}),L=J({mutationFn:({instanceId:e,profileId:t})=>Q.importMakerworldInstance(s?.model_id??0,e,t,l),onSuccess:async e=>{r.invalidateQueries({queryKey:[`library-files`]}),r.invalidateQueries({queryKey:[`library-folders`]}),r.invalidateQueries({queryKey:[`makerworld-recent-imports`]}),e.profile_id&&x(t=>({...t,[e.profile_id]:e})),E?N(e.library_file_id,e.filename):await te(e.library_file_id,e.filename,k)},onError:t=>n(t.message||e(`makerworld.errors.downloadFailed`),`error`)}),R=v1e(F.isPending||L.isPending),z=_1e(R,e),B=e=>{e?.preventDefault();let t=a.trim();t&&P.mutate(t)};(0,y.useEffect)(()=>{if(!h)return;let e=e=>{e.key===`Escape`?g(null):e.key===`ArrowLeft`?g(e=>e&&e.index>0?{...e,index:e.index-1}:e):e.key===`ArrowRight`&&g(e=>e&&e.indexwindow.removeEventListener(`keydown`,e)},[h]);let V=e=>{let t=(Array.isArray(e.pictures)?e.pictures:[]).filter(e=>typeof e==`object`&&!!e).map(e=>({name:A9(e,`name`)||`image`,url:A9(e,`url`)})).filter(e=>e.url);if(t.length>0)return t;let n=A9(e,`cover`);return n?[{name:`cover`,url:n}]:[]},ee=async()=>{if(!s)return;let e=s.instances.filter(e=>{let t=M9(e,`profileId`);return t!==null&&!b[t]});if(e.length!==0){f({current:0,total:e.length});try{for(let t=0;t{try{let{token:r}=await Q.createLibrarySlicerToken(e),i=Q.getLibrarySlicerDownloadUrl(e,r,t);rG(`${window.location.origin}${i}`,n)}catch{let t=Q.getLibraryFileDownloadUrl(e);rG(`${window.location.origin}${t}`,n)}},H=s?.design,ne=h1e(H,`designCreator`),re=s?.instances??[],U=(s?.already_imported_library_ids.length??0)>0,ie=S.data?.can_download??!1,ae=S.data?.sign_in_expired??!1,W=(0,y.useMemo)(()=>A9(H,`coverUrl`),[H]),oe=A9(H,`title`),se=A9(H,`summary`),ce=A9(H,`license`),le=M9(H,`downloadCount`);return(0,K.jsxs)(`div`,{className:`p-4 md:p-8 max-w-screen-2xl space-y-6`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,K.jsx)(wc,{className:`w-7 h-7 text-bambu-green`}),e(`makerworld.title`)]}),(0,K.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:e(`makerworld.description`)})]}),(0,K.jsxs)(`div`,{className:`grid gap-6 lg:grid-cols-[1fr_20rem]`,children:[(0,K.jsxs)(`div`,{className:`space-y-6 min-w-0`,children:[!ie&&(0,K.jsx)(Dd,{className:`border-amber-300 dark:border-amber-700 bg-amber-50 dark:bg-amber-900/20`,children:(0,K.jsx)(kd,{children:(0,K.jsxs)(`div`,{className:`flex items-start gap-3 py-2`,children:[(0,K.jsx)(ms,{className:`w-5 h-5 text-amber-600 dark:text-amber-400 mt-0.5 shrink-0`}),(0,K.jsxs)(`div`,{className:`text-sm`,children:[(0,K.jsx)(`p`,{className:`font-medium text-amber-900 dark:text-amber-100`,children:e(ae?`makerworld.signInExpiredTitle`:`makerworld.signInRequiredTitle`)}),(0,K.jsxs)(`p`,{className:`text-amber-800 dark:text-amber-200 mt-1`,children:[e(ae?`makerworld.signInExpiredBody`:`makerworld.signInRequiredBody`),` `,(0,K.jsx)(Di,{to:`/profiles`,className:`underline`,children:e(`makerworld.openCloudSettings`)})]})]})]})})}),(0,K.jsxs)(Dd,{children:[(0,K.jsx)(Od,{children:(0,K.jsx)(`h2`,{className:`text-lg font-semibold`,children:e(`makerworld.pasteUrlHeader`)})}),(0,K.jsx)(kd,{children:(0,K.jsxs)(`form`,{onSubmit:B,className:`flex gap-2`,children:[(0,K.jsx)(`input`,{type:`text`,value:a,onChange:e=>o(e.target.value),placeholder:e(`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,K.jsxs)($,{type:`submit`,variant:`primary`,disabled:!a.trim()||P.isPending,children:[P.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(Io,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{className:`ml-2`,children:e(`makerworld.resolveButton`)})]})]})})]}),s&&(0,K.jsx)(Dd,{children:(0,K.jsx)(kd,{children:(0,K.jsxs)(`div`,{className:`flex gap-4 py-2`,children:[W&&(0,K.jsx)(`img`,{src:j9(W),alt:oe,className:`w-32 h-32 object-cover rounded`,loading:`lazy`}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`h3`,{className:`text-xl font-semibold truncate`,children:oe||e(`makerworld.untitledModel`)}),ne&&(0,K.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400 mt-1`,children:e(`makerworld.byCreator`,{name:A9(ne,`name`)})}),(0,K.jsxs)(`div`,{className:`flex flex-wrap gap-3 mt-2 text-xs text-gray-500 dark:text-gray-400`,children:[le!==null&&(0,K.jsx)(`span`,{children:e(`makerworld.downloadsCount`,{count:le})}),ce&&(0,K.jsxs)(`span`,{children:[e(`makerworld.licensePrefix`),`: `,ce]}),U&&(0,K.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-emerald-600 dark:text-emerald-400`,children:[(0,K.jsx)(ss,{className:`w-3 h-3`}),` `,e(`makerworld.alreadyImported`)]})]}),se&&(0,K.jsx)(`div`,{className:`mt-3 text-sm prose prose-sm max-w-none dark:prose-invert line-clamp-3`,dangerouslySetInnerHTML:{__html:iK.sanitize(m1e(se))}}),s&&(0,K.jsxs)(`a`,{href:`https://makerworld.com/models/${s.model_id}${s.profile_id?`#profileId-${s.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,K.jsx)(Qs,{className:`w-3 h-3`}),` `,e(`makerworld.openOnMakerworld`)]})]})]})})}),s&&re.length>0&&(0,K.jsxs)(Dd,{children:[(0,K.jsx)(Od,{children:(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,K.jsx)(`h2`,{className:`text-lg font-semibold`,children:e(`makerworld.platesHeader`,{count:re.length})}),(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,K.jsx)(`label`,{className:`text-xs text-gray-600 dark:text-gray-400`,children:e(`makerworld.importTo`)}),(0,K.jsxs)(`select`,{value:l??``,onChange:e=>u(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:d!==null,children:[(0,K.jsx)(`option`,{value:``,children:e(`makerworld.folderAuto`)}),(C.data??[]).filter(e=>!(e.is_external&&e.external_readonly)).flatMap(e=>g1e(e)).map(({folder:e,depth:t})=>(0,K.jsx)(`option`,{value:e.id,children:`${`— `.repeat(t)}${e.name}`},e.id))]}),(0,K.jsx)($,{variant:`primary`,size:`sm`,disabled:!i||!ie||d!==null||F.isPending||L.isPending,onClick:ee,children:d===null?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Gs,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{className:`ml-2`,children:e(`makerworld.importAll`)})]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),(0,K.jsxs)(`span`,{className:`ml-2`,children:[e(`makerworld.importAllProgress`,{current:d.current,total:d.total}),R>0&&` · ${z} · ${R}s`]})]})})]})]})}),(0,K.jsx)(kd,{children:(0,K.jsx)(`div`,{className:`grid gap-3`,children:re.map((t,n)=>{let r=M9(t,`id`),a=M9(t,`profileId`),o=A9(t,`title`),s=A9(t,`cover`),c=M9(t,`materialCnt`),l=t?.needAms===!0,u=M9(t,`downloadCount`),f=t?.compatibility??null,p=t?.otherCompatibility??null,h=f?.devProductName??null,_=Array.isArray(p)?p.map(e=>e?.devProductName??``).filter(Boolean):[];if(r==null)return null;let v=F.isPending&&F.variables?.instanceId===r,y=L.isPending&&L.variables?.instanceId===r,x=a===null?void 0:b[a];return(0,K.jsxs)(`div`,{className:`flex flex-col gap-2 p-3 border rounded border-gray-200 dark:border-gray-700`,children:[(0,K.jsxs)(`div`,{className:`flex gap-3 items-center`,children:[(()=>{let n=V(t),r=n.length>0;return(0,K.jsxs)(`button`,{type:`button`,disabled:!r,onClick:()=>r&&g({images:n,index:0}),className:`relative w-16 h-16 shrink-0 rounded overflow-hidden group`,"aria-label":e(`makerworld.openGallery`),children:[s?(0,K.jsx)(`img`,{src:j9(s),alt:``,className:`w-16 h-16 object-cover`,loading:`lazy`}):(0,K.jsx)(`div`,{className:`w-16 h-16 bg-gray-100 dark:bg-gray-800`}),n.length>1&&(0,K.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,K.jsx)(Lc,{className:`w-2.5 h-2.5`}),n.length]})]})})(),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`p`,{className:`font-medium truncate`,children:o||e(`makerworld.plateDefaultName`,{n:n+1})}),(0,K.jsxs)(`div`,{className:`flex flex-wrap gap-3 text-xs text-gray-500 dark:text-gray-400 mt-1`,children:[h&&(0,K.jsx)(`span`,{className:`font-medium text-gray-700 dark:text-gray-300`,children:e(`makerworld.slicedFor`,{printer:h,defaultValue:`Sliced for {{printer}}`})}),c!==null&&(0,K.jsx)(`span`,{children:e(`makerworld.materialCount`,{count:c})}),l&&(0,K.jsx)(`span`,{children:e(`makerworld.amsRequired`)}),u!==null&&(0,K.jsx)(`span`,{children:e(`makerworld.downloadsCount`,{count:u})})]}),_.length>0&&(0,K.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mt-1`,title:_.join(`, `),children:e(`makerworld.alsoCompatible`,{printers:_.slice(0,6).join(`, `)+(_.length>6?`…`:``),defaultValue:`Also marked compatible: {{printers}}`})})]}),(0,K.jsxs)(`div`,{className:`flex gap-2 shrink-0`,children:[(0,K.jsx)($,{variant:`ghost`,size:`sm`,disabled:!i||!ie||v||y||d!==null,onClick:()=>F.mutate({instanceId:r,profileId:a}),title:ie?void 0:e(`makerworld.signInRequiredTitle`),children:v?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),(0,K.jsxs)(`span`,{className:`ml-2`,children:[z,R>0&&` · ${R}s`]})]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Gs,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{className:`ml-2`,children:e(`makerworld.importToLibrary`)})]})}),(0,K.jsx)($,{variant:`primary`,size:`sm`,disabled:!i||!ie||v||y||d!==null,onClick:()=>L.mutate({instanceId:r,profileId:a}),title:ie?void 0:e(`makerworld.signInRequiredTitle`),children:y?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),(0,K.jsxs)(`span`,{className:`ml-2`,children:[z,R>0&&` · ${R}s`]})]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Qs,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{className:`ml-2`,children:e(`makerworld.sliceIn`,{slicer:A})})]})})]})]}),x&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 pl-20 text-xs`,children:[(0,K.jsx)(ss,{className:`w-3.5 h-3.5 text-emerald-600 dark:text-emerald-400 shrink-0`}),(0,K.jsx)(`span`,{className:`text-emerald-700 dark:text-emerald-300`,children:x.was_existing?e(`makerworld.lastImportAlreadyInLibrary`):e(`makerworld.lastImportSuccess`)}),(0,K.jsxs)($,{variant:`ghost`,size:`sm`,onClick:()=>{let e=x.folder_id?`/files?folder=${x.folder_id}`:`/files`;window.location.assign(e)},children:[(0,K.jsx)(fc,{className:`w-3.5 h-3.5`}),(0,K.jsx)(`span`,{className:`ml-1.5`,children:e(`makerworld.viewInLibrary`)})]}),E?(0,K.jsxs)($,{variant:`ghost`,size:`sm`,onClick:()=>N(x.library_file_id,x.filename),children:[(0,K.jsx)(Ns,{className:`w-3.5 h-3.5`}),(0,K.jsx)(`span`,{className:`ml-1.5`,children:e(`slice.action`,`Slice`)})]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)($,{variant:`ghost`,size:`sm`,onClick:()=>te(x.library_file_id,x.filename,`bambu_studio`),children:[(0,K.jsx)(Qs,{className:`w-3.5 h-3.5`}),(0,K.jsx)(`span`,{className:`ml-1.5`,children:e(`makerworld.openInBambuStudio`)})]}),(0,K.jsxs)($,{variant:`ghost`,size:`sm`,onClick:()=>te(x.library_file_id,x.filename,`orcaslicer`),children:[(0,K.jsx)(Qs,{className:`w-3.5 h-3.5`}),(0,K.jsx)(`span`,{className:`ml-1.5`,children:e(`makerworld.openInOrcaSlicer`)})]})]}),(0,K.jsx)(`div`,{className:`ml-auto`,children:(0,K.jsx)($,{variant:`ghost`,size:`sm`,disabled:I.isPending&&I.variables?.profileId===a,onClick:()=>{a!==null&&m({libraryFileId:x.library_file_id,profileId:a,filename:x.filename})},title:e(`makerworld.deleteImport`),children:I.isPending&&I.variables?.profileId===a?(0,K.jsx)(X,{className:`w-3.5 h-3.5 animate-spin`}):(0,K.jsx)(Du,{className:`w-3.5 h-3.5 text-red-500`})})})]})]},r)})})})]})]}),(0,K.jsx)(`aside`,{className:`lg:sticky lg:top-6 lg:self-start min-w-0`,children:w.data&&w.data.length>0&&(0,K.jsxs)(Dd,{children:[(0,K.jsx)(Od,{children:(0,K.jsx)(`h2`,{className:`text-base font-semibold`,children:e(`makerworld.recentImportsHeader`)})}),(0,K.jsx)(kd,{children:(0,K.jsx)(`div`,{className:`flex flex-col gap-2 max-h-[28rem] overflow-y-auto -mx-2 px-2`,children:w.data.map(t=>(0,K.jsxs)(`div`,{className:`flex gap-2 p-2 border rounded border-gray-200 dark:border-gray-700`,children:[t.thumbnail_path?(0,K.jsx)(`img`,{src:Q.getLibraryFileThumbnailUrl(t.library_file_id),alt:``,className:`w-12 h-12 shrink-0 object-cover rounded bg-gray-100 dark:bg-gray-800`,loading:`lazy`}):(0,K.jsx)(`div`,{className:`w-12 h-12 shrink-0 rounded bg-gray-100 dark:bg-gray-800`}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0 flex flex-col gap-1`,children:[(0,K.jsx)(`p`,{className:`text-xs font-medium truncate`,title:t.filename,children:t.filename}),(0,K.jsxs)(`div`,{className:`flex gap-0.5`,children:[(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:()=>{let e=t.folder_id?`/files?folder=${t.folder_id}`:`/files`;window.location.assign(e)},title:e(`makerworld.viewInLibrary`),children:(0,K.jsx)(fc,{className:`w-3.5 h-3.5`})}),E?(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:()=>N(t.library_file_id,t.filename),title:e(`slice.action`,`Slice`),children:(0,K.jsx)(Ns,{className:`w-3.5 h-3.5`})}):(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:()=>te(t.library_file_id,t.filename,`bambu_studio`),title:e(`makerworld.openInBambuStudio`),children:(0,K.jsx)(Qs,{className:`w-3.5 h-3.5`})}),t.source_url&&(0,K.jsx)(`a`,{href:t.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:e(`makerworld.openOnMakerworld`),children:(0,K.jsx)(wc,{className:`w-3.5 h-3.5`})})]})]})]},t.library_file_id))})})]})})]}),(0,K.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 pt-4 border-t border-gray-200 dark:border-gray-700`,children:e(`makerworld.disclaimer`)}),p&&(0,K.jsx)(qd,{title:e(`makerworld.deleteImport`),message:e(`makerworld.confirmDelete`,{filename:p.filename}),confirmText:e(`makerworld.deleteImport`),variant:`danger`,isLoading:I.isPending,loadingText:e(`makerworld.importDeleting`),onCancel:()=>m(null),onConfirm:()=>I.mutate({libraryFileId:p.libraryFileId,profileId:p.profileId})}),j&&(0,K.jsx)(XW,{source:j,onClose:()=>M(null)}),h&&(0,K.jsxs)(`div`,{className:`fixed inset-0 bg-black/90 flex items-center justify-center z-50`,onClick:()=>g(null),role:`dialog`,"aria-modal":`true`,children:[(0,K.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(),g(null)},"aria-label":e(`common.close`,`Close`),children:(0,K.jsx)(Ju,{className:`w-5 h-5`})}),h.images.length>1&&(0,K.jsxs)(K.Fragment,{children:[(0,K.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(),g(e=>e&&{...e,index:Math.max(0,e.index-1)})},"aria-label":e(`makerworld.galleryPrev`),children:(0,K.jsx)(us,{className:`w-6 h-6`})}),(0,K.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(),g(e=>e&&{...e,index:Math.min(e.images.length-1,e.index+1)})},"aria-label":e(`makerworld.galleryNext`),children:(0,K.jsx)(ls,{className:`w-6 h-6`})})]}),(0,K.jsx)(`img`,{src:j9(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,K.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]})]})]})}var b1e=[`DEBUG`,`INFO`,`WARNING`,`ERROR`],N9={DEBUG:`text-gray-400`,INFO:`text-blue-400`,WARNING:`text-yellow-400`,ERROR:`text-red-400`},x1e={DEBUG:Yo,INFO:Rc,WARNING:Au,ERROR:ms};function S1e(){let e=ao(),[t,n]=(0,y.useState)(!0),[r,i]=(0,y.useState)(new Set),[a,o]=(0,y.useState)(``),[s,c]=(0,y.useState)(`ALL`),[l,u]=(0,y.useState)(!1),[d,f]=(0,y.useState)(!1),p=(0,y.useRef)(null),{data:m,isLoading:h,refetch:g}=q({queryKey:[`application-logs`,s,a],queryFn:()=>hd.getLogs({limit:200,level:s===`ALL`?void 0:s,search:a||void 0}),refetchInterval:d?2e3:!1,enabled:l});(0,y.useEffect)(()=>{l||f(!1)},[l]);let _=J({mutationFn:()=>hd.clearLogs(),onSuccess:()=>{e.invalidateQueries({queryKey:[`application-logs`]})}});(0,y.useEffect)(()=>{t&&p.current&&m?.entries&&(p.current.scrollTop=p.current.scrollHeight)},[m?.entries,t]);let v=e=>{i(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},b=e=>{let t=e.split(` `);return t.length>=2?t[1]:e},x=(0,y.useMemo)(()=>m?.entries??[],[m?.entries]),S=(0,y.useMemo)(()=>[...x].reverse(),[x]),C=({level:e})=>(0,K.jsx)(x1e[e]||Rc,{className:`w-3.5 h-3.5 ${N9[e]||`text-gray-400`}`});return(0,K.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg overflow-hidden`,children:[(0,K.jsxs)(`button`,{onClick:()=>u(!l),className:`w-full flex items-center justify-between p-4 hover:bg-bambu-dark-tertiary/50 transition-colors`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`p-2 rounded-lg ${d?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark-tertiary text-bambu-gray`}`,children:(0,K.jsx)(Yo,{className:`w-5 h-5`})}),(0,K.jsxs)(`div`,{className:`text-left`,children:[(0,K.jsx)(`p`,{className:`font-medium text-white`,children:`Application Logs`}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:d?`Live streaming - ${m?.filtered_count??0} entries`:`View and filter application logs`})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[d&&(0,K.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,K.jsx)(`span`,{className:`w-1.5 h-1.5 bg-bambu-green rounded-full animate-pulse`}),`Live`]}),l?(0,K.jsx)(ds,{className:`w-5 h-5 text-bambu-gray`}):(0,K.jsx)(cs,{className:`w-5 h-5 text-bambu-gray`})]})]}),l&&(0,K.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex flex-col gap-2 p-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[d?(0,K.jsxs)(`button`,{onClick:e=>{e.stopPropagation(),f(!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,K.jsx)(pu,{className:`w-4 h-4`}),`Stop`]}):(0,K.jsxs)(`button`,{onClick:e=>{e.stopPropagation(),f(!0),g()},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,K.jsx)(Dl,{className:`w-4 h-4`}),`Start`]}),(0,K.jsxs)(`button`,{onClick:()=>_.mutate(),disabled:_.isPending||x.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,K.jsx)(Du,{className:`w-4 h-4`}),`Clear`]}),(0,K.jsx)(`button`,{onClick:()=>g(),disabled:h,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,K.jsx)(Fl,{className:`w-4 h-4 ${h?`animate-spin`:``}`})}),(0,K.jsx)(`div`,{className:`flex-1`}),(0,K.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-bambu-gray cursor-pointer`,children:[(0,K.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,K.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[m?.filtered_count??0,`/`,m?.total_in_file??0]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)(`div`,{className:`relative flex-1`,children:[(0,K.jsx)(Gl,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`input`,{type:`text`,placeholder:`Search message or logger name...`,value:a,onChange:e=>o(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`}),a&&(0,K.jsx)(`button`,{onClick:()=>o(``),className:`absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white`,children:(0,K.jsx)(Ju,{className:`w-4 h-4`})})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1 bg-bambu-dark-secondary rounded border border-bambu-dark-tertiary`,children:[(0,K.jsx)(`button`,{onClick:()=>c(`ALL`),className:`px-2 py-1.5 text-xs rounded-l transition-colors ${s===`ALL`?`bg-bambu-green text-white`:`text-bambu-gray hover:text-white`}`,children:`All`}),b1e.map((e,t)=>(0,K.jsx)(`button`,{onClick:()=>c(e),className:`px-2 py-1.5 text-xs transition-colors flex items-center gap-1 ${t===b1e.length-1?`rounded-r`:``} ${s===e?`${N9[e]} bg-bambu-dark-tertiary`:`text-bambu-gray hover:text-white`}`,children:e},e))]})]})]}),(0,K.jsx)(`div`,{ref:p,className:`overflow-auto font-mono text-xs bg-black min-h-[300px] max-h-[500px]`,children:x.length===0?(0,K.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-[300px] text-bambu-gray`,children:[(0,K.jsx)(`p`,{className:`mb-2`,children:`No log entries found`}),(0,K.jsx)(`p`,{className:`text-sm`,children:`Log file may be empty or cleared`})]}):(0,K.jsx)(`div`,{className:`divide-y divide-bambu-dark-tertiary/30`,children:S.map((e,t)=>{let n=r.has(t),i=e.message.includes(` `);return(0,K.jsx)(`div`,{className:`p-2 cursor-pointer hover:bg-bambu-dark-secondary/50 transition-colors ${n?`bg-bambu-dark-secondary/30`:``}`,onClick:()=>i&&v(t),children:(0,K.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray/70 shrink-0 w-20`,children:b(e.timestamp)}),(0,K.jsx)(`span`,{className:`shrink-0`,children:(0,K.jsx)(C,{level:e.level})}),(0,K.jsxs)(`span`,{className:`text-purple-400/80 shrink-0 max-w-[200px] truncate`,title:e.logger_name,children:[`[`,e.logger_name,`]`]}),(0,K.jsx)(`span`,{className:`flex-1 ${N9[e.level]||`text-white/80`} ${!n&&i?`truncate`:``}`,children:n?(0,K.jsx)(`pre`,{className:`whitespace-pre-wrap break-all`,children:e.message}):e.message.split(` -`)[0]}),i&&(0,K.jsx)(`span`,{className:`text-bambu-gray/50 shrink-0`,children:n?(0,K.jsx)(ds,{className:`w-3.5 h-3.5`}):(0,K.jsx)(cs,{className:`w-3.5 h-3.5`})})]})},t)})})}),(0,K.jsx)(`div`,{className:`flex items-center justify-between p-3 border-t border-bambu-dark-tertiary text-sm text-bambu-gray`,children:d?(0,K.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`w-2 h-2 bg-green-500 rounded-full animate-pulse`}),`Auto-refreshing every 2 seconds`]}):(0,K.jsx)(`span`,{children:`Click Start to enable live log streaming`})})]})]})}function C1e(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 P9({icon:e,label:t,value:n,subValue:r,color:i=`text-bambu-green`}){return(0,K.jsxs)(`div`,{className:`flex items-start gap-3 p-4 bg-bambu-dark rounded-lg`,children:[(0,K.jsx)(`div`,{className:`p-2 rounded-lg bg-bambu-dark-tertiary ${i}`,children:(0,K.jsx)(e,{className:`w-5 h-5`})}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:t}),(0,K.jsx)(`p`,{className:`text-lg font-semibold text-white truncate`,children:n}),r&&(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:r})]})]})}function w1e({percent:e,color:t=`bg-bambu-green`}){return(0,K.jsx)(`div`,{className:`w-full h-2 bg-bambu-dark rounded-full overflow-hidden`,children:(0,K.jsx)(`div`,{className:`h-full ${t} transition-all duration-300`,style:{width:`${Math.min(100,e)}%`}})})}function F9({title:e,icon:t,children:n}){return(0,K.jsxs)(Dd,{className:`p-6`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-4`,children:[(0,K.jsx)(t,{className:`w-5 h-5 text-bambu-green`}),(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e})]}),n]})}function T1e(){let{t:e}=$e(),t=ao(),[n,r]=(0,y.useState)(null),[i,a]=(0,y.useState)(!1),[o,s]=(0,y.useState)(!1),[c,l]=(0,y.useState)(null),{data:u,isLoading:d,refetch:f,isFetching:p}=q({queryKey:[`systemInfo`],queryFn:Q.getSystemInfo,refetchInterval:3e4}),{data:m}=q({queryKey:[`debugLogging`],queryFn:hd.getDebugLoggingState,staleTime:10*1e3,refetchInterval:10*1e3}),{data:h}=q({queryKey:[`settings`],queryFn:Q.getSettings}),{data:g}=q({queryKey:[`library-stats`],queryFn:Q.getLibraryStats}),{data:_}=q({queryKey:[`printers`],queryFn:Q.getPrinters}),{data:v,refetch:b,isFetching:x}=q({queryKey:[`systemHealth`],queryFn:Q.getSystemHealth,staleTime:60*1e3}),S=h?.time_format||`system`,C=async()=>{s(!0);try{let e=await hd.setDebugLogging(!m?.enabled);t.setQueryData([`debugLogging`],e)}catch(e){console.error(`Failed to toggle debug logging:`,e)}finally{s(!1)}},w=async()=>{r(null),a(!0);try{await hd.downloadSupportBundle()}catch(e){r(e instanceof Error?e.message:`Failed to download support bundle`)}finally{a(!1)}};if(d)return(0,K.jsx)(`div`,{className:`flex items-center justify-center h-64`,children:(0,K.jsx)(X,{className:`w-8 h-8 text-bambu-green animate-spin`})});if(!u)return(0,K.jsx)(`div`,{className:`p-6 text-center text-bambu-gray`,children:e(`system.failedToLoad`,`Failed to load system information`)});let T=u.storage.disk_percent_used>90?`bg-red-500`:u.storage.disk_percent_used>75?`bg-yellow-500`:`bg-bambu-green`,E=u.memory.percent_used>90?`bg-red-500`:u.memory.percent_used>75?`bg-yellow-500`:`bg-bambu-green`;return(0,K.jsxs)(`div`,{className:`p-6 space-y-6`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h1`,{className:`text-2xl font-bold text-white`,children:e(`system.title`,`System Information`)}),(0,K.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:e(`system.subtitle`,`Monitor system resources and database statistics`)})]}),(0,K.jsxs)(`button`,{onClick:()=>f(),disabled:p,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,K.jsx)(Fl,{className:`w-4 h-4 ${p?`animate-spin`:``}`}),e(`common.refresh`,`Refresh`)]})]}),(0,K.jsx)(F9,{title:e(`system.application`,`Application`),icon:Jl,children:(0,K.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-4`,children:[(0,K.jsx)(P9,{icon:Jl,label:e(`system.version`,`Version`),value:`v${u.app.version}`}),(0,K.jsx)(P9,{icon:Ts,label:e(`system.uptime`,`System Uptime`),value:u.system.uptime_formatted}),(0,K.jsx)(P9,{icon:Jl,label:e(`system.hostname`,`Hostname`),value:u.system.hostname})]})}),(0,K.jsx)(F9,{title:e(`support.title`,`Support & Troubleshooting`),icon:Ac,children:(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.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,K.jsxs)(`div`,{className:`flex items-center justify-between p-4 bg-bambu-dark rounded-lg`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`p-2 rounded-lg ${m?.enabled?`bg-amber-500/20 text-amber-500`:`bg-bambu-dark-tertiary text-bambu-gray`}`,children:(0,K.jsx)(Yo,{className:`w-5 h-5`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`font-medium text-white`,children:e(`support.debugLogging`,`Debug Logging`)}),(0,K.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[m?.enabled?e(`support.debugLoggingEnabled`,`Capturing detailed logs`):e(`support.debugLoggingDisabled`,`Normal logging level`),m?.enabled&&m.duration_seconds!==null&&(0,K.jsxs)(`span`,{className:`text-amber-700 dark:text-amber-400 ml-2`,children:[`(`,Math.floor(m.duration_seconds/60),`m `,m.duration_seconds%60,`s)`]})]})]})]}),(0,K.jsxs)(`button`,{onClick:C,disabled:o,className:`px-4 py-2 rounded-lg font-medium transition-colors flex items-center gap-2 ${m?.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:[o&&(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),m?.enabled?e(`support.disableDebug`,`Disable`):e(`support.enableDebug`,`Enable`)]})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-4 bg-bambu-dark rounded-lg`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`p-2 rounded-lg bg-bambu-dark-tertiary text-bambu-green`,children:(0,K.jsx)(Gs,{className:`w-5 h-5`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`font-medium text-white`,children:e(`support.supportBundle`,`Support Bundle`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`support.supportBundleDescription`,`Download system info and logs as a ZIP file`)})]})]}),(0,K.jsxs)(`button`,{onClick:w,disabled:i||!m?.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:m?.enabled?void 0:e(`support.enableDebugFirst`,`Enable debug logging first`),children:[i&&(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),i?e(`support.bundleGenerating`,`Generating...`):e(`common.download`,`Download`)]})]}),i&&(0,K.jsxs)(`div`,{className:`p-3 bg-bambu-dark-tertiary/40 rounded-lg space-y-1`,children:[(0,K.jsxs)(`p`,{className:`text-sm font-medium text-white flex items-center gap-2`,children:[(0,K.jsx)(X,{className:`w-3.5 h-3.5 animate-spin text-bambu-green`}),e(`support.bundleGenerating`,`Generating...`)]}),(0,K.jsxs)(`ul`,{className:`text-xs text-bambu-gray list-disc list-inside space-y-0.5 pl-1`,children:[(0,K.jsx)(`li`,{children:e(`support.bundleStepConnection`,`Running printer connectivity checks`)}),(0,K.jsx)(`li`,{children:e(`support.bundleStepVirtualPrinters`,`Running virtual-printer setup checks`)}),(0,K.jsx)(`li`,{children:e(`support.bundleStepLogScan`,`Scanning recent logs for known issues`)}),(0,K.jsx)(`li`,{children:e(`support.bundleStepBuild`,`Building the support bundle ZIP`)})]})]}),n&&(0,K.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}),!m?.enabled&&(0,K.jsx)(`div`,{className:`p-4 bg-bambu-dark-tertiary/50 rounded-lg`,children:(0,K.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[(0,K.jsx)(`span`,{className:`text-amber-700 dark:text-amber-400 font-medium`,children:e(`support.instructions`,`To report an issue:`)}),(0,K.jsx)(`br`,{}),`1. `,e(`support.step1`,`Enable debug logging`),(0,K.jsx)(`br`,{}),`2. `,e(`support.step2`,`Reproduce the issue`),(0,K.jsx)(`br`,{}),`3. `,e(`support.step3`,`Download the support bundle`),(0,K.jsx)(`br`,{}),`4. `,e(`support.step4`,`Attach the ZIP file to your issue report`)]})}),(0,K.jsxs)(`div`,{className:`p-4 bg-bambu-dark rounded-lg space-y-3`,children:[(0,K.jsx)(`p`,{className:`text-sm font-medium text-white`,children:e(`support.privacyTitle`,`What's in the support bundle?`)}),(0,K.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4 text-sm`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-bambu-green font-medium mb-1`,children:e(`support.collected`,`Collected:`)}),(0,K.jsxs)(`ul`,{className:`text-bambu-gray space-y-0.5`,children:[(0,K.jsxs)(`li`,{children:[`• `,e(`support.collectItem1`,`App version and debug mode`)]}),(0,K.jsxs)(`li`,{children:[`• `,e(`support.collectItem2`,`OS, architecture, Python version`)]}),(0,K.jsxs)(`li`,{children:[`• `,e(`support.collectItem3`,`Database statistics (counts only)`)]}),(0,K.jsxs)(`li`,{children:[`• `,e(`support.collectItem4`,`Printer models and nozzle counts`)]}),(0,K.jsxs)(`li`,{children:[`• `,e(`support.collectItem5`,`Non-sensitive settings (themes, formats)`)]}),(0,K.jsxs)(`li`,{children:[`• `,e(`support.collectItem6`,`Debug logs (sanitized)`)]}),(0,K.jsxs)(`li`,{children:[`• `,e(`support.collectItem7`,`Printer connectivity and firmware versions`)]}),(0,K.jsxs)(`li`,{children:[`• `,e(`support.collectItem8`,`Integration status (Spoolman, MQTT, HA)`)]}),(0,K.jsxs)(`li`,{children:[`• `,e(`support.collectItem9`,`Network interfaces (subnets only)`)]}),(0,K.jsxs)(`li`,{children:[`• `,e(`support.collectItem10`,`Python package versions`)]}),(0,K.jsxs)(`li`,{children:[`• `,e(`support.collectItem11`,`Database health checks`)]}),(0,K.jsxs)(`li`,{children:[`• `,e(`support.collectItem12`,`Docker environment details`)]})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-red-700 dark:text-red-400 font-medium mb-1`,children:e(`support.notCollected`,`NOT collected:`)}),(0,K.jsxs)(`ul`,{className:`text-bambu-gray space-y-0.5`,children:[(0,K.jsxs)(`li`,{children:[`• `,e(`support.notItem1`,`Printer names and serial numbers`)]}),(0,K.jsxs)(`li`,{children:[`• `,e(`support.notItem2`,`Access codes and passwords`)]}),(0,K.jsxs)(`li`,{children:[`• `,e(`support.notItem3`,`Email addresses`)]}),(0,K.jsxs)(`li`,{children:[`• `,e(`support.notItem4`,`API keys and tokens`)]}),(0,K.jsxs)(`li`,{children:[`• `,e(`support.notItem5`,`Webhook URLs`)]}),(0,K.jsxs)(`li`,{children:[`• `,e(`support.notItem6`,`Your hostname or username`)]}),(0,K.jsxs)(`li`,{children:[`• `,e(`support.notItem7`,`IP addresses`)]})]})]})]}),(0,K.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,K.jsx)(S1e,{})]})}),(0,K.jsxs)(F9,{title:e(`diagnostic.sectionTitle`,`Connection Diagnostic`),icon:hu,children:[(0,K.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.`)}),_&&_.length>0?(0,K.jsx)(`div`,{className:`space-y-2`,children:_.map(t=>(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-3 bg-bambu-dark rounded-lg`,children:[(0,K.jsxs)(`div`,{className:`min-w-0`,children:[(0,K.jsx)(`span`,{className:`font-medium text-white`,children:t.name}),(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray ml-2`,children:t.ip_address})]}),(0,K.jsxs)(`button`,{onClick:()=>l(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,K.jsx)(hu,{className:`w-4 h-4`}),e(`diagnostic.runButton`,`Run diagnostic`)]})]},t.id))}):(0,K.jsx)(`p`,{className:`text-bambu-gray`,children:e(`diagnostic.noPrinters`,`No printers configured.`)})]}),(0,K.jsxs)(F9,{title:e(`systemHealth.sectionTitle`),icon:jc,children:[(0,K.jsxs)(`div`,{className:`flex items-start justify-between gap-3 mb-3`,children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`systemHealth.sectionDescription`)}),(0,K.jsxs)(`button`,{onClick:()=>b(),disabled:x,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,K.jsx)(Fl,{className:`w-4 h-4 ${x?`animate-spin`:``}`}),e(`systemHealth.rescan`)]})]}),v?(0,K.jsx)(Ip,{result:v}):(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`common.loading`)})]}),(0,K.jsxs)(F9,{title:e(`system.database`,`Database`),icon:Bs,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4 mb-4`,children:[(0,K.jsx)(P9,{icon:Bs,label:e(`system.dbEngine`,`Database Engine`),value:u.database.engine||`SQLite`}),(0,K.jsx)(P9,{icon:Bs,label:e(`system.dbVersion`,`Version`),value:u.database.version||`unknown`})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-4 mb-4`,children:[(0,K.jsx)(P9,{icon:jo,label:e(`system.totalArchives`,`Total Archives`),value:u.database.archives}),(0,K.jsx)(P9,{icon:_s,label:e(`system.completed`,`Completed`),value:u.database.archives_completed,color:`text-green-500`}),(0,K.jsx)(P9,{icon:Ss,label:e(`system.failed`,`Failed`),value:u.database.archives_failed,color:`text-red-500`}),(0,K.jsx)(P9,{icon:X,label:e(`system.printing`,`Printing`),value:u.database.archives_printing,color:`text-yellow-500`})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-4`,children:[(0,K.jsx)(P9,{icon:Ml,label:e(`system.printers`,`Printers`),value:u.database.printers}),(0,K.jsx)(P9,{icon:yl,label:e(`system.filaments`,`Filaments`),value:u.database.filaments}),(0,K.jsx)(P9,{icon:dc,label:e(`system.projects`,`Projects`),value:u.database.projects}),(0,K.jsx)(P9,{icon:Ol,label:e(`system.smartPlugs`,`Smart Plugs`),value:u.database.smart_plugs})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4 mt-4`,children:[(0,K.jsx)(P9,{icon:Ts,label:e(`system.totalPrintTime`,`Total Print Time`),value:u.database.total_print_time_formatted}),(0,K.jsx)(P9,{icon:jo,label:e(`system.totalFilament`,`Total Filament Used`),value:`${u.database.total_filament_kg} kg`,subValue:`${u.database.total_filament_grams.toLocaleString()} g`})]})]}),(0,K.jsxs)(F9,{title:e(`system.connectedPrinters`,`Connected Printers`),icon:Ml,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-4 mb-4`,children:[(0,K.jsx)(`div`,{className:`text-3xl font-bold text-bambu-green`,children:u.printers.connected}),(0,K.jsx)(`div`,{className:`text-bambu-gray`,children:e(`system.ofTotal`,`of {{total}} printers connected`,{total:u.printers.total})})]}),u.printers.connected_list.length>0?(0,K.jsx)(`div`,{className:`space-y-2`,children:u.printers.connected_list.map(e=>(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-3 bg-bambu-dark rounded-lg`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-bambu-green`}),(0,K.jsx)(`span`,{className:`font-medium text-white`,children:e.name})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-4 text-sm text-bambu-gray`,children:[(0,K.jsx)(`span`,{children:e.model}),(0,K.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,K.jsx)(`p`,{className:`text-bambu-gray`,children:e(`system.noPrintersConnected`,`No printers connected`)})]}),(0,K.jsx)(F9,{title:e(`system.storage`,`Storage`),icon:Oc,children:(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex justify-between text-sm mb-1`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:e(`system.diskUsage`,`Disk Usage`)}),(0,K.jsxs)(`span`,{className:`text-white`,children:[u.storage.disk_used_formatted,` / `,u.storage.disk_total_formatted]})]}),(0,K.jsx)(w1e,{percent:u.storage.disk_percent_used,color:T}),(0,K.jsxs)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:[u.storage.disk_free_formatted,` `,e(`system.free`,`free`),` (`,(100-u.storage.disk_percent_used).toFixed(1),`%)`]})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-4`,children:[(0,K.jsx)(P9,{icon:jo,label:e(`system.archiveStorage`,`Archive Storage`),value:u.storage.archive_size_formatted}),(0,K.jsx)(P9,{icon:Bs,label:e(`system.databaseSize`,`Database Size`),value:u.storage.database_size_formatted}),g&&(0,K.jsx)(P9,{icon:fc,label:e(`system.fileManagerStorage`,`File Manager`),value:C1e(g.total_size_bytes),subValue:`${g.total_files} files, ${g.total_folders} folders`})]})]})}),(0,K.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-6`,children:[(0,K.jsx)(F9,{title:e(`system.memory`,`Memory`),icon:al,children:(0,K.jsx)(`div`,{className:`space-y-4`,children:(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex justify-between text-sm mb-1`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:e(`system.memoryUsage`,`Memory Usage`)}),(0,K.jsxs)(`span`,{className:`text-white`,children:[u.memory.used_formatted,` / `,u.memory.total_formatted]})]}),(0,K.jsx)(w1e,{percent:u.memory.percent_used,color:E}),(0,K.jsxs)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:[u.memory.available_formatted,` `,e(`system.available`,`available`)]})]})})}),(0,K.jsx)(F9,{title:e(`system.cpu`,`CPU`),icon:Ls,children:(0,K.jsx)(`div`,{className:`space-y-4`,children:(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,K.jsx)(P9,{icon:Ls,label:e(`system.cores`,`Cores`),value:u.cpu.count,subValue:`${u.cpu.count_logical} logical`}),(0,K.jsx)(P9,{icon:Ls,label:e(`system.usage`,`Usage`),value:`${u.cpu.percent}%`})]})})})]}),(0,K.jsx)(F9,{title:e(`system.systemDetails`,`System Details`),icon:Jl,children:(0,K.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-4`,children:[(0,K.jsx)(P9,{icon:Jl,label:e(`system.os`,`Operating System`),value:u.system.platform,subValue:u.system.platform_release}),(0,K.jsx)(P9,{icon:Ls,label:e(`system.architecture`,`Architecture`),value:u.system.architecture}),(0,K.jsx)(P9,{icon:Jl,label:e(`system.python`,`Python`),value:u.system.python_version}),(0,K.jsx)(P9,{icon:Ts,label:e(`system.bootTime`,`Boot Time`),value:Gf(u.system.boot_time,S)})]})}),c&&(0,K.jsx)(Mp,{printerId:c.id,printerName:c.name,onClose:()=>l(null)})]})}var I9=`auth_remember_me`,L9=`auth_post_login_redirect`;function R9(e){return e?`persistent`:`session`}function E1e(){try{let e=sessionStorage.getItem(I9)===`1`;return sessionStorage.removeItem(I9),e}catch(e){return console.warn(`consumeSavedRememberMe: sessionStorage unavailable, Remember Me preference lost across OIDC redirect`,e),!1}}function z9(e){return!e||!e.startsWith(`/`)||e.startsWith(`//`)||e.startsWith(`/login`)?null:e}function D1e(e){let t=z9(e);if(t)try{sessionStorage.setItem(L9,t)}catch(e){console.warn(`stashPostLoginRedirect: sessionStorage unavailable, post-login target will be lost across OIDC redirect`,e)}}function O1e(){try{let e=sessionStorage.getItem(L9);return sessionStorage.removeItem(L9),z9(e)}catch(e){return console.warn(`consumePostLoginRedirect: sessionStorage unavailable`,e),null}}function k1e({provider:e,onClick:t,disabled:n}){let{t:r}=$e(),[i,a]=(0,y.useState)(!1);return(0,K.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&&!i?(0,K.jsx)(`img`,{src:Q.oidcProviderIconUrl(e.id),alt:``,className:`w-5 h-5 object-contain`,onError:()=>a(!0)}):(0,K.jsx)(eu,{className:`w-5 h-5 text-bambu-green`}),r(`login.twoFA.signInWith`,{provider:e.name})]})}function A1e(){let e=ir(),t=tr(),[n]=Fi(),{t:r}=$e(),{login:i,loginWithToken:a,user:o,loading:s}=xd(),{showToast:c}=Fd(),{mode:l}=wd();function u(){let e=t.state?.from;if(e?.pathname){let t=z9(`${e.pathname}${e.search??``}`);if(t)return t}return O1e()??`/`}let[d,f]=(0,y.useState)(``),[p,m]=(0,y.useState)(``),[h,g]=(0,y.useState)(!1),[_,v]=(0,y.useState)(``),[b,x]=(0,y.useState)(`credentials`),[S,C]=(0,y.useState)(``),[w,T]=(0,y.useState)([]),[E,D]=(0,y.useState)(`totp`),[O,k]=(0,y.useState)(``),[A,j]=(0,y.useState)(!1),M=(0,y.useRef)(null),[N,P]=(0,y.useState)(!1),[F,I]=(0,y.useState)(``),[L,R]=(0,y.useState)(``),[z,B]=(0,y.useState)(``),{data:V}=q({queryKey:[`advancedAuthStatus`],queryFn:()=>Q.getAdvancedAuthStatus()}),{data:ee}=q({queryKey:[`oidcProviders`],queryFn:()=>Q.getOIDCProviders()}),[te,H]=(0,y.useState)(!1);(0,y.useEffect)(()=>{!s&&o&&b===`credentials`&&e(`/`,{replace:!0})},[s,o,b,e]);let ne=(0,y.useRef)(!1);(0,y.useEffect)(()=>{if(ne.current||n.get(`fallback`)===`local`||!V||!V.autologin_provider_id||window.location.hash.startsWith(`#oidc_token=`)||n.get(`oidc_error`))return;ne.current=!0;let e=V.autologin_provider_id,t=new Promise((e,t)=>setTimeout(()=>t(Error(`autologin timeout`)),5e3));Promise.race([Q.getOIDCAuthorizeUrl(e),t]).then(e=>{window.location.href=e.auth_url}).catch(()=>{H(!0)})},[V,n]);let re=V?.local_login_enabled!==!1,U=te&&V?.autologin_provider_id!=null;(0,y.useEffect)(()=>{let t=window.location.hash,n=t.startsWith(`#reset_token=`)?t.slice(13):null;n&&(I(n),x(`reset-password`),e(`/login`,{replace:!0}))},[]),(0,y.useEffect)(()=>{let t=window.location.hash,i=t.startsWith(`#oidc_token=`)?t.slice(12):null,o=n.get(`oidc_error`);if(!i&&!o)return;let s=E1e();if(o){c({oidc_provider_error:r(`login.oidcErrors.providerError`),missing_parameters:r(`login.oidcErrors.missingParameters`),invalid_state:r(`login.oidcErrors.invalidState`),state_expired:r(`login.oidcErrors.stateExpired`),provider_not_found:r(`login.oidcErrors.providerNotFound`),discovery_failed:r(`login.oidcErrors.discoveryFailed`),invalid_discovery_document:r(`login.oidcErrors.invalidDiscovery`),token_exchange_network_error:r(`login.oidcErrors.networkError`),token_exchange_bad_response:r(`login.oidcErrors.badResponse`),no_id_token:r(`login.oidcErrors.noIdToken`),token_validation_failed:r(`login.oidcErrors.validationFailed`),nonce_mismatch:r(`login.oidcErrors.nonceMismatch`),missing_sub_claim:r(`login.oidcErrors.missingSubClaim`),no_linked_account:r(`login.oidcErrors.noLinkedAccount`),account_inactive:r(`login.oidcErrors.accountInactive`),user_resolution_failed:r(`login.oidcErrors.userResolutionFailed`),internal_error:r(`login.oidcErrors.internalError`)}[o]??(o.startsWith(`token_exchange_`)?r(`login.oidcErrors.tokenExchangeFailed`):r(`login.oidcLoginFailed`)),`error`),e(`/login`,{replace:!0});return}i&&Q.exchangeOIDCToken(i).then(t=>{if(t.requires_2fa&&t.pre_auth_token){P(s),C(t.pre_auth_token);let n=t.two_fa_methods??[];T(n),n.includes(`totp`)?D(`totp`):n.includes(`email`)?D(`email`):D(`backup`),x(`2fa`),e(`/login`,{replace:!0})}else t.access_token&&t.user?(a(t.access_token,t.user,R9(s)),c(r(`login.loginSuccess`)),e(u(),{replace:!0})):(c(r(`login.oidcLoginFailed`),`error`),e(`/login`,{replace:!0}))}).catch(t=>{console.error(`OIDC token exchange failed`,t),c(r(`login.oidcLoginFailed`),`error`),e(`/login`,{replace:!0})})},[n]);let ie=J({mutationFn:()=>i(d,p,R9(N)),onSuccess:t=>{if(t.requires_2fa&&t.pre_auth_token){C(t.pre_auth_token);let e=t.two_fa_methods??[];T(e),e.includes(`totp`)?D(`totp`):e.includes(`email`)?D(`email`):D(`backup`),x(`2fa`)}else t.access_token&&t.user&&(c(r(`login.loginSuccess`)),e(u(),{replace:!0}))},onError:e=>{c(e.message||r(`login.loginFailed`),`error`)}}),ae=J({mutationFn:e=>Q.forgotPassword({email:e}),onSuccess:e=>{c(e.message,`success`),g(!1),v(``)},onError:e=>{c(e.message,`error`)}}),W=J({mutationFn:()=>Q.forgotPasswordConfirm(F,L),onSuccess:e=>{c(e.message,`success`),x(`credentials`),I(``),R(``),B(``)},onError:e=>{c(e.message||r(`login.resetPassword.resetFailed`),`error`)}}),oe=J({mutationFn:()=>Q.sendEmailOTP(S),onSuccess:e=>{j(!0),e.pre_auth_token&&C(e.pre_auth_token),c(e.message,`success`)},onError:e=>{c(e.message||r(`login.twoFA.sendCodeFailed`),`error`)}}),se=J({mutationFn:()=>Q.verify2FA({pre_auth_token:S,code:O,method:E}),onSuccess:t=>{t.access_token&&t.user?(a(t.access_token,t.user,R9(N)),c(r(`login.loginSuccess`)),e(u(),{replace:!0})):(console.error(`2FA verify: unexpected response shape`,t),c(r(`login.loginFailed`),`error`))},onError:e=>{c(e.message||r(`login.twoFA.invalidCode`),`error`),k(``)}}),ce=J({mutationFn:e=>Q.getOIDCAuthorizeUrl(e),onSuccess:e=>{if(N)try{sessionStorage.setItem(I9,`1`)}catch(e){console.warn(`setItem auth_remember_me failed, Remember Me will not carry through OIDC redirect`,e)}let n=t.state?.from;n?.pathname&&D1e(`${n.pathname}${n.search??``}`),window.location.href=e.auth_url},onError:e=>{c(e.message||r(`login.oidcLoginFailed`),`error`)}}),le=e=>{if(e.preventDefault(),!d||!p){c(r(`login.enterCredentials`),`error`);return}ie.mutate()},ue=e=>{if(e.preventDefault(),!O.trim()){c(r(`login.twoFA.enterCode`),`error`);return}se.mutate()},de=e=>{if(e.preventDefault(),!_){c(r(`login.enterEmail`),`error`);return}ae.mutate(_)},fe=e=>{D(e),k(``),j(!1),setTimeout(()=>M.current?.focus(),0)};return b===`reset-password`?(0,K.jsx)(`div`,{className:`min-h-screen flex items-center justify-center bg-bambu-dark p-4`,children:(0,K.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,K.jsxs)(`div`,{className:`text-center`,children:[(0,K.jsx)(`div`,{className:`flex items-center justify-center mb-4`,children:(0,K.jsx)(`div`,{className:`w-14 h-14 rounded-full bg-bambu-green/20 flex items-center justify-center`,children:(0,K.jsx)(Bc,{className:`w-7 h-7 text-bambu-green`})})}),(0,K.jsx)(`h2`,{className:`text-2xl font-bold text-white`,children:r(`login.resetPassword.title`)}),(0,K.jsx)(`p`,{className:`mt-2 text-sm text-bambu-gray`,children:r(`login.resetPassword.subtitle`)})]}),(0,K.jsxs)(`form`,{onSubmit:e=>{if(e.preventDefault(),L!==z){c(r(`login.resetPassword.passwordsDoNotMatch`),`error`);return}if(L.length<8){c(r(`login.resetPassword.passwordTooShort`),`error`);return}W.mutate()},className:`space-y-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{htmlFor:`new-password`,className:`block text-sm font-medium text-white mb-2`,children:r(`login.resetPassword.newPassword`)}),(0,K.jsx)(`input`,{id:`new-password`,type:`password`,required:!0,value:L,onChange:e=>R(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:r(`login.resetPassword.newPasswordPlaceholder`),autoFocus:!0,autoComplete:`new-password`,minLength:8})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{htmlFor:`confirm-password`,className:`block text-sm font-medium text-white mb-2`,children:r(`login.resetPassword.confirmPassword`)}),(0,K.jsx)(`input`,{id:`confirm-password`,type:`password`,required:!0,value:z,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:r(`login.resetPassword.confirmPasswordPlaceholder`),autoComplete:`new-password`})]}),(0,K.jsx)(`button`,{type:`submit`,disabled:W.isPending||!L||!z,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:W.isPending?r(`login.resetPassword.saving`):r(`login.resetPassword.submit`)})]}),(0,K.jsx)(`div`,{className:`text-center`,children:(0,K.jsx)(`button`,{type:`button`,onClick:()=>{x(`credentials`),I(``),R(``),B(``)},className:`text-sm text-bambu-gray hover:text-bambu-green transition-colors`,children:r(`login.resetPassword.backToLogin`)})})]})}):b===`2fa`?(0,K.jsx)(`div`,{className:`min-h-screen flex items-center justify-center bg-bambu-dark p-4`,children:(0,K.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,K.jsxs)(`div`,{className:`text-center`,children:[(0,K.jsx)(`div`,{className:`flex items-center justify-center mb-4`,children:(0,K.jsx)(`div`,{className:`w-14 h-14 rounded-full bg-bambu-green/20 flex items-center justify-center`,children:(0,K.jsx)(eu,{className:`w-7 h-7 text-bambu-green`})})}),(0,K.jsx)(`h2`,{className:`text-2xl font-bold text-white`,children:r(`login.twoFA.title`)}),(0,K.jsx)(`p`,{className:`mt-2 text-sm text-bambu-gray`,children:r(`login.twoFA.subtitle`)})]}),w.length>1&&(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[w.includes(`totp`)&&(0,K.jsxs)(`button`,{type:`button`,onClick:()=>fe(`totp`),className:`flex-1 flex flex-col items-center gap-1 py-2 px-3 rounded-lg border text-xs font-medium transition-colors ${E===`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,K.jsx)(su,{className:`w-4 h-4`}),r(`login.twoFA.methodAuthenticator`)]}),w.includes(`email`)&&(0,K.jsxs)(`button`,{type:`button`,onClick:()=>fe(`email`),className:`flex-1 flex flex-col items-center gap-1 py-2 px-3 rounded-lg border text-xs font-medium transition-colors ${E===`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,K.jsx)(el,{className:`w-4 h-4`}),r(`login.twoFA.methodEmail`)]}),w.includes(`backup`)&&(0,K.jsxs)(`button`,{type:`button`,onClick:()=>fe(`backup`),className:`flex-1 flex flex-col items-center gap-1 py-2 px-3 rounded-lg border text-xs font-medium transition-colors ${E===`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,K.jsx)(Bc,{className:`w-4 h-4`}),r(`login.twoFA.methodBackup`)]})]}),(0,K.jsxs)(`form`,{onSubmit:ue,className:`space-y-4`,children:[E===`totp`&&(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:r(`login.twoFA.instructionsTotp`)}),E===`email`&&(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:r(A?`login.twoFA.instructionsEmail`:`login.twoFA.instructionsEmailNotSent`)}),!A&&(0,K.jsx)($,{type:`button`,variant:`secondary`,className:`w-full`,onClick:()=>oe.mutate(),disabled:oe.isPending,children:oe.isPending?r(`login.twoFA.sendingCode`):r(`login.twoFA.sendCodeButton`)}),A&&(0,K.jsx)(`button`,{type:`button`,onClick:()=>{j(!1),oe.mutate()},className:`text-xs text-bambu-gray hover:text-bambu-green transition-colors`,children:r(`login.twoFA.resendCode`)})]}),E===`backup`&&(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:r(`login.twoFA.instructionsBackup`)}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{htmlFor:`twofa-code`,className:`block text-sm font-medium text-white mb-2`,children:r(E===`backup`?`login.twoFA.backupCodeLabel`:`login.twoFA.codeLabel`)}),(0,K.jsx)(`input`,{ref:M,id:`twofa-code`,type:`text`,inputMode:E===`backup`?`text`:`numeric`,autoComplete:`one-time-code`,value:O,onChange:e=>k(e.target.value.trim()),disabled:E===`email`&&!A,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:r(E===`backup`?`login.twoFA.backupCodePlaceholder`:`login.twoFA.codePlaceholder`),maxLength:E===`backup`?8:6,autoFocus:!0})]}),(0,K.jsx)(`button`,{type:`submit`,disabled:se.isPending||!O.trim()||E===`email`&&!A,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:se.isPending?r(`login.twoFA.verifyingButton`):r(`login.twoFA.verifyButton`)})]}),(0,K.jsx)(`div`,{className:`text-center`,children:(0,K.jsx)(`button`,{type:`button`,onClick:()=>{x(`credentials`),C(``),k(``),j(!1)},className:`text-sm text-bambu-gray hover:text-bambu-green transition-colors`,children:r(`login.twoFA.backToLogin`)})})]})}):(0,K.jsxs)(`div`,{className:`min-h-screen flex items-center justify-center bg-bambu-dark p-4`,children:[(0,K.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,K.jsxs)(`div`,{className:`text-center`,children:[(0,K.jsx)(`div`,{className:`flex items-center justify-center mb-6`,children:(0,K.jsx)(`img`,{src:l===`dark`?`/img/bambuddy_logo_dark_transparent.png`:`/img/bambuddy_logo_light.png`,alt:`Bambuddy`,className:`h-16`})}),(0,K.jsx)(`h2`,{className:`text-3xl font-bold text-white`,children:r(`login.title`)}),(0,K.jsx)(`p`,{className:`mt-2 text-sm text-bambu-gray`,children:r(`login.subtitle`)})]}),U&&(0,K.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:r(`login.autologinFailed`)}),!re&&(0,K.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:r(`login.localDisabledNotice`)}),re&&(0,K.jsxs)(`form`,{className:`mt-8 space-y-6`,onSubmit:le,children:[(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{htmlFor:`username`,className:`block text-sm font-medium text-white mb-2`,children:V?.advanced_auth_enabled?r(`login.usernameOrEmail`):r(`login.username`)}),(0,K.jsx)(`input`,{id:`username`,type:`text`,required:!0,value:d,onChange:e=>f(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:V?.advanced_auth_enabled?r(`login.usernameOrEmailPlaceholder`):r(`login.usernamePlaceholder`),autoComplete:`username`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{htmlFor:`password`,className:`block text-sm font-medium text-white mb-2`,children:r(`login.password`)||`Password`}),(0,K.jsx)(`input`,{id:`password`,type:`password`,required:!0,value:p,onChange:e=>m(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:r(`login.passwordPlaceholder`),autoComplete:`current-password`})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`input`,{id:`remember-me`,type:`checkbox`,checked:N,onChange:e=>P(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,K.jsx)(`label`,{htmlFor:`remember-me`,className:`text-sm text-bambu-gray cursor-pointer`,children:r(`login.rememberMe`)})]}),(0,K.jsx)(`div`,{children:(0,K.jsx)(`button`,{type:`submit`,disabled:ie.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:ie.isPending?r(`login.signingIn`):r(`login.signIn`)})}),(0,K.jsx)(`div`,{className:`text-center`,children:(0,K.jsx)(`button`,{type:`button`,onClick:()=>g(!0),className:`text-sm text-bambu-gray hover:text-bambu-green transition-colors`,children:r(`login.forgotPassword`)})})]}),ee&&ee.length>0&&(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(`div`,{className:`absolute inset-0 flex items-center`,children:(0,K.jsx)(`div`,{className:`w-full border-t border-bambu-dark-tertiary`})}),(0,K.jsx)(`div`,{className:`relative flex justify-center text-sm`,children:(0,K.jsx)(`span`,{className:`px-2 bg-bambu-dark-secondary text-bambu-gray`,children:r(`login.twoFA.orContinueWith`)})})]}),(0,K.jsx)(`div`,{className:`space-y-2`,children:ee.map(e=>(0,K.jsx)(k1e,{provider:e,onClick:()=>ce.mutate(e.id),disabled:ce.isPending},e.id))})]})]}),h&&(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:()=>g(!1),children:(0,K.jsxs)(Dd,{className:`w-full max-w-md`,onClick:e=>e.stopPropagation(),children:[(0,K.jsx)(Od,{children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(el,{className:`w-5 h-5 text-bambu-green`}),(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:r(`login.forgotPasswordTitle`)})]}),(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:()=>{g(!1),v(``)},children:(0,K.jsx)(Ju,{className:`w-5 h-5`})})]})}),(0,K.jsx)(kd,{children:V?.advanced_auth_enabled?(0,K.jsxs)(`form`,{onSubmit:de,className:`space-y-4`,children:[(0,K.jsx)(`p`,{className:`text-bambu-gray text-sm`,children:r(`login.forgotPasswordEmailMessage`)}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{htmlFor:`forgot-email`,className:`block text-sm font-medium text-white mb-2`,children:r(`login.emailAddress`)}),(0,K.jsx)(`input`,{id:`forgot-email`,type:`email`,required:!0,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:r(`login.emailPlaceholder`)})]}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)($,{type:`button`,variant:`secondary`,className:`flex-1`,onClick:()=>{g(!1),v(``)},children:r(`login.cancel`)}),(0,K.jsx)($,{type:`submit`,className:`flex-1`,disabled:ae.isPending,children:ae.isPending?r(`login.sending`):r(`login.sendResetEmail`)})]})]}):(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsx)(`p`,{className:`text-bambu-gray`,children:r(`login.forgotPasswordMessage`)}),(0,K.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4 space-y-2`,children:[(0,K.jsx)(`p`,{className:`text-sm text-white font-medium`,children:r(`login.howToReset`)}),(0,K.jsxs)(`ol`,{className:`text-sm text-bambu-gray space-y-1 list-decimal list-inside`,children:[(0,K.jsx)(`li`,{children:r(`login.resetStep1`)}),(0,K.jsx)(`li`,{children:r(`login.resetStep2`)}),(0,K.jsx)(`li`,{children:r(`login.resetStep3`)}),(0,K.jsx)(`li`,{children:r(`login.resetStep4`)})]})]}),(0,K.jsx)($,{variant:`secondary`,className:`w-full`,onClick:()=>g(!1),children:r(`login.gotIt`)})]})})]})})]})}function j1e(){let e=ir(),{t}=$e(),{showToast:n}=Fd(),{mode:r}=wd(),{refreshAuth:i}=xd(),[a,o]=(0,y.useState)(!1),[s,c]=(0,y.useState)(``),[l,u]=(0,y.useState)(``),[d,f]=(0,y.useState)(``),p=J({mutationFn:()=>Q.setupAuth({auth_enabled:a,admin_username:a?s:void 0,admin_password:a?l:void 0}),onSuccess:async r=>{await i(),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,K.jsx)(`div`,{className:`min-h-screen flex items-center justify-center bg-bambu-dark p-4`,children:(0,K.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,K.jsxs)(`div`,{className:`text-center`,children:[(0,K.jsx)(`div`,{className:`flex items-center justify-center mb-6`,children:(0,K.jsx)(`img`,{src:r===`dark`?`/img/bambuddy_logo_dark_transparent.png`:`/img/bambuddy_logo_light.png`,alt:`Bambuddy`,className:`h-16`})}),(0,K.jsx)(`h2`,{className:`text-3xl font-bold text-white`,children:t(`setup.title`)}),(0,K.jsx)(`p`,{className:`mt-2 text-sm text-bambu-gray`,children:t(`setup.subtitle`)})]}),(0,K.jsxs)(`form`,{className:`mt-8 space-y-6`,onSubmit:e=>{if(e.preventDefault(),a&&(s||l)){if(!s||!l){n(t(`setup.toast.enterBothCredentials`),`error`);return}if(l!==d){n(t(`setup.toast.passwordsDoNotMatch`),`error`);return}if(l.length<6){n(t(`setup.toast.passwordTooShort`),`error`);return}}p.mutate()},children:[(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center p-4 bg-bambu-dark-secondary/50 rounded-lg border border-bambu-dark-tertiary`,children:[(0,K.jsx)(`input`,{id:`auth-enabled`,type:`checkbox`,checked:a,onChange:e=>o(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,K.jsx)(`label`,{htmlFor:`auth-enabled`,className:`ml-3 block text-sm font-medium text-white`,children:t(`setup.enableAuth`)})]}),a&&(0,K.jsxs)(`div`,{className:`space-y-4 mt-4`,children:[(0,K.jsx)(`div`,{className:`p-3 bg-bambu-dark-secondary/50 border border-bambu-dark-tertiary rounded-lg`,children:(0,K.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,K.jsx)(Rc,{className:`w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0`}),(0,K.jsxs)(`div`,{className:`text-sm text-bambu-gray`,children:[(0,K.jsx)(`p`,{className:`text-white font-medium mb-1`,children:t(`setup.adminAccount`)}),(0,K.jsx)(`p`,{children:t(`setup.adminAccountDesc`)})]})]})}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{htmlFor:`admin-username`,className:`block text-sm font-medium text-white mb-2`,children:[t(`setup.adminUsername`),` `,(0,K.jsx)(`span`,{className:`text-bambu-gray text-xs`,children:t(`setup.optionalIfAdminExists`)})]}),(0,K.jsx)(`input`,{id:`admin-username`,type:`text`,value:s,onChange:e=>c(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,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{htmlFor:`admin-password`,className:`block text-sm font-medium text-white mb-2`,children:[t(`setup.adminPassword`),` `,(0,K.jsx)(`span`,{className:`text-bambu-gray text-xs`,children:t(`setup.optionalIfAdminExists`)})]}),(0,K.jsx)(`input`,{id:`admin-password`,type:`password`,value:l,onChange:e=>u(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`})]}),l&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{htmlFor:`confirm-password`,className:`block text-sm font-medium text-white mb-2`,children:t(`setup.confirmPassword`)}),(0,K.jsx)(`input`,{id:`confirm-password`,type:`password`,value:d,onChange:e=>f(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,K.jsx)(`div`,{children:(0,K.jsx)(`button`,{type:`submit`,disabled:p.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:p.isPending?t(`setup.settingUp`):t(`setup.completeSetup`)})})]})]})})}function M1e(){let{t:e}=$e(),{user:t}=xd(),{showToast:n}=Fd(),r=ao(),i=ir(),[a,o]=(0,y.useState)(!0),[s,c]=(0,y.useState)(!0),[l,u]=(0,y.useState)(!0),[d,f]=(0,y.useState)(!0),[p,m]=(0,y.useState)(!1),{data:h,isLoading:g}=q({queryKey:[`advancedAuthStatus`],queryFn:Q.getAdvancedAuthStatus,staleTime:300*1e3}),{data:_,isLoading:v}=q({queryKey:[`settings`],queryFn:Q.getSettings,staleTime:300*1e3}),{data:b,isLoading:x}=q({queryKey:[`user-email-preferences`],queryFn:()=>Q.getUserEmailPreferences()});(0,y.useEffect)(()=>{(h&&!h.advanced_auth_enabled||_&&!_.user_notifications_enabled)&&i(`/settings`,{replace:!0})},[h,_,i]),(0,y.useEffect)(()=>{b&&(o(b.notify_print_start),c(b.notify_print_complete),u(b.notify_print_failed),f(b.notify_print_stopped),m(!1))},[b]);let S=J({mutationFn:()=>Q.updateUserEmailPreferences({notify_print_start:a,notify_print_complete:s,notify_print_failed:l,notify_print_stopped:d}),onSuccess:()=>{r.invalidateQueries({queryKey:[`user-email-preferences`]}),m(!1),n(e(`notifications.userEmail.saveSuccess`),`success`)},onError:t=>{n(t.message||e(`notifications.userEmail.saveError`),`error`)}}),C=(e,t)=>{e(!t),m(!0)};return x||g||v?(0,K.jsx)(`div`,{className:`flex items-center justify-center h-64`,children:(0,K.jsx)(X,{className:`w-8 h-8 animate-spin text-bambu-green`})}):(0,K.jsxs)(`div`,{className:`p-4 md:p-6 max-w-2xl mx-auto`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3 mb-6`,children:[(0,K.jsx)(Uo,{className:`w-7 h-7 text-bambu-green`}),(0,K.jsx)(`h1`,{className:`text-2xl font-bold text-white`,children:e(`notifications.userEmail.title`)})]}),(0,K.jsx)(Dd,{className:`mb-6 border-blue-300 bg-blue-50 dark:border-blue-500/30 dark:bg-blue-500/5`,children:(0,K.jsx)(kd,{className:`py-4`,children:(0,K.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,K.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,K.jsx)(el,{className:`w-5 h-5 text-blue-600 dark:text-blue-400`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h3`,{className:`text-white font-medium`,children:e(`notifications.userEmail.emailNotifications`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:e(`notifications.userEmail.emailNotificationsDesc`)}),t?.email?(0,K.jsxs)(`p`,{className:`text-sm text-blue-700 dark:text-blue-400 mt-2`,children:[e(`notifications.userEmail.sendingTo`),`: `,(0,K.jsx)(`strong`,{children:t.email})]}):(0,K.jsx)(`p`,{className:`text-sm text-yellow-700 dark:text-yellow-400 mt-2`,children:e(`notifications.userEmail.noEmailWarning`)})]})]})})}),(0,K.jsxs)(Dd,{className:`mb-6`,children:[(0,K.jsxs)(Od,{children:[(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`notifications.userEmail.printJobNotifications`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:e(`notifications.userEmail.printJobNotificationsDesc`)})]}),(0,K.jsxs)(kd,{className:`space-y-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-4 bg-bambu-dark rounded-lg`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.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,K.jsx)(_s,{className:`w-5 h-5 ${a?`text-bambu-green`:`text-bambu-gray`}`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white font-medium`,children:e(`notifications.userEmail.printJobStarts`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`notifications.userEmail.printJobStartsDesc`)})]})]}),(0,K.jsx)(`button`,{onClick:()=>C(o,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,K.jsx)(`span`,{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${a?`translate-x-6`:`translate-x-1`}`})})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-4 bg-bambu-dark rounded-lg`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center ${s?`bg-bambu-green/20`:`bg-bambu-dark-tertiary`}`,children:(0,K.jsx)(_s,{className:`w-5 h-5 ${s?`text-bambu-green`:`text-bambu-gray`}`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white font-medium`,children:e(`notifications.userEmail.printJobFinishes`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`notifications.userEmail.printJobFinishesDesc`)})]})]}),(0,K.jsx)(`button`,{onClick:()=>C(c,s),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 ${s?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,role:`switch`,"aria-checked":s,children:(0,K.jsx)(`span`,{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${s?`translate-x-6`:`translate-x-1`}`})})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-4 bg-bambu-dark rounded-lg`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center ${l?`bg-bambu-green/20`:`bg-bambu-dark-tertiary`}`,children:(0,K.jsx)(_s,{className:`w-5 h-5 ${l?`text-bambu-green`:`text-bambu-gray`}`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white font-medium`,children:e(`notifications.userEmail.printErrors`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`notifications.userEmail.printErrorsDesc`)})]})]}),(0,K.jsx)(`button`,{onClick:()=>C(u,l),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 ${l?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,role:`switch`,"aria-checked":l,children:(0,K.jsx)(`span`,{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${l?`translate-x-6`:`translate-x-1`}`})})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-4 bg-bambu-dark rounded-lg`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center ${d?`bg-bambu-green/20`:`bg-bambu-dark-tertiary`}`,children:(0,K.jsx)(_s,{className:`w-5 h-5 ${d?`text-bambu-green`:`text-bambu-gray`}`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white font-medium`,children:e(`notifications.userEmail.printJobStops`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`notifications.userEmail.printJobStopsDesc`)})]})]}),(0,K.jsx)(`button`,{onClick:()=>C(f,d),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 ${d?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,role:`switch`,"aria-checked":d,children:(0,K.jsx)(`span`,{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${d?`translate-x-6`:`translate-x-1`}`})})]})]})]}),(0,K.jsx)(`div`,{className:`flex justify-end`,children:(0,K.jsx)($,{onClick:()=>S.mutate(),disabled:!p||S.isPending||!t?.email,children:S.isPending?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),e(`common.saving`)]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Bl,{className:`w-4 h-4`}),e(`common.save`)]})})})]})}function N1e(){let e=ir(),[t]=Fi(),{t:n}=$e();if(window!==window.top)return(0,K.jsxs)(`div`,{style:{padding:32,color:`#f88`},children:[`GCode viewer static files not found. Check that the`,` `,(0,K.jsx)(`code`,{children:`gcode_viewer/`}),` directory exists and restart uvicorn.`]});let r=t.has(`archive`),i=t.has(`library_file`),a=r?`/archives`:i?`/files`:`/`,o=n(r?`gcodeViewer.backToArchives`:i?`gcodeViewer.backToFiles`:`gcodeViewer.back`),s=()=>{window.history.length>1?e(-1):e(a)},c=`/gcode-viewer/${window.location.search}`;return(0,K.jsxs)(`div`,{style:{height:`calc(100vh - 3.5rem)`,display:`flex`,flexDirection:`column`},children:[(0,K.jsx)(`div`,{className:`flex items-center gap-2 px-4 py-2 border-b border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-900`,children:(0,K.jsxs)(`button`,{type:`button`,onClick:s,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,K.jsx)(Po,{className:`w-4 h-4`}),o]})}),(0,K.jsx)(`iframe`,{src:c,title:`GCode Viewer`,style:{display:`block`,width:`100%`,flex:1,border:`none`}})]})}var P1e=4401;function F1e(){let e=(0,y.useRef)(null),t=(0,y.useRef)(null),n=(0,y.useRef)(!1),r=ao(),[i,a]=(0,y.useState)(!1),o=(0,y.useRef)(new Map),{showToast:s}=Fd(),{t:c}=$e(),l=(0,y.useRef)(new Set),u=(0,y.useRef)(null),d=(0,y.useRef)(new Map),f=(0,y.useRef)(null),p=(0,y.useRef)([]),m=(0,y.useRef)(!1),h=(0,y.useRef)(()=>{}),g=(0,y.useCallback)(()=>{if(m.current||p.current.length===0)return;m.current=!0;let e=()=>{let t=p.current.shift();t?(h.current(t),p.current.length>0?setTimeout(e,16):m.current=!1):m.current=!1};e()},[]),_=(0,y.useCallback)(async()=>{if(n.current||e.current?.readyState===WebSocket.OPEN)return;let r;try{r=(await Q.getWebSocketToken()).token}catch(e){let t=e instanceof $u?e.status:0;if(t===401||t===403)return}if(n.current)return;let i=window.location.protocol===`https:`?`wss:`:`ws:`,o=r?`?token=${encodeURIComponent(r)}`:``,s=`${i}//${window.location.host}/api/v1/ws${o}`,c=new WebSocket(s),l=null;c.onopen=()=>{console.log(`[WebSocket] Connected`),a(!0),l=window.setInterval(()=>{c.readyState===WebSocket.OPEN&&c.send(JSON.stringify({type:`ping`}))},3e4)},c.onmessage=e=>{try{let t=JSON.parse(e.data);t.type===`printer_status`&&t.printer_id!==void 0&&t.data?h.current(t):(p.current.push(t),g())}catch{}},c.onclose=r=>{console.log(`[WebSocket] Closed`,r.code,r.reason),l&&=(clearInterval(l),null),a(!1),e.current=null,!(n.current||r.code===P1e)&&(t.current=window.setTimeout(()=>{_()},3e3))},c.onerror=e=>{console.error(`[WebSocket] Error`,e),c.close()},e.current=c},[g]),v=(0,y.useCallback)((e,t)=>{let n=d.current.get(e)||{};d.current.set(e,{...n,...t}),f.current||=window.setTimeout(()=>{let e=new Map(d.current);d.current.clear(),f.current=null,e.forEach((e,t)=>{r.setQueryData([`printerStatus`,t],t=>{let n={...t,...e};return n.wifi_signal==null&&t?.wifi_signal!=null&&(n.wifi_signal=t.wifi_signal),n})})},100)},[r]),b=(0,y.useCallback)(e=>{l.current.add(e),u.current&&clearTimeout(u.current),u.current=window.setTimeout(()=>{let e=Array.from(l.current);l.current.clear(),u.current=null;let t=0;e.forEach(e=>{setTimeout(()=>{r.invalidateQueries({queryKey:[e]})},t),t+=500})},3e3)},[r]),x=(0,y.useCallback)(e=>{switch(e.type){case`printer_status`:e.printer_id!==void 0&&e.data&&v(e.printer_id,e.data);break;case`print_start`:e.printer_id!==void 0&&r.invalidateQueries({queryKey:[`printerStatus`,e.printer_id]});break;case`missing_spool_assignment`:{if(e.printer_id===void 0||!Array.isArray(e.missing_slots))break;let t=e.missing_slots.map(e=>e&&typeof e.slot==`string`?e.slot:`Unknown`).filter(e=>e.length>0);if(t.length===0){o.current.delete(e.printer_id);break}let n=t.join(`|`);if(o.current.get(e.printer_id)===n)break;o.current.set(e.printer_id,n),s(c(`printers.toast.missingSpoolAssignment`,{printer:e.printer_name||`Printer ${e.printer_id}`,slots:t.join(`, `)}),`warning`);break}case`print_complete`:b(`archives`),b(`archiveStats`);break;case`archive_created`:b(`archives`),b(`archiveStats`);break;case`archive_updated`:b(`archives`);break;case`pong`:break;case`plate_not_empty`:window.dispatchEvent(new CustomEvent(`plate-not-empty`,{detail:{printer_id:e.printer_id,printer_name:e.printer_name,message:e.message}}));break;case`inventory_changed`:b(`inventory-spools`),b(`spoolman-inventory-spools`),b(y9[0]);break;case`spool_assignment_changed`:b(`spool-assignments`),b(`slotPresets`);break;case`spool_assignment_verified`:{let t=e.printer_name||`Printer`,n=e.slot||`?`;e.verified?e.kprofile_applied===!1?s(c(`printers.toast.assignmentVerifiedNoKprofile`,{slot:n,printer:t}),`warning`):s(c(`printers.toast.assignmentVerified`,{slot:n,printer:t}),`success`):s(c(`printers.toast.assignmentNotConfirmed`,{slot:n,printer:t}),`warning`);break}case`spool_auto_assigned`:b(`inventory-spools`),b(`spool-assignments`);break;case`spool_usage_logged`:b(`inventory-spools`);break;case`unknown_tag`:{let t=e;window.dispatchEvent(new CustomEvent(`unknown-tag`,{detail:{printer_id:t.printer_id,ams_id:t.ams_id,tray_id:t.tray_id,tag_uid:t.tag_uid,tray_uuid:t.tray_uuid,tray_type:t.tray_type,tray_color:t.tray_color,tray_sub_brands:t.tray_sub_brands,tray_count:t.tray_count}}));break}case`spoolbuddy_weight`:window.dispatchEvent(new CustomEvent(`spoolbuddy-weight`,{detail:e}));break;case`spoolbuddy_tag_matched`:window.dispatchEvent(new CustomEvent(`spoolbuddy-tag-matched`,{detail:e})),b(`inventory-spools`);break;case`spoolbuddy_unknown_tag`:window.dispatchEvent(new CustomEvent(`spoolbuddy-unknown-tag`,{detail:e}));break;case`spoolbuddy_tag_removed`:window.dispatchEvent(new CustomEvent(`spoolbuddy-tag-removed`,{detail:e}));break;case`spoolbuddy_tag_written`:window.dispatchEvent(new CustomEvent(`spoolbuddy-tag-written`,{detail:e})),b(`inventory-spools`);break;case`spoolbuddy_tag_write_failed`:window.dispatchEvent(new CustomEvent(`spoolbuddy-tag-write-failed`,{detail:e}));break;case`spoolbuddy_online`:window.dispatchEvent(new CustomEvent(`spoolbuddy-online`,{detail:e})),b(`spoolbuddy-devices`),b(`spoolbuddy-update-check`);break;case`spoolbuddy_offline`:window.dispatchEvent(new CustomEvent(`spoolbuddy-offline`,{detail:e})),b(`spoolbuddy-devices`);break;case`spoolbuddy_update`:b(`spoolbuddy-devices`),b(`spoolbuddy-update-check`);break;case`queue_item_uploading`:case`queue_item_upload_progress`:case`queue_item_acked`:case`queue_item_failed`:window.dispatchEvent(new CustomEvent(`bambuddy:dispatch-toast`,{detail:e}));break;case`pipeline_run_updated`:r.invalidateQueries({queryKey:[`pipeline-runs-all`]}),e.run?.pipeline_id&&r.invalidateQueries({queryKey:[`pipeline-runs`,e.run.pipeline_id]});break}},[r,b,v,s,c]);return(0,y.useEffect)(()=>{h.current=x},[x]),(0,y.useEffect)(()=>(n.current=!1,_(),()=>{n.current=!0,t.current&&clearTimeout(t.current),u.current&&clearTimeout(u.current),f.current&&clearTimeout(f.current),e.current&&e.current.close()}),[_]),{isConnected:i,sendMessage:(0,y.useCallback)(t=>{e.current?.readyState===WebSocket.OPEN&&e.current.send(JSON.stringify(t))},[])}}var I1e=`#00ae42`,B9=e=>e!=null&&e>0?e:1/0;function L1e(e){let t=null;for(let n of e){if(!n||n.state!==`RUNNING`||n.progress==null)continue;if(t===null){t=n;continue}let e=B9(n.remaining_time),r=B9(t.remaining_time);(e(t.progress??0))&&(t=n)}return t}function R1e(e){let t=document.createElement(`canvas`);t.width=32,t.height=32;let n=t.getContext(`2d`);if(!n)return null;let r=getComputedStyle(document.documentElement).getPropertyValue(`--accent`).trim()||I1e,i=Math.max(0,Math.min(100,e))/100,a=-Math.PI/2;return n.lineWidth=4,n.beginPath(),n.arc(16,16,13,0,Math.PI*2),n.strokeStyle=`rgba(128,128,128,0.3)`,n.stroke(),n.beginPath(),n.arc(16,16,13,a,a+i*Math.PI*2),n.strokeStyle=r,n.lineCap=`round`,n.stroke(),t.toDataURL(`image/png`)}function V9(e,t){document.querySelectorAll(`link[rel~="icon"]`).forEach(n=>{if(e)t.has(n)||t.set(n,n.href),n.href=e;else{let e=t.get(n);e!==void 0&&(n.href=e)}}),e||t.clear()}function z1e(){let{progressInTitle:e,resolvedMode:t,darkAccent:n,lightAccent:r}=wd(),i=t===`dark`?n:r,{data:a}=q({queryKey:[`printers`],queryFn:Q.getPrinters,enabled:e}),o=bo({queries:(e?a??[]:[]).map(e=>({queryKey:[`printerStatus`,e.id],queryFn:()=>Q.getPrinterStatus(e.id)}))}),s=(0,y.useRef)(new Map),c=(0,y.useRef)(document.title),l=(0,y.useRef)(!1),u=e?L1e(o.map(e=>e.data)):null,d=u&&u.progress!=null?Math.round(u.progress):null;(0,y.useEffect)(()=>{e&&d!=null?(document.title=`${d}% · ${c.current}`,V9(R1e(d),s.current),l.current=!0):l.current&&=(document.title=c.current,V9(null,s.current),!1)},[e,d,i]),(0,y.useEffect)(()=>{let e=s.current,t=l,n=c.current;return()=>{t.current&&(document.title=n,V9(null,e))}},[])}function B1e({children:e}){let{authEnabled:t,user:n,loading:r}=xd(),{data:i}=q({queryKey:[`color-catalog-map`],queryFn:async()=>(await Q.getColorNameMap()).colors,staleTime:1/0,gcTime:1/0,retry:2,enabled:!r&&(!t||n!==null)});return(0,y.useEffect)(()=>{i&&af(i)},[i]),(0,K.jsx)(K.Fragment,{children:e})}function V1e({selectedPrinterId:e,onPrinterChange:t,deviceOnline:n}){let{t:r}=$e(),[i,a]=(0,y.useState)(new Date),{data:o=[]}=q({queryKey:[`printers`],queryFn:()=>Q.getPrinters()}),s=bo({queries:o.map(e=>({queryKey:[`printerStatus`,e.id],queryFn:()=>Q.getPrinterStatus(e.id),refetchInterval:1e4}))}),c=(0,y.useMemo)(()=>o.filter((e,t)=>s[t]?.data?.connected),[o,s]);(0,y.useEffect)(()=>{let n=c.some(t=>t.id===e);(!e||!n)&&c.length>0&&t(c[0].id)},[c,e,t]);let{data:l}=q({queryKey:[`settings`],queryFn:Q.getSettings});return(0,y.useEffect)(()=>{let e=setInterval(()=>a(new Date),1e3);return()=>clearInterval(e)},[]),(0,K.jsxs)(`div`,{className:`h-12 bg-bambu-dark-secondary border-b border-bambu-dark-tertiary flex items-center px-3 gap-4 shrink-0`,children:[(0,K.jsx)(`div`,{className:`flex items-center shrink-0`,children:(0,K.jsx)(`img`,{src:`/img/spoolbuddy_logo_dark_small.png`,alt:`SpoolBuddy`,width:113,height:28,className:`h-7 w-auto`})}),(0,K.jsx)(`div`,{className:`flex-1 flex justify-center`,children:(0,K.jsx)(`select`,{value:e??``,onChange:e=>t(Number(e.target.value)),className:`bg-bambu-dark text-white text-base px-4 py-2 rounded border border-bambu-dark-tertiary focus:outline-none focus:border-bambu-green min-w-[180px]`,children:c.length===0?(0,K.jsx)(`option`,{value:``,children:r(`spoolbuddy.status.noPrinters`,`No printers online`)}):c.map(e=>(0,K.jsx)(`option`,{value:e.id,children:e.name},e.id))})}),(0,K.jsxs)(`div`,{className:`flex items-center gap-3 shrink-0`,children:[(0,K.jsx)(`div`,{className:`flex items-center`,title:n?r(`spoolbuddy.status.backend`,`Backend`):r(`spoolbuddy.status.offline`,`Offline`),children:n?(0,K.jsx)(`div`,{className:`flex items-end gap-0.5 h-4`,children:[1,2,3,4].map(e=>(0,K.jsx)(`div`,{className:`w-1 rounded-sm ${e<=4?`bg-white`:`bg-bambu-dark-tertiary`}`,style:{height:`${e*4}px`}},e))}):(0,K.jsx)(Uu,{className:`w-5 h-5 text-red-400`})}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,K.jsx)(`div`,{className:`w-3 h-3 rounded-full ${n?`bg-bambu-green shadow-[0_0_6px_rgba(34,197,94,0.5)]`:`bg-bambu-gray`}`}),(0,K.jsx)(`span`,{className:`text-sm text-white/50`,children:n?r(`spoolbuddy.status.backend`,`Backend`):r(`spoolbuddy.status.offline`,`Offline`)})]}),(0,K.jsx)(`span`,{className:`text-white/50 text-base font-mono min-w-[50px] text-right`,children:Kf(i,l?.time_format||`system`)})]})]})}var H1e=[{to:`/spoolbuddy`,labelKey:`spoolbuddy.nav.dashboard`,fallback:`Dashboard`,icon:(0,K.jsx)(`svg`,{className:`w-6 h-6`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,K.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M3 12l2-2m0 0l7-7 7 7M5 10v10a1 1 0 001 1h3m10-11l2 2m-2-2v10a1 1 0 01-1 1h-3m-6 0a1 1 0 001-1v-4a1 1 0 011-1h2a1 1 0 011 1v4a1 1 0 001 1m-6 0h6`})})},{to:`/spoolbuddy/ams`,labelKey:`spoolbuddy.nav.ams`,fallback:`AMS`,icon:(0,K.jsx)(`svg`,{className:`w-6 h-6`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,K.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10`})})},{to:`/spoolbuddy/write-tag`,labelKey:`spoolbuddy.nav.writeTag`,fallback:`Write`,icon:(0,K.jsxs)(`svg`,{className:`w-6 h-6`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:2,children:[(0,K.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,K.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M12.53 18.22l-.53.53-.53-.53a.75.75 0 011.06 0z`})]})},{to:`/spoolbuddy/inventory`,labelKey:`spoolbuddy.nav.inventory`,fallback:`Inventory`,icon:(0,K.jsx)(`svg`,{className:`w-6 h-6`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,K.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M20 7l-8-4-8 4m16 0l-8 4m8-4v10l-8 4m0-10L4 7m8 4v10M4 7v10l8 4`})})},{to:`/spoolbuddy/settings`,labelKey:`spoolbuddy.nav.settings`,fallback:`Settings`,icon:(0,K.jsxs)(`svg`,{className:`w-6 h-6`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:[(0,K.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.066 2.573c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.573 1.066c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.066-2.573c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z`}),(0,K.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M15 12a3 3 0 11-6 0 3 3 0 016 0z`})]})}];function U1e(){let{t:e}=$e();return(0,K.jsx)(`nav`,{className:`h-14 bg-bambu-dark-secondary border-t border-bambu-dark-tertiary flex items-stretch shrink-0`,children:H1e.map(t=>(0,K.jsxs)(Oi,{to:t.to,end:t.to===`/spoolbuddy`,className:({isActive:e})=>`flex-1 flex flex-col items-center justify-center gap-1 transition-colors ${e?`text-bambu-green bg-bambu-dark`:`text-white/50 hover:text-white/70 hover:bg-bambu-dark-tertiary`}`,children:[t.icon,(0,K.jsx)(`span`,{className:`text-xs font-medium`,children:e(t.labelKey,t.fallback)})]},t.to))})}function W1e({alert:e}){let{t}=$e(),n=e?e.type===`error`?`bg-red-500`:e.type===`warning`?`bg-amber-500`:`bg-bambu-green`:`bg-bambu-green`;return(0,K.jsxs)(`div`,{className:`h-9 bg-bambu-dark-secondary border-t-2 ${e?e.type===`error`?`border-red-500`:e.type===`warning`?`border-amber-500`:`border-bambu-dark-tertiary`:`border-bambu-dark-tertiary`} flex items-center px-3 gap-3 shrink-0`,children:[(0,K.jsx)(`div`,{className:`w-3.5 h-3.5 rounded-full ${n}`}),(0,K.jsx)(`div`,{className:`flex-1 text-sm text-white/50 truncate`,children:e?(0,K.jsx)(`span`,{children:e.message}):(0,K.jsx)(`span`,{className:`text-bambu-green`,children:t(`spoolbuddy.status.systemReady`,`System Ready`)})})]})}function G1e({isOpen:e,onClose:t,deviceId:n,deviceOnline:r}){let{t:i}=$e(),[a,o]=(0,y.useState)(null),[s,c]=(0,y.useState)(!1),[l,u]=(0,y.useState)(new Map),{data:d=[]}=q({queryKey:[`printers`],queryFn:()=>Q.getPrinters(),enabled:e}),{data:f=[]}=q({queryKey:[`smart-plugs`],queryFn:()=>Q.getSmartPlugs(),enabled:e}),p=d.map(e=>{let t=f.find(t=>t.printer_id===e.id&&t.plug_type!==`mqtt`&&t.enabled);if(!t)return null;let n=l.get(t.id);return{plug:t,printer:e,status:n?{state:n.state,reachable:!0,device_name:null,energy:null}:null,loading:n?.loading??!1}}).filter(Boolean);(0,y.useEffect)(()=>{!e||f.length===0||f.filter(e=>e.printer_id!==null&&e.plug_type!==`mqtt`&&e.enabled).forEach(async e=>{try{let t=await Q.getSmartPlugStatus(e.id);u(n=>{let r=new Map(n);return r.set(e.id,{loading:!1,state:t.state}),r})}catch{u(t=>{let n=new Map(t);return n.set(e.id,{loading:!1,state:null}),n})}})},[e,f]),(0,y.useEffect)(()=>{e||(o(null),c(!1))},[e]);let m=(0,y.useCallback)(async e=>{u(t=>{let n=new Map(t),r=n.get(e.id);return n.set(e.id,{loading:!0,state:r?.state??null}),n});try{await Q.controlSmartPlug(e.id,`toggle`);let t=await Q.getSmartPlugStatus(e.id);u(n=>{let r=new Map(n);return r.set(e.id,{loading:!1,state:t.state}),r})}catch{u(t=>{let n=new Map(t),r=n.get(e.id);return n.set(e.id,{loading:!1,state:r?.state??null}),n})}},[]),h=(0,y.useCallback)(async e=>{if(n){c(!0);try{await gd.systemCommand(n,e),setTimeout(()=>t(),500)}catch{c(!1)}}},[n,t]),g=(0,y.useCallback)(()=>{a&&(a.type===`system`?h(a.command):m(a.plug),o(null))},[a,h,m]);if(!e)return null;let _=e=>e===`ON`||e===`on`;return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`fixed inset-0 z-40 bg-black/50`,onPointerDown:t}),(0,K.jsxs)(`div`,{className:`fixed top-0 left-0 right-0 z-50 bg-bambu-dark-secondary border-b border-bambu-dark-tertiary rounded-b-2xl shadow-2xl animate-slide-down`,children:[(0,K.jsx)(`div`,{className:`flex justify-center pt-2 pb-1`,children:(0,K.jsx)(`div`,{className:`w-10 h-1 rounded-full bg-zinc-600`})}),(0,K.jsxs)(`div`,{className:`px-4 pb-4 max-h-[80vh] overflow-y-auto`,children:[p.length>0&&(0,K.jsxs)(`div`,{className:`mb-4`,children:[(0,K.jsx)(`h3`,{className:`text-xs font-semibold text-zinc-500 uppercase tracking-wide mb-2`,children:i(`spoolbuddy.quickMenu.printerPower`,`Printer Power`)}),(0,K.jsx)(`div`,{className:`space-y-1`,children:p.map(({plug:e,printer:t,loading:n})=>{let r=l.get(e.id),i=_(r?.state??null);return(0,K.jsxs)(`button`,{onClick:()=>o({type:`plug`,plug:e,printer:t,currentState:r?.state??null}),disabled:n,className:`w-full flex items-center gap-2 px-3 py-1.5 rounded-lg bg-zinc-800/60 hover:bg-zinc-700/60 transition-colors min-h-[36px]`,children:[(0,K.jsx)(`div`,{className:`w-2 h-2 rounded-full shrink-0 ${i?`bg-green-500`:`bg-zinc-600`}`}),n&&(0,K.jsx)(X,{className:`w-3 h-3 animate-spin text-zinc-400 shrink-0`}),(0,K.jsx)(`span`,{className:`flex-1 text-sm text-zinc-200 text-left truncate`,children:t.name}),(0,K.jsx)(`span`,{className:`text-xs font-medium ${i?`text-green-400`:`text-zinc-500`}`,children:r?.state??`—`})]},e.id)})})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h3`,{className:`text-xs font-semibold text-zinc-500 uppercase tracking-wide mb-2`,children:i(`spoolbuddy.quickMenu.systemControls`,`System`)}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,K.jsx)(H9,{icon:(0,K.jsx)(Rl,{className:`w-4 h-4`}),label:i(`spoolbuddy.quickMenu.restartDaemon`,`Restart Daemon`),onClick:()=>o({type:`system`,command:`restart_daemon`}),disabled:!n||!r||s}),(0,K.jsx)(H9,{icon:(0,K.jsx)(dl,{className:`w-4 h-4`}),label:i(`spoolbuddy.quickMenu.restartBrowser`,`Restart Browser`),onClick:()=>o({type:`system`,command:`restart_browser`}),disabled:!n||!r||s}),(0,K.jsx)(H9,{icon:(0,K.jsx)(Rl,{className:`w-4 h-4`}),label:i(`spoolbuddy.quickMenu.reboot`,`Reboot`),onClick:()=>o({type:`system`,command:`reboot`}),disabled:!n||!r||s,variant:`warning`}),(0,K.jsx)(H9,{icon:(0,K.jsx)(Al,{className:`w-4 h-4`}),label:i(`spoolbuddy.quickMenu.shutdown`,`Shutdown`),onClick:()=>o({type:`system`,command:`shutdown`}),disabled:!n||!r||s,variant:`danger`})]})]}),(0,K.jsx)(`div`,{className:`flex justify-center mt-3`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-1 text-xs text-zinc-600`,children:[(0,K.jsx)(cs,{className:`w-3 h-3`}),(0,K.jsx)(`span`,{children:i(`spoolbuddy.quickMenu.swipeToClose`,`Swipe down to close`)})]})})]})]}),a&&(0,K.jsx)(`div`,{className:`fixed inset-0 z-[60] flex items-center justify-center bg-black/60`,children:(0,K.jsxs)(`div`,{className:`bg-zinc-800 rounded-2xl p-5 mx-4 max-w-sm w-full border border-zinc-700`,children:[(0,K.jsx)(`h3`,{className:`text-lg font-semibold text-zinc-100 mb-2`,children:i(`spoolbuddy.quickMenu.confirmTitle`,`Confirm`)}),(0,K.jsx)(`p`,{className:`text-sm text-zinc-400 mb-5`,children:a.type===`plug`?_(a.currentState)?i(`spoolbuddy.quickMenu.confirmPlugOff`,`Turn off {{name}}?`,{name:a.printer.name}):i(`spoolbuddy.quickMenu.confirmPlugOn`,`Turn on {{name}}?`,{name:a.printer.name}):a.command===`shutdown`?i(`spoolbuddy.quickMenu.confirmShutdown`,`Are you sure you want to shut down the SpoolBuddy? You will need physical access to turn it back on.`):a.command===`reboot`?i(`spoolbuddy.quickMenu.confirmReboot`,`Are you sure you want to reboot the SpoolBuddy?`):a.command===`restart_daemon`?i(`spoolbuddy.quickMenu.confirmRestartDaemon`,`Restart the SpoolBuddy daemon? NFC and scale will be temporarily unavailable.`):i(`spoolbuddy.quickMenu.confirmRestartBrowser`,`Restart the kiosk browser? The display will briefly go blank.`)}),(0,K.jsxs)(`div`,{className:`flex gap-3`,children:[(0,K.jsx)(`button`,{onClick:()=>o(null),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:i(`common.cancel`,`Cancel`)}),(0,K.jsx)(`button`,{onClick:g,disabled:s,className:`flex-1 px-4 py-2.5 rounded-lg text-sm font-medium text-white transition-colors min-h-[44px] ${a.type===`plug`?_(a.currentState)?`bg-red-600 hover:bg-red-700`:`bg-green-600 hover:bg-green-700`:a.command===`shutdown`?`bg-red-600 hover:bg-red-700`:a.command===`reboot`?`bg-amber-600 hover:bg-amber-700`:`bg-blue-600 hover:bg-blue-700`} disabled:opacity-50`,children:s?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin mx-auto`}):a.type===`plug`?_(a.currentState)?i(`spoolbuddy.quickMenu.turnOff`,`Turn Off`):i(`spoolbuddy.quickMenu.turnOn`,`Turn On`):i(`spoolbuddy.quickMenu.confirm`,`Confirm`)})]})]})})]})}function H9({icon:e,label:t,onClick:n,disabled:r,variant:i=`default`}){return(0,K.jsxs)(`button`,{onClick:n,disabled:r,className:`flex items-center gap-2.5 p-3 rounded-xl transition-colors min-h-[48px] disabled:opacity-40 ${{default:`bg-zinc-800/60 hover:bg-zinc-700/60 text-zinc-300`,warning:`bg-amber-900/30 hover:bg-amber-900/50 text-amber-400`,danger:`bg-red-900/30 hover:bg-red-900/50 text-red-400`}[i]}`,children:[e,(0,K.jsx)(`span`,{className:`text-sm font-medium`,children:t})]})}var K1e={weight:null,weightStable:!1,rawAdc:null,matchedSpool:null,unknownTagUid:null,unknownTrayUuid:null,deviceOnline:!1,deviceId:null};function q1e(e,t){switch(t.type){case`WEIGHT_UPDATE`:return{...e,weight:t.weight,weightStable:t.stable,rawAdc:t.rawAdc,deviceId:t.deviceId,deviceOnline:!0};case`TAG_MATCHED`:return{...e,matchedSpool:t.spool,unknownTagUid:null,unknownTrayUuid:null,deviceId:t.deviceId};case`UNKNOWN_TAG`:return{...e,matchedSpool:null,unknownTagUid:t.tagUid,unknownTrayUuid:t.trayUuid??null,deviceId:t.deviceId};case`TAG_REMOVED`:return{...e,matchedSpool:null,unknownTagUid:null,unknownTrayUuid:null};case`DEVICE_ONLINE`:return{...e,deviceOnline:!0,deviceId:t.deviceId};case`DEVICE_OFFLINE`:return{...e,deviceOnline:!1,weight:null,weightStable:!1,rawAdc:null};default:return e}}function J1e(){let[e,t]=(0,y.useReducer)(q1e,K1e),n=(0,y.useCallback)(e=>{let n=e.detail;t({type:`WEIGHT_UPDATE`,weight:n.weight_grams??n.data?.weight_grams,stable:n.stable??n.data?.stable??!1,rawAdc:n.raw_adc??n.data?.raw_adc??null,deviceId:n.device_id??n.data?.device_id??``})},[]),r=(0,y.useCallback)(e=>{let n=e.detail,r=n.spool??n.data?.spool;r&&t({type:`TAG_MATCHED`,spool:{id:r.id,tag_uid:n.tag_uid??n.data?.tag_uid??``,material:r.material??``,subtype:r.subtype??null,color_name:r.color_name??null,rgba:r.rgba??null,brand:r.brand??null,label_weight:r.label_weight??0,core_weight:r.core_weight??0,weight_used:r.weight_used??0},deviceId:n.device_id??n.data?.device_id??``})},[]),i=(0,y.useCallback)(e=>{let n=e.detail;t({type:`UNKNOWN_TAG`,tagUid:n.tag_uid??n.data?.tag_uid??``,trayUuid:n.tray_uuid??n.data?.tray_uuid??null,deviceId:n.device_id??n.data?.device_id??``})},[]),a=(0,y.useCallback)(e=>{let n=e.detail;t({type:`TAG_REMOVED`,deviceId:n.device_id??n.data?.device_id??``})},[]),o=(0,y.useCallback)(e=>{let n=e.detail;t({type:`DEVICE_ONLINE`,deviceId:n.device_id??n.data?.device_id??``})},[]),s=(0,y.useCallback)(e=>{let n=e.detail;t({type:`DEVICE_OFFLINE`,deviceId:n.device_id??n.data?.device_id??``})},[]);(0,y.useEffect)(()=>(window.addEventListener(`spoolbuddy-weight`,n),window.addEventListener(`spoolbuddy-tag-matched`,r),window.addEventListener(`spoolbuddy-unknown-tag`,i),window.addEventListener(`spoolbuddy-tag-removed`,a),window.addEventListener(`spoolbuddy-online`,o),window.addEventListener(`spoolbuddy-offline`,s),()=>{window.removeEventListener(`spoolbuddy-weight`,n),window.removeEventListener(`spoolbuddy-tag-matched`,r),window.removeEventListener(`spoolbuddy-unknown-tag`,i),window.removeEventListener(`spoolbuddy-tag-removed`,a),window.removeEventListener(`spoolbuddy-online`,o),window.removeEventListener(`spoolbuddy-offline`,s)}),[n,r,i,a,o,s]);let c=e.matchedSpool?Math.max(0,e.matchedSpool.label_weight-e.matchedSpool.weight_used):null,l=e.weight!==null&&e.matchedSpool?Math.max(0,e.weight-e.matchedSpool.core_weight):null;return{...e,remainingWeight:c,netWeight:l}}var Y1e=l(o(((e,t)=>{(function(n,r){typeof e==`object`&&typeof t==`object`?t.exports=r(f()):typeof define==`function`&&define.amd?define([`react`],r):typeof e==`object`?e.ReactSimpleKeyboard=r(f()):n.ReactSimpleKeyboard=r(n.React)})(e,(function(e){return function(){var t={981:function(){typeof Element>`u`||`remove`in Element.prototype||(Element.prototype.remove=function(){this.parentNode&&this.parentNode.removeChild(this)}),typeof self<`u`&&`document`in self&&((!(`classList`in document.createElement(`_`))||document.createElementNS&&!(`classList`in document.createElementNS(`http://www.w3.org/2000/svg`,`g`)))&&function(e){if(`Element`in e){var t=`classList`,n=`prototype`,r=e.Element[n],i=Object,a=String[n].trim||function(){return this.replace(/^\s+|\s+$/g,``)},o=Array[n].indexOf||function(e){for(var t=0,n=this.length;t1?arguments[1]:void 0)}},7916:function(e,t,n){var r=n(6080),i=n(9565),a=n(8981),o=n(6319),s=n(4209),c=n(3517),l=n(6198),u=n(4659),d=n(4527),f=n(81),p=n(851),m=Array;e.exports=function(e){var t=a(e),n=c(this),h=arguments.length,g=h>1?arguments[1]:void 0,_=g!==void 0;_&&(g=r(g,h>2?arguments[2]:void 0));var v,y,b,x,S,C,w=p(t),T=0;if(!w||this===m&&s(w))for(v=l(t),y=n?new this(v):m(v);v>T;T++)C=_?g(t[T],T):t[T],u(y,T,C);else for(y=n?new this:[],S=(x=f(t,w)).next;!(b=i(S,x)).done;T++)C=_?o(x,g,[b.value,T],!0):b.value,u(y,T,C);return d(y,T),y}},9617:function(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,u=i(o,c);if(e&&n!=n){for(;c>u;)if((l=s[u++])!=l)return!0}else for(;c>u;u++)if((e||u in s)&&s[u]===n)return e||u||0;return!e&&-1}};e.exports={includes:o(!0),indexOf:o(!1)}},9213:function(e,t,n){var r=n(6080),i=n(7055),a=n(8981),o=n(6198),s=n(1469),c=n(4659),l=function(e){var t=e===1,n=e===2,l=e===3,u=e===4,d=e===6,f=e===7,p=e===5||d;return function(m,h,g){for(var _,v,y=a(m),b=i(y),x=o(b),S=r(h,g),C=0,w=0,T=t?s(m,x):n||f?s(m,0):void 0;x>C;C++)if((p||C in b)&&(v=S(_=b[C],C,y),e))if(t)c(T,C,v);else if(v)switch(e){case 3:return!0;case 5:return _;case 6:return C;case 2:c(T,w++,_)}else switch(e){case 4:return!1;case 7:c(T,w++,_)}return d?-1:l||u?u:T}};e.exports={forEach:l(0),map:l(1),filter:l(2),some:l(3),every:l(4),find:l(5),findIndex:l(6),filterReject:l(7)}},597:function(e,t,n){var r=n(9039),i=n(8227),a=n(9519),o=i(`species`);e.exports=function(e){return a>=51||!r((function(){var t=[];return(t.constructor={})[o]=function(){return{foo:1}},t[e](Boolean).foo!==1}))}},4598:function(e,t,n){var r=n(9039);e.exports=function(e,t){var n=[][e];return!!n&&r((function(){n.call(null,t||function(){return 1},1)}))}},926:function(e,t,n){var r=n(9306),i=n(8981),a=n(7055),o=n(6198),s=TypeError,c=`Reduce of empty array with no initial value`,l=function(e){return function(t,n,l,u){var d=i(t),f=a(d),p=o(d);if(r(n),p===0&&l<2)throw new s(c);var m=e?p-1:0,h=e?-1:1;if(l<2)for(;;){if(m in f){u=f[m],m+=h;break}if(m+=h,e?m<0:p<=m)throw new s(c)}for(;e?m>=0:p>m;m+=h)m in f&&(u=n(u,f[m],m,d));return u}};e.exports={left:l(!1),right:l(!0)}},4527:function(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:function(e,t,n){e.exports=n(9504)([].slice)},4488:function(e,t,n){var r=n(7680),i=Math.floor,a=function(e,t){var n=e.length;if(n<8)for(var o,s,c=1;c0;)e[s]=e[--s];s!==c++&&(e[s]=o)}else for(var l=i(n/2),u=a(r(e,0,l),t),d=a(r(e,l),t),f=u.length,p=d.length,m=0,h=0;m9007199254740991)throw t(`Maximum allowed index exceeded`);return e}},7400:function(e){e.exports={CSSRuleList:0,CSSStyleDeclaration:0,CSSValueList:0,ClientRectList:0,DOMRectList:0,DOMStringList:0,DOMTokenList:1,DataTransferItemList:0,FileList:0,HTMLAllCollection:0,HTMLCollection:0,HTMLFormElement:0,HTMLSelectElement:0,MediaList:0,MimeTypeArray:0,NamedNodeMap:0,NodeList:1,PaintRequestList:0,Plugin:0,PluginArray:0,SVGLengthList:0,SVGNumberList:0,SVGPathSegList:0,SVGPointList:0,SVGStringList:0,SVGTransformList:0,SourceBufferList:0,StyleSheetList:0,TextTrackCueList:0,TextTrackList:0,TouchList:0}},9296:function(e,t,n){var r=n(4055)(`span`).classList,i=r&&r.constructor&&r.constructor.prototype;e.exports=i===Object.prototype?void 0:i},8727:function(e){e.exports=[`constructor`,`hasOwnProperty`,`isPrototypeOf`,`propertyIsEnumerable`,`toLocaleString`,`toString`,`valueOf`]},3709:function(e,t,n){var r=n(2839).match(/firefox\/(\d+)/i);e.exports=!!r&&+r[1]},3763:function(e,t,n){var r=n(2839);e.exports=/MSIE|Trident/.test(r)},6193:function(e,t,n){e.exports=n(4215)===`NODE`},2839:function(e,t,n){var r=n(4576).navigator,i=r&&r.userAgent;e.exports=i?String(i):``},9519:function(e,t,n){var r,i,a=n(4576),o=n(2839),s=a.process,c=a.Deno,l=s&&s.versions||c&&c.version,u=l&&l.v8;u&&(i=(r=u.split(`.`))[0]>0&&r[0]<4?1:+(r[0]+r[1])),!i&&o&&(!(r=o.match(/Edge\/(\d+)/))||r[1]>=74)&&(r=o.match(/Chrome\/(\d+)/))&&(i=+r[1]),e.exports=i},3607:function(e,t,n){var r=n(2839).match(/AppleWebKit\/(\d+)\./);e.exports=!!r&&+r[1]},4215:function(e,t,n){var r=n(4576),i=n(2839),a=n(2195),o=function(e){return i.slice(0,e.length)===e};e.exports=o(`Bun/`)?`BUN`:o(`Cloudflare-Workers`)?`CLOUDFLARE`:o(`Deno/`)?`DENO`:o(`Node.js/`)?`NODE`:r.Bun&&typeof Bun.version==`string`?`BUN`:r.Deno&&typeof Deno.version==`object`?`DENO`:a(r.process)===`process`?`NODE`:r.window&&r.document?`BROWSER`:`REST`},6518:function(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,u,d,f,p,m=e.target,h=e.global,g=e.stat;if(n=h?r:g?r[m]||s(m,{}):r[m]&&r[m].prototype)for(u in t){if(f=t[u],d=e.dontCallGetSet?(p=i(n,u))&&p.value:n[u],!l(h?u:m+(g?`.`:`#`)+u,e.forced)&&d!==void 0){if(typeof f==typeof d)continue;c(f,d)}(e.sham||d&&d.sham)&&a(f,`sham`,!0),o(n,u,f,e)}}},9039:function(e){e.exports=function(e){try{return!!e()}catch{return!0}}},9228:function(e,t,n){n(7495);var r=n(9565),i=n(6840),a=n(7323),o=n(9039),s=n(8227),c=n(6699),l=s(`species`),u=RegExp.prototype;e.exports=function(e,t,n,d){var f=s(e),p=!o((function(){var t={};return t[f]=function(){return 7},``[e](t)!==7})),m=p&&!o((function(){var t=!1,n=/a/;if(e===`split`){var r={};r[l]=function(){return n},(n={constructor:r,flags:``})[f]=/./[f]}return n.exec=function(){return t=!0,null},n[f](``),!t}));if(!p||!m||n){var h=/./[f],g=t(f,``[e],(function(e,t,n,i,o){var s=t.exec;return s===a||s===u.exec?p&&!o?{done:!0,value:r(h,t,n,i)}:{done:!0,value:r(e,n,t,i)}:{done:!1}}));i(String.prototype,e,g[0]),i(u,f,g[1])}d&&c(u[f],`sham`,!0)}},8745:function(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:function(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:function(e,t,n){e.exports=!n(9039)((function(){var e=function(){}.bind();return typeof e!=`function`||e.hasOwnProperty(`prototype`)}))},566:function(e,t,n){var r=n(9504),i=n(9306),a=n(34),o=n(9297),s=n(7680),c=n(616),l=Function,u=r([].concat),d=r([].join),f={};e.exports=c?l.bind:function(e){var t=i(this),n=t.prototype,r=s(arguments,1),c=function(){var n=u(r,s(arguments));return this instanceof c?function(e,t,n){if(!o(f,t)){for(var r=[],i=0;i]*>)/g,u=/\$([$&'`]|\d{1,2})/g;e.exports=function(e,t,n,r,d,f){var p=n+e.length,m=r.length,h=u;return d!==void 0&&(d=i(d),h=l),s(f,h,(function(i,s){var l;switch(o(s,0)){case`$`:return`$`;case`&`:return e;case"`":return c(t,0,n);case`'`:return c(t,p);case`<`:l=d[c(s,1,-1)];break;default:var u=+s;if(u===0)return i;if(u>m){var f=a(u/10);return f===0?i:f<=m?r[f-1]===void 0?o(s,1):r[f-1]+o(s,1):i}l=r[u-1]}return l===void 0?``:l}))}},4576:function(e,t,n){var r=function(e){return e&&e.Math===Math&&e};e.exports=r(typeof globalThis==`object`&&globalThis)||r(typeof window==`object`&&window)||r(typeof self==`object`&&self)||r(typeof n.g==`object`&&n.g)||r(typeof this==`object`&&this)||function(){return this}()||Function(`return this`)()},9297:function(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:function(e){e.exports={}},397:function(e,t,n){e.exports=n(7751)(`document`,`documentElement`)},5917:function(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:function(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:function(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:function(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:function(e,t,n){var r,i,a,o=n(8622),s=n(4576),c=n(34),l=n(6699),u=n(9297),d=n(7629),f=n(6119),p=n(421),m=`Object already initialized`,h=s.TypeError,g=s.WeakMap;if(o||d.state){var _=d.state||=new g;_.get=_.get,_.has=_.has,_.set=_.set,r=function(e,t){if(_.has(e))throw new h(m);return t.facade=e,_.set(e,t),t},i=function(e){return _.get(e)||{}},a=function(e){return _.has(e)}}else{var v=f(`state`);p[v]=!0,r=function(e,t){if(u(e,v))throw new h(m);return t.facade=e,l(e,v,t),t},i=function(e){return u(e,v)?e[v]:{}},a=function(e){return u(e,v)}}e.exports={set:r,get:i,has:a,enforce:function(e){return a(e)?i(e):r(e,{})},getterFor:function(e){return function(t){var n;if(!c(t)||(n=i(t)).type!==e)throw new h(`Incompatible receiver, `+e+` required`);return n}}}},4209:function(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:function(e,t,n){var r=n(2195);e.exports=Array.isArray||function(e){return r(e)===`Array`}},4901:function(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`}},3517:function(e,t,n){var r=n(9504),i=n(9039),a=n(4901),o=n(6955),s=n(7751),c=n(3706),l=function(){},u=s(`Reflect`,`construct`),d=/^\s*(?:class|function)\b/,f=r(d.exec),p=!d.test(l),m=function(e){if(!a(e))return!1;try{return u(l,[],e),!0}catch{return!1}},h=function(e){if(!a(e))return!1;switch(o(e)){case`AsyncFunction`:case`GeneratorFunction`:case`AsyncGeneratorFunction`:return!1}try{return p||!!f(d,c(e))}catch{return!0}};h.sham=!0,e.exports=!u||i((function(){var e;return m(m.call)||!m(Object)||!m((function(){e=!0}))||e}))?h:m},2796:function(e,t,n){var r=n(9039),i=n(4901),a=/#|\.prototype\./,o=function(e,t){var n=c[s(e)];return n===u||n!==l&&(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},2087:function(e,t,n){var r=n(34),i=Math.floor;e.exports=Number.isInteger||function(e){return!r(e)&&isFinite(e)&&i(e)===e}},4117:function(e){e.exports=function(e){return e==null}},34:function(e,t,n){var r=n(4901);e.exports=function(e){return typeof e==`object`?e!==null:r(e)}},3925:function(e,t,n){var r=n(34);e.exports=function(e){return r(e)||e===null}},6395:function(e){e.exports=!1},5810:function(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`}},788:function(e,t,n){var r=n(34),i=n(2195),a=n(8227)(`match`);e.exports=function(e){var t;return r(e)&&((t=e[a])===void 0?i(e)===`RegExp`:!!t)}},757:function(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))}},9539:function(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`))){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}},3994:function(e,t,n){var r=n(7657).IteratorPrototype,i=n(2360),a=n(6980),o=n(687),s=n(6269),c=function(){return this};e.exports=function(e,t,n,l){var u=t+` Iterator`;return e.prototype=i(r,{next:a(+!l,n)}),o(e,u,!1,!0),s[u]=c,e}},1088:function(e,t,n){var r=n(6518),i=n(9565),a=n(6395),o=n(350),s=n(4901),c=n(3994),l=n(2787),u=n(2967),d=n(687),f=n(6699),p=n(6840),m=n(8227),h=n(6269),g=n(7657),_=o.PROPER,v=o.CONFIGURABLE,y=g.IteratorPrototype,b=g.BUGGY_SAFARI_ITERATORS,x=m(`iterator`),S=`keys`,C=`values`,w=`entries`,T=function(){return this};e.exports=function(e,t,n,o,m,g,E){c(n,t,o);var D,O,k,A=function(e){if(e===m&&F)return F;if(!b&&e&&e in N)return N[e];switch(e){case S:case C:case w:return function(){return new n(this,e)}}return function(){return new n(this)}},j=t+` Iterator`,M=!1,N=e.prototype,P=N[x]||N[`@@iterator`]||m&&N[m],F=!b&&P||A(m),I=t===`Array`&&N.entries||P;if(I&&(D=l(I.call(new e)))!==Object.prototype&&D.next&&(a||l(D)===y||(u?u(D,y):s(D[x])||p(D,x,T)),d(D,j,!0,!0),a&&(h[j]=T)),_&&m===C&&P&&P.name!==C&&(!a&&v?f(N,`name`,C):(M=!0,F=function(){return i(P,this)})),m)if(O={values:A(C),keys:g?F:A(S),entries:A(w)},E)for(k in O)(b||M||!(k in N))&&p(N,k,O[k]);else r({target:t,proto:!0,forced:b||M},O);return a&&!E||N[x]===F||p(N,x,F,{name:m}),h[t]=F,O}},7657:function(e,t,n){var r,i,a,o=n(9039),s=n(4901),c=n(34),l=n(2360),u=n(2787),d=n(6840),f=n(8227),p=n(6395),m=f(`iterator`),h=!1;[].keys&&(`next`in(a=[].keys())?(i=u(u(a)))!==Object.prototype&&(r=i):h=!0),!c(r)||o((function(){var e={};return r[m].call(e)!==e}))?r={}:p&&(r=l(r)),s(r[m])||d(r,m,(function(){return this})),e.exports={IteratorPrototype:r,BUGGY_SAFARI_ITERATORS:h}},6269:function(e){e.exports={}},6198:function(e,t,n){var r=n(8014);e.exports=function(e){return r(e.length)}},283:function(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`)},741:function(e){var t=Math.ceil,n=Math.floor;e.exports=Math.trunc||function(e){var r=+e;return(r>0?n:t)(r)}},7819:function(e,t,n){e.exports=!n(9039)((function(){var e=`9007199254740993`,t=JSON.rawJSON(e);return!JSON.isRawJSON(t)||JSON.stringify(t)!==e}))},5749:function(e,t,n){var r=n(788),i=TypeError;e.exports=function(e){if(r(e))throw new i(`The method doesn't accept regular expressions`);return e}},4213:function(e,t,n){var r=n(3724),i=n(9504),a=n(9565),o=n(9039),s=n(1072),c=n(3717),l=n(8773),u=n(8981),d=n(7055),f=Object.assign,p=Object.defineProperty,m=i([].concat);e.exports=!f||o((function(){if(r&&f({b:1},f(p({},`a`,{enumerable:!0,get:function(){p(this,`b`,{value:3,enumerable:!1})}}),{b:2})).b!==1)return!0;var e={},t={},n=Symbol(`assign detection`),i=`abcdefghijklmnopqrst`;return e[n]=7,i.split(``).forEach((function(e){t[e]=e})),f({},e)[n]!==7||s(f({},t)).join(``)!==i}))?function(e,t){for(var n=u(e),i=arguments.length,o=1,f=c.f,p=l.f;i>o;)for(var h,g=d(arguments[o++]),_=f?m(s(g),f(g)):s(g),v=_.length,y=0;v>y;)h=_[y++],r&&!a(p,g,h)||(n[h]=g[h]);return n}:f},2360:function(e,t,n){var r,i=n(8551),a=n(6801),o=n(8727),s=n(421),c=n(397),l=n(4055),u=n(6119),d=`prototype`,f=`script`,p=u(`IE_PROTO`),m=function(){},h=function(e){return`<`+f+`>`+e+``},g=function(e){e.write(h(``)),e.close();var t=e.parentWindow.Object;return e=null,t},_=function(){try{r=new ActiveXObject(`htmlfile`)}catch{}var e,t,n;_=typeof document<`u`?document.domain&&r?g(r):(t=l(`iframe`),n=`java`+f+`:`,t.style.display=`none`,c.appendChild(t),t.src=String(n),(e=t.contentWindow.document).open(),e.write(h(`document.F=Object`)),e.close(),e.F):g(r);for(var i=o.length;i--;)delete _[d][o[i]];return _()};s[p]=!0,e.exports=Object.create||function(e,t){var n;return e===null?n=_():(m[d]=i(e),n=new m,m[d]=null,n[p]=e),t===void 0?n:a.f(n,t)}},6801:function(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,r=s(t),i=c(t),l=i.length,u=0;l>u;)a.f(e,n=i[u++],r[n]);return e}},4913:function(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:function(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])}},298:function(e,t,n){var r=n(2195),i=n(5397),a=n(8480).f,o=n(7680),s=typeof window==`object`&&window&&Object.getOwnPropertyNames?Object.getOwnPropertyNames(window):[];e.exports.f=function(e){return s&&r(e)===`Window`?function(e){try{return a(e)}catch{return o(s)}}(e):a(i(e))}},8480:function(e,t,n){var r=n(1828),i=n(8727).concat(`length`,`prototype`);t.f=Object.getOwnPropertyNames||function(e){return r(e,i)}},3717:function(e,t){t.f=Object.getOwnPropertySymbols},2787:function(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:function(e,t,n){e.exports=n(9504)({}.isPrototypeOf)},1828:function(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,r=a(e),l=0,u=[];for(n in r)!i(s,n)&&i(r,n)&&c(u,n);for(;t.length>l;)i(r,n=t[l++])&&(~o(u,n)||c(u,n));return u}},1072:function(e,t,n){var r=n(1828),i=n(8727);e.exports=Object.keys||function(e){return r(e,i)}},8773:function(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},2551:function(e,t,n){var r=n(6395),i=n(4576),a=n(9039),o=n(3607);e.exports=r||!a((function(){if(!(o&&o<535)){var e=Math.random();__defineSetter__.call(null,e,(function(){})),delete i[e]}}))},2967:function(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,t=!1,n={};try{(e=r(Object.prototype,`__proto__`,`set`))(n,[]),t=n instanceof Array}catch{}return function(n,r){return a(n),o(r),i(n)&&(t?e(n,r):n.__proto__=r),n}}():void 0)},3179:function(e,t,n){var r=n(2140),i=n(6955);e.exports=r?{}.toString:function(){return`[object `+i(this)+`]`}},4270:function(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:function(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:function(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":` +`)[0]}),i&&(0,K.jsx)(`span`,{className:`text-bambu-gray/50 shrink-0`,children:n?(0,K.jsx)(ds,{className:`w-3.5 h-3.5`}):(0,K.jsx)(cs,{className:`w-3.5 h-3.5`})})]})},t)})})}),(0,K.jsx)(`div`,{className:`flex items-center justify-between p-3 border-t border-bambu-dark-tertiary text-sm text-bambu-gray`,children:d?(0,K.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`w-2 h-2 bg-green-500 rounded-full animate-pulse`}),`Auto-refreshing every 2 seconds`]}):(0,K.jsx)(`span`,{children:`Click Start to enable live log streaming`})})]})]})}function C1e(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 P9({icon:e,label:t,value:n,subValue:r,color:i=`text-bambu-green`}){return(0,K.jsxs)(`div`,{className:`flex items-start gap-3 p-4 bg-bambu-dark rounded-lg`,children:[(0,K.jsx)(`div`,{className:`p-2 rounded-lg bg-bambu-dark-tertiary ${i}`,children:(0,K.jsx)(e,{className:`w-5 h-5`})}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:t}),(0,K.jsx)(`p`,{className:`text-lg font-semibold text-white truncate`,children:n}),r&&(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:r})]})]})}function w1e({percent:e,color:t=`bg-bambu-green`}){return(0,K.jsx)(`div`,{className:`w-full h-2 bg-bambu-dark rounded-full overflow-hidden`,children:(0,K.jsx)(`div`,{className:`h-full ${t} transition-all duration-300`,style:{width:`${Math.min(100,e)}%`}})})}function F9({title:e,icon:t,children:n}){return(0,K.jsxs)(Dd,{className:`p-6`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-4`,children:[(0,K.jsx)(t,{className:`w-5 h-5 text-bambu-green`}),(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e})]}),n]})}function T1e(){let{t:e}=$e(),t=ao(),[n,r]=(0,y.useState)(null),[i,a]=(0,y.useState)(!1),[o,s]=(0,y.useState)(!1),[c,l]=(0,y.useState)(null),{data:u,isLoading:d,refetch:f,isFetching:p}=q({queryKey:[`systemInfo`],queryFn:Q.getSystemInfo,refetchInterval:3e4}),{data:m}=q({queryKey:[`debugLogging`],queryFn:hd.getDebugLoggingState,staleTime:10*1e3,refetchInterval:10*1e3}),{data:h}=q({queryKey:[`settings`],queryFn:Q.getSettings}),{data:g}=q({queryKey:[`library-stats`],queryFn:Q.getLibraryStats}),{data:_}=q({queryKey:[`printers`],queryFn:Q.getPrinters}),{data:v,refetch:b,isFetching:x}=q({queryKey:[`systemHealth`],queryFn:Q.getSystemHealth,staleTime:60*1e3}),S=h?.time_format||`system`,C=async()=>{s(!0);try{let e=await hd.setDebugLogging(!m?.enabled);t.setQueryData([`debugLogging`],e)}catch(e){console.error(`Failed to toggle debug logging:`,e)}finally{s(!1)}},w=async()=>{r(null),a(!0);try{await hd.downloadSupportBundle()}catch(e){r(e instanceof Error?e.message:`Failed to download support bundle`)}finally{a(!1)}};if(d)return(0,K.jsx)(`div`,{className:`flex items-center justify-center h-64`,children:(0,K.jsx)(X,{className:`w-8 h-8 text-bambu-green animate-spin`})});if(!u)return(0,K.jsx)(`div`,{className:`p-6 text-center text-bambu-gray`,children:e(`system.failedToLoad`,`Failed to load system information`)});let T=u.storage.disk_percent_used>90?`bg-red-500`:u.storage.disk_percent_used>75?`bg-yellow-500`:`bg-bambu-green`,E=u.memory.percent_used>90?`bg-red-500`:u.memory.percent_used>75?`bg-yellow-500`:`bg-bambu-green`;return(0,K.jsxs)(`div`,{className:`p-6 space-y-6`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h1`,{className:`text-2xl font-bold text-white`,children:e(`system.title`,`System Information`)}),(0,K.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:e(`system.subtitle`,`Monitor system resources and database statistics`)})]}),(0,K.jsxs)(`button`,{onClick:()=>f(),disabled:p,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,K.jsx)(Fl,{className:`w-4 h-4 ${p?`animate-spin`:``}`}),e(`common.refresh`,`Refresh`)]})]}),(0,K.jsx)(F9,{title:e(`system.application`,`Application`),icon:Jl,children:(0,K.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-4`,children:[(0,K.jsx)(P9,{icon:Jl,label:e(`system.version`,`Version`),value:`v${u.app.version}`}),(0,K.jsx)(P9,{icon:Ts,label:e(`system.uptime`,`System Uptime`),value:u.system.uptime_formatted}),(0,K.jsx)(P9,{icon:Jl,label:e(`system.hostname`,`Hostname`),value:u.system.hostname})]})}),(0,K.jsx)(F9,{title:e(`support.title`,`Support & Troubleshooting`),icon:Ac,children:(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.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,K.jsxs)(`div`,{className:`flex items-center justify-between p-4 bg-bambu-dark rounded-lg`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`p-2 rounded-lg ${m?.enabled?`bg-amber-500/20 text-amber-500`:`bg-bambu-dark-tertiary text-bambu-gray`}`,children:(0,K.jsx)(Yo,{className:`w-5 h-5`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`font-medium text-white`,children:e(`support.debugLogging`,`Debug Logging`)}),(0,K.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[m?.enabled?e(`support.debugLoggingEnabled`,`Capturing detailed logs`):e(`support.debugLoggingDisabled`,`Normal logging level`),m?.enabled&&m.duration_seconds!==null&&(0,K.jsxs)(`span`,{className:`text-amber-700 dark:text-amber-400 ml-2`,children:[`(`,Math.floor(m.duration_seconds/60),`m `,m.duration_seconds%60,`s)`]})]})]})]}),(0,K.jsxs)(`button`,{onClick:C,disabled:o,className:`px-4 py-2 rounded-lg font-medium transition-colors flex items-center gap-2 ${m?.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:[o&&(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),m?.enabled?e(`support.disableDebug`,`Disable`):e(`support.enableDebug`,`Enable`)]})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-4 bg-bambu-dark rounded-lg`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`p-2 rounded-lg bg-bambu-dark-tertiary text-bambu-green`,children:(0,K.jsx)(Gs,{className:`w-5 h-5`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`font-medium text-white`,children:e(`support.supportBundle`,`Support Bundle`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`support.supportBundleDescription`,`Download system info and logs as a ZIP file`)})]})]}),(0,K.jsxs)(`button`,{onClick:w,disabled:i||!m?.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:m?.enabled?void 0:e(`support.enableDebugFirst`,`Enable debug logging first`),children:[i&&(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),i?e(`support.bundleGenerating`,`Generating...`):e(`common.download`,`Download`)]})]}),i&&(0,K.jsxs)(`div`,{className:`p-3 bg-bambu-dark-tertiary/40 rounded-lg space-y-1`,children:[(0,K.jsxs)(`p`,{className:`text-sm font-medium text-white flex items-center gap-2`,children:[(0,K.jsx)(X,{className:`w-3.5 h-3.5 animate-spin text-bambu-green`}),e(`support.bundleGenerating`,`Generating...`)]}),(0,K.jsxs)(`ul`,{className:`text-xs text-bambu-gray list-disc list-inside space-y-0.5 pl-1`,children:[(0,K.jsx)(`li`,{children:e(`support.bundleStepConnection`,`Running printer connectivity checks`)}),(0,K.jsx)(`li`,{children:e(`support.bundleStepVirtualPrinters`,`Running virtual-printer setup checks`)}),(0,K.jsx)(`li`,{children:e(`support.bundleStepLogScan`,`Scanning recent logs for known issues`)}),(0,K.jsx)(`li`,{children:e(`support.bundleStepBuild`,`Building the support bundle ZIP`)})]})]}),n&&(0,K.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}),!m?.enabled&&(0,K.jsx)(`div`,{className:`p-4 bg-bambu-dark-tertiary/50 rounded-lg`,children:(0,K.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[(0,K.jsx)(`span`,{className:`text-amber-700 dark:text-amber-400 font-medium`,children:e(`support.instructions`,`To report an issue:`)}),(0,K.jsx)(`br`,{}),`1. `,e(`support.step1`,`Enable debug logging`),(0,K.jsx)(`br`,{}),`2. `,e(`support.step2`,`Reproduce the issue`),(0,K.jsx)(`br`,{}),`3. `,e(`support.step3`,`Download the support bundle`),(0,K.jsx)(`br`,{}),`4. `,e(`support.step4`,`Attach the ZIP file to your issue report`)]})}),(0,K.jsxs)(`div`,{className:`p-4 bg-bambu-dark rounded-lg space-y-3`,children:[(0,K.jsx)(`p`,{className:`text-sm font-medium text-white`,children:e(`support.privacyTitle`,`What's in the support bundle?`)}),(0,K.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4 text-sm`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-bambu-green font-medium mb-1`,children:e(`support.collected`,`Collected:`)}),(0,K.jsxs)(`ul`,{className:`text-bambu-gray space-y-0.5`,children:[(0,K.jsxs)(`li`,{children:[`• `,e(`support.collectItem1`,`App version and debug mode`)]}),(0,K.jsxs)(`li`,{children:[`• `,e(`support.collectItem2`,`OS, architecture, Python version`)]}),(0,K.jsxs)(`li`,{children:[`• `,e(`support.collectItem3`,`Database statistics (counts only)`)]}),(0,K.jsxs)(`li`,{children:[`• `,e(`support.collectItem4`,`Printer models and nozzle counts`)]}),(0,K.jsxs)(`li`,{children:[`• `,e(`support.collectItem5`,`Non-sensitive settings (themes, formats)`)]}),(0,K.jsxs)(`li`,{children:[`• `,e(`support.collectItem6`,`Debug logs (sanitized)`)]}),(0,K.jsxs)(`li`,{children:[`• `,e(`support.collectItem7`,`Printer connectivity and firmware versions`)]}),(0,K.jsxs)(`li`,{children:[`• `,e(`support.collectItem8`,`Integration status (Spoolman, MQTT, HA)`)]}),(0,K.jsxs)(`li`,{children:[`• `,e(`support.collectItem9`,`Network interfaces (subnets only)`)]}),(0,K.jsxs)(`li`,{children:[`• `,e(`support.collectItem10`,`Python package versions`)]}),(0,K.jsxs)(`li`,{children:[`• `,e(`support.collectItem11`,`Database health checks`)]}),(0,K.jsxs)(`li`,{children:[`• `,e(`support.collectItem12`,`Docker environment details`)]})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-red-700 dark:text-red-400 font-medium mb-1`,children:e(`support.notCollected`,`NOT collected:`)}),(0,K.jsxs)(`ul`,{className:`text-bambu-gray space-y-0.5`,children:[(0,K.jsxs)(`li`,{children:[`• `,e(`support.notItem1`,`Printer names and serial numbers`)]}),(0,K.jsxs)(`li`,{children:[`• `,e(`support.notItem2`,`Access codes and passwords`)]}),(0,K.jsxs)(`li`,{children:[`• `,e(`support.notItem3`,`Email addresses`)]}),(0,K.jsxs)(`li`,{children:[`• `,e(`support.notItem4`,`API keys and tokens`)]}),(0,K.jsxs)(`li`,{children:[`• `,e(`support.notItem5`,`Webhook URLs`)]}),(0,K.jsxs)(`li`,{children:[`• `,e(`support.notItem6`,`Your hostname or username`)]}),(0,K.jsxs)(`li`,{children:[`• `,e(`support.notItem7`,`IP addresses`)]})]})]})]}),(0,K.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,K.jsx)(S1e,{})]})}),(0,K.jsxs)(F9,{title:e(`diagnostic.sectionTitle`,`Connection Diagnostic`),icon:hu,children:[(0,K.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.`)}),_&&_.length>0?(0,K.jsx)(`div`,{className:`space-y-2`,children:_.map(t=>(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-3 bg-bambu-dark rounded-lg`,children:[(0,K.jsxs)(`div`,{className:`min-w-0`,children:[(0,K.jsx)(`span`,{className:`font-medium text-white`,children:t.name}),(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray ml-2`,children:t.ip_address})]}),(0,K.jsxs)(`button`,{onClick:()=>l(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,K.jsx)(hu,{className:`w-4 h-4`}),e(`diagnostic.runButton`,`Run diagnostic`)]})]},t.id))}):(0,K.jsx)(`p`,{className:`text-bambu-gray`,children:e(`diagnostic.noPrinters`,`No printers configured.`)})]}),(0,K.jsxs)(F9,{title:e(`systemHealth.sectionTitle`),icon:jc,children:[(0,K.jsxs)(`div`,{className:`flex items-start justify-between gap-3 mb-3`,children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`systemHealth.sectionDescription`)}),(0,K.jsxs)(`button`,{onClick:()=>b(),disabled:x,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,K.jsx)(Fl,{className:`w-4 h-4 ${x?`animate-spin`:``}`}),e(`systemHealth.rescan`)]})]}),v?(0,K.jsx)(Ip,{result:v}):(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`common.loading`)})]}),(0,K.jsxs)(F9,{title:e(`system.database`,`Database`),icon:Bs,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4 mb-4`,children:[(0,K.jsx)(P9,{icon:Bs,label:e(`system.dbEngine`,`Database Engine`),value:u.database.engine||`SQLite`}),(0,K.jsx)(P9,{icon:Bs,label:e(`system.dbVersion`,`Version`),value:u.database.version||`unknown`})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-4 mb-4`,children:[(0,K.jsx)(P9,{icon:jo,label:e(`system.totalArchives`,`Total Archives`),value:u.database.archives}),(0,K.jsx)(P9,{icon:_s,label:e(`system.completed`,`Completed`),value:u.database.archives_completed,color:`text-green-500`}),(0,K.jsx)(P9,{icon:Ss,label:e(`system.failed`,`Failed`),value:u.database.archives_failed,color:`text-red-500`}),(0,K.jsx)(P9,{icon:X,label:e(`system.printing`,`Printing`),value:u.database.archives_printing,color:`text-yellow-500`})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-4`,children:[(0,K.jsx)(P9,{icon:Ml,label:e(`system.printers`,`Printers`),value:u.database.printers}),(0,K.jsx)(P9,{icon:yl,label:e(`system.filaments`,`Filaments`),value:u.database.filaments}),(0,K.jsx)(P9,{icon:dc,label:e(`system.projects`,`Projects`),value:u.database.projects}),(0,K.jsx)(P9,{icon:Ol,label:e(`system.smartPlugs`,`Smart Plugs`),value:u.database.smart_plugs})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4 mt-4`,children:[(0,K.jsx)(P9,{icon:Ts,label:e(`system.totalPrintTime`,`Total Print Time`),value:u.database.total_print_time_formatted}),(0,K.jsx)(P9,{icon:jo,label:e(`system.totalFilament`,`Total Filament Used`),value:`${u.database.total_filament_kg} kg`,subValue:`${u.database.total_filament_grams.toLocaleString()} g`})]})]}),(0,K.jsxs)(F9,{title:e(`system.connectedPrinters`,`Connected Printers`),icon:Ml,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-4 mb-4`,children:[(0,K.jsx)(`div`,{className:`text-3xl font-bold text-bambu-green`,children:u.printers.connected}),(0,K.jsx)(`div`,{className:`text-bambu-gray`,children:e(`system.ofTotal`,`of {{total}} printers connected`,{total:u.printers.total})})]}),u.printers.connected_list.length>0?(0,K.jsx)(`div`,{className:`space-y-2`,children:u.printers.connected_list.map(e=>(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-3 bg-bambu-dark rounded-lg`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-bambu-green`}),(0,K.jsx)(`span`,{className:`font-medium text-white`,children:e.name})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-4 text-sm text-bambu-gray`,children:[(0,K.jsx)(`span`,{children:e.model}),(0,K.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,K.jsx)(`p`,{className:`text-bambu-gray`,children:e(`system.noPrintersConnected`,`No printers connected`)})]}),(0,K.jsx)(F9,{title:e(`system.storage`,`Storage`),icon:Oc,children:(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex justify-between text-sm mb-1`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:e(`system.diskUsage`,`Disk Usage`)}),(0,K.jsxs)(`span`,{className:`text-white`,children:[u.storage.disk_used_formatted,` / `,u.storage.disk_total_formatted]})]}),(0,K.jsx)(w1e,{percent:u.storage.disk_percent_used,color:T}),(0,K.jsxs)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:[u.storage.disk_free_formatted,` `,e(`system.free`,`free`),` (`,(100-u.storage.disk_percent_used).toFixed(1),`%)`]})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-4`,children:[(0,K.jsx)(P9,{icon:jo,label:e(`system.archiveStorage`,`Archive Storage`),value:u.storage.archive_size_formatted}),(0,K.jsx)(P9,{icon:Bs,label:e(`system.databaseSize`,`Database Size`),value:u.storage.database_size_formatted}),g&&(0,K.jsx)(P9,{icon:fc,label:e(`system.fileManagerStorage`,`File Manager`),value:C1e(g.total_size_bytes),subValue:`${g.total_files} files, ${g.total_folders} folders`})]})]})}),(0,K.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-6`,children:[(0,K.jsx)(F9,{title:e(`system.memory`,`Memory`),icon:al,children:(0,K.jsx)(`div`,{className:`space-y-4`,children:(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex justify-between text-sm mb-1`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:e(`system.memoryUsage`,`Memory Usage`)}),(0,K.jsxs)(`span`,{className:`text-white`,children:[u.memory.used_formatted,` / `,u.memory.total_formatted]})]}),(0,K.jsx)(w1e,{percent:u.memory.percent_used,color:E}),(0,K.jsxs)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:[u.memory.available_formatted,` `,e(`system.available`,`available`)]})]})})}),(0,K.jsx)(F9,{title:e(`system.cpu`,`CPU`),icon:Ls,children:(0,K.jsx)(`div`,{className:`space-y-4`,children:(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,K.jsx)(P9,{icon:Ls,label:e(`system.cores`,`Cores`),value:u.cpu.count,subValue:`${u.cpu.count_logical} logical`}),(0,K.jsx)(P9,{icon:Ls,label:e(`system.usage`,`Usage`),value:`${u.cpu.percent}%`})]})})})]}),(0,K.jsx)(F9,{title:e(`system.systemDetails`,`System Details`),icon:Jl,children:(0,K.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-4`,children:[(0,K.jsx)(P9,{icon:Jl,label:e(`system.os`,`Operating System`),value:u.system.platform,subValue:u.system.platform_release}),(0,K.jsx)(P9,{icon:Ls,label:e(`system.architecture`,`Architecture`),value:u.system.architecture}),(0,K.jsx)(P9,{icon:Jl,label:e(`system.python`,`Python`),value:u.system.python_version}),(0,K.jsx)(P9,{icon:Ts,label:e(`system.bootTime`,`Boot Time`),value:Gf(u.system.boot_time,S)})]})}),c&&(0,K.jsx)(Mp,{printerId:c.id,printerName:c.name,onClose:()=>l(null)})]})}var I9=`auth_remember_me`,L9=`auth_post_login_redirect`;function R9(e){return e?`persistent`:`session`}function E1e(){try{let e=sessionStorage.getItem(I9)===`1`;return sessionStorage.removeItem(I9),e}catch(e){return console.warn(`consumeSavedRememberMe: sessionStorage unavailable, Remember Me preference lost across OIDC redirect`,e),!1}}function z9(e){return!e||!e.startsWith(`/`)||e.startsWith(`//`)||e.startsWith(`/login`)?null:e}function D1e(e){let t=z9(e);if(t)try{sessionStorage.setItem(L9,t)}catch(e){console.warn(`stashPostLoginRedirect: sessionStorage unavailable, post-login target will be lost across OIDC redirect`,e)}}function O1e(){try{let e=sessionStorage.getItem(L9);return sessionStorage.removeItem(L9),z9(e)}catch(e){return console.warn(`consumePostLoginRedirect: sessionStorage unavailable`,e),null}}function k1e({provider:e,onClick:t,disabled:n}){let{t:r}=$e(),[i,a]=(0,y.useState)(!1);return(0,K.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&&!i?(0,K.jsx)(`img`,{src:Q.oidcProviderIconUrl(e.id),alt:``,className:`w-5 h-5 object-contain`,onError:()=>a(!0)}):(0,K.jsx)(eu,{className:`w-5 h-5 text-bambu-green`}),r(`login.twoFA.signInWith`,{provider:e.name})]})}function A1e(){let e=ir(),t=tr(),[n]=Fi(),{t:r}=$e(),{login:i,loginWithToken:a,user:o,loading:s}=xd(),{showToast:c}=Fd(),{mode:l}=wd();function u(){let e=t.state?.from;if(e?.pathname){let t=z9(`${e.pathname}${e.search??``}`);if(t)return t}return O1e()??`/`}let[d,f]=(0,y.useState)(``),[p,m]=(0,y.useState)(``),[h,g]=(0,y.useState)(!1),[_,v]=(0,y.useState)(``),[b,x]=(0,y.useState)(`credentials`),[S,C]=(0,y.useState)(``),[w,T]=(0,y.useState)([]),[E,D]=(0,y.useState)(`totp`),[O,k]=(0,y.useState)(``),[A,j]=(0,y.useState)(!1),M=(0,y.useRef)(null),[N,P]=(0,y.useState)(!1),[F,I]=(0,y.useState)(``),[L,R]=(0,y.useState)(``),[z,B]=(0,y.useState)(``),{data:V}=q({queryKey:[`advancedAuthStatus`],queryFn:()=>Q.getAdvancedAuthStatus()}),{data:ee}=q({queryKey:[`oidcProviders`],queryFn:()=>Q.getOIDCProviders()}),[te,H]=(0,y.useState)(!1);(0,y.useEffect)(()=>{!s&&o&&b===`credentials`&&e(`/`,{replace:!0})},[s,o,b,e]);let ne=(0,y.useRef)(!1);(0,y.useEffect)(()=>{if(ne.current||n.get(`fallback`)===`local`||!V||!V.autologin_provider_id||window.location.hash.startsWith(`#oidc_token=`)||n.get(`oidc_error`))return;ne.current=!0;let e=V.autologin_provider_id,t=new Promise((e,t)=>setTimeout(()=>t(Error(`autologin timeout`)),5e3));Promise.race([Q.getOIDCAuthorizeUrl(e),t]).then(e=>{window.location.href=e.auth_url}).catch(()=>{H(!0)})},[V,n]);let re=V?.local_login_enabled!==!1,U=te&&V?.autologin_provider_id!=null;(0,y.useEffect)(()=>{let t=window.location.hash,n=t.startsWith(`#reset_token=`)?t.slice(13):null;n&&(I(n),x(`reset-password`),e(`/login`,{replace:!0}))},[]),(0,y.useEffect)(()=>{let t=window.location.hash,i=t.startsWith(`#oidc_token=`)?t.slice(12):null,o=n.get(`oidc_error`);if(!i&&!o)return;let s=E1e();if(o){c({oidc_provider_error:r(`login.oidcErrors.providerError`),missing_parameters:r(`login.oidcErrors.missingParameters`),invalid_state:r(`login.oidcErrors.invalidState`),state_expired:r(`login.oidcErrors.stateExpired`),provider_not_found:r(`login.oidcErrors.providerNotFound`),discovery_failed:r(`login.oidcErrors.discoveryFailed`),invalid_discovery_document:r(`login.oidcErrors.invalidDiscovery`),token_exchange_network_error:r(`login.oidcErrors.networkError`),token_exchange_bad_response:r(`login.oidcErrors.badResponse`),no_id_token:r(`login.oidcErrors.noIdToken`),token_validation_failed:r(`login.oidcErrors.validationFailed`),nonce_mismatch:r(`login.oidcErrors.nonceMismatch`),missing_sub_claim:r(`login.oidcErrors.missingSubClaim`),no_linked_account:r(`login.oidcErrors.noLinkedAccount`),account_inactive:r(`login.oidcErrors.accountInactive`),user_resolution_failed:r(`login.oidcErrors.userResolutionFailed`),internal_error:r(`login.oidcErrors.internalError`)}[o]??(o.startsWith(`token_exchange_`)?r(`login.oidcErrors.tokenExchangeFailed`):r(`login.oidcLoginFailed`)),`error`),e(`/login`,{replace:!0});return}i&&Q.exchangeOIDCToken(i).then(t=>{if(t.requires_2fa&&t.pre_auth_token){P(s),C(t.pre_auth_token);let n=t.two_fa_methods??[];T(n),n.includes(`totp`)?D(`totp`):n.includes(`email`)?D(`email`):D(`backup`),x(`2fa`),e(`/login`,{replace:!0})}else t.access_token&&t.user?(a(t.access_token,t.user,R9(s)),c(r(`login.loginSuccess`)),e(u(),{replace:!0})):(c(r(`login.oidcLoginFailed`),`error`),e(`/login`,{replace:!0}))}).catch(t=>{console.error(`OIDC token exchange failed`,t),c(r(`login.oidcLoginFailed`),`error`),e(`/login`,{replace:!0})})},[n]);let ie=J({mutationFn:()=>i(d,p,R9(N)),onSuccess:t=>{if(t.requires_2fa&&t.pre_auth_token){C(t.pre_auth_token);let e=t.two_fa_methods??[];T(e),e.includes(`totp`)?D(`totp`):e.includes(`email`)?D(`email`):D(`backup`),x(`2fa`)}else t.access_token&&t.user&&(c(r(`login.loginSuccess`)),e(u(),{replace:!0}))},onError:e=>{c(e.message||r(`login.loginFailed`),`error`)}}),ae=J({mutationFn:e=>Q.forgotPassword({email:e}),onSuccess:e=>{c(e.message,`success`),g(!1),v(``)},onError:e=>{c(e.message,`error`)}}),W=J({mutationFn:()=>Q.forgotPasswordConfirm(F,L),onSuccess:e=>{c(e.message,`success`),x(`credentials`),I(``),R(``),B(``)},onError:e=>{c(e.message||r(`login.resetPassword.resetFailed`),`error`)}}),oe=J({mutationFn:()=>Q.sendEmailOTP(S),onSuccess:e=>{j(!0),e.pre_auth_token&&C(e.pre_auth_token),c(e.message,`success`)},onError:e=>{c(e.message||r(`login.twoFA.sendCodeFailed`),`error`)}}),se=J({mutationFn:()=>Q.verify2FA({pre_auth_token:S,code:O,method:E}),onSuccess:t=>{t.access_token&&t.user?(a(t.access_token,t.user,R9(N)),c(r(`login.loginSuccess`)),e(u(),{replace:!0})):(console.error(`2FA verify: unexpected response shape`,t),c(r(`login.loginFailed`),`error`))},onError:e=>{c(e.message||r(`login.twoFA.invalidCode`),`error`),k(``)}}),ce=J({mutationFn:e=>Q.getOIDCAuthorizeUrl(e),onSuccess:e=>{if(N)try{sessionStorage.setItem(I9,`1`)}catch(e){console.warn(`setItem auth_remember_me failed, Remember Me will not carry through OIDC redirect`,e)}let n=t.state?.from;n?.pathname&&D1e(`${n.pathname}${n.search??``}`),window.location.href=e.auth_url},onError:e=>{c(e.message||r(`login.oidcLoginFailed`),`error`)}}),le=e=>{if(e.preventDefault(),!d||!p){c(r(`login.enterCredentials`),`error`);return}ie.mutate()},ue=e=>{if(e.preventDefault(),!O.trim()){c(r(`login.twoFA.enterCode`),`error`);return}se.mutate()},de=e=>{if(e.preventDefault(),!_){c(r(`login.enterEmail`),`error`);return}ae.mutate(_)},fe=e=>{D(e),k(``),j(!1),setTimeout(()=>M.current?.focus(),0)};return b===`reset-password`?(0,K.jsx)(`div`,{className:`min-h-screen flex items-center justify-center bg-bambu-dark p-4`,children:(0,K.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,K.jsxs)(`div`,{className:`text-center`,children:[(0,K.jsx)(`div`,{className:`flex items-center justify-center mb-4`,children:(0,K.jsx)(`div`,{className:`w-14 h-14 rounded-full bg-bambu-green/20 flex items-center justify-center`,children:(0,K.jsx)(Bc,{className:`w-7 h-7 text-bambu-green`})})}),(0,K.jsx)(`h2`,{className:`text-2xl font-bold text-white`,children:r(`login.resetPassword.title`)}),(0,K.jsx)(`p`,{className:`mt-2 text-sm text-bambu-gray`,children:r(`login.resetPassword.subtitle`)})]}),(0,K.jsxs)(`form`,{onSubmit:e=>{if(e.preventDefault(),L!==z){c(r(`login.resetPassword.passwordsDoNotMatch`),`error`);return}if(L.length<8){c(r(`login.resetPassword.passwordTooShort`),`error`);return}W.mutate()},className:`space-y-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{htmlFor:`new-password`,className:`block text-sm font-medium text-white mb-2`,children:r(`login.resetPassword.newPassword`)}),(0,K.jsx)(`input`,{id:`new-password`,type:`password`,required:!0,value:L,onChange:e=>R(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:r(`login.resetPassword.newPasswordPlaceholder`),autoFocus:!0,autoComplete:`new-password`,minLength:8})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{htmlFor:`confirm-password`,className:`block text-sm font-medium text-white mb-2`,children:r(`login.resetPassword.confirmPassword`)}),(0,K.jsx)(`input`,{id:`confirm-password`,type:`password`,required:!0,value:z,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:r(`login.resetPassword.confirmPasswordPlaceholder`),autoComplete:`new-password`})]}),(0,K.jsx)(`button`,{type:`submit`,disabled:W.isPending||!L||!z,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:W.isPending?r(`login.resetPassword.saving`):r(`login.resetPassword.submit`)})]}),(0,K.jsx)(`div`,{className:`text-center`,children:(0,K.jsx)(`button`,{type:`button`,onClick:()=>{x(`credentials`),I(``),R(``),B(``)},className:`text-sm text-bambu-gray hover:text-bambu-green transition-colors`,children:r(`login.resetPassword.backToLogin`)})})]})}):b===`2fa`?(0,K.jsx)(`div`,{className:`min-h-screen flex items-center justify-center bg-bambu-dark p-4`,children:(0,K.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,K.jsxs)(`div`,{className:`text-center`,children:[(0,K.jsx)(`div`,{className:`flex items-center justify-center mb-4`,children:(0,K.jsx)(`div`,{className:`w-14 h-14 rounded-full bg-bambu-green/20 flex items-center justify-center`,children:(0,K.jsx)(eu,{className:`w-7 h-7 text-bambu-green`})})}),(0,K.jsx)(`h2`,{className:`text-2xl font-bold text-white`,children:r(`login.twoFA.title`)}),(0,K.jsx)(`p`,{className:`mt-2 text-sm text-bambu-gray`,children:r(`login.twoFA.subtitle`)})]}),w.length>1&&(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[w.includes(`totp`)&&(0,K.jsxs)(`button`,{type:`button`,onClick:()=>fe(`totp`),className:`flex-1 flex flex-col items-center gap-1 py-2 px-3 rounded-lg border text-xs font-medium transition-colors ${E===`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,K.jsx)(su,{className:`w-4 h-4`}),r(`login.twoFA.methodAuthenticator`)]}),w.includes(`email`)&&(0,K.jsxs)(`button`,{type:`button`,onClick:()=>fe(`email`),className:`flex-1 flex flex-col items-center gap-1 py-2 px-3 rounded-lg border text-xs font-medium transition-colors ${E===`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,K.jsx)(el,{className:`w-4 h-4`}),r(`login.twoFA.methodEmail`)]}),w.includes(`backup`)&&(0,K.jsxs)(`button`,{type:`button`,onClick:()=>fe(`backup`),className:`flex-1 flex flex-col items-center gap-1 py-2 px-3 rounded-lg border text-xs font-medium transition-colors ${E===`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,K.jsx)(Bc,{className:`w-4 h-4`}),r(`login.twoFA.methodBackup`)]})]}),(0,K.jsxs)(`form`,{onSubmit:ue,className:`space-y-4`,children:[E===`totp`&&(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:r(`login.twoFA.instructionsTotp`)}),E===`email`&&(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:r(A?`login.twoFA.instructionsEmail`:`login.twoFA.instructionsEmailNotSent`)}),!A&&(0,K.jsx)($,{type:`button`,variant:`secondary`,className:`w-full`,onClick:()=>oe.mutate(),disabled:oe.isPending,children:oe.isPending?r(`login.twoFA.sendingCode`):r(`login.twoFA.sendCodeButton`)}),A&&(0,K.jsx)(`button`,{type:`button`,onClick:()=>{j(!1),oe.mutate()},className:`text-xs text-bambu-gray hover:text-bambu-green transition-colors`,children:r(`login.twoFA.resendCode`)})]}),E===`backup`&&(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:r(`login.twoFA.instructionsBackup`)}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{htmlFor:`twofa-code`,className:`block text-sm font-medium text-white mb-2`,children:r(E===`backup`?`login.twoFA.backupCodeLabel`:`login.twoFA.codeLabel`)}),(0,K.jsx)(`input`,{ref:M,id:`twofa-code`,type:`text`,inputMode:E===`backup`?`text`:`numeric`,autoComplete:`one-time-code`,value:O,onChange:e=>k(e.target.value.trim()),disabled:E===`email`&&!A,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:r(E===`backup`?`login.twoFA.backupCodePlaceholder`:`login.twoFA.codePlaceholder`),maxLength:E===`backup`?8:6,autoFocus:!0})]}),(0,K.jsx)(`button`,{type:`submit`,disabled:se.isPending||!O.trim()||E===`email`&&!A,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:se.isPending?r(`login.twoFA.verifyingButton`):r(`login.twoFA.verifyButton`)})]}),(0,K.jsx)(`div`,{className:`text-center`,children:(0,K.jsx)(`button`,{type:`button`,onClick:()=>{x(`credentials`),C(``),k(``),j(!1)},className:`text-sm text-bambu-gray hover:text-bambu-green transition-colors`,children:r(`login.twoFA.backToLogin`)})})]})}):(0,K.jsxs)(`div`,{className:`min-h-screen flex items-center justify-center bg-bambu-dark p-4`,children:[(0,K.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,K.jsxs)(`div`,{className:`text-center`,children:[(0,K.jsx)(`div`,{className:`flex items-center justify-center mb-6`,children:(0,K.jsx)(`img`,{src:l===`dark`?`/img/bambuddy_logo_dark_transparent.png`:`/img/bambuddy_logo_light.png`,alt:`Bambuddy`,className:`h-16`})}),(0,K.jsx)(`h2`,{className:`text-3xl font-bold text-white`,children:r(`login.title`)}),(0,K.jsx)(`p`,{className:`mt-2 text-sm text-bambu-gray`,children:r(`login.subtitle`)})]}),U&&(0,K.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:r(`login.autologinFailed`)}),!re&&(0,K.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:r(`login.localDisabledNotice`)}),re&&(0,K.jsxs)(`form`,{className:`mt-8 space-y-6`,onSubmit:le,children:[(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{htmlFor:`username`,className:`block text-sm font-medium text-white mb-2`,children:V?.advanced_auth_enabled?r(`login.usernameOrEmail`):r(`login.username`)}),(0,K.jsx)(`input`,{id:`username`,type:`text`,required:!0,value:d,onChange:e=>f(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:V?.advanced_auth_enabled?r(`login.usernameOrEmailPlaceholder`):r(`login.usernamePlaceholder`),autoComplete:`username`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{htmlFor:`password`,className:`block text-sm font-medium text-white mb-2`,children:r(`login.password`)||`Password`}),(0,K.jsx)(`input`,{id:`password`,type:`password`,required:!0,value:p,onChange:e=>m(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:r(`login.passwordPlaceholder`),autoComplete:`current-password`})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`input`,{id:`remember-me`,type:`checkbox`,checked:N,onChange:e=>P(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,K.jsx)(`label`,{htmlFor:`remember-me`,className:`text-sm text-bambu-gray cursor-pointer`,children:r(`login.rememberMe`)})]}),(0,K.jsx)(`div`,{children:(0,K.jsx)(`button`,{type:`submit`,disabled:ie.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:ie.isPending?r(`login.signingIn`):r(`login.signIn`)})}),(0,K.jsx)(`div`,{className:`text-center`,children:(0,K.jsx)(`button`,{type:`button`,onClick:()=>g(!0),className:`text-sm text-bambu-gray hover:text-bambu-green transition-colors`,children:r(`login.forgotPassword`)})})]}),ee&&ee.length>0&&(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(`div`,{className:`absolute inset-0 flex items-center`,children:(0,K.jsx)(`div`,{className:`w-full border-t border-bambu-dark-tertiary`})}),(0,K.jsx)(`div`,{className:`relative flex justify-center text-sm`,children:(0,K.jsx)(`span`,{className:`px-2 bg-bambu-dark-secondary text-bambu-gray`,children:r(`login.twoFA.orContinueWith`)})})]}),(0,K.jsx)(`div`,{className:`space-y-2`,children:ee.map(e=>(0,K.jsx)(k1e,{provider:e,onClick:()=>ce.mutate(e.id),disabled:ce.isPending},e.id))})]})]}),h&&(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:()=>g(!1),children:(0,K.jsxs)(Dd,{className:`w-full max-w-md`,onClick:e=>e.stopPropagation(),children:[(0,K.jsx)(Od,{children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(el,{className:`w-5 h-5 text-bambu-green`}),(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:r(`login.forgotPasswordTitle`)})]}),(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:()=>{g(!1),v(``)},children:(0,K.jsx)(Ju,{className:`w-5 h-5`})})]})}),(0,K.jsx)(kd,{children:V?.advanced_auth_enabled?(0,K.jsxs)(`form`,{onSubmit:de,className:`space-y-4`,children:[(0,K.jsx)(`p`,{className:`text-bambu-gray text-sm`,children:r(`login.forgotPasswordEmailMessage`)}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{htmlFor:`forgot-email`,className:`block text-sm font-medium text-white mb-2`,children:r(`login.emailAddress`)}),(0,K.jsx)(`input`,{id:`forgot-email`,type:`email`,required:!0,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:r(`login.emailPlaceholder`)})]}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)($,{type:`button`,variant:`secondary`,className:`flex-1`,onClick:()=>{g(!1),v(``)},children:r(`login.cancel`)}),(0,K.jsx)($,{type:`submit`,className:`flex-1`,disabled:ae.isPending,children:ae.isPending?r(`login.sending`):r(`login.sendResetEmail`)})]})]}):(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsx)(`p`,{className:`text-bambu-gray`,children:r(`login.forgotPasswordMessage`)}),(0,K.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4 space-y-2`,children:[(0,K.jsx)(`p`,{className:`text-sm text-white font-medium`,children:r(`login.howToReset`)}),(0,K.jsxs)(`ol`,{className:`text-sm text-bambu-gray space-y-1 list-decimal list-inside`,children:[(0,K.jsx)(`li`,{children:r(`login.resetStep1`)}),(0,K.jsx)(`li`,{children:r(`login.resetStep2`)}),(0,K.jsx)(`li`,{children:r(`login.resetStep3`)}),(0,K.jsx)(`li`,{children:r(`login.resetStep4`)})]})]}),(0,K.jsx)($,{variant:`secondary`,className:`w-full`,onClick:()=>g(!1),children:r(`login.gotIt`)})]})})]})})]})}function j1e(){let e=ir(),{t}=$e(),{showToast:n}=Fd(),{mode:r}=wd(),{refreshAuth:i}=xd(),[a,o]=(0,y.useState)(!1),[s,c]=(0,y.useState)(``),[l,u]=(0,y.useState)(``),[d,f]=(0,y.useState)(``),p=J({mutationFn:()=>Q.setupAuth({auth_enabled:a,admin_username:a?s:void 0,admin_password:a?l:void 0}),onSuccess:async r=>{await i(),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,K.jsx)(`div`,{className:`min-h-screen flex items-center justify-center bg-bambu-dark p-4`,children:(0,K.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,K.jsxs)(`div`,{className:`text-center`,children:[(0,K.jsx)(`div`,{className:`flex items-center justify-center mb-6`,children:(0,K.jsx)(`img`,{src:r===`dark`?`/img/bambuddy_logo_dark_transparent.png`:`/img/bambuddy_logo_light.png`,alt:`Bambuddy`,className:`h-16`})}),(0,K.jsx)(`h2`,{className:`text-3xl font-bold text-white`,children:t(`setup.title`)}),(0,K.jsx)(`p`,{className:`mt-2 text-sm text-bambu-gray`,children:t(`setup.subtitle`)})]}),(0,K.jsxs)(`form`,{className:`mt-8 space-y-6`,onSubmit:e=>{if(e.preventDefault(),a&&(s||l)){if(!s||!l){n(t(`setup.toast.enterBothCredentials`),`error`);return}if(l!==d){n(t(`setup.toast.passwordsDoNotMatch`),`error`);return}if(l.length<6){n(t(`setup.toast.passwordTooShort`),`error`);return}}p.mutate()},children:[(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center p-4 bg-bambu-dark-secondary/50 rounded-lg border border-bambu-dark-tertiary`,children:[(0,K.jsx)(`input`,{id:`auth-enabled`,type:`checkbox`,checked:a,onChange:e=>o(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,K.jsx)(`label`,{htmlFor:`auth-enabled`,className:`ml-3 block text-sm font-medium text-white`,children:t(`setup.enableAuth`)})]}),a&&(0,K.jsxs)(`div`,{className:`space-y-4 mt-4`,children:[(0,K.jsx)(`div`,{className:`p-3 bg-bambu-dark-secondary/50 border border-bambu-dark-tertiary rounded-lg`,children:(0,K.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,K.jsx)(Rc,{className:`w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0`}),(0,K.jsxs)(`div`,{className:`text-sm text-bambu-gray`,children:[(0,K.jsx)(`p`,{className:`text-white font-medium mb-1`,children:t(`setup.adminAccount`)}),(0,K.jsx)(`p`,{children:t(`setup.adminAccountDesc`)})]})]})}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{htmlFor:`admin-username`,className:`block text-sm font-medium text-white mb-2`,children:[t(`setup.adminUsername`),` `,(0,K.jsx)(`span`,{className:`text-bambu-gray text-xs`,children:t(`setup.optionalIfAdminExists`)})]}),(0,K.jsx)(`input`,{id:`admin-username`,type:`text`,value:s,onChange:e=>c(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,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{htmlFor:`admin-password`,className:`block text-sm font-medium text-white mb-2`,children:[t(`setup.adminPassword`),` `,(0,K.jsx)(`span`,{className:`text-bambu-gray text-xs`,children:t(`setup.optionalIfAdminExists`)})]}),(0,K.jsx)(`input`,{id:`admin-password`,type:`password`,value:l,onChange:e=>u(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`})]}),l&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{htmlFor:`confirm-password`,className:`block text-sm font-medium text-white mb-2`,children:t(`setup.confirmPassword`)}),(0,K.jsx)(`input`,{id:`confirm-password`,type:`password`,value:d,onChange:e=>f(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,K.jsx)(`div`,{children:(0,K.jsx)(`button`,{type:`submit`,disabled:p.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:p.isPending?t(`setup.settingUp`):t(`setup.completeSetup`)})})]})]})})}function M1e(){let{t:e}=$e(),{user:t}=xd(),{showToast:n}=Fd(),r=ao(),i=ir(),[a,o]=(0,y.useState)(!0),[s,c]=(0,y.useState)(!0),[l,u]=(0,y.useState)(!0),[d,f]=(0,y.useState)(!0),[p,m]=(0,y.useState)(!1),{data:h,isLoading:g}=q({queryKey:[`advancedAuthStatus`],queryFn:Q.getAdvancedAuthStatus,staleTime:300*1e3}),{data:_,isLoading:v}=q({queryKey:[`settings`],queryFn:Q.getSettings,staleTime:300*1e3}),{data:b,isLoading:x}=q({queryKey:[`user-email-preferences`],queryFn:()=>Q.getUserEmailPreferences()});(0,y.useEffect)(()=>{(h&&!h.advanced_auth_enabled||_&&!_.user_notifications_enabled)&&i(`/settings`,{replace:!0})},[h,_,i]),(0,y.useEffect)(()=>{b&&(o(b.notify_print_start),c(b.notify_print_complete),u(b.notify_print_failed),f(b.notify_print_stopped),m(!1))},[b]);let S=J({mutationFn:()=>Q.updateUserEmailPreferences({notify_print_start:a,notify_print_complete:s,notify_print_failed:l,notify_print_stopped:d}),onSuccess:()=>{r.invalidateQueries({queryKey:[`user-email-preferences`]}),m(!1),n(e(`notifications.userEmail.saveSuccess`),`success`)},onError:t=>{n(t.message||e(`notifications.userEmail.saveError`),`error`)}}),C=(e,t)=>{e(!t),m(!0)};return x||g||v?(0,K.jsx)(`div`,{className:`flex items-center justify-center h-64`,children:(0,K.jsx)(X,{className:`w-8 h-8 animate-spin text-bambu-green`})}):(0,K.jsxs)(`div`,{className:`p-4 md:p-6 max-w-2xl mx-auto`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3 mb-6`,children:[(0,K.jsx)(Uo,{className:`w-7 h-7 text-bambu-green`}),(0,K.jsx)(`h1`,{className:`text-2xl font-bold text-white`,children:e(`notifications.userEmail.title`)})]}),(0,K.jsx)(Dd,{className:`mb-6 border-blue-300 bg-blue-50 dark:border-blue-500/30 dark:bg-blue-500/5`,children:(0,K.jsx)(kd,{className:`py-4`,children:(0,K.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,K.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,K.jsx)(el,{className:`w-5 h-5 text-blue-600 dark:text-blue-400`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h3`,{className:`text-white font-medium`,children:e(`notifications.userEmail.emailNotifications`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:e(`notifications.userEmail.emailNotificationsDesc`)}),t?.email?(0,K.jsxs)(`p`,{className:`text-sm text-blue-700 dark:text-blue-400 mt-2`,children:[e(`notifications.userEmail.sendingTo`),`: `,(0,K.jsx)(`strong`,{children:t.email})]}):(0,K.jsx)(`p`,{className:`text-sm text-yellow-700 dark:text-yellow-400 mt-2`,children:e(`notifications.userEmail.noEmailWarning`)})]})]})})}),(0,K.jsxs)(Dd,{className:`mb-6`,children:[(0,K.jsxs)(Od,{children:[(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`notifications.userEmail.printJobNotifications`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:e(`notifications.userEmail.printJobNotificationsDesc`)})]}),(0,K.jsxs)(kd,{className:`space-y-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-4 bg-bambu-dark rounded-lg`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.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,K.jsx)(_s,{className:`w-5 h-5 ${a?`text-bambu-green`:`text-bambu-gray`}`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white font-medium`,children:e(`notifications.userEmail.printJobStarts`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`notifications.userEmail.printJobStartsDesc`)})]})]}),(0,K.jsx)(`button`,{onClick:()=>C(o,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,K.jsx)(`span`,{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${a?`translate-x-6`:`translate-x-1`}`})})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-4 bg-bambu-dark rounded-lg`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center ${s?`bg-bambu-green/20`:`bg-bambu-dark-tertiary`}`,children:(0,K.jsx)(_s,{className:`w-5 h-5 ${s?`text-bambu-green`:`text-bambu-gray`}`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white font-medium`,children:e(`notifications.userEmail.printJobFinishes`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`notifications.userEmail.printJobFinishesDesc`)})]})]}),(0,K.jsx)(`button`,{onClick:()=>C(c,s),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 ${s?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,role:`switch`,"aria-checked":s,children:(0,K.jsx)(`span`,{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${s?`translate-x-6`:`translate-x-1`}`})})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-4 bg-bambu-dark rounded-lg`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center ${l?`bg-bambu-green/20`:`bg-bambu-dark-tertiary`}`,children:(0,K.jsx)(_s,{className:`w-5 h-5 ${l?`text-bambu-green`:`text-bambu-gray`}`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white font-medium`,children:e(`notifications.userEmail.printErrors`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`notifications.userEmail.printErrorsDesc`)})]})]}),(0,K.jsx)(`button`,{onClick:()=>C(u,l),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 ${l?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,role:`switch`,"aria-checked":l,children:(0,K.jsx)(`span`,{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${l?`translate-x-6`:`translate-x-1`}`})})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-4 bg-bambu-dark rounded-lg`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center ${d?`bg-bambu-green/20`:`bg-bambu-dark-tertiary`}`,children:(0,K.jsx)(_s,{className:`w-5 h-5 ${d?`text-bambu-green`:`text-bambu-gray`}`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white font-medium`,children:e(`notifications.userEmail.printJobStops`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`notifications.userEmail.printJobStopsDesc`)})]})]}),(0,K.jsx)(`button`,{onClick:()=>C(f,d),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 ${d?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,role:`switch`,"aria-checked":d,children:(0,K.jsx)(`span`,{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${d?`translate-x-6`:`translate-x-1`}`})})]})]})]}),(0,K.jsx)(`div`,{className:`flex justify-end`,children:(0,K.jsx)($,{onClick:()=>S.mutate(),disabled:!p||S.isPending||!t?.email,children:S.isPending?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),e(`common.saving`)]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Bl,{className:`w-4 h-4`}),e(`common.save`)]})})})]})}function N1e(){let e=ir(),[t]=Fi(),{t:n}=$e();if(window!==window.top)return(0,K.jsxs)(`div`,{style:{padding:32,color:`#f88`},children:[`GCode viewer static files not found. Check that the`,` `,(0,K.jsx)(`code`,{children:`gcode_viewer/`}),` directory exists and restart uvicorn.`]});let r=t.has(`archive`),i=t.has(`library_file`),a=r?`/archives`:i?`/files`:`/`,o=n(r?`gcodeViewer.backToArchives`:i?`gcodeViewer.backToFiles`:`gcodeViewer.back`),s=()=>{window.history.length>1?e(-1):e(a)},c=`/gcode-viewer/${window.location.search}`;return(0,K.jsxs)(`div`,{style:{height:`calc(100vh - 3.5rem)`,display:`flex`,flexDirection:`column`},children:[(0,K.jsx)(`div`,{className:`flex items-center gap-2 px-4 py-2 border-b border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-900`,children:(0,K.jsxs)(`button`,{type:`button`,onClick:s,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,K.jsx)(Po,{className:`w-4 h-4`}),o]})}),(0,K.jsx)(`iframe`,{src:c,title:`GCode Viewer`,style:{display:`block`,width:`100%`,flex:1,border:`none`}})]})}var P1e=4401;function F1e(){let e=(0,y.useRef)(null),t=(0,y.useRef)(null),n=(0,y.useRef)(!1),r=ao(),[i,a]=(0,y.useState)(!1),o=(0,y.useRef)(new Map),{showToast:s}=Fd(),{t:c}=$e(),l=(0,y.useRef)(new Set),u=(0,y.useRef)(null),d=(0,y.useRef)(new Map),f=(0,y.useRef)(null),p=(0,y.useRef)([]),m=(0,y.useRef)(!1),h=(0,y.useRef)(()=>{}),g=(0,y.useCallback)(()=>{if(m.current||p.current.length===0)return;m.current=!0;let e=()=>{let t=p.current.shift();t?(h.current(t),p.current.length>0?setTimeout(e,16):m.current=!1):m.current=!1};e()},[]),_=(0,y.useCallback)(async()=>{if(n.current||e.current?.readyState===WebSocket.OPEN)return;let r;try{r=(await Q.getWebSocketToken()).token}catch(e){let t=e instanceof $u?e.status:0;if(t===401||t===403)return}if(n.current)return;let i=window.location.protocol===`https:`?`wss:`:`ws:`,o=r?`?token=${encodeURIComponent(r)}`:``,s=`${i}//${window.location.host}/api/v1/ws${o}`,c=new WebSocket(s),l=null;c.onopen=()=>{console.log(`[WebSocket] Connected`),a(!0),l=window.setInterval(()=>{c.readyState===WebSocket.OPEN&&c.send(JSON.stringify({type:`ping`}))},3e4)},c.onmessage=e=>{try{let t=JSON.parse(e.data);t.type===`printer_status`&&t.printer_id!==void 0&&t.data?h.current(t):(p.current.push(t),g())}catch{}},c.onclose=r=>{console.log(`[WebSocket] Closed`,r.code,r.reason),l&&=(clearInterval(l),null),a(!1),e.current=null,!(n.current||r.code===P1e)&&(t.current=window.setTimeout(()=>{_()},3e3))},c.onerror=e=>{console.error(`[WebSocket] Error`,e),c.close()},e.current=c},[g]),v=(0,y.useCallback)(()=>{f.current&&=(clearTimeout(f.current),null);let e=new Map(d.current);d.current.clear(),e.forEach((e,t)=>{r.setQueryData([`printerStatus`,t],t=>{let n={...t,...e};return n.wifi_signal==null&&t?.wifi_signal!=null&&(n.wifi_signal=t.wifi_signal),n})})},[r]),b=(0,y.useCallback)((e,t)=>{let n=d.current.get(e)||{};if(d.current.set(e,{...n,...t}),document.hidden){v();return}f.current||=window.setTimeout(v,100)},[v]),x=(0,y.useCallback)(e=>{l.current.add(e),u.current&&clearTimeout(u.current),u.current=window.setTimeout(()=>{let e=Array.from(l.current);l.current.clear(),u.current=null;let t=0;e.forEach(e=>{setTimeout(()=>{r.invalidateQueries({queryKey:[e]})},t),t+=500})},3e3)},[r]),S=(0,y.useCallback)(e=>{switch(e.type){case`printer_status`:e.printer_id!==void 0&&e.data&&b(e.printer_id,e.data);break;case`print_start`:e.printer_id!==void 0&&r.invalidateQueries({queryKey:[`printerStatus`,e.printer_id]});break;case`missing_spool_assignment`:{if(e.printer_id===void 0||!Array.isArray(e.missing_slots))break;let t=e.missing_slots.map(e=>e&&typeof e.slot==`string`?e.slot:`Unknown`).filter(e=>e.length>0);if(t.length===0){o.current.delete(e.printer_id);break}let n=t.join(`|`);if(o.current.get(e.printer_id)===n)break;o.current.set(e.printer_id,n),s(c(`printers.toast.missingSpoolAssignment`,{printer:e.printer_name||`Printer ${e.printer_id}`,slots:t.join(`, `)}),`warning`);break}case`print_complete`:x(`archives`),x(`archiveStats`);break;case`archive_created`:x(`archives`),x(`archiveStats`);break;case`archive_updated`:x(`archives`);break;case`pong`:break;case`plate_not_empty`:window.dispatchEvent(new CustomEvent(`plate-not-empty`,{detail:{printer_id:e.printer_id,printer_name:e.printer_name,message:e.message}}));break;case`inventory_changed`:x(`inventory-spools`),x(`spoolman-inventory-spools`),x(y9[0]);break;case`spool_assignment_changed`:x(`spool-assignments`),x(`slotPresets`);break;case`spool_assignment_verified`:{let t=e.printer_name||`Printer`,n=e.slot||`?`;e.verified?e.kprofile_applied===!1?s(c(`printers.toast.assignmentVerifiedNoKprofile`,{slot:n,printer:t}),`warning`):s(c(`printers.toast.assignmentVerified`,{slot:n,printer:t}),`success`):s(c(`printers.toast.assignmentNotConfirmed`,{slot:n,printer:t}),`warning`);break}case`spool_auto_assigned`:x(`inventory-spools`),x(`spool-assignments`);break;case`spool_usage_logged`:x(`inventory-spools`);break;case`unknown_tag`:{let t=e;window.dispatchEvent(new CustomEvent(`unknown-tag`,{detail:{printer_id:t.printer_id,ams_id:t.ams_id,tray_id:t.tray_id,tag_uid:t.tag_uid,tray_uuid:t.tray_uuid,tray_type:t.tray_type,tray_color:t.tray_color,tray_sub_brands:t.tray_sub_brands,tray_count:t.tray_count}}));break}case`spoolbuddy_weight`:window.dispatchEvent(new CustomEvent(`spoolbuddy-weight`,{detail:e}));break;case`spoolbuddy_tag_matched`:window.dispatchEvent(new CustomEvent(`spoolbuddy-tag-matched`,{detail:e})),x(`inventory-spools`);break;case`spoolbuddy_unknown_tag`:window.dispatchEvent(new CustomEvent(`spoolbuddy-unknown-tag`,{detail:e}));break;case`spoolbuddy_tag_removed`:window.dispatchEvent(new CustomEvent(`spoolbuddy-tag-removed`,{detail:e}));break;case`spoolbuddy_tag_written`:window.dispatchEvent(new CustomEvent(`spoolbuddy-tag-written`,{detail:e})),x(`inventory-spools`);break;case`spoolbuddy_tag_write_failed`:window.dispatchEvent(new CustomEvent(`spoolbuddy-tag-write-failed`,{detail:e}));break;case`spoolbuddy_online`:window.dispatchEvent(new CustomEvent(`spoolbuddy-online`,{detail:e})),x(`spoolbuddy-devices`),x(`spoolbuddy-update-check`);break;case`spoolbuddy_offline`:window.dispatchEvent(new CustomEvent(`spoolbuddy-offline`,{detail:e})),x(`spoolbuddy-devices`);break;case`spoolbuddy_update`:x(`spoolbuddy-devices`),x(`spoolbuddy-update-check`);break;case`queue_item_uploading`:case`queue_item_upload_progress`:case`queue_item_acked`:case`queue_item_failed`:window.dispatchEvent(new CustomEvent(`bambuddy:dispatch-toast`,{detail:e}));break;case`pipeline_run_updated`:r.invalidateQueries({queryKey:[`pipeline-runs-all`]}),e.run?.pipeline_id&&r.invalidateQueries({queryKey:[`pipeline-runs`,e.run.pipeline_id]});break}},[r,x,b,s,c]);return(0,y.useEffect)(()=>{h.current=S},[S]),(0,y.useEffect)(()=>(n.current=!1,_(),()=>{n.current=!0,t.current&&clearTimeout(t.current),u.current&&clearTimeout(u.current),f.current&&clearTimeout(f.current),e.current&&e.current.close()}),[_]),{isConnected:i,sendMessage:(0,y.useCallback)(t=>{e.current?.readyState===WebSocket.OPEN&&e.current.send(JSON.stringify(t))},[])}}var I1e=`#00ae42`,B9=e=>e!=null&&e>0?e:1/0;function L1e(e){let t=null;for(let n of e){if(!n||n.state!==`RUNNING`||n.progress==null)continue;if(t===null){t=n;continue}let e=B9(n.remaining_time),r=B9(t.remaining_time);(e(t.progress??0))&&(t=n)}return t}function R1e(e){let t=document.createElement(`canvas`);t.width=32,t.height=32;let n=t.getContext(`2d`);if(!n)return null;let r=getComputedStyle(document.documentElement).getPropertyValue(`--accent`).trim()||I1e,i=Math.max(0,Math.min(100,e))/100,a=-Math.PI/2;return n.lineWidth=4,n.beginPath(),n.arc(16,16,13,0,Math.PI*2),n.strokeStyle=`rgba(128,128,128,0.3)`,n.stroke(),n.beginPath(),n.arc(16,16,13,a,a+i*Math.PI*2),n.strokeStyle=r,n.lineCap=`round`,n.stroke(),t.toDataURL(`image/png`)}function V9(e,t){document.querySelectorAll(`link[rel~="icon"]`).forEach(n=>{if(e)t.has(n)||t.set(n,n.href),n.href=e;else{let e=t.get(n);e!==void 0&&(n.href=e)}}),e||t.clear()}function z1e(){let{progressInTitle:e,resolvedMode:t,darkAccent:n,lightAccent:r}=wd(),i=t===`dark`?n:r,{data:a}=q({queryKey:[`printers`],queryFn:Q.getPrinters,enabled:e}),o=bo({queries:(e?a??[]:[]).map(e=>({queryKey:[`printerStatus`,e.id],queryFn:()=>Q.getPrinterStatus(e.id)}))}),s=(0,y.useRef)(new Map),c=(0,y.useRef)(document.title),l=(0,y.useRef)(!1),u=e?L1e(o.map(e=>e.data)):null,d=u&&u.progress!=null?Math.round(u.progress):null;(0,y.useEffect)(()=>{e&&d!=null?(document.title=`${d}% · ${c.current}`,V9(R1e(d),s.current),l.current=!0):l.current&&=(document.title=c.current,V9(null,s.current),!1)},[e,d,i]),(0,y.useEffect)(()=>{let e=s.current,t=l,n=c.current;return()=>{t.current&&(document.title=n,V9(null,e))}},[])}function B1e({children:e}){let{authEnabled:t,user:n,loading:r}=xd(),{data:i}=q({queryKey:[`color-catalog-map`],queryFn:async()=>(await Q.getColorNameMap()).colors,staleTime:1/0,gcTime:1/0,retry:2,enabled:!r&&(!t||n!==null)});return(0,y.useEffect)(()=>{i&&af(i)},[i]),(0,K.jsx)(K.Fragment,{children:e})}function V1e({selectedPrinterId:e,onPrinterChange:t,deviceOnline:n}){let{t:r}=$e(),[i,a]=(0,y.useState)(new Date),{data:o=[]}=q({queryKey:[`printers`],queryFn:()=>Q.getPrinters()}),s=bo({queries:o.map(e=>({queryKey:[`printerStatus`,e.id],queryFn:()=>Q.getPrinterStatus(e.id),refetchInterval:1e4}))}),c=(0,y.useMemo)(()=>o.filter((e,t)=>s[t]?.data?.connected),[o,s]);(0,y.useEffect)(()=>{let n=c.some(t=>t.id===e);(!e||!n)&&c.length>0&&t(c[0].id)},[c,e,t]);let{data:l}=q({queryKey:[`settings`],queryFn:Q.getSettings});return(0,y.useEffect)(()=>{let e=setInterval(()=>a(new Date),1e3);return()=>clearInterval(e)},[]),(0,K.jsxs)(`div`,{className:`h-12 bg-bambu-dark-secondary border-b border-bambu-dark-tertiary flex items-center px-3 gap-4 shrink-0`,children:[(0,K.jsx)(`div`,{className:`flex items-center shrink-0`,children:(0,K.jsx)(`img`,{src:`/img/spoolbuddy_logo_dark_small.png`,alt:`SpoolBuddy`,width:113,height:28,className:`h-7 w-auto`})}),(0,K.jsx)(`div`,{className:`flex-1 flex justify-center`,children:(0,K.jsx)(`select`,{value:e??``,onChange:e=>t(Number(e.target.value)),className:`bg-bambu-dark text-white text-base px-4 py-2 rounded border border-bambu-dark-tertiary focus:outline-none focus:border-bambu-green min-w-[180px]`,children:c.length===0?(0,K.jsx)(`option`,{value:``,children:r(`spoolbuddy.status.noPrinters`,`No printers online`)}):c.map(e=>(0,K.jsx)(`option`,{value:e.id,children:e.name},e.id))})}),(0,K.jsxs)(`div`,{className:`flex items-center gap-3 shrink-0`,children:[(0,K.jsx)(`div`,{className:`flex items-center`,title:n?r(`spoolbuddy.status.backend`,`Backend`):r(`spoolbuddy.status.offline`,`Offline`),children:n?(0,K.jsx)(`div`,{className:`flex items-end gap-0.5 h-4`,children:[1,2,3,4].map(e=>(0,K.jsx)(`div`,{className:`w-1 rounded-sm ${e<=4?`bg-white`:`bg-bambu-dark-tertiary`}`,style:{height:`${e*4}px`}},e))}):(0,K.jsx)(Uu,{className:`w-5 h-5 text-red-400`})}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,K.jsx)(`div`,{className:`w-3 h-3 rounded-full ${n?`bg-bambu-green shadow-[0_0_6px_rgba(34,197,94,0.5)]`:`bg-bambu-gray`}`}),(0,K.jsx)(`span`,{className:`text-sm text-white/50`,children:n?r(`spoolbuddy.status.backend`,`Backend`):r(`spoolbuddy.status.offline`,`Offline`)})]}),(0,K.jsx)(`span`,{className:`text-white/50 text-base font-mono min-w-[50px] text-right`,children:Kf(i,l?.time_format||`system`)})]})]})}var H1e=[{to:`/spoolbuddy`,labelKey:`spoolbuddy.nav.dashboard`,fallback:`Dashboard`,icon:(0,K.jsx)(`svg`,{className:`w-6 h-6`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,K.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M3 12l2-2m0 0l7-7 7 7M5 10v10a1 1 0 001 1h3m10-11l2 2m-2-2v10a1 1 0 01-1 1h-3m-6 0a1 1 0 001-1v-4a1 1 0 011-1h2a1 1 0 011 1v4a1 1 0 001 1m-6 0h6`})})},{to:`/spoolbuddy/ams`,labelKey:`spoolbuddy.nav.ams`,fallback:`AMS`,icon:(0,K.jsx)(`svg`,{className:`w-6 h-6`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,K.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10`})})},{to:`/spoolbuddy/write-tag`,labelKey:`spoolbuddy.nav.writeTag`,fallback:`Write`,icon:(0,K.jsxs)(`svg`,{className:`w-6 h-6`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:2,children:[(0,K.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,K.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M12.53 18.22l-.53.53-.53-.53a.75.75 0 011.06 0z`})]})},{to:`/spoolbuddy/inventory`,labelKey:`spoolbuddy.nav.inventory`,fallback:`Inventory`,icon:(0,K.jsx)(`svg`,{className:`w-6 h-6`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,K.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M20 7l-8-4-8 4m16 0l-8 4m8-4v10l-8 4m0-10L4 7m8 4v10M4 7v10l8 4`})})},{to:`/spoolbuddy/settings`,labelKey:`spoolbuddy.nav.settings`,fallback:`Settings`,icon:(0,K.jsxs)(`svg`,{className:`w-6 h-6`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:[(0,K.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.066 2.573c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.573 1.066c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.066-2.573c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z`}),(0,K.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M15 12a3 3 0 11-6 0 3 3 0 016 0z`})]})}];function U1e(){let{t:e}=$e();return(0,K.jsx)(`nav`,{className:`h-14 bg-bambu-dark-secondary border-t border-bambu-dark-tertiary flex items-stretch shrink-0`,children:H1e.map(t=>(0,K.jsxs)(Oi,{to:t.to,end:t.to===`/spoolbuddy`,className:({isActive:e})=>`flex-1 flex flex-col items-center justify-center gap-1 transition-colors ${e?`text-bambu-green bg-bambu-dark`:`text-white/50 hover:text-white/70 hover:bg-bambu-dark-tertiary`}`,children:[t.icon,(0,K.jsx)(`span`,{className:`text-xs font-medium`,children:e(t.labelKey,t.fallback)})]},t.to))})}function W1e({alert:e}){let{t}=$e(),n=e?e.type===`error`?`bg-red-500`:e.type===`warning`?`bg-amber-500`:`bg-bambu-green`:`bg-bambu-green`;return(0,K.jsxs)(`div`,{className:`h-9 bg-bambu-dark-secondary border-t-2 ${e?e.type===`error`?`border-red-500`:e.type===`warning`?`border-amber-500`:`border-bambu-dark-tertiary`:`border-bambu-dark-tertiary`} flex items-center px-3 gap-3 shrink-0`,children:[(0,K.jsx)(`div`,{className:`w-3.5 h-3.5 rounded-full ${n}`}),(0,K.jsx)(`div`,{className:`flex-1 text-sm text-white/50 truncate`,children:e?(0,K.jsx)(`span`,{children:e.message}):(0,K.jsx)(`span`,{className:`text-bambu-green`,children:t(`spoolbuddy.status.systemReady`,`System Ready`)})})]})}function G1e({isOpen:e,onClose:t,deviceId:n,deviceOnline:r}){let{t:i}=$e(),[a,o]=(0,y.useState)(null),[s,c]=(0,y.useState)(!1),[l,u]=(0,y.useState)(new Map),{data:d=[]}=q({queryKey:[`printers`],queryFn:()=>Q.getPrinters(),enabled:e}),{data:f=[]}=q({queryKey:[`smart-plugs`],queryFn:()=>Q.getSmartPlugs(),enabled:e}),p=d.map(e=>{let t=f.find(t=>t.printer_id===e.id&&t.plug_type!==`mqtt`&&t.enabled);if(!t)return null;let n=l.get(t.id);return{plug:t,printer:e,status:n?{state:n.state,reachable:!0,device_name:null,energy:null}:null,loading:n?.loading??!1}}).filter(Boolean);(0,y.useEffect)(()=>{!e||f.length===0||f.filter(e=>e.printer_id!==null&&e.plug_type!==`mqtt`&&e.enabled).forEach(async e=>{try{let t=await Q.getSmartPlugStatus(e.id);u(n=>{let r=new Map(n);return r.set(e.id,{loading:!1,state:t.state}),r})}catch{u(t=>{let n=new Map(t);return n.set(e.id,{loading:!1,state:null}),n})}})},[e,f]),(0,y.useEffect)(()=>{e||(o(null),c(!1))},[e]);let m=(0,y.useCallback)(async e=>{u(t=>{let n=new Map(t),r=n.get(e.id);return n.set(e.id,{loading:!0,state:r?.state??null}),n});try{await Q.controlSmartPlug(e.id,`toggle`);let t=await Q.getSmartPlugStatus(e.id);u(n=>{let r=new Map(n);return r.set(e.id,{loading:!1,state:t.state}),r})}catch{u(t=>{let n=new Map(t),r=n.get(e.id);return n.set(e.id,{loading:!1,state:r?.state??null}),n})}},[]),h=(0,y.useCallback)(async e=>{if(n){c(!0);try{await gd.systemCommand(n,e),setTimeout(()=>t(),500)}catch{c(!1)}}},[n,t]),g=(0,y.useCallback)(()=>{a&&(a.type===`system`?h(a.command):m(a.plug),o(null))},[a,h,m]);if(!e)return null;let _=e=>e===`ON`||e===`on`;return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`fixed inset-0 z-40 bg-black/50`,onPointerDown:t}),(0,K.jsxs)(`div`,{className:`fixed top-0 left-0 right-0 z-50 bg-bambu-dark-secondary border-b border-bambu-dark-tertiary rounded-b-2xl shadow-2xl animate-slide-down`,children:[(0,K.jsx)(`div`,{className:`flex justify-center pt-2 pb-1`,children:(0,K.jsx)(`div`,{className:`w-10 h-1 rounded-full bg-zinc-600`})}),(0,K.jsxs)(`div`,{className:`px-4 pb-4 max-h-[80vh] overflow-y-auto`,children:[p.length>0&&(0,K.jsxs)(`div`,{className:`mb-4`,children:[(0,K.jsx)(`h3`,{className:`text-xs font-semibold text-zinc-500 uppercase tracking-wide mb-2`,children:i(`spoolbuddy.quickMenu.printerPower`,`Printer Power`)}),(0,K.jsx)(`div`,{className:`space-y-1`,children:p.map(({plug:e,printer:t,loading:n})=>{let r=l.get(e.id),i=_(r?.state??null);return(0,K.jsxs)(`button`,{onClick:()=>o({type:`plug`,plug:e,printer:t,currentState:r?.state??null}),disabled:n,className:`w-full flex items-center gap-2 px-3 py-1.5 rounded-lg bg-zinc-800/60 hover:bg-zinc-700/60 transition-colors min-h-[36px]`,children:[(0,K.jsx)(`div`,{className:`w-2 h-2 rounded-full shrink-0 ${i?`bg-green-500`:`bg-zinc-600`}`}),n&&(0,K.jsx)(X,{className:`w-3 h-3 animate-spin text-zinc-400 shrink-0`}),(0,K.jsx)(`span`,{className:`flex-1 text-sm text-zinc-200 text-left truncate`,children:t.name}),(0,K.jsx)(`span`,{className:`text-xs font-medium ${i?`text-green-400`:`text-zinc-500`}`,children:r?.state??`—`})]},e.id)})})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h3`,{className:`text-xs font-semibold text-zinc-500 uppercase tracking-wide mb-2`,children:i(`spoolbuddy.quickMenu.systemControls`,`System`)}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,K.jsx)(H9,{icon:(0,K.jsx)(Rl,{className:`w-4 h-4`}),label:i(`spoolbuddy.quickMenu.restartDaemon`,`Restart Daemon`),onClick:()=>o({type:`system`,command:`restart_daemon`}),disabled:!n||!r||s}),(0,K.jsx)(H9,{icon:(0,K.jsx)(dl,{className:`w-4 h-4`}),label:i(`spoolbuddy.quickMenu.restartBrowser`,`Restart Browser`),onClick:()=>o({type:`system`,command:`restart_browser`}),disabled:!n||!r||s}),(0,K.jsx)(H9,{icon:(0,K.jsx)(Rl,{className:`w-4 h-4`}),label:i(`spoolbuddy.quickMenu.reboot`,`Reboot`),onClick:()=>o({type:`system`,command:`reboot`}),disabled:!n||!r||s,variant:`warning`}),(0,K.jsx)(H9,{icon:(0,K.jsx)(Al,{className:`w-4 h-4`}),label:i(`spoolbuddy.quickMenu.shutdown`,`Shutdown`),onClick:()=>o({type:`system`,command:`shutdown`}),disabled:!n||!r||s,variant:`danger`})]})]}),(0,K.jsx)(`div`,{className:`flex justify-center mt-3`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-1 text-xs text-zinc-600`,children:[(0,K.jsx)(cs,{className:`w-3 h-3`}),(0,K.jsx)(`span`,{children:i(`spoolbuddy.quickMenu.swipeToClose`,`Swipe down to close`)})]})})]})]}),a&&(0,K.jsx)(`div`,{className:`fixed inset-0 z-[60] flex items-center justify-center bg-black/60`,children:(0,K.jsxs)(`div`,{className:`bg-zinc-800 rounded-2xl p-5 mx-4 max-w-sm w-full border border-zinc-700`,children:[(0,K.jsx)(`h3`,{className:`text-lg font-semibold text-zinc-100 mb-2`,children:i(`spoolbuddy.quickMenu.confirmTitle`,`Confirm`)}),(0,K.jsx)(`p`,{className:`text-sm text-zinc-400 mb-5`,children:a.type===`plug`?_(a.currentState)?i(`spoolbuddy.quickMenu.confirmPlugOff`,`Turn off {{name}}?`,{name:a.printer.name}):i(`spoolbuddy.quickMenu.confirmPlugOn`,`Turn on {{name}}?`,{name:a.printer.name}):a.command===`shutdown`?i(`spoolbuddy.quickMenu.confirmShutdown`,`Are you sure you want to shut down the SpoolBuddy? You will need physical access to turn it back on.`):a.command===`reboot`?i(`spoolbuddy.quickMenu.confirmReboot`,`Are you sure you want to reboot the SpoolBuddy?`):a.command===`restart_daemon`?i(`spoolbuddy.quickMenu.confirmRestartDaemon`,`Restart the SpoolBuddy daemon? NFC and scale will be temporarily unavailable.`):i(`spoolbuddy.quickMenu.confirmRestartBrowser`,`Restart the kiosk browser? The display will briefly go blank.`)}),(0,K.jsxs)(`div`,{className:`flex gap-3`,children:[(0,K.jsx)(`button`,{onClick:()=>o(null),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:i(`common.cancel`,`Cancel`)}),(0,K.jsx)(`button`,{onClick:g,disabled:s,className:`flex-1 px-4 py-2.5 rounded-lg text-sm font-medium text-white transition-colors min-h-[44px] ${a.type===`plug`?_(a.currentState)?`bg-red-600 hover:bg-red-700`:`bg-green-600 hover:bg-green-700`:a.command===`shutdown`?`bg-red-600 hover:bg-red-700`:a.command===`reboot`?`bg-amber-600 hover:bg-amber-700`:`bg-blue-600 hover:bg-blue-700`} disabled:opacity-50`,children:s?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin mx-auto`}):a.type===`plug`?_(a.currentState)?i(`spoolbuddy.quickMenu.turnOff`,`Turn Off`):i(`spoolbuddy.quickMenu.turnOn`,`Turn On`):i(`spoolbuddy.quickMenu.confirm`,`Confirm`)})]})]})})]})}function H9({icon:e,label:t,onClick:n,disabled:r,variant:i=`default`}){return(0,K.jsxs)(`button`,{onClick:n,disabled:r,className:`flex items-center gap-2.5 p-3 rounded-xl transition-colors min-h-[48px] disabled:opacity-40 ${{default:`bg-zinc-800/60 hover:bg-zinc-700/60 text-zinc-300`,warning:`bg-amber-900/30 hover:bg-amber-900/50 text-amber-400`,danger:`bg-red-900/30 hover:bg-red-900/50 text-red-400`}[i]}`,children:[e,(0,K.jsx)(`span`,{className:`text-sm font-medium`,children:t})]})}var K1e={weight:null,weightStable:!1,rawAdc:null,matchedSpool:null,unknownTagUid:null,unknownTrayUuid:null,deviceOnline:!1,deviceId:null};function q1e(e,t){switch(t.type){case`WEIGHT_UPDATE`:return{...e,weight:t.weight,weightStable:t.stable,rawAdc:t.rawAdc,deviceId:t.deviceId,deviceOnline:!0};case`TAG_MATCHED`:return{...e,matchedSpool:t.spool,unknownTagUid:null,unknownTrayUuid:null,deviceId:t.deviceId};case`UNKNOWN_TAG`:return{...e,matchedSpool:null,unknownTagUid:t.tagUid,unknownTrayUuid:t.trayUuid??null,deviceId:t.deviceId};case`TAG_REMOVED`:return{...e,matchedSpool:null,unknownTagUid:null,unknownTrayUuid:null};case`DEVICE_ONLINE`:return{...e,deviceOnline:!0,deviceId:t.deviceId};case`DEVICE_OFFLINE`:return{...e,deviceOnline:!1,weight:null,weightStable:!1,rawAdc:null};default:return e}}function J1e(){let[e,t]=(0,y.useReducer)(q1e,K1e),n=(0,y.useCallback)(e=>{let n=e.detail;t({type:`WEIGHT_UPDATE`,weight:n.weight_grams??n.data?.weight_grams,stable:n.stable??n.data?.stable??!1,rawAdc:n.raw_adc??n.data?.raw_adc??null,deviceId:n.device_id??n.data?.device_id??``})},[]),r=(0,y.useCallback)(e=>{let n=e.detail,r=n.spool??n.data?.spool;r&&t({type:`TAG_MATCHED`,spool:{id:r.id,tag_uid:n.tag_uid??n.data?.tag_uid??``,material:r.material??``,subtype:r.subtype??null,color_name:r.color_name??null,rgba:r.rgba??null,brand:r.brand??null,label_weight:r.label_weight??0,core_weight:r.core_weight??0,weight_used:r.weight_used??0},deviceId:n.device_id??n.data?.device_id??``})},[]),i=(0,y.useCallback)(e=>{let n=e.detail;t({type:`UNKNOWN_TAG`,tagUid:n.tag_uid??n.data?.tag_uid??``,trayUuid:n.tray_uuid??n.data?.tray_uuid??null,deviceId:n.device_id??n.data?.device_id??``})},[]),a=(0,y.useCallback)(e=>{let n=e.detail;t({type:`TAG_REMOVED`,deviceId:n.device_id??n.data?.device_id??``})},[]),o=(0,y.useCallback)(e=>{let n=e.detail;t({type:`DEVICE_ONLINE`,deviceId:n.device_id??n.data?.device_id??``})},[]),s=(0,y.useCallback)(e=>{let n=e.detail;t({type:`DEVICE_OFFLINE`,deviceId:n.device_id??n.data?.device_id??``})},[]);(0,y.useEffect)(()=>(window.addEventListener(`spoolbuddy-weight`,n),window.addEventListener(`spoolbuddy-tag-matched`,r),window.addEventListener(`spoolbuddy-unknown-tag`,i),window.addEventListener(`spoolbuddy-tag-removed`,a),window.addEventListener(`spoolbuddy-online`,o),window.addEventListener(`spoolbuddy-offline`,s),()=>{window.removeEventListener(`spoolbuddy-weight`,n),window.removeEventListener(`spoolbuddy-tag-matched`,r),window.removeEventListener(`spoolbuddy-unknown-tag`,i),window.removeEventListener(`spoolbuddy-tag-removed`,a),window.removeEventListener(`spoolbuddy-online`,o),window.removeEventListener(`spoolbuddy-offline`,s)}),[n,r,i,a,o,s]);let c=e.matchedSpool?Math.max(0,e.matchedSpool.label_weight-e.matchedSpool.weight_used):null,l=e.weight!==null&&e.matchedSpool?Math.max(0,e.weight-e.matchedSpool.core_weight):null;return{...e,remainingWeight:c,netWeight:l}}var Y1e=l(o(((e,t)=>{(function(n,r){typeof e==`object`&&typeof t==`object`?t.exports=r(f()):typeof define==`function`&&define.amd?define([`react`],r):typeof e==`object`?e.ReactSimpleKeyboard=r(f()):n.ReactSimpleKeyboard=r(n.React)})(e,(function(e){return function(){var t={981:function(){typeof Element>`u`||`remove`in Element.prototype||(Element.prototype.remove=function(){this.parentNode&&this.parentNode.removeChild(this)}),typeof self<`u`&&`document`in self&&((!(`classList`in document.createElement(`_`))||document.createElementNS&&!(`classList`in document.createElementNS(`http://www.w3.org/2000/svg`,`g`)))&&function(e){if(`Element`in e){var t=`classList`,n=`prototype`,r=e.Element[n],i=Object,a=String[n].trim||function(){return this.replace(/^\s+|\s+$/g,``)},o=Array[n].indexOf||function(e){for(var t=0,n=this.length;t1?arguments[1]:void 0)}},7916:function(e,t,n){var r=n(6080),i=n(9565),a=n(8981),o=n(6319),s=n(4209),c=n(3517),l=n(6198),u=n(4659),d=n(4527),f=n(81),p=n(851),m=Array;e.exports=function(e){var t=a(e),n=c(this),h=arguments.length,g=h>1?arguments[1]:void 0,_=g!==void 0;_&&(g=r(g,h>2?arguments[2]:void 0));var v,y,b,x,S,C,w=p(t),T=0;if(!w||this===m&&s(w))for(v=l(t),y=n?new this(v):m(v);v>T;T++)C=_?g(t[T],T):t[T],u(y,T,C);else for(y=n?new this:[],S=(x=f(t,w)).next;!(b=i(S,x)).done;T++)C=_?o(x,g,[b.value,T],!0):b.value,u(y,T,C);return d(y,T),y}},9617:function(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,u=i(o,c);if(e&&n!=n){for(;c>u;)if((l=s[u++])!=l)return!0}else for(;c>u;u++)if((e||u in s)&&s[u]===n)return e||u||0;return!e&&-1}};e.exports={includes:o(!0),indexOf:o(!1)}},9213:function(e,t,n){var r=n(6080),i=n(7055),a=n(8981),o=n(6198),s=n(1469),c=n(4659),l=function(e){var t=e===1,n=e===2,l=e===3,u=e===4,d=e===6,f=e===7,p=e===5||d;return function(m,h,g){for(var _,v,y=a(m),b=i(y),x=o(b),S=r(h,g),C=0,w=0,T=t?s(m,x):n||f?s(m,0):void 0;x>C;C++)if((p||C in b)&&(v=S(_=b[C],C,y),e))if(t)c(T,C,v);else if(v)switch(e){case 3:return!0;case 5:return _;case 6:return C;case 2:c(T,w++,_)}else switch(e){case 4:return!1;case 7:c(T,w++,_)}return d?-1:l||u?u:T}};e.exports={forEach:l(0),map:l(1),filter:l(2),some:l(3),every:l(4),find:l(5),findIndex:l(6),filterReject:l(7)}},597:function(e,t,n){var r=n(9039),i=n(8227),a=n(9519),o=i(`species`);e.exports=function(e){return a>=51||!r((function(){var t=[];return(t.constructor={})[o]=function(){return{foo:1}},t[e](Boolean).foo!==1}))}},4598:function(e,t,n){var r=n(9039);e.exports=function(e,t){var n=[][e];return!!n&&r((function(){n.call(null,t||function(){return 1},1)}))}},926:function(e,t,n){var r=n(9306),i=n(8981),a=n(7055),o=n(6198),s=TypeError,c=`Reduce of empty array with no initial value`,l=function(e){return function(t,n,l,u){var d=i(t),f=a(d),p=o(d);if(r(n),p===0&&l<2)throw new s(c);var m=e?p-1:0,h=e?-1:1;if(l<2)for(;;){if(m in f){u=f[m],m+=h;break}if(m+=h,e?m<0:p<=m)throw new s(c)}for(;e?m>=0:p>m;m+=h)m in f&&(u=n(u,f[m],m,d));return u}};e.exports={left:l(!1),right:l(!0)}},4527:function(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:function(e,t,n){e.exports=n(9504)([].slice)},4488:function(e,t,n){var r=n(7680),i=Math.floor,a=function(e,t){var n=e.length;if(n<8)for(var o,s,c=1;c0;)e[s]=e[--s];s!==c++&&(e[s]=o)}else for(var l=i(n/2),u=a(r(e,0,l),t),d=a(r(e,l),t),f=u.length,p=d.length,m=0,h=0;m9007199254740991)throw t(`Maximum allowed index exceeded`);return e}},7400:function(e){e.exports={CSSRuleList:0,CSSStyleDeclaration:0,CSSValueList:0,ClientRectList:0,DOMRectList:0,DOMStringList:0,DOMTokenList:1,DataTransferItemList:0,FileList:0,HTMLAllCollection:0,HTMLCollection:0,HTMLFormElement:0,HTMLSelectElement:0,MediaList:0,MimeTypeArray:0,NamedNodeMap:0,NodeList:1,PaintRequestList:0,Plugin:0,PluginArray:0,SVGLengthList:0,SVGNumberList:0,SVGPathSegList:0,SVGPointList:0,SVGStringList:0,SVGTransformList:0,SourceBufferList:0,StyleSheetList:0,TextTrackCueList:0,TextTrackList:0,TouchList:0}},9296:function(e,t,n){var r=n(4055)(`span`).classList,i=r&&r.constructor&&r.constructor.prototype;e.exports=i===Object.prototype?void 0:i},8727:function(e){e.exports=[`constructor`,`hasOwnProperty`,`isPrototypeOf`,`propertyIsEnumerable`,`toLocaleString`,`toString`,`valueOf`]},3709:function(e,t,n){var r=n(2839).match(/firefox\/(\d+)/i);e.exports=!!r&&+r[1]},3763:function(e,t,n){var r=n(2839);e.exports=/MSIE|Trident/.test(r)},6193:function(e,t,n){e.exports=n(4215)===`NODE`},2839:function(e,t,n){var r=n(4576).navigator,i=r&&r.userAgent;e.exports=i?String(i):``},9519:function(e,t,n){var r,i,a=n(4576),o=n(2839),s=a.process,c=a.Deno,l=s&&s.versions||c&&c.version,u=l&&l.v8;u&&(i=(r=u.split(`.`))[0]>0&&r[0]<4?1:+(r[0]+r[1])),!i&&o&&(!(r=o.match(/Edge\/(\d+)/))||r[1]>=74)&&(r=o.match(/Chrome\/(\d+)/))&&(i=+r[1]),e.exports=i},3607:function(e,t,n){var r=n(2839).match(/AppleWebKit\/(\d+)\./);e.exports=!!r&&+r[1]},4215:function(e,t,n){var r=n(4576),i=n(2839),a=n(2195),o=function(e){return i.slice(0,e.length)===e};e.exports=o(`Bun/`)?`BUN`:o(`Cloudflare-Workers`)?`CLOUDFLARE`:o(`Deno/`)?`DENO`:o(`Node.js/`)?`NODE`:r.Bun&&typeof Bun.version==`string`?`BUN`:r.Deno&&typeof Deno.version==`object`?`DENO`:a(r.process)===`process`?`NODE`:r.window&&r.document?`BROWSER`:`REST`},6518:function(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,u,d,f,p,m=e.target,h=e.global,g=e.stat;if(n=h?r:g?r[m]||s(m,{}):r[m]&&r[m].prototype)for(u in t){if(f=t[u],d=e.dontCallGetSet?(p=i(n,u))&&p.value:n[u],!l(h?u:m+(g?`.`:`#`)+u,e.forced)&&d!==void 0){if(typeof f==typeof d)continue;c(f,d)}(e.sham||d&&d.sham)&&a(f,`sham`,!0),o(n,u,f,e)}}},9039:function(e){e.exports=function(e){try{return!!e()}catch{return!0}}},9228:function(e,t,n){n(7495);var r=n(9565),i=n(6840),a=n(7323),o=n(9039),s=n(8227),c=n(6699),l=s(`species`),u=RegExp.prototype;e.exports=function(e,t,n,d){var f=s(e),p=!o((function(){var t={};return t[f]=function(){return 7},``[e](t)!==7})),m=p&&!o((function(){var t=!1,n=/a/;if(e===`split`){var r={};r[l]=function(){return n},(n={constructor:r,flags:``})[f]=/./[f]}return n.exec=function(){return t=!0,null},n[f](``),!t}));if(!p||!m||n){var h=/./[f],g=t(f,``[e],(function(e,t,n,i,o){var s=t.exec;return s===a||s===u.exec?p&&!o?{done:!0,value:r(h,t,n,i)}:{done:!0,value:r(e,n,t,i)}:{done:!1}}));i(String.prototype,e,g[0]),i(u,f,g[1])}d&&c(u[f],`sham`,!0)}},8745:function(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:function(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:function(e,t,n){e.exports=!n(9039)((function(){var e=function(){}.bind();return typeof e!=`function`||e.hasOwnProperty(`prototype`)}))},566:function(e,t,n){var r=n(9504),i=n(9306),a=n(34),o=n(9297),s=n(7680),c=n(616),l=Function,u=r([].concat),d=r([].join),f={};e.exports=c?l.bind:function(e){var t=i(this),n=t.prototype,r=s(arguments,1),c=function(){var n=u(r,s(arguments));return this instanceof c?function(e,t,n){if(!o(f,t)){for(var r=[],i=0;i]*>)/g,u=/\$([$&'`]|\d{1,2})/g;e.exports=function(e,t,n,r,d,f){var p=n+e.length,m=r.length,h=u;return d!==void 0&&(d=i(d),h=l),s(f,h,(function(i,s){var l;switch(o(s,0)){case`$`:return`$`;case`&`:return e;case"`":return c(t,0,n);case`'`:return c(t,p);case`<`:l=d[c(s,1,-1)];break;default:var u=+s;if(u===0)return i;if(u>m){var f=a(u/10);return f===0?i:f<=m?r[f-1]===void 0?o(s,1):r[f-1]+o(s,1):i}l=r[u-1]}return l===void 0?``:l}))}},4576:function(e,t,n){var r=function(e){return e&&e.Math===Math&&e};e.exports=r(typeof globalThis==`object`&&globalThis)||r(typeof window==`object`&&window)||r(typeof self==`object`&&self)||r(typeof n.g==`object`&&n.g)||r(typeof this==`object`&&this)||function(){return this}()||Function(`return this`)()},9297:function(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:function(e){e.exports={}},397:function(e,t,n){e.exports=n(7751)(`document`,`documentElement`)},5917:function(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:function(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:function(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:function(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:function(e,t,n){var r,i,a,o=n(8622),s=n(4576),c=n(34),l=n(6699),u=n(9297),d=n(7629),f=n(6119),p=n(421),m=`Object already initialized`,h=s.TypeError,g=s.WeakMap;if(o||d.state){var _=d.state||=new g;_.get=_.get,_.has=_.has,_.set=_.set,r=function(e,t){if(_.has(e))throw new h(m);return t.facade=e,_.set(e,t),t},i=function(e){return _.get(e)||{}},a=function(e){return _.has(e)}}else{var v=f(`state`);p[v]=!0,r=function(e,t){if(u(e,v))throw new h(m);return t.facade=e,l(e,v,t),t},i=function(e){return u(e,v)?e[v]:{}},a=function(e){return u(e,v)}}e.exports={set:r,get:i,has:a,enforce:function(e){return a(e)?i(e):r(e,{})},getterFor:function(e){return function(t){var n;if(!c(t)||(n=i(t)).type!==e)throw new h(`Incompatible receiver, `+e+` required`);return n}}}},4209:function(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:function(e,t,n){var r=n(2195);e.exports=Array.isArray||function(e){return r(e)===`Array`}},4901:function(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`}},3517:function(e,t,n){var r=n(9504),i=n(9039),a=n(4901),o=n(6955),s=n(7751),c=n(3706),l=function(){},u=s(`Reflect`,`construct`),d=/^\s*(?:class|function)\b/,f=r(d.exec),p=!d.test(l),m=function(e){if(!a(e))return!1;try{return u(l,[],e),!0}catch{return!1}},h=function(e){if(!a(e))return!1;switch(o(e)){case`AsyncFunction`:case`GeneratorFunction`:case`AsyncGeneratorFunction`:return!1}try{return p||!!f(d,c(e))}catch{return!0}};h.sham=!0,e.exports=!u||i((function(){var e;return m(m.call)||!m(Object)||!m((function(){e=!0}))||e}))?h:m},2796:function(e,t,n){var r=n(9039),i=n(4901),a=/#|\.prototype\./,o=function(e,t){var n=c[s(e)];return n===u||n!==l&&(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},2087:function(e,t,n){var r=n(34),i=Math.floor;e.exports=Number.isInteger||function(e){return!r(e)&&isFinite(e)&&i(e)===e}},4117:function(e){e.exports=function(e){return e==null}},34:function(e,t,n){var r=n(4901);e.exports=function(e){return typeof e==`object`?e!==null:r(e)}},3925:function(e,t,n){var r=n(34);e.exports=function(e){return r(e)||e===null}},6395:function(e){e.exports=!1},5810:function(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`}},788:function(e,t,n){var r=n(34),i=n(2195),a=n(8227)(`match`);e.exports=function(e){var t;return r(e)&&((t=e[a])===void 0?i(e)===`RegExp`:!!t)}},757:function(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))}},9539:function(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`))){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}},3994:function(e,t,n){var r=n(7657).IteratorPrototype,i=n(2360),a=n(6980),o=n(687),s=n(6269),c=function(){return this};e.exports=function(e,t,n,l){var u=t+` Iterator`;return e.prototype=i(r,{next:a(+!l,n)}),o(e,u,!1,!0),s[u]=c,e}},1088:function(e,t,n){var r=n(6518),i=n(9565),a=n(6395),o=n(350),s=n(4901),c=n(3994),l=n(2787),u=n(2967),d=n(687),f=n(6699),p=n(6840),m=n(8227),h=n(6269),g=n(7657),_=o.PROPER,v=o.CONFIGURABLE,y=g.IteratorPrototype,b=g.BUGGY_SAFARI_ITERATORS,x=m(`iterator`),S=`keys`,C=`values`,w=`entries`,T=function(){return this};e.exports=function(e,t,n,o,m,g,E){c(n,t,o);var D,O,k,A=function(e){if(e===m&&F)return F;if(!b&&e&&e in N)return N[e];switch(e){case S:case C:case w:return function(){return new n(this,e)}}return function(){return new n(this)}},j=t+` Iterator`,M=!1,N=e.prototype,P=N[x]||N[`@@iterator`]||m&&N[m],F=!b&&P||A(m),I=t===`Array`&&N.entries||P;if(I&&(D=l(I.call(new e)))!==Object.prototype&&D.next&&(a||l(D)===y||(u?u(D,y):s(D[x])||p(D,x,T)),d(D,j,!0,!0),a&&(h[j]=T)),_&&m===C&&P&&P.name!==C&&(!a&&v?f(N,`name`,C):(M=!0,F=function(){return i(P,this)})),m)if(O={values:A(C),keys:g?F:A(S),entries:A(w)},E)for(k in O)(b||M||!(k in N))&&p(N,k,O[k]);else r({target:t,proto:!0,forced:b||M},O);return a&&!E||N[x]===F||p(N,x,F,{name:m}),h[t]=F,O}},7657:function(e,t,n){var r,i,a,o=n(9039),s=n(4901),c=n(34),l=n(2360),u=n(2787),d=n(6840),f=n(8227),p=n(6395),m=f(`iterator`),h=!1;[].keys&&(`next`in(a=[].keys())?(i=u(u(a)))!==Object.prototype&&(r=i):h=!0),!c(r)||o((function(){var e={};return r[m].call(e)!==e}))?r={}:p&&(r=l(r)),s(r[m])||d(r,m,(function(){return this})),e.exports={IteratorPrototype:r,BUGGY_SAFARI_ITERATORS:h}},6269:function(e){e.exports={}},6198:function(e,t,n){var r=n(8014);e.exports=function(e){return r(e.length)}},283:function(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`)},741:function(e){var t=Math.ceil,n=Math.floor;e.exports=Math.trunc||function(e){var r=+e;return(r>0?n:t)(r)}},7819:function(e,t,n){e.exports=!n(9039)((function(){var e=`9007199254740993`,t=JSON.rawJSON(e);return!JSON.isRawJSON(t)||JSON.stringify(t)!==e}))},5749:function(e,t,n){var r=n(788),i=TypeError;e.exports=function(e){if(r(e))throw new i(`The method doesn't accept regular expressions`);return e}},4213:function(e,t,n){var r=n(3724),i=n(9504),a=n(9565),o=n(9039),s=n(1072),c=n(3717),l=n(8773),u=n(8981),d=n(7055),f=Object.assign,p=Object.defineProperty,m=i([].concat);e.exports=!f||o((function(){if(r&&f({b:1},f(p({},`a`,{enumerable:!0,get:function(){p(this,`b`,{value:3,enumerable:!1})}}),{b:2})).b!==1)return!0;var e={},t={},n=Symbol(`assign detection`),i=`abcdefghijklmnopqrst`;return e[n]=7,i.split(``).forEach((function(e){t[e]=e})),f({},e)[n]!==7||s(f({},t)).join(``)!==i}))?function(e,t){for(var n=u(e),i=arguments.length,o=1,f=c.f,p=l.f;i>o;)for(var h,g=d(arguments[o++]),_=f?m(s(g),f(g)):s(g),v=_.length,y=0;v>y;)h=_[y++],r&&!a(p,g,h)||(n[h]=g[h]);return n}:f},2360:function(e,t,n){var r,i=n(8551),a=n(6801),o=n(8727),s=n(421),c=n(397),l=n(4055),u=n(6119),d=`prototype`,f=`script`,p=u(`IE_PROTO`),m=function(){},h=function(e){return`<`+f+`>`+e+``},g=function(e){e.write(h(``)),e.close();var t=e.parentWindow.Object;return e=null,t},_=function(){try{r=new ActiveXObject(`htmlfile`)}catch{}var e,t,n;_=typeof document<`u`?document.domain&&r?g(r):(t=l(`iframe`),n=`java`+f+`:`,t.style.display=`none`,c.appendChild(t),t.src=String(n),(e=t.contentWindow.document).open(),e.write(h(`document.F=Object`)),e.close(),e.F):g(r);for(var i=o.length;i--;)delete _[d][o[i]];return _()};s[p]=!0,e.exports=Object.create||function(e,t){var n;return e===null?n=_():(m[d]=i(e),n=new m,m[d]=null,n[p]=e),t===void 0?n:a.f(n,t)}},6801:function(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,r=s(t),i=c(t),l=i.length,u=0;l>u;)a.f(e,n=i[u++],r[n]);return e}},4913:function(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:function(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])}},298:function(e,t,n){var r=n(2195),i=n(5397),a=n(8480).f,o=n(7680),s=typeof window==`object`&&window&&Object.getOwnPropertyNames?Object.getOwnPropertyNames(window):[];e.exports.f=function(e){return s&&r(e)===`Window`?function(e){try{return a(e)}catch{return o(s)}}(e):a(i(e))}},8480:function(e,t,n){var r=n(1828),i=n(8727).concat(`length`,`prototype`);t.f=Object.getOwnPropertyNames||function(e){return r(e,i)}},3717:function(e,t){t.f=Object.getOwnPropertySymbols},2787:function(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:function(e,t,n){e.exports=n(9504)({}.isPrototypeOf)},1828:function(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,r=a(e),l=0,u=[];for(n in r)!i(s,n)&&i(r,n)&&c(u,n);for(;t.length>l;)i(r,n=t[l++])&&(~o(u,n)||c(u,n));return u}},1072:function(e,t,n){var r=n(1828),i=n(8727);e.exports=Object.keys||function(e){return r(e,i)}},8773:function(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},2551:function(e,t,n){var r=n(6395),i=n(4576),a=n(9039),o=n(3607);e.exports=r||!a((function(){if(!(o&&o<535)){var e=Math.random();__defineSetter__.call(null,e,(function(){})),delete i[e]}}))},2967:function(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,t=!1,n={};try{(e=r(Object.prototype,`__proto__`,`set`))(n,[]),t=n instanceof Array}catch{}return function(n,r){return a(n),o(r),i(n)&&(t?e(n,r):n.__proto__=r),n}}():void 0)},3179:function(e,t,n){var r=n(2140),i=n(6955);e.exports=r?{}.toString:function(){return`[object `+i(this)+`]`}},4270:function(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:function(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:function(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=``;t0&&(!p.multiline||p.multiline&&v(T,p.lastIndex-1)!==` `)&&(A=`(?: `+A+`)`,M=` `+M,j++),n=RegExp(`^(?:`+A+`)`,k)),w&&(n=RegExp(`^`+A+`$(?!\\s)`,k)),S&&(r=p.lastIndex),i=a(g,O?n:p,M),O?i?(i.input=x(i.input,j),i[0]=x(i[0],j),i.index=p.lastIndex,p.lastIndex+=i[0].length):p.lastIndex=0:S&&i&&(p.lastIndex=p.global?i.index+i[0].length:r),w&&i&&i.length>1&&a(h,i[0],n,(function(){for(o=1;ob)`,`g`);return e.exec(`b`).groups.a!==`b`||`b`.replace(e,`$c`)!==`bc`}))},7750:function(e,t,n){var r=n(4117),i=TypeError;e.exports=function(e){if(r(e))throw new i(`Can't call method on `+e);return e}},7633:function(e,t,n){var r=n(7751),i=n(2106),a=n(8227),o=n(3724),s=a(`species`);e.exports=function(e){var t=r(e);o&&t&&!t[s]&&i(t,s,{configurable:!0,get:function(){return this}})}},687:function(e,t,n){var r=n(4913).f,i=n(9297),a=n(8227)(`toStringTag`);e.exports=function(e,t,n){e&&!n&&(e=e.prototype),e&&!i(e,a)&&r(e,a,{configurable:!0,value:t})}},6119:function(e,t,n){var r=n(5745),i=n(3392),a=r(`keys`);e.exports=function(e){return a[e]||(a[e]=i(e))}},7629:function(e,t,n){var r=n(6395),i=n(4576),a=n(9433),o=`__core-js_shared__`,s=e.exports=i[o]||a(o,{});(s.versions||=[]).push({version:`3.48.0`,mode:r?`pure`:`global`,copyright:`© 2013–2025 Denis Pushkarev (zloirock.ru), 2025–2026 CoreJS Company (core-js.io). All rights reserved.`,license:`https://github.com/zloirock/core-js/blob/v3.48.0/LICENSE`,source:`https://github.com/zloirock/core-js`})},5745:function(e,t,n){var r=n(7629);e.exports=function(e,t){return r[e]||(r[e]=t||{})}},2293:function(e,t,n){var r=n(8551),i=n(5548),a=n(4117),o=n(8227)(`species`);e.exports=function(e,t){var n,s=r(e).constructor;return s===void 0||a(n=r(s)[o])?t:i(n)}},8183:function(e,t,n){var r=n(9504),i=n(1291),a=n(655),o=n(7750),s=r(``.charAt),c=r(``.charCodeAt),l=r(``.slice),u=function(e){return function(t,n){var r,u,d=a(o(t)),f=i(n),p=d.length;return f<0||f>=p?e?``:void 0:(r=c(d,f))<55296||r>56319||f+1===p||(u=c(d,f+1))<56320||u>57343?e?s(d,f):r:e?l(d,f,f+2):u-56320+(r-55296<<10)+65536}};e.exports={codeAt:u(!1),charAt:u(!0)}},706:function(e,t,n){var r=n(350).PROPER,i=n(9039),a=n(7452);e.exports=function(e){return i((function(){return!!a[e]()||`​…᠎`[e]()!==`​…᠎`||r&&a[e].name!==e}))}},3802:function(e,t,n){var r=n(9504),i=n(7750),a=n(655),o=n(7452),s=r(``.replace),c=RegExp(`^[`+o+`]+`),l=RegExp(`(^|[^`+o+`])[`+o+`]+$`),u=function(e){return function(t){var n=a(i(t));return 1&e&&(n=s(n,c,``)),2&e&&(n=s(n,l,`$1`)),n}};e.exports={start:u(1),end:u(2),trim:u(3)}},4495:function(e,t,n){var r=n(9519),i=n(9039),a=n(4576).String;e.exports=!!Object.getOwnPropertySymbols&&!i((function(){var e=Symbol(`symbol detection`);return!a(e)||!(Object(e)instanceof Symbol)||!Symbol.sham&&r&&r<41}))},8242:function(e,t,n){var r=n(9565),i=n(7751),a=n(8227),o=n(6840);e.exports=function(){var e=i(`Symbol`),t=e&&e.prototype,n=t&&t.valueOf,s=a(`toPrimitive`);t&&!t[s]&&o(t,s,(function(e){return r(n,this)}),{arity:1})}},1296:function(e,t,n){e.exports=n(4495)&&!!Symbol.for&&!!Symbol.keyFor},1240:function(e,t,n){e.exports=n(9504)(1.1.valueOf)},5610:function(e,t,n){var r=n(1291),i=Math.max,a=Math.min;e.exports=function(e,t){var n=r(e);return n<0?i(n+t,0):a(n,t)}},5397:function(e,t,n){var r=n(7055),i=n(7750);e.exports=function(e){return r(i(e))}},1291:function(e,t,n){var r=n(741);e.exports=function(e){var t=+e;return t!=t||t===0?0:r(t)}},8014:function(e,t,n){var r=n(1291),i=Math.min;e.exports=function(e){var t=r(e);return t>0?i(t,9007199254740991):0}},8981:function(e,t,n){var r=n(7750),i=Object;e.exports=function(e){return i(r(e))}},2777:function(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,c=o(e,u);if(c){if(t===void 0&&(t=`default`),n=r(c,e,t),!i(n)||a(n))return n;throw new l(`Can't convert object to primitive value`)}return t===void 0&&(t=`number`),s(e,t)}},6969:function(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:function(e,t,n){var r={};r[n(8227)(`toStringTag`)]=`z`,e.exports=String(r)===`[object z]`},655:function(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:function(e){var t=String;e.exports=function(e){try{return t(e)}catch{return`Object`}}},3392:function(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)}},7040:function(e,t,n){e.exports=n(4495)&&!Symbol.sham&&typeof Symbol.iterator==`symbol`},8686:function(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}))},8622:function(e,t,n){var r=n(4576),i=n(4901),a=r.WeakMap;e.exports=i(a)&&/native code/.test(String(a))},511:function(e,t,n){var r=n(9167),i=n(9297),a=n(1951),o=n(4913).f;e.exports=function(e){var t=r.Symbol||={};i(t,e)||o(t,e,{value:a.f(e)})}},1951:function(e,t,n){t.f=n(8227)},8227:function(e,t,n){var r=n(4576),i=n(5745),a=n(9297),o=n(3392),s=n(4495),c=n(7040),l=r.Symbol,u=i(`wks`),d=c?l.for||l:l&&l.withoutSetter||o;e.exports=function(e){return a(u,e)||(u[e]=s&&a(l,e)?l[e]:d(`Symbol.`+e)),u[e]}},7452:function(e){e.exports=` diff --git a/static/index.html b/static/index.html index 246ba841d..9db943451 100644 --- a/static/index.html +++ b/static/index.html @@ -26,7 +26,7 @@ - +