diff --git a/CHANGELOG.md b/CHANGELOG.md index f736e189d..4ff21a802 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ All notable changes to Bambuddy will be documented in this file. ## [0.2.5b2] - Unreleased ### Fixed +- **P1S camera still black on every page load, recovering only after ~20 minutes (#2521, reporter @nnimby848)** — The previous round of fixes did not take, and the reporter re-tested on two daily builds to say so. The fan-out barrier added last time — a replacement stream waits for the displaced one's socket to close before dialling, so a printer that allows a single camera connection never sees two at once — was correct, and was being **bypassed**. `shutdown_broadcaster()` *popped* the broadcaster out of the registry and only then awaited its teardown, so for the duration of the socket close the registry slot sat empty. A `/camera/stream` request landing in that window found nothing, minted a broadcaster with no predecessor to wait for, and dialled port 6000 immediately. The barrier only engages when the displaced broadcaster is still findable — and the one path that tears a stream down on purpose removed it first, disabling the barrier in exactly the case it was written for. A page reload fires `/camera/stop` and the new `/camera/stream` **concurrently**, which is why it reproduced on essentially every load. The printer then held two connections, kept feeding the orphan, and starved the live viewer: the new socket connects (the reporter's logs show `Chamber image: connected`) and then receives nothing until the printer's TCP keepalive reaps the dead one — **his 20 minutes, to the minute**. The stopped broadcaster now stays in the registry so the next viewer chains behind its socket close, which is what the barrier always intended. Pinned by a test that counts *actual* sockets through the real stop-then-restream race and fails with `2` against the old code; the existing barrier tests placed the broadcaster into the registry by hand, which is precisely why they never caught this. +- **Every camera page load attached two viewers and abandoned one (#2521)** — Found while reproducing the above, and the reason it fired on *every* load rather than occasionally. The stream-token query runs whether or not authentication is enabled, and the camera page subscribes to it: the first render produced an `` with no token, the token arrived, and the re-render **changed the src**. The browser aborts the in-flight request and issues a second one — and with auth disabled no token is required, so *both* reached the backend and attached to the fan-out. The reporter's HAR shows it exactly: two requests to the same stream URL, same cache-buster, one without `token=` and one with. His backend log shows the consequence, `subscribers=2`, on a printer that allows one connection. The src is now rendered only once the token query has settled — one URL, one request, one viewer — and an auth-disabled install whose token endpoint fails still streams, because it never needed a token. +- **A viewer that left during a black stream stayed counted for 30 seconds (#2521)** — Also found on the way. A subscriber only checked whether its client was still connected *after* it had yielded a frame, or when a 30-second idle timeout fired. So a browser that walked away while the stream was producing nothing — the exact situation above — went on being counted as an attached viewer for up to half a minute. That matters beyond tidiness: `/camera/stop` consults the subscriber count to decide whether to tear the upstream down, so a phantom viewer could make it skip the teardown entirely and leave the socket open. Disconnects are now noticed within a second even when no frames are flowing. - **"Please login." when importing from MakerWorld — while Bambuddy said you were connected to Bambu Cloud** — An expired Bambu Cloud token was indistinguishable from a working one, so the UI reported "Connected as ..." indefinitely while every cloud call was being rejected. The toast you got was Bambu Lab's own words, forwarded verbatim: their 401 body is `{"code":4,"error":"Please login.","message":""}`, and we passed the `error` field straight through — which read as Bambuddy telling you to log in, next to an indicator saying you already were. **The status was never real.** `set_token()` stamped `token_expiry = now + 30 days` *every time a stored token was loaded from the database* — re-derived from the current moment, for a token of entirely unknown age — and `is_authenticated` was "we have a string, and we're not past that expiry". The expiry reset on every request, so the check could never fail. It was a string-presence test wearing an expiry costume, and `/cloud/status` answered `true` for as long as any token existed. Bambu's access token is opaque (no readable claims), Bambu's login response carries no expiry, and Bambuddy discards the `refreshToken` it is handed, so nothing else in the system knew either. When a token lapsed — Bambu's own comment in our code says they last around three months — **every** cloud feature died at once (MakerWorld imports, cloud profiles, slicer presets, firmware checks) with no signal anywhere that a re-login was needed. **Bambu is now the authority.** No expiry is invented. `/cloud/status` asks Bambu whether the token is still accepted, cached for five minutes so the several components polling it don't each pay a round-trip, and any 401 from any authenticated cloud call durably records the credential as dead — so the whole app agrees at once instead of each feature failing separately. An unreachable Bambu, a 5xx, or a Cloudflare challenge is treated as *unknown*, never as *expired*: an outage must not sign a working session out. The Profiles page now explains why the login form is back, MakerWorld says the sign-in expired rather than that one is required, and its import buttons stop pretending they can download. The user-facing message names the **Profiles** page, where the Bambu Cloud sign-in actually lives — the old fallback text pointed at "Settings → Bambu Cloud", which does not exist. - **Importing from MakerWorld failed on Windows with a certificate error (#2562)** — Paste a MakerWorld URL, click Save, and the import dies with `S3 download failed: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate`. Only native Windows installs are affected; Docker never sees it. The import walks several hosts, and the failure is at the last hop: Bambu Cloud answers the download request with an **AWS presigned URL**, and that one URL is fetched with `urllib` rather than httpx, on purpose — S3 signs the exact query-string bytes, and httpx re-encodes them into a `SignatureDoesNotMatch`. What that swap quietly also changed was the **trust store**. httpx — every other network call in Bambuddy, including the `api.bambulab.com` calls that succeed immediately before this one — verifies against the bundled `certifi` CA bundle. `urllib` verifies against the *operating system's* store, and on Windows the two disagree: Python's `ssl.load_default_certs()` only enumerates the roots already cached in the Windows ROOT store, which Windows fills in lazily through CryptoAPI's auto-update — a mechanism Python never triggers. On a machine where the Amazon root signing the S3 chain has not been cached yet, verification fails with exactly the error above. Linux images ship a complete `ca-certificates` bundle, so the OS store and certifi agree and the bug is invisible there. The S3 hop now verifies against certifi too, so it trusts precisely what the rest of the app already trusts. Verification itself is untouched — the certificate is still checked and the hostname still matched; the fix changes where the CA list comes from, not whether TLS is enforced. The URL still reaches the transport byte-for-byte, so the S3 signature is unaffected, and the no-redirect guard that keeps the download-host allowlist meaningful is unchanged. `certifi` is now an explicit requirement rather than one inherited from httpx, so a future httpx release cannot drop it out from under this import. - **Prints on a multi-printer farm started one by one, up to an hour apart (#2555, reporter @Maxtrim3D)** — Start a batch across several printers and they trickle out one at a time; the more printers, the worse it gets. Not a misconfiguration, and nothing in the wiki could have helped: the scheduler awaited each dispatch inline in its selection loop, and a dispatch includes the FTP upload. So every printer queued behind every other printer's transfer, even though they are entirely independent machines. **The arithmetic is the whole bug report.** A Bambu printer's FTP server sustains around 150 KB/s — its own SD-card write is the bottleneck, not the network — so the reporter's 41 MB `.3mf` took **254 seconds per printer**, straight from his logs (`40978500 bytes in 254.1s, 157 KB/s`). Nineteen printers in series is roughly **80 minutes** before the last one starts, which is exactly the "up to 1 hour" he reported, and exactly why it got worse the more printers he selected — the delay is linear in fleet size. The logs show the next upload beginning **131 ms** after the previous one finished, back to back, forever. **Uploads to different printers now run concurrently**, capped by a new **Settings → Workflow → Queue & Dispatch → Concurrent Uploads** value (default 4, up to 16; set it to 1 for the old strictly-serial behaviour if your network or host cannot take parallel transfers). Selection is unchanged and still sequential — only the transfers overlap — so every existing gate (busy printers, plate-clear, filament deficit, shortest-job-first, staggered start) behaves exactly as before, and a queue pass still finishes all of its uploads before the next one begins, which is what stops the same still-`pending` row being dispatched twice. FTP work also moves off asyncio's shared default executor onto its own pool: that executor is sized `min(32, cpu_count + 4)` — six threads on a 2-core NAS — and is shared with everything else in the app, so parallel uploads would have parked one thread each, for minutes at a time, and starved unrelated work. diff --git a/backend/app/services/camera_fanout.py b/backend/app/services/camera_fanout.py index 6ca1de7c7..d38f3071d 100644 --- a/backend/app/services/camera_fanout.py +++ b/backend/app/services/camera_fanout.py @@ -40,6 +40,13 @@ _SUBSCRIBER_QUEUE_SIZE = 4 # subscriber's read loop can break out cleanly instead of hanging on get(). _UPSTREAM_GONE = b"" +# How often a subscriber that isn't receiving frames re-checks whether its +# client is still connected. Only pays a cost when the stream is *not* producing +# frames — the normal path returns from queue.get() as soon as a frame lands and +# checks after the yield. Kept short because the subscriber count derived from +# it is what /camera/stop uses to decide whether to tear the upstream down. +_DISCONNECT_POLL_SECONDS = 1.0 + UpstreamFactory = Callable[[asyncio.Event], AsyncGenerator[bytes, None]] @@ -279,11 +286,30 @@ async def get_or_create_broadcaster(key: str, factory: UpstreamFactory) -> Mjpeg async def shutdown_broadcaster(key: str) -> bool: - """Force-shutdown the broadcaster for `key`. Returns True if one was running.""" + """Force-shutdown the broadcaster for `key`. Returns True if one was running. + + The stopped broadcaster stays in the registry on purpose. It used to be + popped *before* ``force_shutdown()`` was awaited, which vacated the slot + while the upstream socket was still closing: a ``/camera/stream`` request + landing in that window found nothing, minted a broadcaster with + ``predecessor=None``, and dialled the printer immediately. That is exactly + the two-sockets-at-once overlap the predecessor gate exists to prevent — + the gate only engages when the stopped broadcaster is still *findable*, and + popping it here bypassed the gate in the one case it was written for. A page + reload fires ``/camera/stop`` and the new stream request concurrently, so a + single-connection cam (chamber-image port 6000) ended up with an orphaned + socket that the printer kept feeding, starving the live viewer until the + printer's TCP keepalive reaped it ~20 min later (#2521). + + Leaving it in place is safe: ``get_or_create_broadcaster`` replaces a stopped + entry (chaining the successor behind its teardown), ``get_subscriber_count`` + reports 0 for it, and ``active_broadcaster_keys`` filters it out. There is at + most one entry per printer, and it is overwritten by the next viewer. + """ async with _registry_lock: - bc = _broadcasters.pop(key, None) - if bc is None: - return False + bc = _broadcasters.get(key) + if bc is None or bc.stopped: + return False await bc.force_shutdown() return True @@ -338,10 +364,16 @@ async def iter_subscriber( try: while True: try: - chunk = await asyncio.wait_for(queue.get(), timeout=30.0) + chunk = await asyncio.wait_for(queue.get(), timeout=_DISCONNECT_POLL_SECONDS) except asyncio.TimeoutError: - # No frame in 30s — check whether the client is still there. - # If yes, keep waiting; if no, bail out. + # No frame this tick — is the client still there? This used to + # wait 30 s before asking, and the disconnect check after a yield + # only fires when frames are actually flowing. So a viewer that + # went away while the stream was black stayed *counted* as a + # subscriber for up to half a minute — and ``/camera/stop`` + # trusts that count to decide whether to tear the upstream down, + # so a phantom subscriber could make it skip teardown entirely + # (#2521). Poll often enough that the count means something. if is_disconnected is not None and await is_disconnected(): break continue diff --git a/backend/tests/unit/services/test_camera_fanout.py b/backend/tests/unit/services/test_camera_fanout.py index bb4c39d1a..a34758bda 100644 --- a/backend/tests/unit/services/test_camera_fanout.py +++ b/backend/tests/unit/services/test_camera_fanout.py @@ -445,3 +445,142 @@ async def test_successor_pump_times_out_if_predecessor_wedges(monkeypatch): # After the bounded wait elapses the pump dials and delivers a frame. assert await asyncio.wait_for(queue.get(), timeout=1.0) == b"x" await shutdown_broadcaster("p1") + + +# --------------------------------------------------------------------------- +# The printer only has ONE camera socket (#2521) +# --------------------------------------------------------------------------- + + +def _socket_counting_factory(state: dict, *, close_delay: float = 0.05): + """Upstream factory that models a real TCP socket to the printer. + + Records the peak number of simultaneously-open sockets. A chamber-image cam + (P1/A1, port 6000) accepts exactly one connection: when a second overlaps, + the printer keeps feeding the first and the newcomer never sees a frame — + until the printer's TCP keepalive reaps the orphan, ~20 minutes later. + """ + + async def factory(disconnect: asyncio.Event) -> AsyncGenerator[bytes, None]: + await asyncio.sleep(0.01) # dial + TLS handshake + state["open"] += 1 + state["peak"] = max(state["peak"], state["open"]) + try: + while not disconnect.is_set(): + await asyncio.sleep(0.01) + yield b"frame" + finally: + await asyncio.sleep(close_delay) # TCP close is not instantaneous + state["open"] -= 1 + + return factory + + +async def test_stop_then_restream_never_opens_two_sockets(): + """A page reload fires POST /camera/stop and GET /camera/stream at the same + time. ``shutdown_broadcaster`` used to *pop* the broadcaster out of the + registry and only then await its teardown, so a stream request landing in + that window found an empty slot, minted a broadcaster with no predecessor, + and dialled the printer while the old socket was still closing (#2521). + """ + state = {"open": 0, "peak": 0} + factory = _socket_counting_factory(state) + + bc1 = await get_or_create_broadcaster("p1", factory) + queue = await bc1.subscribe() + assert await asyncio.wait_for(queue.get(), timeout=1.0) == b"frame" + await bc1.unsubscribe(queue) + + async def viewer_unmount_stop(): + await shutdown_broadcaster("p1") + + async def reloaded_page_streams(): + await asyncio.sleep(0.005) # lands a hair after the stop + bc = await get_or_create_broadcaster("p1", factory) + q = await bc.subscribe() + return await asyncio.wait_for(q.get(), timeout=2.0) + + _stop_result, frame = await asyncio.gather(viewer_unmount_stop(), reloaded_page_streams()) + + assert frame == b"frame", "the reloaded page's viewer never received a frame" + assert state["peak"] == 1, ( + f"opened {state['peak']} concurrent sockets to a printer that allows one — " + "the new stream dialled before the old socket closed" + ) + await shutdown_broadcaster("p1") + + +async def test_shutdown_broadcaster_leaves_a_chainable_predecessor(): + """The stopped broadcaster must stay findable in the registry: that is what + lets the next viewer's pump chain behind its socket close.""" + state = {"open": 0, "peak": 0} + factory = _socket_counting_factory(state) + + bc1 = await get_or_create_broadcaster("p1", factory) + await bc1.subscribe() + await shutdown_broadcaster("p1") + + assert camera_fanout._broadcasters.get("p1") is bc1, ( # noqa: SLF001 + "the stopped broadcaster was removed from the registry — a successor " + "created now would have predecessor=None and dial immediately" + ) + bc2 = await get_or_create_broadcaster("p1", factory) + assert bc2._predecessor is bc1 # noqa: SLF001 — white-box: the chain is the fix + await shutdown_broadcaster("p1") + + +async def test_shutdown_broadcaster_is_idempotent(): + """/camera/stop can fire twice (unmount + beforeunload). The second call + must report nothing was running rather than tearing down a live successor.""" + factory = _make_factory([b"x"] * 1000, delay=0.02) + bc = await get_or_create_broadcaster("p1", factory) + await bc.subscribe() + + assert await shutdown_broadcaster("p1") is True + assert await shutdown_broadcaster("p1") is False + assert await shutdown_broadcaster("never-existed") is False + + +async def test_stopped_broadcaster_reports_no_subscribers(): + """/camera/stop's reference-count guard must not see the corpse's leftovers.""" + from backend.app.services.camera_fanout import get_subscriber_count + + factory = _make_factory([b"x"] * 1000, delay=0.02) + bc = await get_or_create_broadcaster("p1", factory) + await bc.subscribe() + assert get_subscriber_count("p1") == 1 + + await shutdown_broadcaster("p1") + assert get_subscriber_count("p1") == 0, "a stopped broadcaster still reported subscribers" + + +async def test_subscriber_with_no_frames_detaches_promptly(): + """A viewer that goes away while the stream is black must stop being counted. + + The disconnect check only ran after a chunk was yielded, or on a 30 s idle + timeout — so a client that left during a black stream stayed *counted* as a + subscriber for up to half a minute. /camera/stop trusts that count to decide + whether to tear the upstream down, so a phantom subscriber could make it + skip teardown entirely (#2521). + """ + + async def silent_factory(disconnect: asyncio.Event) -> AsyncGenerator[bytes, None]: + await disconnect.wait() # connected, but the printer sends nothing + return + yield # pragma: no cover — makes this an async generator + + bc = MjpegBroadcaster("p1", silent_factory) + queue = await bc.subscribe() + assert bc.subscriber_count == 1 + + async def is_disconnected() -> bool: + return True # the browser aborted the request + + async def drain(): + async for _chunk in iter_subscriber(bc, queue, is_disconnected=is_disconnected): + pass + + # Must notice well inside the old 30 s idle timeout. + await asyncio.wait_for(drain(), timeout=3.0) + assert bc.subscriber_count == 0 + await bc.force_shutdown() diff --git a/frontend/src/__tests__/pages/CameraPage.test.tsx b/frontend/src/__tests__/pages/CameraPage.test.tsx index 74034ec43..e3b006083 100644 --- a/frontend/src/__tests__/pages/CameraPage.test.tsx +++ b/frontend/src/__tests__/pages/CameraPage.test.tsx @@ -177,13 +177,58 @@ describe('CameraPage', () => { }); }); - it('renders image src immediately when auth is disabled (no token required)', async () => { + it('does not fire a tokenless stream request when auth is disabled (#2521)', async () => { + // The stream-token query runs whether or not auth is enabled, and this page + // subscribes to it. So the src used to be rendered on the first pass with no + // token, and swapped once the token landed. Changing img.src makes the + // browser abort the in-flight request and issue a second one — and with auth + // disabled no token is required, so BOTH reached the backend and attached to + // the camera fan-out. Every page load put two viewers on a printer that + // allows one socket, then abandoned one of them. + let resolveToken!: () => void; + const gate = new Promise((resolve) => { + resolveToken = resolve; + }); + + server.use( + http.post('*/api/v1/printers/camera/stream-token', async () => { + await gate; + return HttpResponse.json({ token: 'tok-xyz' }); + }) + ); + + renderCameraPage(1); + await waitFor(() => { + expect(screen.getByText('X1 Carbon')).toBeInTheDocument(); + }); + + // Token still in flight: the must not already be pulling the stream. + const early = (document.querySelector('img') as HTMLImageElement | null)?.getAttribute('src') || ''; + expect(early).not.toContain('/camera/stream'); + + resolveToken(); + + // The first — and only — stream URL the browser ever sees is the tokened one. + await waitFor(() => { + const src = (document.querySelector('img') as HTMLImageElement | null)?.getAttribute('src') || ''; + expect(src).toContain('/api/v1/printers/1/camera/stream'); + expect(src).toContain('token=tok-xyz'); + }); + }); + + it('still streams when auth is disabled and the token endpoint fails', async () => { + // Waiting for the token must not become a way to never render at all: an + // auth-disabled backend doesn't need one. Once the query settles — even + // unsuccessfully — the stream loads. + server.use( + http.post('*/api/v1/printers/camera/stream-token', () => new HttpResponse(null, { status: 500 })) + ); + renderCameraPage(1); await waitFor(() => { const src = (document.querySelector('img') as HTMLImageElement | null)?.getAttribute('src') || ''; - expect(src).toContain(`/api/v1/printers/1/camera/stream`); - expect(src).not.toContain('token='); + expect(src).toContain('/api/v1/printers/1/camera/stream'); }); }); }); diff --git a/frontend/src/pages/CameraPage.tsx b/frontend/src/pages/CameraPage.tsx index e17d86f4a..364ad98c4 100644 --- a/frontend/src/pages/CameraPage.tsx +++ b/frontend/src/pages/CameraPage.tsx @@ -31,7 +31,7 @@ export function CameraPage() { // arrives. useStreamTokenSync (mounted in App) already owns the fetch; this // useQuery call dedupes via the shared key and just reads the cached value. useStreamTokenSync(); - const { data: streamTokenData } = useQuery({ + const { data: streamTokenData, isPending: streamTokenPending } = useQuery({ queryKey: ['camera-stream-token', user?.id ?? null], queryFn: () => api.getCameraStreamToken(), enabled: authEnabled ? !!user : true, @@ -617,7 +617,17 @@ export function CameraPage() { // the token directly from the reactive query value instead of relying on the // module-level cache in withStreamToken(), because that cache is updated in a // useEffect that runs after render. - const waitingForStreamToken = authEnabled && !streamTokenValue; + // + // We also wait when auth is *disabled* (#2521). The token query runs either + // way, and this page subscribes to it — so the first render produced a src + // with no token, the token landed, and the re-render CHANGED img.src. The + // browser aborts the in-flight request and issues a second one. With auth off + // no token is required, so *both* reached the backend and attached to the + // fan-out: every page load added two viewers and abandoned one of them. Wait + // for the query to settle and there is one src, one request, one viewer. + // Falling through once it has settled without a token keeps an auth-disabled + // install working even if the token endpoint fails — it doesn't need one. + const waitingForStreamToken = !streamTokenValue && (authEnabled || streamTokenPending); const appendToken = (url: string) => streamTokenValue ? `${url}&token=${encodeURIComponent(streamTokenValue)}` : withStreamToken(url); const currentUrl = transitioning || waitingForStreamToken diff --git a/static/assets/index-B_yurhVI.js b/static/assets/index-C-4pTpBI.js similarity index 99% rename from static/assets/index-B_yurhVI.js rename to static/assets/index-C-4pTpBI.js index 963894157..8783b7b85 100644 --- a/static/assets/index-B_yurhVI.js +++ b/static/assets/index-C-4pTpBI.js @@ -8746,7 +8746,7 @@ ${t.slice(l+2)}`,d+=1;else break}t.push({indent:l,number:parseInt(s,10),content: `))+1))}let o=`#`.repeat(i),s=n.enter(`headingAtx`),c=n.enter(`phrasing`);a.move(o+` `);let l=n.containerPhrasing(e,{before:`# `,after:` `,...a.current()});return/^[\t ]/.test(l)&&(l=M7(l.charCodeAt(0))+l.slice(1)),l=l?o+` `+l:o,n.options.closeAtx&&(l+=` `+o),c(),s(),l}F7.peek=SYe;function F7(e){return e.value||``}function SYe(){return`<`}I7.peek=CYe;function I7(e,t,n,r){let i=j7(n),a=i===`"`?`Quote`:`Apostrophe`,o=n.enter(`image`),s=n.enter(`label`),c=n.createTracker(r),l=c.move(`![`);return l+=c.move(n.safe(e.alt,{before:l,after:`]`,...c.current()})),l+=c.move(`](`),s(),!e.url&&e.title||/[\0- \u007F]/.test(e.url)?(s=n.enter(`destinationLiteral`),l+=c.move(`<`),l+=c.move(n.safe(e.url,{before:l,after:`>`,...c.current()})),l+=c.move(`>`)):(s=n.enter(`destinationRaw`),l+=c.move(n.safe(e.url,{before:l,after:e.title?` `:`)`,...c.current()}))),s(),e.title&&(s=n.enter(`title${a}`),l+=c.move(` `+i),l+=c.move(n.safe(e.title,{before:l,after:i,...c.current()})),l+=c.move(i),s()),l+=c.move(`)`),o(),l}function CYe(){return`!`}L7.peek=wYe;function L7(e,t,n,r){let i=e.referenceType,a=n.enter(`imageReference`),o=n.enter(`label`),s=n.createTracker(r),c=s.move(`![`),l=n.safe(e.alt,{before:c,after:`]`,...s.current()});c+=s.move(l+`][`),o();let u=n.stack;n.stack=[],o=n.enter(`reference`);let d=n.safe(n.associationId(e),{before:c,after:`]`,...s.current()});return o(),n.stack=u,a(),i===`full`||!l||l!==d?c+=s.move(d+`]`):i===`shortcut`?c=c.slice(0,-1):c+=s.move(`]`),c}function wYe(){return`!`}R7.peek=TYe;function R7(e,t,n){let r=e.value||``,i="`",a=-1;for(;RegExp("(^|[^`])"+i+"([^`]|$)").test(r);)i+="`";for(/[^ \r\n]/.test(r)&&(/^[ \r\n]/.test(r)&&/[ \r\n]$/.test(r)||/^`|`$/.test(r))&&(r=` `+r+` `);++a\u007F]/.test(e.url))}B7.peek=EYe;function B7(e,t,n,r){let i=j7(n),a=i===`"`?`Quote`:`Apostrophe`,o=n.createTracker(r),s,c;if(z7(e,n)){let t=n.stack;n.stack=[],s=n.enter(`autolink`);let r=o.move(`<`);return r+=o.move(n.containerPhrasing(e,{before:r,after:`>`,...o.current()})),r+=o.move(`>`),s(),n.stack=t,r}s=n.enter(`link`),c=n.enter(`label`);let l=o.move(`[`);return l+=o.move(n.containerPhrasing(e,{before:l,after:`](`,...o.current()})),l+=o.move(`](`),c(),!e.url&&e.title||/[\0- \u007F]/.test(e.url)?(c=n.enter(`destinationLiteral`),l+=o.move(`<`),l+=o.move(n.safe(e.url,{before:l,after:`>`,...o.current()})),l+=o.move(`>`)):(c=n.enter(`destinationRaw`),l+=o.move(n.safe(e.url,{before:l,after:e.title?` `:`)`,...o.current()}))),c(),e.title&&(c=n.enter(`title${a}`),l+=o.move(` `+i),l+=o.move(n.safe(e.title,{before:l,after:i,...o.current()})),l+=o.move(i),c()),l+=o.move(`)`),s(),l}function EYe(e,t,n){return z7(e,n)?`<`:`[`}V7.peek=DYe;function V7(e,t,n,r){let i=e.referenceType,a=n.enter(`linkReference`),o=n.enter(`label`),s=n.createTracker(r),c=s.move(`[`),l=n.containerPhrasing(e,{before:c,after:`]`,...s.current()});c+=s.move(l+`][`),o();let u=n.stack;n.stack=[],o=n.enter(`reference`);let d=n.safe(n.associationId(e),{before:c,after:`]`,...s.current()});return o(),n.stack=u,a(),i===`full`||!l||l!==d?c+=s.move(d+`]`):i===`shortcut`?c=c.slice(0,-1):c+=s.move(`]`),c}function DYe(){return`[`}function H7(e){let t=e.options.bullet||`*`;if(t!==`*`&&t!==`+`&&t!==`-`)throw Error("Cannot serialize items with `"+t+"` for `options.bullet`, expected `*`, `+`, or `-`");return t}function OYe(e){let t=H7(e),n=e.options.bulletOther;if(!n)return t===`*`?`-`:`*`;if(n!==`*`&&n!==`+`&&n!==`-`)throw Error("Cannot serialize items with `"+n+"` for `options.bulletOther`, expected `*`, `+`, or `-`");if(n===t)throw Error("Expected `bullet` (`"+t+"`) and `bulletOther` (`"+n+"`) to be different");return n}function kYe(e){let t=e.options.bulletOrdered||`.`;if(t!==`.`&&t!==`)`)throw Error("Cannot serialize items with `"+t+"` for `options.bulletOrdered`, expected `.` or `)`");return t}function U7(e){let t=e.options.rule||`*`;if(t!==`*`&&t!==`-`&&t!==`_`)throw Error("Cannot serialize rules with `"+t+"` for `options.rule`, expected `*`, `-`, or `_`");return t}function AYe(e,t,n,r){let i=n.enter(`list`),a=n.bulletCurrent,o=e.ordered?kYe(n):H7(n),s=e.ordered?o===`.`?`)`:`.`:OYe(n),c=t&&n.bulletLastUsed?o===n.bulletLastUsed:!1;if(!e.ordered){let t=e.children?e.children[0]:void 0;if((o===`*`||o===`-`)&&t&&(!t.children||!t.children[0])&&n.stack[n.stack.length-1]===`list`&&n.stack[n.stack.length-2]===`listItem`&&n.stack[n.stack.length-3]===`list`&&n.stack[n.stack.length-4]===`listItem`&&n.indexStack[n.indexStack.length-1]===0&&n.indexStack[n.indexStack.length-2]===0&&n.indexStack[n.indexStack.length-3]===0&&(c=!0),U7(n)===o&&t){let t=-1;for(;++t-1?t.start:1)+(n.options.incrementListMarker===!1?0:t.children.indexOf(e))+a);let o=a.length+1;(i===`tab`||i===`mixed`&&(t&&t.type===`list`&&t.spread||e.spread))&&(o=Math.ceil(o/4)*4);let s=n.createTracker(r);s.move(a+` `.repeat(o-a.length)),s.shift(o);let c=n.enter(`listItem`),l=n.indentLines(n.containerFlow(e,s.current()),u);return c(),l;function u(e,t,n){return t?(n?``:` `.repeat(o))+e:(n?a:a+` `.repeat(o-a.length))+e}}function NYe(e,t,n,r){let i=n.enter(`paragraph`),a=n.enter(`phrasing`),o=n.containerPhrasing(e,r);return a(),i(),o}var PYe=q5([`break`,`delete`,`emphasis`,`footnote`,`footnoteReference`,`image`,`imageReference`,`inlineCode`,`inlineMath`,`link`,`linkReference`,`mdxJsxTextElement`,`mdxTextExpression`,`strong`,`text`,`textDirective`]);function FYe(e,t,n,r){return(e.children.some(function(e){return PYe(e)})?n.containerPhrasing:n.containerFlow).call(n,e,r)}function IYe(e){let t=e.options.strong||`*`;if(t!==`*`&&t!==`_`)throw Error("Cannot serialize strong with `"+t+"` for `options.strong`, expected `*`, or `_`");return t}W7.peek=LYe;function W7(e,t,n,r){let i=IYe(n),a=n.enter(`strong`),o=n.createTracker(r),s=o.move(i+i),c=o.move(n.containerPhrasing(e,{after:i,before:s,...o.current()})),l=c.charCodeAt(0),u=N7(r.before.charCodeAt(r.before.length-1),l,i);u.inside&&(c=M7(l)+c.slice(1));let d=c.charCodeAt(c.length-1),f=N7(r.after.charCodeAt(0),d,i);f.inside&&(c=c.slice(0,-1)+M7(d));let p=o.move(i+i);return a(),n.attentionEncodeSurroundingInfo={after:f.outside,before:u.outside},s+c+p}function LYe(e,t,n){return n.options.strong||`*`}function RYe(e,t,n,r){return n.safe(e.value,r)}function zYe(e){let t=e.options.ruleRepetition||3;if(t<3)throw Error("Cannot serialize rules with repetition `"+t+"` for `options.ruleRepetition`, expected `3` or more");return t}function BYe(e,t,n){let r=(U7(n)+(n.options.ruleSpaces?` `:``)).repeat(zYe(n));return n.options.ruleSpaces?r.slice(0,-1):r}var G7={blockquote:lYe,break:A7,code:hYe,definition:_Ye,emphasis:P7,hardBreak:A7,heading:xYe,html:F7,image:I7,imageReference:L7,inlineCode:R7,link:B7,linkReference:V7,list:AYe,listItem:MYe,paragraph:NYe,root:FYe,strong:W7,text:RYe,thematicBreak:BYe};function VYe(){return{enter:{table:HYe,tableData:q7,tableHeader:q7,tableRow:WYe},exit:{codeText:GYe,table:UYe,tableData:K7,tableHeader:K7,tableRow:K7}}}function HYe(e){let t=e._align;this.enter({type:`table`,align:t.map(function(e){return e===`none`?null:e}),children:[]},e),this.data.inTable=!0}function UYe(e){this.exit(e),this.data.inTable=void 0}function WYe(e){this.enter({type:`tableRow`,children:[]},e)}function K7(e){this.exit(e)}function q7(e){this.enter({type:`tableCell`,children:[]},e)}function GYe(e){let t=this.resume();this.data.inTable&&(t=t.replace(/\\([\\|])/g,KYe));let n=this.stack[this.stack.length-1];n.type,n.value=t,this.exit(e)}function KYe(e,t){return t===`|`?t:e}function qYe(e){let t=e||{},n=t.tableCellPadding,r=t.tablePipeAlign,i=t.stringLength,a=n?` `:`|`;return{unsafe:[{character:`\r`,inConstruct:`tableCell`},{character:` `,inConstruct:`tableCell`},{atBreak:!0,character:`|`,after:`[ :-]`},{character:`|`,inConstruct:`tableCell`},{atBreak:!0,character:`:`,after:`-`},{atBreak:!0,character:`-`,after:`[:|-]`}],handlers:{inlineCode:f,table:o,tableCell:c,tableRow:s}};function o(e,t,n,r){return l(u(e,n,r),e.align)}function s(e,t,n,r){let i=l([d(e,n,r)]);return i.slice(0,i.indexOf(` -`))}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 sYe(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 dXe={tokenize:yXe,partial:!0};function fXe(){return{document:{91:{name:`gfmFootnoteDefinition`,tokenize:gXe,continuation:{tokenize:_Xe},exit:vXe}},text:{91:{name:`gfmFootnoteCall`,tokenize:hXe},93:{name:`gfmPotentialFootnoteCall`,add:`after`,tokenize:pXe,resolveTo:mXe}}}}function pXe(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=W8(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 mXe(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 hXe(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||X8(s))return n(s);if(s===93){e.exit(`chunkString`);let a=e.exit(`gfmFootnoteCallString`);return i.includes(W8(r.sliceSerialize(a)))?(e.enter(`gfmFootnoteCallLabelMarker`),e.consume(s),e.exit(`gfmFootnoteCallLabelMarker`),e.exit(`gfmFootnoteCall`),t):n(s)}return X8(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 gXe(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||X8(t))return n(t);if(t===93){e.exit(`chunkString`);let n=e.exit(`gfmFootnoteDefinitionLabelString`);return a=W8(r.sliceSerialize(n)),e.enter(`gfmFootnoteDefinitionLabelMarker`),e.consume(t),e.exit(`gfmFootnoteDefinitionLabelMarker`),e.exit(`gfmFootnoteDefinitionLabel`),f}return X8(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),n5(e,p,`gfmFootnoteDefinitionWhitespace`)):n(t)}function p(e){return t(e)}}function _Xe(e,t,n){return e.check(c5,t,e.attempt(dXe,t,n))}function vXe(e){e.exit(`gfmFootnoteDefinition`)}function yXe(e,t,n){let r=this;return n5(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 bXe(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=i5(a);return l._open=!u||u===2&&!!s,l._close=!s||s===2&&!!u,n(a)}}}var xXe=class{constructor(){this.map=[]}add(e,t,n){SXe(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 SXe(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):Y8(t)?a>1?(a=0,r.interrupt=!0,e.exit(`tableRow`),e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),p):n(t):Z8(t)?n5(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||X8(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,Z8(t)?n5(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 Z8(t)?n5(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||Y8(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 Z8(t)?n5(e,b,`whitespace`)(t):b(t)}function b(n){return n===124?m(n):n===null||Y8(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||Y8(n)?(e.exit(`tableRow`),t(n)):Z8(n)?n5(e,C,`whitespace`)(n):(e.enter(`data`),w(n))}function w(t){return t===null||t===124||X8(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 EXe(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 xXe;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({},u9(t.events,i)),e.add(i,0,[[`exit`,a,t]]),a=void 0),a}function l9(e,t,n,r,i){let a=[],o=u9(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 u9(e,t){let n=e[t],r=n[0]===`enter`?`start`:`end`;return n[1][r]}var DXe={name:`tasklistCheck`,tokenize:kXe};function OXe(){return{text:{91:DXe}}}function kXe(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 X8(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 Y8(r)?t(r):Z8(r)?e.check({tokenize:AXe},t,n)(r):n(r)}}function AXe(e,t,n){return n5(e,r,`whitespace`);function r(e){return e===null?n(e):t(e)}}function jXe(e){return H8([nXe(),fXe(),bXe(e),wXe(),OXe()])}var MXe={};function NXe(e){let t=this,n=e||MXe,r=t.data(),i=r.micromarkExtensions||=[],a=r.fromMarkdownExtensions||=[],o=r.toMarkdownExtensions||=[];i.push(jXe(n)),a.push(QYe()),o.push($Ye(n))}var d9=`fileManager.readmeCollapsed`;function PXe({folderId:e}){let{t}=W(),[n,r]=(0,y.useState)(()=>localStorage.getItem(d9)===`1`);(0,y.useEffect)(()=>{localStorage.setItem(d9,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)(nc,{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)(_l,{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)(_l,{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)(nc,{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)(gl,{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)(bJe,{remarkPlugins:[NXe],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 FXe({open:e,onClose:t,onPickTag:n}){let{t:r}=W(),i=no(),{showToast:a}=jd(),[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:W6,queryFn:Q.getLibraryTags,enabled:e}),g=()=>{i.invalidateQueries({queryKey:W6}),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)(hu,{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)(Tl,{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)(Wu,{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)(xl,{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)(Cu,{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)(zd,{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 IXe=90;function LXe({onClose:e}){let{t}=W(),n=no(),{showToast:r}=jd(),[i,a]=(0,y.useState)(IXe),[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)(Cu,{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)(Wu,{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:kd(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)(Eu,{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 RXe({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 zXe({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)(uc,{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 BXe=`<>:"/\\|?*`;function VXe(e){for(let t of e)if(BXe.includes(t)||t.charCodeAt(0)<32)return t;return null}function HXe({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`?VXe(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 UXe({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)(cc,{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 WXe({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)(Vc,{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)(Wu,{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)(Go,{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)(Oo,{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)(Qs,{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)(ku,{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 f9({folder:e,selectedFolderId:t,onSelect:n,onDelete:r,onLink:i,onRename:a,depth:o=0,wrapNames:s=!1,defaultExpanded:c=!0,hasPermission:l,t:u}){let[d,f]=(0,y.useState)(c),[p,m]=(0,y.useState)(!1),h=e.children.length>0,g=e.project_id||e.archive_id,_=e.is_external;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:[h?(0,K.jsx)(`button`,{onClick:e=>{e.stopPropagation(),f(!d)},className:`p-0.5 hover:bg-bambu-dark-tertiary rounded`,children:(0,K.jsx)(is,{className:`w-3.5 h-3.5 transition-transform ${d?`rotate-90`:``}`})}):(0,K.jsx)(`div`,{className:`w-4.5`}),_?(0,K.jsx)(uc,{className:`w-4 h-4 text-purple-600 dark:text-purple-400 flex-shrink-0`}):(0,K.jsx)(cc,{className:`w-4 h-4 text-bambu-green flex-shrink-0`}),(0,K.jsx)(`span`,{className:`text-sm flex-1 min-w-0 ${s?`break-all`:`truncate`}`,title:e.name,children:e.name}),g&&(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)(Vc,{className:`w-3 h-3`}),e.project_name?(0,K.jsx)(Go,{className:`w-3 h-3`}):(0,K.jsx)(Oo,{className:`w-3 h-3`})]}),_&&e.external_readonly&&(0,K.jsx)(`span`,{title:u(`fileManager.readOnly`),children:(0,K.jsx)(qc,{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}),!g&&!_&&(0,K.jsx)(`button`,{onClick:t=>{t.stopPropagation(),i(e)},className:`flex-shrink-0 p-1 rounded hover:bg-bambu-dark-tertiary`,title:u(`fileManager.linkToProjectOrArchive`),children:(0,K.jsx)(Vc,{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:()=>m(!p),className:`p-1 rounded hover:bg-bambu-dark-tertiary`,children:(0,K.jsx)(Ws,{className:`w-3.5 h-3.5 text-bambu-gray`})}),p&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>m(!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 ${l(`library:update_all`)?`text-white hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{l(`library:update_all`)&&(a(e),m(!1))},disabled:!l(`library:update_all`),title:l(`library:update_all`)?void 0:u(`fileManager.noPermissionRenameFolder`),children:[(0,K.jsx)(xl,{className:`w-3.5 h-3.5`}),u(`common.rename`)]}),(0,K.jsxs)(`button`,{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${l(`library:update_all`)?`text-white hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{l(`library:update_all`)&&(i(e),m(!1))},disabled:!l(`library:update_all`),title:l(`library:update_all`)?void 0:u(`fileManager.noPermissionLinkFolder`),children:[(0,K.jsx)(Vc,{className:`w-3.5 h-3.5`}),u(g?`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 ${l(`library:delete_all`)?`text-red-700 dark:text-red-400 hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{l(`library:delete_all`)&&(r(e.id),m(!1))},disabled:!l(`library:delete_all`),title:l(`library:delete_all`)?void 0:u(`fileManager.noPermissionDeleteFolder`),children:[(0,K.jsx)(Cu,{className:`w-3.5 h-3.5`}),u(`common.delete`)]})]})]})]})})]}),h&&d&&(0,K.jsx)(`div`,{children:e.children.map(e=>(0,K.jsx)(f9,{folder:e,selectedFolderId:t,onSelect:n,onDelete:r,onLink:i,onRename:a,depth:o+1,wrapNames:s,defaultExpanded:c,hasPermission:l,t:u},e.id))})]})}function p9(e){let t=e.toLowerCase();return t.endsWith(`.gcode`)||t.endsWith(`.gcode.3mf`)}function m9(e){let t=e.toLowerCase();return t.endsWith(`.gcode`)||t.endsWith(`.gcode.3mf`)?!1:t.endsWith(`.stl`)||t.endsWith(`.3mf`)||t.endsWith(`.step`)||t.endsWith(`.stp`)}function GXe({file:e,isSelected:t,isMobile:n,onSelect:r,onDelete:i,onDownload:a,onPrint:o,onSlice:s,onRunPipeline:c,useSlicerApi:l,onPreview3d:u,onRename:d,onGenerateThumbnail:f,onTagClick:p,thumbnailVersion:m,hasPermission:h,canModify:g,authEnabled:_,t:v}){let[b,x]=(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)}${m?(Q.getLibraryFileThumbnailUrl(e.id).includes(`?`)?`&`:`?`)+`v=${m}`:``}`,alt:e.filename,className:`w-full h-full object-cover`}):(0,K.jsx)(Qs,{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:kd(e.file_size)}),e.print_time_seconds&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(xs,{className:`w-3 h-3`}),Pf(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)(Ol,{className:`w-3 h-3`}),e.sliced_for_model]}),e.print_count>0&&(0,K.jsx)(`div`,{className:`mt-1 text-xs text-bambu-green`,children:v(`fileManager.printedCount`,{count:e.print_count})}),_&&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)(ju,{className:`w-3 h-3`}),e.created_by_username]}),(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:()=>p?.(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)(hu,{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:()=>x(!b),className:`p-1.5 rounded bg-bambu-dark-secondary/90 hover:bg-bambu-dark-tertiary`,children:(0,K.jsx)(Ws,{className:`w-4 h-4 text-bambu-gray`})}),b&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>x(!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&&p9(e.filename)&&(0,K.jsxs)(`button`,{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${h(`queue:create`)?`text-bambu-green hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{h(`queue:create`)&&(o(e),x(!1))},disabled:!h(`queue:create`),title:h(`queue:create`)?void 0:v(`fileManager.noPermissionAddToQueue`),children:[(0,K.jsx)(Ol,{className:`w-3.5 h-3.5`}),v(`common.print`)]}),s&&l&&m9(e.filename)&&(0,K.jsxs)(`button`,{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${h(`library:upload`)?`text-white hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{h(`library:upload`)&&(s(e),x(!1))},disabled:!h(`library:upload`),title:h(`library:upload`)?void 0:v(`fileManager.noPermissionSlice`),children:[(0,K.jsx)(ks,{className:`w-3.5 h-3.5`}),v(`slice.action`)]}),c&&l&&m9(e.filename)&&(0,K.jsxs)(`button`,{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${h(`pipelines:run`)?`text-white hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{h(`pipelines:run`)&&(c(e),x(!1))},disabled:!h(`pipelines:run`),title:h(`pipelines:run`)?void 0:v(`library.runWithPipeline.noPermission`),children:[(0,K.jsx)(Cl,{className:`w-3.5 h-3.5`}),v(`library.runWithPipeline.actionLabel`)]}),u&&(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 ${h(`library:read`)?`text-white hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{h(`library:read`)&&(u(e),x(!1))},disabled:!h(`library:read`),title:h(`library:read`)?void 0:`You do not have permission to preview files`,children:[(0,K.jsx)(Wo,{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 ${h(`library:read`)?`text-white hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{h(`library:read`)&&(a(e.id),x(!1))},disabled:!h(`library:read`),title:h(`library:read`)?void 0:v(`fileManager.noPermissionDownload`),children:[(0,K.jsx)(Vs,{className:`w-3.5 h-3.5`}),v(`common.download`)]}),d&&(0,K.jsxs)(`button`,{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${g(`library`,`update`,e.created_by_id)?`text-white hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{g(`library`,`update`,e.created_by_id)&&(d(e),x(!1))},disabled:!g(`library`,`update`,e.created_by_id),title:g(`library`,`update`,e.created_by_id)?void 0:v(`fileManager.noPermissionRenameFile`),children:[(0,K.jsx)(xl,{className:`w-3.5 h-3.5`}),v(`common.rename`)]}),f&&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 ${g(`library`,`update`,e.created_by_id)?`text-white hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{g(`library`,`update`,e.created_by_id)&&(f(e),x(!1))},disabled:!g(`library`,`update`,e.created_by_id),title:g(`library`,`update`,e.created_by_id)?void 0:v(`fileManager.noPermissionGenerateThumbnail`),children:[(0,K.jsx)(Mc,{className:`w-3.5 h-3.5`}),v(`fileManager.generateThumbnail`)]}),(0,K.jsxs)(`button`,{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${g(`library`,`delete`,e.created_by_id)?`text-red-700 dark:text-red-400 hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{g(`library`,`delete`,e.created_by_id)&&(i(e.id),x(!1))},disabled:!g(`library`,`delete`,e.created_by_id),title:g(`library`,`delete`,e.created_by_id)?void 0:v(`fileManager.noPermissionDeleteFile`),children:[(0,K.jsx)(Cu,{className:`w-3.5 h-3.5`}),v(`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 KXe(){let{t:e}=W(),t=no(),{showToast:n}=jd(),{hasPermission:r,hasAnyPermission:i,canModify:a,authEnabled:o}=_d(),[s]=Mi(),c=$n(),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,ne]=(0,y.useState)(null),[re,ie]=(0,y.useState)(null),[H,ae]=(0,y.useState)({}),[oe,U]=(0,y.useState)(null),[se,ce]=(0,y.useState)(()=>localStorage.getItem(`library-view-mode`)||`grid`),[le,ue]=(0,y.useState)(()=>localStorage.getItem(`library-wrap-folders`)===`true`),[de,fe]=(0,y.useState)(()=>localStorage.getItem(`library-collapse-folders`)===`true`),[pe,me]=(0,y.useState)(()=>localStorage.getItem(`library-folder-sort-field`)===`activity`?`activity`:`name`),[he,ge]=(0,y.useState)(()=>localStorage.getItem(`library-folder-sort-direction`)===`desc`?`desc`:`asc`),[_e,ve]=(0,y.useState)(()=>{let e=localStorage.getItem(`library-sidebar-width`);return e?parseInt(e,10):256}),[ye,be]=(0,y.useState)(!1),xe=(0,y.useRef)(null);(0,y.useEffect)(()=>{if(!ye)return;document.body.style.userSelect=`none`,document.body.style.cursor=`col-resize`;let e=e=>{if(!xe.current)return;let t=xe.current.parentElement?.getBoundingClientRect();if(!t)return;let n=e.clientX-t.left;ve(Math.min(500,Math.max(200,n)))},t=()=>{be(!1),document.body.style.userSelect=``,document.body.style.cursor=``,localStorage.setItem(`library-sidebar-width`,String(_e))};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=``}},[ye,_e]);let[Se,Ce]=(0,y.useState)(``),[we,Te]=(0,y.useState)(`all`),[Ee,De]=(0,y.useState)(``),[Oe,ke]=(0,y.useState)(()=>localStorage.getItem(`library-sort-field`)||`name`),[Ae,je]=(0,y.useState)(()=>localStorage.getItem(`library-sort-direction`)||`asc`),Me=YW();(0,y.useEffect)(()=>{let e=s.get(`folder`);e&&d(parseInt(e,10))},[s]);let{data:Ne}=q({queryKey:[`settings`],queryFn:()=>Q.getSettings()}),{data:Pe,isLoading:Fe}=q({queryKey:[`library-folders`],queryFn:()=>Q.getLibraryFolders()}),Ie=(0,y.useMemo)(()=>{if(!Pe)return Pe;let e=t=>[...t].sort((e,t)=>{let n=0;if(pe===`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 he===`asc`?n:-n}).map(t=>({...t,children:e(t.children)}));return e(Pe)},[Pe,pe,he]),{data:Le}=q({queryKey:[`library-trash-count`],queryFn:async()=>{try{return(await Q.listLibraryTrash(1,0)).total}catch{return 0}},staleTime:3e4}),Re=u!==null&&Se.trim().length>0,ze=(0,y.useMemo)(()=>[...N].sort((e,t)=>e-t),[N]),{data:Be=[]}=q({queryKey:[`library-tags`],queryFn:Q.getLibraryTags}),Ve=(0,y.useMemo)(()=>{let e=new Map;for(let t of Be)e.set(t.id,t.name);return e},[Be]);(0,y.useEffect)(()=>{Be.length!==0&&P(e=>{let t=e.filter(e=>Ve.has(e));return t.length===e.length?e:t})},[Be.length,Ve]);let He=(0,y.useCallback)(e=>{P(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},[]),{data:Ue,isLoading:We}=q({queryKey:[`library-files`,u,f,Re,ze],queryFn:()=>Q.getLibraryFiles(u,!1,void 0,u===null?f:void 0,Re,ze)}),{data:Ge}=q({queryKey:[`library-stats`],queryFn:()=>Q.getLibraryStats()}),{data:Ke}=q({queryKey:[`users`],queryFn:()=>Q.getUsers()}),qe=(0,y.useMemo)(()=>{if(!Ue)return[];let e=new Set(Ue.map(e=>e.file_type));return Array.from(e).sort()},[Ue]),Je=(0,y.useMemo)(()=>{if(!Ue)return[];let e=[...Ue];if(Se.trim()){let t=Se.toLowerCase();e=e.filter(e=>e.filename.toLowerCase().includes(t)||e.print_name&&e.print_name.toLowerCase().includes(t))}if(we!==`all`&&(e=e.filter(e=>e.file_type===we)),Ee.trim()){let t=Ee.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(Oe){case`name`:n=(e.print_name||e.filename).localeCompare(t.print_name||t.filename);break;case`date`:n=(kf(e.created_at)?.getTime()??0)-(kf(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 Ae===`asc`?n:-n}),e},[Ue,Se,we,Ee,Oe,Ae]),Ye=(0,y.useMemo)(()=>{if(!Ge||!Ne)return!1;let e=(Ne.library_disk_warning_gb||5)*1024*1024*1024;return Ge.disk_free_bytesQ.createLibraryFolder(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-folders`]}),_(!1),n(e(`fileManager.toast.folderCreated`),`success`)},onError:e=>n(e.message,`error`)}),Ze=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`)}),Qe=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`)}),$e=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`)}}),et=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`)}}),tt=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`)}}),nt=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`)}),rt=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`)}),it=J({mutationFn:({id:e,filename:t})=>Q.updateLibraryFile(e,{filename:t}),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-files`]}),ie(null),n(e(`fileManager.toast.fileRenamed`),`success`)},onError:e=>{ie(null),n(e.message,`error`)}}),at=J({mutationFn:({id:e,name:t})=>Q.updateLibraryFolder(e,{name:t}),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-files`]}),ie(null),n(e(`fileManager.toast.folderRenamed`),`success`)},onError:e=>{ie(null),n(e.message,`error`)}}),ot=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)}),ae(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`)}),st=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&&ae(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`)}),ct=(0,y.useCallback)(e=>{let t=e.toLowerCase();return t.endsWith(`.gcode`)||t.includes(`.gcode.`)},[]),lt=(0,y.useMemo)(()=>Ue?Ue.filter(e=>m.includes(e.id)&&ct(e.filename)):[],[Ue,m,ct]),ut=(0,y.useCallback)(e=>{h(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},[]),dt=(0,y.useCallback)(()=>{Je.length>0&&h(Je.map(e=>e.id))},[Je]),ft=(0,y.useCallback)(()=>{h([])},[]),pt=()=>{t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-stats`]})},{isDraggingOver:mt,dragHandlers:ht}=XW({disabled:!r(`library:upload`)||C,onFiles:e=>{E(e),w(!0)}}),gt=e=>{Q.downloadLibraryFile(e).catch(e=>{console.error(`Library file download failed:`,e)})},_t=()=>{L&&(L.type===`file`?et.mutate(L.id):L.type===`folder`?$e.mutate(L.id):L.type===`bulk`&&tt.mutate(m))},vt=$e.isPending||et.isPending||tt.isPending,yt=e=>{ce(e),localStorage.setItem(`library-view-mode`,e)},bt=Fe||We,xt=(0,y.useMemo)(()=>{if(!u||!Pe)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(Pe)},[u,Pe]);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`,...ht,children:[mt&&(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)(Au,{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)(cc,{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:()=>yt(`grid`),className:`p-1.5 rounded transition-colors ${se===`grid`?`bg-bambu-dark-secondary text-white`:`text-bambu-gray hover:text-white`}`,title:e(`fileManager.gridView`),children:(0,K.jsx)(zc,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>yt(`list`),className:`p-1.5 rounded transition-colors ${se===`list`?`bg-bambu-dark-secondary text-white`:`text-bambu-gray hover:text-white`}`,title:e(`fileManager.listView`),children:(0,K.jsx)(Gc,{className:`w-4 h-4`})})]}),(0,K.jsxs)($,{variant:`secondary`,onClick:()=>ot.mutate(),disabled:ot.isPending||!i(`library:update_own`,`library:update_all`),title:i(`library:update_own`,`library:update_all`)?e(`fileManager.generateThumbnailsForMissing`):e(`fileManager.noPermissionGenerateThumbnail`),children:[ot.isPending?(0,K.jsx)(X,{className:`w-4 h-4 mr-2 animate-spin`}):(0,K.jsx)(Mc,{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)(uc,{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)(lc,{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)(hu,{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)(Cu,{className:`w-4 h-4 mr-2`}),e(`libraryPurge.headerButton`)]}),i(`library:delete_own`,`library:delete_all`)&&(0,K.jsxs)(wi,{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)(Cu,{className:`w-4 h-4 mr-2`}),e(`libraryTrash.headerButton`),typeof Le==`number`&&Le>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:Le})]}),(0,K.jsxs)($,{onClick:()=>w(!0),disabled:!r(`library:upload`),title:r(`library:upload`)?void 0:e(`fileManager.noPermissionUpload`),children:[(0,K.jsx)(Au,{className:`w-4 h-4 mr-2`}),e(`common.upload`)]})]})]}),Ye&&Ge&&Ne&&(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)(Eu,{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:kd(Ge.disk_free_bytes),total:kd(Ge.disk_total_bytes),threshold:Ne.library_disk_warning_gb})})]})]}),Ge&&(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)(rc,{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:Ge.total_files})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,K.jsx)(cc,{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:Ge.total_folders})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,K.jsx)(wc,{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:kd(Ge.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 ${Ye?`text-amber-500`:`text-white`}`,children:kd(Ge.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`)]}),Pe?.some(e=>e.is_external)&&(0,K.jsxs)(`option`,{value:`__top:external`,children:[`🔗 `,e(`fileManager.allExternal`)]}),Ie&&(()=>{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(Ie).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:xe,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:`${_e}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 ${ye?`bg-bambu-green`:`hover:bg-bambu-green/50`}`,onMouseDown:e=>{e.preventDefault(),be(!0)},onDoubleClick:()=>{ve(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 ${ye?`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:pe,onChange:e=>{let t=e.target.value===`activity`?`activity`:`name`;me(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=he===`asc`?`desc`:`asc`;ge(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(he===`asc`?`fileManager.ascending`:`fileManager.descending`),"aria-label":e(he===`asc`?`fileManager.ascending`:`fileManager.descending`),children:he===`asc`?(0,K.jsx)(Fo,{className:`w-3.5 h-3.5`}):(0,K.jsx)(ko,{className:`w-3.5 h-3.5`})}),(0,K.jsx)(`button`,{onClick:()=>{let e=!de;fe(e),localStorage.setItem(`library-collapse-folders`,String(e))},className:`text-xs px-1.5 py-0.5 rounded transition-colors ${de?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:text-white hover:bg-bambu-dark`}`,title:e(de?`fileManager.expandFoldersByDefault`:`fileManager.collapseFoldersByDefault`),children:e(`fileManager.collapse`)}),(0,K.jsx)(`button`,{onClick:()=>{let e=!le;ue(e),localStorage.setItem(`library-wrap-folders`,String(e))},className:`text-xs px-1.5 py-0.5 rounded transition-colors ${le?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:text-white hover:bg-bambu-dark`}`,title:e(le?`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)(Qs,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{className:`text-sm`,children:e(`fileManager.allFiles`)})]}),Pe?.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)(uc,{className:`w-4 h-4 text-purple-600 dark:text-purple-400`}),(0,K.jsx)(`span`,{className:`text-sm`,children:e(`fileManager.allExternal`)})]}),Ie?.map(t=>(0,K.jsx)(f9,{folder:t,selectedFolderId:u,onSelect:d,onDelete:e=>R({type:`folder`,id:e}),onLink:I,onRename:e=>ie({type:`folder`,id:e.id,name:e.name}),wrapNames:le,defaultExpanded:!de,hasPermission:r,t:e},`${t.id}-${de?`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:[Be.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`)}),Be.map(e=>{let t=N.includes(e.id);return(0,K.jsxs)(`button`,{type:`button`,onClick:()=>He(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)(hu,{className:`w-3 h-3`}),(0,K.jsx)(`span`,{children:e.name}),t&&(0,K.jsx)(Wu,{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`)})]}),xt?.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)(uc,{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`)}),xt.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)(qc,{className:`w-3 h-3`}),e(`fileManager.readOnly`)]})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray truncate font-mono`,title:xt.external_path||``,children:xt.external_path})]}),(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:()=>u&&Qe.mutate(u),disabled:Qe.isPending,title:e(`fileManager.scanFolder`),children:[Qe.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(jl,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{className:`ml-1.5`,children:e(`fileManager.scanFolder`)})]})]}),Ue&&Ue.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)(Vl,{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:Se,onChange:e=>Ce(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`}),Re&&(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)(mc,{className:`w-4 h-4 text-bambu-gray hidden sm:block`}),(0,K.jsxs)(`select`,{value:we,onChange:e=>Te(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`)}),qe.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:Ee,onChange:e=>De(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 ${Ee?`pr-7`:``}`,style:Ee?{WebkitAppearance:`none`,MozAppearance:`textfield`}:void 0}),Ee&&(0,K.jsx)(`button`,{onClick:()=>De(``),className:`absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white z-10`,children:(0,K.jsx)(Wu,{className:`w-3 h-3`})}),(0,K.jsx)(`datalist`,{id:`usernames-list`,children:Ke?.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:Oe,onChange:e=>{let t=e.target.value;ke(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:()=>je(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(Ae===`asc`?`fileManager.ascending`:`fileManager.descending`),children:Ae===`asc`?(0,K.jsx)(Fo,{className:`w-4 h-4 text-white`}):(0,K.jsx)(ko,{className:`w-4 h-4 text-white`})})]}),(Se||we!==`all`||Ee)&&(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray hidden sm:inline`,children:e(`fileManager.resultsCount`,{showing:Je.length,total:Ue.length})})]}),Je.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===Je.length&&m.length>0?(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:ft,children:[(0,K.jsx)(lu,{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:dt,children:[(0,K.jsx)(su,{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:[lt.length===1&&(0,K.jsxs)($,{variant:`primary`,size:`sm`,onClick:()=>B(lt[0]),disabled:!r(`queue:create`),title:r(`queue:create`)?void 0:e(`fileManager.noPermissionAddToQueue`),children:[(0,K.jsx)(Ol,{className:`w-4 h-4 sm:mr-1`}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.print`)})]}),(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)(ll,{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)(hu,{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)(Cu,{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:ft,children:[(0,K.jsx)(Wu,{className:`w-4 h-4 sm:mr-1`}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.clear`)})]})]})]})]}),bt?(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`)})]})}):Ue?.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)(Qs,{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)(Tl,{className:`w-4 h-4 mr-2`}),e(`fileManager.uploadFiles`)]})]}):Je.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)(Vl,{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:()=>{Ce(``),Te(`all`)},children:e(`fileManager.clearFilters`)})]}):se===`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:Je.map(t=>(0,K.jsx)(GXe,{file:t,isSelected:m.includes(t.id),isMobile:Me,t:e,onSelect:ut,onDelete:e=>R({type:`file`,id:e}),onDownload:gt,onPrint:B,onSlice:ee,onRunPipeline:ne,useSlicerApi:Ne?.use_slicer_api??!1,onPreview3d:e=>{p9(e.filename)?c(`/gcode-viewer?library_file=${e.id}`):U(e)},onRename:e=>ie({type:`file`,id:e.id,name:e.filename}),onGenerateThumbnail:e=>st.mutate(e.id),onTagClick:He,thumbnailVersion:H[t.id],hasPermission:r,canModify:a,authEnabled:o},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`,{})]}),Je.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:()=>ut(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)}${H[t.id]?(Q.getLibraryFileThumbnailUrl(t.id).includes(`?`)?`&`:`?`)+`v=${H[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)(Qs,{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)}${H[t.id]?(Q.getLibraryFileThumbnailUrl(t.id).includes(`?`)?`&`:`?`)+`v=${H[t.id]}`:``}`,alt:t.filename,className:`w-full h-full object-contain`})})})]}),(0,K.jsx)(`div`,{className:`min-w-0`,children:(0,K.jsx)(`div`,{className:`text-sm text-white truncate`,children:t.print_name||t.filename})})]}),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)(ju,{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:kd(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:()=>He(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)(hu,{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:[p9(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)(Ol,{className:`w-4 h-4`})})}),(Ne?.use_slicer_api??!1)&&m9(t.filename)&&(0,K.jsx)(`button`,{onClick:()=>r(`library:upload`)&&ee(t),className:`p-1.5 rounded transition-colors ${r(`library:upload`)?`hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green`:`text-bambu-gray/50 cursor-not-allowed`}`,title:r(`library:upload`)?e(`slice.action`):e(`fileManager.noPermissionSlice`),disabled:!r(`library:upload`),children:(0,K.jsx)(ks,{className:`w-4 h-4`})}),(Ne?.use_slicer_api??!1)&&m9(t.filename)&&(0,K.jsx)(`button`,{onClick:()=>r(`pipelines:run`)&&ne(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)(Cl,{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`)&&(p9(t.filename)?c(`/gcode-viewer?library_file=${t.id}`):U(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)(Wo,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>r(`library:read`)&>(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)(Vs,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>a(`library`,`update`,t.created_by_id)&&ie({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)(xl,{className:`w-4 h-4`})}),t.file_type===`stl`&&(0,K.jsx)(`button`,{onClick:()=>a(`library`,`update`,t.created_by_id)&&st.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:st.isPending||!a(`library`,`update`,t.created_by_id),children:(0,K.jsx)(Mc,{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)(Cu,{className:`w-4 h-4`})})]})]},t.id))]})})]}),u!==null&&(0,K.jsx)(PXe,{folderId:u})]})]}),g&&(0,K.jsx)(RXe,{parentId:u,onClose:()=>_(!1),onSave:e=>Xe.mutate(e),isLoading:Xe.isPending,t:e}),v&&(0,K.jsx)(zXe,{onClose:()=>b(!1),onSave:e=>Ze.mutate(e),isLoading:Ze.isPending,t:e}),x&&Pe&&(0,K.jsx)(UXe,{folders:Pe,selectedFiles:m,currentFolderId:u,onClose:()=>S(!1),onMove:e=>nt.mutate({fileIds:m,folderId:e}),isLoading:nt.isPending,t:e}),C&&(0,K.jsx)(XU,{folderId:u,onClose:()=>{w(!1),E([])},onUploadComplete:pt,initialFiles:T.length>0?T:void 0}),D&&(0,K.jsx)(LXe,{onClose:()=>O(!1)}),(0,K.jsx)(FXe,{open:k,onClose:()=>A(!1),onPickTag:e=>{N.includes(e)||P(t=>[...t,e])}}),(0,K.jsx)(fWe,{open:j,fileIds:m,onClose:()=>M(!1)}),F&&(0,K.jsx)(WXe,{folder:F,onClose:()=>I(null),onLink:e=>rt.mutate({id:F.id,data:e}),isLoading:rt.isPending,t:e}),L&&(0,K.jsx)(zd,{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:vt,loadingText:e(`fileManager.deleting`),onConfirm:_t,onCancel:()=>R(null)}),z&&(0,K.jsx)(uW,{mode:`create`,libraryFileId:z.id,archiveName: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)(UW,{source:{kind:`libraryFile`,id:V.id,filename:V.filename},onClose:()=>ee(null)}),te&&(0,K.jsx)(KW,{source:{kind:`libraryFile`,id:te.id,filename:te.filename},onClose:()=>ne(null)}),oe&&(0,K.jsx)(dWe,{libraryFileId:oe.id,title:oe.print_name||oe.filename,fileType:oe.file_type,onClose:()=>U(null),onSliceWithBambuddy:m9(oe.filename)&&r(`library:upload`)?()=>{let e=oe;U(null),ee(e)}:void 0}),re&&(0,K.jsx)(HXe,{type:re.type,currentName:re.name,onClose:()=>ie(null),onSave:e=>{re.type===`file`?it.mutate({id:re.id,filename:e}):at.mutate({id:re.id,name:e})},isLoading:it.isPending||at.isPending,t:e})]})}function qXe(e){let t=kf(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 JXe(e){let t=kf(e);return t?t.toLocaleString():e}function YXe(){let{t:e}=W(),t=$n(),n=no(),{showToast:r}=jd(),{hasPermission:i,authEnabled:a}=_d(),[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)(wi,{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)(jo,{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)(Cu,{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)(Il,{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:kd(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)(Nl,{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)(Cu,{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:kd(t.file_size)}),(0,K.jsx)(`td`,{className:`px-3 py-2 text-gray-600 dark:text-gray-400 whitespace-nowrap`,children:JXe(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:JXe(t.auto_purge_at),children:e(`libraryTrash.autoPurgeIn`,{when:qXe(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)(Nl,{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)(Cu,{className:`w-3.5 h-3.5`}),e(`libraryTrash.purgeNow`)]})]})]},t.id))})]})})]}),o&&(0,K.jsx)(zd,{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 XXe(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 ZXe(){let{authEnabled:e,user:t,loading:n}=_d(),r=no(),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 ed(e),e&&XXe(document,e),()=>ed(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=td();!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 h9=5,QXe=2e3,$Xe=3e4,eZe=5e3;function tZe(){let{t:e}=W(),t=no(),{showToast:n}=jd(),{hasPermission:r,authEnabled:i,user:a}=_d(),{printerId:o}=ir(),s=parseInt(o||`0`,10),[c]=Mi(),l=parseInt(c.get(`fps`)||`15`,10),u=Math.min(Math.max(isNaN(l)?15:l,1),30);ZXe();let{data:d}=q({queryKey:[`camera-stream-token`,a?.id??null],queryFn:()=>Q.getCameraStreamToken(),enabled:i?!!a:!0,staleTime:3e3*1e3}),f=d?.token??td(),[p,m]=(0,y.useState)(`stream`),[h,g]=(0,y.useState)(!1),[_,v]=(0,y.useState)(!1),[b,x]=(0,y.useState)(!1),[S,C]=(0,y.useState)(!0),[w,T]=(0,y.useState)(Date.now()),[E,D]=(0,y.useState)(!1),[O,k]=(0,y.useState)(!1),[A,j]=(0,y.useState)(0),[M,N]=(0,y.useState)(!1),[P,F]=(0,y.useState)(0),[I,L]=(0,y.useState)(1),[R,z]=(0,y.useState)({x:0,y:0}),[B,V]=(0,y.useState)(!1),[ee,te]=(0,y.useState)({x:0,y:0}),[ne,re]=(0,y.useState)(null),[ie,H]=(0,y.useState)(null),ae=(0,y.useRef)(null),oe=(0,y.useRef)(null),U=(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=Qu();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(S&&!E){let e=setTimeout(()=>{C(!1)},p===`stream`?3e3:2e4);return()=>clearTimeout(e)}},[p,S,w,E]),(0,y.useEffect)(()=>{let e=()=>{k(!!document.fullscreenElement),L(1),z({x:0,y:0}),p===`stream`&&!E&&(ae.current&&(ae.current.src=``),setTimeout(()=>{C(!0),T(Date.now())},200))};return document.addEventListener(`fullscreenchange`,e),()=>document.removeEventListener(`fullscreenchange`,e)},[p,E]),(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)(()=>()=>{U.current&&clearTimeout(U.current),se.current&&clearInterval(se.current),ce.current&&clearInterval(ce.current)},[]);let he=(0,y.useCallback)(()=>{if(A>=h9){N(!1),x(!0);return}let e=Math.min(QXe*2**A,$Xe);N(!0),F(Math.ceil(e/1e3)),se.current=setInterval(()=>{F(e=>e<=1?(se.current&&clearInterval(se.current),0):e-1)},1e3),U.current=setTimeout(()=>{j(e=>e+1),N(!1),C(!0),x(!1),ae.current&&(ae.current.src=``),T(Date.now())},e)},[A]);(0,y.useEffect)(()=>{if(p!==`stream`||S||M||E){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&&!b)){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),C(!1),he()}catch{}},eZe),()=>{ce.current&&=(clearInterval(ce.current),null)}},[p,S,b,M,E,s,he]);let ge=()=>{C(!1),p===`stream`&&A{if(C(!1),x(!1),j(0),le.current=0,N(!1),U.current&&clearTimeout(U.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=Qu();t&&(e.Authorization=`Bearer ${t}`),fetch(`/api/v1/printers/${s}/camera/stop`,{method:`POST`,headers:e}).catch(()=>{})}},ye=e=>{p===e||E||(D(!0),C(!0),x(!1),j(0),N(!1),L(1),z({x:0,y:0}),U.current&&clearTimeout(U.current),se.current&&clearInterval(se.current),ae.current&&(ae.current.src=``),p===`stream`&&ve(),setTimeout(()=>{m(e),T(Date.now()),D(!1)},100))},be=()=>{E||(D(!0),C(!0),x(!1),j(0),N(!1),U.current&&clearTimeout(U.current),se.current&&clearInterval(se.current),ae.current&&(ae.current.src=``),p===`stream`&&ve(),setTimeout(()=>{T(Date.now()),D(!1)},100))},xe=()=>{oe.current&&(document.fullscreenElement?document.exitFullscreen():oe.current.requestFullscreen())},Se=()=>{L(e=>Math.min(e+.5,4))},Ce=()=>{L(e=>{let t=Math.max(e-.5,1);return t===1&&z({x:0,y:0}),t})},we=e=>{e.preventDefault(),e.deltaY<0?Se():Ce()},Te=e=>{I>1&&(e.preventDefault(),V(!0),te({x:e.clientX-R.x,y:e.clientY-R.y}))},Ee=(0,y.useCallback)(()=>{if(!oe.current)return{x:300,y:200};let e=oe.current.getBoundingClientRect(),t=e.width*(I-1)/2,n=e.height*(I-1)/2;return{x:Math.max(50,t),y:Math.max(50,n)}},[I]),De=e=>{if(B&&I>1){let t=e.clientX-ee.x,n=e.clientY-ee.y,r=Ee();z({x:Math.max(-r.x,Math.min(r.x,t)),y:Math.max(-r.y,Math.min(r.y,n))})}},Oe=()=>{V(!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)),H(Ae(e.touches))):e.touches.length===1&&I>1&&(e.preventDefault(),V(!0),te({x:e.touches[0].clientX-R.x,y:e.touches[0].clientY-R.y}))},Me=e=>{if(e.touches.length===2&&ne!==null){e.preventDefault();let t=ke(e.touches),n=t/ne;L(e=>{let t=Math.max(1,Math.min(4,e*n));return t===1&&z({x:0,y:0}),t}),re(t);let r=Ae(e.touches);if(ie){let e=Ee();z(t=>({x:Math.max(-e.x,Math.min(e.x,t.x+(r.x-ie.x))),y:Math.max(-e.y,Math.min(e.y,t.y+(r.y-ie.y)))}))}H(r)}else if(e.touches.length===1&&B&&I>1){e.preventDefault();let t=e.touches[0].clientX-ee.x,n=e.touches[0].clientY-ee.y,r=Ee();z({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),H(null)),e.touches.length===0&&V(!1)},Pe=()=>{L(1),z({x:0,y:0})},Fe=E||i&&!f?``:(e=>f?`${e}&token=${encodeURIComponent(f)}`:nd(e))(p===`stream`?`/api/v1/printers/${s}/camera/stream?fps=${u}&t=${w}`:`/api/v1/printers/${s}/camera/snapshot?t=${w}`),Ie=S||E||M;return s?(0,K.jsxs)(`div`,{ref:oe,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)(Zo,{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 ${p===`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 ${p===`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:()=>g(!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(p===`stream`?`camera.restartStream`:`camera.refreshSnapshot`),children:(0,K.jsx)(jl,{className:`w-4 h-4 text-bambu-gray ${Ie?`animate-spin`:``}`})}),(0,K.jsx)(`button`,{onClick:()=>v(!0),className:`p-1.5 hover:bg-bambu-dark-tertiary rounded`,title:e(`camera.diagnose.button`),children:(0,K.jsx)(du,{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(O?`camera.exitFullscreen`:`camera.fullscreen`),children:O?(0,K.jsx)(il,{className:`w-4 h-4 text-bambu-gray`}):(0,K.jsx)(el,{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:[(S||E)&&!M&&(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)(jl,{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(p===`stream`?`camera.connectingToCamera`:`camera.capturingSnapshot`)})]})}),M&&(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)(zu,{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:P,attempt:Math.min(A+1,h9),max:h9})}),(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`)})]})}),b&&!M&&(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)(Eu,{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:()=>v(!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(${I}) translate(${R.x/I}px, ${R.y/I}px) rotate(${ue?.camera_rotation||0}deg)`,...ue?.camera_rotation===90||ue?.camera_rotation===270?{maxWidth:`100vh`,maxHeight:`100vw`}:{},cursor:I>1?B?`grabbing`:`grab`:`default`},onError:Fe?ge:void 0,onLoad:Fe?_e:void 0,onMouseDown:Te,draggable:!1},w),(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:I<=1,className:`p-1.5 hover:bg-white/10 rounded disabled:opacity-30`,title:e(`camera.zoomOut`),children:(0,K.jsx)(qu,{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(I*100),`%`]}),(0,K.jsx)(`button`,{onClick:Se,disabled:I>=4,className:`p-1.5 hover:bg-white/10 rounded disabled:opacity-30`,title:e(`camera.zoomIn`),children:(0,K.jsx)(Gu,{className:`w-4 h-4 text-white`})})]})]})}),(0,K.jsx)(_T,{printerId:s,isOpen:h,onClose:()=>g(!1)}),_&&(0,K.jsx)(vT,{printerId:s,printerName:ue?.name||null,onClose:()=>v(!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 nZe=5e3,rZe=4,iZe=8,aZe=1,oZe=16,sZe=2,cZe=60;function lZe(e,t,n,r){let i=parseInt(e??``,10);return Number.isFinite(i)?Math.min(r,Math.max(n,i)):t}function uZe(e,t,n,r,i,a){return e.has(t)?lZe(e.get(t),r,i,a):lZe(localStorage.getItem(n),r,i,a)}function dZe(){let{t:e}=W(),t=Xn(),{authEnabled:n,loading:r,user:i}=_d(),[a]=Mi(),o=a.get(`token`),s=o!=null&&o!==``,[c,l]=(0,y.useState)(()=>uZe(a,`maxLive`,`camWallMaxLive`,rZe,aZe,oZe)),[u,d]=(0,y.useState)(()=>uZe(a,`interval`,`camWallSnapshotSec`,iZe,sZe,cZe)),[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 ed(o),()=>ed(null)},[s,o]);let m=q({queryKey:[`camwall-printers`,o],queryFn:()=>Q.getCamWallPrinters(o??void 0),enabled:s,refetchInterval:nZe}),h=q({queryKey:[`printers`],queryFn:()=>Q.getPrinters(),enabled:!s&&!r&&(!n||i!==null),refetchInterval:nZe}),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)(Or,{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 fZe(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 pZe(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`)}}function mZe(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 hZe(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 gZe(){let{printerId:e}=ir(),[t]=Mi(),{t:n}=W(),r=no(),i=parseInt(e||`0`,10),[a,o]=(0,y.useState)(Date.now()),s=(0,y.useMemo)(()=>pZe(t),[t]),c=hZe(s.size),{data:l}=q({queryKey:[`printer`,i],queryFn:()=>Q.getPrinter(i),enabled:i>0}),{data:u}=q({queryKey:[`printerStatus`,i],queryFn:()=>Q.getPrinterStatus(i),enabled:i>0,refetchInterval:2e3}),{data:d}=q({queryKey:[`settings`],queryFn:Q.getSettings}),f=d?.time_format||`system`;(0,y.useEffect)(()=>{if(!i)return;let e=null,t=!1;return(async()=>{let n;try{n=(await Q.getWebSocketToken()).token}catch(e){let t=e instanceof Yu?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,r]),(0,y.useEffect)(()=>(document.title=l?`${l.name} - ${n(`streamOverlay.title`)}`:n(`streamOverlay.title`),()=>{document.title=`Bambuddy`}),[l,n]);let p=()=>{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(!u)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 m=u.state===`RUNNING`||u.state===`PAUSE`,h=u.progress||0,g=nd(`/api/v1/printers/${i}/camera/stream?fps=${s.fps}&t=${a}`);return(0,K.jsxs)(`div`,{className:`min-h-screen bg-black relative overflow-hidden`,children:[s.showCamera&&(0,K.jsx)(`img`,{src:g,alt:n(`streamOverlay.cameraStream`),className:`absolute inset-0 w-full h-full object-contain`,style:l?.camera_rotation?{transform:`rotate(${l.camera_rotation}deg)`}:void 0,onError:p},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&&l&&(0,K.jsxs)(`div`,{className:`flex items-center ${c.gap} mb-2`,children:[(0,K.jsx)(Ol,{className:`${c.icon} text-white/70`}),(0,K.jsx)(`span`,{className:`${c.text} text-white font-medium`,children:l.name})]}),s.showFilename&&u.current_print&&(0,K.jsx)(`div`,{className:`${c.textLarge} text-white font-semibold mb-2 truncate drop-shadow-md`,children:fZe(u.current_print.replace(/\.gcode\.3mf$|\.3mf$|\.gcode$/i,``),u.gcode_file,n)}),s.showStatus&&(0,K.jsx)(`div`,{className:`${c.text} text-white/70 mb-2`,children:mZe(u,n)}),s.showProgress&&m&&(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(h),`%`]})]}),(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:`${h}%`}})})]}),m&&(s.showLayers||s.showEta)&&(0,K.jsxs)(`div`,{className:`flex items-center ${c.gap} flex-wrap`,children:[s.showLayers&&u.layer_num!=null&&u.total_layers!=null&&u.total_layers>0&&(0,K.jsxs)(`div`,{className:`flex items-center ${c.gap} text-white/70`,children:[(0,K.jsx)(Rc,{className:c.icon}),(0,K.jsxs)(`span`,{className:c.text,children:[(0,K.jsx)(`span`,{className:`text-white`,children:u.layer_num}),(0,K.jsx)(`span`,{className:`mx-1`,children:`/`}),(0,K.jsx)(`span`,{children:u.total_layers})]})]}),s.showEta&&u.remaining_time!=null&&u.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)(Su,{className:c.icon}),(0,K.jsx)(`span`,{className:`${c.text} text-white`,children:Pf(u.remaining_time*60)})]}),(0,K.jsxs)(`div`,{className:`flex items-center ${c.gap} text-white/70`,children:[(0,K.jsx)(xs,{className:c.icon}),(0,K.jsxs)(`span`,{className:`${c.text} text-white`,children:[n(`streamOverlay.eta`),` `,Nf(u.remaining_time,f,n)]})]})]})]}),!m&&(0,K.jsx)(`div`,{className:`${c.text} text-white/70 py-2`,children:u.connected?n(`streamOverlay.printerIdle`):n(`streamOverlay.printerOffline`)})]})})]})}function _Ze(){let{t:e}=W(),{id:t}=ir(),{mode:n}=bd(),{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)(Eu,{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 vZe(){let{id:e}=ir(),t=$n(),n=no(),{t:r}=W(),{showToast:i}=jd(),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)(jo,{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)(Eu,{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)(Vl,{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)(Cd,{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)(ns,{className:`w-3 h-3 text-white`}),o&&!a&&(0,K.jsx)(al,{className:`w-3 h-3 text-white`})]}),(0,K.jsx)(Xl,{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)(Il,{className:`w-4 h-4`}),r(`common.save`)]})})]})]})}var yZe=1.65,bZe=[`#1DB954`,`#3B82F6`,`#F59E0B`,`#EF4444`,`#8B5CF6`];function g9(e,t,n,r){return`${e}||${t??``}||${n??``}||${r??``}`}function _9(e,t){let n=new Date(e);return n.setDate(n.getDate()+Math.round(t)),n}function v9(e){return e.toLocaleDateString(void 0,{month:`short`,day:`numeric`,year:`numeric`})}function y9(e){return e.toLocaleDateString(void 0,{month:`short`,day:`numeric`})}function xZe(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 SZe(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(g9(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=g9(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(g9(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=xZe(u);if(m!==null)d=m.rate,f=m.stdDev,p=`history`;else{let e=SZe(t.spools);e!==null&&(d=e,p=`delta`)}let h=yZe*(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:_9(e,_),y=d&&d>0?Math.floor((s-g)/d):null,b=y===null?null:_9(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)(qc,{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)(Eu,{className:`w-4 h-4`}),r(`forecast.alertCount`,{count:L.length}),c?(0,K.jsx)(ss,{className:`w-3.5 h-3.5`}):(0,K.jsx)(rs,{className:`w-3.5 h-3.5`})]}),s&&(0,K.jsx)(OZe,{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)(Zl,{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)(TZe,{forecast:e,onCart:()=>b(e)},e.group.key))}),x&&(0,K.jsx)(NZe,{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)(DZe,{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)(wu,{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)(b9,{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)(b9,{col:`stock`,active:u,dir:f,onSort:z,children:r(`forecast.stock`)}),(0,K.jsx)(b9,{col:`used`,active:u,dir:f,onSort:z,children:r(`forecast.dailyRate`)}),(0,K.jsx)(b9,{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)(kZe,{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)(FZe,{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 b9({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)(Io,{className:`w-3 h-3 ml-1 text-bambu-green`}):(0,K.jsx)(Ao,{className:`w-3 h-3 ml-1 text-bambu-green`}):(0,K.jsx)(Po,{className:`w-3 h-3 ml-1 opacity-40`})]})})}function TZe({forecast:e,onCart:t}){let{t:n}=W(),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)(Eu,{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?v9(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)(Zl,{className:`w-3 h-3`}),` `,n(`forecast.order`)]})]})}var EZe=[{label:`1W`,value:7},{label:`1M`,value:30},{label:`6M`,value:180}];function DZe({forecasts:e,days:t,onDaysChange:n}){let{t:r}=W(),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:bZe[n%bZe.length],rop:e.reorderPointG,points:CZe(e,t)})),o=i.map(e=>{let t={day:e,label:y9(_9(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)(wu,{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:EZe.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)(DA,{width:`100%`,height:220,children:(0,K.jsxs)(uU,{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)(NV,{strokeDasharray:`3 3`,stroke:`#374151`,strokeOpacity:.5}),(0,K.jsx)(bH,{dataKey:`label`,tick:{fill:`#6B7280`,fontSize:10},interval:Math.max(0,Math.ceil(s/8)-1),axisLine:!1,tickLine:!1}),(0,K.jsx)(TH,{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)(gz,{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)(Tj,{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)(QV,{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)(vV,{y:e.rop,stroke:e.color,strokeDasharray:`4 3`,strokeOpacity:.6},`rop-${e.key}`))]})})]})}function OZe({value:e,onSave:t}){let{t:n}=W(),[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)(Pc,{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)(bl,{className:`w-3 h-3`})})]})]})}function kZe({forecast:e,globalLeadTime:t,canWrite:n,onSaved:r,onCart:i,showToast:a}){let{t:o}=W(),[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?rf(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?v9(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?v9(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)(Zl,{className:`w-4 h-4`})}),!x&&(e.stockBreakAlert?(0,K.jsx)(Eu,{className:`w-4 h-4 text-red-600 dark:text-red-400`,"aria-label":o(`forecast.stockBreakRisk`)}):e.reorderAlert?(0,K.jsx)(Eu,{className:`w-4 h-4 text-yellow-600 dark:text-yellow-400`,"aria-label":o(`forecast.reorderNow`)}):e.daysRemaining===null?null:(0,K.jsx)(ns,{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)(zo,{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)(ss,{className:`w-4 h-4`}):(0,K.jsx)(rs,{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)(AZe,{label:o(`forecast.effectiveLeadTime`),value:`${e.effectiveLeadTimeDays}d`,hint:o(`forecast.effectiveLeadTimeHint`,{global:t,sku:e.settings?.lead_time_days??0})}),(0,K.jsx)(AZe,{label:o(`forecast.reorderPoint`),value:`${Math.round(e.reorderPointG)}g`,hint:o(`forecast.reorderPointHint`)}),n&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(jZe,{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)(MZe,{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 AZe({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 jZe({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)(Pc,{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)(bl,{className:`w-3 h-3`})})]})]})}function MZe({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}=W(),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)(Pc,{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)(bl,{className:`w-3 h-3`})})]})]})}function NZe({items:e,forecasts:t,globalLeadTime:n,canWrite:r,onClose:i,onRemove:a,onClear:o}){let{t:s}=W(),c=no(),[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(g9(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(g9(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?v9(_9(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(` +`))}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 sYe(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 dXe={tokenize:yXe,partial:!0};function fXe(){return{document:{91:{name:`gfmFootnoteDefinition`,tokenize:gXe,continuation:{tokenize:_Xe},exit:vXe}},text:{91:{name:`gfmFootnoteCall`,tokenize:hXe},93:{name:`gfmPotentialFootnoteCall`,add:`after`,tokenize:pXe,resolveTo:mXe}}}}function pXe(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=W8(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 mXe(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 hXe(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||X8(s))return n(s);if(s===93){e.exit(`chunkString`);let a=e.exit(`gfmFootnoteCallString`);return i.includes(W8(r.sliceSerialize(a)))?(e.enter(`gfmFootnoteCallLabelMarker`),e.consume(s),e.exit(`gfmFootnoteCallLabelMarker`),e.exit(`gfmFootnoteCall`),t):n(s)}return X8(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 gXe(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||X8(t))return n(t);if(t===93){e.exit(`chunkString`);let n=e.exit(`gfmFootnoteDefinitionLabelString`);return a=W8(r.sliceSerialize(n)),e.enter(`gfmFootnoteDefinitionLabelMarker`),e.consume(t),e.exit(`gfmFootnoteDefinitionLabelMarker`),e.exit(`gfmFootnoteDefinitionLabel`),f}return X8(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),n5(e,p,`gfmFootnoteDefinitionWhitespace`)):n(t)}function p(e){return t(e)}}function _Xe(e,t,n){return e.check(c5,t,e.attempt(dXe,t,n))}function vXe(e){e.exit(`gfmFootnoteDefinition`)}function yXe(e,t,n){let r=this;return n5(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 bXe(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=i5(a);return l._open=!u||u===2&&!!s,l._close=!s||s===2&&!!u,n(a)}}}var xXe=class{constructor(){this.map=[]}add(e,t,n){SXe(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 SXe(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):Y8(t)?a>1?(a=0,r.interrupt=!0,e.exit(`tableRow`),e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),p):n(t):Z8(t)?n5(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||X8(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,Z8(t)?n5(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 Z8(t)?n5(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||Y8(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 Z8(t)?n5(e,b,`whitespace`)(t):b(t)}function b(n){return n===124?m(n):n===null||Y8(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||Y8(n)?(e.exit(`tableRow`),t(n)):Z8(n)?n5(e,C,`whitespace`)(n):(e.enter(`data`),w(n))}function w(t){return t===null||t===124||X8(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 EXe(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 xXe;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({},u9(t.events,i)),e.add(i,0,[[`exit`,a,t]]),a=void 0),a}function l9(e,t,n,r,i){let a=[],o=u9(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 u9(e,t){let n=e[t],r=n[0]===`enter`?`start`:`end`;return n[1][r]}var DXe={name:`tasklistCheck`,tokenize:kXe};function OXe(){return{text:{91:DXe}}}function kXe(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 X8(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 Y8(r)?t(r):Z8(r)?e.check({tokenize:AXe},t,n)(r):n(r)}}function AXe(e,t,n){return n5(e,r,`whitespace`);function r(e){return e===null?n(e):t(e)}}function jXe(e){return H8([nXe(),fXe(),bXe(e),wXe(),OXe()])}var MXe={};function NXe(e){let t=this,n=e||MXe,r=t.data(),i=r.micromarkExtensions||=[],a=r.fromMarkdownExtensions||=[],o=r.toMarkdownExtensions||=[];i.push(jXe(n)),a.push(QYe()),o.push($Ye(n))}var d9=`fileManager.readmeCollapsed`;function PXe({folderId:e}){let{t}=W(),[n,r]=(0,y.useState)(()=>localStorage.getItem(d9)===`1`);(0,y.useEffect)(()=>{localStorage.setItem(d9,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)(nc,{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)(_l,{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)(_l,{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)(nc,{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)(gl,{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)(bJe,{remarkPlugins:[NXe],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 FXe({open:e,onClose:t,onPickTag:n}){let{t:r}=W(),i=no(),{showToast:a}=jd(),[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:W6,queryFn:Q.getLibraryTags,enabled:e}),g=()=>{i.invalidateQueries({queryKey:W6}),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)(hu,{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)(Tl,{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)(Wu,{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)(xl,{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)(Cu,{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)(zd,{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 IXe=90;function LXe({onClose:e}){let{t}=W(),n=no(),{showToast:r}=jd(),[i,a]=(0,y.useState)(IXe),[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)(Cu,{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)(Wu,{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:kd(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)(Eu,{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 RXe({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 zXe({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)(uc,{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 BXe=`<>:"/\\|?*`;function VXe(e){for(let t of e)if(BXe.includes(t)||t.charCodeAt(0)<32)return t;return null}function HXe({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`?VXe(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 UXe({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)(cc,{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 WXe({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)(Vc,{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)(Wu,{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)(Go,{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)(Oo,{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)(Qs,{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)(ku,{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 f9({folder:e,selectedFolderId:t,onSelect:n,onDelete:r,onLink:i,onRename:a,depth:o=0,wrapNames:s=!1,defaultExpanded:c=!0,hasPermission:l,t:u}){let[d,f]=(0,y.useState)(c),[p,m]=(0,y.useState)(!1),h=e.children.length>0,g=e.project_id||e.archive_id,_=e.is_external;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:[h?(0,K.jsx)(`button`,{onClick:e=>{e.stopPropagation(),f(!d)},className:`p-0.5 hover:bg-bambu-dark-tertiary rounded`,children:(0,K.jsx)(is,{className:`w-3.5 h-3.5 transition-transform ${d?`rotate-90`:``}`})}):(0,K.jsx)(`div`,{className:`w-4.5`}),_?(0,K.jsx)(uc,{className:`w-4 h-4 text-purple-600 dark:text-purple-400 flex-shrink-0`}):(0,K.jsx)(cc,{className:`w-4 h-4 text-bambu-green flex-shrink-0`}),(0,K.jsx)(`span`,{className:`text-sm flex-1 min-w-0 ${s?`break-all`:`truncate`}`,title:e.name,children:e.name}),g&&(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)(Vc,{className:`w-3 h-3`}),e.project_name?(0,K.jsx)(Go,{className:`w-3 h-3`}):(0,K.jsx)(Oo,{className:`w-3 h-3`})]}),_&&e.external_readonly&&(0,K.jsx)(`span`,{title:u(`fileManager.readOnly`),children:(0,K.jsx)(qc,{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}),!g&&!_&&(0,K.jsx)(`button`,{onClick:t=>{t.stopPropagation(),i(e)},className:`flex-shrink-0 p-1 rounded hover:bg-bambu-dark-tertiary`,title:u(`fileManager.linkToProjectOrArchive`),children:(0,K.jsx)(Vc,{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:()=>m(!p),className:`p-1 rounded hover:bg-bambu-dark-tertiary`,children:(0,K.jsx)(Ws,{className:`w-3.5 h-3.5 text-bambu-gray`})}),p&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>m(!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 ${l(`library:update_all`)?`text-white hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{l(`library:update_all`)&&(a(e),m(!1))},disabled:!l(`library:update_all`),title:l(`library:update_all`)?void 0:u(`fileManager.noPermissionRenameFolder`),children:[(0,K.jsx)(xl,{className:`w-3.5 h-3.5`}),u(`common.rename`)]}),(0,K.jsxs)(`button`,{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${l(`library:update_all`)?`text-white hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{l(`library:update_all`)&&(i(e),m(!1))},disabled:!l(`library:update_all`),title:l(`library:update_all`)?void 0:u(`fileManager.noPermissionLinkFolder`),children:[(0,K.jsx)(Vc,{className:`w-3.5 h-3.5`}),u(g?`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 ${l(`library:delete_all`)?`text-red-700 dark:text-red-400 hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{l(`library:delete_all`)&&(r(e.id),m(!1))},disabled:!l(`library:delete_all`),title:l(`library:delete_all`)?void 0:u(`fileManager.noPermissionDeleteFolder`),children:[(0,K.jsx)(Cu,{className:`w-3.5 h-3.5`}),u(`common.delete`)]})]})]})]})})]}),h&&d&&(0,K.jsx)(`div`,{children:e.children.map(e=>(0,K.jsx)(f9,{folder:e,selectedFolderId:t,onSelect:n,onDelete:r,onLink:i,onRename:a,depth:o+1,wrapNames:s,defaultExpanded:c,hasPermission:l,t:u},e.id))})]})}function p9(e){let t=e.toLowerCase();return t.endsWith(`.gcode`)||t.endsWith(`.gcode.3mf`)}function m9(e){let t=e.toLowerCase();return t.endsWith(`.gcode`)||t.endsWith(`.gcode.3mf`)?!1:t.endsWith(`.stl`)||t.endsWith(`.3mf`)||t.endsWith(`.step`)||t.endsWith(`.stp`)}function GXe({file:e,isSelected:t,isMobile:n,onSelect:r,onDelete:i,onDownload:a,onPrint:o,onSlice:s,onRunPipeline:c,useSlicerApi:l,onPreview3d:u,onRename:d,onGenerateThumbnail:f,onTagClick:p,thumbnailVersion:m,hasPermission:h,canModify:g,authEnabled:_,t:v}){let[b,x]=(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)}${m?(Q.getLibraryFileThumbnailUrl(e.id).includes(`?`)?`&`:`?`)+`v=${m}`:``}`,alt:e.filename,className:`w-full h-full object-cover`}):(0,K.jsx)(Qs,{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:kd(e.file_size)}),e.print_time_seconds&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(xs,{className:`w-3 h-3`}),Pf(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)(Ol,{className:`w-3 h-3`}),e.sliced_for_model]}),e.print_count>0&&(0,K.jsx)(`div`,{className:`mt-1 text-xs text-bambu-green`,children:v(`fileManager.printedCount`,{count:e.print_count})}),_&&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)(ju,{className:`w-3 h-3`}),e.created_by_username]}),(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:()=>p?.(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)(hu,{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:()=>x(!b),className:`p-1.5 rounded bg-bambu-dark-secondary/90 hover:bg-bambu-dark-tertiary`,children:(0,K.jsx)(Ws,{className:`w-4 h-4 text-bambu-gray`})}),b&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>x(!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&&p9(e.filename)&&(0,K.jsxs)(`button`,{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${h(`queue:create`)?`text-bambu-green hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{h(`queue:create`)&&(o(e),x(!1))},disabled:!h(`queue:create`),title:h(`queue:create`)?void 0:v(`fileManager.noPermissionAddToQueue`),children:[(0,K.jsx)(Ol,{className:`w-3.5 h-3.5`}),v(`common.print`)]}),s&&l&&m9(e.filename)&&(0,K.jsxs)(`button`,{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${h(`library:upload`)?`text-white hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{h(`library:upload`)&&(s(e),x(!1))},disabled:!h(`library:upload`),title:h(`library:upload`)?void 0:v(`fileManager.noPermissionSlice`),children:[(0,K.jsx)(ks,{className:`w-3.5 h-3.5`}),v(`slice.action`)]}),c&&l&&m9(e.filename)&&(0,K.jsxs)(`button`,{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${h(`pipelines:run`)?`text-white hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{h(`pipelines:run`)&&(c(e),x(!1))},disabled:!h(`pipelines:run`),title:h(`pipelines:run`)?void 0:v(`library.runWithPipeline.noPermission`),children:[(0,K.jsx)(Cl,{className:`w-3.5 h-3.5`}),v(`library.runWithPipeline.actionLabel`)]}),u&&(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 ${h(`library:read`)?`text-white hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{h(`library:read`)&&(u(e),x(!1))},disabled:!h(`library:read`),title:h(`library:read`)?void 0:`You do not have permission to preview files`,children:[(0,K.jsx)(Wo,{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 ${h(`library:read`)?`text-white hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{h(`library:read`)&&(a(e.id),x(!1))},disabled:!h(`library:read`),title:h(`library:read`)?void 0:v(`fileManager.noPermissionDownload`),children:[(0,K.jsx)(Vs,{className:`w-3.5 h-3.5`}),v(`common.download`)]}),d&&(0,K.jsxs)(`button`,{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${g(`library`,`update`,e.created_by_id)?`text-white hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{g(`library`,`update`,e.created_by_id)&&(d(e),x(!1))},disabled:!g(`library`,`update`,e.created_by_id),title:g(`library`,`update`,e.created_by_id)?void 0:v(`fileManager.noPermissionRenameFile`),children:[(0,K.jsx)(xl,{className:`w-3.5 h-3.5`}),v(`common.rename`)]}),f&&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 ${g(`library`,`update`,e.created_by_id)?`text-white hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{g(`library`,`update`,e.created_by_id)&&(f(e),x(!1))},disabled:!g(`library`,`update`,e.created_by_id),title:g(`library`,`update`,e.created_by_id)?void 0:v(`fileManager.noPermissionGenerateThumbnail`),children:[(0,K.jsx)(Mc,{className:`w-3.5 h-3.5`}),v(`fileManager.generateThumbnail`)]}),(0,K.jsxs)(`button`,{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${g(`library`,`delete`,e.created_by_id)?`text-red-700 dark:text-red-400 hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{g(`library`,`delete`,e.created_by_id)&&(i(e.id),x(!1))},disabled:!g(`library`,`delete`,e.created_by_id),title:g(`library`,`delete`,e.created_by_id)?void 0:v(`fileManager.noPermissionDeleteFile`),children:[(0,K.jsx)(Cu,{className:`w-3.5 h-3.5`}),v(`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 KXe(){let{t:e}=W(),t=no(),{showToast:n}=jd(),{hasPermission:r,hasAnyPermission:i,canModify:a,authEnabled:o}=_d(),[s]=Mi(),c=$n(),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,ne]=(0,y.useState)(null),[re,ie]=(0,y.useState)(null),[H,ae]=(0,y.useState)({}),[oe,U]=(0,y.useState)(null),[se,ce]=(0,y.useState)(()=>localStorage.getItem(`library-view-mode`)||`grid`),[le,ue]=(0,y.useState)(()=>localStorage.getItem(`library-wrap-folders`)===`true`),[de,fe]=(0,y.useState)(()=>localStorage.getItem(`library-collapse-folders`)===`true`),[pe,me]=(0,y.useState)(()=>localStorage.getItem(`library-folder-sort-field`)===`activity`?`activity`:`name`),[he,ge]=(0,y.useState)(()=>localStorage.getItem(`library-folder-sort-direction`)===`desc`?`desc`:`asc`),[_e,ve]=(0,y.useState)(()=>{let e=localStorage.getItem(`library-sidebar-width`);return e?parseInt(e,10):256}),[ye,be]=(0,y.useState)(!1),xe=(0,y.useRef)(null);(0,y.useEffect)(()=>{if(!ye)return;document.body.style.userSelect=`none`,document.body.style.cursor=`col-resize`;let e=e=>{if(!xe.current)return;let t=xe.current.parentElement?.getBoundingClientRect();if(!t)return;let n=e.clientX-t.left;ve(Math.min(500,Math.max(200,n)))},t=()=>{be(!1),document.body.style.userSelect=``,document.body.style.cursor=``,localStorage.setItem(`library-sidebar-width`,String(_e))};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=``}},[ye,_e]);let[Se,Ce]=(0,y.useState)(``),[we,Te]=(0,y.useState)(`all`),[Ee,De]=(0,y.useState)(``),[Oe,ke]=(0,y.useState)(()=>localStorage.getItem(`library-sort-field`)||`name`),[Ae,je]=(0,y.useState)(()=>localStorage.getItem(`library-sort-direction`)||`asc`),Me=YW();(0,y.useEffect)(()=>{let e=s.get(`folder`);e&&d(parseInt(e,10))},[s]);let{data:Ne}=q({queryKey:[`settings`],queryFn:()=>Q.getSettings()}),{data:Pe,isLoading:Fe}=q({queryKey:[`library-folders`],queryFn:()=>Q.getLibraryFolders()}),Ie=(0,y.useMemo)(()=>{if(!Pe)return Pe;let e=t=>[...t].sort((e,t)=>{let n=0;if(pe===`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 he===`asc`?n:-n}).map(t=>({...t,children:e(t.children)}));return e(Pe)},[Pe,pe,he]),{data:Le}=q({queryKey:[`library-trash-count`],queryFn:async()=>{try{return(await Q.listLibraryTrash(1,0)).total}catch{return 0}},staleTime:3e4}),Re=u!==null&&Se.trim().length>0,ze=(0,y.useMemo)(()=>[...N].sort((e,t)=>e-t),[N]),{data:Be=[]}=q({queryKey:[`library-tags`],queryFn:Q.getLibraryTags}),Ve=(0,y.useMemo)(()=>{let e=new Map;for(let t of Be)e.set(t.id,t.name);return e},[Be]);(0,y.useEffect)(()=>{Be.length!==0&&P(e=>{let t=e.filter(e=>Ve.has(e));return t.length===e.length?e:t})},[Be.length,Ve]);let He=(0,y.useCallback)(e=>{P(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},[]),{data:Ue,isLoading:We}=q({queryKey:[`library-files`,u,f,Re,ze],queryFn:()=>Q.getLibraryFiles(u,!1,void 0,u===null?f:void 0,Re,ze)}),{data:Ge}=q({queryKey:[`library-stats`],queryFn:()=>Q.getLibraryStats()}),{data:Ke}=q({queryKey:[`users`],queryFn:()=>Q.getUsers()}),qe=(0,y.useMemo)(()=>{if(!Ue)return[];let e=new Set(Ue.map(e=>e.file_type));return Array.from(e).sort()},[Ue]),Je=(0,y.useMemo)(()=>{if(!Ue)return[];let e=[...Ue];if(Se.trim()){let t=Se.toLowerCase();e=e.filter(e=>e.filename.toLowerCase().includes(t)||e.print_name&&e.print_name.toLowerCase().includes(t))}if(we!==`all`&&(e=e.filter(e=>e.file_type===we)),Ee.trim()){let t=Ee.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(Oe){case`name`:n=(e.print_name||e.filename).localeCompare(t.print_name||t.filename);break;case`date`:n=(kf(e.created_at)?.getTime()??0)-(kf(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 Ae===`asc`?n:-n}),e},[Ue,Se,we,Ee,Oe,Ae]),Ye=(0,y.useMemo)(()=>{if(!Ge||!Ne)return!1;let e=(Ne.library_disk_warning_gb||5)*1024*1024*1024;return Ge.disk_free_bytesQ.createLibraryFolder(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-folders`]}),_(!1),n(e(`fileManager.toast.folderCreated`),`success`)},onError:e=>n(e.message,`error`)}),Ze=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`)}),Qe=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`)}),$e=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`)}}),et=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`)}}),tt=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`)}}),nt=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`)}),rt=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`)}),it=J({mutationFn:({id:e,filename:t})=>Q.updateLibraryFile(e,{filename:t}),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-files`]}),ie(null),n(e(`fileManager.toast.fileRenamed`),`success`)},onError:e=>{ie(null),n(e.message,`error`)}}),at=J({mutationFn:({id:e,name:t})=>Q.updateLibraryFolder(e,{name:t}),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-files`]}),ie(null),n(e(`fileManager.toast.folderRenamed`),`success`)},onError:e=>{ie(null),n(e.message,`error`)}}),ot=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)}),ae(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`)}),st=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&&ae(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`)}),ct=(0,y.useCallback)(e=>{let t=e.toLowerCase();return t.endsWith(`.gcode`)||t.includes(`.gcode.`)},[]),lt=(0,y.useMemo)(()=>Ue?Ue.filter(e=>m.includes(e.id)&&ct(e.filename)):[],[Ue,m,ct]),ut=(0,y.useCallback)(e=>{h(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},[]),dt=(0,y.useCallback)(()=>{Je.length>0&&h(Je.map(e=>e.id))},[Je]),ft=(0,y.useCallback)(()=>{h([])},[]),pt=()=>{t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-stats`]})},{isDraggingOver:mt,dragHandlers:ht}=XW({disabled:!r(`library:upload`)||C,onFiles:e=>{E(e),w(!0)}}),gt=e=>{Q.downloadLibraryFile(e).catch(e=>{console.error(`Library file download failed:`,e)})},_t=()=>{L&&(L.type===`file`?et.mutate(L.id):L.type===`folder`?$e.mutate(L.id):L.type===`bulk`&&tt.mutate(m))},vt=$e.isPending||et.isPending||tt.isPending,yt=e=>{ce(e),localStorage.setItem(`library-view-mode`,e)},bt=Fe||We,xt=(0,y.useMemo)(()=>{if(!u||!Pe)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(Pe)},[u,Pe]);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`,...ht,children:[mt&&(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)(Au,{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)(cc,{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:()=>yt(`grid`),className:`p-1.5 rounded transition-colors ${se===`grid`?`bg-bambu-dark-secondary text-white`:`text-bambu-gray hover:text-white`}`,title:e(`fileManager.gridView`),children:(0,K.jsx)(zc,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>yt(`list`),className:`p-1.5 rounded transition-colors ${se===`list`?`bg-bambu-dark-secondary text-white`:`text-bambu-gray hover:text-white`}`,title:e(`fileManager.listView`),children:(0,K.jsx)(Gc,{className:`w-4 h-4`})})]}),(0,K.jsxs)($,{variant:`secondary`,onClick:()=>ot.mutate(),disabled:ot.isPending||!i(`library:update_own`,`library:update_all`),title:i(`library:update_own`,`library:update_all`)?e(`fileManager.generateThumbnailsForMissing`):e(`fileManager.noPermissionGenerateThumbnail`),children:[ot.isPending?(0,K.jsx)(X,{className:`w-4 h-4 mr-2 animate-spin`}):(0,K.jsx)(Mc,{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)(uc,{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)(lc,{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)(hu,{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)(Cu,{className:`w-4 h-4 mr-2`}),e(`libraryPurge.headerButton`)]}),i(`library:delete_own`,`library:delete_all`)&&(0,K.jsxs)(wi,{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)(Cu,{className:`w-4 h-4 mr-2`}),e(`libraryTrash.headerButton`),typeof Le==`number`&&Le>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:Le})]}),(0,K.jsxs)($,{onClick:()=>w(!0),disabled:!r(`library:upload`),title:r(`library:upload`)?void 0:e(`fileManager.noPermissionUpload`),children:[(0,K.jsx)(Au,{className:`w-4 h-4 mr-2`}),e(`common.upload`)]})]})]}),Ye&&Ge&&Ne&&(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)(Eu,{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:kd(Ge.disk_free_bytes),total:kd(Ge.disk_total_bytes),threshold:Ne.library_disk_warning_gb})})]})]}),Ge&&(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)(rc,{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:Ge.total_files})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,K.jsx)(cc,{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:Ge.total_folders})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,K.jsx)(wc,{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:kd(Ge.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 ${Ye?`text-amber-500`:`text-white`}`,children:kd(Ge.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`)]}),Pe?.some(e=>e.is_external)&&(0,K.jsxs)(`option`,{value:`__top:external`,children:[`🔗 `,e(`fileManager.allExternal`)]}),Ie&&(()=>{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(Ie).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:xe,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:`${_e}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 ${ye?`bg-bambu-green`:`hover:bg-bambu-green/50`}`,onMouseDown:e=>{e.preventDefault(),be(!0)},onDoubleClick:()=>{ve(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 ${ye?`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:pe,onChange:e=>{let t=e.target.value===`activity`?`activity`:`name`;me(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=he===`asc`?`desc`:`asc`;ge(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(he===`asc`?`fileManager.ascending`:`fileManager.descending`),"aria-label":e(he===`asc`?`fileManager.ascending`:`fileManager.descending`),children:he===`asc`?(0,K.jsx)(Fo,{className:`w-3.5 h-3.5`}):(0,K.jsx)(ko,{className:`w-3.5 h-3.5`})}),(0,K.jsx)(`button`,{onClick:()=>{let e=!de;fe(e),localStorage.setItem(`library-collapse-folders`,String(e))},className:`text-xs px-1.5 py-0.5 rounded transition-colors ${de?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:text-white hover:bg-bambu-dark`}`,title:e(de?`fileManager.expandFoldersByDefault`:`fileManager.collapseFoldersByDefault`),children:e(`fileManager.collapse`)}),(0,K.jsx)(`button`,{onClick:()=>{let e=!le;ue(e),localStorage.setItem(`library-wrap-folders`,String(e))},className:`text-xs px-1.5 py-0.5 rounded transition-colors ${le?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:text-white hover:bg-bambu-dark`}`,title:e(le?`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)(Qs,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{className:`text-sm`,children:e(`fileManager.allFiles`)})]}),Pe?.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)(uc,{className:`w-4 h-4 text-purple-600 dark:text-purple-400`}),(0,K.jsx)(`span`,{className:`text-sm`,children:e(`fileManager.allExternal`)})]}),Ie?.map(t=>(0,K.jsx)(f9,{folder:t,selectedFolderId:u,onSelect:d,onDelete:e=>R({type:`folder`,id:e}),onLink:I,onRename:e=>ie({type:`folder`,id:e.id,name:e.name}),wrapNames:le,defaultExpanded:!de,hasPermission:r,t:e},`${t.id}-${de?`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:[Be.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`)}),Be.map(e=>{let t=N.includes(e.id);return(0,K.jsxs)(`button`,{type:`button`,onClick:()=>He(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)(hu,{className:`w-3 h-3`}),(0,K.jsx)(`span`,{children:e.name}),t&&(0,K.jsx)(Wu,{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`)})]}),xt?.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)(uc,{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`)}),xt.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)(qc,{className:`w-3 h-3`}),e(`fileManager.readOnly`)]})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray truncate font-mono`,title:xt.external_path||``,children:xt.external_path})]}),(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:()=>u&&Qe.mutate(u),disabled:Qe.isPending,title:e(`fileManager.scanFolder`),children:[Qe.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(jl,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{className:`ml-1.5`,children:e(`fileManager.scanFolder`)})]})]}),Ue&&Ue.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)(Vl,{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:Se,onChange:e=>Ce(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`}),Re&&(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)(mc,{className:`w-4 h-4 text-bambu-gray hidden sm:block`}),(0,K.jsxs)(`select`,{value:we,onChange:e=>Te(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`)}),qe.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:Ee,onChange:e=>De(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 ${Ee?`pr-7`:``}`,style:Ee?{WebkitAppearance:`none`,MozAppearance:`textfield`}:void 0}),Ee&&(0,K.jsx)(`button`,{onClick:()=>De(``),className:`absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white z-10`,children:(0,K.jsx)(Wu,{className:`w-3 h-3`})}),(0,K.jsx)(`datalist`,{id:`usernames-list`,children:Ke?.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:Oe,onChange:e=>{let t=e.target.value;ke(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:()=>je(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(Ae===`asc`?`fileManager.ascending`:`fileManager.descending`),children:Ae===`asc`?(0,K.jsx)(Fo,{className:`w-4 h-4 text-white`}):(0,K.jsx)(ko,{className:`w-4 h-4 text-white`})})]}),(Se||we!==`all`||Ee)&&(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray hidden sm:inline`,children:e(`fileManager.resultsCount`,{showing:Je.length,total:Ue.length})})]}),Je.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===Je.length&&m.length>0?(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:ft,children:[(0,K.jsx)(lu,{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:dt,children:[(0,K.jsx)(su,{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:[lt.length===1&&(0,K.jsxs)($,{variant:`primary`,size:`sm`,onClick:()=>B(lt[0]),disabled:!r(`queue:create`),title:r(`queue:create`)?void 0:e(`fileManager.noPermissionAddToQueue`),children:[(0,K.jsx)(Ol,{className:`w-4 h-4 sm:mr-1`}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.print`)})]}),(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)(ll,{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)(hu,{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)(Cu,{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:ft,children:[(0,K.jsx)(Wu,{className:`w-4 h-4 sm:mr-1`}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.clear`)})]})]})]})]}),bt?(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`)})]})}):Ue?.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)(Qs,{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)(Tl,{className:`w-4 h-4 mr-2`}),e(`fileManager.uploadFiles`)]})]}):Je.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)(Vl,{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:()=>{Ce(``),Te(`all`)},children:e(`fileManager.clearFilters`)})]}):se===`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:Je.map(t=>(0,K.jsx)(GXe,{file:t,isSelected:m.includes(t.id),isMobile:Me,t:e,onSelect:ut,onDelete:e=>R({type:`file`,id:e}),onDownload:gt,onPrint:B,onSlice:ee,onRunPipeline:ne,useSlicerApi:Ne?.use_slicer_api??!1,onPreview3d:e=>{p9(e.filename)?c(`/gcode-viewer?library_file=${e.id}`):U(e)},onRename:e=>ie({type:`file`,id:e.id,name:e.filename}),onGenerateThumbnail:e=>st.mutate(e.id),onTagClick:He,thumbnailVersion:H[t.id],hasPermission:r,canModify:a,authEnabled:o},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`,{})]}),Je.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:()=>ut(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)}${H[t.id]?(Q.getLibraryFileThumbnailUrl(t.id).includes(`?`)?`&`:`?`)+`v=${H[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)(Qs,{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)}${H[t.id]?(Q.getLibraryFileThumbnailUrl(t.id).includes(`?`)?`&`:`?`)+`v=${H[t.id]}`:``}`,alt:t.filename,className:`w-full h-full object-contain`})})})]}),(0,K.jsx)(`div`,{className:`min-w-0`,children:(0,K.jsx)(`div`,{className:`text-sm text-white truncate`,children:t.print_name||t.filename})})]}),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)(ju,{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:kd(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:()=>He(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)(hu,{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:[p9(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)(Ol,{className:`w-4 h-4`})})}),(Ne?.use_slicer_api??!1)&&m9(t.filename)&&(0,K.jsx)(`button`,{onClick:()=>r(`library:upload`)&&ee(t),className:`p-1.5 rounded transition-colors ${r(`library:upload`)?`hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green`:`text-bambu-gray/50 cursor-not-allowed`}`,title:r(`library:upload`)?e(`slice.action`):e(`fileManager.noPermissionSlice`),disabled:!r(`library:upload`),children:(0,K.jsx)(ks,{className:`w-4 h-4`})}),(Ne?.use_slicer_api??!1)&&m9(t.filename)&&(0,K.jsx)(`button`,{onClick:()=>r(`pipelines:run`)&&ne(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)(Cl,{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`)&&(p9(t.filename)?c(`/gcode-viewer?library_file=${t.id}`):U(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)(Wo,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>r(`library:read`)&>(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)(Vs,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>a(`library`,`update`,t.created_by_id)&&ie({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)(xl,{className:`w-4 h-4`})}),t.file_type===`stl`&&(0,K.jsx)(`button`,{onClick:()=>a(`library`,`update`,t.created_by_id)&&st.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:st.isPending||!a(`library`,`update`,t.created_by_id),children:(0,K.jsx)(Mc,{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)(Cu,{className:`w-4 h-4`})})]})]},t.id))]})})]}),u!==null&&(0,K.jsx)(PXe,{folderId:u})]})]}),g&&(0,K.jsx)(RXe,{parentId:u,onClose:()=>_(!1),onSave:e=>Xe.mutate(e),isLoading:Xe.isPending,t:e}),v&&(0,K.jsx)(zXe,{onClose:()=>b(!1),onSave:e=>Ze.mutate(e),isLoading:Ze.isPending,t:e}),x&&Pe&&(0,K.jsx)(UXe,{folders:Pe,selectedFiles:m,currentFolderId:u,onClose:()=>S(!1),onMove:e=>nt.mutate({fileIds:m,folderId:e}),isLoading:nt.isPending,t:e}),C&&(0,K.jsx)(XU,{folderId:u,onClose:()=>{w(!1),E([])},onUploadComplete:pt,initialFiles:T.length>0?T:void 0}),D&&(0,K.jsx)(LXe,{onClose:()=>O(!1)}),(0,K.jsx)(FXe,{open:k,onClose:()=>A(!1),onPickTag:e=>{N.includes(e)||P(t=>[...t,e])}}),(0,K.jsx)(fWe,{open:j,fileIds:m,onClose:()=>M(!1)}),F&&(0,K.jsx)(WXe,{folder:F,onClose:()=>I(null),onLink:e=>rt.mutate({id:F.id,data:e}),isLoading:rt.isPending,t:e}),L&&(0,K.jsx)(zd,{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:vt,loadingText:e(`fileManager.deleting`),onConfirm:_t,onCancel:()=>R(null)}),z&&(0,K.jsx)(uW,{mode:`create`,libraryFileId:z.id,archiveName: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)(UW,{source:{kind:`libraryFile`,id:V.id,filename:V.filename},onClose:()=>ee(null)}),te&&(0,K.jsx)(KW,{source:{kind:`libraryFile`,id:te.id,filename:te.filename},onClose:()=>ne(null)}),oe&&(0,K.jsx)(dWe,{libraryFileId:oe.id,title:oe.print_name||oe.filename,fileType:oe.file_type,onClose:()=>U(null),onSliceWithBambuddy:m9(oe.filename)&&r(`library:upload`)?()=>{let e=oe;U(null),ee(e)}:void 0}),re&&(0,K.jsx)(HXe,{type:re.type,currentName:re.name,onClose:()=>ie(null),onSave:e=>{re.type===`file`?it.mutate({id:re.id,filename:e}):at.mutate({id:re.id,name:e})},isLoading:it.isPending||at.isPending,t:e})]})}function qXe(e){let t=kf(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 JXe(e){let t=kf(e);return t?t.toLocaleString():e}function YXe(){let{t:e}=W(),t=$n(),n=no(),{showToast:r}=jd(),{hasPermission:i,authEnabled:a}=_d(),[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)(wi,{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)(jo,{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)(Cu,{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)(Il,{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:kd(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)(Nl,{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)(Cu,{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:kd(t.file_size)}),(0,K.jsx)(`td`,{className:`px-3 py-2 text-gray-600 dark:text-gray-400 whitespace-nowrap`,children:JXe(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:JXe(t.auto_purge_at),children:e(`libraryTrash.autoPurgeIn`,{when:qXe(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)(Nl,{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)(Cu,{className:`w-3.5 h-3.5`}),e(`libraryTrash.purgeNow`)]})]})]},t.id))})]})})]}),o&&(0,K.jsx)(zd,{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 XXe(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 ZXe(){let{authEnabled:e,user:t,loading:n}=_d(),r=no(),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 ed(e),e&&XXe(document,e),()=>ed(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=td();!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 h9=5,QXe=2e3,$Xe=3e4,eZe=5e3;function tZe(){let{t:e}=W(),t=no(),{showToast:n}=jd(),{hasPermission:r,authEnabled:i,user:a}=_d(),{printerId:o}=ir(),s=parseInt(o||`0`,10),[c]=Mi(),l=parseInt(c.get(`fps`)||`15`,10),u=Math.min(Math.max(isNaN(l)?15:l,1),30);ZXe();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??td(),[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,ne]=(0,y.useState)({x:0,y:0}),[re,ie]=(0,y.useState)(null),[H,ae]=(0,y.useState)(null),oe=(0,y.useRef)(null),U=(0,y.useRef)(null),se=(0,y.useRef)(null),ce=(0,y.useRef)(null),le=(0,y.useRef)(null),ue=(0,y.useRef)(0),{data:de}=q({queryKey:[`printer`,s],queryFn:()=>Q.getPrinter(s),enabled:s>0}),{data:fe}=q({queryKey:[`printerStatus`,s],queryFn:()=>Q.getPrinterStatus(s),refetchInterval:3e4,enabled:s>0}),pe=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`)}}),me=(fe?.state===`RUNNING`||fe?.state===`PAUSE`)&&(fe?.printable_objects_count??0)>=2;(0,y.useEffect)(()=>(de&&(document.title=`${de.name} - Camera`),()=>{document.title=`Bambuddy`}),[de]);let he=(0,y.useRef)(!1);(0,y.useEffect)(()=>{let e=`/api/v1/printers/${s}/camera/stop`;he.current=!1;let t=()=>{if(s>0&&!he.current){he.current=!0;let t={},n=Qu();n&&(t.Authorization=`Bearer ${n}`),fetch(e,{method:`POST`,keepalive:!0,headers:t}).catch(()=>{})}},n=()=>{t()};window.addEventListener(`beforeunload`,n);let r=oe.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&&(oe.current&&(oe.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)(()=>()=>{se.current&&clearTimeout(se.current),ce.current&&clearInterval(ce.current),le.current&&clearInterval(le.current)},[]);let ge=(0,y.useCallback)(()=>{if(j>=h9){P(!1),S(!0);return}let e=Math.min(QXe*2**j,$Xe);P(!0),I(Math.ceil(e/1e3)),ce.current=setInterval(()=>{I(e=>e<=1?(ce.current&&clearInterval(ce.current),0):e-1)},1e3),se.current=setTimeout(()=>{M(e=>e+1),P(!1),w(!0),S(!1),oe.current&&(oe.current.src=``),E(Date.now())},e)},[j]);(0,y.useEffect)(()=>{if(m!==`stream`||C||N||D){le.current&&=(clearInterval(le.current),null);return}return ue.current=0,le.current=setInterval(async()=>{try{let e=await Q.getCameraStatus(s);if(!(e.stalled||!e.active&&!x)){ue.current=0;return}if(ue.current+=1,ue.current<2)return;ue.current=0,console.log(`Stream issue detected: stalled=${e.stalled}, active=${e.active}, reconnecting...`),le.current&&=(clearInterval(le.current),null),w(!1),ge()}catch{}},eZe),()=>{le.current&&=(clearInterval(le.current),null)}},[m,C,x,N,D,s,ge]);let _e=()=>{w(!1),m===`stream`&&j{if(w(!1),S(!1),M(0),ue.current=0,P(!1),se.current&&clearTimeout(se.current),ce.current&&clearInterval(ce.current),oe.current&&!localStorage.getItem(`cameraWindowState`)){let e=oe.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{}}}},ye=()=>{if(s>0){let e={},t=Qu();t&&(e.Authorization=`Bearer ${t}`),fetch(`/api/v1/printers/${s}/camera/stop`,{method:`POST`,headers:e}).catch(()=>{})}},be=e=>{m===e||D||(O(!0),w(!0),S(!1),M(0),P(!1),R(1),B({x:0,y:0}),se.current&&clearTimeout(se.current),ce.current&&clearInterval(ce.current),oe.current&&(oe.current.src=``),m===`stream`&&ye(),setTimeout(()=>{h(e),E(Date.now()),O(!1)},100))},xe=()=>{D||(O(!0),w(!0),S(!1),M(0),P(!1),se.current&&clearTimeout(se.current),ce.current&&clearInterval(ce.current),oe.current&&(oe.current.src=``),m===`stream`&&ye(),setTimeout(()=>{E(Date.now()),O(!1)},100))},Se=()=>{U.current&&(document.fullscreenElement?document.exitFullscreen():U.current.requestFullscreen())},Ce=()=>{R(e=>Math.min(e+.5,4))},we=()=>{R(e=>{let t=Math.max(e-.5,1);return t===1&&B({x:0,y:0}),t})},Te=e=>{e.preventDefault(),e.deltaY<0?Ce():we()},Ee=e=>{L>1&&(e.preventDefault(),ee(!0),ne({x:e.clientX-z.x,y:e.clientY-z.y}))},De=(0,y.useCallback)(()=>{if(!U.current)return{x:300,y:200};let e=U.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]),Oe=e=>{if(V&&L>1){let t=e.clientX-te.x,n=e.clientY-te.y,r=De();B({x:Math.max(-r.x,Math.min(r.x,t)),y:Math.max(-r.y,Math.min(r.y,n))})}},ke=()=>{ee(!1)},Ae=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)},je=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},Me=e=>{e.touches.length===2?(e.preventDefault(),ie(Ae(e.touches)),ae(je(e.touches))):e.touches.length===1&&L>1&&(e.preventDefault(),ee(!0),ne({x:e.touches[0].clientX-z.x,y:e.touches[0].clientY-z.y}))},Ne=e=>{if(e.touches.length===2&&re!==null){e.preventDefault();let t=Ae(e.touches),n=t/re;R(e=>{let t=Math.max(1,Math.min(4,e*n));return t===1&&B({x:0,y:0}),t}),ie(t);let r=je(e.touches);if(H){let e=De();B(t=>({x:Math.max(-e.x,Math.min(e.x,t.x+(r.x-H.x))),y:Math.max(-e.y,Math.min(e.y,t.y+(r.y-H.y)))}))}ae(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=De();B({x:Math.max(-r.x,Math.min(r.x,t)),y:Math.max(-r.y,Math.min(r.y,n))})}},Pe=e=>{e.touches.length<2&&(ie(null),ae(null)),e.touches.length===0&&ee(!1)},Fe=()=>{R(1),B({x:0,y:0})},Ie=D||!p&&(i||f)?``:(e=>p?`${e}&token=${encodeURIComponent(p)}`:nd(e))(m===`stream`?`/api/v1/printers/${s}/camera/stream?fps=${u}&t=${T}`:`/api/v1/printers/${s}/camera/snapshot?t=${T}`),Le=C||D||N;return s?(0,K.jsxs)(`div`,{ref:U,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)(Zo,{className:`w-4 h-4`}),de?.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:()=>be(`stream`),disabled:Le,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:()=>be(`snapshot`),disabled:Le,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:()=>pe.mutate(!fe?.chamber_light),disabled:!fe?.connected||pe.isPending||!r(`printers:control`),className:`p-1.5 rounded disabled:opacity-50 ${fe?.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:fe?.chamber_light??!1,className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>_(!0),disabled:!me||!r(`printers:control`),className:`p-1.5 rounded disabled:opacity-50 ${me&&r(`printers:control`)?`hover:bg-bambu-dark-tertiary`:``}`,title:r(`printers:control`)?e(me?`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:xe,disabled:Le,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)(jl,{className:`w-4 h-4 text-bambu-gray ${Le?`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)(du,{className:`w-4 h-4 text-bambu-gray`})}),(0,K.jsx)(`button`,{onClick:Se,className:`p-1.5 hover:bg-bambu-dark-tertiary rounded`,title:e(k?`camera.exitFullscreen`:`camera.fullscreen`),children:k?(0,K.jsx)(il,{className:`w-4 h-4 text-bambu-gray`}):(0,K.jsx)(el,{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:Te,onMouseMove:Oe,onMouseUp:ke,onMouseLeave:ke,onTouchStart:Me,onTouchMove:Ne,onTouchEnd:Pe,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)(jl,{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)(zu,{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,h9),max:h9})}),(0,K.jsx)(`button`,{onClick:xe,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)(Eu,{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:xe,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:oe,src:Ie,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(${de?.camera_rotation||0}deg)`,...de?.camera_rotation===90||de?.camera_rotation===270?{maxWidth:`100vh`,maxHeight:`100vw`}:{},cursor:L>1?V?`grabbing`:`grab`:`default`},onError:Ie?_e:void 0,onLoad:Ie?ve:void 0,onMouseDown:Ee,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:we,disabled:L<=1,className:`p-1.5 hover:bg-white/10 rounded disabled:opacity-30`,title:e(`camera.zoomOut`),children:(0,K.jsx)(qu,{className:`w-4 h-4 text-white`})}),(0,K.jsxs)(`button`,{onClick:Fe,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:Ce,disabled:L>=4,className:`p-1.5 hover:bg-white/10 rounded disabled:opacity-30`,title:e(`camera.zoomIn`),children:(0,K.jsx)(Gu,{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:de?.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 nZe=5e3,rZe=4,iZe=8,aZe=1,oZe=16,sZe=2,cZe=60;function lZe(e,t,n,r){let i=parseInt(e??``,10);return Number.isFinite(i)?Math.min(r,Math.max(n,i)):t}function uZe(e,t,n,r,i,a){return e.has(t)?lZe(e.get(t),r,i,a):lZe(localStorage.getItem(n),r,i,a)}function dZe(){let{t:e}=W(),t=Xn(),{authEnabled:n,loading:r,user:i}=_d(),[a]=Mi(),o=a.get(`token`),s=o!=null&&o!==``,[c,l]=(0,y.useState)(()=>uZe(a,`maxLive`,`camWallMaxLive`,rZe,aZe,oZe)),[u,d]=(0,y.useState)(()=>uZe(a,`interval`,`camWallSnapshotSec`,iZe,sZe,cZe)),[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 ed(o),()=>ed(null)},[s,o]);let m=q({queryKey:[`camwall-printers`,o],queryFn:()=>Q.getCamWallPrinters(o??void 0),enabled:s,refetchInterval:nZe}),h=q({queryKey:[`printers`],queryFn:()=>Q.getPrinters(),enabled:!s&&!r&&(!n||i!==null),refetchInterval:nZe}),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)(Or,{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 fZe(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 pZe(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`)}}function mZe(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 hZe(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 gZe(){let{printerId:e}=ir(),[t]=Mi(),{t:n}=W(),r=no(),i=parseInt(e||`0`,10),[a,o]=(0,y.useState)(Date.now()),s=(0,y.useMemo)(()=>pZe(t),[t]),c=hZe(s.size),{data:l}=q({queryKey:[`printer`,i],queryFn:()=>Q.getPrinter(i),enabled:i>0}),{data:u}=q({queryKey:[`printerStatus`,i],queryFn:()=>Q.getPrinterStatus(i),enabled:i>0,refetchInterval:2e3}),{data:d}=q({queryKey:[`settings`],queryFn:Q.getSettings}),f=d?.time_format||`system`;(0,y.useEffect)(()=>{if(!i)return;let e=null,t=!1;return(async()=>{let n;try{n=(await Q.getWebSocketToken()).token}catch(e){let t=e instanceof Yu?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,r]),(0,y.useEffect)(()=>(document.title=l?`${l.name} - ${n(`streamOverlay.title`)}`:n(`streamOverlay.title`),()=>{document.title=`Bambuddy`}),[l,n]);let p=()=>{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(!u)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 m=u.state===`RUNNING`||u.state===`PAUSE`,h=u.progress||0,g=nd(`/api/v1/printers/${i}/camera/stream?fps=${s.fps}&t=${a}`);return(0,K.jsxs)(`div`,{className:`min-h-screen bg-black relative overflow-hidden`,children:[s.showCamera&&(0,K.jsx)(`img`,{src:g,alt:n(`streamOverlay.cameraStream`),className:`absolute inset-0 w-full h-full object-contain`,style:l?.camera_rotation?{transform:`rotate(${l.camera_rotation}deg)`}:void 0,onError:p},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&&l&&(0,K.jsxs)(`div`,{className:`flex items-center ${c.gap} mb-2`,children:[(0,K.jsx)(Ol,{className:`${c.icon} text-white/70`}),(0,K.jsx)(`span`,{className:`${c.text} text-white font-medium`,children:l.name})]}),s.showFilename&&u.current_print&&(0,K.jsx)(`div`,{className:`${c.textLarge} text-white font-semibold mb-2 truncate drop-shadow-md`,children:fZe(u.current_print.replace(/\.gcode\.3mf$|\.3mf$|\.gcode$/i,``),u.gcode_file,n)}),s.showStatus&&(0,K.jsx)(`div`,{className:`${c.text} text-white/70 mb-2`,children:mZe(u,n)}),s.showProgress&&m&&(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(h),`%`]})]}),(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:`${h}%`}})})]}),m&&(s.showLayers||s.showEta)&&(0,K.jsxs)(`div`,{className:`flex items-center ${c.gap} flex-wrap`,children:[s.showLayers&&u.layer_num!=null&&u.total_layers!=null&&u.total_layers>0&&(0,K.jsxs)(`div`,{className:`flex items-center ${c.gap} text-white/70`,children:[(0,K.jsx)(Rc,{className:c.icon}),(0,K.jsxs)(`span`,{className:c.text,children:[(0,K.jsx)(`span`,{className:`text-white`,children:u.layer_num}),(0,K.jsx)(`span`,{className:`mx-1`,children:`/`}),(0,K.jsx)(`span`,{children:u.total_layers})]})]}),s.showEta&&u.remaining_time!=null&&u.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)(Su,{className:c.icon}),(0,K.jsx)(`span`,{className:`${c.text} text-white`,children:Pf(u.remaining_time*60)})]}),(0,K.jsxs)(`div`,{className:`flex items-center ${c.gap} text-white/70`,children:[(0,K.jsx)(xs,{className:c.icon}),(0,K.jsxs)(`span`,{className:`${c.text} text-white`,children:[n(`streamOverlay.eta`),` `,Nf(u.remaining_time,f,n)]})]})]})]}),!m&&(0,K.jsx)(`div`,{className:`${c.text} text-white/70 py-2`,children:u.connected?n(`streamOverlay.printerIdle`):n(`streamOverlay.printerOffline`)})]})})]})}function _Ze(){let{t:e}=W(),{id:t}=ir(),{mode:n}=bd(),{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)(Eu,{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 vZe(){let{id:e}=ir(),t=$n(),n=no(),{t:r}=W(),{showToast:i}=jd(),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)(jo,{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)(Eu,{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)(Vl,{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)(Cd,{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)(ns,{className:`w-3 h-3 text-white`}),o&&!a&&(0,K.jsx)(al,{className:`w-3 h-3 text-white`})]}),(0,K.jsx)(Xl,{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)(Il,{className:`w-4 h-4`}),r(`common.save`)]})})]})]})}var yZe=1.65,bZe=[`#1DB954`,`#3B82F6`,`#F59E0B`,`#EF4444`,`#8B5CF6`];function g9(e,t,n,r){return`${e}||${t??``}||${n??``}||${r??``}`}function _9(e,t){let n=new Date(e);return n.setDate(n.getDate()+Math.round(t)),n}function v9(e){return e.toLocaleDateString(void 0,{month:`short`,day:`numeric`,year:`numeric`})}function y9(e){return e.toLocaleDateString(void 0,{month:`short`,day:`numeric`})}function xZe(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 SZe(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(g9(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=g9(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(g9(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=xZe(u);if(m!==null)d=m.rate,f=m.stdDev,p=`history`;else{let e=SZe(t.spools);e!==null&&(d=e,p=`delta`)}let h=yZe*(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:_9(e,_),y=d&&d>0?Math.floor((s-g)/d):null,b=y===null?null:_9(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)(qc,{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)(Eu,{className:`w-4 h-4`}),r(`forecast.alertCount`,{count:L.length}),c?(0,K.jsx)(ss,{className:`w-3.5 h-3.5`}):(0,K.jsx)(rs,{className:`w-3.5 h-3.5`})]}),s&&(0,K.jsx)(OZe,{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)(Zl,{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)(TZe,{forecast:e,onCart:()=>b(e)},e.group.key))}),x&&(0,K.jsx)(NZe,{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)(DZe,{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)(wu,{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)(b9,{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)(b9,{col:`stock`,active:u,dir:f,onSort:z,children:r(`forecast.stock`)}),(0,K.jsx)(b9,{col:`used`,active:u,dir:f,onSort:z,children:r(`forecast.dailyRate`)}),(0,K.jsx)(b9,{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)(kZe,{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)(FZe,{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 b9({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)(Io,{className:`w-3 h-3 ml-1 text-bambu-green`}):(0,K.jsx)(Ao,{className:`w-3 h-3 ml-1 text-bambu-green`}):(0,K.jsx)(Po,{className:`w-3 h-3 ml-1 opacity-40`})]})})}function TZe({forecast:e,onCart:t}){let{t:n}=W(),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)(Eu,{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?v9(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)(Zl,{className:`w-3 h-3`}),` `,n(`forecast.order`)]})]})}var EZe=[{label:`1W`,value:7},{label:`1M`,value:30},{label:`6M`,value:180}];function DZe({forecasts:e,days:t,onDaysChange:n}){let{t:r}=W(),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:bZe[n%bZe.length],rop:e.reorderPointG,points:CZe(e,t)})),o=i.map(e=>{let t={day:e,label:y9(_9(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)(wu,{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:EZe.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)(DA,{width:`100%`,height:220,children:(0,K.jsxs)(uU,{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)(NV,{strokeDasharray:`3 3`,stroke:`#374151`,strokeOpacity:.5}),(0,K.jsx)(bH,{dataKey:`label`,tick:{fill:`#6B7280`,fontSize:10},interval:Math.max(0,Math.ceil(s/8)-1),axisLine:!1,tickLine:!1}),(0,K.jsx)(TH,{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)(gz,{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)(Tj,{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)(QV,{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)(vV,{y:e.rop,stroke:e.color,strokeDasharray:`4 3`,strokeOpacity:.6},`rop-${e.key}`))]})})]})}function OZe({value:e,onSave:t}){let{t:n}=W(),[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)(Pc,{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)(bl,{className:`w-3 h-3`})})]})]})}function kZe({forecast:e,globalLeadTime:t,canWrite:n,onSaved:r,onCart:i,showToast:a}){let{t:o}=W(),[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?rf(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?v9(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?v9(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)(Zl,{className:`w-4 h-4`})}),!x&&(e.stockBreakAlert?(0,K.jsx)(Eu,{className:`w-4 h-4 text-red-600 dark:text-red-400`,"aria-label":o(`forecast.stockBreakRisk`)}):e.reorderAlert?(0,K.jsx)(Eu,{className:`w-4 h-4 text-yellow-600 dark:text-yellow-400`,"aria-label":o(`forecast.reorderNow`)}):e.daysRemaining===null?null:(0,K.jsx)(ns,{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)(zo,{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)(ss,{className:`w-4 h-4`}):(0,K.jsx)(rs,{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)(AZe,{label:o(`forecast.effectiveLeadTime`),value:`${e.effectiveLeadTimeDays}d`,hint:o(`forecast.effectiveLeadTimeHint`,{global:t,sku:e.settings?.lead_time_days??0})}),(0,K.jsx)(AZe,{label:o(`forecast.reorderPoint`),value:`${Math.round(e.reorderPointG)}g`,hint:o(`forecast.reorderPointHint`)}),n&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(jZe,{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)(MZe,{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 AZe({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 jZe({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)(Pc,{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)(bl,{className:`w-3 h-3`})})]})]})}function MZe({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}=W(),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)(Pc,{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)(bl,{className:`w-3 h-3`})})]})]})}function NZe({items:e,forecasts:t,globalLeadTime:n,canWrite:r,onClose:i,onRemove:a,onClear:o}){let{t:s}=W(),c=no(),[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(g9(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(g9(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?v9(_9(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)(Zl,{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)(ml,{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)(es,{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)(Vs,{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)(Wu,{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)(ml,{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(g9(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?_9(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)(Eu,{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?v9(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)(Nl,{className:`w-4 h-4`}):(0,K.jsx)(Ps,{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)(fl,{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)(Cu,{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)(PZe,{item:e,forecast:t,globalLeadTime:n,canWrite:r,onRemove:()=>a(e.id)},e.id))})]})}function PZe({item:e,forecast:t,globalLeadTime:n,canWrite:r,onRemove:i}){let{t:a}=W(),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=y9(_9(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)(gz,{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)(QV,{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)(vV,{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)(vV,{y:t.safetyStockG,stroke:`#6B7280`,strokeDasharray:`3 3`,strokeOpacity:.6,label:{value:`SS`,position:`insideTopRight`,fill:`#6B7280`,fontSize:9}}),(0,K.jsx)(vV,{x:y9(_9(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)(vV,{x:y9(_9(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 FZe({forecast:e,onClose:t,onAdd:n}){let{t:r}=W(),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)(Zl,{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)(Wu,{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 x9={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},IZe=new Set([`material`,`subtype`,`brand`,`rgba`,`color_name`,`label_weight`]);function LZe(e,t=!1,n=!1){let r={};return t||n?(!e.material&&!e.spoolman_filament_id&&(r.material=`Material is required`),{isValid:Object.keys(r).length===0,errors:r}):(e.slicer_filament||(r.slicer_filament=`Slicer preset is required`),e.material||(r.material=`Material is required`),e.brand||(r.brand=`Brand is required`),e.subtype||(r.subtype=`Subtype is required`),{isValid:Object.keys(r).length===0,errors:r})}function RZe({formData:e,updateField:t,cloudAuthenticated:n,loadingCloudPresets:r,presetInputValue:i,setPresetInputValue:a,selectedPresetOption:o,filamentOptions:s,availableBrands:c,availableMaterials:l,quickAdd:u,quantity:d,onQuantityChange:f,errors:p}){let{t:m}=W(),[h,g]=(0,y.useState)(!1),[_,v]=(0,y.useState)(!1),[b,x]=(0,y.useState)(!1),[S,C]=(0,y.useState)(!1),[w,T]=(0,y.useState)(``),[E,D]=(0,y.useState)(``),[O,k]=(0,y.useState)(``),[A,j]=(0,y.useState)(String(e.label_weight)),[M,N]=(0,y.useState)(!1),P=(0,y.useRef)(null),F=(0,y.useRef)(null),I=(0,y.useRef)(null),L=(0,y.useRef)(null);(0,y.useEffect)(()=>{let e=e=>{P.current&&!P.current.contains(e.target)&&g(!1),L.current&&!L.current.contains(e.target)&&C(!1),F.current&&!F.current.contains(e.target)&&v(!1),I.current&&!I.current.contains(e.target)&&x(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[]);let R=(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]),z=(0,y.useMemo)(()=>{if(!w)return c;let e=w.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,w]),B=(0,y.useMemo)(()=>{if(!E)return OU;let e=E.toLowerCase();return OU.filter(t=>t.toLowerCase().includes(e))},[E]),V=(0,y.useMemo)(()=>{if(!O)return l;let e=O.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)})},[O,l]);(0,y.useEffect)(()=>{M||j(String(e.label_weight))},[e.label_weight,M]);let ee=e=>{t(`slicer_filament`,e.code),a(e.displayName),g(!1);let n=MU(e.name);n.material&&t(`material`,n.material),n.brand&&t(`brand`,n.brand),n.variant&&t(`subtype`,n.variant)};return(0,K.jsxs)(`div`,{className:`space-y-4`,children:[!u&&(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`}),` `,m(`inventory.loadingPresets`)]}):n?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(ws,{className:`w-3 h-3 text-bambu-green`}),` `,m(`inventory.cloudConnected`)]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Ss,{className:`w-3 h-3`}),` `,m(`inventory.cloudNotConnected`)]})}),!u&&(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:[m(`inventory.slicerPreset`),` *`]}),(0,K.jsxs)(`div`,{className:`relative`,ref:P,children:[(0,K.jsx)(Vl,{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:m(`inventory.searchPresets`),value:i,onChange:e=>{a(e.target.value),g(!0)},onFocus:()=>{g(!0),a(``)}}),h&&(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:R.length===0?(0,K.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:m(`inventory.noPresetsFound`)}):R.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:()=>ee(e),children:e.displayName},`${e.code}::${e.name}`))})]}),o&&(0,K.jsxs)(`div`,{className:`mt-1 text-xs text-bambu-gray`,children:[m(`inventory.selectedPreset`),`: `,(0,K.jsx)(`span`,{className:`font-mono text-bambu-green`,children:o.code})]}),p?.slicer_filament&&(0,K.jsx)(`p`,{className:`mt-1 text-xs text-red-700 dark:text-red-400`,children:p.slicer_filament})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:[m(`inventory.material`),` *`]}),(0,K.jsxs)(`div`,{className:`relative`,ref:L,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:m(`inventory.selectMaterial`),value:S?O:e.material,onChange:e=>{k(e.target.value),C(!0)},onFocus:()=>{C(!0),k(``)}}),(0,K.jsx)(rs,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50 pointer-events-none`}),S&&(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:[V.length===0?(0,K.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:m(`inventory.noResults`)}):V.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.material===n?`bg-bambu-green/10 text-bambu-green`:`text-white`}`,onClick:()=>{t(`material`,n),C(!1),k(``)},children:n},n)),O&&!V.includes(O)&&(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(`material`,O),C(!1),k(``)},children:m(`inventory.useCustomMaterial`,{material:O})})]})]}),p?.material&&(0,K.jsx)(`p`,{className:`mt-1 text-xs text-red-700 dark:text-red-400`,children:p.material})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:[m(`inventory.brand`),!u&&` *`]}),(0,K.jsxs)(`div`,{className:`relative`,ref:F,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:m(`inventory.searchBrand`),value:_?w:e.brand,onChange:e=>{T(e.target.value),v(!0)},onFocus:()=>{v(!0),T(``)}}),(0,K.jsx)(rs,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50 pointer-events-none`}),_&&(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:[z.length===0?(0,K.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:m(`inventory.noResults`)}):z.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.brand===n?`bg-bambu-green/10 text-bambu-green`:`text-white`}`,onClick:()=>{t(`brand`,n),v(!1),T(``)},children:n},n)),w&&!z.includes(w)&&(0,K.jsx)(`button`,{type:`button`,className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary text-bambu-green border-t border-bambu-dark-tertiary`,onClick:()=>{t(`brand`,w),v(!1),T(``)},children:m(`inventory.useCustomBrand`,{brand:w})})]})]}),p?.brand&&(0,K.jsx)(`p`,{className:`mt-1 text-xs text-red-700 dark:text-red-400`,children:p.brand})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:[m(`inventory.subtype`),!u&&` *`]}),(0,K.jsxs)(`div`,{className:`relative`,ref:I,children:[(0,K.jsx)(`input`,{type:`text`,value:b?E:e.subtype,onChange:e=>{D(e.target.value),x(!0)},onFocus:()=>{x(!0),D(``)},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)(rs,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50 pointer-events-none`}),b&&(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:[B.length===0?(0,K.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:m(`inventory.noResults`)}):B.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.subtype===n?`bg-bambu-green/10 text-bambu-green`:`text-white`}`,onClick:()=>{t(`subtype`,n),x(!1),D(``)},children:n},n)),E&&!OU.some(e=>e.toLowerCase()===E.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:()=>{t(`subtype`,E),x(!1),D(``)},children:m(`inventory.useCustomBrand`,{brand:E})})]})]}),p?.subtype&&(0,K.jsx)(`p`,{className:`mt-1 text-xs text-red-700 dark:text-red-400`,children:p.subtype})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:m(`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:A,min:0,onFocus:()=>N(!0),onChange:e=>j(e.target.value),onBlur:()=>{N(!1);let n=A.trim(),r=Number(n);if(!n||!Number.isFinite(r)||r<0){j(String(e.label_weight));return}let i=Math.round(r);t(`label_weight`,i),j(String(i))}}),(0,K.jsx)(`span`,{className:`absolute right-2 top-1/2 -translate-y-1/2 text-xs text-bambu-gray`,children:`g`})]})]}),u&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:m(`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:d,min:1,max:100,onChange:e=>{f(Math.max(1,Math.min(100,parseInt(e.target.value)||1)))}})]})]})}function zZe(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 BZe({formData:e,updateField:t,recentColors:n,onColorUsed:r,catalogColors:i}){let{t:a}=W(),[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=>rf(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?AU.filter(e=>e.name.toLowerCase().includes(c.toLowerCase())):o?AU:kU,[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)(()=>t6({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}=zZe(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)(xs,{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)(Vl,{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)(ss,{className:`w-3 h-3`})]}):(0,K.jsxs)(K.Fragment,{children:[a(`inventory.showAll`),` `,(0,K.jsx)(rs,{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)(ou,{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:Q3.map(e=>(0,K.jsx)(`option`,{value:e.value,children:a(e.labelKey)},e.value||`none`))}),(0,K.jsx)(n6,{rgba:e.rgba,extraColors:e.extra_colors,effectType:e.effect_type,subtype:e.subtype,effectSize:`preview`,className:`w-10 h-10`,shape:`square`})]})]})]})]})}function VZe({catalog:e,value:t,onChange:n,catalogId:r,onCatalogIdChange:i}){let{t:a}=W(),[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)(Ll,{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 HZe({formData:e,updateField:t,spoolCatalog:n,currencySymbol:r,availableCategories:i,availableLocations:a=[],onCreateLocation:o,globalLowStockThreshold:s,spoolmanMode:c=!1}){let{t:l}=W(),{showToast:u}=jd(),[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)(VZe,{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 UZe({filaments:e,isLoading:t,selectedId:n,onSelect:r}){let{t:i}=W(),[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)(ml,{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)(rs,{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 WZe({formData:e,printersWithCalibrations:t,selectedProfiles:n,setSelectedProfiles:r,expandedPrinters:i,setExpandedPrinters:a}){let{t:o}=W(),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.jsx)(`div`,{className:`flex items-center gap-2 shrink-0`,children:(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)(ou,{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)(rs,{className:`w-4 h-4 text-bambu-gray`}):(0,K.jsx)(is,{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 GZe(e){let t=kf(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 KZe={completed:`text-bambu-green`,failed:`text-red-700 dark:text-red-400`,aborted:`text-yellow-700 dark:text-yellow-400`};function qZe({spoolId:e}){let{t}=W(),n=no(),{showToast:r}=jd(),{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)(xs,{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)(Cu,{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:GZe(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:KZe[e.status]||`text-bambu-gray`,children:e.status})]})]},e.id))})]})}var S9=[`inventory-locations`];function C9(e){return e.invalidateQueries({queryKey:S9})}function JZe(e,t){return Promise.all([e.invalidateQueries({queryKey:[...t]}),C9(e)])}var YZe={tag_uid:null,tray_uuid:null,tag_type:null,data_origin:null};function XZe({isOpen:e,onClose:t,spool:n,mode:r,printersWithCalibrations:i=[],currencySymbol:a,onSpoolsCreated:o,spoolmanMode:s=!1,spoolsQueryKey:c=[`inventory-spools`]}){let{t:l}=W(),u=no(),{showToast:d}=jd(),f=()=>JZe(u,c),p=r===`edit`,m=r===`copy`,[h,g]=(0,y.useState)(x9),[_,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)([]),[ne,re]=(0,y.useState)([]),[ie,H]=(0,y.useState)([]),[ae,oe]=(0,y.useState)([]),[U,se]=(0,y.useState)([]),[ce,le]=(0,y.useState)(new Set),[ue,de]=(0,y.useState)(new Set),fe=i.length>0?i:U,pe=ce.size,{data:me=[],isLoading:he,error:ge}=q({queryKey:[`spoolman-inventory-filaments`],queryFn:()=>Q.getSpoolmanInventoryFilaments(),enabled:s&&e,staleTime:6e4,retry:!1});(0,y.useEffect)(()=>{oe(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(H).catch(console.error),Q.getLocalPresets().then(e=>te(e.filament)).catch(console.error),Q.getBuiltinFilaments().then(re).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({cali_idx:e.slot_id,filament_id:e.filament_id,setting_id:e.setting_id||``,name:e.name,k_value:parseFloat(e.k_value)||0,n_coef:parseFloat(e.n_coef)||0,extruder_id:e.extruder_id,nozzle_diameter:e.nozzle_diameter}))}catch{}n.push({printer:{...i,connected:a},calibrations:o})}se(n)}catch(e){console.error(`Failed to fetch printer calibrations:`,e)}})()),()=>{t=!0}},[e,i.length]);let _e=(0,y.useMemo)(()=>PU(P,new Set,ee,ne),[P,ee,ne]),ve=(0,y.useMemo)(()=>{let e=NU(P,ee),t=ie.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,ie]),ye=(0,y.useMemo)(()=>{let e=ie.map(e=>e.material?.trim()).filter(e=>!!e),t=new Set([...EU,...e]);return Array.from(t).sort((e,t)=>e.localeCompare(t))},[ie]),be=(0,y.useMemo)(()=>{let e=[];for(let t of ie){let n=t.manufacturer?.trim(),r=t.material?.trim();n&&r&&e.push({brand:n,material:r})}for(let t of P){let n=MU(t.name);n.brand&&n.material&&e.push({brand:n.brand,material:n.material})}for(let t of ee){let n=MU(t.name),r=t.filament_vendor?.trim()||n.brand,i=n.material;r&&i&&e.push({brand:r,material:i})}return e},[P,ie,ee]),xe=(0,y.useMemo)(()=>{let e=new Map;for(let t of be){let n=t.brand.toLowerCase(),r=t.material.toLowerCase();e.has(n)||e.set(n,new Set),e.get(n).add(r)}return e},[be]),Se=(0,y.useMemo)(()=>{let e=new Map;for(let t of be){let n=t.brand.toLowerCase(),r=t.material.toLowerCase();e.has(r)||e.set(r,new Set),e.get(r).add(n)}return e},[be]),Ce=(0,y.useMemo)(()=>{if(!h.material)return ve;let e=h.material.toLowerCase(),t=Se.get(e);return!t||t.size===0?ve:ve.filter(e=>t.has(e.toLowerCase()))},[ve,h.material,Se]),we=(0,y.useMemo)(()=>{if(!h.brand)return ye;let e=h.brand.toLowerCase(),t=xe.get(e);return!t||t.size===0?ye:ye.filter(e=>t.has(e.toLowerCase()))},[ye,h.brand,xe]),Te=(0,y.useMemo)(()=>FU(h.slicer_filament,_e),[h.slicer_filament,_e]);(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`}`);le(e)}else le(new Set)}else g(x9),L(``),le(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&&fe.length>0&&de(new Set(fe.map(e=>String(e.printer.id))))},[e,fe]);let Ee=(e,t)=>{let n=IZe.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}))},De=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`)},Oe=e=>{oe(t=>LU(e,t))},ke=J({mutationFn:e=>s?Q.createSpoolmanInventorySpool(e):Q.createSpool(e),onSuccess:async e=>{e?.id&&!await Ve(e.id)||(await f(),o&&o([e]),d(l(`inventory.spoolCreated`),`success`),t())},onError:e=>{e instanceof Yu&&e.status===503?d(l(`inventory.spoolmanUnreachable`),`error`):d(l(`inventory.saveFailed`),`error`)}}),Ae=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(ce.size>0)for(let e of r)await Ve(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 Yu&&e.status===503?d(l(`inventory.spoolmanUnreachable`),`error`):d(l(`inventory.saveFailed`),`error`)}}),je=J({mutationFn:e=>s?Q.updateSpoolmanInventorySpool(n.id,e):Q.updateSpool(n.id,e),onSuccess:async()=>{n?.id&&!await Ve(n.id)||(await f(),d(l(`inventory.spoolUpdated`),`success`),t())},onError:e=>{e instanceof Yu&&e.status===503?d(l(`inventory.spoolmanUnreachable`),`error`):d(l(`inventory.saveFailed`),`error`)}}),Me=J({mutationFn:()=>s?Q.updateSpoolmanInventorySpool(n.id,YZe):Q.updateSpool(n.id,YZe),onSuccess:async()=>{await f(),d(l(`inventory.rfidCleared`,`RFID tag cleared`),`success`),t()},onError:e=>{e instanceof Yu&&e.status===503?d(l(`inventory.spoolmanUnreachable`),`error`):d(l(`inventory.tagClearFailed`),`error`)}}),{data:Ne}=q({queryKey:[`spool-assignments`],queryFn:()=>Q.getAssignments(),enabled:e&&p&&!s}),{data:Pe}=q({queryKey:[`spoolman-slot-assignments-all`],queryFn:()=>Q.getSpoolmanSlotAssignments(),enabled:e&&p&&s}),Fe=(()=>{if(n)return s?Pe?.find(e=>e.spoolman_spool_id===n.id):Ne?.find(e=>e.spool_id===n.id)})(),{data:Ie}=q({queryKey:[`inventory-spools`],queryFn:()=>Q.getSpools(!0),enabled:e}),{data:Le}=q({queryKey:[`settings`],queryFn:Q.getSettings,enabled:e}),Re=(()=>{let e=new Set;for(let t of Ie??[]){let n=t.category?.trim();n&&e.add(n)}return Array.from(e).sort((e,t)=>e.localeCompare(t))})(),ze=Le?.low_stock_threshold??20,Be=J({mutationFn:async()=>{if(!Fe)throw Error(`No assignment`);if(s){if(!n)throw Error(`No spool`);await Q.unassignSpoolmanSlot(n.id);return}await Q.unassignSpool(Fe.printer_id,Fe.ams_id,Fe.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`)}}),Ve=async e=>{let t=s?Q.saveSpoolmanKProfiles:Q.saveSpoolKProfiles;if(ce.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 ce){let[t,i,a]=e.split(`:`),o=parseInt(t),s=parseInt(i),c=a===`null`?0:parseInt(a),l=fe.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(ce)),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 He=()=>{let e=LZe(h,E,s);if(!e.isValid){v(e.errors),(e.errors.slicer_filament||e.errors.material||e.errors.brand||e.errors.subtype)&&x(`filament`);return}let t=Te?.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?je.mutate(n):O>1?Ae.mutate({data:n,qty:O}):ke.mutate(n)},Ue=ke.isPending||Ae.isPending||je.isPending||Me.isPending||Be.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)(Wu,{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)(Ku,{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)(hl,{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)(Ro,{className:`w-4 h-4`}),l(`inventory.paProfileTab`),pe>0&&(0,K.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded-full bg-bambu-green/20 text-bambu-green`,children:pe})]})]}),(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:ge?(0,K.jsx)(`p`,{className:`text-sm text-red-700 dark:text-red-400 px-1`,children:l(`inventory.spoolmanCatalogLoadFailed`)}):(0,K.jsx)(UZe,{filaments:me,isLoading:he,selectedId:h.spoolman_filament_id,onSelect:De})}),(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)(RZe,{formData:h,updateField:Ee,cloudAuthenticated:A,loadingCloudPresets:M,presetInputValue:I,setPresetInputValue:L,selectedPresetOption:Te,filamentOptions:_e,availableBrands:Ce,availableMaterials:we,quickAdd:E,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)(BZe,{formData:h,updateField:Ee,recentColors:ae,onColorUsed:Oe,catalogColors:ie})]}),(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)(HZe,{formData:h,updateField:Ee,spoolCatalog:R,currencySymbol:a,availableCategories:Re,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 C9(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:ze,spoolmanMode:s})]}),p&&n&&!s&&(0,K.jsx)(`div`,{children:(0,K.jsx)(qZe,{spoolId:n.id})})]}):(0,K.jsx)(WZe,{formData:h,updateField:Ee,printersWithCalibrations:fe,selectedProfiles:ce,setSelectedProfiles:le,expandedPrinters:ue,setExpandedPrinters:de})}),(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:()=>Me.mutate(),disabled:Ue||!n?.tag_uid,children:[(0,K.jsx)(hu,{className:`w-4 h-4`}),l(`inventory.clearRfid`,`Clear RFID Tag`)]}),(0,K.jsxs)($,{variant:`secondary`,onClick:()=>Be.mutate(),disabled:Ue||!Fe,children:[(0,K.jsx)(ku,{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:He,disabled:Ue,children:Ue?(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)(Il,{className:`w-4 h-4`}),l(p?`common.save`:m?`inventory.copySpool`:`inventory.addSpool`)]})})]})]})]})]})}function ZZe({isOpen:e,onClose:t,columns:n,defaultColumns:r,onSave:i}){let{t:a}=W(),[o,s]=(0,y.useState)(n),[c,l]=(0,y.useState)(null),u=(0,y.useRef)(null);if((0,y.useEffect)(()=>{e&&s(n.map(e=>({...e})))},[e,n]),(0,y.useEffect)(()=>{if(!e)return;let n=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,n),()=>window.removeEventListener(`keydown`,n)},[e,t]),!e)return null;let d=e=>{s(t=>t.map((t,n)=>n===e?{...t,visible:!t.visible}:t))},f=(e,t)=>{t<0||t>=o.length||s(n=>{let r=[...n],[i]=r.splice(e,1);return r.splice(t,0,i),r})},p=(e,t)=>{u.current=t,l(t),e.dataTransfer.effectAllowed=`move`},m=(e,t)=>{e.preventDefault(),e.dataTransfer.dropEffect=`move`;let n=u.current;n!==null&&n!==t&&(f(n,t),u.current=t,l(t))},h=e=>{e.preventDefault()},g=()=>{u.current=null,l(null)},_=()=>{s(r.map(e=>({...e})))},v=()=>{i(o),t()},b=o.filter(e=>e.visible).length;return(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,onClick:t,children:(0,K.jsx)(Cd,{className:`w-full max-w-md max-h-[80vh] flex flex-col`,onClick:e=>e.stopPropagation(),children:(0,K.jsxs)(Td,{className:`p-6 flex flex-col min-h-0`,children:[(0,K.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-2`,children:a(`inventory.configureColumns`)}),(0,K.jsxs)(`p`,{className:`text-sm text-bambu-gray mb-4`,children:[a(`inventory.configureColumnsDesc`),(0,K.jsxs)(`span`,{className:`ml-2 text-bambu-gray/60`,children:[`(`,b,` `,a(`inventory.of`),` `,o.length,` `,a(`inventory.visible`),`)`]})]}),(0,K.jsx)(`div`,{className:`space-y-1 overflow-y-auto flex-1 min-h-0 pr-1`,children:o.map((e,t)=>(0,K.jsxs)(`div`,{className:`flex items-center gap-2 p-2 rounded-lg border transition-colors ${c===t?`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary bg-bambu-dark-tertiary/50`} ${e.visible?``:`opacity-50`}`,draggable:!0,onDragStart:e=>p(e,t),onDragOver:e=>m(e,t),onDrop:h,onDragEnd:g,children:[(0,K.jsx)(`div`,{className:`cursor-grab text-bambu-gray/50 hover:text-bambu-gray`,children:(0,K.jsx)(xc,{className:`w-4 h-4`})}),(0,K.jsx)(`span`,{className:`flex-1 font-medium text-sm text-white`,children:e.label}),(0,K.jsxs)(`div`,{className:`flex items-center gap-0.5`,children:[(0,K.jsx)(`button`,{onClick:()=>f(t,t-1),disabled:t===0,className:`p-1 rounded text-bambu-gray hover:bg-bambu-dark-secondary disabled:opacity-30 disabled:cursor-not-allowed`,title:a(`inventory.moveUp`),children:(0,K.jsx)(ss,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>f(t,t+1),disabled:t===o.length-1,className:`p-1 rounded text-bambu-gray hover:bg-bambu-dark-secondary disabled:opacity-30 disabled:cursor-not-allowed`,title:a(`inventory.moveDown`),children:(0,K.jsx)(rs,{className:`w-4 h-4`})})]}),(0,K.jsx)(`button`,{onClick:()=>d(t),className:`p-1.5 rounded transition-colors ${e.visible?`text-bambu-green hover:bg-bambu-green/10`:`text-bambu-gray/50 hover:bg-bambu-dark-secondary`}`,title:e.visible?a(`inventory.hideColumn`):a(`inventory.showColumn`),children:e.visible?(0,K.jsx)(Xs,{className:`w-4 h-4`}):(0,K.jsx)(Ys,{className:`w-4 h-4`})})]},e.id))}),(0,K.jsxs)(`div`,{className:`flex items-center gap-3 mt-4 pt-4 border-t border-bambu-dark-tertiary`,children:[(0,K.jsxs)($,{variant:`secondary`,onClick:_,className:`mr-auto`,children:[(0,K.jsx)(Nl,{className:`w-4 h-4`}),a(`inventory.reset`)]}),(0,K.jsx)($,{variant:`secondary`,onClick:t,children:a(`inventory.cancel`)}),(0,K.jsx)($,{onClick:v,children:a(`inventory.applyChanges`)})]})]})})})}var QZe=[{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 $Ze(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 eQe(e){return rf(e)}function tQe(e){return`${e.color_name??`${e.material}${e.subtype?` ${e.subtype}`:``}`}${e.brand?` · ${e.brand}`:``}`}function nQe(e){return[e.color_name,e.material,e.subtype,e.brand,`#${e.id}`].filter(Boolean).join(` `).toLowerCase()}function rQe(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 iQe({isOpen:e,onClose:t,availableSpools:n,initialSelectedIds:r,spoolmanMode:i}){let{t:a}=W(),{showToast:o}=jd(),[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=rQe(e.rgba),r=rQe(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&&!nQe(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{$Ze(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)(Ol,{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)(Wu,{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)(Vl,{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)(su,{className:`w-4 h-4 text-bambu-green shrink-0`}):(0,K.jsx)(lu,{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:eQe(e.rgba)}),(0,K.jsx)(`span`,{className:`flex-1 min-w-0 truncate text-sm text-white`,children:tQe(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)(su,{className:`w-4 h-4 text-bambu-green shrink-0`}):(0,K.jsx)(lu,{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:QZe.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 aQe({onClose:e,onImported:t}){let{t:n}=W(),[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)(fs,{className:`w-4 h-4 text-green-500 flex-shrink-0`}):e===`error`?(0,K.jsx)(vs,{className:`w-4 h-4 text-red-500 flex-shrink-0`}):(0,K.jsx)(hs,{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)(Wu,{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)(Au,{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)(nc,{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)(vs,{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:rf(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)(Lu,{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)(Eu,{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)(Ms,{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 oQe({open:e,onClose:t,onPickLocation:n}){let{t:r}=W(),i=no(),{showToast:a}=jd(),[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:S9,queryFn:Q.getLocations,enabled:e}),g=()=>{C9(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)(Zc,{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)(Tl,{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)(Wu,{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)(xl,{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)(Cu,{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)(zd,{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 w9=[{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 sQe({value:e,onChange:t,options:n,allowCustom:r,placeholderKey:i,disabled:a}){let{t:o}=W(),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)(rs,{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 T9(...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 cQe({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}=W(),{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)(()=>PU(p,new Set,m?.filament??[],h),[p,m,h]),[_,v]=(0,y.useState)({}),b=(0,y.useMemo)(()=>T9(EU,i).map(e=>({value:e,label:e})),[i]),x=(0,y.useMemo)(()=>T9(OU,a).map(e=>({value:e,label:e})),[a]),S=(0,y.useMemo)(()=>T9(DU,o).map(e=>({value:e,label:e})),[o]),C=(0,y.useMemo)(()=>T9(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 w9){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=w9.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)(sQe,{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)(Wu,{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:w9.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 lQe(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 E9(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 uQe(e){return`${e.material}|${e.subtype||``}|${e.brand||``}|${e.color_name||``}|${e.rgba||``}|${e.extra_colors||``}|${e.effect_type||``}|${e.label_weight}`}var dQe=`bambuddy-inventory-columns`,D9=[{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 fQe(){try{let e=localStorage.getItem(dQe);if(e){let t=JSON.parse(e),n=new Set(D9.map(e=>e.id)),r=new Set(t.map(e=>e.id)),i=t.filter(e=>n.has(e.id)),a=D9.filter(e=>!r.has(e.id));return[...i,...a]}}catch{}return D9.map(e=>({...e}))}function pQe(e){try{localStorage.setItem(dQe,JSON.stringify(e))}catch{}}function O9(e,t=!1){return t&&e>=1e3?`${(e/1e3).toFixed(1)}kg`:`${Math.round(e)}g`}var mQe={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 k9(e,t=`system`){if(!e)return`-`;let n=kf(e);return n?xf(n,t):`-`}var hQe={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`)},A9={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:k9(e.created_at,t)}),encode_time:({spool:e,dateFormat:t})=>(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:k9(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?k9(e.last_used,t):`Never`}),rgba:({spool:e})=>(0,K.jsx)(`div`,{className:`flex items-center justify-center`,children:(0,K.jsx)(n6,{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:tf(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,` `,qf(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:O9(e.label_weight)}),net:({remaining:e})=>(0,K.jsx)(`span`,{className:`text-sm text-white`,children:O9(e)}),gross:({spool:e,remaining:t})=>(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:O9(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?O9(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)(ns,{className:`w-3 h-3`}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Eu,{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)(jl,{className:`w-3.5 h-3.5`})})]})]})}},j9={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(),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||``} ${qf(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)}},M9=`bambuddy-inventory-sort`;function gQe(){try{let e=localStorage.getItem(M9);if(e)return JSON.parse(e)}catch{}return null}function _Qe(e){try{e?localStorage.setItem(M9,JSON.stringify(e)):localStorage.removeItem(M9)}catch{}}function vQe(){let{data:e}=q({queryKey:[`spoolman-settings`],queryFn:Q.getSpoolmanSettings,staleTime:300*1e3}),t=e!==void 0;return(0,K.jsx)(yQe,{spoolmanMode:e?.spoolman_enabled===`true`&&!!e?.spoolman_url,spoolmanModeReady:t})}function yQe({spoolmanMode:e=!1,spoolmanModeReady:t=!0}){let{t:n}=W(),r=no(),{showToast:i}=jd(),{hasPermission:a,loading:o}=_d(),s=!o&&a(`inventory:forecast_read`),[c,l]=Mi(),[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)(gQe),[ne,re]=(0,y.useState)(fQe),[ie,H]=(0,y.useState)(!1),[ae,oe]=(0,y.useState)(()=>{try{return localStorage.getItem(`bambuddy-inventory-group`)===`true`}catch{return!1}}),[U,se]=(0,y.useState)(new Set),[ce,le]=(0,y.useState)(new Set),[ue,de]=(0,y.useState)(!1),[fe,pe]=(0,y.useState)(null),me=(0,y.useCallback)(e=>{le(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),he=(0,y.useCallback)(()=>le(new Set),[]);(0,y.useEffect)(()=>{le(new Set)},[w,E,O,A,M,P,I,R]);let[ge,_e]=(0,y.useState)(0),[ve,ye]=(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:be}=q({queryKey:[`settings`],queryFn:Q.getSettings}),xe=be?.date_format||`system`,Se=e?[`spoolman-inventory-spools`]:[`inventory-spools`],Ce=()=>JZe(r,Se),{data:we,isLoading:Te}=q({queryKey:Se,queryFn:()=>e?Q.getSpoolmanInventorySpools(!0):Q.getSpools(!0),refetchInterval:3e4}),Ee=(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]),De=e?n(`inventory.csv.spoolmanHint`,`In Spoolman mode, use Spoolman's built-in CSV import/export.`):void 0,{data:Oe=[]}=q({queryKey:S9,queryFn:Q.getLocations}),ke=c.get(`location_id`),Ae=ke===`__none__`?`__none__`:ke&&/^\d+$/.test(ke)&&Number(ke)>0?ke:``,je=c.get(`spool`),Me=je&&/^\d+$/.test(je)&&Number(je)>0?Number(je):null,Ne=we?.find(e=>e.id===Me)??null,Pe=(0,y.useCallback)(()=>{f.current=!0,l(e=>(e.delete(`spool`),e),{replace:!0})},[l]),{data:Fe,isError:Ie,error:Le}=q({queryKey:e?[`spoolman-inventory-spool`,Me]:[`inventory-spool`,Me],queryFn:()=>e?Q.getSpoolmanInventorySpool(Me):Q.getSpool(Me),enabled:t&&Me!==null&&Ne===null,staleTime:1/0,retry:(e,t)=>e<2&&!(t instanceof Yu&&t.status===404)});(0,y.useEffect)(()=>{if(!f.current){if(t&&Me&&Ne){Pe(),d({spool:Ne,mode:`edit`});return}if(Fe){Pe(),d({spool:Fe,mode:`edit`});return}Ie&&(Pe(),i(n(Le instanceof Yu&&Le.status===404?`inventory.deepLinkSpoolNotFound`:`inventory.deepLinkFetchFailed`),`error`))}},[t,Me,Ne,Fe,Ie,Le,Pe,i,n]);let{data:Re}=q({queryKey:[`spool-assignments`],queryFn:()=>Q.getAssignments(),refetchInterval:3e4}),{data:ze=[],isError:Be}=q({queryKey:[`spoolman-slot-assignments-all`],queryFn:()=>Q.getSpoolmanSlotAssignments(),enabled:e,refetchInterval:3e4,staleTime:1e4,retry:1}),Ve=(0,y.useRef)(!1);(0,y.useEffect)(()=>{Be&&!Ve.current?(Ve.current=!0,i(n(`inventory.spoolmanUnreachable`),`error`)):Be||(Ve.current=!1)},[Be,i,n]);let{data:He}=q({queryKey:[`spool-catalog`],queryFn:()=>Q.getSpoolCatalog()}),Ue=J({mutationFn:t=>e?Q.deleteSpoolmanInventorySpool(t):Q.deleteSpool(t),onSuccess:()=>{Ce(),i(n(`inventory.spoolDeleted`),`success`)},onError:e=>{e instanceof Yu&&e.status===404?i(n(`inventory.deleteSpoolNotFound`),`error`):e instanceof Yu&&e.status===503?i(n(`inventory.spoolmanUnreachable`),`error`):i(n(`inventory.deleteFailed`),`error`)}}),We=J({mutationFn:t=>e?Q.archiveSpoolmanInventorySpool(t):Q.archiveSpool(t),onSuccess:()=>{Ce(),i(n(`inventory.spoolArchived`),`success`)},onError:e=>{e instanceof Yu&&e.status===404?i(n(`inventory.archiveSpoolNotFound`),`error`):e instanceof Yu&&e.status===503?i(n(`inventory.spoolmanUnreachable`),`error`):i(n(`inventory.archiveFailed`),`error`)}}),Ge=J({mutationFn:t=>e?Q.restoreSpoolmanInventorySpool(t):Q.restoreSpool(t),onSuccess:()=>{Ce(),i(n(`inventory.spoolRestored`),`success`)},onError:e=>{e instanceof Yu&&e.status===404?i(n(`inventory.restoreSpoolNotFound`),`error`):e instanceof Yu&&e.status===503?i(n(`inventory.spoolmanUnreachable`),`error`):i(n(`inventory.restoreFailed`),`error`)}}),Ke=J({mutationFn:t=>e?Q.resetSpoolmanInventorySpoolConsumedCounter(t):Q.resetSpoolConsumedCounter(t),onSuccess:()=>{r.invalidateQueries({queryKey:Se}),i(n(`inventory.consumedCounterReset`),`success`)},onError:()=>{i(n(`inventory.resetConsumedCounterFailed`),`error`)}}),qe=J({mutationFn:t=>e?Q.bulkResetSpoolmanInventorySpoolConsumedCounter(t):Q.bulkResetSpoolConsumedCounter(t),onSuccess:e=>{r.invalidateQueries({queryKey:Se}),i(n(`inventory.allConsumedCountersReset`,{count:e.reset}),`success`),pe(null),he()},onError:()=>{i(n(`inventory.resetConsumedCounterFailed`),`error`)}}),Je=e=>(e.not_found?.length??0)+(e.errors?.length??0),Ye=J({mutationFn:async({ids:t,update:n})=>e?Q.bulkUpdateSpoolmanInventorySpools(t,n):Q.bulkUpdateSpools(t,n),onSuccess:e=>{Ce();let t=Je(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`),de(!1),he()},onError:e=>{i(e.message||n(`inventory.bulk.updateFailed`),`error`)}}),Xe=J({mutationFn:async t=>e?Q.bulkDeleteSpoolmanInventorySpools(t):Q.bulkDeleteSpools(t),onSuccess:e=>{Ce();let t=Je(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`),pe(null),he()},onError:e=>{i(e.message||n(`inventory.bulk.deleteFailed`),`error`)}}),Ze=J({mutationFn:async t=>e?Q.bulkArchiveSpoolmanInventorySpools(t):Q.bulkArchiveSpools(t),onSuccess:e=>{Ce();let t=Je(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`),pe(null),he()},onError:e=>{i(e.message||n(`inventory.bulk.archiveFailed`),`error`)}}),Qe=J({mutationFn:async t=>e?Q.bulkRestoreSpoolmanInventorySpools(t):Q.bulkRestoreSpools(t),onSuccess:e=>{Ce();let t=Je(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`),pe(null),he()},onError:e=>{i(e.message||n(`inventory.bulk.restoreFailed`),`error`)}}),$e=(0,y.useMemo)(()=>(we??[]).map(e=>e.id),[we]),et=async t=>{if(t.last_scale_weight!=null)try{e?await Q.syncSpoolmanSpoolWeight(t.id,t.last_scale_weight):await fd.updateSpoolWeight(t.id,t.last_scale_weight),r.invalidateQueries({queryKey:Se}),i(`Synced "${[t.brand,t.material,t.color_name].filter(Boolean).join(` `)}" to scale weight`,`success`)}catch(e){let t=e instanceof Yu&&e.status===404,r=e instanceof Yu&&e.status===503;i(n(t?`inventory.syncWeightSpoolNotFound`:r?`inventory.syncWeightSpoolmanUnreachable`:`inventory.syncWeightFailed`),`error`)}},tt=be?.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(!we)return null;let e=0,t=0,n=0,r=0,i={};for(let a of we){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}},[we,tt]),ct=(Re?.length??0)+(e?ze.length:0),lt=lf(be?.currency||`USD`),ut=(0,y.useMemo)(()=>{let e={};for(let t of Re||[])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 ze)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},[Re,ze]),dt=(0,y.useMemo)(()=>{let e={};for(let t of He||[])e[t.id]=t;return e},[He]),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=we||[];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(Ae)if(Ae===`__none__`)e=e.filter(e=>!e.location_id&&!e.storage_location?.trim());else{let t=Number(Ae),n=Oe.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=vU(e,R)),e},[we,w,E,O,A,M,P,I,Ae,R,tt,Oe]),mt=()=>_e(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(we?.map(e=>e.material)||[])].sort(),_t=[...new Set(we?.map(e=>e.brand).filter(Boolean)||[])].sort(),vt=[...new Set(we?.map(e=>e.category?.trim()).filter(Boolean)||[])].sort(),yt=(we??[]).some(e=>!e.category),bt=[...new Set(we?.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=(we??[]).some(e=>!e.location_id&&!e.storage_location?.trim()),St=w!==`active`||E!==`all`||!!O||!!A||!!M||!!P||!!Ae||I!==`all`||!!R,Ct=e=>{re(e),pQe(e)},wt=(0,y.useMemo)(()=>ne.filter(e=>e.visible).map(e=>e.id),[ne]),Tt=e=>{j9[e]&&(te(t=>{let n;return n=t?.column===e?t.direction===`asc`?{column:e,direction:`desc`}:null:{column:e,direction:`asc`},_Qe(n),n}),mt())},Et=(0,y.useMemo)(()=>{if(!ee)return pt;let e=j9[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(!ae)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=uQe(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=uQe(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,ae,ut]),Ot=ve===-1,kt=Dt.length,At=Ot?kt||1:ve,jt=Math.max(1,Math.ceil(kt/At)),Mt=Ot?0:Math.min(ge,jt-1),Nt=Ot?Dt:Dt.slice(Mt*At,(Mt+1)*At),Pt=()=>{let e=!ae;oe(e),se(new Set),mt();try{localStorage.setItem(`bambuddy-inventory-group`,String(e))}catch{}},G=e=>{se(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},Ft=e=>{ye(e),_e(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)(ml,{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:De,children:[(0,K.jsx)(Au,{className:`w-4 h-4`}),n(`inventory.csv.importButton`,`Import CSV`)]}),(0,K.jsxs)($,{variant:`secondary`,disabled:e||b,onClick:Ee,title:De,children:[b?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(Vs,{className:`w-4 h-4`}),n(`inventory.csv.exportButton`,`Export CSV`)]}),(0,K.jsxs)($,{variant:`secondary`,onClick:()=>C(!0),children:[(0,K.jsx)(Zc,{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)(Ol,{className:`w-4 h-4`}),n(`inventory.labels.printLabels`,`Print labels…`)]}),(0,K.jsxs)($,{onClick:()=>d({spool:null,mode:`create`}),children:[(0,K.jsx)(Tl,{className:`w-4 h-4`}),n(`inventory.addSpool`)]})]})]}),st&&!Te&&(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)(ml,{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:O9(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)(wu,{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&&$e.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)(qs,{className:`w-3.5 h-3.5`})})]}),(0,K.jsx)(`div`,{className:`text-xl font-bold text-white`,children:O9(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)(Rc,{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 ${mQe[e]||`bg-bambu-dark-tertiary text-bambu-gray`}`,children:[e,` `,(0,K.jsx)(`span`,{className:`opacity-70`,children:O9(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)(Ol,{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)(Eu,{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)(bl,{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)(Vl,{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)(Wu,{className:`w-4 h-4`})})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[B===`table`&&(0,K.jsxs)(`button`,{onClick:()=>H(!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)(As,{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 ${ae?`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)(Sc,{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)(mu,{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)(zc,{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)(Tu,{className:`w-4 h-4`}):(0,K.jsx)(qc,{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)(ml,{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)(Oo,{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)(xs,{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)(Eu,{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))]}),(Oe.length>0||Ae)&&(0,K.jsxs)(`select`,{value:Ae,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 ${Ae?`bg-bambu-green/20 text-bambu-green border-bambu-green/30`:`bg-transparent text-bambu-gray border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary`}`,children:[(0,K.jsx)(`option`,{value:``,children:n(`inventory.storageLocation`)}),Oe.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)(Wu,{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`),ae&&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:ce.size})}),(0,K.jsxs)(`div`,{className:`ml-auto flex flex-wrap items-center gap-2`,children:[(0,K.jsxs)($,{size:`sm`,variant:`secondary`,onClick:()=>de(!0),children:[(0,K.jsx)(bl,{className:`w-3.5 h-3.5 mr-1.5`}),n(`inventory.bulk.edit`)]}),(0,K.jsxs)($,{size:`sm`,variant:`secondary`,onClick:()=>g([...ce]),children:[(0,K.jsx)(Ol,{className:`w-3.5 h-3.5 mr-1.5`}),n(`inventory.bulk.printLabels`)]}),(0,K.jsxs)($,{size:`sm`,variant:`secondary`,onClick:()=>pe(`reset-consumed-counter`),children:[(0,K.jsx)(qs,{className:`w-3.5 h-3.5 mr-1.5`}),n(`inventory.bulk.resetUsage`)]}),w===`archived`?(0,K.jsxs)($,{size:`sm`,variant:`secondary`,onClick:()=>pe(`restore`),children:[(0,K.jsx)(Nl,{className:`w-3.5 h-3.5 mr-1.5`}),n(`inventory.bulk.restore`)]}):(0,K.jsxs)($,{size:`sm`,variant:`secondary`,onClick:()=>pe(`archive`),children:[(0,K.jsx)(Oo,{className:`w-3.5 h-3.5 mr-1.5`}),n(`inventory.bulk.archive`)]}),(0,K.jsxs)($,{size:`sm`,variant:`danger`,onClick:()=>pe(`delete`),children:[(0,K.jsx)(Cu,{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:he,title:n(`inventory.bulk.clearSelection`),"aria-label":n(`inventory.bulk.clearSelection`),children:(0,K.jsx)(Wu,{className:`w-4 h-4`})})]})]}),Te?(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)(wZe,{spools:we||[]}):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=t6({rgba:i.rgba,extraColors:i.extra_colors,effectType:i.effect_type,subtype:i.subtype,effectSize:`groupheader`}),s=U.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:()=>G(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:tf(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)(rs,{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:O9(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)(xQe,{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)(xQe,{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)(bQe,{pageIndex:Mt,pageSize:ve,totalRows:kt,totalPages:jt,onPageChange:_e,onPageSizeChange:Ft,t:n})]}):(0,K.jsx)(wQe,{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=>ce.has(e))),onChange:e=>{if(e.target.checked){let e=new Set(ce);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)}le(e)}else{let e=new Set(ce);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)}le(e)}}})}),wt.map(e=>{let t=!!j9[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:[hQe[e]?.(n)??e,t&&(r?ee.direction===`asc`?(0,K.jsx)(Io,{className:`w-3 h-3`}):(0,K.jsx)(Ao,{className:`w-3 h-3`}):(0,K.jsx)(Po,{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=U.has(t),a=lQe(r),o=Math.max(0,a.label_weight-a.weight_used);return(0,K.jsx)(CQe,{spools:r,headerSpool:a,remaining:o,pct:a.label_weight>0?o/a.label_weight*100:0,isExpanded:i,onToggle:()=>G(t),selectedIds:ce,onToggleSelected:me,onToggleGroupSelected:(e,t)=>{le(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:xe,t:n,onSyncWeight:et},`group-${t}`)}let t=e.spool,r=Math.max(0,t.label_weight-t.weight_used);return(0,K.jsx)(SQe,{spool:t,remaining:r,pct:t.label_weight>0?r/t.label_weight*100:0,isSelected:ce.has(t.id),onToggleSelected:()=>me(t.id),onEdit:()=>d({spool:t,mode:`edit`}),onCopy:()=>d({spool:t,mode:`copy`}),onRestore:()=>Ge.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:xe,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:ve,onChange:e=>Ft(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:()=>_e(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)(cs,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>_e(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)(as,{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:()=>_e(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)(is,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>_e(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)(ls,{className:`w-4 h-4`})})]})]})]})]}):(0,K.jsx)(wQe,{hasFilters:St,onAddSpool:()=>d({spool:null,mode:`create`}),t:n}),u!==null&&(0,K.jsx)(XZe,{isOpen:!0,onClose:()=>d(null),spool:u.spool,mode:u.mode,currencySymbol:lt,spoolmanMode:e,spoolsQueryKey:Se}),p&&(0,K.jsx)(zd,{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:$e.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`?Ue.mutate(p.spoolId):p.type===`archive`?We.mutate(p.spoolId):p.type===`reset-consumed-counter`?Ke.mutate(p.spoolId):qe.mutate($e),m(null)},onCancel:()=>m(null)}),(0,K.jsx)(ZZe,{isOpen:ie,onClose:()=>H(!1),columns:ne,defaultColumns:D9,onSave:Ct}),(0,K.jsx)(iQe,{isOpen:h!==null,onClose:()=>g(null),availableSpools:pt,initialSelectedIds:h??[],spoolmanMode:e}),(0,K.jsx)(cQe,{isOpen:ue,selectedCount:ce.size,isPending:Ye.isPending,availableLocations:Oe.map(e=>({id:e.id,name:e.name})),availableMaterials:E9((we??[]).map(e=>e.material)),availableSubtypes:E9((we??[]).map(e=>e.subtype)),availableBrands:E9((we??[]).map(e=>e.brand)),availableCategories:E9((we??[]).map(e=>e.category)),availableSlicerFilaments:E9((we??[]).map(e=>e.slicer_filament)),availableSlicerFilamentNames:E9((we??[]).map(e=>e.slicer_filament_name)),onClose:()=>de(!1),onApply:e=>Ye.mutate({ids:[...ce],update:e})}),fe&&(0,K.jsx)(zd,{title:n(fe===`delete`?`inventory.bulk.deleteTitle`:fe===`archive`?`inventory.bulk.archiveTitle`:fe===`restore`?`inventory.bulk.restoreTitle`:`inventory.bulk.resetUsageTitle`),message:n(fe===`delete`?`inventory.bulk.deleteMessage`:fe===`archive`?`inventory.bulk.archiveMessage`:fe===`restore`?`inventory.bulk.restoreMessage`:`inventory.bulk.resetUsageMessage`,{count:ce.size}),confirmText:n(fe===`delete`?`common.delete`:fe===`archive`?`inventory.archive`:fe===`restore`?`inventory.restore`:`inventory.resetConsumedCounter`),variant:fe===`delete`?`danger`:`warning`,isLoading:Xe.isPending||Ze.isPending||Qe.isPending||qe.isPending,onConfirm:()=>{let e=[...ce];fe===`delete`?Xe.mutate(e):fe===`archive`?Ze.mutate(e):fe===`restore`?Qe.mutate(e):qe.mutate(e)},onCancel:()=>pe(null)}),_&&(0,K.jsx)(aQe,{onClose:()=>v(!1),onImported:e=>{v(!1),r.invalidateQueries({queryKey:Se}),i(n(`inventory.csv.importSuccess`,`{{count}} spools imported`,{count:e}),`success`)}}),(0,K.jsx)(oQe,{open:S,onClose:()=>C(!1),onPickLocation:e=>ht(String(e))})]})}function bQe({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)(cs,{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)(as,{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)(is,{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)(ls,{className:`w-4 h-4`})})]})]})]})}function xQe({spool:e,remaining:t,pct:n,onClick:r,onPrintLabel:i,onCopy:a,t:o}){let s=t6({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:tf(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)(Ms,{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)(Ol,{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:O9(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?O9(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 SQe({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:A9[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)(bl,{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)(Ms,{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)(Ol,{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)(qs,{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)(Nl,{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)(Oo,{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)(Cu,{className:`w-4 h-4`})})]})})]})}function CQe({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)(rs,{className:`w-4 h-4 text-bambu-gray transition-transform ${i?``:`-rotate-90`}`}),A9[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})}):A9[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)(SQe,{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 wQe({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)(Vl,{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)(ml,{className:`w-4 h-4`}),n(`inventory.addSpool`)]})]})}function N9(e,t){let n=e?.[t];return typeof n==`string`?n:``}function TQe(e){return e.replace(/(https?:\/\/(?:makerworld|public-cdn)\.bblmw\.com\/[^\s"']+)/gi,e=>`/api/v1/makerworld/thumbnail?url=${encodeURIComponent(e)}`)}function P9(e){return e?/^https?:\/\/(makerworld|public-cdn)\.bblmw\.com\//i.test(e)?`/api/v1/makerworld/thumbnail?url=${encodeURIComponent(e)}`:e:``}function F9(e,t){let n=e?.[t];return typeof n==`number`?n:null}function EQe(e,t){let n=e?.[t];return n&&typeof n==`object`&&!Array.isArray(n)?n:void 0}function DQe(e,t=0,n=[]){n.push({folder:e,depth:t});for(let r of e.children??[])DQe(r,t+1,n);return n}function OQe(e,t){return t(e<1?`makerworld.phaseResolving`:`makerworld.phaseDownloading`)}function kQe(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 AQe(){let{t:e}=W(),{hasPermission:t}=_d(),{showToast:n}=jd(),r=no(),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=T.data?.open_in_slicer||D,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=kQe(F.isPending||L.isPending),z=OQe(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:N9(e,`name`)||`image`,url:N9(e,`url`)})).filter(e=>e.url);if(t.length>0)return t;let n=N9(e,`cover`);return n?[{name:`cover`,url:n}]:[]},ee=async()=>{if(!s)return;let e=s.instances.filter(e=>{let t=F9(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);qW(`${window.location.origin}${i}`,n)}catch{let t=Q.getLibraryFileDownloadUrl(e);qW(`${window.location.origin}${t}`,n)}},ne=s?.design,re=EQe(ne,`designCreator`),ie=s?.instances??[],H=(s?.already_imported_library_ids.length??0)>0,ae=S.data?.can_download??!1,oe=S.data?.sign_in_expired??!1,U=(0,y.useMemo)(()=>N9(ne,`coverUrl`),[ne]),se=N9(ne,`title`),ce=N9(ne,`summary`),le=N9(ne,`license`),ue=F9(ne,`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)(bc,{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:[!ae&&(0,K.jsx)(Cd,{className:`border-amber-300 dark:border-amber-700 bg-amber-50 dark:bg-amber-900/20`,children:(0,K.jsx)(Td,{children:(0,K.jsxs)(`div`,{className:`flex items-start gap-3 py-2`,children:[(0,K.jsx)(us,{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(oe?`makerworld.signInExpiredTitle`:`makerworld.signInRequiredTitle`)}),(0,K.jsxs)(`p`,{className:`text-amber-800 dark:text-amber-200 mt-1`,children:[e(oe?`makerworld.signInExpiredBody`:`makerworld.signInRequiredBody`),` `,(0,K.jsx)(wi,{to:`/profiles`,className:`underline`,children:e(`makerworld.openCloudSettings`)})]})]})]})})}),(0,K.jsxs)(Cd,{children:[(0,K.jsx)(wd,{children:(0,K.jsx)(`h2`,{className:`text-lg font-semibold`,children:e(`makerworld.pasteUrlHeader`)})}),(0,K.jsx)(Td,{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)(No,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{className:`ml-2`,children:e(`makerworld.resolveButton`)})]})]})})]}),s&&(0,K.jsx)(Cd,{children:(0,K.jsx)(Td,{children:(0,K.jsxs)(`div`,{className:`flex gap-4 py-2`,children:[U&&(0,K.jsx)(`img`,{src:P9(U),alt:se,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:se||e(`makerworld.untitledModel`)}),re&&(0,K.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400 mt-1`,children:e(`makerworld.byCreator`,{name:N9(re,`name`)})}),(0,K.jsxs)(`div`,{className:`flex flex-wrap gap-3 mt-2 text-xs text-gray-500 dark:text-gray-400`,children:[ue!==null&&(0,K.jsx)(`span`,{children:e(`makerworld.downloadsCount`,{count:ue})}),le&&(0,K.jsxs)(`span`,{children:[e(`makerworld.licensePrefix`),`: `,le]}),H&&(0,K.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-emerald-600 dark:text-emerald-400`,children:[(0,K.jsx)(ns,{className:`w-3 h-3`}),` `,e(`makerworld.alreadyImported`)]})]}),ce&&(0,K.jsx)(`div`,{className:`mt-3 text-sm prose prose-sm max-w-none dark:prose-invert line-clamp-3`,dangerouslySetInnerHTML:{__html:qG.sanitize(TQe(ce))}}),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)(Js,{className:`w-3 h-3`}),` `,e(`makerworld.openOnMakerworld`)]})]})]})})}),s&&ie.length>0&&(0,K.jsxs)(Cd,{children:[(0,K.jsx)(wd,{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:ie.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=>DQe(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||!ae||d!==null||F.isPending||L.isPending,onClick:ee,children:d===null?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Vs,{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)(Td,{children:(0,K.jsx)(`div`,{className:`grid gap-3`,children:ie.map((t,n)=>{let r=F9(t,`id`),a=F9(t,`profileId`),o=N9(t,`title`),s=N9(t,`cover`),c=F9(t,`materialCnt`),l=t?.needAms===!0,u=F9(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:P9(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)(Nc,{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||!ae||v||y||d!==null,onClick:()=>F.mutate({instanceId:r,profileId:a}),title:ae?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)(Vs,{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||!ae||v||y||d!==null,onClick:()=>L.mutate({instanceId:r,profileId:a}),title:ae?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)(Js,{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)(ns,{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)(cc,{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)(ks,{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)(Js,{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)(Js,{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)(Cu,{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)(Cd,{children:[(0,K.jsx)(wd,{children:(0,K.jsx)(`h2`,{className:`text-base font-semibold`,children:e(`makerworld.recentImportsHeader`)})}),(0,K.jsx)(Td,{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)(cc,{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)(ks,{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)(Js,{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)(bc,{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)(zd,{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)(UW,{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)(Wu,{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)(as,{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)(is,{className:`w-6 h-6`})})]}),(0,K.jsx)(`img`,{src:P9(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 jQe=[`DEBUG`,`INFO`,`WARNING`,`ERROR`],I9={DEBUG:`text-gray-400`,INFO:`text-blue-400`,WARNING:`text-yellow-400`,ERROR:`text-red-400`},MQe={DEBUG:Ko,INFO:Pc,WARNING:Eu,ERROR:us};function NQe(){let e=no(),[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:()=>dd.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:()=>dd.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)(MQe[e]||Pc,{className:`w-3.5 h-3.5 ${I9[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)(Ko,{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)(ss,{className:`w-5 h-5 text-bambu-gray`}):(0,K.jsx)(rs,{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)(lu,{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)(Cl,{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)(Cu,{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)(jl,{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)(Vl,{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)(Wu,{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`}),jQe.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===jQe.length-1?`rounded-r`:``} ${s===e?`${I9[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 ${I9[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)(ss,{className:`w-3.5 h-3.5`}):(0,K.jsx)(rs,{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 PQe(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 L9({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 FQe({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 R9({title:e,icon:t,children:n}){return(0,K.jsxs)(Cd,{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 IQe(){let{t:e}=W(),t=no(),[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:dd.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 dd.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 dd.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)(jl,{className:`w-4 h-4 ${p?`animate-spin`:``}`}),e(`common.refresh`,`Refresh`)]})]}),(0,K.jsx)(R9,{title:e(`system.application`,`Application`),icon:Wl,children:(0,K.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-4`,children:[(0,K.jsx)(L9,{icon:Wl,label:e(`system.version`,`Version`),value:`v${u.app.version}`}),(0,K.jsx)(L9,{icon:xs,label:e(`system.uptime`,`System Uptime`),value:u.system.uptime_formatted}),(0,K.jsx)(L9,{icon:Wl,label:e(`system.hostname`,`Hostname`),value:u.system.hostname})]})}),(0,K.jsx)(R9,{title:e(`support.title`,`Support & Troubleshooting`),icon:Ec,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)(Ko,{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)(Vs,{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)(NQe,{})]})}),(0,K.jsxs)(R9,{title:e(`diagnostic.sectionTitle`,`Connection Diagnostic`),icon:du,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)(du,{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)(R9,{title:e(`systemHealth.sectionTitle`),icon:Dc,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)(jl,{className:`w-4 h-4 ${x?`animate-spin`:``}`}),e(`systemHealth.rescan`)]})]}),v?(0,K.jsx)(xp,{result:v}):(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`common.loading`)})]}),(0,K.jsxs)(R9,{title:e(`system.database`,`Database`),icon:Is,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4 mb-4`,children:[(0,K.jsx)(L9,{icon:Is,label:e(`system.dbEngine`,`Database Engine`),value:u.database.engine||`SQLite`}),(0,K.jsx)(L9,{icon:Is,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)(L9,{icon:Oo,label:e(`system.totalArchives`,`Total Archives`),value:u.database.archives}),(0,K.jsx)(L9,{icon:ps,label:e(`system.completed`,`Completed`),value:u.database.archives_completed,color:`text-green-500`}),(0,K.jsx)(L9,{icon:vs,label:e(`system.failed`,`Failed`),value:u.database.archives_failed,color:`text-red-500`}),(0,K.jsx)(L9,{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)(L9,{icon:Ol,label:e(`system.printers`,`Printers`),value:u.database.printers}),(0,K.jsx)(L9,{icon:hl,label:e(`system.filaments`,`Filaments`),value:u.database.filaments}),(0,K.jsx)(L9,{icon:sc,label:e(`system.projects`,`Projects`),value:u.database.projects}),(0,K.jsx)(L9,{icon:wl,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)(L9,{icon:xs,label:e(`system.totalPrintTime`,`Total Print Time`),value:u.database.total_print_time_formatted}),(0,K.jsx)(L9,{icon:Oo,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)(R9,{title:e(`system.connectedPrinters`,`Connected Printers`),icon:Ol,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)(R9,{title:e(`system.storage`,`Storage`),icon:wc,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)(FQe,{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)(L9,{icon:Oo,label:e(`system.archiveStorage`,`Archive Storage`),value:u.storage.archive_size_formatted}),(0,K.jsx)(L9,{icon:Is,label:e(`system.databaseSize`,`Database Size`),value:u.storage.database_size_formatted}),g&&(0,K.jsx)(L9,{icon:cc,label:e(`system.fileManagerStorage`,`File Manager`),value:PQe(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)(R9,{title:e(`system.memory`,`Memory`),icon:tl,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)(FQe,{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)(R9,{title:e(`system.cpu`,`CPU`),icon:Ns,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)(L9,{icon:Ns,label:e(`system.cores`,`Cores`),value:u.cpu.count,subValue:`${u.cpu.count_logical} logical`}),(0,K.jsx)(L9,{icon:Ns,label:e(`system.usage`,`Usage`),value:`${u.cpu.percent}%`})]})})})]}),(0,K.jsx)(R9,{title:e(`system.systemDetails`,`System Details`),icon:Wl,children:(0,K.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-4`,children:[(0,K.jsx)(L9,{icon:Wl,label:e(`system.os`,`Operating System`),value:u.system.platform,subValue:u.system.platform_release}),(0,K.jsx)(L9,{icon:Ns,label:e(`system.architecture`,`Architecture`),value:u.system.architecture}),(0,K.jsx)(L9,{icon:Wl,label:e(`system.python`,`Python`),value:u.system.python_version}),(0,K.jsx)(L9,{icon:xs,label:e(`system.bootTime`,`Boot Time`),value:jf(u.system.boot_time,S)})]})}),c&&(0,K.jsx)(_p,{printerId:c.id,printerName:c.name,onClose:()=>l(null)})]})}var z9=`auth_remember_me`,B9=`auth_post_login_redirect`;function V9(e){return e?`persistent`:`session`}function LQe(){try{let e=sessionStorage.getItem(z9)===`1`;return sessionStorage.removeItem(z9),e}catch(e){return console.warn(`consumeSavedRememberMe: sessionStorage unavailable, Remember Me preference lost across OIDC redirect`,e),!1}}function H9(e){return!e||!e.startsWith(`/`)||e.startsWith(`//`)||e.startsWith(`/login`)?null:e}function RQe(e){let t=H9(e);if(t)try{sessionStorage.setItem(B9,t)}catch(e){console.warn(`stashPostLoginRedirect: sessionStorage unavailable, post-login target will be lost across OIDC redirect`,e)}}function zQe(){try{let e=sessionStorage.getItem(B9);return sessionStorage.removeItem(B9),H9(e)}catch(e){return console.warn(`consumePostLoginRedirect: sessionStorage unavailable`,e),null}}function BQe({provider:e,onClick:t,disabled:n}){let{t:r}=W(),[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)(Xl,{className:`w-5 h-5 text-bambu-green`}),r(`login.twoFA.signInWith`,{provider:e.name})]})}function VQe(){let e=$n(),t=Xn(),[n]=Mi(),{t:r}=W(),{login:i,loginWithToken:a,user:o,loading:s}=_d(),{showToast:c}=jd(),{mode:l}=bd();function u(){let e=t.state?.from;if(e?.pathname){let t=H9(`${e.pathname}${e.search??``}`);if(t)return t}return zQe()??`/`}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,ne]=(0,y.useState)(!1);(0,y.useEffect)(()=>{!s&&o&&b===`credentials`&&e(`/`,{replace:!0})},[s,o,b,e]);let re=(0,y.useRef)(!1);(0,y.useEffect)(()=>{if(re.current||n.get(`fallback`)===`local`||!V||!V.autologin_provider_id||window.location.hash.startsWith(`#oidc_token=`)||n.get(`oidc_error`))return;re.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(()=>{ne(!0)})},[V,n]);let ie=V?.local_login_enabled!==!1,H=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=LQe();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,V9(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 ae=J({mutationFn:()=>i(d,p,V9(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`)}}),oe=J({mutationFn:e=>Q.forgotPassword({email:e}),onSuccess:e=>{c(e.message,`success`),g(!1),v(``)},onError:e=>{c(e.message,`error`)}}),U=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`)}}),se=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`)}}),ce=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,V9(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(``)}}),le=J({mutationFn:e=>Q.getOIDCAuthorizeUrl(e),onSuccess:e=>{if(N)try{sessionStorage.setItem(z9,`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&&RQe(`${n.pathname}${n.search??``}`),window.location.href=e.auth_url},onError:e=>{c(e.message||r(`login.oidcLoginFailed`),`error`)}}),ue=e=>{if(e.preventDefault(),!d||!p){c(r(`login.enterCredentials`),`error`);return}ae.mutate()},de=e=>{if(e.preventDefault(),!O.trim()){c(r(`login.twoFA.enterCode`),`error`);return}ce.mutate()},fe=e=>{if(e.preventDefault(),!_){c(r(`login.enterEmail`),`error`);return}oe.mutate(_)},pe=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)(Ic,{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}U.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:U.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:U.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)(Xl,{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:()=>pe(`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)(ru,{className:`w-4 h-4`}),r(`login.twoFA.methodAuthenticator`)]}),w.includes(`email`)&&(0,K.jsxs)(`button`,{type:`button`,onClick:()=>pe(`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)(Xc,{className:`w-4 h-4`}),r(`login.twoFA.methodEmail`)]}),w.includes(`backup`)&&(0,K.jsxs)(`button`,{type:`button`,onClick:()=>pe(`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)(Ic,{className:`w-4 h-4`}),r(`login.twoFA.methodBackup`)]})]}),(0,K.jsxs)(`form`,{onSubmit:de,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:()=>se.mutate(),disabled:se.isPending,children:se.isPending?r(`login.twoFA.sendingCode`):r(`login.twoFA.sendCodeButton`)}),A&&(0,K.jsx)(`button`,{type:`button`,onClick:()=>{j(!1),se.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:ce.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:ce.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`)})]}),H&&(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`)}),!ie&&(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`)}),ie&&(0,K.jsxs)(`form`,{className:`mt-8 space-y-6`,onSubmit:ue,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:ae.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:ae.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)(BQe,{provider:e,onClick:()=>le.mutate(e.id),disabled:le.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)(Cd,{className:`w-full max-w-md`,onClick:e=>e.stopPropagation(),children:[(0,K.jsx)(wd,{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)(Xc,{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)(Wu,{className:`w-5 h-5`})})]})}),(0,K.jsx)(Td,{children:V?.advanced_auth_enabled?(0,K.jsxs)(`form`,{onSubmit:fe,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:oe.isPending,children:oe.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 HQe(){let e=$n(),{t}=W(),{showToast:n}=jd(),{mode:r}=bd(),{refreshAuth:i}=_d(),[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)(Pc,{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 UQe(){let{t:e}=W(),{user:t}=_d(),{showToast:n}=jd(),r=no(),i=$n(),[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)(Bo,{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)(Cd,{className:`mb-6 border-blue-300 bg-blue-50 dark:border-blue-500/30 dark:bg-blue-500/5`,children:(0,K.jsx)(Td,{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)(Xc,{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)(Cd,{className:`mb-6`,children:[(0,K.jsxs)(wd,{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)(Td,{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)(ps,{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)(ps,{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)(ps,{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)(ps,{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)(Il,{className:`w-4 h-4`}),e(`common.save`)]})})})]})}function WQe(){let e=$n(),[t]=Mi(),{t:n}=W();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)(jo,{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 GQe=4401;function KQe(){let e=(0,y.useRef)(null),t=(0,y.useRef)(null),n=(0,y.useRef)(!1),r=no(),[i,a]=(0,y.useState)(!1),o=(0,y.useRef)(new Map),{showToast:s}=jd(),{t:c}=W(),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?requestAnimationFrame(()=>{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 Yu?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===GQe)&&(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,requestAnimationFrame(()=>{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(()=>{requestAnimationFrame(()=>{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(S9[0]);break;case`spool_assignment_changed`:b(`spool-assignments`),b(`slotPresets`);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))},[])}}function qQe({children:e}){let{authEnabled:t,user:n,loading:r}=_d(),{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&&Xd(i)},[i]),(0,K.jsx)(K.Fragment,{children:e})}function JQe({selectedPrinterId:e,onPrinterChange:t,deviceOnline:n}){let{t:r}=W(),[i,a]=(0,y.useState)(new Date),{data:o=[]}=q({queryKey:[`printers`],queryFn:()=>Q.getPrinters()}),s=_o({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)(zu,{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:Mf(i,l?.time_format||`system`)})]})]})}var YQe=[{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 XQe(){let{t:e}=W();return(0,K.jsx)(`nav`,{className:`h-14 bg-bambu-dark-secondary border-t border-bambu-dark-tertiary flex items-stretch shrink-0`,children:YQe.map(t=>(0,K.jsxs)(Ti,{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 ZQe({alert:e}){let{t}=W(),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 QQe({isOpen:e,onClose:t,deviceId:n,deviceOnline:r}){let{t:i}=W(),[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 fd.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)(U9,{icon:(0,K.jsx)(Pl,{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)(U9,{icon:(0,K.jsx)(sl,{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)(U9,{icon:(0,K.jsx)(Pl,{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)(U9,{icon:(0,K.jsx)(El,{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)(rs,{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 U9({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 $Qe={weight:null,weightStable:!1,rawAdc:null,matchedSpool:null,unknownTagUid:null,unknownTrayUuid:null,deviceOnline:!1,deviceId:null};function e$e(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 t$e(){let[e,t]=(0,y.useReducer)(e$e,$Qe),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 n$e=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":` diff --git a/static/index.html b/static/index.html index cb2ff87f2..f18e4a558 100644 --- a/static/index.html +++ b/static/index.html @@ -26,7 +26,7 @@ - +